2009-04-27 11:51:44 -05:00
|
|
|
#include <qendian.h>
|
|
|
|
#include <QHostAddress>
|
|
|
|
|
|
|
|
#include "snap.h"
|
|
|
|
|
|
|
|
SnapConfigForm::SnapConfigForm(QWidget *parent)
|
2009-12-28 02:31:28 -06:00
|
|
|
: QWidget(parent)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
setupUi(this);
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
SnapProtocol::SnapProtocol(StreamBase *stream, AbstractProtocol *parent)
|
2009-12-28 02:31:28 -06:00
|
|
|
: AbstractProtocol(stream, parent)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
configForm = NULL;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SnapProtocol::~SnapProtocol()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
delete configForm;
|
2009-08-02 09:52:34 -05:00
|
|
|
}
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
AbstractProtocol* SnapProtocol::createInstance(StreamBase *stream,
|
2009-12-28 02:31:28 -06:00
|
|
|
AbstractProtocol *parent)
|
2009-08-02 09:52:34 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return new SnapProtocol(stream, parent);
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
quint32 SnapProtocol::protocolNumber() const
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return OstProto::Protocol::kSnapFieldNumber;
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
void SnapProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
protocol.MutableExtension(OstProto::snap)->CopyFrom(data);
|
|
|
|
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
void SnapProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
if (protocol.protocol_id().id() == protocolNumber() &&
|
|
|
|
protocol.HasExtension(OstProto::snap))
|
|
|
|
data.MergeFrom(protocol.GetExtension(OstProto::snap));
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SnapProtocol::name() const
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return QString("SubNetwork Access Protocol");
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SnapProtocol::shortName() const
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return QString("SNAP");
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-11-13 10:00:57 -06:00
|
|
|
AbstractProtocol::ProtocolIdType SnapProtocol::protocolIdType() const
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return ProtocolIdEth;
|
2009-11-13 10:00:57 -06:00
|
|
|
}
|
|
|
|
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
quint32 SnapProtocol::protocolId(ProtocolIdType type) const
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case ProtocolIdLlc: return 0xAAAA03;
|
|
|
|
default: break;
|
|
|
|
}
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
return AbstractProtocol::protocolId(type);
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
}
|
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
int SnapProtocol::fieldCount() const
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return snap_fieldCount;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant SnapProtocol::fieldData(int index, FieldAttrib attrib,
|
2009-12-28 02:31:28 -06:00
|
|
|
int streamIndex) const
|
|
|
|
{
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case snap_oui:
|
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
|
|
|
return QString("OUI");
|
|
|
|
case FieldValue:
|
|
|
|
return data.oui();
|
|
|
|
case FieldTextValue:
|
|
|
|
return QString("%1").arg(data.oui(), 6, BASE_HEX, QChar('0'));
|
|
|
|
case FieldFrameValue:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
|
|
|
fv.resize(4);
|
|
|
|
qToBigEndian((quint32) data.oui(), (uchar*) fv.data());
|
|
|
|
fv.remove(0, 1);
|
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case snap_type:
|
|
|
|
{
|
|
|
|
quint16 type;
|
|
|
|
|
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
|
|
|
return QString("Type");
|
|
|
|
case FieldValue:
|
|
|
|
type = payloadProtocolId(ProtocolIdEth);
|
|
|
|
return type;
|
|
|
|
case FieldTextValue:
|
|
|
|
type = payloadProtocolId(ProtocolIdEth);
|
|
|
|
return QString("%1").arg(type, 4, BASE_HEX, QChar('0'));
|
|
|
|
case FieldFrameValue:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
|
|
|
fv.resize(2);
|
|
|
|
type = payloadProtocolId(ProtocolIdEth);
|
|
|
|
qToBigEndian(type, (uchar*) fv.data());
|
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AbstractProtocol::fieldData(index, attrib, streamIndex);
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2010-01-03 02:56:16 -06:00
|
|
|
bool SnapProtocol::setFieldData(int /*index*/, const QVariant &/*value*/,
|
|
|
|
FieldAttrib /*attrib*/)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return false;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget* SnapProtocol::configWidget()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
if (configForm == NULL)
|
|
|
|
{
|
|
|
|
configForm = new SnapConfigForm;
|
|
|
|
loadConfigWidget();
|
|
|
|
}
|
|
|
|
return configForm;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SnapProtocol::loadConfigWidget()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
configWidget();
|
2009-08-02 09:52:34 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
configForm->leOui->setText(uintToHexStr(
|
|
|
|
fieldData(snap_oui, FieldValue).toUInt(), 3));
|
|
|
|
configForm->leType->setText(uintToHexStr(
|
|
|
|
fieldData(snap_type, FieldValue).toUInt(), 2));
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SnapProtocol::storeConfigWidget()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
bool isOk;
|
2009-04-27 11:51:44 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
configWidget();
|
2009-08-02 09:52:34 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
data.set_oui(configForm->leOui->text().toULong(&isOk, BASE_HEX));
|
|
|
|
data.set_type(configForm->leType->text().toULong(&isOk, BASE_HEX));
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|