2009-04-27 11:51:44 -05:00
|
|
|
#include <qendian.h>
|
|
|
|
#include <QHostAddress>
|
|
|
|
|
|
|
|
#include "eth2.h"
|
|
|
|
|
|
|
|
Eth2ConfigForm::Eth2ConfigForm(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
Eth2Protocol::Eth2Protocol(StreamBase *stream)
|
|
|
|
: AbstractProtocol(stream)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
configForm = NULL;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Eth2Protocol::~Eth2Protocol()
|
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
delete configForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProtocol* Eth2Protocol::createInstance(StreamBase *stream)
|
|
|
|
{
|
|
|
|
return new Eth2Protocol(stream);
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
quint32 Eth2Protocol::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-08-02 09:52:34 -05:00
|
|
|
return OstProto::Protocol::kEth2FieldNumber;
|
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 Eth2Protocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
protocol.MutableExtension(OstProto::eth2)->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 Eth2Protocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
if (protocol.protocol_id().id() == protocolNumber() &&
|
|
|
|
protocol.HasExtension(OstProto::eth2))
|
|
|
|
data.MergeFrom(protocol.GetExtension(OstProto::eth2));
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Eth2Protocol::name() const
|
|
|
|
{
|
|
|
|
return QString("Ethernet II");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Eth2Protocol::shortName() const
|
|
|
|
{
|
|
|
|
return QString("Eth II");
|
|
|
|
}
|
|
|
|
|
|
|
|
int Eth2Protocol::fieldCount() const
|
|
|
|
{
|
|
|
|
return eth2_fieldCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Eth2Protocol::fieldData(int index, FieldAttrib attrib,
|
|
|
|
int streamIndex) const
|
|
|
|
{
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case eth2_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
|
|
|
{
|
|
|
|
quint16 type;
|
2009-04-27 11:51:44 -05:00
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
|
|
|
return QString("Type");
|
|
|
|
case FieldValue:
|
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
|
|
|
type = payloadProtocolId(ProtocolIdEth);
|
|
|
|
return type;
|
2009-04-27 11:51:44 -05:00
|
|
|
case FieldTextValue:
|
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
|
|
|
type = payloadProtocolId(ProtocolIdEth);
|
|
|
|
return QString("0x%1").arg(type, 4, BASE_HEX, QChar('0'));
|
2009-04-27 11:51:44 -05:00
|
|
|
case FieldFrameValue:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
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
|
|
|
type = payloadProtocolId(ProtocolIdEth);
|
2009-04-27 11:51:44 -05:00
|
|
|
fv.resize(2);
|
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
|
|
|
qToBigEndian((quint16) type, (uchar*) fv.data());
|
2009-04-27 11:51:44 -05:00
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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-04-27 11:51:44 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AbstractProtocol::fieldData(index, attrib, streamIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Eth2Protocol::setFieldData(int index, const QVariant &value,
|
|
|
|
FieldAttrib attrib)
|
|
|
|
{
|
|
|
|
bool isOk = false;
|
|
|
|
|
|
|
|
if (attrib != FieldValue)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case eth2_type:
|
|
|
|
{
|
|
|
|
uint type = value.toUInt(&isOk);
|
|
|
|
if (isOk)
|
|
|
|
data.set_type(type);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return isOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget* Eth2Protocol::configWidget()
|
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
if (configForm == NULL)
|
2009-09-23 09:53:26 -05:00
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
configForm = new Eth2ConfigForm;
|
2009-09-23 09:53:26 -05:00
|
|
|
loadConfigWidget();
|
|
|
|
}
|
2009-04-27 11:51:44 -05:00
|
|
|
return configForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Eth2Protocol::loadConfigWidget()
|
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
configWidget();
|
|
|
|
|
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
|
|
|
configForm->leType->setText(uintToHexStr(
|
|
|
|
fieldData(eth2_type, FieldValue).toUInt(), 2));
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void Eth2Protocol::storeConfigWidget()
|
|
|
|
{
|
|
|
|
bool isOk;
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
configWidget();
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
data.set_type(configForm->leType->text().remove(QChar(' ')).toULong(&isOk, 16));
|
|
|
|
}
|
|
|
|
|