2009-04-27 11:51:44 -05:00
|
|
|
#include <qendian.h>
|
|
|
|
#include <QHostAddress>
|
|
|
|
|
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
|
|
|
//#include "../client/stream.h"
|
2009-04-27 11:51:44 -05:00
|
|
|
#include "payload.h"
|
2009-08-02 09:52:34 -05:00
|
|
|
#include "streambase.h"
|
2009-04-27 11:51:44 -05: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
|
|
|
#define SZ_FCS 4
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
PayloadConfigForm::PayloadConfigForm(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PayloadConfigForm::on_cmbPatternMode_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
switch(index)
|
|
|
|
{
|
|
|
|
case OstProto::Payload::e_dp_fixed_word:
|
|
|
|
lePattern->setEnabled(true);
|
|
|
|
break;
|
|
|
|
case OstProto::Payload::e_dp_inc_byte:
|
|
|
|
case OstProto::Payload::e_dp_dec_byte:
|
|
|
|
case OstProto::Payload::e_dp_random:
|
|
|
|
lePattern->setDisabled(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qWarning("Unhandled/Unknown PatternMode = %d",index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
PayloadProtocol::PayloadProtocol(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
|
|
|
}
|
|
|
|
|
|
|
|
PayloadProtocol::~PayloadProtocol()
|
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
delete configForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProtocol* PayloadProtocol::createInstance(StreamBase *stream)
|
|
|
|
{
|
|
|
|
return new PayloadProtocol(stream);
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
quint32 PayloadProtocol::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::kPayloadFieldNumber;
|
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 PayloadProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
protocol.MutableExtension(OstProto::payload)->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 PayloadProtocol::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::payload))
|
|
|
|
data.MergeFrom(protocol.GetExtension(OstProto::payload));
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString PayloadProtocol::name() const
|
|
|
|
{
|
|
|
|
return QString("Payload Data");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString PayloadProtocol::shortName() const
|
|
|
|
{
|
|
|
|
return QString("DATA");
|
|
|
|
}
|
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
int PayloadProtocol::protocolFrameSize() const
|
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
return (mpStream->frameLen() - protocolFrameOffset() - SZ_FCS);
|
2009-05-24 09:54:11 -05:00
|
|
|
}
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
int PayloadProtocol::fieldCount() const
|
|
|
|
{
|
|
|
|
return payload_fieldCount;
|
|
|
|
}
|
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
AbstractProtocol::FieldFlags PayloadProtocol::fieldFlags(int index) const
|
|
|
|
{
|
|
|
|
AbstractProtocol::FieldFlags flags;
|
|
|
|
|
|
|
|
flags = AbstractProtocol::fieldFlags(index);
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case payload_dataPattern:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Meta fields
|
|
|
|
case payload_dataPatternMode:
|
|
|
|
flags |= FieldIsMeta;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
QVariant PayloadProtocol::fieldData(int index, FieldAttrib attrib,
|
|
|
|
int streamIndex) const
|
|
|
|
{
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case payload_dataPattern:
|
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
|
|
|
return QString("Data");
|
|
|
|
case FieldValue:
|
|
|
|
return data.pattern();
|
|
|
|
case FieldTextValue:
|
|
|
|
return QString(fieldData(index, FieldFrameValue,
|
|
|
|
streamIndex).toByteArray().toHex());
|
|
|
|
case FieldFrameValue:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
|
|
|
int dataLen;
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
dataLen = mpStream->frameLen() - protocolFrameOffset();
|
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
|
|
|
dataLen -= SZ_FCS;
|
2009-09-23 09:53:26 -05:00
|
|
|
|
|
|
|
// FIXME: Hack! Bad! Bad! Very Bad!!!
|
|
|
|
if (dataLen <= 0)
|
|
|
|
dataLen = 1;
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
fv.resize(dataLen+4);
|
|
|
|
switch(data.pattern_mode())
|
|
|
|
{
|
|
|
|
case OstProto::Payload::e_dp_fixed_word:
|
|
|
|
for (int i = 0; i < (dataLen/4)+1; i++)
|
|
|
|
qToBigEndian((quint32) data.pattern(),
|
|
|
|
(uchar*)(fv.data()+(i*4)) );
|
|
|
|
break;
|
|
|
|
case OstProto::Payload::e_dp_inc_byte:
|
|
|
|
for (int i = 0; i < dataLen; i++)
|
|
|
|
fv[i] = i % (0xFF + 1);
|
|
|
|
break;
|
|
|
|
case OstProto::Payload::e_dp_dec_byte:
|
|
|
|
for (int i = 0; i < dataLen; i++)
|
|
|
|
fv[i] = 0xFF - (i % (0xFF + 1));
|
|
|
|
break;
|
|
|
|
case OstProto::Payload::e_dp_random:
|
2009-05-24 09:54:11 -05:00
|
|
|
//! \todo cksum will be incorrect for random pattern
|
2009-04-27 11:51:44 -05:00
|
|
|
for (int i = 0; i < dataLen; i++)
|
|
|
|
fv[i] = qrand() % (0xFF + 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qWarning("Unhandled data pattern %d",
|
|
|
|
data.pattern_mode());
|
|
|
|
}
|
|
|
|
fv.resize(dataLen);
|
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Meta fields
|
|
|
|
|
|
|
|
case payload_dataPatternMode:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AbstractProtocol::fieldData(index, attrib, streamIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PayloadProtocol::setFieldData(int index, const QVariant &value,
|
|
|
|
FieldAttrib attrib)
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget* PayloadProtocol::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 PayloadConfigForm;
|
2009-09-23 09:53:26 -05:00
|
|
|
loadConfigWidget();
|
|
|
|
}
|
2009-04-27 11:51:44 -05:00
|
|
|
return configForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PayloadProtocol::loadConfigWidget()
|
|
|
|
{
|
2009-08-02 09:52:34 -05:00
|
|
|
configWidget();
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
configForm->cmbPatternMode->setCurrentIndex(data.pattern_mode());
|
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->lePattern->setText(uintToHexStr(data.pattern(), 4));
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PayloadProtocol::storeConfigWidget()
|
|
|
|
{
|
|
|
|
bool isOk;
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
configWidget();
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
data.set_pattern_mode((OstProto::Payload::DataPatternMode)
|
|
|
|
configForm->cmbPatternMode->currentIndex());
|
|
|
|
data.set_pattern(configForm->lePattern->text().remove(QChar(' ')).toULong(&isOk, 16));
|
|
|
|
}
|
|
|
|
|