- Fixed some trivial compilation problems with Drone
- Putting in the new PacketTreeView code (still not complete)
This commit is contained in:
parent
8251383351
commit
03ab9c4349
@ -1,158 +1,45 @@
|
|||||||
#include "packetmodel.h"
|
#include "packetmodel.h"
|
||||||
|
|
||||||
|
|
||||||
PacketModel::PacketModel(Stream *pStream, QObject *parent)
|
PacketModel::PacketModel(Stream *pStream, QObject *parent)
|
||||||
{
|
{
|
||||||
mpStream = pStream;
|
mpStream = pStream;
|
||||||
|
populatePacketProtocols();
|
||||||
|
registerFrameTypeProto();
|
||||||
|
registerVlanProto();
|
||||||
|
registerIpProto();
|
||||||
|
registerArpProto();
|
||||||
|
registerTcpProto();
|
||||||
|
registerUdpProto();
|
||||||
|
registerIcmpProto();
|
||||||
|
registerIgmpProto();
|
||||||
|
registerData();
|
||||||
|
registerInvalidProto();
|
||||||
}
|
}
|
||||||
|
|
||||||
int PacketModel::rowCount(const QModelIndex &parent) const
|
int PacketModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
// Parent - Invisible Root.
|
IndexId parentId;
|
||||||
// Children - Top Level Items
|
|
||||||
|
// Parent - Invalid i.e. Invisible Root.
|
||||||
|
// Children - Protocol (Top Level) Items
|
||||||
if (!parent.isValid())
|
if (!parent.isValid())
|
||||||
|
return mPacketProtocols.count();
|
||||||
|
|
||||||
|
// Parent - Valid Item
|
||||||
|
parentId.w = parent.internalId();
|
||||||
|
switch(parentId.ws.type)
|
||||||
{
|
{
|
||||||
int v = 0;
|
case ITYP_PROTOCOL:
|
||||||
|
return fieldCount(parentId.ws.protocol);
|
||||||
if (mpStream->l2.eth.vlanMask & VM_SVLAN_TAGGED)
|
case ITYP_FIELD:
|
||||||
v++;
|
return subfieldCount(parentId.ws.protocol, parentId.ws.field);
|
||||||
if (mpStream->l2.eth.vlanMask & VM_CVLAN_TAGGED)
|
case ITYP_SUBFIELD:
|
||||||
v++;
|
return 0;
|
||||||
|
|
||||||
if (mpStream->proto.protoMask & PM_L3_PROTO_NONE)
|
|
||||||
return v+2; // L2, Data
|
|
||||||
if (mpStream->proto.protoMask & PM_L4_PROTO_NONE)
|
|
||||||
return v+3; // L2, L3, Data
|
|
||||||
else
|
|
||||||
return v+4; // L2, L3, L4, Data
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parent - Top Level Item (L2)
|
|
||||||
// Children(count) - Second Level Items (L2 fields)
|
|
||||||
if (isIndexL2Container(parent))
|
|
||||||
{
|
|
||||||
switch(mpStream->proto.ft)
|
|
||||||
{
|
|
||||||
case Stream::e_ft_none:
|
|
||||||
return 2; // DstMac, SrcMac
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Stream::e_ft_eth_2:
|
|
||||||
case Stream::e_ft_802_3_raw:
|
|
||||||
return 3; // DstMac, SrcMac, Type/Len
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Stream::e_ft_802_3_llc:
|
|
||||||
case Stream::e_ft_snap:
|
|
||||||
return 5; // DstMac, SrcMac, Type, DSAP, SSAP, CTL, OUI, Type
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
qDebug("%s: Unsupported frametype", __FUNCTION__);
|
qWarning("%s: Unhandled ItemType", __FUNCTION__);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parent - Top Level Item (SVLAN)
|
qWarning("%s: Catch all - need to investigate", __FUNCTION__);
|
||||||
// Children(count) - Second Level Items (SVLAN fields)
|
|
||||||
if (isIndexSvlanContainer(parent))
|
|
||||||
{
|
|
||||||
return 4; // TPID, PCP, DE, VlanId
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parent - Top Level Item (CVLAN)
|
|
||||||
// Children(count) - Second Level Items (CVLAN fields)
|
|
||||||
if (isIndexCvlanContainer(parent))
|
|
||||||
{
|
|
||||||
return 4; // TPID, Prio, CFI, VlanId
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parent - Top Level Item (L3)
|
|
||||||
// Children(count) - Second Level Items (L3 fields)
|
|
||||||
if (isIndexL3Container(parent))
|
|
||||||
{
|
|
||||||
// L3 cannot be "None"
|
|
||||||
Q_ASSERT(mpStream->proto.protoMask & PM_L3_PROTO_NONE);
|
|
||||||
|
|
||||||
switch(mpStream->proto.etherType)
|
|
||||||
{
|
|
||||||
case ETH_TYP_IP:
|
|
||||||
return 12; // Ver, HdrLen, TOS, TotLen, Id, Flags,
|
|
||||||
// FragOfs, TTL, Proto, Cksum, SrcIp, DstIp
|
|
||||||
break;
|
|
||||||
case ETH_TYP_ARP:
|
|
||||||
return 0; // TODO(LOW)
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
qDebug("%s: Unsupported ethtype", __FUNCTION__);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parent - Top Level Item (L4)
|
|
||||||
// Children(count) - Second Level Items (L4 fields)
|
|
||||||
if (isIndexL4Container(parent))
|
|
||||||
{
|
|
||||||
// L4 cannot be "None"
|
|
||||||
Q_ASSERT(mpStream->proto.protoMask & PM_L4_PROTO_NONE);
|
|
||||||
|
|
||||||
switch(mpStream->proto.ipProto)
|
|
||||||
{
|
|
||||||
case IP_PROTO_TCP:
|
|
||||||
return 10; // SrcPort, DstPort, SeqNum, AckNum, HdrLen,
|
|
||||||
// Rsvd, Flags, Window, Cksum, UrgPtr,
|
|
||||||
break;
|
|
||||||
case IP_PROTO_UDP:
|
|
||||||
return 4; // SrcPort, DstPort, TotLen, Cksum
|
|
||||||
break;
|
|
||||||
case IP_PROTO_ICMP:
|
|
||||||
case IP_PROTO_IGMP:
|
|
||||||
return 0; // TODO(LOW)
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
qDebug("%s: Unsupported ethtype", __FUNCTION__);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parent - Second Level Item (L2 field)
|
|
||||||
// Children(count) - Third Level Items (L2 subfield)
|
|
||||||
if (isIndexL2Field(parent))
|
|
||||||
{
|
|
||||||
return 0; // No subfields for any L2 field
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parent - Second Level Item (L3 field)
|
|
||||||
// Children(count) - Third Level Items (L3 subfield)
|
|
||||||
if (isIndexL3Field(parent))
|
|
||||||
{
|
|
||||||
if (isIndexIpField(parent))
|
|
||||||
return 0; // TODO (MED)
|
|
||||||
if (isIndexArpField(parent))
|
|
||||||
return 0; // TODO (LOW)
|
|
||||||
|
|
||||||
qDebug("%s: Unknown L3 Field", __FUNCTION__);
|
|
||||||
return 0; // catch all
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parent - Second Level Item (L4 field)
|
|
||||||
// Children(count) - Third Level Items (L4 subfield)
|
|
||||||
if (isIndexL4Field(parent))
|
|
||||||
{
|
|
||||||
if (isIndexTcpField(parent))
|
|
||||||
return 0; // TODO (MED)
|
|
||||||
if (isIndexUdpField(parent))
|
|
||||||
return 0; // No subfields for any UDP fields
|
|
||||||
if (isIndexIcmpField(parent))
|
|
||||||
return 0; // TODO (LOW)
|
|
||||||
if (isIndexIgmpField(parent))
|
|
||||||
return 0; // TODO (LOW)
|
|
||||||
|
|
||||||
qDebug("%s: Unknown L4 Field", __FUNCTION__);
|
|
||||||
return 0; // catch all
|
|
||||||
}
|
|
||||||
|
|
||||||
//qDebug("%s: Catch all - need to investigate", __FUNCTION__);
|
|
||||||
return 0; // catch all
|
return 0; // catch all
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,68 +52,42 @@ QModelIndex PacketModel::index(int row, int col, const QModelIndex &parent) cons
|
|||||||
{
|
{
|
||||||
QModelIndex index;
|
QModelIndex index;
|
||||||
IndexId id, parentId;
|
IndexId id, parentId;
|
||||||
uint vlanMask = mpStream->l2.eth.vlanMask;
|
|
||||||
|
|
||||||
if (!hasIndex(row, col, parent))
|
if (!hasIndex(row, col, parent))
|
||||||
goto _exit;
|
goto _exit;
|
||||||
|
|
||||||
|
// Parent is Invisible Root
|
||||||
|
// Request for a Protocol Item
|
||||||
|
if (!parent.isValid())
|
||||||
|
{
|
||||||
|
id.w = 0;
|
||||||
|
id.ws.type = ITYP_PROTOCOL;
|
||||||
|
id.ws.protocol = mPacketProtocols.at(row);
|
||||||
|
index = createIndex(row, col, id.w);
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parent is a Valid Item
|
||||||
parentId.w = parent.internalId();
|
parentId.w = parent.internalId();
|
||||||
|
id.w = parentId.w;
|
||||||
// Parent - Invisible Root
|
switch(parentId.ws.type)
|
||||||
// Requested child - First/Top Level Item
|
|
||||||
if (parentId.ws.b2 == 0xFF)
|
|
||||||
{
|
{
|
||||||
Q_ASSERT(!parent.isValid());
|
case ITYP_PROTOCOL:
|
||||||
|
id.ws.type = ITYP_FIELD;
|
||||||
if (mpStream->l2.eth.vlanMask & VM_UNTAGGED)
|
id.ws.field = row;
|
||||||
id.ws.b1 = row+2; // Only L2, L3, L4
|
|
||||||
else if (VM_SINGLE_TAGGED(vlanMask))
|
|
||||||
{
|
|
||||||
switch (row)
|
|
||||||
{
|
|
||||||
case 0: id.ws.b1 = 2; break; // L2
|
|
||||||
case 1: id.ws.b1 = (vlanMask & VM_SVLAN_TAGGED)?0x88:0x81; break;
|
|
||||||
case 2: id.ws.b1 = 3; break; // L3
|
|
||||||
case 3: id.ws.b1 = 4; break; // L4
|
|
||||||
case 4: id.ws.b1 = 0; break; // Data
|
|
||||||
default: qWarning("%s: Unexpected row (%d)", __FUNCTION__, row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (VM_DOUBLE_TAGGED(vlanMask))
|
|
||||||
{
|
|
||||||
switch (row)
|
|
||||||
{
|
|
||||||
case 0: id.ws.b1 = 2; break; // L2
|
|
||||||
case 1: id.ws.b1 = 0x88; break; // SVLAN
|
|
||||||
case 2: id.ws.b1 = 0x81; break; // CVLAN
|
|
||||||
case 3: id.ws.b1 = 3; break; // L3
|
|
||||||
case 4: id.ws.b1 = 4; break; // L4
|
|
||||||
case 5: id.ws.b1 = 0; break; // Data
|
|
||||||
default: qWarning("%s: Unexpected row (%d)", __FUNCTION__, row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
id.ws.b2 = 0xFF;
|
|
||||||
index = createIndex(row, col, id.w);
|
index = createIndex(row, col, id.w);
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
|
||||||
|
|
||||||
// Parent - First Level Item
|
case ITYP_FIELD:
|
||||||
// Requested child - Second Level Item
|
// TODO(MED): Nothing till subfield support is added
|
||||||
if (parentId.ws.b3 == 0xFF)
|
|
||||||
{
|
|
||||||
Q_ASSERT(parentId.ws.b1 != 0xFF);
|
|
||||||
Q_ASSERT(parentId.ws.b2 != 0xFF);
|
|
||||||
|
|
||||||
id.ws.b1 = parentId.ws.b1;
|
|
||||||
id.ws.b2 = 0; // TODO(MED): Set Field Id for subfields
|
|
||||||
index = createIndex(row, col, id.w);
|
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
|
||||||
|
|
||||||
// Parent - Second Level Item (Field)
|
case ITYP_SUBFIELD:
|
||||||
// Requested child - Third Level Item (Subfield)
|
goto _exit;
|
||||||
// TODO(MED): Support subfields
|
|
||||||
// Till then we return an invalid index
|
default:
|
||||||
|
qWarning("%s: Unhandled ItemType", __FUNCTION__);
|
||||||
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
return index;
|
return index;
|
||||||
@ -234,207 +95,342 @@ _exit:
|
|||||||
|
|
||||||
QModelIndex PacketModel::parent(const QModelIndex &index) const
|
QModelIndex PacketModel::parent(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
|
QModelIndex parentIndex;
|
||||||
IndexId id, parentId;
|
IndexId id, parentId;
|
||||||
|
|
||||||
|
if (!index.isValid())
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
id.w = index.internalId();
|
id.w = index.internalId();
|
||||||
parentId = id;
|
parentId.w = id.w;
|
||||||
|
switch(id.ws.type)
|
||||||
|
{
|
||||||
|
case ITYP_PROTOCOL:
|
||||||
|
// return invalid index for invisible root
|
||||||
|
goto _exit;
|
||||||
|
|
||||||
// 1st/Top Level Item - Protocol
|
case ITYP_FIELD:
|
||||||
// Requested Parent => Invisible Root
|
parentId.ws.type = ITYP_PROTOCOL;
|
||||||
if (id.ws.b2 == 0xFF)
|
parentId.ws.field = 0;
|
||||||
return QModelIndex();
|
parentIndex = createIndex(mPacketProtocols.indexOf(parentId.ws.protocol), 0,
|
||||||
|
parentId.w);
|
||||||
|
goto _exit;
|
||||||
|
|
||||||
// Second Level Item - Field
|
case ITYP_SUBFIELD:
|
||||||
// Requested Parent => 1st Level Item (Protocol)
|
// TODO(MED): invalid index till subfield support is added
|
||||||
if (id.ws.b3 == 0xFF)
|
goto _exit;
|
||||||
{
|
|
||||||
uint vlanMask = mpStream->l2.eth.vlanMask;
|
|
||||||
int row = -1;
|
|
||||||
|
|
||||||
parentId.ws.b2 = 0xFF;
|
default:
|
||||||
|
qWarning("%s: Unhandled ItemType", __FUNCTION__);
|
||||||
if (vlanMask & VM_UNTAGGED)
|
|
||||||
{
|
|
||||||
row = parentId.ws.b1 - 2;
|
|
||||||
}
|
|
||||||
else if (VM_SINGLE_TAGGED(vlanMask))
|
|
||||||
{
|
|
||||||
switch (parentId.ws.b1)
|
|
||||||
{
|
|
||||||
case 2: row = 0; break; // L2
|
|
||||||
case 0x88:
|
|
||||||
case 0x81: row = 1; break; // SVlan/CVlan
|
|
||||||
case 3: row = 2; break; // L3
|
|
||||||
case 4: row = 3; break; // L4
|
|
||||||
case 0: row = 4; break; // Data
|
|
||||||
default: qWarning("%s: Unexpected b1 (%d)", __FUNCTION__, parentId.ws.b1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (VM_DOUBLE_TAGGED(vlanMask))
|
|
||||||
{
|
|
||||||
switch (parentId.ws.b1)
|
|
||||||
{
|
|
||||||
case 2: row = 0; break; // L2
|
|
||||||
case 0x88: row = 1; break; // Svlan
|
|
||||||
case 0x81: row = 2; break; // CVlan
|
|
||||||
case 3: row = 3; break; // L3
|
|
||||||
case 4: row = 4; break; // L4
|
|
||||||
case 0: row = 5; break; // Data
|
|
||||||
default: qWarning("%s: Unexpected b1 (%d)", __FUNCTION__, parentId.ws.b1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
qWarning("%s: Unhandled leg", __FUNCTION__);
|
|
||||||
|
|
||||||
return createIndex(row, 0, parentId.w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Third Level Item - Subfield
|
_exit:
|
||||||
// Requested Parent => 2nd Level Item (Field)
|
return parentIndex;
|
||||||
// TODO(Med)
|
|
||||||
qWarning("%s: Unexpected leg", __FUNCTION__);
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant PacketModel::data(const QModelIndex &index, int role) const
|
QVariant PacketModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
IndexId id;
|
IndexId id;
|
||||||
|
ProtocolInfo proto;
|
||||||
|
|
||||||
|
if (!index.isValid())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
if (role != Qt::DisplayRole)
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
id.w = index.internalId();
|
id.w = index.internalId();
|
||||||
|
foreach(proto, mProtocols)
|
||||||
|
{
|
||||||
|
if (proto.handle == id.ws.protocol)
|
||||||
|
goto _found;
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
if (id.ws.b2 == 0xFF)
|
_found:
|
||||||
return QString("Protocol Header");
|
switch(id.ws.type)
|
||||||
else
|
{
|
||||||
return QString("Field: Value");
|
case ITYP_PROTOCOL:
|
||||||
|
return proto.name;
|
||||||
|
|
||||||
|
case ITYP_FIELD:
|
||||||
|
return proto.fieldList.at(id.ws.field).name;
|
||||||
|
|
||||||
|
case ITYP_SUBFIELD:
|
||||||
|
return QVariant(); // TODO(MED): Till subfield support is added
|
||||||
|
|
||||||
|
default:
|
||||||
|
qWarning("%s: Unhandled ItemType", __FUNCTION__);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** --------------- Private Stuff -----------------
|
** --------------- Private Stuff -----------------
|
||||||
*/
|
*/
|
||||||
typedef union
|
void PacketModel::populatePacketProtocols()
|
||||||
{
|
{
|
||||||
quint32 w;
|
int proto;
|
||||||
struct
|
|
||||||
{
|
|
||||||
quint8 b1;
|
|
||||||
quint8 b2;
|
|
||||||
quint8 b3;
|
|
||||||
quint8 b4;
|
|
||||||
} ws;
|
|
||||||
} IndexId;
|
|
||||||
|
|
||||||
bool PacketModel::isIndexContainer(const QModelIndex& index, int level) const
|
// Clear the protocols list
|
||||||
{
|
mPacketProtocols.clear();
|
||||||
IndexId id;
|
|
||||||
|
|
||||||
id.w = index.internalId();
|
// Check and populate L2 Protocol
|
||||||
if ((id.ws.b1 == level) && (id.ws.b2 == 0xFF))
|
switch(mpStream->proto.ft)
|
||||||
return true;
|
{
|
||||||
else
|
case Stream::e_ft_none:
|
||||||
return false;
|
proto = PTYP_L2_NONE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Stream::e_ft_eth_2:
|
||||||
|
proto = PTYP_L2_ETH_2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Stream::e_ft_802_3_raw:
|
||||||
|
proto = PTYP_L2_802_3_RAW;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Stream::e_ft_802_3_llc:
|
||||||
|
proto = PTYP_L2_802_3_LLC;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Stream::e_ft_snap:
|
||||||
|
proto = PTYP_L2_SNAP;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
qDebug("%s: Unsupported frametype", __FUNCTION__);
|
||||||
|
proto = PTYP_INVALID;
|
||||||
|
}
|
||||||
|
mPacketProtocols.append(proto);
|
||||||
|
|
||||||
|
// Check and populate VLANs, if present
|
||||||
|
if (mpStream->l2.eth.vlanMask & VM_SVLAN_TAGGED)
|
||||||
|
mPacketProtocols.append(PTYP_SVLAN);
|
||||||
|
|
||||||
|
if (mpStream->l2.eth.vlanMask & VM_CVLAN_TAGGED)
|
||||||
|
mPacketProtocols.append(PTYP_CVLAN);
|
||||||
|
|
||||||
|
// Check and populate L3 protocols
|
||||||
|
if (mpStream->proto.protoMask & PM_L3_PROTO_NONE)
|
||||||
|
goto _data;
|
||||||
|
|
||||||
|
switch(mpStream->proto.etherType)
|
||||||
|
{
|
||||||
|
case ETH_TYP_IP:
|
||||||
|
proto = PTYP_L3_IP;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ETH_TYP_ARP:
|
||||||
|
proto = PTYP_L3_ARP;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
qDebug("%s: Unsupported ethtype", __FUNCTION__);
|
||||||
|
proto = PTYP_INVALID;
|
||||||
|
}
|
||||||
|
mPacketProtocols.append(proto);
|
||||||
|
|
||||||
|
if (mpStream->proto.protoMask & PM_L4_PROTO_NONE)
|
||||||
|
goto _data;
|
||||||
|
|
||||||
|
switch(mpStream->proto.ipProto)
|
||||||
|
{
|
||||||
|
case IP_PROTO_TCP:
|
||||||
|
proto = PTYP_L4_TCP;
|
||||||
|
break;
|
||||||
|
case IP_PROTO_UDP:
|
||||||
|
proto = PTYP_L4_UDP;
|
||||||
|
break;
|
||||||
|
case IP_PROTO_ICMP:
|
||||||
|
proto = PTYP_L4_ICMP;
|
||||||
|
break;
|
||||||
|
case IP_PROTO_IGMP:
|
||||||
|
proto = PTYP_L4_IGMP;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qDebug("%s: Unsupported ipProto", __FUNCTION__);
|
||||||
|
proto = PTYP_INVALID;
|
||||||
|
};
|
||||||
|
mPacketProtocols.append(proto);
|
||||||
|
|
||||||
|
_data:
|
||||||
|
mPacketProtocols.append(PTYP_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexL2Container(const QModelIndex& index) const
|
int PacketModel::fieldCount(uint protocol) const
|
||||||
{
|
{
|
||||||
return isIndexContainer(index, 2);
|
ProtocolInfo proto;
|
||||||
|
|
||||||
|
foreach(proto, mProtocols)
|
||||||
|
{
|
||||||
|
if (proto.handle == protocol)
|
||||||
|
{
|
||||||
|
qDebug("proto=%d, name=%s",protocol,proto.name.toAscii().data());
|
||||||
|
qDebug("fieldcount = %d", proto.fieldList.size());
|
||||||
|
return proto.fieldList.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexSvlanContainer(const QModelIndex& index) const
|
return 0;
|
||||||
{
|
|
||||||
return isIndexContainer(index, 0x88);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexCvlanContainer(const QModelIndex& index) const
|
int PacketModel::subfieldCount(uint protocol, int field) const
|
||||||
{
|
{
|
||||||
return isIndexContainer(index, 0x81);
|
// TODO(MED): Till subfield support is added
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexL3Container(const QModelIndex& index) const
|
/*
|
||||||
|
** ------------- Registration Functions ---------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
void PacketModel::registerProto(uint handle, char *name, char *abbr)
|
||||||
{
|
{
|
||||||
return isIndexContainer(index, 3);
|
ProtocolInfo proto;
|
||||||
|
|
||||||
|
proto.handle = handle;
|
||||||
|
proto.name = QString(name);
|
||||||
|
proto.abbr = QString(abbr);
|
||||||
|
mProtocols.append(proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexL4Container(const QModelIndex& index) const
|
void PacketModel::registerField(uint protoHandle, char *name, char *abbr)
|
||||||
{
|
{
|
||||||
return isIndexContainer(index, 4);
|
for (int i = 0; i < mProtocols.size(); i++)
|
||||||
|
{
|
||||||
|
if (mProtocols.at(i).handle == protoHandle)
|
||||||
|
{
|
||||||
|
FieldInfo field;
|
||||||
|
|
||||||
|
field.name = QString(name);
|
||||||
|
field.abbr = QString(abbr);
|
||||||
|
mProtocols[i].fieldList.append(field);
|
||||||
|
qDebug("proto = %d, name = %s", protoHandle, name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexField(const QModelIndex& index, int level) const
|
void PacketModel::registerFrameTypeProto()
|
||||||
{
|
{
|
||||||
IndexId id;
|
registerProto(PTYP_L2_NONE, "None", "");
|
||||||
|
registerField(PTYP_L2_NONE, "Destination Mac", "dstMac");
|
||||||
|
registerField(PTYP_L2_NONE, "Source Mac", "srcMac");
|
||||||
|
|
||||||
|
registerProto(PTYP_L2_ETH_2, "Ethernet II", "eth");
|
||||||
|
registerField(PTYP_L2_ETH_2, "Destination Mac", "dstMac");
|
||||||
|
registerField(PTYP_L2_ETH_2, "Source Mac", "srcMac");
|
||||||
|
registerField(PTYP_L2_ETH_2, "Ethernet Type", "type");
|
||||||
|
|
||||||
|
registerProto(PTYP_L2_802_3_RAW, "IEEE 802.3 Raw", "dot3raw");
|
||||||
|
registerField(PTYP_L2_802_3_RAW, "Destination Mac", "dstMac");
|
||||||
|
registerField(PTYP_L2_802_3_RAW, "Source Mac", "srcMac");
|
||||||
|
registerField(PTYP_L2_802_3_RAW, "Length", "len");
|
||||||
|
|
||||||
|
registerProto(PTYP_L2_802_3_LLC, "802.3 LLC", "dot3llc");
|
||||||
|
registerField(PTYP_L2_802_3_LLC, "Destination Mac", "dstMac");
|
||||||
|
registerField(PTYP_L2_802_3_LLC, "Source Mac", "srcMac");
|
||||||
|
registerField(PTYP_L2_802_3_LLC, "Destination Service Acces Point", "dsap");
|
||||||
|
registerField(PTYP_L2_802_3_LLC, "Source Service Acces Point", "ssap");
|
||||||
|
registerField(PTYP_L2_802_3_LLC, "Control", "ctl");
|
||||||
|
|
||||||
|
registerProto(PTYP_L2_SNAP, "802.3 LLC SNAP", "dot3snap");
|
||||||
|
registerField(PTYP_L2_SNAP, "Destination Mac", "dstMac");
|
||||||
|
registerField(PTYP_L2_SNAP, "Source Mac", "srcMac");
|
||||||
|
registerField(PTYP_L2_SNAP, "Destination Service Acces Point", "dsap");
|
||||||
|
registerField(PTYP_L2_SNAP, "Source Service Access Point", "ssap");
|
||||||
|
registerField(PTYP_L2_SNAP, "Control", "ctl");
|
||||||
|
registerField(PTYP_L2_SNAP, "Organisationally Unique Identifier", "oui");
|
||||||
|
registerField(PTYP_L2_SNAP, "Type", "type");
|
||||||
|
|
||||||
id.w = index.internalId();
|
|
||||||
if ((id.ws.b1 == level) && (id.ws.b2 != 0xFF) && (id.ws.b3 == 0xFF))
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexL2Field(const QModelIndex& index) const
|
void PacketModel::registerVlanProto()
|
||||||
{
|
{
|
||||||
return isIndexField(index, 2);
|
registerProto(PTYP_SVLAN, "IEEE 802.1ad Service VLAN", "SVLAN");
|
||||||
|
|
||||||
|
registerField(PTYP_SVLAN, "Tag Protocol Identifier", "tpid");
|
||||||
|
registerField(PTYP_SVLAN, "Priority Code Point", "pcp");
|
||||||
|
registerField(PTYP_SVLAN, "Drop Eligible", "de");
|
||||||
|
registerField(PTYP_SVLAN, "VLAN Identifier", "vlan");
|
||||||
|
|
||||||
|
registerProto(PTYP_CVLAN, "IEEE 802.1Q VLAN/CVLAN", "VLAN");
|
||||||
|
|
||||||
|
registerField(PTYP_CVLAN, "Tag Protocol Identifier", "tpid");
|
||||||
|
registerField(PTYP_CVLAN, "Priority", "prio");
|
||||||
|
registerField(PTYP_CVLAN, "Canonical Format Indicator", "cfi");
|
||||||
|
registerField(PTYP_CVLAN, "VLAN Identifier", "vlan");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexL3Field(const QModelIndex& index) const
|
void PacketModel::registerIpProto()
|
||||||
{
|
{
|
||||||
return isIndexField(index, 3);
|
registerProto(PTYP_L3_IP, "Internet Protocol version 4", "IPv4");
|
||||||
|
|
||||||
|
registerField(PTYP_L3_IP, "Version", "ver");
|
||||||
|
registerField(PTYP_L3_IP, "Header Length", "hdrlen");
|
||||||
|
registerField(PTYP_L3_IP, "Type of Service/DiffServ Code Point", "tos");
|
||||||
|
registerField(PTYP_L3_IP, "Total Length", "len");
|
||||||
|
registerField(PTYP_L3_IP, "Identification", "id");
|
||||||
|
registerField(PTYP_L3_IP, "Flags", "flags");
|
||||||
|
registerField(PTYP_L3_IP, "Fragment Offset", "fragofs");
|
||||||
|
registerField(PTYP_L3_IP, "Time to Live", "ttl");
|
||||||
|
registerField(PTYP_L3_IP, "Protocol Id", "proto");
|
||||||
|
registerField(PTYP_L3_IP, "Checksum", "cksum");
|
||||||
|
registerField(PTYP_L3_IP, "Source IP", "srcip");
|
||||||
|
registerField(PTYP_L3_IP, "Destination IP", "dstip");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexL4Field(const QModelIndex& index) const
|
void PacketModel::registerArpProto()
|
||||||
{
|
{
|
||||||
return isIndexField(index, 4);
|
// TODO (LOW)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexIpField(const QModelIndex& index) const
|
void PacketModel::registerTcpProto()
|
||||||
{
|
{
|
||||||
IndexId id;
|
registerProto(PTYP_L4_TCP, "Transmission Control Protocol", "TCP");
|
||||||
|
|
||||||
id.w = index.internalId();
|
registerField(PTYP_L4_TCP, "Source Port", "srcport");
|
||||||
if ((id.ws.b1 == 3) && (id.ws.b2 == 1) && (id.ws.b3 == 0xFF))
|
registerField(PTYP_L4_TCP, "Destination Port", "dstport");
|
||||||
return true;
|
registerField(PTYP_L4_TCP, "Sequence Number", "seqnum");
|
||||||
else
|
registerField(PTYP_L4_TCP, "Acknowledgement Number", "acknum");
|
||||||
return false;
|
registerField(PTYP_L4_TCP, "Header Length", "hdrlen");
|
||||||
|
registerField(PTYP_L4_TCP, "Reserved", "rsvd");
|
||||||
|
registerField(PTYP_L4_TCP, "Flags", "flags");
|
||||||
|
registerField(PTYP_L4_TCP, "Window", "win");
|
||||||
|
registerField(PTYP_L4_TCP, "Checksum", "cksum");
|
||||||
|
registerField(PTYP_L4_TCP, "Urgent Pointer", "urgptr");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexArpField(const QModelIndex& index) const
|
void PacketModel::registerUdpProto()
|
||||||
{
|
{
|
||||||
IndexId id;
|
registerProto(PTYP_L4_UDP, "User Datagram Protocol", "UDP");
|
||||||
|
|
||||||
id.w = index.internalId();
|
registerField(PTYP_L4_UDP, "Source Port", "srcport");
|
||||||
if ((id.ws.b1 == 3) && (id.ws.b2 == 2) && (id.ws.b3 == 0xFF))
|
registerField(PTYP_L4_UDP, "Destination Port", "dstport");
|
||||||
return true;
|
registerField(PTYP_L4_UDP, "Length", "len");
|
||||||
else
|
registerField(PTYP_L4_UDP, "Checksum", "cksum");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexL4ProtoField(const QModelIndex& index, int proto) const
|
void PacketModel::registerIcmpProto()
|
||||||
{
|
{
|
||||||
IndexId id;
|
// TODO (LOW)
|
||||||
|
|
||||||
id.w = index.internalId();
|
|
||||||
if ((id.ws.b1 == 4) && (id.ws.b2 == proto) && (id.ws.b3 == 0xFF))
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexTcpField(const QModelIndex& index) const
|
void PacketModel::registerIgmpProto()
|
||||||
{
|
{
|
||||||
return isIndexL4ProtoField(index, IP_PROTO_TCP);
|
// TODO (LOW)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexUdpField(const QModelIndex& index) const
|
void PacketModel::registerInvalidProto()
|
||||||
{
|
{
|
||||||
return isIndexL4ProtoField(index, IP_PROTO_UDP);
|
registerProto(PTYP_INVALID, "Invalid Protocol (bug in code)", "invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexIcmpField(const QModelIndex& index) const
|
void PacketModel::registerData()
|
||||||
{
|
{
|
||||||
return isIndexL4ProtoField(index, IP_PROTO_ICMP);
|
registerProto(PTYP_DATA, "Data", "data");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketModel::isIndexIgmpField(const QModelIndex& index) const
|
|
||||||
{
|
|
||||||
return isIndexL4ProtoField(index, IP_PROTO_IGMP);
|
|
||||||
}
|
|
||||||
|
@ -13,40 +13,84 @@ public:
|
|||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation,
|
||||||
|
int role = Qt::DisplayRole) const { return QVariant(); } ;
|
||||||
QModelIndex index (int row, int col, const QModelIndex & parent = QModelIndex() ) const;
|
QModelIndex index (int row, int col, const QModelIndex & parent = QModelIndex() ) const;
|
||||||
QModelIndex parent(const QModelIndex &index) const;
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Stream *mpStream;
|
|
||||||
typedef union _IndexId
|
typedef union _IndexId
|
||||||
{
|
{
|
||||||
quint32 w;
|
quint32 w;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
quint8 b1; // 1st Level
|
quint8 type;
|
||||||
quint8 b2; // 2nd Level
|
#define ITYP_PROTOCOL 1
|
||||||
quint8 b3; // 3rd Level
|
#define ITYP_FIELD 2
|
||||||
quint8 b4; // Reserved
|
#define ITYP_SUBFIELD 3
|
||||||
|
quint8 protocol;
|
||||||
|
quint8 field;
|
||||||
|
quint8 subfield;
|
||||||
} ws;
|
} ws;
|
||||||
} IndexId;
|
} IndexId;
|
||||||
|
|
||||||
bool PacketModel::isIndexContainer(const QModelIndex& index, int level) const;
|
typedef struct
|
||||||
bool PacketModel::isIndexL2Container(const QModelIndex& index) const;
|
{
|
||||||
bool PacketModel::isIndexSvlanContainer(const QModelIndex& index) const;
|
QString name;
|
||||||
bool PacketModel::isIndexCvlanContainer(const QModelIndex& index) const;
|
QString abbr;
|
||||||
bool PacketModel::isIndexL3Container(const QModelIndex& index) const;
|
} FieldInfo;
|
||||||
bool PacketModel::isIndexL4Container(const QModelIndex& index) const;
|
|
||||||
bool PacketModel::isIndexField(const QModelIndex& index, int level) const;
|
typedef struct
|
||||||
bool PacketModel::isIndexL2Field(const QModelIndex& index) const;
|
{
|
||||||
bool PacketModel::isIndexL3Field(const QModelIndex& index) const;
|
uint handle;
|
||||||
bool PacketModel::isIndexL4Field(const QModelIndex& index) const;
|
QString name;
|
||||||
bool PacketModel::isIndexIpField(const QModelIndex& index) const;
|
QString abbr;
|
||||||
bool PacketModel::isIndexArpField(const QModelIndex& index) const;
|
QList<FieldInfo> fieldList;
|
||||||
bool PacketModel::isIndexL4ProtoField(const QModelIndex& index, int proto) const;
|
} ProtocolInfo;
|
||||||
bool PacketModel::isIndexTcpField(const QModelIndex& index) const;
|
|
||||||
bool PacketModel::isIndexUdpField(const QModelIndex& index) const;
|
Stream *mpStream;
|
||||||
bool PacketModel::isIndexIcmpField(const QModelIndex& index) const;
|
QList<uint> mPacketProtocols;
|
||||||
bool PacketModel::isIndexIgmpField(const QModelIndex& index) const;
|
QList<ProtocolInfo> mProtocols;
|
||||||
|
|
||||||
|
void registerProto(uint handle, char *name, char *abbr);
|
||||||
|
void registerField(uint protoHandle, char *name, char *abbr);
|
||||||
|
|
||||||
|
void registerFrameTypeProto();
|
||||||
|
void registerVlanProto();
|
||||||
|
void registerIpProto();
|
||||||
|
void registerArpProto();
|
||||||
|
void registerTcpProto();
|
||||||
|
void registerUdpProto();
|
||||||
|
void registerIcmpProto();
|
||||||
|
void registerIgmpProto();
|
||||||
|
void registerData();
|
||||||
|
void registerInvalidProto();
|
||||||
|
|
||||||
|
void populatePacketProtocols();
|
||||||
|
int fieldCount(uint protocol) const;
|
||||||
|
int subfieldCount(uint protocol, int field) const;
|
||||||
|
|
||||||
|
// FIXME(HIGH): Is this how I want this?
|
||||||
|
#define PTYP_L2_NONE 1
|
||||||
|
#define PTYP_L2_ETH_2 2
|
||||||
|
#define PTYP_L2_802_3_RAW 3
|
||||||
|
#define PTYP_L2_802_3_LLC 4
|
||||||
|
#define PTYP_L2_SNAP 5
|
||||||
|
|
||||||
|
#define PTYP_SVLAN 10
|
||||||
|
#define PTYP_CVLAN 11
|
||||||
|
|
||||||
|
#define PTYP_L3_IP 30
|
||||||
|
#define PTYP_L3_ARP 31
|
||||||
|
|
||||||
|
#define PTYP_L4_TCP 40
|
||||||
|
#define PTYP_L4_UDP 41
|
||||||
|
#define PTYP_L4_ICMP 42
|
||||||
|
#define PTYP_L4_IGMP 43
|
||||||
|
|
||||||
|
#define PTYP_INVALID 0
|
||||||
|
#define PTYP_DATA 0xFF
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ void RxTx::ProcessMsg(const char* msg, int len)
|
|||||||
ProcessPortConfig(msg+sizeof(tCommHdr), len - sizeof(tCommHdr));
|
ProcessPortConfig(msg+sizeof(tCommHdr), len - sizeof(tCommHdr));
|
||||||
break;
|
break;
|
||||||
case e_MT_GetPortConfig:
|
case e_MT_GetPortConfig:
|
||||||
SendPortInfo();
|
SendPortInfo(0); // FIXME
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -300,9 +300,7 @@ _exit:
|
|||||||
|
|
||||||
void RxTx::SendPortInfo(unsigned int port)
|
void RxTx::SendPortInfo(unsigned int port)
|
||||||
{
|
{
|
||||||
// Assumption: port is valid
|
// FIXME
|
||||||
assert(port < numPorts);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user