author | mickeyl <mickeyl> | 2003-04-08 14:15:35 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-08 14:15:35 (UTC) |
commit | 1af4ae3d621d63c82f7d78efda05218a3457981f (patch) (side-by-side diff) | |
tree | 99423ee25f8bf9d008d8e990725c4ecefc864ecd | |
parent | 77b1330ad7380ac87db4ab532acec7ae11c3bd3a (diff) | |
download | opie-1af4ae3d621d63c82f7d78efda05218a3457981f.zip opie-1af4ae3d621d63c82f7d78efda05218a3457981f.tar.gz opie-1af4ae3d621d63c82f7d78efda05218a3457981f.tar.bz2 |
- add skeleton for the last missing parts in the 802.11 decoding framework
- fix huge memory leak in packet capturer
- add more fine granular 802.11 subtype handling
-rw-r--r-- | libopie2/opienet/802_11_user.h | 16 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 95 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 22 |
3 files changed, 104 insertions, 29 deletions
diff --git a/libopie2/opienet/802_11_user.h b/libopie2/opienet/802_11_user.h index ffdcb93..f596bd8 100644 --- a/libopie2/opienet/802_11_user.h +++ b/libopie2/opienet/802_11_user.h @@ -257,2 +257,14 @@ struct ieee_802_11_data_header { +struct ieee_802_11_control_header { + u_int16_t frame_control; + u_int16_t duration; + u_int8_t mac1[6]; + u_int8_t mac2[6]; + u_int8_t mac3[6]; + u_int16_t SeqCtl; + u_int8_t mac4[6]; +// u_int16_t gapLen; +// u_int8_t gap[8]; +}; + #define CAPABILITY_ESS(cap) ((cap) & 0x0001) @@ -364,2 +376,6 @@ struct ieee_802_11_data_body { +struct ieee_802_11_control_body { +//FIXME +}; + struct ctrl_rts_t { diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 40aac2c..5c464cf 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp @@ -46,19 +46,24 @@ -OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* parent ) +OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) :QObject( parent, "Generic" ), _hdr( header ), _data( data ) { - qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); + //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); _end = (unsigned char*) data + header.len; - qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); + //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); - if ( packetCapturer()->dataLink() == DLT_EN10MB ) + switch ( datalink ) { + case DLT_EN10MB: qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); new OEthernetPacket( _end, (const struct ether_header*) data, this ); - } - else - { + break; + + case DLT_IEEE802_11: qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); + break; + + default: + qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink ); } @@ -72,8 +77,2 @@ OPacket::~OPacket() -OPacketCapturer* OPacket::packetCapturer() const -{ - return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0; -} - - timevalstruct OPacket::timeval() const @@ -318,3 +317,3 @@ OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_ qDebug( "powermanagement: %d", usesPowerManagement() ); - qDebug( "wep: %d", usesWep() ); + qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); @@ -328,4 +327,4 @@ OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_ case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; - //case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_ctrl_header*) data, this ); break; - default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" ); + case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; + default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); } @@ -419,10 +418,3 @@ OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, co qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); - - switch ( ((OWaveLanPacket*) this->parent() )->subType() ) - { - case ST_BEACON: - { - // nice, received a beacon... - } - } + qDebug( "Detected subtype is '%s'", (const char*) managementType() ); @@ -454,2 +446,24 @@ OWaveLanManagementPacket::~OWaveLanManagementPacket() +QString OWaveLanManagementPacket::managementType() const +{ + switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) + { + case ST_ASSOC_REQUEST: return "AssociationRequest"; break; + case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; + case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; + case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; + case ST_PROBE_REQUEST: return "ProbeRequest"; break; + case ST_PROBE_RESPONSE: return "ProbeResponse"; break; + case ST_BEACON: return "Beacon"; break; + case ST_ATIM: return "Atim"; break; + case ST_DISASSOC: return "Disassociation"; break; + case ST_AUTH: return "Authentication"; break; + case ST_DEAUTH: return "Deathentication"; break; + default: + qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); + return "Unknown"; + } +} + + int OWaveLanManagementPacket::beaconInterval() const @@ -684,2 +698,20 @@ OLLCPacket::~OLLCPacket() + +/*====================================================================================== + * OWaveLanControlPacket + *======================================================================================*/ + +OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) + :QObject( parent, "802.11 Data" ), _header( data ) +{ + qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); + //TODO: Implement this +} + + +OWaveLanControlPacket::~OWaveLanControlPacket() +{ +} + + /*====================================================================================== @@ -772,6 +804,14 @@ OPacket* OPacketCapturer::next() if ( header.len ) - return new OPacket( header, pdata, this ); + { + return new OPacket( dataLink(), header, pdata, 0 ); + // packets shouldn't be inserted in the QObject child-parent hierarchy, + // because due to memory constraints they will be deleted as soon + // as possible - that is right after they have been processed + // by emit() [ see below ] + } else + { return 0; } +} @@ -829,3 +869,6 @@ void OPacketCapturer::readyToReceive() qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" ); - emit receivedPacket( next() ); + OPacket* p = next(); + emit receivedPacket( p ); + // emit is synchronous - packet has been dealt with, now it's safe to delete + delete p; } diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 04d22ff..ddef278 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h @@ -73,3 +73,3 @@ class OPacket : public QObject public: - OPacket( packetheaderstruct, const unsigned char*, QObject* parent ); + OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); virtual ~OPacket(); @@ -78,4 +78,2 @@ class OPacket : public QObject - OPacketCapturer* packetCapturer() const; - int caplen() const; @@ -153,2 +151,4 @@ class OWaveLanManagementPacket : public QObject + QString managementType() const; + int beaconInterval() const; @@ -317,2 +317,18 @@ class OWaveLanDataPacket : public QObject /*====================================================================================== + * OWaveLanControlPacket - type: control (T_CTRL) + *======================================================================================*/ + +class OWaveLanControlPacket : public QObject +{ + Q_OBJECT + + public: + OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); + virtual ~OWaveLanControlPacket(); + + private: + const struct ieee_802_11_control_header* _header; +}; + +/*====================================================================================== * OLLCPacket - IEEE 802.2 Link Level Control |