-rw-r--r-- | libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp | 11 | ||||
-rw-r--r-- | libopie2/opiecore/oapplication.cpp | 14 | ||||
-rw-r--r-- | libopie2/opiecore/oapplication.h | 16 | ||||
-rw-r--r-- | libopie2/opienet/802_11_user.h | 20 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 40 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 7 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 253 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 160 |
8 files changed, 461 insertions, 60 deletions
diff --git a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp index aec9cc7..7581888 100644 --- a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp +++ b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp | |||
@@ -163,30 +163,33 @@ public slots: | |||
163 | void receivePacket(OPacket* p) | 163 | void receivePacket(OPacket* p) |
164 | { | 164 | { |
165 | if (!p) | 165 | if (!p) |
166 | { | 166 | { |
167 | printf( "(empty packet received)\n" ); | 167 | printf( "(empty packet received)\n" ); |
168 | return; | 168 | return; |
169 | } | 169 | } |
170 | 170 | ||
171 | OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" ); | 171 | OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" ); |
172 | 172 | ||
173 | if ( beacon ) | 173 | if ( beacon ) |
174 | { | 174 | { |
175 | if ( stations.find( beacon->SSID() ) ) | 175 | OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); |
176 | stations[beacon->SSID()]->beacons++; | 176 | QString essid = ssid ? ssid->ID() : "<unknown>"; |
177 | |||
178 | if ( stations.find( essid ) ) | ||
179 | stations[essid]->beacons++; | ||
177 | else | 180 | else |
178 | { | 181 | { |
179 | printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) beacon->SSID() ); | 182 | printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid ); |
180 | stations.insert( beacon->SSID(), new Station( "unknown", wiface->channel(), | 183 | stations.insert( essid, new Station( "unknown", wiface->channel(), |
181 | ((OWaveLanPacket*) beacon->parent())->usesWep() ) ); | 184 | ((OWaveLanPacket*) beacon->parent())->usesWep() ) ); |
182 | } | 185 | } |
183 | } | 186 | } |
184 | } | 187 | } |
185 | private: | 188 | private: |
186 | OPacketCapturer* cap; | 189 | OPacketCapturer* cap; |
187 | OWirelessNetworkInterface* wiface; | 190 | OWirelessNetworkInterface* wiface; |
188 | }; | 191 | }; |
189 | 192 | ||
190 | 193 | ||
191 | int main( int argc, char** argv ) | 194 | int main( int argc, char** argv ) |
192 | { | 195 | { |
diff --git a/libopie2/opiecore/oapplication.cpp b/libopie2/opiecore/oapplication.cpp index a0abcc2..12418d5 100644 --- a/libopie2/opiecore/oapplication.cpp +++ b/libopie2/opiecore/oapplication.cpp | |||
@@ -83,28 +83,42 @@ void OApplication::init() | |||
83 | { | 83 | { |
84 | d = new OApplicationPrivate(); | 84 | d = new OApplicationPrivate(); |
85 | if ( !OApplication::_instance ) | 85 | if ( !OApplication::_instance ) |
86 | { | 86 | { |
87 | OApplication::_instance = this; | 87 | OApplication::_instance = this; |
88 | } | 88 | } |
89 | else | 89 | else |
90 | { | 90 | { |
91 | qFatal( "OApplication: Can't create more than one OApplication object. Aborting." ); | 91 | qFatal( "OApplication: Can't create more than one OApplication object. Aborting." ); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | |||
95 | void OApplication::setMainWidget( QWidget* widget ) | 96 | void OApplication::setMainWidget( QWidget* widget ) |
96 | { | 97 | { |
97 | showMainWidget( widget ); | 98 | showMainWidget( widget ); |
98 | } | 99 | } |
99 | 100 | ||
101 | |||
100 | void OApplication::showMainWidget( QWidget* widget, bool nomax ) | 102 | void OApplication::showMainWidget( QWidget* widget, bool nomax ) |
101 | { | 103 | { |
102 | #ifdef Q_WS_QWS | 104 | #ifdef Q_WS_QWS |
103 | QPEApplication::showMainWidget( widget, nomax ); | 105 | QPEApplication::showMainWidget( widget, nomax ); |
104 | #else | 106 | #else |
105 | QApplication::setMainWidget( widget ); | 107 | QApplication::setMainWidget( widget ); |
106 | widget->show(); | 108 | widget->show(); |
107 | #endif | 109 | #endif |
108 | widget->setCaption( _appname ); | 110 | widget->setCaption( _appname ); |
111 | } | ||
109 | 112 | ||
113 | |||
114 | void OApplication::setTitle( QString title ) const | ||
115 | { | ||
116 | if ( mainWidget() ) | ||
117 | { | ||
118 | if ( !title.isNull() ) | ||
119 | mainWidget()->setCaption( QString(_appname) + QString( " - " ) + title ); | ||
120 | else | ||
121 | mainWidget()->setCaption( _appname ); | ||
110 | } | 122 | } |
123 | } | ||
124 | |||
diff --git a/libopie2/opiecore/oapplication.h b/libopie2/opiecore/oapplication.h index 736e786..4d25202 100644 --- a/libopie2/opiecore/oapplication.h +++ b/libopie2/opiecore/oapplication.h | |||
@@ -60,55 +60,71 @@ class OApplication: public OApplicationBaseClass | |||
60 | * Destructor. Destroys the application object and its children. | 60 | * Destructor. Destroys the application object and its children. |
61 | */ | 61 | */ |
62 | virtual ~OApplication(); | 62 | virtual ~OApplication(); |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Returns the current application object. | 65 | * Returns the current application object. |
66 | * | 66 | * |
67 | * This is similar to the global @ref QApplication pointer qApp. It | 67 | * This is similar to the global @ref QApplication pointer qApp. It |
68 | * allows access to the single global OApplication object, since | 68 | * allows access to the single global OApplication object, since |
69 | * more than one cannot be created in the same application. It | 69 | * more than one cannot be created in the same application. It |
70 | * saves you the trouble of having to pass the pointer explicitly | 70 | * saves you the trouble of having to pass the pointer explicitly |
71 | * to every function that may require it. | 71 | * to every function that may require it. |
72 | * | ||
72 | * @return the current application object | 73 | * @return the current application object |
73 | */ | 74 | */ |
74 | static const OApplication* oApplication() { return _instance; }; | 75 | static const OApplication* oApplication() { return _instance; }; |
75 | 76 | ||
76 | /** | 77 | /** |
77 | * Returns the application name as given during creation. | 78 | * Returns the application name as given during creation. |
78 | * | 79 | * |
79 | * @return A reference to the application name | 80 | * @return A reference to the application name |
80 | */ | 81 | */ |
81 | const QCString& appName() const { return _appname; }; | 82 | const QCString& appName() const { return _appname; }; |
82 | 83 | ||
83 | /** | 84 | /** |
84 | * Returns the application session config object. | 85 | * Returns the application session config object. |
85 | * | 86 | * |
86 | * @return A pointer to the application's instance specific | 87 | * @return A pointer to the application's instance specific |
87 | * @ref OConfig object. | 88 | * @ref OConfig object. |
88 | * @see OConfig | 89 | * @see OConfig |
89 | */ | 90 | */ |
90 | OConfig* config(); | 91 | OConfig* config(); |
91 | 92 | ||
92 | /** | 93 | /** |
93 | * Sets the main widget - reimplemented to call showMainWidget() | 94 | * Sets the main widget - reimplemented to call showMainWidget() |
94 | * on Qt/Embedded. | 95 | * on Qt/Embedded. |
96 | * | ||
97 | * @param mainWidget the widget to become the main widget | ||
98 | * @see QWidget object | ||
95 | */ | 99 | */ |
96 | virtual void setMainWidget( QWidget *mainWidget ); | 100 | virtual void setMainWidget( QWidget *mainWidget ); |
97 | 101 | ||
98 | /** | 102 | /** |
99 | * Shows the main widget - reimplemented to call setMainWidget() | 103 | * Shows the main widget - reimplemented to call setMainWidget() |
100 | * on platforms other than Qt/Embedded. | 104 | * on platforms other than Qt/Embedded. |
105 | * | ||
106 | * @param mainWidget the widget to become the main widget | ||
107 | * @see QWidget object | ||
101 | */ | 108 | */ |
102 | virtual void showMainWidget( QWidget* widget, bool nomax = false ); | 109 | virtual void showMainWidget( QWidget* widget, bool nomax = false ); |
103 | 110 | ||
111 | /** | ||
112 | * Set the application title. The application title will be concatenated | ||
113 | * to the application name given in the constructor. | ||
114 | * | ||
115 | * @param title the title. If not given, resets caption to appname | ||
116 | */ | ||
117 | virtual void setTitle( QString title = QString::null ) const; | ||
118 | //virtual void setTitle() const; | ||
119 | |||
104 | protected: | 120 | protected: |
105 | void init(); | 121 | void init(); |
106 | 122 | ||
107 | private: | 123 | private: |
108 | const QCString _appname; | 124 | const QCString _appname; |
109 | static OApplication* _instance; | 125 | static OApplication* _instance; |
110 | OConfig* _config; | 126 | OConfig* _config; |
111 | OApplicationPrivate* d; | 127 | OApplicationPrivate* d; |
112 | }; | 128 | }; |
113 | 129 | ||
114 | #endif // OAPPLICATION_H | 130 | #endif // OAPPLICATION_H |
diff --git a/libopie2/opienet/802_11_user.h b/libopie2/opienet/802_11_user.h index 0b3f198..ffdcb93 100644 --- a/libopie2/opienet/802_11_user.h +++ b/libopie2/opienet/802_11_user.h | |||
@@ -309,53 +309,61 @@ struct cf_t { | |||
309 | }; | 309 | }; |
310 | 310 | ||
311 | 311 | ||
312 | struct tim_t { | 312 | struct tim_t { |
313 | u_int8_telement_id; | 313 | u_int8_telement_id; |
314 | u_int8_tlength; | 314 | u_int8_tlength; |
315 | u_int8_tcount; | 315 | u_int8_tcount; |
316 | u_int8_tperiod; | 316 | u_int8_tperiod; |
317 | u_int8_tbitmap_control; | 317 | u_int8_tbitmap_control; |
318 | u_int8_tbitmap[251]; | 318 | u_int8_tbitmap[251]; |
319 | }; | 319 | }; |
320 | 320 | ||
321 | |||
322 | struct ibss_t { | ||
323 | u_int8_telement_id; | ||
324 | u_int8_tlength; | ||
325 | u_int16_tatim_window; | ||
326 | }; | ||
327 | |||
328 | |||
321 | #define E_SSID 0 | 329 | #define E_SSID 0 |
322 | #define E_RATES 1 | 330 | #define E_RATES 1 |
323 | #define E_FH 2 | 331 | #define E_FH 2 |
324 | #define E_DS 3 | 332 | #define E_DS 3 |
325 | #define E_CF 4 | 333 | #define E_CF 4 |
326 | #define E_TIM 5 | 334 | #define E_TIM 5 |
327 | #define E_IBSS 6 | 335 | #define E_IBSS 6 |
328 | #define E_CHALLENGE 16 | 336 | #define E_CHALLENGE 16 |
329 | #define E_CISCO 133 | 337 | #define E_CISCO 133 |
330 | 338 | ||
331 | 339 | ||
332 | struct ieee_802_11_mgmt_body { | 340 | struct ieee_802_11_mgmt_body { |
333 | u_int8_t timestamp[8]; | 341 | u_int8_t timestamp[8]; |
334 | u_int16_t beacon_interval; | 342 | u_int16_t beacon_interval; |
335 | // u_int16_t listen_interval; | 343 | // u_int16_t listen_interval; |
336 | // u_int16_t status_code; | 344 | // u_int16_t status_code; |
337 | // u_int16_t aid; | 345 | // u_int16_t aid; |
338 | // u_char ap[6]; | 346 | // u_char ap[6]; |
339 | // u_int16_treason_code; | 347 | // u_int16_treason_code; |
340 | // u_int16_tauth_alg; | 348 | // u_int16_tauth_alg; |
341 | // u_int16_tauth_trans_seq_num; | 349 | // u_int16_tauth_trans_seq_num; |
342 | // struct challenge_t challenge; | 350 | // struct challenge_t challenge; |
343 | u_int16_tcapability_info; | 351 | u_int16_tcapability_info; |
344 | struct ssid_tssid; | 352 | // struct ssid_tssid; |
345 | struct rates_t rates; | 353 | // struct rates_t rates; |
346 | struct ds_tds; | 354 | // struct ds_tds; |
347 | struct cf_tcf; | 355 | // struct cf_tcf; |
348 | struct fh_tfh; | 356 | // struct fh_tfh; |
349 | struct tim_ttim; | 357 | // struct tim_ttim; |
350 | }; | 358 | }; |
351 | 359 | ||
352 | 360 | ||
353 | struct ieee_802_11_data_body { | 361 | struct ieee_802_11_data_body { |
354 | //FIXME | 362 | //FIXME |
355 | }; | 363 | }; |
356 | 364 | ||
357 | struct ctrl_rts_t { | 365 | struct ctrl_rts_t { |
358 | u_int16_tfc; | 366 | u_int16_tfc; |
359 | u_int16_tduration; | 367 | u_int16_tduration; |
360 | u_int8_tra[6]; | 368 | u_int8_tra[6]; |
361 | u_int8_tta[6]; | 369 | u_int8_tta[6]; |
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 1d3b9fe..25c70e0 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -282,73 +282,86 @@ bool ONetworkInterface::promiscuousMode() const | |||
282 | bool ONetworkInterface::isWireless() const | 282 | bool ONetworkInterface::isWireless() const |
283 | { | 283 | { |
284 | return ioctl( SIOCGIWNAME ); | 284 | return ioctl( SIOCGIWNAME ); |
285 | } | 285 | } |
286 | 286 | ||
287 | 287 | ||
288 | /*====================================================================================== | 288 | /*====================================================================================== |
289 | * OChannelHopper | 289 | * OChannelHopper |
290 | *======================================================================================*/ | 290 | *======================================================================================*/ |
291 | 291 | ||
292 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 292 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
293 | :QObject( 0, "Mickey's funky hopper" ), | 293 | :QObject( 0, "Mickey's funky hopper" ), |
294 | _iface( iface ), _interval( 0 ), _channel( 0 ), _tid( 0 ) | 294 | _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ), |
295 | _maxChannel( iface->channels()+1 ) | ||
295 | { | 296 | { |
296 | } | 297 | } |
297 | 298 | ||
298 | 299 | ||
299 | OChannelHopper::~OChannelHopper() | 300 | OChannelHopper::~OChannelHopper() |
300 | { | 301 | { |
301 | } | 302 | } |
302 | 303 | ||
303 | 304 | ||
305 | bool OChannelHopper::isActive() const | ||
306 | { | ||
307 | return _tid; | ||
308 | } | ||
309 | |||
310 | |||
311 | int OChannelHopper::channel() const | ||
312 | { | ||
313 | return _channel; | ||
314 | } | ||
315 | |||
316 | |||
304 | void OChannelHopper::timerEvent( QTimerEvent* ) | 317 | void OChannelHopper::timerEvent( QTimerEvent* ) |
305 | { | 318 | { |
306 | //FIXME: Get available channels from OWirelessNetworkInterface | 319 | if ( !--_channel ) _channel = _maxChannel; |
307 | if ( --_channel < 0 ) _channel = 13; | ||
308 | _iface->setChannel( _channel ); | 320 | _iface->setChannel( _channel ); |
309 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 321 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", |
310 | _channel, (const char*) _iface->name() ); | 322 | _channel, (const char*) _iface->name() ); |
311 | } | 323 | } |
312 | 324 | ||
313 | 325 | ||
314 | void OChannelHopper::setInterval( int interval ) | 326 | void OChannelHopper::setInterval( int interval ) |
315 | { | 327 | { |
316 | if ( interval == _interval ) | 328 | if ( interval == _interval ) |
317 | return; | 329 | return; |
318 | 330 | ||
319 | if ( _interval ) | 331 | if ( _interval ) |
320 | killTimer( _tid ); | 332 | killTimer( _tid ); |
321 | 333 | ||
334 | _tid = 0; | ||
322 | _interval = interval; | 335 | _interval = interval; |
323 | 336 | ||
324 | if ( _interval ) | 337 | if ( _interval ) |
325 | { | 338 | { |
326 | _tid = startTimer( interval ); | 339 | _tid = startTimer( interval ); |
327 | } | 340 | } |
328 | } | 341 | } |
329 | 342 | ||
330 | 343 | ||
331 | int OChannelHopper::interval() const | 344 | int OChannelHopper::interval() const |
332 | { | 345 | { |
333 | return _interval; | 346 | return _interval; |
334 | } | 347 | } |
335 | 348 | ||
336 | 349 | ||
337 | /*====================================================================================== | 350 | /*====================================================================================== |
338 | * OWirelessNetworkInterface | 351 | * OWirelessNetworkInterface |
339 | *======================================================================================*/ | 352 | *======================================================================================*/ |
340 | 353 | ||
341 | OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) | 354 | OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) |
342 | :ONetworkInterface( name ), _hopper( this ) | 355 | :ONetworkInterface( name ), _hopper( 0 ) |
343 | { | 356 | { |
344 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 357 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); |
345 | init(); | 358 | init(); |
346 | } | 359 | } |
347 | 360 | ||
348 | 361 | ||
349 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 362 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
350 | { | 363 | { |
351 | } | 364 | } |
352 | 365 | ||
353 | 366 | ||
354 | iwreqstruct& OWirelessNetworkInterface::iwr() const | 367 | iwreqstruct& OWirelessNetworkInterface::iwr() const |
@@ -367,31 +380,28 @@ void OWirelessNetworkInterface::init() | |||
367 | //FIXME: get these directly from the interface | 380 | //FIXME: get these directly from the interface |
368 | //FIXME: check if these channels are off-by-one | 381 | //FIXME: check if these channels are off-by-one |
369 | 382 | ||
370 | iwrangestruct range; | 383 | iwrangestruct range; |
371 | _iwr.u.data.pointer = (char*) ⦥ | 384 | _iwr.u.data.pointer = (char*) ⦥ |
372 | _iwr.u.data.length = sizeof( iwrangestruct ); | 385 | _iwr.u.data.length = sizeof( iwrangestruct ); |
373 | if ( !wioctl( SIOCGIWRANGE ) ) | 386 | if ( !wioctl( SIOCGIWRANGE ) ) |
374 | { | 387 | { |
375 | qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); | 388 | qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); |
376 | return; | 389 | return; |
377 | } | 390 | } |
378 | 391 | ||
379 | //TODO: Find out what the difference between num_channel and | ||
380 | // num_frequency is about. | ||
381 | |||
382 | for ( int i = 0; i < range.num_frequency; ++i ) | 392 | for ( int i = 0; i < range.num_frequency; ++i ) |
383 | { | 393 | { |
384 | int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 ); | 394 | int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 ); |
385 | _channels.insert( freq, i ); | 395 | _channels.insert( freq, i+1 ); |
386 | } | 396 | } |
387 | } | 397 | } |
388 | 398 | ||
389 | 399 | ||
390 | QString OWirelessNetworkInterface::associatedAP() const | 400 | QString OWirelessNetworkInterface::associatedAP() const |
391 | { | 401 | { |
392 | //FIXME: use OMacAddress | 402 | //FIXME: use OMacAddress |
393 | QString mac; | 403 | QString mac; |
394 | 404 | ||
395 | if ( ioctl( SIOCGIWAP ) ) | 405 | if ( ioctl( SIOCGIWAP ) ) |
396 | { | 406 | { |
397 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 407 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
@@ -403,31 +413,36 @@ QString OWirelessNetworkInterface::associatedAP() const | |||
403 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); | 413 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); |
404 | } | 414 | } |
405 | else | 415 | else |
406 | { | 416 | { |
407 | mac = "<Unknown>"; | 417 | mac = "<Unknown>"; |
408 | } | 418 | } |
409 | return mac; | 419 | return mac; |
410 | } | 420 | } |
411 | 421 | ||
412 | 422 | ||
413 | int OWirelessNetworkInterface::channel() const | 423 | int OWirelessNetworkInterface::channel() const |
414 | { | 424 | { |
425 | //FIXME: When monitoring enabled, then use it | ||
426 | //FIXME: to gather the current RF channel | ||
427 | //FIXME: Until then, get active channel from hopper. | ||
428 | if ( _hopper && _hopper->isActive() ) | ||
429 | return _hopper->channel(); | ||
430 | |||
415 | if ( !wioctl( SIOCGIWFREQ ) ) | 431 | if ( !wioctl( SIOCGIWFREQ ) ) |
416 | { | 432 | { |
417 | return -1; | 433 | return -1; |
418 | } | 434 | } |
419 | else | 435 | else |
420 | { | 436 | { |
421 | //FIXME: This is off-by-one !? Why? | ||
422 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ]; | 437 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ]; |
423 | } | 438 | } |
424 | } | 439 | } |
425 | 440 | ||
426 | 441 | ||
427 | void OWirelessNetworkInterface::setChannel( int c ) const | 442 | void OWirelessNetworkInterface::setChannel( int c ) const |
428 | { | 443 | { |
429 | if ( !_mon ) | 444 | if ( !_mon ) |
430 | { | 445 | { |
431 | memset( &_iwr, 0, sizeof( iwreqstruct ) ); | 446 | memset( &_iwr, 0, sizeof( iwreqstruct ) ); |
432 | _iwr.u.freq.m = c; | 447 | _iwr.u.freq.m = c; |
433 | _iwr.u.freq.e = 0; | 448 | _iwr.u.freq.e = 0; |
@@ -452,42 +467,45 @@ double OWirelessNetworkInterface::frequency() const | |||
452 | } | 467 | } |
453 | } | 468 | } |
454 | 469 | ||
455 | 470 | ||
456 | int OWirelessNetworkInterface::channels() const | 471 | int OWirelessNetworkInterface::channels() const |
457 | { | 472 | { |
458 | return _channels.count(); | 473 | return _channels.count(); |
459 | } | 474 | } |
460 | 475 | ||
461 | 476 | ||
462 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 477 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
463 | { | 478 | { |
464 | _hopper.setInterval( interval ); | 479 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
480 | _hopper->setInterval( interval ); | ||
481 | //FIXME: When and by whom will the channel hopper be deleted? | ||
465 | } | 482 | } |
466 | 483 | ||
467 | 484 | ||
468 | int OWirelessNetworkInterface::channelHopping() const | 485 | int OWirelessNetworkInterface::channelHopping() const |
469 | { | 486 | { |
470 | return _hopper.interval(); | 487 | return _hopper->interval(); |
471 | } | 488 | } |
472 | 489 | ||
473 | 490 | ||
474 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 491 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
475 | { | 492 | { |
476 | if ( _mon ) | 493 | if ( _mon ) |
477 | _mon->setEnabled( b ); | 494 | _mon->setEnabled( b ); |
478 | else | 495 | else |
479 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 496 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
480 | } | 497 | } |
481 | 498 | ||
499 | |||
482 | bool OWirelessNetworkInterface::monitorMode() const | 500 | bool OWirelessNetworkInterface::monitorMode() const |
483 | { | 501 | { |
484 | return _mon ? _mon->enabled() : false; | 502 | return _mon ? _mon->enabled() : false; |
485 | } | 503 | } |
486 | 504 | ||
487 | 505 | ||
488 | QString OWirelessNetworkInterface::nickName() const | 506 | QString OWirelessNetworkInterface::nickName() const |
489 | { | 507 | { |
490 | char str[IW_ESSID_MAX_SIZE]; | 508 | char str[IW_ESSID_MAX_SIZE]; |
491 | _iwr.u.data.pointer = &str[0]; | 509 | _iwr.u.data.pointer = &str[0]; |
492 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 510 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
493 | if ( !wioctl( SIOCGIWNICKN ) ) | 511 | if ( !wioctl( SIOCGIWNICKN ) ) |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 9a68a74..936ac85 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -133,33 +133,36 @@ class ONetworkInterface | |||
133 | bool ioctl( int call, ifreqstruct& ) const; | 133 | bool ioctl( int call, ifreqstruct& ) const; |
134 | }; | 134 | }; |
135 | 135 | ||
136 | /*====================================================================================== | 136 | /*====================================================================================== |
137 | * OChannelHopper | 137 | * OChannelHopper |
138 | *======================================================================================*/ | 138 | *======================================================================================*/ |
139 | 139 | ||
140 | class OChannelHopper : public QObject | 140 | class OChannelHopper : public QObject |
141 | { | 141 | { |
142 | public: | 142 | public: |
143 | OChannelHopper( OWirelessNetworkInterface* ); | 143 | OChannelHopper( OWirelessNetworkInterface* ); |
144 | virtual ~OChannelHopper(); | 144 | virtual ~OChannelHopper(); |
145 | bool isActive() const; | ||
146 | int channel() const; | ||
145 | virtual void timerEvent( QTimerEvent* ); | 147 | virtual void timerEvent( QTimerEvent* ); |
146 | void setInterval( int ); | 148 | void setInterval( int ); |
147 | int interval() const; | 149 | int interval() const; |
148 | 150 | ||
149 | private: | 151 | private: |
150 | OWirelessNetworkInterface* _iface; | 152 | OWirelessNetworkInterface* _iface; |
151 | int _interval; | 153 | int _interval; |
152 | int _channel; | 154 | int _channel; |
153 | int _tid; | 155 | int _tid; |
156 | int _maxChannel; | ||
154 | }; | 157 | }; |
155 | 158 | ||
156 | 159 | ||
157 | /*====================================================================================== | 160 | /*====================================================================================== |
158 | * OWirelessNetworkInterface | 161 | * OWirelessNetworkInterface |
159 | *======================================================================================*/ | 162 | *======================================================================================*/ |
160 | 163 | ||
161 | class OWirelessNetworkInterface : public ONetworkInterface | 164 | class OWirelessNetworkInterface : public ONetworkInterface |
162 | { | 165 | { |
163 | friend class OMonitoringInterface; | 166 | friend class OMonitoringInterface; |
164 | friend class OCiscoMonitoringInterface; | 167 | friend class OCiscoMonitoringInterface; |
165 | friend class OWlanNGMonitoringInterface; | 168 | friend class OWlanNGMonitoringInterface; |
@@ -175,48 +178,48 @@ class OWirelessNetworkInterface : public ONetworkInterface | |||
175 | virtual void setChannel( int ) const; | 178 | virtual void setChannel( int ) const; |
176 | virtual int channel() const; | 179 | virtual int channel() const; |
177 | virtual double frequency() const; | 180 | virtual double frequency() const; |
178 | virtual int channels() const; | 181 | virtual int channels() const; |
179 | //virtual double frequency(int) const; | 182 | //virtual double frequency(int) const; |
180 | 183 | ||
181 | virtual void setMode( Mode ) {}; | 184 | virtual void setMode( Mode ) {}; |
182 | virtual bool mode() const {}; | 185 | virtual bool mode() const {}; |
183 | 186 | ||
184 | virtual void setMonitorMode( bool ); | 187 | virtual void setMonitorMode( bool ); |
185 | virtual bool monitorMode() const; | 188 | virtual bool monitorMode() const; |
186 | 189 | ||
187 | virtual void setChannelHopping( int interval ); | 190 | virtual void setChannelHopping( int interval = 0 ); |
188 | virtual int channelHopping() const; | 191 | virtual int channelHopping() const; |
189 | 192 | ||
190 | virtual void setNickName( const QString& ) {}; | 193 | virtual void setNickName( const QString& ) {}; |
191 | virtual QString nickName() const; | 194 | virtual QString nickName() const; |
192 | 195 | ||
193 | virtual bool isAssociated() const {}; | 196 | virtual bool isAssociated() const {}; |
194 | virtual QString associatedAP() const; | 197 | virtual QString associatedAP() const; |
195 | 198 | ||
196 | virtual void setSSID( const QString& ); | 199 | virtual void setSSID( const QString& ); |
197 | virtual QString SSID() const; | 200 | virtual QString SSID() const; |
198 | 201 | ||
199 | protected: | 202 | protected: |
200 | mutable iwreqstruct _iwr; | 203 | mutable iwreqstruct _iwr; |
201 | QMap<int,int> _channels; | 204 | QMap<int,int> _channels; |
202 | 205 | ||
203 | protected: | 206 | protected: |
204 | virtual void init(); | 207 | virtual void init(); |
205 | iwreqstruct& iwr() const; | 208 | iwreqstruct& iwr() const; |
206 | bool wioctl( int call ) const; | 209 | bool wioctl( int call ) const; |
207 | bool wioctl( int call, iwreqstruct& ) const; | 210 | bool wioctl( int call, iwreqstruct& ) const; |
208 | 211 | ||
209 | private: | 212 | private: |
210 | OChannelHopper _hopper; | 213 | OChannelHopper* _hopper; |
211 | }; | 214 | }; |
212 | 215 | ||
213 | 216 | ||
214 | /*====================================================================================== | 217 | /*====================================================================================== |
215 | * OMonitoringInterface | 218 | * OMonitoringInterface |
216 | *======================================================================================*/ | 219 | *======================================================================================*/ |
217 | 220 | ||
218 | 221 | ||
219 | class OMonitoringInterface | 222 | class OMonitoringInterface |
220 | { | 223 | { |
221 | public: | 224 | public: |
222 | OMonitoringInterface(); | 225 | OMonitoringInterface(); |
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 48f874f..913d42e 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -40,33 +40,36 @@ | |||
40 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) | 40 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) |
41 | #include <qsocketnotifier.h> | 41 | #include <qsocketnotifier.h> |
42 | 42 | ||
43 | /*====================================================================================== | 43 | /*====================================================================================== |
44 | * OPacket | 44 | * OPacket |
45 | *======================================================================================*/ | 45 | *======================================================================================*/ |
46 | 46 | ||
47 | OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* parent ) | 47 | OPacket::OPacket( 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; | ||
53 | qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | ||
54 | |||
52 | if ( packetCapturer()->dataLink() == DLT_EN10MB ) | 55 | if ( packetCapturer()->dataLink() == DLT_EN10MB ) |
53 | { | 56 | { |
54 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); | 57 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); |
55 | new OEthernetPacket( (const struct ether_header*) data, this ); | 58 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); |
56 | } | 59 | } |
57 | else | 60 | else |
58 | { | 61 | { |
59 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); | 62 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); |
60 | new OWaveLanPacket( (const struct ieee_802_11_header*) data, this ); | 63 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); |
61 | } | 64 | } |
62 | } | 65 | } |
63 | 66 | ||
64 | 67 | ||
65 | OPacket::~OPacket() | 68 | OPacket::~OPacket() |
66 | { | 69 | { |
67 | } | 70 | } |
68 | 71 | ||
69 | 72 | ||
70 | OPacketCapturer* OPacket::packetCapturer() const | 73 | OPacketCapturer* OPacket::packetCapturer() const |
71 | { | 74 | { |
72 | return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0; | 75 | return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0; |
@@ -100,40 +103,40 @@ void OPacket::dump() const | |||
100 | 103 | ||
101 | 104 | ||
102 | 105 | ||
103 | int OPacket::len() const | 106 | int OPacket::len() const |
104 | { | 107 | { |
105 | return _hdr.len; | 108 | return _hdr.len; |
106 | } | 109 | } |
107 | 110 | ||
108 | /*====================================================================================== | 111 | /*====================================================================================== |
109 | * OEthernetPacket | 112 | * OEthernetPacket |
110 | *======================================================================================*/ | 113 | *======================================================================================*/ |
111 | 114 | ||
112 | OEthernetPacket::OEthernetPacket( const struct ether_header* data, QObject* parent ) | 115 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
113 | :QObject( parent, "Ethernet" ), _ether( data ) | 116 | :QObject( parent, "Ethernet" ), _ether( data ) |
114 | 117 | ||
115 | { | 118 | { |
116 | 119 | ||
117 | qDebug( "Source = %s", (const char*) sourceAddress().toString() ); | 120 | qDebug( "Source = %s", (const char*) sourceAddress().toString() ); |
118 | qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); | 121 | qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); |
119 | 122 | ||
120 | if ( sourceAddress() == OMacAddress::broadcast ) | 123 | if ( sourceAddress() == OMacAddress::broadcast ) |
121 | qDebug( "Source is broadcast address" ); | 124 | qDebug( "Source is broadcast address" ); |
122 | if ( destinationAddress() == OMacAddress::broadcast ) | 125 | if ( destinationAddress() == OMacAddress::broadcast ) |
123 | qDebug( "Destination is broadcast address" ); | 126 | qDebug( "Destination is broadcast address" ); |
124 | 127 | ||
125 | switch ( type() ) | 128 | switch ( type() ) |
126 | { | 129 | { |
127 | case ETHERTYPE_IP: new OIPPacket( (const struct iphdr*) (data+1), this ); break; | 130 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
128 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } | 131 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } |
129 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } | 132 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } |
130 | default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); | 133 | default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); |
131 | } | 134 | } |
132 | 135 | ||
133 | } | 136 | } |
134 | 137 | ||
135 | 138 | ||
136 | OEthernetPacket::~OEthernetPacket() | 139 | OEthernetPacket::~OEthernetPacket() |
137 | { | 140 | { |
138 | } | 141 | } |
139 | 142 | ||
@@ -151,40 +154,40 @@ OMacAddress OEthernetPacket::destinationAddress() const | |||
151 | 154 | ||
152 | int OEthernetPacket::type() const | 155 | int OEthernetPacket::type() const |
153 | { | 156 | { |
154 | return ntohs( _ether->ether_type ); | 157 | return ntohs( _ether->ether_type ); |
155 | } | 158 | } |
156 | 159 | ||
157 | 160 | ||
158 | /*====================================================================================== | 161 | /*====================================================================================== |
159 | * OIPPacket | 162 | * OIPPacket |
160 | *======================================================================================*/ | 163 | *======================================================================================*/ |
161 | 164 | ||
162 | 165 | ||
163 | OIPPacket::OIPPacket( const struct iphdr* data, QObject* parent ) | 166 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
164 | :QObject( parent, "IP" ), _iphdr( data ) | 167 | :QObject( parent, "IP" ), _iphdr( data ) |
165 | 168 | ||
166 | { | 169 | { |
167 | qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); | 170 | qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); |
168 | 171 | ||
169 | //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); | 172 | //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); |
170 | //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); | 173 | //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); |
171 | 174 | ||
172 | qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); | 175 | qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); |
173 | qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); | 176 | qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); |
174 | 177 | ||
175 | switch ( protocol() ) | 178 | switch ( protocol() ) |
176 | { | 179 | { |
177 | case IPPROTO_UDP: new OUDPPacket( (const struct udphdr*) (data+1), this ); break; | 180 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
178 | case IPPROTO_TCP: new OTCPPacket( (const struct tcphdr*) (data+1), this ); break; | 181 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
179 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); | 182 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); |
180 | } | 183 | } |
181 | 184 | ||
182 | } | 185 | } |
183 | 186 | ||
184 | OIPPacket::~OIPPacket() | 187 | OIPPacket::~OIPPacket() |
185 | { | 188 | { |
186 | } | 189 | } |
187 | 190 | ||
188 | 191 | ||
189 | QHostAddress OIPPacket::fromIPAddress() const | 192 | QHostAddress OIPPacket::fromIPAddress() const |
190 | { | 193 | { |
@@ -235,78 +238,78 @@ int OIPPacket::protocol() const | |||
235 | 238 | ||
236 | 239 | ||
237 | int OIPPacket::checksum() const | 240 | int OIPPacket::checksum() const |
238 | { | 241 | { |
239 | return EXTRACT_16BITS( &_iphdr->check ); | 242 | return EXTRACT_16BITS( &_iphdr->check ); |
240 | } | 243 | } |
241 | 244 | ||
242 | /*====================================================================================== | 245 | /*====================================================================================== |
243 | * OUDPPacket | 246 | * OUDPPacket |
244 | *======================================================================================*/ | 247 | *======================================================================================*/ |
245 | 248 | ||
246 | 249 | ||
247 | OUDPPacket::OUDPPacket( const struct udphdr* data, QObject* parent ) | 250 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
248 | :QObject( parent, "UDP" ), _udphdr( data ) | 251 | :QObject( parent, "UDP" ), _udphdr( data ) |
249 | 252 | ||
250 | { | 253 | { |
251 | qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); | 254 | qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); |
252 | } | 255 | } |
253 | 256 | ||
254 | OUDPPacket::~OUDPPacket() | 257 | OUDPPacket::~OUDPPacket() |
255 | { | 258 | { |
256 | } | 259 | } |
257 | 260 | ||
258 | 261 | ||
259 | /*====================================================================================== | 262 | /*====================================================================================== |
260 | * OTCPPacket | 263 | * OTCPPacket |
261 | *======================================================================================*/ | 264 | *======================================================================================*/ |
262 | 265 | ||
263 | 266 | ||
264 | OTCPPacket::OTCPPacket( const struct tcphdr* data, QObject* parent ) | 267 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) |
265 | :QObject( parent, "TCP" ), _tcphdr( data ) | 268 | :QObject( parent, "TCP" ), _tcphdr( data ) |
266 | 269 | ||
267 | { | 270 | { |
268 | qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); | 271 | qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); |
269 | } | 272 | } |
270 | 273 | ||
271 | OTCPPacket::~OTCPPacket() | 274 | OTCPPacket::~OTCPPacket() |
272 | { | 275 | { |
273 | } | 276 | } |
274 | 277 | ||
275 | 278 | ||
276 | /*====================================================================================== | 279 | /*====================================================================================== |
277 | * OWaveLanPacket | 280 | * OWaveLanPacket |
278 | *======================================================================================*/ | 281 | *======================================================================================*/ |
279 | 282 | ||
280 | 283 | ||
281 | OWaveLanPacket::OWaveLanPacket( const struct ieee_802_11_header* data, QObject* parent ) | 284 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
282 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 285 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
283 | 286 | ||
284 | { | 287 | { |
285 | qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); | 288 | qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); |
286 | qDebug( "type: %0X", type() ); | 289 | qDebug( "type: %0X", type() ); |
287 | qDebug( "subType: %0X", subType() ); | 290 | qDebug( "subType: %0X", subType() ); |
288 | qDebug( "duration: %d", duration() ); | 291 | qDebug( "duration: %d", duration() ); |
289 | qDebug( "powermanagement: %d", usesPowerManagement() ); | 292 | qDebug( "powermanagement: %d", usesPowerManagement() ); |
290 | qDebug( "wep: %d", usesWep() ); | 293 | qDebug( "wep: %d", usesWep() ); |
291 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); | 294 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); |
292 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); | 295 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); |
293 | qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); | 296 | qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); |
294 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); | 297 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); |
295 | 298 | ||
296 | switch ( type() ) | 299 | switch ( type() ) |
297 | { | 300 | { |
298 | case T_MGMT: new OWaveLanManagementPacket( (const struct ieee_802_11_mgmt_header*) data, this ); break; | 301 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
299 | case T_DATA: new OWaveLanDataPacket( (const struct ieee_802_11_data_header*) data, this ); break; | 302 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
300 | //case T_CTRL: new OWaveLanControlPacket( (const struct ieee_802_11_ctrl_header*) data, this ); break; | 303 | //case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_ctrl_header*) data, this ); break; |
301 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" ); | 304 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" ); |
302 | } | 305 | } |
303 | } | 306 | } |
304 | 307 | ||
305 | OWaveLanPacket::~OWaveLanPacket() | 308 | OWaveLanPacket::~OWaveLanPacket() |
306 | { | 309 | { |
307 | } | 310 | } |
308 | 311 | ||
309 | 312 | ||
310 | int OWaveLanPacket::duration() const | 313 | int OWaveLanPacket::duration() const |
311 | { | 314 | { |
312 | return _wlanhdr->duration; | 315 | return _wlanhdr->duration; |
@@ -374,115 +377,301 @@ bool OWaveLanPacket::usesPowerManagement() const | |||
374 | 377 | ||
375 | 378 | ||
376 | bool OWaveLanPacket::usesWep() const | 379 | bool OWaveLanPacket::usesWep() const |
377 | { | 380 | { |
378 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 381 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
379 | } | 382 | } |
380 | 383 | ||
381 | 384 | ||
382 | /*====================================================================================== | 385 | /*====================================================================================== |
383 | * OWaveLanManagementPacket | 386 | * OWaveLanManagementPacket |
384 | *======================================================================================*/ | 387 | *======================================================================================*/ |
385 | 388 | ||
386 | OWaveLanManagementPacket::OWaveLanManagementPacket( const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 389 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
387 | :QObject( parent, "802.11 Management" ), _header( data ), | 390 | :QObject( parent, "802.11 Management" ), _header( data ), |
388 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 391 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
389 | { | 392 | { |
390 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); | 393 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); |
391 | 394 | ||
392 | switch ( ((OWaveLanPacket*) this->parent() )->subType() ) | 395 | switch ( ((OWaveLanPacket*) this->parent() )->subType() ) |
393 | { | 396 | { |
394 | case ST_BEACON: | 397 | case ST_BEACON: |
395 | { | 398 | { |
396 | qDebug( "TYPE: BEACON FRAME" ); | 399 | // nice, received a beacon... |
397 | qDebug( "ESSID: %s", (const char*) SSID() ); | 400 | } |
398 | break; | 401 | } |
402 | |||
403 | // grab tagged values | ||
404 | const unsigned char* ptr = (const unsigned char*) (_body+1); | ||
405 | while (ptr < end) | ||
406 | { | ||
407 | switch ( *ptr ) | ||
408 | { | ||
409 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | ||
410 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | ||
411 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | ||
412 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | ||
413 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | ||
414 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | ||
415 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | ||
416 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | ||
399 | } | 417 | } |
418 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | ||
419 | ptr+= 2; // skip tag ID and length | ||
400 | } | 420 | } |
401 | } | 421 | } |
402 | 422 | ||
403 | 423 | ||
404 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 424 | OWaveLanManagementPacket::~OWaveLanManagementPacket() |
405 | { | 425 | { |
406 | } | 426 | } |
407 | 427 | ||
408 | 428 | ||
409 | QString OWaveLanManagementPacket::SSID() const | 429 | int OWaveLanManagementPacket::beaconInterval() const |
430 | { | ||
431 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | ||
432 | } | ||
433 | |||
434 | |||
435 | int OWaveLanManagementPacket::capabilities() const | ||
436 | { | ||
437 | return EXTRACT_LE_16BITS( &_body->capability_info ); | ||
438 | } | ||
439 | |||
440 | |||
441 | bool OWaveLanManagementPacket::canESS() const | ||
410 | { | 442 | { |
411 | int length = _body->ssid.length; | 443 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
444 | } | ||
445 | |||
446 | |||
447 | bool OWaveLanManagementPacket::canIBSS() const | ||
448 | { | ||
449 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
450 | } | ||
451 | |||
452 | |||
453 | bool OWaveLanManagementPacket::canCFP() const | ||
454 | { | ||
455 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
456 | } | ||
457 | |||
458 | |||
459 | bool OWaveLanManagementPacket::canCFP_REQ() const | ||
460 | { | ||
461 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
462 | } | ||
463 | |||
464 | |||
465 | bool OWaveLanManagementPacket::canPrivacy() const | ||
466 | { | ||
467 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
468 | } | ||
469 | |||
470 | |||
471 | /*====================================================================================== | ||
472 | * OWaveLanManagementSSID | ||
473 | *======================================================================================*/ | ||
474 | |||
475 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | ||
476 | :QObject( parent, "802.11 SSID" ), _data( data ) | ||
477 | { | ||
478 | qDebug( "OWaveLanManagementSSID()" ); | ||
479 | } | ||
480 | |||
481 | |||
482 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | ||
483 | { | ||
484 | } | ||
485 | |||
486 | |||
487 | QString OWaveLanManagementSSID::ID() const | ||
488 | { | ||
489 | int length = _data->length; | ||
412 | if ( length > 32 ) length = 32; | 490 | if ( length > 32 ) length = 32; |
413 | char essid[length+1]; | 491 | char essid[length+1]; |
414 | memcpy( &essid, _body->ssid.ssid, length ); | 492 | memcpy( &essid, &_data->ssid, length ); |
415 | essid[length] = 0x0; | 493 | essid[length] = 0x0; |
416 | return essid; | 494 | return essid; |
417 | } | 495 | } |
418 | 496 | ||
419 | 497 | ||
420 | /*====================================================================================== | 498 | /*====================================================================================== |
499 | * OWaveLanManagementRates | ||
500 | *======================================================================================*/ | ||
501 | |||
502 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) | ||
503 | :QObject( parent, "802.11 Rates" ), _data( data ) | ||
504 | { | ||
505 | qDebug( "OWaveLanManagementRates()" ); | ||
506 | } | ||
507 | |||
508 | |||
509 | OWaveLanManagementRates::~OWaveLanManagementRates() | ||
510 | { | ||
511 | } | ||
512 | |||
513 | /*====================================================================================== | ||
514 | * OWaveLanManagementCF | ||
515 | *======================================================================================*/ | ||
516 | |||
517 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) | ||
518 | :QObject( parent, "802.11 CF" ), _data( data ) | ||
519 | { | ||
520 | qDebug( "OWaveLanManagementCF()" ); | ||
521 | } | ||
522 | |||
523 | |||
524 | OWaveLanManagementCF::~OWaveLanManagementCF() | ||
525 | { | ||
526 | } | ||
527 | |||
528 | /*====================================================================================== | ||
529 | * OWaveLanManagementFH | ||
530 | *======================================================================================*/ | ||
531 | |||
532 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | ||
533 | :QObject( parent, "802.11 FH" ), _data( data ) | ||
534 | { | ||
535 | qDebug( "OWaveLanManagementFH()" ); | ||
536 | } | ||
537 | |||
538 | |||
539 | OWaveLanManagementFH::~OWaveLanManagementFH() | ||
540 | { | ||
541 | } | ||
542 | |||
543 | /*====================================================================================== | ||
544 | * OWaveLanManagementDS | ||
545 | *======================================================================================*/ | ||
546 | |||
547 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | ||
548 | :QObject( parent, "802.11 DS" ), _data( data ) | ||
549 | { | ||
550 | qDebug( "OWaveLanManagementDS()" ); | ||
551 | } | ||
552 | |||
553 | |||
554 | OWaveLanManagementDS::~OWaveLanManagementDS() | ||
555 | { | ||
556 | } | ||
557 | |||
558 | |||
559 | int OWaveLanManagementDS::channel() const | ||
560 | { | ||
561 | return _data->channel; | ||
562 | } | ||
563 | |||
564 | /*====================================================================================== | ||
565 | * OWaveLanManagementTim | ||
566 | *======================================================================================*/ | ||
567 | |||
568 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | ||
569 | :QObject( parent, "802.11 Tim" ), _data( data ) | ||
570 | { | ||
571 | qDebug( "OWaveLanManagementTim()" ); | ||
572 | } | ||
573 | |||
574 | |||
575 | OWaveLanManagementTim::~OWaveLanManagementTim() | ||
576 | { | ||
577 | } | ||
578 | |||
579 | /*====================================================================================== | ||
580 | * OWaveLanManagementIBSS | ||
581 | *======================================================================================*/ | ||
582 | |||
583 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | ||
584 | :QObject( parent, "802.11 IBSS" ), _data( data ) | ||
585 | { | ||
586 | qDebug( "OWaveLanManagementIBSS()" ); | ||
587 | } | ||
588 | |||
589 | |||
590 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | ||
591 | { | ||
592 | } | ||
593 | |||
594 | /*====================================================================================== | ||
595 | * OWaveLanManagementChallenge | ||
596 | *======================================================================================*/ | ||
597 | |||
598 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | ||
599 | :QObject( parent, "802.11 Challenge" ), _data( data ) | ||
600 | { | ||
601 | qDebug( "OWaveLanManagementChallenge()" ); | ||
602 | } | ||
603 | |||
604 | |||
605 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | ||
606 | { | ||
607 | } | ||
608 | |||
609 | /*====================================================================================== | ||
421 | * OWaveLanDataPacket | 610 | * OWaveLanDataPacket |
422 | *======================================================================================*/ | 611 | *======================================================================================*/ |
423 | 612 | ||
424 | OWaveLanDataPacket::OWaveLanDataPacket( const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 613 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
425 | :QObject( parent, "802.11 Data" ), _header( data ) | 614 | :QObject( parent, "802.11 Data" ), _header( data ) |
426 | { | 615 | { |
427 | //qDebug( "size of header = %d", sizeof( struct ieee_802_11_data_header ) ); | 616 | //qDebug( "size of header = %d", sizeof( struct ieee_802_11_data_header ) ); |
428 | //qDebug( "header: %0x", data ); | 617 | //qDebug( "header: %0x", data ); |
429 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 618 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
430 | //qDebug( "payload: %0x", payload ); | 619 | //qDebug( "payload: %0x", payload ); |
431 | 620 | ||
432 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 621 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
433 | 622 | ||
434 | new OLLCPacket( (const struct ieee_802_11_802_2_header*) payload, this ); | 623 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
435 | } | 624 | } |
436 | 625 | ||
437 | 626 | ||
438 | OWaveLanDataPacket::~OWaveLanDataPacket() | 627 | OWaveLanDataPacket::~OWaveLanDataPacket() |
439 | { | 628 | { |
440 | } | 629 | } |
441 | 630 | ||
442 | 631 | ||
443 | /*====================================================================================== | 632 | /*====================================================================================== |
444 | * OLLCPacket | 633 | * OLLCPacket |
445 | *======================================================================================*/ | 634 | *======================================================================================*/ |
446 | 635 | ||
447 | OLLCPacket::OLLCPacket( const struct ieee_802_11_802_2_header* data, QObject* parent ) | 636 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
448 | :QObject( parent, "802.11 802_2" ), _header( data ) | 637 | :QObject( parent, "802.11 802_2" ), _header( data ) |
449 | { | 638 | { |
450 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); | 639 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); |
451 | 640 | ||
452 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 641 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
453 | { | 642 | { |
454 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 643 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); |
455 | 644 | ||
456 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 645 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
457 | { | 646 | { |
458 | case ETH_P_IP: new OIPPacket( (const struct iphdr*) (data+1), this ); break; | 647 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
459 | default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); | 648 | default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); |
460 | } | 649 | } |
461 | 650 | ||
462 | } | 651 | } |
463 | } | 652 | } |
464 | 653 | ||
465 | 654 | ||
466 | OLLCPacket::~OLLCPacket() | 655 | OLLCPacket::~OLLCPacket() |
467 | { | 656 | { |
468 | } | 657 | } |
469 | 658 | ||
470 | /*====================================================================================== | 659 | /*====================================================================================== |
471 | * OPacketCapturer | 660 | * OPacketCapturer |
472 | *======================================================================================*/ | 661 | *======================================================================================*/ |
473 | 662 | ||
474 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 663 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
475 | :QObject( parent, name ), _name( QString::null ), _open( false ), | 664 | :QObject( parent, name ), _name( QString::null ), _open( false ), |
476 | _pch( 0 ) | 665 | _pch( 0 ), _sn( 0 ) |
477 | { | 666 | { |
478 | } | 667 | } |
479 | 668 | ||
480 | 669 | ||
481 | OPacketCapturer::~OPacketCapturer() | 670 | OPacketCapturer::~OPacketCapturer() |
482 | { | 671 | { |
483 | if ( _open ) | 672 | if ( _open ) |
484 | { | 673 | { |
485 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); | 674 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); |
486 | close(); | 675 | close(); |
487 | } | 676 | } |
488 | } | 677 | } |
@@ -508,24 +697,29 @@ bool OPacketCapturer::blocking() const | |||
508 | { | 697 | { |
509 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); | 698 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); |
510 | return -1; | 699 | return -1; |
511 | } | 700 | } |
512 | return !b; | 701 | return !b; |
513 | } | 702 | } |
514 | 703 | ||
515 | 704 | ||
516 | void OPacketCapturer::close() | 705 | void OPacketCapturer::close() |
517 | { | 706 | { |
518 | if ( _open ) | 707 | if ( _open ) |
519 | { | 708 | { |
709 | if ( _sn ) | ||
710 | { | ||
711 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | ||
712 | delete _sn; | ||
713 | } | ||
520 | pcap_close( _pch ); | 714 | pcap_close( _pch ); |
521 | _open = false; | 715 | _open = false; |
522 | } | 716 | } |
523 | } | 717 | } |
524 | 718 | ||
525 | 719 | ||
526 | int OPacketCapturer::dataLink() const | 720 | int OPacketCapturer::dataLink() const |
527 | { | 721 | { |
528 | return pcap_datalink( _pch ); | 722 | return pcap_datalink( _pch ); |
529 | } | 723 | } |
530 | 724 | ||
531 | 725 | ||
@@ -536,25 +730,28 @@ int OPacketCapturer::fileno() const | |||
536 | return pcap_fileno( _pch ); | 730 | return pcap_fileno( _pch ); |
537 | } | 731 | } |
538 | else | 732 | else |
539 | { | 733 | { |
540 | return -1; | 734 | return -1; |
541 | } | 735 | } |
542 | } | 736 | } |
543 | 737 | ||
544 | 738 | ||
545 | OPacket* OPacketCapturer::next() | 739 | OPacket* OPacketCapturer::next() |
546 | { | 740 | { |
547 | packetheaderstruct header; | 741 | packetheaderstruct header; |
742 | qDebug( "==> OPacketCapturer::next()" ); | ||
548 | const unsigned char* pdata = pcap_next( _pch, &header ); | 743 | const unsigned char* pdata = pcap_next( _pch, &header ); |
744 | qDebug( "<== OPacketCapturer::next()" ); | ||
745 | |||
549 | if ( header.len ) | 746 | if ( header.len ) |
550 | return new OPacket( header, pdata, this ); | 747 | return new OPacket( header, pdata, this ); |
551 | else | 748 | else |
552 | return 0; | 749 | return 0; |
553 | } | 750 | } |
554 | 751 | ||
555 | 752 | ||
556 | bool OPacketCapturer::open( const QString& name ) | 753 | bool OPacketCapturer::open( const QString& name ) |
557 | { | 754 | { |
558 | if ( _open ) | 755 | if ( _open ) |
559 | { | 756 | { |
560 | if ( name == _name ) // ignore opening an already openend device | 757 | if ( name == _name ) // ignore opening an already openend device |
@@ -568,29 +765,29 @@ bool OPacketCapturer::open( const QString& name ) | |||
568 | } | 765 | } |
569 | 766 | ||
570 | _name = name; | 767 | _name = name; |
571 | 768 | ||
572 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); | 769 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); |
573 | 770 | ||
574 | if ( handle ) | 771 | if ( handle ) |
575 | { | 772 | { |
576 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); | 773 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); |
577 | _pch = handle; | 774 | _pch = handle; |
578 | _open = true; | 775 | _open = true; |
579 | 776 | ||
580 | // in case we have a qapp, create a socket notifier | 777 | // in case we have an application object, create a socket notifier |
581 | if ( qApp ) | 778 | if ( qApp ) |
582 | { | 779 | { |
583 | QSocketNotifier* sn = new QSocketNotifier( fileno(), QSocketNotifier::Read, this ); | 780 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
584 | connect( sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 781 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
585 | } | 782 | } |
586 | 783 | ||
587 | return true; | 784 | return true; |
588 | } | 785 | } |
589 | else | 786 | else |
590 | { | 787 | { |
591 | qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf ); | 788 | qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf ); |
592 | return false; | 789 | return false; |
593 | } | 790 | } |
594 | 791 | ||
595 | } | 792 | } |
596 | 793 | ||
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 65c550c..0b06572 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -51,81 +51,83 @@ extern "C" // work around a bpf/pcap conflict in recent headers | |||
51 | #include <qstring.h> | 51 | #include <qstring.h> |
52 | 52 | ||
53 | /* OPIE */ | 53 | /* OPIE */ |
54 | #include <opie2/onetutils.h> | 54 | #include <opie2/onetutils.h> |
55 | #include "802_11_user.h" | 55 | #include "802_11_user.h" |
56 | 56 | ||
57 | /* TYPEDEFS */ | 57 | /* TYPEDEFS */ |
58 | typedef struct timeval timevalstruct; | 58 | typedef struct timeval timevalstruct; |
59 | typedef struct pcap_pkthdr packetheaderstruct; | 59 | typedef struct pcap_pkthdr packetheaderstruct; |
60 | 60 | ||
61 | /* FORWARDS */ | 61 | /* FORWARDS */ |
62 | class OPacketCapturer; | 62 | class OPacketCapturer; |
63 | class QSocketNotifier; | ||
63 | 64 | ||
64 | /*====================================================================================== | 65 | /*====================================================================================== |
65 | * OPacket - A frame on the wire | 66 | * OPacket - A frame on the wire |
66 | *======================================================================================*/ | 67 | *======================================================================================*/ |
67 | 68 | ||
68 | class OPacket : public QObject | 69 | class OPacket : public QObject |
69 | { | 70 | { |
70 | Q_OBJECT | 71 | Q_OBJECT |
71 | 72 | ||
72 | public: | 73 | public: |
73 | OPacket( packetheaderstruct, const unsigned char*, QObject* parent ); | 74 | OPacket( packetheaderstruct, const unsigned char*, QObject* parent ); |
74 | virtual ~OPacket(); | 75 | virtual ~OPacket(); |
75 | 76 | ||
76 | timevalstruct timeval() const; | 77 | timevalstruct timeval() const; |
77 | 78 | ||
78 | OPacketCapturer* packetCapturer() const; | 79 | OPacketCapturer* packetCapturer() const; |
79 | 80 | ||
80 | int caplen() const; | 81 | int caplen() const; |
81 | int len() const; | 82 | int len() const; |
82 | void dump() const; | 83 | void dump() const; |
83 | 84 | ||
84 | private: | 85 | private: |
85 | const packetheaderstruct _hdr; // pcap packet header | 86 | const packetheaderstruct _hdr; // pcap packet header |
86 | const unsigned char* _data; // pcap packet data | 87 | const unsigned char* _data; // pcap packet data |
88 | const unsigned char* _end; // end of pcap packet data | ||
87 | }; | 89 | }; |
88 | 90 | ||
89 | /*====================================================================================== | 91 | /*====================================================================================== |
90 | * OEthernetPacket - DLT_EN10MB frame | 92 | * OEthernetPacket - DLT_EN10MB frame |
91 | *======================================================================================*/ | 93 | *======================================================================================*/ |
92 | 94 | ||
93 | class OEthernetPacket : public QObject | 95 | class OEthernetPacket : public QObject |
94 | { | 96 | { |
95 | Q_OBJECT | 97 | Q_OBJECT |
96 | 98 | ||
97 | public: | 99 | public: |
98 | OEthernetPacket( const struct ether_header*, QObject* parent = 0 ); | 100 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); |
99 | virtual ~OEthernetPacket(); | 101 | virtual ~OEthernetPacket(); |
100 | 102 | ||
101 | OMacAddress sourceAddress() const; | 103 | OMacAddress sourceAddress() const; |
102 | OMacAddress destinationAddress() const; | 104 | OMacAddress destinationAddress() const; |
103 | int type() const; | 105 | int type() const; |
104 | 106 | ||
105 | private: | 107 | private: |
106 | const struct ether_header* _ether; | 108 | const struct ether_header* _ether; |
107 | }; | 109 | }; |
108 | 110 | ||
109 | 111 | ||
110 | /*====================================================================================== | 112 | /*====================================================================================== |
111 | * OWaveLanPacket - DLT_IEEE802_11 frame | 113 | * OWaveLanPacket - DLT_IEEE802_11 frame |
112 | *======================================================================================*/ | 114 | *======================================================================================*/ |
113 | 115 | ||
114 | class OWaveLanPacket : public QObject | 116 | class OWaveLanPacket : public QObject |
115 | { | 117 | { |
116 | Q_OBJECT | 118 | Q_OBJECT |
117 | 119 | ||
118 | public: | 120 | public: |
119 | OWaveLanPacket( const struct ieee_802_11_header*, QObject* parent = 0 ); | 121 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); |
120 | virtual ~OWaveLanPacket(); | 122 | virtual ~OWaveLanPacket(); |
121 | 123 | ||
122 | int duration() const; | 124 | int duration() const; |
123 | bool fromDS() const; | 125 | bool fromDS() const; |
124 | bool toDS() const; | 126 | bool toDS() const; |
125 | virtual OMacAddress macAddress1() const; | 127 | virtual OMacAddress macAddress1() const; |
126 | virtual OMacAddress macAddress2() const; | 128 | virtual OMacAddress macAddress2() const; |
127 | virtual OMacAddress macAddress3() const; | 129 | virtual OMacAddress macAddress3() const; |
128 | virtual OMacAddress macAddress4() const; | 130 | virtual OMacAddress macAddress4() const; |
129 | bool usesPowerManagement() const; | 131 | bool usesPowerManagement() const; |
130 | int type() const; | 132 | int type() const; |
131 | int subType() const; | 133 | int subType() const; |
@@ -137,77 +139,216 @@ class OWaveLanPacket : public QObject | |||
137 | }; | 139 | }; |
138 | 140 | ||
139 | 141 | ||
140 | /*====================================================================================== | 142 | /*====================================================================================== |
141 | * OWaveLanManagementPacket - type: management (T_MGMT) | 143 | * OWaveLanManagementPacket - type: management (T_MGMT) |
142 | *======================================================================================*/ | 144 | *======================================================================================*/ |
143 | 145 | ||
144 | class OWaveLanManagementPacket : public QObject | 146 | class OWaveLanManagementPacket : public QObject |
145 | { | 147 | { |
146 | Q_OBJECT | 148 | Q_OBJECT |
147 | 149 | ||
148 | public: | 150 | public: |
149 | OWaveLanManagementPacket( const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); | 151 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); |
150 | virtual ~OWaveLanManagementPacket(); | 152 | virtual ~OWaveLanManagementPacket(); |
151 | 153 | ||
152 | QString SSID() const; | 154 | int beaconInterval() const; |
155 | int capabilities() const; // generic | ||
156 | |||
157 | bool canESS() const; | ||
158 | bool canIBSS() const; | ||
159 | bool canCFP() const; | ||
160 | bool canCFP_REQ() const; | ||
161 | bool canPrivacy() const; | ||
153 | 162 | ||
154 | private: | 163 | private: |
155 | const struct ieee_802_11_mgmt_header* _header; | 164 | const struct ieee_802_11_mgmt_header* _header; |
156 | const struct ieee_802_11_mgmt_body* _body; | 165 | const struct ieee_802_11_mgmt_body* _body; |
157 | }; | 166 | }; |
158 | 167 | ||
159 | 168 | ||
160 | /*====================================================================================== | 169 | /*====================================================================================== |
170 | * OWaveLanManagementSSID | ||
171 | *======================================================================================*/ | ||
172 | |||
173 | class OWaveLanManagementSSID : public QObject | ||
174 | { | ||
175 | Q_OBJECT | ||
176 | |||
177 | public: | ||
178 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); | ||
179 | virtual ~OWaveLanManagementSSID(); | ||
180 | |||
181 | QString ID() const; | ||
182 | |||
183 | private: | ||
184 | const struct ssid_t* _data; | ||
185 | }; | ||
186 | |||
187 | /*====================================================================================== | ||
188 | * OWaveLanManagementRates | ||
189 | *======================================================================================*/ | ||
190 | |||
191 | class OWaveLanManagementRates : public QObject | ||
192 | { | ||
193 | Q_OBJECT | ||
194 | |||
195 | public: | ||
196 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); | ||
197 | virtual ~OWaveLanManagementRates(); | ||
198 | |||
199 | private: | ||
200 | const struct rates_t* _data; | ||
201 | }; | ||
202 | |||
203 | /*====================================================================================== | ||
204 | * OWaveLanManagementCF | ||
205 | *======================================================================================*/ | ||
206 | |||
207 | class OWaveLanManagementCF : public QObject | ||
208 | { | ||
209 | Q_OBJECT | ||
210 | |||
211 | public: | ||
212 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); | ||
213 | virtual ~OWaveLanManagementCF(); | ||
214 | |||
215 | private: | ||
216 | const struct cf_t* _data; | ||
217 | }; | ||
218 | |||
219 | /*====================================================================================== | ||
220 | * OWaveLanManagementFH | ||
221 | *======================================================================================*/ | ||
222 | |||
223 | class OWaveLanManagementFH : public QObject | ||
224 | { | ||
225 | Q_OBJECT | ||
226 | |||
227 | public: | ||
228 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); | ||
229 | virtual ~OWaveLanManagementFH(); | ||
230 | |||
231 | private: | ||
232 | const struct fh_t* _data; | ||
233 | }; | ||
234 | |||
235 | /*====================================================================================== | ||
236 | * OWaveLanManagementDS | ||
237 | *======================================================================================*/ | ||
238 | |||
239 | class OWaveLanManagementDS : public QObject | ||
240 | { | ||
241 | Q_OBJECT | ||
242 | |||
243 | public: | ||
244 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); | ||
245 | virtual ~OWaveLanManagementDS(); | ||
246 | |||
247 | int channel() const; | ||
248 | |||
249 | private: | ||
250 | const struct ds_t* _data; | ||
251 | }; | ||
252 | |||
253 | /*====================================================================================== | ||
254 | * OWaveLanManagementTim | ||
255 | *======================================================================================*/ | ||
256 | |||
257 | class OWaveLanManagementTim : public QObject | ||
258 | { | ||
259 | Q_OBJECT | ||
260 | |||
261 | public: | ||
262 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); | ||
263 | virtual ~OWaveLanManagementTim(); | ||
264 | |||
265 | private: | ||
266 | const struct tim_t* _data; | ||
267 | }; | ||
268 | |||
269 | /*====================================================================================== | ||
270 | * OWaveLanManagementIBSS | ||
271 | *======================================================================================*/ | ||
272 | |||
273 | class OWaveLanManagementIBSS : public QObject | ||
274 | { | ||
275 | Q_OBJECT | ||
276 | |||
277 | public: | ||
278 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); | ||
279 | virtual ~OWaveLanManagementIBSS(); | ||
280 | |||
281 | private: | ||
282 | const struct ibss_t* _data; | ||
283 | }; | ||
284 | |||
285 | /*====================================================================================== | ||
286 | * OWaveLanManagementChallenge | ||
287 | *======================================================================================*/ | ||
288 | |||
289 | class OWaveLanManagementChallenge : public QObject | ||
290 | { | ||
291 | Q_OBJECT | ||
292 | |||
293 | public: | ||
294 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); | ||
295 | virtual ~OWaveLanManagementChallenge(); | ||
296 | |||
297 | private: | ||
298 | const struct challenge_t* _data; | ||
299 | }; | ||
300 | |||
301 | /*====================================================================================== | ||
161 | * OWaveLanDataPacket - type: data (T_DATA) | 302 | * OWaveLanDataPacket - type: data (T_DATA) |
162 | *======================================================================================*/ | 303 | *======================================================================================*/ |
163 | 304 | ||
164 | class OWaveLanDataPacket : public QObject | 305 | class OWaveLanDataPacket : public QObject |
165 | { | 306 | { |
166 | Q_OBJECT | 307 | Q_OBJECT |
167 | 308 | ||
168 | public: | 309 | public: |
169 | OWaveLanDataPacket( const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); | 310 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); |
170 | virtual ~OWaveLanDataPacket(); | 311 | virtual ~OWaveLanDataPacket(); |
171 | 312 | ||
172 | private: | 313 | private: |
173 | const struct ieee_802_11_data_header* _header; | 314 | const struct ieee_802_11_data_header* _header; |
174 | }; | 315 | }; |
175 | 316 | ||
176 | /*====================================================================================== | 317 | /*====================================================================================== |
177 | * OLLCPacket - IEEE 802.2 Link Level Control | 318 | * OLLCPacket - IEEE 802.2 Link Level Control |
178 | *======================================================================================*/ | 319 | *======================================================================================*/ |
179 | 320 | ||
180 | class OLLCPacket : public QObject | 321 | class OLLCPacket : public QObject |
181 | { | 322 | { |
182 | Q_OBJECT | 323 | Q_OBJECT |
183 | 324 | ||
184 | public: | 325 | public: |
185 | OLLCPacket( const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); | 326 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); |
186 | virtual ~OLLCPacket(); | 327 | virtual ~OLLCPacket(); |
187 | 328 | ||
188 | private: | 329 | private: |
189 | const struct ieee_802_11_802_2_header* _header; | 330 | const struct ieee_802_11_802_2_header* _header; |
190 | }; | 331 | }; |
191 | 332 | ||
192 | /*====================================================================================== | 333 | /*====================================================================================== |
193 | * OIPPacket | 334 | * OIPPacket |
194 | *======================================================================================*/ | 335 | *======================================================================================*/ |
195 | 336 | ||
196 | class OIPPacket : public QObject | 337 | class OIPPacket : public QObject |
197 | { | 338 | { |
198 | Q_OBJECT | 339 | Q_OBJECT |
199 | 340 | ||
200 | public: | 341 | public: |
201 | OIPPacket( const struct iphdr*, QObject* parent = 0 ); | 342 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); |
202 | virtual ~OIPPacket(); | 343 | virtual ~OIPPacket(); |
203 | 344 | ||
204 | QHostAddress fromIPAddress() const; | 345 | QHostAddress fromIPAddress() const; |
205 | QHostAddress toIPAddress() const; | 346 | QHostAddress toIPAddress() const; |
206 | 347 | ||
207 | int tos() const; | 348 | int tos() const; |
208 | int len() const; | 349 | int len() const; |
209 | int id() const; | 350 | int id() const; |
210 | int offset() const; | 351 | int offset() const; |
211 | int ttl() const; | 352 | int ttl() const; |
212 | int protocol() const; | 353 | int protocol() const; |
213 | int checksum() const; | 354 | int checksum() const; |
@@ -216,44 +357,44 @@ class OIPPacket : public QObject | |||
216 | const struct iphdr* _iphdr; | 357 | const struct iphdr* _iphdr; |
217 | }; | 358 | }; |
218 | 359 | ||
219 | /*====================================================================================== | 360 | /*====================================================================================== |
220 | * OUDPPacket | 361 | * OUDPPacket |
221 | *======================================================================================*/ | 362 | *======================================================================================*/ |
222 | 363 | ||
223 | class OUDPPacket : public QObject | 364 | class OUDPPacket : public QObject |
224 | { | 365 | { |
225 | Q_OBJECT | 366 | Q_OBJECT |
226 | 367 | ||
227 | public: | 368 | public: |
228 | OUDPPacket( const struct udphdr*, QObject* parent = 0 ); | 369 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); |
229 | virtual ~OUDPPacket(); | 370 | virtual ~OUDPPacket(); |
230 | 371 | ||
231 | int fromPort() const; | 372 | int fromPort() const; |
232 | int toPort() const; | 373 | int toPort() const; |
233 | 374 | ||
234 | private: | 375 | private: |
235 | const struct udphdr* _udphdr; | 376 | const struct udphdr* _udphdr; |
236 | }; | 377 | }; |
237 | 378 | ||
238 | /*====================================================================================== | 379 | /*====================================================================================== |
239 | * OTCPPacket | 380 | * OTCPPacket |
240 | *======================================================================================*/ | 381 | *======================================================================================*/ |
241 | 382 | ||
242 | class OTCPPacket : public QObject | 383 | class OTCPPacket : public QObject |
243 | { | 384 | { |
244 | Q_OBJECT | 385 | Q_OBJECT |
245 | 386 | ||
246 | public: | 387 | public: |
247 | OTCPPacket( const struct tcphdr*, QObject* parent = 0 ); | 388 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); |
248 | virtual ~OTCPPacket(); | 389 | virtual ~OTCPPacket(); |
249 | 390 | ||
250 | int fromPort() const; | 391 | int fromPort() const; |
251 | int toPort() const; | 392 | int toPort() const; |
252 | 393 | ||
253 | private: | 394 | private: |
254 | const struct tcphdr* _tcphdr; | 395 | const struct tcphdr* _tcphdr; |
255 | }; | 396 | }; |
256 | 397 | ||
257 | 398 | ||
258 | /*====================================================================================== | 399 | /*====================================================================================== |
259 | * OPacketCapturer | 400 | * OPacketCapturer |
@@ -278,17 +419,18 @@ class OPacketCapturer : public QObject | |||
278 | bool isOpen() const; | 419 | bool isOpen() const; |
279 | 420 | ||
280 | signals: | 421 | signals: |
281 | void receivedPacket( OPacket* ); | 422 | void receivedPacket( OPacket* ); |
282 | 423 | ||
283 | protected slots: | 424 | protected slots: |
284 | void readyToReceive(); | 425 | void readyToReceive(); |
285 | 426 | ||
286 | protected: | 427 | protected: |
287 | QString _name; // devicename | 428 | QString _name; // devicename |
288 | bool _open; // check this before doing pcap calls | 429 | bool _open; // check this before doing pcap calls |
289 | pcap_t* _pch; // pcap library handle | 430 | pcap_t* _pch; // pcap library handle |
431 | QSocketNotifier* _sn; // socket notifier for main loop | ||
290 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; | 432 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; |
291 | }; | 433 | }; |
292 | 434 | ||
293 | #endif // OPCAP_H | 435 | #endif // OPCAP_H |
294 | 436 | ||