-rw-r--r-- | libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp | 2 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp index 34d32d2..c49daa0 100644 --- a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp +++ b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp | |||
@@ -1,217 +1,217 @@ | |||
1 | #include <qdict.h> | 1 | #include <qdict.h> |
2 | #include <qsocketnotifier.h> | 2 | #include <qsocketnotifier.h> |
3 | #include <qstring.h> | 3 | #include <qstring.h> |
4 | #include <opie2/onetwork.h> | 4 | #include <opie2/onetwork.h> |
5 | #include <qapplication.h> | 5 | #include <qapplication.h> |
6 | #include <opie2/opcap.h> | 6 | #include <opie2/opcap.h> |
7 | #include <cerrno> | 7 | #include <cerrno> |
8 | #include <cstdio> | 8 | #include <cstdio> |
9 | #include <cstdlib> | 9 | #include <cstdlib> |
10 | #include <cstring> | 10 | #include <cstring> |
11 | 11 | ||
12 | //======================== Station help class =============================== | 12 | //======================== Station help class =============================== |
13 | 13 | ||
14 | class Station | 14 | class Station |
15 | { | 15 | { |
16 | public: | 16 | public: |
17 | Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {}; | 17 | Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {}; |
18 | ~Station() {}; | 18 | ~Station() {}; |
19 | 19 | ||
20 | QString type; | 20 | QString type; |
21 | int channel; | 21 | int channel; |
22 | bool wep; | 22 | bool wep; |
23 | int beacons; | 23 | int beacons; |
24 | }; | 24 | }; |
25 | 25 | ||
26 | QDict<Station> stations; | 26 | QDict<Station> stations; |
27 | 27 | ||
28 | //======================== Application class =============================== | 28 | //======================== Application class =============================== |
29 | 29 | ||
30 | class Wellenreiter : public QApplication | 30 | class Wellenreiter : public QApplication |
31 | { | 31 | { |
32 | Q_OBJECT | 32 | Q_OBJECT |
33 | public: | 33 | public: |
34 | Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ) | 34 | Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ) |
35 | { | 35 | { |
36 | 36 | ||
37 | ONetwork* net = ONetwork::instance(); | 37 | ONetwork* net = ONetwork::instance(); |
38 | 38 | ||
39 | if ( argc < 3 ) | 39 | if ( argc < 3 ) |
40 | { | 40 | { |
41 | printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] ); | 41 | printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] ); |
42 | printf( "\n" ); | 42 | printf( "\n" ); |
43 | printf( "Valid wireless interfaces (detected) are:\n" ); | 43 | printf( "Valid wireless interfaces (detected) are:\n" ); |
44 | 44 | ||
45 | ONetwork::InterfaceIterator it = net->iterator(); | 45 | ONetwork::InterfaceIterator it = net->iterator(); |
46 | while ( it.current() ) | 46 | while ( it.current() ) |
47 | { | 47 | { |
48 | if ( it.current()->isWireless() ) | 48 | if ( it.current()->isWireless() ) |
49 | { | 49 | { |
50 | printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(), | 50 | printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(), |
51 | (const char*) it.current()->macAddress().toString(), | 51 | (const char*) it.current()->macAddress().toString(), |
52 | (const char*) it.current()->ipV4Address() ); | 52 | (const char*) it.current()->ipV4Address() ); |
53 | } | 53 | } |
54 | ++it; | 54 | ++it; |
55 | } | 55 | } |
56 | exit( -1 ); | 56 | exit( -1 ); |
57 | } | 57 | } |
58 | 58 | ||
59 | printf( "****************************************************\n" ); | 59 | printf( "****************************************************\n" ); |
60 | printf( "* Wellenreiter mini edition 1.0 (C) 2003 M-M-M *\n" ); | 60 | printf( "* Wellenreiter mini edition 1.0 (C) 2003 M-M-M *\n" ); |
61 | printf( "****************************************************\n" ); | 61 | printf( "****************************************************\n" ); |
62 | printf( "\n\n" ); | 62 | printf( "\n\n" ); |
63 | 63 | ||
64 | QString interface( argv[1] ); | 64 | QString interface( argv[1] ); |
65 | QString driver( argv[2] ); | 65 | QString driver( argv[2] ); |
66 | 66 | ||
67 | printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver ); | 67 | printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver ); |
68 | 68 | ||
69 | // sanity checks before downcasting | 69 | // sanity checks before downcasting |
70 | ONetworkInterface* iface = net->interface( interface ); | 70 | ONetworkInterface* iface = net->interface( interface ); |
71 | if ( !iface ) | 71 | if ( !iface ) |
72 | { | 72 | { |
73 | printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface ); | 73 | printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface ); |
74 | exit( -1 ); | 74 | exit( -1 ); |
75 | } | 75 | } |
76 | if ( !iface->isWireless() ) | 76 | if ( !iface->isWireless() ) |
77 | { | 77 | { |
78 | printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface ); | 78 | printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface ); |
79 | exit( -1 ); | 79 | exit( -1 ); |
80 | } | 80 | } |
81 | 81 | ||
82 | // downcast should be safe now | 82 | // downcast should be safe now |
83 | wiface = (OWirelessNetworkInterface*) iface; | 83 | wiface = (OWirelessNetworkInterface*) iface; |
84 | printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() ); | 84 | printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() ); |
85 | 85 | ||
86 | // ifconfig +promisc the interface to receive all packets | 86 | // ifconfig +promisc the interface to receive all packets |
87 | if ( !wiface->promiscuousMode() ) | 87 | if ( !wiface->promiscuousMode() ) |
88 | { | 88 | { |
89 | printf( "Interface status is not promisc... switching to promisc... " ); | 89 | printf( "Interface status is not promisc... switching to promisc... " ); |
90 | wiface->setPromiscuousMode( true ); | 90 | wiface->setPromiscuousMode( true ); |
91 | if ( !wiface->promiscuousMode() ) | 91 | if ( !wiface->promiscuousMode() ) |
92 | { | 92 | { |
93 | printf( "failed (%s). Exiting.\n", strerror( errno ) ); | 93 | printf( "failed (%s). Exiting.\n", strerror( errno ) ); |
94 | exit( -1 ); | 94 | exit( -1 ); |
95 | } | 95 | } |
96 | else | 96 | else |
97 | { | 97 | { |
98 | printf( "ok.\n" ); | 98 | printf( "ok.\n" ); |
99 | } | 99 | } |
100 | } | 100 | } |
101 | else | 101 | else |
102 | printf( "Interface status is already promisc - good.\n" ); | 102 | printf( "Interface status is already promisc - good.\n" ); |
103 | 103 | ||
104 | // connect a monitoring strategy to the interface | 104 | // connect a monitoring strategy to the interface |
105 | if ( driver == "orinoco" ) | 105 | if ( driver == "orinoco" ) |
106 | new OOrinocoMonitoringInterface( wiface ); | 106 | new OOrinocoMonitoringInterface( wiface, false ); |
107 | else | 107 | else |
108 | { | 108 | { |
109 | printf( "Unknown driver. Exiting\n" ); | 109 | printf( "Unknown driver. Exiting\n" ); |
110 | exit( -1 ); | 110 | exit( -1 ); |
111 | } | 111 | } |
112 | 112 | ||
113 | // enable monitoring mode | 113 | // enable monitoring mode |
114 | printf( "Enabling monitor mode...\n" ); | 114 | printf( "Enabling monitor mode...\n" ); |
115 | //wiface->setMonitorMode( true ); | 115 | //wiface->setMonitorMode( true ); |
116 | 116 | ||
117 | // open a packet capturer | 117 | // open a packet capturer |
118 | cap = new OPacketCapturer(); | 118 | cap = new OPacketCapturer(); |
119 | cap->open( interface ); | 119 | cap->open( interface ); |
120 | if ( !cap->isOpen() ) | 120 | if ( !cap->isOpen() ) |
121 | { | 121 | { |
122 | printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) ); | 122 | printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) ); |
123 | exit( -1 ); | 123 | exit( -1 ); |
124 | } | 124 | } |
125 | 125 | ||
126 | // set capturer to non-blocking mode | 126 | // set capturer to non-blocking mode |
127 | cap->setBlocking( false ); | 127 | cap->setBlocking( false ); |
128 | 128 | ||
129 | // start channel hopper | 129 | // start channel hopper |
130 | //wiface->setChannelHopping( 1000 ); | 130 | //wiface->setChannelHopping( 1000 ); |
131 | 131 | ||
132 | // connect | 132 | // connect |
133 | connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); | 133 | connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); |
134 | 134 | ||
135 | } | 135 | } |
136 | 136 | ||
137 | ~Wellenreiter() {}; | 137 | ~Wellenreiter() {}; |
138 | 138 | ||
139 | public slots: | 139 | public slots: |
140 | void receivePacket(OPacket* p) | 140 | void receivePacket(OPacket* p) |
141 | { | 141 | { |
142 | if (!p) | 142 | if (!p) |
143 | { | 143 | { |
144 | printf( "(empty packet received)\n" ); | 144 | printf( "(empty packet received)\n" ); |
145 | return; | 145 | return; |
146 | } | 146 | } |
147 | 147 | ||
148 | OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" ); | 148 | OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" ); |
149 | if ( beacon ) | 149 | if ( beacon ) |
150 | { | 150 | { |
151 | OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); | 151 | OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); |
152 | QString essid = ssid ? ssid->ID() : "<unknown>"; | 152 | QString essid = ssid ? ssid->ID() : "<unknown>"; |
153 | 153 | ||
154 | if ( stations.find( essid ) ) | 154 | if ( stations.find( essid ) ) |
155 | stations[essid]->beacons++; | 155 | stations[essid]->beacons++; |
156 | else | 156 | else |
157 | { | 157 | { |
158 | printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid ); | 158 | printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid ); |
159 | stations.insert( essid, new Station( "unknown", wiface->channel(), | 159 | stations.insert( essid, new Station( "unknown", wiface->channel(), |
160 | ((OWaveLanPacket*) beacon->parent())->usesWep() ) ); | 160 | ((OWaveLanPacket*) beacon->parent())->usesWep() ) ); |
161 | } | 161 | } |
162 | return; | 162 | return; |
163 | } | 163 | } |
164 | 164 | ||
165 | OWaveLanDataPacket* data = (OWaveLanDataPacket*) p->child( "802.11 Data" ); | 165 | OWaveLanDataPacket* data = (OWaveLanDataPacket*) p->child( "802.11 Data" ); |
166 | if ( data ) | 166 | if ( data ) |
167 | { | 167 | { |
168 | OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); | 168 | OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); |
169 | if ( wlan->fromDS() && !wlan->toDS() ) | 169 | if ( wlan->fromDS() && !wlan->toDS() ) |
170 | { | 170 | { |
171 | printf( "FromDS: '%s' -> '%s' via '%s'\n", | 171 | printf( "FromDS: '%s' -> '%s' via '%s'\n", |
172 | (const char*) wlan->macAddress3().toString(true), | 172 | (const char*) wlan->macAddress3().toString(true), |
173 | (const char*) wlan->macAddress1().toString(true), | 173 | (const char*) wlan->macAddress1().toString(true), |
174 | (const char*) wlan->macAddress2().toString(true) ); | 174 | (const char*) wlan->macAddress2().toString(true) ); |
175 | } | 175 | } |
176 | else | 176 | else |
177 | if ( !wlan->fromDS() && wlan->toDS() ) | 177 | if ( !wlan->fromDS() && wlan->toDS() ) |
178 | { | 178 | { |
179 | printf( "ToDS: '%s' -> '%s' via '%s'\n", | 179 | printf( "ToDS: '%s' -> '%s' via '%s'\n", |
180 | (const char*) wlan->macAddress2().toString(true), | 180 | (const char*) wlan->macAddress2().toString(true), |
181 | (const char*) wlan->macAddress3().toString(true), | 181 | (const char*) wlan->macAddress3().toString(true), |
182 | (const char*) wlan->macAddress1().toString(true) ); | 182 | (const char*) wlan->macAddress1().toString(true) ); |
183 | } | 183 | } |
184 | else | 184 | else |
185 | if ( wlan->fromDS() && wlan->toDS() ) | 185 | if ( wlan->fromDS() && wlan->toDS() ) |
186 | { | 186 | { |
187 | printf( "WSD(bridge): '%s' -> '%s' via '%s' and '%s'\n", | 187 | printf( "WSD(bridge): '%s' -> '%s' via '%s' and '%s'\n", |
188 | (const char*) wlan->macAddress4().toString(true), | 188 | (const char*) wlan->macAddress4().toString(true), |
189 | (const char*) wlan->macAddress3().toString(true), | 189 | (const char*) wlan->macAddress3().toString(true), |
190 | (const char*) wlan->macAddress1().toString(true), | 190 | (const char*) wlan->macAddress1().toString(true), |
191 | (const char*) wlan->macAddress2().toString(true) ); | 191 | (const char*) wlan->macAddress2().toString(true) ); |
192 | } | 192 | } |
193 | else | 193 | else |
194 | { | 194 | { |
195 | printf( "IBSS(AdHoc): '%s' -> '%s' (Cell: '%s')'\n", | 195 | printf( "IBSS(AdHoc): '%s' -> '%s' (Cell: '%s')'\n", |
196 | (const char*) wlan->macAddress2().toString(true), | 196 | (const char*) wlan->macAddress2().toString(true), |
197 | (const char*) wlan->macAddress1().toString(true), | 197 | (const char*) wlan->macAddress1().toString(true), |
198 | (const char*) wlan->macAddress3().toString(true) ); | 198 | (const char*) wlan->macAddress3().toString(true) ); |
199 | } | 199 | } |
200 | return; | 200 | return; |
201 | } | 201 | } |
202 | } | 202 | } |
203 | private: | 203 | private: |
204 | OPacketCapturer* cap; | 204 | OPacketCapturer* cap; |
205 | OWirelessNetworkInterface* wiface; | 205 | OWirelessNetworkInterface* wiface; |
206 | }; | 206 | }; |
207 | 207 | ||
208 | 208 | ||
209 | int main( int argc, char** argv ) | 209 | int main( int argc, char** argv ) |
210 | { | 210 | { |
211 | Wellenreiter w( argc, argv ); | 211 | Wellenreiter w( argc, argv ); |
212 | w.exec(); | 212 | w.exec(); |
213 | return 0; | 213 | return 0; |
214 | } | 214 | } |
215 | 215 | ||
216 | #include "miniwellenreiter.moc" | 216 | #include "miniwellenreiter.moc" |
217 | 217 | ||
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index f6d05ea..523be3e 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -425,633 +425,633 @@ OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_ | |||
425 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); | 425 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); |
426 | 426 | ||
427 | switch ( type() ) | 427 | switch ( type() ) |
428 | { | 428 | { |
429 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 429 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
430 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 430 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
431 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; | 431 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
432 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); | 432 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); |
433 | } | 433 | } |
434 | } | 434 | } |
435 | 435 | ||
436 | OWaveLanPacket::~OWaveLanPacket() | 436 | OWaveLanPacket::~OWaveLanPacket() |
437 | { | 437 | { |
438 | } | 438 | } |
439 | 439 | ||
440 | 440 | ||
441 | int OWaveLanPacket::duration() const | 441 | int OWaveLanPacket::duration() const |
442 | { | 442 | { |
443 | return _wlanhdr->duration; | 443 | return _wlanhdr->duration; |
444 | } | 444 | } |
445 | 445 | ||
446 | 446 | ||
447 | OMacAddress OWaveLanPacket::macAddress1() const | 447 | OMacAddress OWaveLanPacket::macAddress1() const |
448 | { | 448 | { |
449 | return OMacAddress( _wlanhdr->mac1 ); | 449 | return OMacAddress( _wlanhdr->mac1 ); |
450 | } | 450 | } |
451 | 451 | ||
452 | 452 | ||
453 | OMacAddress OWaveLanPacket::macAddress2() const | 453 | OMacAddress OWaveLanPacket::macAddress2() const |
454 | { | 454 | { |
455 | return OMacAddress( _wlanhdr->mac2 ); | 455 | return OMacAddress( _wlanhdr->mac2 ); |
456 | } | 456 | } |
457 | 457 | ||
458 | 458 | ||
459 | OMacAddress OWaveLanPacket::macAddress3() const | 459 | OMacAddress OWaveLanPacket::macAddress3() const |
460 | { | 460 | { |
461 | return OMacAddress( _wlanhdr->mac3 ); | 461 | return OMacAddress( _wlanhdr->mac3 ); |
462 | } | 462 | } |
463 | 463 | ||
464 | 464 | ||
465 | OMacAddress OWaveLanPacket::macAddress4() const | 465 | OMacAddress OWaveLanPacket::macAddress4() const |
466 | { | 466 | { |
467 | return OMacAddress( _wlanhdr->mac4 ); | 467 | return OMacAddress( _wlanhdr->mac4 ); |
468 | } | 468 | } |
469 | 469 | ||
470 | 470 | ||
471 | int OWaveLanPacket::subType() const | 471 | int OWaveLanPacket::subType() const |
472 | { | 472 | { |
473 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 473 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
474 | } | 474 | } |
475 | 475 | ||
476 | 476 | ||
477 | int OWaveLanPacket::type() const | 477 | int OWaveLanPacket::type() const |
478 | { | 478 | { |
479 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 479 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
480 | } | 480 | } |
481 | 481 | ||
482 | 482 | ||
483 | int OWaveLanPacket::version() const | 483 | int OWaveLanPacket::version() const |
484 | { | 484 | { |
485 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 485 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
486 | } | 486 | } |
487 | 487 | ||
488 | 488 | ||
489 | bool OWaveLanPacket::fromDS() const | 489 | bool OWaveLanPacket::fromDS() const |
490 | { | 490 | { |
491 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 491 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
492 | } | 492 | } |
493 | 493 | ||
494 | 494 | ||
495 | bool OWaveLanPacket::toDS() const | 495 | bool OWaveLanPacket::toDS() const |
496 | { | 496 | { |
497 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 497 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
498 | } | 498 | } |
499 | 499 | ||
500 | 500 | ||
501 | bool OWaveLanPacket::usesPowerManagement() const | 501 | bool OWaveLanPacket::usesPowerManagement() const |
502 | { | 502 | { |
503 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 503 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
504 | } | 504 | } |
505 | 505 | ||
506 | 506 | ||
507 | bool OWaveLanPacket::usesWep() const | 507 | bool OWaveLanPacket::usesWep() const |
508 | { | 508 | { |
509 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 509 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
510 | } | 510 | } |
511 | 511 | ||
512 | 512 | ||
513 | /*====================================================================================== | 513 | /*====================================================================================== |
514 | * OWaveLanManagementPacket | 514 | * OWaveLanManagementPacket |
515 | *======================================================================================*/ | 515 | *======================================================================================*/ |
516 | 516 | ||
517 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 517 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
518 | :QObject( parent, "802.11 Management" ), _header( data ), | 518 | :QObject( parent, "802.11 Management" ), _header( data ), |
519 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 519 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
520 | { | 520 | { |
521 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); | 521 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); |
522 | qDebug( "Detected subtype is '%s'", (const char*) managementType() ); | 522 | qDebug( "Detected subtype is '%s'", (const char*) managementType() ); |
523 | 523 | ||
524 | // grab tagged values | 524 | // grab tagged values |
525 | const unsigned char* ptr = (const unsigned char*) (_body+1); | 525 | const unsigned char* ptr = (const unsigned char*) (_body+1); |
526 | while (ptr < end) | 526 | while (ptr < end) |
527 | { | 527 | { |
528 | switch ( *ptr ) | 528 | switch ( *ptr ) |
529 | { | 529 | { |
530 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | 530 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; |
531 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | 531 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; |
532 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | 532 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; |
533 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | 533 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; |
534 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | 534 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; |
535 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | 535 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; |
536 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | 536 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; |
537 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | 537 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; |
538 | } | 538 | } |
539 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | 539 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value |
540 | ptr+= 2; // skip tag ID and length | 540 | ptr+= 2; // skip tag ID and length |
541 | } | 541 | } |
542 | } | 542 | } |
543 | 543 | ||
544 | 544 | ||
545 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 545 | OWaveLanManagementPacket::~OWaveLanManagementPacket() |
546 | { | 546 | { |
547 | } | 547 | } |
548 | 548 | ||
549 | 549 | ||
550 | QString OWaveLanManagementPacket::managementType() const | 550 | QString OWaveLanManagementPacket::managementType() const |
551 | { | 551 | { |
552 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 552 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
553 | { | 553 | { |
554 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | 554 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; |
555 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | 555 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; |
556 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | 556 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; |
557 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | 557 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; |
558 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | 558 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; |
559 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; | 559 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; |
560 | case ST_BEACON: return "Beacon"; break; | 560 | case ST_BEACON: return "Beacon"; break; |
561 | case ST_ATIM: return "Atim"; break; | 561 | case ST_ATIM: return "Atim"; break; |
562 | case ST_DISASSOC: return "Disassociation"; break; | 562 | case ST_DISASSOC: return "Disassociation"; break; |
563 | case ST_AUTH: return "Authentication"; break; | 563 | case ST_AUTH: return "Authentication"; break; |
564 | case ST_DEAUTH: return "Deathentication"; break; | 564 | case ST_DEAUTH: return "Deathentication"; break; |
565 | default: | 565 | default: |
566 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); | 566 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); |
567 | return "Unknown"; | 567 | return "Unknown"; |
568 | } | 568 | } |
569 | } | 569 | } |
570 | 570 | ||
571 | 571 | ||
572 | int OWaveLanManagementPacket::beaconInterval() const | 572 | int OWaveLanManagementPacket::beaconInterval() const |
573 | { | 573 | { |
574 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | 574 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); |
575 | } | 575 | } |
576 | 576 | ||
577 | 577 | ||
578 | int OWaveLanManagementPacket::capabilities() const | 578 | int OWaveLanManagementPacket::capabilities() const |
579 | { | 579 | { |
580 | return EXTRACT_LE_16BITS( &_body->capability_info ); | 580 | return EXTRACT_LE_16BITS( &_body->capability_info ); |
581 | } | 581 | } |
582 | 582 | ||
583 | 583 | ||
584 | bool OWaveLanManagementPacket::canESS() const | 584 | bool OWaveLanManagementPacket::canESS() const |
585 | { | 585 | { |
586 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 586 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
587 | } | 587 | } |
588 | 588 | ||
589 | 589 | ||
590 | bool OWaveLanManagementPacket::canIBSS() const | 590 | bool OWaveLanManagementPacket::canIBSS() const |
591 | { | 591 | { |
592 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 592 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
593 | } | 593 | } |
594 | 594 | ||
595 | 595 | ||
596 | bool OWaveLanManagementPacket::canCFP() const | 596 | bool OWaveLanManagementPacket::canCFP() const |
597 | { | 597 | { |
598 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 598 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
599 | } | 599 | } |
600 | 600 | ||
601 | 601 | ||
602 | bool OWaveLanManagementPacket::canCFP_REQ() const | 602 | bool OWaveLanManagementPacket::canCFP_REQ() const |
603 | { | 603 | { |
604 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 604 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
605 | } | 605 | } |
606 | 606 | ||
607 | 607 | ||
608 | bool OWaveLanManagementPacket::canPrivacy() const | 608 | bool OWaveLanManagementPacket::canPrivacy() const |
609 | { | 609 | { |
610 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 610 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
611 | } | 611 | } |
612 | 612 | ||
613 | 613 | ||
614 | /*====================================================================================== | 614 | /*====================================================================================== |
615 | * OWaveLanManagementSSID | 615 | * OWaveLanManagementSSID |
616 | *======================================================================================*/ | 616 | *======================================================================================*/ |
617 | 617 | ||
618 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | 618 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) |
619 | :QObject( parent, "802.11 SSID" ), _data( data ) | 619 | :QObject( parent, "802.11 SSID" ), _data( data ) |
620 | { | 620 | { |
621 | qDebug( "OWaveLanManagementSSID()" ); | 621 | qDebug( "OWaveLanManagementSSID()" ); |
622 | } | 622 | } |
623 | 623 | ||
624 | 624 | ||
625 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | 625 | OWaveLanManagementSSID::~OWaveLanManagementSSID() |
626 | { | 626 | { |
627 | } | 627 | } |
628 | 628 | ||
629 | 629 | ||
630 | QString OWaveLanManagementSSID::ID() const | 630 | QString OWaveLanManagementSSID::ID() const |
631 | { | 631 | { |
632 | int length = _data->length; | 632 | int length = _data->length; |
633 | if ( length > 32 ) length = 32; | 633 | if ( length > 32 ) length = 32; |
634 | char essid[length+1]; | 634 | char essid[length+1]; |
635 | memcpy( &essid, &_data->ssid, length ); | 635 | memcpy( &essid, &_data->ssid, length ); |
636 | essid[length] = 0x0; | 636 | essid[length] = 0x0; |
637 | return essid; | 637 | return essid; |
638 | } | 638 | } |
639 | 639 | ||
640 | 640 | ||
641 | /*====================================================================================== | 641 | /*====================================================================================== |
642 | * OWaveLanManagementRates | 642 | * OWaveLanManagementRates |
643 | *======================================================================================*/ | 643 | *======================================================================================*/ |
644 | 644 | ||
645 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) | 645 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) |
646 | :QObject( parent, "802.11 Rates" ), _data( data ) | 646 | :QObject( parent, "802.11 Rates" ), _data( data ) |
647 | { | 647 | { |
648 | qDebug( "OWaveLanManagementRates()" ); | 648 | qDebug( "OWaveLanManagementRates()" ); |
649 | } | 649 | } |
650 | 650 | ||
651 | 651 | ||
652 | OWaveLanManagementRates::~OWaveLanManagementRates() | 652 | OWaveLanManagementRates::~OWaveLanManagementRates() |
653 | { | 653 | { |
654 | } | 654 | } |
655 | 655 | ||
656 | /*====================================================================================== | 656 | /*====================================================================================== |
657 | * OWaveLanManagementCF | 657 | * OWaveLanManagementCF |
658 | *======================================================================================*/ | 658 | *======================================================================================*/ |
659 | 659 | ||
660 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) | 660 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) |
661 | :QObject( parent, "802.11 CF" ), _data( data ) | 661 | :QObject( parent, "802.11 CF" ), _data( data ) |
662 | { | 662 | { |
663 | qDebug( "OWaveLanManagementCF()" ); | 663 | qDebug( "OWaveLanManagementCF()" ); |
664 | } | 664 | } |
665 | 665 | ||
666 | 666 | ||
667 | OWaveLanManagementCF::~OWaveLanManagementCF() | 667 | OWaveLanManagementCF::~OWaveLanManagementCF() |
668 | { | 668 | { |
669 | } | 669 | } |
670 | 670 | ||
671 | /*====================================================================================== | 671 | /*====================================================================================== |
672 | * OWaveLanManagementFH | 672 | * OWaveLanManagementFH |
673 | *======================================================================================*/ | 673 | *======================================================================================*/ |
674 | 674 | ||
675 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | 675 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) |
676 | :QObject( parent, "802.11 FH" ), _data( data ) | 676 | :QObject( parent, "802.11 FH" ), _data( data ) |
677 | { | 677 | { |
678 | qDebug( "OWaveLanManagementFH()" ); | 678 | qDebug( "OWaveLanManagementFH()" ); |
679 | } | 679 | } |
680 | 680 | ||
681 | 681 | ||
682 | OWaveLanManagementFH::~OWaveLanManagementFH() | 682 | OWaveLanManagementFH::~OWaveLanManagementFH() |
683 | { | 683 | { |
684 | } | 684 | } |
685 | 685 | ||
686 | /*====================================================================================== | 686 | /*====================================================================================== |
687 | * OWaveLanManagementDS | 687 | * OWaveLanManagementDS |
688 | *======================================================================================*/ | 688 | *======================================================================================*/ |
689 | 689 | ||
690 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | 690 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) |
691 | :QObject( parent, "802.11 DS" ), _data( data ) | 691 | :QObject( parent, "802.11 DS" ), _data( data ) |
692 | { | 692 | { |
693 | qDebug( "OWaveLanManagementDS()" ); | 693 | qDebug( "OWaveLanManagementDS()" ); |
694 | } | 694 | } |
695 | 695 | ||
696 | 696 | ||
697 | OWaveLanManagementDS::~OWaveLanManagementDS() | 697 | OWaveLanManagementDS::~OWaveLanManagementDS() |
698 | { | 698 | { |
699 | } | 699 | } |
700 | 700 | ||
701 | 701 | ||
702 | int OWaveLanManagementDS::channel() const | 702 | int OWaveLanManagementDS::channel() const |
703 | { | 703 | { |
704 | return _data->channel; | 704 | return _data->channel; |
705 | } | 705 | } |
706 | 706 | ||
707 | /*====================================================================================== | 707 | /*====================================================================================== |
708 | * OWaveLanManagementTim | 708 | * OWaveLanManagementTim |
709 | *======================================================================================*/ | 709 | *======================================================================================*/ |
710 | 710 | ||
711 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | 711 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) |
712 | :QObject( parent, "802.11 Tim" ), _data( data ) | 712 | :QObject( parent, "802.11 Tim" ), _data( data ) |
713 | { | 713 | { |
714 | qDebug( "OWaveLanManagementTim()" ); | 714 | qDebug( "OWaveLanManagementTim()" ); |
715 | } | 715 | } |
716 | 716 | ||
717 | 717 | ||
718 | OWaveLanManagementTim::~OWaveLanManagementTim() | 718 | OWaveLanManagementTim::~OWaveLanManagementTim() |
719 | { | 719 | { |
720 | } | 720 | } |
721 | 721 | ||
722 | /*====================================================================================== | 722 | /*====================================================================================== |
723 | * OWaveLanManagementIBSS | 723 | * OWaveLanManagementIBSS |
724 | *======================================================================================*/ | 724 | *======================================================================================*/ |
725 | 725 | ||
726 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | 726 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) |
727 | :QObject( parent, "802.11 IBSS" ), _data( data ) | 727 | :QObject( parent, "802.11 IBSS" ), _data( data ) |
728 | { | 728 | { |
729 | qDebug( "OWaveLanManagementIBSS()" ); | 729 | qDebug( "OWaveLanManagementIBSS()" ); |
730 | } | 730 | } |
731 | 731 | ||
732 | 732 | ||
733 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | 733 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() |
734 | { | 734 | { |
735 | } | 735 | } |
736 | 736 | ||
737 | /*====================================================================================== | 737 | /*====================================================================================== |
738 | * OWaveLanManagementChallenge | 738 | * OWaveLanManagementChallenge |
739 | *======================================================================================*/ | 739 | *======================================================================================*/ |
740 | 740 | ||
741 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | 741 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) |
742 | :QObject( parent, "802.11 Challenge" ), _data( data ) | 742 | :QObject( parent, "802.11 Challenge" ), _data( data ) |
743 | { | 743 | { |
744 | qDebug( "OWaveLanManagementChallenge()" ); | 744 | qDebug( "OWaveLanManagementChallenge()" ); |
745 | } | 745 | } |
746 | 746 | ||
747 | 747 | ||
748 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | 748 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() |
749 | { | 749 | { |
750 | } | 750 | } |
751 | 751 | ||
752 | /*====================================================================================== | 752 | /*====================================================================================== |
753 | * OWaveLanDataPacket | 753 | * OWaveLanDataPacket |
754 | *======================================================================================*/ | 754 | *======================================================================================*/ |
755 | 755 | ||
756 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 756 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
757 | :QObject( parent, "802.11 Data" ), _header( data ) | 757 | :QObject( parent, "802.11 Data" ), _header( data ) |
758 | { | 758 | { |
759 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); | 759 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); |
760 | 760 | ||
761 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 761 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
762 | 762 | ||
763 | #warning The next line works for most cases, but can not be correct generally! | 763 | #warning The next line works for most cases, but can not be correct generally! |
764 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 764 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
765 | 765 | ||
766 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); | 766 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
767 | } | 767 | } |
768 | 768 | ||
769 | 769 | ||
770 | OWaveLanDataPacket::~OWaveLanDataPacket() | 770 | OWaveLanDataPacket::~OWaveLanDataPacket() |
771 | { | 771 | { |
772 | } | 772 | } |
773 | 773 | ||
774 | 774 | ||
775 | /*====================================================================================== | 775 | /*====================================================================================== |
776 | * OLLCPacket | 776 | * OLLCPacket |
777 | *======================================================================================*/ | 777 | *======================================================================================*/ |
778 | 778 | ||
779 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 779 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
780 | :QObject( parent, "802.11 LLC" ), _header( data ) | 780 | :QObject( parent, "802.11 LLC" ), _header( data ) |
781 | { | 781 | { |
782 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); | 782 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); |
783 | 783 | ||
784 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 784 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
785 | { | 785 | { |
786 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 786 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); |
787 | 787 | ||
788 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 788 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
789 | { | 789 | { |
790 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 790 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
791 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 791 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
792 | default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 792 | default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); |
793 | } | 793 | } |
794 | 794 | ||
795 | } | 795 | } |
796 | } | 796 | } |
797 | 797 | ||
798 | 798 | ||
799 | OLLCPacket::~OLLCPacket() | 799 | OLLCPacket::~OLLCPacket() |
800 | { | 800 | { |
801 | } | 801 | } |
802 | 802 | ||
803 | 803 | ||
804 | /*====================================================================================== | 804 | /*====================================================================================== |
805 | * OWaveLanControlPacket | 805 | * OWaveLanControlPacket |
806 | *======================================================================================*/ | 806 | *======================================================================================*/ |
807 | 807 | ||
808 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | 808 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) |
809 | :QObject( parent, "802.11 Data" ), _header( data ) | 809 | :QObject( parent, "802.11 Control" ), _header( data ) |
810 | { | 810 | { |
811 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); | 811 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); |
812 | //TODO: Implement this | 812 | //TODO: Implement this |
813 | } | 813 | } |
814 | 814 | ||
815 | 815 | ||
816 | OWaveLanControlPacket::~OWaveLanControlPacket() | 816 | OWaveLanControlPacket::~OWaveLanControlPacket() |
817 | { | 817 | { |
818 | } | 818 | } |
819 | 819 | ||
820 | 820 | ||
821 | /*====================================================================================== | 821 | /*====================================================================================== |
822 | * OPacketCapturer | 822 | * OPacketCapturer |
823 | *======================================================================================*/ | 823 | *======================================================================================*/ |
824 | 824 | ||
825 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 825 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
826 | :QObject( parent, name ), _name( QString::null ), _open( false ), | 826 | :QObject( parent, name ), _name( QString::null ), _open( false ), |
827 | _pch( 0 ), _pcd( 0 ), _sn( 0 ) | 827 | _pch( 0 ), _pcd( 0 ), _sn( 0 ) |
828 | { | 828 | { |
829 | } | 829 | } |
830 | 830 | ||
831 | 831 | ||
832 | OPacketCapturer::~OPacketCapturer() | 832 | OPacketCapturer::~OPacketCapturer() |
833 | { | 833 | { |
834 | if ( _open ) | 834 | if ( _open ) |
835 | { | 835 | { |
836 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); | 836 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); |
837 | close(); | 837 | close(); |
838 | } | 838 | } |
839 | } | 839 | } |
840 | 840 | ||
841 | 841 | ||
842 | void OPacketCapturer::setBlocking( bool b ) | 842 | void OPacketCapturer::setBlocking( bool b ) |
843 | { | 843 | { |
844 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | 844 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) |
845 | { | 845 | { |
846 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); | 846 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); |
847 | } | 847 | } |
848 | else | 848 | else |
849 | { | 849 | { |
850 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); | 850 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); |
851 | } | 851 | } |
852 | } | 852 | } |
853 | 853 | ||
854 | 854 | ||
855 | bool OPacketCapturer::blocking() const | 855 | bool OPacketCapturer::blocking() const |
856 | { | 856 | { |
857 | int b = pcap_getnonblock( _pch, _errbuf ); | 857 | int b = pcap_getnonblock( _pch, _errbuf ); |
858 | if ( b == -1 ) | 858 | if ( b == -1 ) |
859 | { | 859 | { |
860 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); | 860 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); |
861 | return -1; | 861 | return -1; |
862 | } | 862 | } |
863 | return !b; | 863 | return !b; |
864 | } | 864 | } |
865 | 865 | ||
866 | 866 | ||
867 | void OPacketCapturer::close() | 867 | void OPacketCapturer::close() |
868 | { | 868 | { |
869 | if ( _open ) | 869 | if ( _open ) |
870 | { | 870 | { |
871 | if ( _sn ) | 871 | if ( _sn ) |
872 | { | 872 | { |
873 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 873 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
874 | delete _sn; | 874 | delete _sn; |
875 | } | 875 | } |
876 | if ( _pcd ) | 876 | if ( _pcd ) |
877 | { | 877 | { |
878 | pcap_dump_close( _pcd ); | 878 | pcap_dump_close( _pcd ); |
879 | _pcd = 0; | 879 | _pcd = 0; |
880 | } | 880 | } |
881 | pcap_close( _pch ); | 881 | pcap_close( _pch ); |
882 | _open = false; | 882 | _open = false; |
883 | } | 883 | } |
884 | 884 | ||
885 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); | 885 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); |
886 | qDebug( "--------------------------------------------------" ); | 886 | qDebug( "--------------------------------------------------" ); |
887 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) | 887 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) |
888 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); | 888 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); |
889 | qDebug( "--------------------------------------------------" ); | 889 | qDebug( "--------------------------------------------------" ); |
890 | 890 | ||
891 | } | 891 | } |
892 | 892 | ||
893 | 893 | ||
894 | int OPacketCapturer::dataLink() const | 894 | int OPacketCapturer::dataLink() const |
895 | { | 895 | { |
896 | return pcap_datalink( _pch ); | 896 | return pcap_datalink( _pch ); |
897 | } | 897 | } |
898 | 898 | ||
899 | 899 | ||
900 | int OPacketCapturer::fileno() const | 900 | int OPacketCapturer::fileno() const |
901 | { | 901 | { |
902 | if ( _open ) | 902 | if ( _open ) |
903 | { | 903 | { |
904 | return pcap_fileno( _pch ); | 904 | return pcap_fileno( _pch ); |
905 | } | 905 | } |
906 | else | 906 | else |
907 | { | 907 | { |
908 | return -1; | 908 | return -1; |
909 | } | 909 | } |
910 | } | 910 | } |
911 | 911 | ||
912 | OPacket* OPacketCapturer::next() | 912 | OPacket* OPacketCapturer::next() |
913 | { | 913 | { |
914 | packetheaderstruct header; | 914 | packetheaderstruct header; |
915 | qDebug( "==> OPacketCapturer::next()" ); | 915 | qDebug( "==> OPacketCapturer::next()" ); |
916 | const unsigned char* pdata = pcap_next( _pch, &header ); | 916 | const unsigned char* pdata = pcap_next( _pch, &header ); |
917 | qDebug( "<== OPacketCapturer::next()" ); | 917 | qDebug( "<== OPacketCapturer::next()" ); |
918 | if ( _pcd ) | 918 | if ( _pcd ) |
919 | pcap_dump( (u_char*) _pcd, &header, pdata ); | 919 | pcap_dump( (u_char*) _pcd, &header, pdata ); |
920 | 920 | ||
921 | if ( pdata && header.len ) | 921 | if ( pdata && header.len ) |
922 | { | 922 | { |
923 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); | 923 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); |
924 | // packets shouldn't be inserted in the QObject child-parent hierarchy, | 924 | // packets shouldn't be inserted in the QObject child-parent hierarchy, |
925 | // because due to memory constraints they will be deleted as soon | 925 | // because due to memory constraints they will be deleted as soon |
926 | // as possible - that is right after they have been processed | 926 | // as possible - that is right after they have been processed |
927 | // by emit() [ see below ] | 927 | // by emit() [ see below ] |
928 | //TODO: make gathering statistics optional, because it takes time | 928 | //TODO: make gathering statistics optional, because it takes time |
929 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); | 929 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); |
930 | 930 | ||
931 | return p; | 931 | return p; |
932 | } | 932 | } |
933 | else | 933 | else |
934 | { | 934 | { |
935 | qWarning( "OPacketCapturer::next() - no packet received!" ); | 935 | qWarning( "OPacketCapturer::next() - no packet received!" ); |
936 | return 0; | 936 | return 0; |
937 | } | 937 | } |
938 | } | 938 | } |
939 | 939 | ||
940 | 940 | ||
941 | bool OPacketCapturer::open( const QString& name, const QString& filename ) | 941 | bool OPacketCapturer::open( const QString& name, const QString& filename ) |
942 | { | 942 | { |
943 | if ( _open ) | 943 | if ( _open ) |
944 | { | 944 | { |
945 | if ( name == _name ) // ignore opening an already openend device | 945 | if ( name == _name ) // ignore opening an already openend device |
946 | { | 946 | { |
947 | return true; | 947 | return true; |
948 | } | 948 | } |
949 | else // close the last opened device | 949 | else // close the last opened device |
950 | { | 950 | { |
951 | close(); | 951 | close(); |
952 | } | 952 | } |
953 | } | 953 | } |
954 | 954 | ||
955 | _name = name; | 955 | _name = name; |
956 | 956 | ||
957 | // open libpcap | 957 | // open libpcap |
958 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); | 958 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); |
959 | 959 | ||
960 | if ( !handle ) | 960 | if ( !handle ) |
961 | { | 961 | { |
962 | qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); | 962 | qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); |
963 | return false; | 963 | return false; |
964 | } | 964 | } |
965 | 965 | ||
966 | qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); | 966 | qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); |
967 | _pch = handle; | 967 | _pch = handle; |
968 | _open = true; | 968 | _open = true; |
969 | _stats.clear(); | 969 | _stats.clear(); |
970 | 970 | ||
971 | // in case we have an application object, create a socket notifier | 971 | // in case we have an application object, create a socket notifier |
972 | if ( qApp ) //TODO: I don't like this here... | 972 | if ( qApp ) //TODO: I don't like this here... |
973 | { | 973 | { |
974 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 974 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
975 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 975 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
976 | } | 976 | } |
977 | 977 | ||
978 | // if requested, open a dump | 978 | // if requested, open a dump |
979 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); | 979 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); |
980 | if ( !dump ) | 980 | if ( !dump ) |
981 | { | 981 | { |
982 | qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); | 982 | qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); |
983 | return false; | 983 | return false; |
984 | } | 984 | } |
985 | qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); | 985 | qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); |
986 | _pcd = dump; | 986 | _pcd = dump; |
987 | 987 | ||
988 | return true; | 988 | return true; |
989 | } | 989 | } |
990 | 990 | ||
991 | 991 | ||
992 | bool OPacketCapturer::open( const QFile& file ) | 992 | bool OPacketCapturer::open( const QFile& file ) |
993 | { | 993 | { |
994 | QString name = file.name(); | 994 | QString name = file.name(); |
995 | 995 | ||
996 | if ( _open ) | 996 | if ( _open ) |
997 | { | 997 | { |
998 | close(); | 998 | close(); |
999 | if ( name == _name ) // ignore opening an already openend device | 999 | if ( name == _name ) // ignore opening an already openend device |
1000 | { | 1000 | { |
1001 | return true; | 1001 | return true; |
1002 | } | 1002 | } |
1003 | else // close the last opened device | 1003 | else // close the last opened device |
1004 | { | 1004 | { |
1005 | close(); | 1005 | close(); |
1006 | } | 1006 | } |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | _name = name; | 1009 | _name = name; |
1010 | 1010 | ||
1011 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); | 1011 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); |
1012 | 1012 | ||
1013 | if ( handle ) | 1013 | if ( handle ) |
1014 | { | 1014 | { |
1015 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); | 1015 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); |
1016 | _pch = handle; | 1016 | _pch = handle; |
1017 | _open = true; | 1017 | _open = true; |
1018 | 1018 | ||
1019 | // in case we have an application object, create a socket notifier | 1019 | // in case we have an application object, create a socket notifier |
1020 | if ( qApp ) | 1020 | if ( qApp ) |
1021 | { | 1021 | { |
1022 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1022 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
1023 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1023 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | return true; | 1026 | return true; |
1027 | } | 1027 | } |
1028 | else | 1028 | else |
1029 | { | 1029 | { |
1030 | qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); | 1030 | qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); |
1031 | return false; | 1031 | return false; |
1032 | } | 1032 | } |
1033 | 1033 | ||
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | 1036 | ||
1037 | bool OPacketCapturer::isOpen() const | 1037 | bool OPacketCapturer::isOpen() const |
1038 | { | 1038 | { |
1039 | return _open; | 1039 | return _open; |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | 1042 | ||
1043 | void OPacketCapturer::readyToReceive() | 1043 | void OPacketCapturer::readyToReceive() |
1044 | { | 1044 | { |
1045 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); | 1045 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); |
1046 | OPacket* p = next(); | 1046 | OPacket* p = next(); |
1047 | emit receivedPacket( p ); | 1047 | emit receivedPacket( p ); |
1048 | // emit is synchronous - packet has been dealt with, now it's safe to delete | 1048 | // emit is synchronous - packet has been dealt with, now it's safe to delete |
1049 | delete p; | 1049 | delete p; |
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | 1052 | ||
1053 | const QMap<QString,int>& OPacketCapturer::statistics() const | 1053 | const QMap<QString,int>& OPacketCapturer::statistics() const |
1054 | { | 1054 | { |
1055 | return _stats; | 1055 | return _stats; |
1056 | } | 1056 | } |
1057 | 1057 | ||