Following protocols now allow overriding of their type/length/protocolId fields - Ethernet II, 802.3, LLC, SNAP, IPv4. Since new fields have been added to the .proto files, the Ostinato native file format revision number has been bumped

Fixes Issue 20
This commit is contained in:
Srivats P. 2011-01-30 15:31:50 +05:30
parent 8d85fd30de
commit f140717f81
21 changed files with 732 additions and 118 deletions

View File

@ -17,17 +17,18 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#include <qendian.h>
#include <QHostAddress>
#include "dot3.h"
#include "streambase.h"
#include <QHostAddress>
#include <QIntValidator>
#include <qendian.h>
Dot3ConfigForm::Dot3ConfigForm(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
leLength->setValidator(new QIntValidator(0, 16384, this));
}
Dot3Protocol::Dot3Protocol(StreamBase *stream, AbstractProtocol *parent)
@ -80,6 +81,29 @@ int Dot3Protocol::fieldCount() const
return dot3_fieldCount;
}
AbstractProtocol::FieldFlags Dot3Protocol::fieldFlags(int index) const
{
AbstractProtocol::FieldFlags flags;
flags = AbstractProtocol::fieldFlags(index);
switch (index)
{
case dot3_length:
break;
case dot3_is_override_length:
flags &= ~FrameField;
flags |= MetaField;
break;
default:
break;
}
return flags;
}
QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
int streamIndex) const
{
@ -92,24 +116,23 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
return QString("Length");
case FieldValue:
{
quint16 len;
len = protocolFramePayloadSize(streamIndex);
quint16 len = data.is_override_length() ?
data.length() : protocolFramePayloadSize(streamIndex);
return len;
}
case FieldTextValue:
{
quint16 len;
quint16 len = data.is_override_length() ?
data.length() : protocolFramePayloadSize(streamIndex);
len = protocolFramePayloadSize(streamIndex);
return QString("%1").arg(len);
}
case FieldFrameValue:
{
quint16 len;
quint16 len = data.is_override_length() ?
data.length() : protocolFramePayloadSize(streamIndex);
QByteArray fv;
len = protocolFramePayloadSize(streamIndex);
fv.resize(2);
qToBigEndian(len, (uchar*) fv.data());
return fv;
@ -121,17 +144,58 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
}
break;
// Meta fields
case dot3_is_override_length:
{
switch(attrib)
{
case FieldValue:
return data.is_override_length();
default:
break;
}
break;
}
default:
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
index);
break;
}
return AbstractProtocol::fieldData(index, attrib, streamIndex);
}
bool Dot3Protocol::setFieldData(int /*index*/, const QVariant &/*value*/,
FieldAttrib /*attrib*/)
bool Dot3Protocol::setFieldData(int index, const QVariant &value,
FieldAttrib attrib)
{
return false;
bool isOk = false;
if (attrib != FieldValue)
return false;
switch (index)
{
case dot3_length:
{
uint len = value.toUInt(&isOk);
if (isOk)
data.set_length(len);
break;
}
case dot3_is_override_length:
{
bool ovr = value.toBool();
data.set_is_override_length(ovr);
isOk = true;
break;
}
default:
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
index);
break;
}
return isOk;
}
bool Dot3Protocol::isProtocolFrameValueVariable() const
@ -153,16 +217,18 @@ void Dot3Protocol::loadConfigWidget()
{
configWidget();
configForm->cbOverrideLength->setChecked(
fieldData(dot3_is_override_length, FieldValue).toBool());
configForm->leLength->setText(
fieldData(dot3_length, FieldValue).toString());
}
void Dot3Protocol::storeConfigWidget()
{
bool isOk;
configWidget();
data.set_length(configForm->leLength->text().toULong(&isOk));
setFieldData(dot3_is_override_length,
configForm->cbOverrideLength->isChecked());
setFieldData(dot3_length,configForm->leLength->text());
}

View File

