4c2df3c5a7
--------- - all protocols on allocation of a configWidget, also populate it before returning from configWidget() - VLAN TPID override is now correctly saved and restored from/to its widget (vlan.cpp) - Payload protocol returns a minimum frame value of 1 byte size (Hack to avoid crash in stream config dialog when sum of all protocol frame sizes is greater than the frame length - small layout changes in mac widget (mac.ui) - src/dst ip mask changed from 255.255.255.255 to 255.255.255.0 (ip4.proto) - src mac changed from u32 to u64 (mac.proto) - "Combo Protocol" protocol container introduced to define newer protocols as a combination of existing protocols e.g. dot2 = dot3 + llc - THIS IS NOT YET COMPLETE (comboprotocol.h) Client/StreamConfigDialog ------------------------- - Advanced Protocol Selection implemented - Simple Protocol Selection rewritten to work alongside Advanced - Payload Widget is treated like any other protocol - hence it is not placedinto the dialog specially - Any protocol selection change (in Simple/Advanced mode) immediately triggers change in the Stream's protocolList - Protocol Widgets now are arranged in a toolBox on a top level tab of the dialog instead of a nested tabWidget - Vlan selection (Simple Mode) uses Radio buttons instead of checkboxes - Double Tagged (SVlan + CVlan) now works via Simple Mode
214 lines
4.5 KiB
C++
214 lines
4.5 KiB
C++
#include <qendian.h>
|
|
#include <QHostAddress>
|
|
|
|
//#include "../client/stream.h"
|
|
#include "payload.h"
|
|
#include "streambase.h"
|
|
|
|
#define SZ_FCS 4
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
PayloadProtocol::PayloadProtocol(StreamBase *stream)
|
|
: AbstractProtocol(stream)
|
|
{
|
|
configForm = NULL;
|
|
}
|
|
|
|
PayloadProtocol::~PayloadProtocol()
|
|
{
|
|
delete configForm;
|
|
}
|
|
|
|
AbstractProtocol* PayloadProtocol::createInstance(StreamBase *stream)
|
|
{
|
|
return new PayloadProtocol(stream);
|
|
}
|
|
|
|
quint32 PayloadProtocol::protocolNumber() const
|
|
{
|
|
return OstProto::Protocol::kPayloadFieldNumber;
|
|
}
|
|
|
|
void PayloadProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
|
{
|
|
protocol.MutableExtension(OstProto::payload)->CopyFrom(data);
|
|
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
|
}
|
|
|
|
void PayloadProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
|
{
|
|
if (protocol.protocol_id().id() == protocolNumber() &&
|
|
protocol.HasExtension(OstProto::payload))
|
|
data.MergeFrom(protocol.GetExtension(OstProto::payload));
|
|
}
|
|
|
|
QString PayloadProtocol::name() const
|
|
{
|
|
return QString("Payload Data");
|
|
}
|
|
|
|
QString PayloadProtocol::shortName() const
|
|
{
|
|
return QString("DATA");
|
|
}
|
|
|
|
int PayloadProtocol::protocolFrameSize() const
|
|
{
|
|
return (mpStream->frameLen() - protocolFrameOffset() - SZ_FCS);
|
|
}
|
|
|
|
int PayloadProtocol::fieldCount() const
|
|
{
|
|
return payload_fieldCount;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
|
|
dataLen = mpStream->frameLen() - protocolFrameOffset();
|
|
dataLen -= SZ_FCS;
|
|
|
|
// FIXME: Hack! Bad! Bad! Very Bad!!!
|
|
if (dataLen <= 0)
|
|
dataLen = 1;
|
|
|
|
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:
|
|
//! \todo cksum will be incorrect for random pattern
|
|
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()
|
|
{
|
|
if (configForm == NULL)
|
|
{
|
|
configForm = new PayloadConfigForm;
|
|
loadConfigWidget();
|
|
}
|
|
return configForm;
|
|
}
|
|
|
|
void PayloadProtocol::loadConfigWidget()
|
|
{
|
|
configWidget();
|
|
|
|
configForm->cmbPatternMode->setCurrentIndex(data.pattern_mode());
|
|
configForm->lePattern->setText(uintToHexStr(data.pattern(), 4));
|
|
}
|
|
|
|
void PayloadProtocol::storeConfigWidget()
|
|
{
|
|
bool isOk;
|
|
|
|
configWidget();
|
|
|
|
data.set_pattern_mode((OstProto::Payload::DataPatternMode)
|
|
configForm->cmbPatternMode->currentIndex());
|
|
data.set_pattern(configForm->lePattern->text().remove(QChar(' ')).toULong(&isOk, 16));
|
|
}
|
|
|