-rw-r--r-- | libopie2/opienet/802_11_user.h | 16 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 103 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 22 |
3 files changed, 108 insertions, 33 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 | |||
@@ -256,4 +256,16 @@ struct ieee_802_11_data_header { | |||
256 | }; | 256 | }; |
257 | 257 | ||
258 | struct ieee_802_11_control_header { | ||
259 | u_int16_tframe_control; | ||
260 | u_int16_tduration; | ||
261 | u_int8_tmac1[6]; | ||
262 | u_int8_tmac2[6]; | ||
263 | u_int8_tmac3[6]; | ||
264 | u_int16_tSeqCtl; | ||
265 | u_int8_tmac4[6]; | ||
266 | // u_int16_tgapLen; | ||
267 | // u_int8_tgap[8]; | ||
268 | }; | ||
269 | |||
258 | #define CAPABILITY_ESS(cap) ((cap) & 0x0001) | 270 | #define CAPABILITY_ESS(cap) ((cap) & 0x0001) |
259 | #define CAPABILITY_IBSS(cap) ((cap) & 0x0002) | 271 | #define CAPABILITY_IBSS(cap) ((cap) & 0x0002) |
@@ -363,4 +375,8 @@ struct ieee_802_11_data_body { | |||
363 | }; | 375 | }; |
364 | 376 | ||
377 | struct ieee_802_11_control_body { | ||
378 | //FIXME | ||
379 | }; | ||
380 | |||
365 | struct ctrl_rts_t { | 381 | struct ctrl_rts_t { |
366 | u_int16_tfc; | 382 | u_int16_tfc; |
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 | |||
@@ -45,21 +45,26 @@ | |||
45 | *======================================================================================*/ | 45 | *======================================================================================*/ |
46 | 46 | ||
47 | OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* parent ) | 47 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) |
48 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) | 48 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) |
49 | { | 49 | { |
50 | qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | 50 | //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); |
51 | 51 | ||
52 | _end = (unsigned char*) data + header.len; | 52 | _end = (unsigned char*) data + header.len; |
53 | qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | 53 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); |
54 | 54 | ||
55 | if ( packetCapturer()->dataLink() == DLT_EN10MB ) | 55 | switch ( datalink ) |
56 | { | 56 | { |
57 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); | 57 | case DLT_EN10MB: |
58 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); | 58 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); |
59 | } | 59 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); |
60 | else | 60 | break; |
61 | { | 61 | |
62 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); | 62 | case DLT_IEEE802_11: |
63 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); | 63 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); |
64 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); | ||
65 | break; | ||
66 | |||
67 | default: | ||
68 | qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink ); | ||
64 | } | 69 | } |
65 | } | 70 | } |
@@ -71,10 +76,4 @@ OPacket::~OPacket() | |||
71 | 76 | ||
72 | 77 | ||
73 | OPacketCapturer* OPacket::packetCapturer() const | ||
74 | { | ||
75 | return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0; | ||
76 | } | ||
77 | |||
78 | |||
79 | timevalstruct OPacket::timeval() const | 78 | timevalstruct OPacket::timeval() const |
80 | { | 79 | { |
@@ -317,5 +316,5 @@ OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_ | |||
317 | qDebug( "duration: %d", duration() ); | 316 | qDebug( "duration: %d", duration() ); |
318 | qDebug( "powermanagement: %d", usesPowerManagement() ); | 317 | qDebug( "powermanagement: %d", usesPowerManagement() ); |
319 | qDebug( "wep: %d", usesWep() ); | 318 | qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); |
320 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); | 319 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); |
321 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); | 320 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); |
@@ -327,6 +326,6 @@ OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_ | |||
327 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 326 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
328 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 327 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
329 | //case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_ctrl_header*) data, this ); break; | 328 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
330 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" ); | 329 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); |
331 | } | 330 | } |
332 | } | 331 | } |
@@ -418,12 +417,5 @@ OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, co | |||
418 | { | 417 | { |
419 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); | 418 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); |
420 | 419 | qDebug( "Detected subtype is '%s'", (const char*) managementType() ); | |
421 | switch ( ((OWaveLanPacket*) this->parent() )->subType() ) | ||
422 | { | ||
423 | case ST_BEACON: | ||
424 | { | ||
425 | // nice, received a beacon... | ||
426 | } | ||
427 | } | ||
428 | 420 | ||
429 | // grab tagged values | 421 | // grab tagged values |
@@ -453,4 +445,26 @@ OWaveLanManagementPacket::~OWaveLanManagementPacket() | |||
453 | 445 | ||
454 | 446 | ||
447 | QString OWaveLanManagementPacket::managementType() const | ||
448 | { | ||
449 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | ||
450 | { | ||
451 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | ||
452 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | ||
453 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | ||
454 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | ||
455 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | ||
456 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; | ||
457 | case ST_BEACON: return "Beacon"; break; | ||
458 | case ST_ATIM: return "Atim"; break; | ||
459 | case ST_DISASSOC: return "Disassociation"; break; | ||
460 | case ST_AUTH: return "Authentication"; break; | ||
461 | case ST_DEAUTH: return "Deathentication"; break; | ||
462 | default: | ||
463 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); | ||
464 | return "Unknown"; | ||
465 | } | ||
466 | } | ||
467 | |||
468 | |||
455 | int OWaveLanManagementPacket::beaconInterval() const | 469 | int OWaveLanManagementPacket::beaconInterval() const |
456 | { | 470 | { |
@@ -683,4 +697,22 @@ OLLCPacket::~OLLCPacket() | |||
683 | } | 697 | } |
684 | 698 | ||
699 | |||
700 | /*====================================================================================== | ||
701 | * OWaveLanControlPacket | ||
702 | *======================================================================================*/ | ||
703 | |||
704 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | ||
705 | :QObject( parent, "802.11 Data" ), _header( data ) | ||
706 | { | ||
707 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); | ||
708 | //TODO: Implement this | ||
709 | } | ||
710 | |||
711 | |||
712 | OWaveLanControlPacket::~OWaveLanControlPacket() | ||
713 | { | ||
714 | } | ||
715 | |||
716 | |||
685 | /*====================================================================================== | 717 | /*====================================================================================== |
686 | * OPacketCapturer | 718 | * OPacketCapturer |
@@ -771,7 +803,15 @@ OPacket* OPacketCapturer::next() | |||
771 | 803 | ||
772 | if ( header.len ) | 804 | if ( header.len ) |
773 | return new OPacket( header, pdata, this ); | 805 | { |
806 | return new OPacket( dataLink(), header, pdata, 0 ); | ||
807 | // packets shouldn't be inserted in the QObject child-parent hierarchy, | ||
808 | // because due to memory constraints they will be deleted as soon | ||
809 | // as possible - that is right after they have been processed | ||
810 | // by emit() [ see below ] | ||
811 | } | ||
774 | else | 812 | else |
813 | { | ||
775 | return 0; | 814 | return 0; |
815 | } | ||
776 | } | 816 | } |
777 | 817 | ||
@@ -828,5 +868,8 @@ void OPacketCapturer::readyToReceive() | |||
828 | { | 868 | { |
829 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" ); | 869 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" ); |
830 | emit receivedPacket( next() ); | 870 | OPacket* p = next(); |
871 | emit receivedPacket( p ); | ||
872 | // emit is synchronous - packet has been dealt with, now it's safe to delete | ||
873 | delete p; | ||
831 | } | 874 | } |
832 | 875 | ||
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 | |||
@@ -72,11 +72,9 @@ class OPacket : public QObject | |||
72 | 72 | ||
73 | public: | 73 | public: |
74 | OPacket( packetheaderstruct, const unsigned char*, QObject* parent ); | 74 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); |
75 | virtual ~OPacket(); | 75 | virtual ~OPacket(); |
76 | 76 | ||
77 | timevalstruct timeval() const; | 77 | timevalstruct timeval() const; |
78 | 78 | ||
79 | OPacketCapturer* packetCapturer() const; | ||
80 | |||
81 | int caplen() const; | 79 | int caplen() const; |
82 | int len() const; | 80 | int len() const; |
@@ -152,4 +150,6 @@ class OWaveLanManagementPacket : public QObject | |||
152 | virtual ~OWaveLanManagementPacket(); | 150 | virtual ~OWaveLanManagementPacket(); |
153 | 151 | ||
152 | QString managementType() const; | ||
153 | |||
154 | int beaconInterval() const; | 154 | int beaconInterval() const; |
155 | int capabilities() const; // generic | 155 | int capabilities() const; // generic |
@@ -316,4 +316,20 @@ class OWaveLanDataPacket : public QObject | |||
316 | 316 | ||
317 | /*====================================================================================== | 317 | /*====================================================================================== |
318 | * OWaveLanControlPacket - type: control (T_CTRL) | ||
319 | *======================================================================================*/ | ||
320 | |||
321 | class OWaveLanControlPacket : public QObject | ||
322 | { | ||
323 | Q_OBJECT | ||
324 | |||
325 | public: | ||
326 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); | ||
327 | virtual ~OWaveLanControlPacket(); | ||
328 | |||
329 | private: | ||
330 | const struct ieee_802_11_control_header* _header; | ||
331 | }; | ||
332 | |||
333 | /*====================================================================================== | ||
318 | * OLLCPacket - IEEE 802.2 Link Level Control | 334 | * OLLCPacket - IEEE 802.2 Link Level Control |
319 | *======================================================================================*/ | 335 | *======================================================================================*/ |