@ -41,6 +41,9 @@ private:
{
dot3_length,
// Meta-fields
dot3_is_override_length,
dot3_fieldCount
};
@ -60,6 +63,7 @@ public:
virtual int fieldCount() const;
virtual AbstractProtocol::FieldFlags fieldFlags(int index) const;
virtual QVariant fieldData(int index, FieldAttrib attrib,
int streamIndex = 0) const;
virtual bool setFieldData(int index, const QVariant &value,

View File

@ -23,7 +23,8 @@ package OstProto;
// 802.3
message Dot3 {
optional uint32 length = 1;
optional bool is_override_length = 2;
optional uint32 length = 1;
}
extend Protocol {

View File

@ -5,28 +5,25 @@
<rect>
<x>0</x>
<y>0</y>
<width>131</width>
<height>72</height>
<width>181</width>
<height>98</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<layout class="QHBoxLayout" >
<item>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>802.3</string>
</property>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="lblLength" >
<widget class="QCheckBox" name="cbOverrideLength" >
<property name="text" >
<string>Length</string>
</property>
<property name="buddy" >
<cstring>leLength</cstring>
</property>
</widget>
</item>
<item>
@ -39,7 +36,7 @@
</layout>
</widget>
</item>
<item>
<item row="0" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
@ -52,8 +49,38 @@
</property>
</spacer>
</item>
<item row="1" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>cbOverrideLength</sender>
<signal>toggled(bool)</signal>
<receiver>leLength</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>55</x>
<y>39</y>
</hint>
<hint type="destinationlabel" >
<x>84</x>
<y>43</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -83,6 +83,29 @@ int Eth2Protocol::fieldCount() const
return eth2_fieldCount;
}
AbstractProtocol::FieldFlags Eth2Protocol::fieldFlags(int index) const
{
AbstractProtocol::FieldFlags flags;
flags = AbstractProtocol::fieldFlags(index);
switch (index)
{
case eth2_type:
break;
case eth2_is_override_type:
flags &= ~FrameField;
flags |= MetaField;
break;
default:
break;
}
return flags;
}
QVariant Eth2Protocol::fieldData(int index, FieldAttrib attrib,
int streamIndex) const
{
@ -90,21 +113,27 @@ QVariant Eth2Protocol::fieldData(int index, FieldAttrib attrib,
{
case eth2_type:
{
quint16 type;
switch(attrib)
{
case FieldName:
return QString("Type");
case FieldValue:
type = payloadProtocolId(ProtocolIdEth);
{
quint16 type = data.is_override_type() ?
data.type() : payloadProtocolId(ProtocolIdEth);
return type;
}
case FieldTextValue:
type = payloadProtocolId(ProtocolIdEth);
{
quint16 type = data.is_override_type() ?
data.type() : payloadProtocolId(ProtocolIdEth);
return QString("0x%1").arg(type, 4, BASE_HEX, QChar('0'));
}
case FieldFrameValue:
{
QByteArray fv;
type = payloadProtocolId(ProtocolIdEth);
quint16 type = data.is_override_type() ?
data.type() : payloadProtocolId(ProtocolIdEth);
fv.resize(2);
qToBigEndian((quint16) type, (uchar*) fv.data());
return fv;
@ -114,7 +143,23 @@ QVariant Eth2Protocol::fieldData(int index, FieldAttrib attrib,
}
break;
}
// Meta fields
case eth2_is_override_type:
{
switch(attrib)
{
case FieldValue:
return data.is_override_type();
default:
break;
}
break;
}
default:
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
index);
break;
}
@ -136,8 +181,18 @@ bool Eth2Protocol::setFieldData(int index, const QVariant &value,
uint type = value.toUInt(&isOk);
if (isOk)
data.set_type(type);
break;
}
case eth2_is_override_type:
{
bool ovr = value.toBool();
data.set_is_override_type(ovr);
isOk = true;
break;
}
default:
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
index);
break;
}
return isOk;
@ -157,6 +212,8 @@ void Eth2Protocol::loadConfigWidget()
{
configWidget();
configForm->cbOverrideType->setChecked(
fieldData(eth2_is_override_type, FieldValue).toBool());
configForm->leType->setText(uintToHexStr(
fieldData(eth2_type, FieldValue).toUInt(), 2));
}
@ -167,6 +224,8 @@ void Eth2Protocol::storeConfigWidget()
configWidget();
setFieldData(eth2_is_override_type,
configForm->cbOverrideType->isChecked());
data.set_type(configForm->leType->text().remove(QChar(' ')).toULong(&isOk, 16));
}

View File

@ -41,6 +41,8 @@ private:
{
eth2_type = 0,
eth2_is_override_type,
eth2_fieldCount
};
@ -60,8 +62,9 @@ public:
virtual ProtocolIdType protocolIdType() const;
virtual int fieldCount() const;
virtual int fieldCount() const;
virtual AbstractProtocol::FieldFlags fieldFlags(int index) const;
virtual QVariant fieldData(int index, FieldAttrib attrib,
int streamIndex = 0) const;
virtual bool setFieldData(int index, const QVariant &value,

View File

@ -23,7 +23,9 @@ package OstProto;
// Ethernet II
message Eth2 {
optional uint32 type = 1;
optional bool is_override_type = 2;
optional uint32 type = 1;
}
extend Protocol {

View File

@ -5,7 +5,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>267</width>
<width>190</width>
<height>64</height>
</rect>
</property>
@ -14,13 +14,10 @@
</property>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="lblType" >
<widget class="QCheckBox" name="cbOverrideType" >
<property name="text" >
<string>Ethernet Type</string>
</property>
<property name="buddy" >
<cstring>leType</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
@ -46,7 +43,7 @@
</property>
</spacer>
</item>
<item row="1" column="1" >
<item row="1" column="0" colspan="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
@ -62,5 +59,22 @@
</layout>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>cbOverrideType</sender>
<signal>toggled(bool)</signal>
<receiver>leType</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>98</x>
<y>27</y>
</hint>
<hint type="destinationlabel" >
<x>118</x>
<y>27</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -49,7 +49,7 @@ private:
// Native file format version
static const uint kFileFormatVersionMajor = 0;
static const uint kFileFormatVersionMinor = 1;
static const uint kFileFormatVersionRevision = 2;
static const uint kFileFormatVersionRevision = 3;
void initFileMetaData(OstProto::FileMetaData &metaData);
};

View File

@ -166,6 +166,7 @@ AbstractProtocol::FieldFlags Ip4Protocol::fieldFlags(int index) const
case ip4_isOverrideVer:
case ip4_isOverrideHdrLen:
case ip4_isOverrideTotLen:
case ip4_isOverrideProto:
case ip4_isOverrideCksum:
case ip4_srcAddrMode:
case ip4_srcAddrCount:
@ -381,17 +382,20 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
return QString("Protocol");
case FieldValue:
{
unsigned char id = payloadProtocolId(ProtocolIdIp);
unsigned char id = data.is_override_proto() ?
data.proto() : payloadProtocolId(ProtocolIdIp);
return id;
}
case FieldFrameValue:
{
unsigned char id = payloadProtocolId(ProtocolIdIp);
unsigned char id = data.is_override_proto() ?
data.proto() : payloadProtocolId(ProtocolIdIp);
return QByteArray(1, (char) id);
}
case FieldTextValue:
{
unsigned char id = payloadProtocolId(ProtocolIdIp);
unsigned char id = data.is_override_proto() ?
data.proto() : payloadProtocolId(ProtocolIdIp);
return QString("0x%1").
arg(id, 2, BASE_HEX, QChar('0'));
}
@ -559,6 +563,7 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
case ip4_isOverrideVer:
case ip4_isOverrideHdrLen:
case ip4_isOverrideTotLen:
case ip4_isOverrideProto:
case ip4_isOverrideCksum:
case ip4_srcAddrMode:
@ -669,6 +674,8 @@ void Ip4Protocol::loadConfigWidget()
configForm->cbIpFlagsMf->setChecked((data.flags() & IP_FLAG_MF) > 0);
configForm->leIpTtl->setText(QString().setNum(data.ttl()));
configForm->cbIpProtocolOverride->setChecked(data.is_override_proto());
configForm->leIpProto->setText(uintToHexStr(
fieldData(ip4_proto, FieldValue).toUInt(), 1));
@ -712,6 +719,8 @@ void Ip4Protocol::storeConfigWidget()
data.set_flags(ff);
data.set_ttl(configForm->leIpTtl->text().toULong(&isOk));
data.set_is_override_proto(configForm->cbIpProtocolOverride->isChecked());
data.set_proto(configForm->leIpProto->text().remove(QChar(' ')).toULong(&isOk, 16));
data.set_is_override_cksum(configForm->cbIpCksumOverride->isChecked());

View File

@ -64,6 +64,7 @@ private:
ip4_isOverrideVer,
ip4_isOverrideHdrLen,
ip4_isOverrideTotLen,
ip4_isOverrideProto,
ip4_isOverrideCksum,
ip4_srcAddrMode,

View File

@ -33,7 +33,8 @@ message Ip4 {
optional bool is_override_ver = 1;
optional bool is_override_hdrlen = 2;
optional bool is_override_totlen = 3;
optional bool is_override_cksum = 4;
optional bool is_override_proto = 30;
optional bool is_override_cksum = 4;
optional uint32 ver_hdrlen = 5 [default = 0x45];
optional uint32 tos = 6;

View File

@ -5,7 +5,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>493</width>
<width>507</width>
<height>308</height>
</rect>
</property>
@ -137,18 +137,14 @@ Length (x4)</string>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="label_27" >
<property name="text" >
<string>Protocol</string>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QLineEdit" name="leIpProto" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="inputMask" >
<string>>HH; </string>
</property>
<property name="text" >
<string/>
</property>
@ -171,6 +167,13 @@ Length (x4)</string>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QCheckBox" name="cbIpProtocolOverride" >
<property name="text" >
<string>Override Protocol</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" colspan="3" >
@ -399,6 +402,34 @@ Length (x4)</string>
</item>
</layout>
</widget>
<tabstops>
<tabstop>cbIpVersionOverride</tabstop>
<tabstop>leIpVersion</tabstop>
<tabstop>cbIpHdrLenOverride</tabstop>
<tabstop>leIpHdrLen</tabstop>
<tabstop>leIpTos</tabstop>
<tabstop>cbIpLengthOverride</tabstop>
<tabstop>leIpLength</tabstop>
<tabstop>leIpId</tabstop>
<tabstop>leIpFragOfs</tabstop>
<tabstop>cbIpFlagsDf</tabstop>
<tabstop>cbIpFlagsMf</tabstop>
<tabstop>leIpTtl</tabstop>
<tabstop>cbIpProtocolOverride</tabstop>
<tabstop>leIpProto</tabstop>
<tabstop>cbIpCksumOverride</tabstop>
<tabstop>leIpCksum</tabstop>
<tabstop>leIpSrcAddr</tabstop>
<tabstop>cmbIpSrcAddrMode</tabstop>
<tabstop>leIpSrcAddrCount</tabstop>
<tabstop>leIpSrcAddrMask</tabstop>
<tabstop>leIpDstAddr</tabstop>
<tabstop>cmbIpDstAddrMode</tabstop>
<tabstop>leIpDstAddrCount</tabstop>
<tabstop>leIpDstAddrMask</tabstop>
<tabstop>leIpOptions</tabstop>
<tabstop>tbIpOptionsEdit</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
@ -424,8 +455,8 @@ Length (x4)</string>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>118</x>
<y>43</y>
<x>113</x>
<y>67</y>
</hint>
<hint type="destinationlabel" >
<x>166</x>
@ -440,12 +471,12 @@ Length (x4)</string>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>79</x>
<y>97</y>
<x>89</x>
<y>118</y>
</hint>
<hint type="destinationlabel" >
<x>172</x>
<y>97</y>
<x>236</x>
<y>119</y>
</hint>
</hints>
</connection>
@ -456,8 +487,8 @@ Length (x4)</string>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>345</x>
<y>122</y>
<x>387</x>
<y>140</y>
</hint>
<hint type="destinationlabel" >
<x>406</x>
@ -465,5 +496,21 @@ Length (x4)</string>
</hint>
</hints>
</connection>
<connection>
<sender>cbIpProtocolOverride</sender>
<signal>toggled(bool)</signal>
<receiver>leIpProto</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>363</x>
<y>95</y>
</hint>
<hint type="destinationlabel" >
<x>398</x>
<y>94</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -83,6 +83,33 @@ int LlcProtocol::fieldCount() const
return llc_fieldCount;
}
AbstractProtocol::FieldFlags LlcProtocol::fieldFlags(int index) const
{
AbstractProtocol::FieldFlags flags;
flags = AbstractProtocol::fieldFlags(index);
switch (index)
{
case llc_dsap:
case llc_ssap:
case llc_ctl:
break;
case llc_is_override_dsap:
case llc_is_override_ssap:
case llc_is_override_ctl:
flags &= ~FrameField;
flags |= MetaField;
break;
default:
break;
}
return flags;
}
QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib,
int streamIndex) const
{
@ -90,9 +117,9 @@ QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib,
quint8 dsap, ssap, ctl;
id = payloadProtocolId(ProtocolIdLlc);
dsap = (id >> 16) & 0xFF;
ssap = (id >> 8) & 0xFF;
ctl = (id >> 0) & 0xFF;
dsap = data.is_override_dsap() ? data.dsap() : (id >> 16) & 0xFF;
ssap = data.is_override_ssap() ? data.ssap() : (id >> 8) & 0xFF;
ctl = data.is_override_ctl() ? data.ctl() : (id >> 0) & 0xFF;
switch (index)
{
@ -142,17 +169,109 @@ QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib,
}
break;
// Meta fields
case llc_is_override_dsap:
{
switch(attrib)
{
case FieldValue:
return data.is_override_dsap();
default:
break;
}
break;
}
case llc_is_override_ssap:
{
switch(attrib)
{
case FieldValue:
return data.is_override_ssap();
default:
break;
}
break;
}
case llc_is_override_ctl:
{
switch(attrib)
{
case FieldValue:
return data.is_override_ctl();
default:
break;
}
break;
}
default:
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
index);
break;
}
return AbstractProtocol::fieldData(index, attrib, streamIndex);
}
bool LlcProtocol::setFieldData(int /*index*/, const QVariant &/*value*/,
FieldAttrib /*attrib*/)
bool LlcProtocol::setFieldData(int index, const QVariant &value,
FieldAttrib attrib)
{
return false;
bool isOk = false;
if (attrib != FieldValue)
return false;
switch (index)
{
case llc_dsap:
{
uint dsap = value.toUInt(&isOk) & 0xFF;
if (isOk)
data.set_dsap(dsap);
break;
}
case llc_ssap:
{
uint ssap = value.toUInt(&isOk) & 0xFF;
if (isOk)
data.set_ssap(ssap);
break;
}
case llc_ctl:
{
uint ctl = value.toUInt(&isOk) & 0xFF;
if (isOk)
data.set_ctl(ctl);
break;
}
case llc_is_override_dsap:
{
bool ovr = value.toBool();
data.set_is_override_dsap(ovr);
isOk = true;
break;
}
case llc_is_override_ssap:
{
bool ovr = value.toBool();
data.set_is_override_ssap(ovr);
isOk = true;
break;
}
case llc_is_override_ctl:
{
bool ovr = value.toBool();
data.set_is_override_ctl(ovr);
isOk = true;
break;
}
default:
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
index);
break;
}
return isOk;
}
@ -173,10 +292,18 @@ void LlcProtocol::loadConfigWidget()
configWidget();
configForm->cbOverrideDsap->setChecked(
fieldData(llc_is_override_dsap, FieldValue).toBool());
configForm->leDsap->setText(uintToHexStr(
fieldData(llc_dsap, FieldValue).toUInt(), 1));
configForm->cbOverrideSsap->setChecked(
fieldData(llc_is_override_ssap, FieldValue).toBool());
configForm->leSsap->setText(uintToHexStr(
fieldData(llc_ssap, FieldValue).toUInt(), 1));
configForm->cbOverrideControl->setChecked(
fieldData(llc_is_override_ctl, FieldValue).toBool());
configForm->leControl->setText(uintToHexStr(
fieldData(llc_ctl, FieldValue).toUInt(), 1));
#undef uintToHexStr
@ -188,8 +315,17 @@ void LlcProtocol::storeConfigWidget()
configWidget();
data.set_dsap(configForm->leDsap->text().toULong(&isOk, BASE_HEX));
data.set_ssap(configForm->leSsap->text().toULong(&isOk, BASE_HEX));
data.set_ctl(configForm->leControl->text().toULong(&isOk, BASE_HEX));
setFieldData(llc_is_override_dsap,
configForm->cbOverrideDsap->isChecked());
setFieldData(llc_dsap, configForm->leDsap->text().toUInt(&isOk, BASE_HEX));
setFieldData(llc_is_override_ssap,
configForm->cbOverrideSsap->isChecked());
setFieldData(llc_ssap, configForm->leSsap->text().toUInt(&isOk, BASE_HEX));
setFieldData(llc_is_override_ctl,
configForm->cbOverrideControl->isChecked());
setFieldData(llc_ctl,
configForm->leControl->text().toUInt(&isOk, BASE_HEX));
}

