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 <qendian.h>
|
2009-08-02 09:52:34 -05:00
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
#include "abstractprotocol.h"
|
2009-08-02 09:52:34 -05:00
|
|
|
#include "streambase.h"
|
|
|
|
#include "protocollistiterator.h"
|
2009-04-27 11:51:44 -05:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\class AbstractProtocol
|
|
|
|
|
2009-11-03 08:02:09 -06:00
|
|
|
\todo (MED) update AbstractProtocol documentation
|
2009-04-27 11:51:44 -05:00
|
|
|
Bare Minimum set of methods that a subclass needs to reimplement
|
|
|
|
- protoDataCopyInto() [pure virtual]
|
|
|
|
- protoDataCopyFrom() [pure virtual]
|
|
|
|
- fieldCount()
|
|
|
|
|
|
|
|
Any useful protocol should also provide implementations for
|
|
|
|
- name()
|
|
|
|
- shortName()
|
|
|
|
- fieldName()
|
|
|
|
|
|
|
|
Protocols with meta fields should additionally implement
|
|
|
|
- metaFieldCount()
|
|
|
|
- isMetaField()
|
|
|
|
*/
|
2009-10-14 10:16:56 -05:00
|
|
|
AbstractProtocol::AbstractProtocol(StreamBase *stream, AbstractProtocol *parent)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
//qDebug("%s: &prev = %p &next = %p", __FUNCTION__, &prev, &next);
|
2009-08-02 09:52:34 -05:00
|
|
|
mpStream = stream;
|
2009-10-14 10:16:56 -05:00
|
|
|
this->parent = parent;
|
|
|
|
prev = next = NULL;
|
2009-04-27 11:51:44 -05:00
|
|
|
metaCount = -1;
|
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
|
|
|
protoSize = -1;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProtocol::~AbstractProtocol()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
AbstractProtocol* AbstractProtocol::createInstance(StreamBase *stream,
|
|
|
|
AbstractProtocol *parent)
|
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
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-04-27 11:51:44 -05:00
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
quint32 AbstractProtocol::protocolNumber() const
|
|
|
|
{
|
2009-11-13 10:00:57 -06:00
|
|
|
qFatal("Something wrong!!!");
|
2009-08-02 09:52:34 -05:00
|
|
|
return 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
\fn virtual void protoDataCopyInto(OstProto::OstProto::StreamCore &stream) = 0;
|
2009-04-27 11:51:44 -05:00
|
|
|
|
|
|
|
Copy the protocol's protobuf into the passed in stream \n
|
|
|
|
In the base class this is a pure virtual function. Subclasses should
|
|
|
|
implement this function by using - \n
|
|
|
|
stream.AddExtension(<ExtId>)->CopyFrom(<protobuf_data>) */
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
\fn virtual void protoDataCopyFrom(const OstProto::OstProto::StreamCore &stream) = 0;
|
2009-11-03 08:02:09 -06:00
|
|
|
*/
|
2009-04-27 11:51:44 -05:00
|
|
|
|
|
|
|
/*! Returns the full name of the protocol \n
|
|
|
|
The default implementation returns a null string */
|
|
|
|
QString AbstractProtocol::name() const
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Returns the short name or abbreviation of the protocol \n
|
|
|
|
The default implementation forms and returns a abbreviation composed
|
|
|
|
of all the upper case chars in name() \n
|
|
|
|
The default implementation caches the abbreviation on its first invocation
|
|
|
|
and subsequently returns the cached abbreviation */
|
|
|
|
QString AbstractProtocol::shortName() const
|
|
|
|
{
|
|
|
|
if (protoAbbr.isNull())
|
|
|
|
{
|
|
|
|
QString abbr;
|
|
|
|
|
|
|
|
for (int i = 0; i < name().size(); i++)
|
|
|
|
if (name().at(i).isUpper()) abbr.append(name().at(i));
|
|
|
|
|
|
|
|
if (abbr.size())
|
|
|
|
protoAbbr = abbr;
|
|
|
|
else
|
|
|
|
protoAbbr = QString("");
|
|
|
|
}
|
|
|
|
|
|
|
|
return protoAbbr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Returns the number of fields (both Frame and Meta fields) \n
|
|
|
|
The default implementation returns zero */
|
|
|
|
int AbstractProtocol::fieldCount() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Returns the number of meta fields \n
|
|
|
|
The default implementation counts and returns the number of fields for which
|
2009-05-24 09:54:11 -05:00
|
|
|
the FieldIsMeta flag is set\n
|
2009-04-27 11:51:44 -05:00
|
|
|
The default implementation caches the count on its first invocation
|
|
|
|
and subsequently returns the cached count */
|
|
|
|
int AbstractProtocol::metaFieldCount() const
|
|
|
|
{
|
|
|
|
if (metaCount < 0)
|
|
|
|
{
|
|
|
|
int c = 0;
|
|
|
|
for (int i = 0; i < fieldCount() ; i++)
|
2009-05-24 09:54:11 -05:00
|
|
|
if (fieldFlags(i).testFlag(FieldIsMeta))
|
2009-04-27 11:51:44 -05:00
|
|
|
c++;
|
|
|
|
metaCount = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
return metaCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Returns the number of frame fields \n
|
|
|
|
Convenience method - same as fieldCount() minus metaFieldCount() */
|
|
|
|
int AbstractProtocol::frameFieldCount() const
|
|
|
|
{
|
|
|
|
//qDebug("%s:%d, %d", __FUNCTION__, fieldCount(), metaFieldCount());
|
|
|
|
return (fieldCount() - metaFieldCount());
|
|
|
|
}
|
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
AbstractProtocol::FieldFlags AbstractProtocol::fieldFlags(int index) const
|
|
|
|
{
|
|
|
|
return FieldIsNormal;
|
|
|
|
}
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
/*! Returns the requested field attribute data \n
|
|
|
|
Protocols which have meta fields that vary a frame field across
|
|
|
|
streams may use the streamIndex to return the appropriate field value \n
|
|
|
|
Some field attriubutes e.g. FieldName may be invariant across streams\n
|
|
|
|
The default implementation returns the fieldValue() converted to string
|
|
|
|
The FieldTextValue attribute may include additional information about
|
|
|
|
the field's value e.g. a checksum field may include "(correct)" or
|
|
|
|
"(incorrect)" alongwith the actual checksum value. \n
|
2009-11-03 08:02:09 -06:00
|
|
|
|
|
|
|
The default implementation returns a empty string for FieldName and
|
|
|
|
FieldTextValue; empty byte array of size 0 for FieldFrameValue; 0 for
|
|
|
|
FieldValue; subclasses are expected to return meaning values for all
|
|
|
|
these attributes. The only exception is the 'FieldBitSize' attribute -
|
|
|
|
the default implementation takes the (byte) size of FieldFrameValue,
|
|
|
|
multiplies it with 8 and returns the result - this can be used by
|
|
|
|
subclasses for fields which are an integral multiple of bytes; for
|
|
|
|
fields whose size are a non-integral multiple of bytes or smaller than
|
|
|
|
a byte, subclasses should return the correct value. Also for fields
|
|
|
|
which represent checksums, subclasses should return a value for
|
|
|
|
FieldBitSize - even if it is an integral multiple of bytes
|
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
|
|
|
|
|
|
|
\note If a subclass uses any of the below functions to derive
|
|
|
|
FieldFrameValue, the subclass should handle and return a value for
|
|
|
|
FieldBitSize to prevent endless recrusion -
|
|
|
|
- protocolFrameCksum()
|
2009-10-14 10:16:56 -05:00
|
|
|
- protocolFramePayloadSize()
|
2009-04-27 11:51:44 -05:00
|
|
|
*/
|
|
|
|
QVariant AbstractProtocol::fieldData(int index, FieldAttrib attrib,
|
|
|
|
int streamIndex) const
|
|
|
|
{
|
|
|
|
switch (attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
|
|
|
return QString();
|
|
|
|
case FieldBitSize:
|
2009-05-24 09:54:11 -05:00
|
|
|
Q_ASSERT_X(!fieldFlags(index).testFlag(FieldIsCksum),
|
|
|
|
"AbstractProtocol::fieldData()",
|
|
|
|
"FieldBitSize for checksum fields need to be handled by the subclass");
|
2009-04-27 11:51:44 -05:00
|
|
|
return fieldData(index, FieldFrameValue, streamIndex).
|
|
|
|
toByteArray().size() * 8;
|
|
|
|
case FieldValue:
|
|
|
|
return 0;
|
|
|
|
case FieldFrameValue:
|
|
|
|
return QByteArray();
|
|
|
|
case FieldTextValue:
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
default:
|
|
|
|
qFatal("%s:%d: unhandled case %d\n", __FUNCTION__, __LINE__,
|
|
|
|
attrib);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! Sets the value of a field corresponding to index \n
|
|
|
|
Returns true if field is successfully set, false otherwise \n
|
|
|
|
The default implementation always returns false */
|
|
|
|
bool AbstractProtocol::setFieldData(int index, const QVariant &value,
|
|
|
|
FieldAttrib attrib)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-13 10:00:57 -06:00
|
|
|
AbstractProtocol::ProtocolIdType AbstractProtocol::protocolIdType() const
|
|
|
|
{
|
|
|
|
return ProtocolIdNone;
|
|
|
|
}
|
|
|
|
|
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 AbstractProtocol::protocolId(ProtocolIdType type) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 AbstractProtocol::payloadProtocolId(ProtocolIdType type) const
|
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
quint32 id;
|
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-10-14 10:16:56 -05:00
|
|
|
if (next)
|
|
|
|
id = next->protocolId(type);
|
|
|
|
else if (parent)
|
|
|
|
id = parent->payloadProtocolId(type);
|
|
|
|
else
|
|
|
|
id = 0xFFFFFFFF;
|
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-10-14 10:16:56 -05:00
|
|
|
qDebug("%s: payloadProtocolId = 0x%x", __FUNCTION__, id);
|
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
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2009-11-03 08:02:09 -06:00
|
|
|
int AbstractProtocol::protocolFrameSize(int streamIndex) 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
|
|
|
{
|
|
|
|
if (protoSize < 0)
|
|
|
|
{
|
|
|
|
int bitsize = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < fieldCount(); i++)
|
|
|
|
{
|
2009-05-24 09:54:11 -05:00
|
|
|
if (!fieldFlags(i).testFlag(FieldIsMeta))
|
2009-11-03 08:02:09 -06:00
|
|
|
bitsize += fieldData(i, FieldBitSize, streamIndex).toUInt();
|
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
|
|
|
}
|
|
|
|
protoSize = (bitsize+7)/8;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("%s: protoSize = %d", __FUNCTION__, protoSize);
|
|
|
|
return protoSize;
|
|
|
|
}
|
|
|
|
|
2009-11-03 08:02:09 -06:00
|
|
|
int AbstractProtocol::protocolFrameOffset(int streamIndex) 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
|
|
|
{
|
|
|
|
int size = 0;
|
2009-10-14 10:16:56 -05:00
|
|
|
AbstractProtocol *p = prev;
|
|
|
|
while (p)
|
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-11-03 08:02:09 -06:00
|
|
|
size += p->protocolFrameSize(streamIndex);
|
2009-10-14 10:16:56 -05:00
|
|
|
p = p->prev;
|
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-10-14 10:16:56 -05:00
|
|
|
|
|
|
|
if (parent)
|
2009-11-03 08:02:09 -06:00
|
|
|
size += parent->protocolFrameOffset(streamIndex);
|
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
|
|
|
|
|
|
|
qDebug("%s: ofs = %d", __FUNCTION__, size);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2009-11-03 08:02:09 -06:00
|
|
|
int AbstractProtocol::protocolFramePayloadSize(int streamIndex) 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
|
|
|
{
|
|
|
|
int size = 0;
|
2009-10-14 10:16:56 -05:00
|
|
|
AbstractProtocol *p = next;
|
|
|
|
while (p)
|
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-11-03 08:02:09 -06:00
|
|
|
size += p->protocolFrameSize(streamIndex);
|
2009-10-14 10:16:56 -05:00
|
|
|
p = p->next;
|
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-10-14 10:16:56 -05:00
|
|
|
if (parent)
|
2009-11-03 08:02:09 -06:00
|
|
|
size += parent->protocolFramePayloadSize(streamIndex);
|
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
|
|
|
|
|
|
|
qDebug("%s: payloadSize = %d", __FUNCTION__, size);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
/*! Returns a byte array encoding the protocol (and its fields) which can be
|
|
|
|
inserted into the stream's frame
|
|
|
|
The default implementation forms and returns an ordered concatenation of
|
|
|
|
the FrameValue of all the 'frame' fields of the protocol taking care of fields
|
|
|
|
which are not an integral number of bytes\n */
|
2009-05-24 09:54:11 -05:00
|
|
|
QByteArray AbstractProtocol::protocolFrameValue(int streamIndex, bool forCksum) const
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
|
|
|
QByteArray proto, field;
|
2009-05-24 09:54:11 -05:00
|
|
|
uint bits, lastbitpos = 0;
|
|
|
|
FieldFlags flags;
|
2009-04-27 11:51:44 -05:00
|
|
|
|
|
|
|
for (int i=0; i < fieldCount() ; i++)
|
|
|
|
{
|
2009-05-24 09:54:11 -05:00
|
|
|
flags = fieldFlags(i);
|
|
|
|
if (!flags.testFlag(FieldIsMeta))
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
|
|
|
bits = fieldData(i, FieldBitSize, streamIndex).toUInt();
|
2009-11-28 02:35:05 -06:00
|
|
|
if (bits == 0)
|
|
|
|
continue;
|
2009-05-24 09:54:11 -05:00
|
|
|
Q_ASSERT(bits > 0);
|
2009-04-27 11:51:44 -05:00
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
if (forCksum && flags.testFlag(FieldIsCksum))
|
|
|
|
{
|
|
|
|
field.resize((bits+7)/8);
|
|
|
|
field.fill('\0');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
field = fieldData(i, FieldFrameValue, streamIndex).toByteArray();
|
|
|
|
qDebug("<<< %d, %d/%d >>>>", proto.size(), bits, field.size());
|
2009-04-27 11:51:44 -05:00
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
if (bits == (uint) field.size() * 8)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
|
|
|
if (lastbitpos == 0)
|
|
|
|
proto.append(field);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Q_ASSERT(field.size() > 0);
|
|
|
|
|
|
|
|
char c = proto[proto.size() - 1];
|
|
|
|
proto[proto.size() - 1] = c | (field.at(0) >> lastbitpos);
|
|
|
|
for (int j = 0; j < field.size() - 1; j++)
|
|
|
|
proto.append(field.at(j) << lastbitpos |
|
|
|
|
field.at(j+1) >> lastbitpos);
|
|
|
|
}
|
|
|
|
}
|
2009-05-24 09:54:11 -05:00
|
|
|
else if (bits < (uint) field.size() * 8)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-05-24 09:54:11 -05:00
|
|
|
uchar c;
|
|
|
|
uint v;
|
|
|
|
|
|
|
|
v = (field.size()*8) - bits;
|
|
|
|
|
|
|
|
Q_ASSERT(v < 8);
|
2009-04-27 11:51:44 -05:00
|
|
|
|
|
|
|
if (lastbitpos == 0)
|
|
|
|
{
|
2009-05-24 09:54:11 -05:00
|
|
|
for (int j = 0; j < field.size(); j++)
|
|
|
|
{
|
|
|
|
c = field.at(j) << v;
|
|
|
|
if ((j+1) < field.size())
|
|
|
|
c |= ((uchar)field.at(j+1) >> (8-v));
|
|
|
|
proto.append(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
lastbitpos = (lastbitpos + bits) % 8;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-24 09:54:11 -05:00
|
|
|
Q_ASSERT(proto.size() > 0);
|
|
|
|
|
|
|
|
for (int j = 0; j < field.size(); j++)
|
|
|
|
{
|
|
|
|
uchar d;
|
|
|
|
|
|
|
|
c = field.at(j) << v;
|
|
|
|
if ((j+1) < field.size())
|
|
|
|
c |= ((uchar) field.at(j+1) >> (8-v));
|
|
|
|
d = proto[proto.size() - 1];
|
|
|
|
proto[proto.size() - 1] = d | ((uchar) c >> lastbitpos);
|
|
|
|
if (bits > (8*j + (8 - v)))
|
|
|
|
proto.append(c << (8-lastbitpos));
|
|
|
|
}
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
lastbitpos = (lastbitpos + bits) % 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // if (bits > field.size() * 8)
|
|
|
|
{
|
|
|
|
qFatal("bitsize more than FrameValue size. skipping...");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
2009-11-13 10:00:57 -06:00
|
|
|
bool AbstractProtocol::isProtocolFrameValueVariable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractProtocol::isProtocolFrameSizeVariable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractProtocol::isProtocolFramePayloadValueVariable() const
|
|
|
|
{
|
|
|
|
AbstractProtocol *p = next;
|
|
|
|
|
|
|
|
while (p)
|
|
|
|
{
|
|
|
|
if (p->isProtocolFrameValueVariable())
|
|
|
|
return true;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
if (parent && parent->isProtocolFramePayloadValueVariable())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractProtocol::isProtocolFramePayloadSizeVariable() const
|
|
|
|
{
|
|
|
|
AbstractProtocol *p = next;
|
|
|
|
|
|
|
|
while (p)
|
|
|
|
{
|
|
|
|
if (p->isProtocolFrameSizeVariable())
|
|
|
|
return true;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
if (parent && parent->isProtocolFramePayloadSizeVariable())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
/*!
|
|
|
|
\note If a subclass uses protocolFrameCksum() from within fieldData() to
|
|
|
|
derive a cksum field, it MUST handle and return the 'FieldBitSize'
|
|
|
|
attribute also for that particular field instead of using the default
|
|
|
|
AbstractProtocol implementation for 'FieldBitSize' - this is required
|
|
|
|
to prevent infinite recursion
|
|
|
|
*/
|
|
|
|
quint32 AbstractProtocol::protocolFrameCksum(int streamIndex,
|
|
|
|
CksumType cksumType) 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-05-24 09:54:11 -05:00
|
|
|
static int recursionCount = 0;
|
2009-10-14 10:16:56 -05:00
|
|
|
quint32 cksum = 0xFFFFFFFF;
|
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-05-24 09:54:11 -05:00
|
|
|
recursionCount++;
|
|
|
|
Q_ASSERT_X(recursionCount < 10, "protocolFrameCksum", "potential infinite recursion - does a protocol checksum field not implement FieldBitSize?");
|
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-05-24 09:54:11 -05:00
|
|
|
switch(cksumType)
|
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-05-24 09:54:11 -05:00
|
|
|
case CksumIp:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
|
|
|
quint16 *ip;
|
|
|
|
quint32 len, sum = 0;
|
|
|
|
|
|
|
|
fv = protocolFrameValue(streamIndex, true);
|
|
|
|
ip = (quint16*) fv.constData();
|
|
|
|
len = fv.size();
|
|
|
|
|
|
|
|
while(len > 1)
|
|
|
|
{
|
|
|
|
sum += *ip;
|
|
|
|
if(sum & 0x80000000)
|
|
|
|
sum = (sum & 0xFFFF) + (sum >> 16);
|
|
|
|
ip++;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len)
|
|
|
|
sum += (unsigned short) *(unsigned char *)ip;
|
|
|
|
|
|
|
|
while(sum>>16)
|
|
|
|
sum = (sum & 0xFFFF) + (sum >> 16);
|
|
|
|
|
|
|
|
cksum = qFromBigEndian((quint16) ~sum);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CksumTcpUdp:
|
|
|
|
{
|
|
|
|
quint16 cks;
|
|
|
|
quint32 sum = 0;
|
|
|
|
|
|
|
|
cks = protocolFrameCksum(streamIndex, CksumIp);
|
|
|
|
sum += (quint16) ~cks;
|
|
|
|
cks = protocolFramePayloadCksum(streamIndex, CksumIp);
|
|
|
|
sum += (quint16) ~cks;
|
|
|
|
cks = protocolFrameHeaderCksum(streamIndex, CksumIpPseudo);
|
|
|
|
sum += (quint16) ~cks;
|
|
|
|
|
|
|
|
while(sum>>16)
|
|
|
|
sum = (sum & 0xFFFF) + (sum >> 16);
|
|
|
|
|
|
|
|
cksum = (~sum) & 0xFFFF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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-05-24 09:54:11 -05:00
|
|
|
recursionCount--;
|
|
|
|
return cksum;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 AbstractProtocol::protocolFrameHeaderCksum(int streamIndex,
|
|
|
|
CksumType cksumType) const
|
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
quint32 sum = 0;
|
|
|
|
quint16 cksum;
|
|
|
|
AbstractProtocol *p = prev;
|
2009-05-24 09:54:11 -05:00
|
|
|
|
|
|
|
Q_ASSERT(cksumType == CksumIpPseudo);
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
while (p)
|
|
|
|
{
|
|
|
|
cksum = p->protocolFrameCksum(streamIndex, cksumType);
|
|
|
|
sum += (quint16) ~cksum;
|
|
|
|
p = p->prev;
|
|
|
|
qDebug("%s: sum = %u, cksum = %u", __FUNCTION__, sum, cksum);
|
|
|
|
}
|
|
|
|
if (parent)
|
2009-05-24 09:54:11 -05:00
|
|
|
{
|
2009-10-14 10:16:56 -05:00
|
|
|
cksum = parent->protocolFrameHeaderCksum(streamIndex, cksumType);
|
|
|
|
sum += (quint16) ~cksum;
|
2009-05-24 09:54:11 -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
|
|
|
|
|
|
|
while(sum>>16)
|
|
|
|
sum = (sum & 0xFFFF) + (sum >> 16);
|
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
return (quint16) ~sum;
|
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-05-24 09:54:11 -05:00
|
|
|
quint32 AbstractProtocol::protocolFramePayloadCksum(int streamIndex,
|
|
|
|
CksumType cksumType) 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-05-24 09:54:11 -05:00
|
|
|
quint32 sum = 0;
|
|
|
|
quint16 cksum;
|
2009-10-14 10:16:56 -05:00
|
|
|
AbstractProtocol *p = next;
|
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-05-24 09:54:11 -05:00
|
|
|
Q_ASSERT(cksumType == CksumIp);
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
while (p)
|
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-10-14 10:16:56 -05:00
|
|
|
cksum = p->protocolFrameCksum(streamIndex, cksumType);
|
|
|
|
sum += (quint16) ~cksum;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
cksum = parent->protocolFramePayloadCksum(streamIndex, cksumType);
|
|
|
|
sum += (quint16) ~cksum;
|
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-05-24 09:54:11 -05:00
|
|
|
while(sum>>16)
|
|
|
|
sum = (sum & 0xFFFF) + (sum >> 16);
|
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-05-24 09:54:11 -05:00
|
|
|
return (quint16) ~sum;
|
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
|
|
|
}
|
|
|
|
|