View File

@ -46,6 +46,11 @@ private:
llc_ssap,
llc_ctl,
// Meta fields
llc_is_override_dsap,
llc_is_override_ssap,
llc_is_override_ctl,
llc_fieldCount
};
@ -65,8 +70,9 @@ public:
virtual ProtocolIdType protocolIdType() const;
virtual int fieldCount() const;
virtual int fieldCount() const;
virtual AbstractProtocol::FieldFlags fieldFlags(int index) const;
virtual QVariant fieldData(int index, FieldAttrib attrib,
int streamIndex = 0) const;
virtual bool setFieldData(int index, const QVariant &value,

View File

@ -22,9 +22,13 @@ import "protocol.proto";
package OstProto;
message Llc {
optional uint32 dsap = 1;
optional uint32 ssap = 2;
optional uint32 ctl = 3;
optional bool is_override_dsap = 4;
optional bool is_override_ssap = 5;
optional bool is_override_ctl = 6;
optional uint32 dsap = 1;
optional uint32 ssap = 2;
optional uint32 ctl = 3;
}
extend Protocol {

View File

@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>304</width>
<height>72</height>
<width>396</width>
<height>98</height>
</rect>
</property>
<property name="sizePolicy" >
@ -18,21 +18,18 @@
<property name="windowTitle" >
<string>Form</string>
</property>
<layout class="QHBoxLayout" >
<item>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>LLC</string>
</property>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="lblDsap" >
<widget class="QCheckBox" name="cbOverrideDsap" >
<property name="text" >
<string>DSAP</string>
</property>
<property name="buddy" >
<cstring>leDsap</cstring>
</property>
</widget>
</item>
<item>
@ -46,13 +43,10 @@
</widget>
</item>
<item>
<widget class="QLabel" name="lblSsap" >
<widget class="QCheckBox" name="cbOverrideSsap" >
<property name="text" >
<string>SSAP</string>
</property>
<property name="buddy" >
<cstring>leSsap</cstring>
</property>
</widget>
</item>
<item>
@ -66,13 +60,10 @@
</widget>
</item>
<item>
<widget class="QLabel" name="lblControl" >
<widget class="QCheckBox" name="cbOverrideControl" >
<property name="text" >
<string>Control</string>
</property>
<property name="buddy" >
<cstring>leControl</cstring>
</property>
</widget>
</item>
<item>
@ -88,21 +79,83 @@
</layout>
</widget>
</item>
<item>
<item row="0" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>cbOverrideDsap</sender>
<signal>toggled(bool)</signal>
<receiver>leDsap</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>54</x>
<y>34</y>
</hint>
<hint type="destinationlabel" >
<x>92</x>
<y>33</y>
</hint>
</hints>
</connection>
<connection>
<sender>cbOverrideSsap</sender>
<signal>toggled(bool)</signal>
<receiver>leSsap</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>167</x>
<y>34</y>
</hint>
<hint type="destinationlabel" >
<x>192</x>
<y>33</y>
</hint>
</hints>
</connection>
<connection>
<sender>cbOverrideControl</sender>
<signal>toggled(bool)</signal>
<receiver>leControl</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>285</x>
<y>34</y>
</hint>
<hint type="destinationlabel" >
<x>310</x>
<y>33</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -22,6 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "snap.h"
quint32 kStdOui = 0x000000;
SnapConfigForm::SnapConfigForm(QWidget *parent)
: QWidget(parent)
{
@ -89,11 +91,36 @@ quint32 SnapProtocol::protocolId(ProtocolIdType type) const
return AbstractProtocol::protocolId(type);
}
int SnapProtocol::fieldCount() const
int SnapProtocol::fieldCount() const
{
return snap_fieldCount;
}
AbstractProtocol::FieldFlags SnapProtocol::fieldFlags(int index) const
{
AbstractProtocol::FieldFlags flags;
flags = AbstractProtocol::fieldFlags(index);
switch (index)
{
case snap_oui:
case snap_type:
break;
case snap_is_override_oui:
case snap_is_override_type:
flags &= ~FrameField;
flags |= MetaField;
break;
default:
break;
}
return flags;
}
QVariant SnapProtocol::fieldData(int index, FieldAttrib attrib,
int streamIndex) const
{
@ -105,14 +132,21 @@ QVariant SnapProtocol::fieldData(int index, FieldAttrib attrib,
case FieldName:
return QString("OUI");
case FieldValue:
return data.oui();
{
quint32 oui = data.is_override_oui() ? data.oui() : kStdOui;
return oui;
}
case FieldTextValue:
return QString("%1").arg(data.oui(), 6, BASE_HEX, QChar('0'));
{
quint32 oui = data.is_override_oui() ? data.oui() : kStdOui;
return QString("%1").arg(oui, 6, BASE_HEX, QChar('0'));
}
case FieldFrameValue:
{
quint32 oui = data.is_override_oui() ? data.oui() : kStdOui;
QByteArray fv;
fv.resize(4);
qToBigEndian((quint32) data.oui(), (uchar*) fv.data());
qToBigEndian(oui, (uchar*) fv.data());
fv.remove(0, 1);
return fv;
}
@ -129,16 +163,19 @@ QVariant SnapProtocol::fieldData(int index, FieldAttrib attrib,
case FieldName:
return QString("Type");
case FieldValue:
type = payloadProtocolId(ProtocolIdEth);
type = data.is_override_type() ?
data.type() : payloadProtocolId(ProtocolIdEth);
return type;
case FieldTextValue:
type = payloadProtocolId(ProtocolIdEth);
type = data.is_override_type() ?
data.type() : payloadProtocolId(ProtocolIdEth);
return QString("%1").arg(type, 4, BASE_HEX, QChar('0'));
case FieldFrameValue:
{
QByteArray fv;
fv.resize(2);
type = payloadProtocolId(ProtocolIdEth);
type = data.is_override_type() ?
data.type() : payloadProtocolId(ProtocolIdEth);
qToBigEndian(type, (uchar*) fv.data());
return fv;
}
@ -147,19 +184,86 @@ QVariant SnapProtocol::fieldData(int index, FieldAttrib attrib,
}
break;
}
// Meta fields
case snap_is_override_oui:
{
switch(attrib)
{
case FieldValue:
return data.is_override_oui();
default:
break;
}
break;
}
case snap_is_override_type:
{
switch(attrib)
{
case FieldValue:
return data.is_override_type();
default:
break;
}
break;
}
default:
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
index);
break;
}
return AbstractProtocol::fieldData(index, attrib, streamIndex);
}
bool SnapProtocol::setFieldData(int /*index*/, const QVariant &/*value*/,
FieldAttrib /*attrib*/)
bool SnapProtocol::setFieldData(int index, const QVariant &value,
FieldAttrib attrib)
{
return false;
}
bool isOk = false;
if (attrib != FieldValue)
return false;
switch (index)
{
case snap_oui:
{
uint oui = value.toUInt(&isOk);
if (isOk)
data.set_oui(oui);
break;
}
case snap_type:
{
uint type = value.toUInt(&isOk);
if (isOk)
data.set_type(type);
break;
}
case snap_is_override_oui:
{
bool ovr = value.toBool();
data.set_is_override_oui(ovr);
isOk = true;
break;
}
case snap_is_override_type:
{
bool ovr = value.toBool();
data.set_is_override_type(ovr);
isOk = true;
break;
}
default:
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
index);
break;
}
return isOk;
}
QWidget* SnapProtocol::configWidget()
{
@ -175,8 +279,13 @@ void SnapProtocol::loadConfigWidget()
{
configWidget();
configForm->cbOverrideOui->setChecked(
fieldData(snap_is_override_oui, FieldValue).toBool());
configForm->leOui->setText(uintToHexStr(
fieldData(snap_oui, FieldValue).toUInt(), 3));
configForm->cbOverrideType->setChecked(
fieldData(snap_is_override_type, FieldValue).toBool());
configForm->leType->setText(uintToHexStr(
fieldData(snap_type, FieldValue).toUInt(), 2));
}
@ -184,10 +293,15 @@ void SnapProtocol::loadConfigWidget()
void SnapProtocol::storeConfigWidget()
{
bool isOk;
configWidget();
data.set_oui(configForm->leOui->text().toULong(&isOk, BASE_HEX));
data.set_type(configForm->leType->text().toULong(&isOk, BASE_HEX));
}
setFieldData(snap_is_override_oui,
configForm->cbOverrideOui->isChecked());
setFieldData(snap_oui, configForm->leOui->text().remove(QChar(' '))
.toUInt(&isOk, BASE_HEX));
setFieldData(snap_is_override_type,
configForm->cbOverrideType->isChecked());
setFieldData(snap_type, configForm->leType->text().remove(QChar(' '))
.toUInt(&isOk, BASE_HEX));
}

View File

@ -42,6 +42,10 @@ private:
snap_oui = 0,
snap_type,
// Meta fields
snap_is_override_oui,
snap_is_override_type,
snap_fieldCount
};
@ -62,8 +66,9 @@ public:
virtual ProtocolIdType protocolIdType() const;
virtual quint32 protocolId(ProtocolIdType type) const;
virtual int fieldCount() const;
virtual int fieldCount() const;
virtual AbstractProtocol::FieldFlags fieldFlags(int index) const;
virtual QVariant fieldData(int index, FieldAttrib attrib,
int streamIndex = 0) const;
virtual bool setFieldData(int index, const QVariant &value,

View File

@ -22,8 +22,11 @@ import "protocol.proto";
package OstProto;
message Snap {
optional uint32 oui = 1;
optional uint32 type = 2;
optional bool is_override_oui = 3;
optional bool is_override_type = 4;
optional uint32 oui = 1;
optional uint32 type = 2;
}
extend Protocol {

View File

@ -5,22 +5,22 @@
<rect>
<x>0</x>
<y>0</y>
<width>194</width>
<height>72</height>
<width>268</width>
<height>98</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<layout class="QHBoxLayout" >
<item>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>SNAP</string>
</property>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="lblOui" >
<widget class="QCheckBox" name="cbOverrideOui" >
<property name="text" >
<string>OUI</string>
</property>
@ -37,7 +37,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="lblType" >
<widget class="QCheckBox" name="cbOverrideType" >
<property name="text" >
<string>Type</string>
</property>
@ -56,8 +56,67 @@
</layout>
</widget>
</item>
<item row="0" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>cbOverrideOui</sender>
<signal>toggled(bool)</signal>
<receiver>leOui</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>49</x>
<y>42</y>
</hint>
<hint type="destinationlabel" >
<x>68</x>
<y>43</y>
</hint>
</hints>
</connection>
<connection>
<sender>cbOverrideType</sender>
<signal>toggled(bool)</signal>
<receiver>leType</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>161</x>
<y>34</y>
</hint>
<hint type="destinationlabel" >
<x>183</x>
<y>33</y>
</hint>
</hints>
</connection>
</connections>
</ui>