summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/802_11_user.h16
-rw-r--r--libopie2/opienet/opcap.cpp103
-rw-r--r--libopie2/opienet/opcap.h22
3 files changed, 108 insertions, 33 deletions
diff --git a/libopie2/opienet/802_11_user.h b/libopie2/opienet/802_11_user.h
index ffdcb93..f596bd8 100644
--- a/libopie2/opienet/802_11_user.h
+++ b/libopie2/opienet/802_11_user.h
@@ -234,48 +234,60 @@ struct ieee_802_11_frame_subtype_class {
234 234
235 235
236struct ieee_802_11_mgmt_header { 236struct ieee_802_11_mgmt_header {
237 u_int16_t fc; 237 u_int16_t fc;
238 u_int16_t duration; 238 u_int16_t duration;
239 u_int8_t da[6]; 239 u_int8_t da[6];
240 u_int8_t sa[6]; 240 u_int8_t sa[6];
241 u_int8_t bssid[6]; 241 u_int8_t bssid[6];
242 u_int16_t seq_ctrl; 242 u_int16_t seq_ctrl;
243}; 243};
244 244
245 245
246struct ieee_802_11_data_header { 246struct ieee_802_11_data_header {
247 u_int16_tframe_control; 247 u_int16_tframe_control;
248 u_int16_tduration; 248 u_int16_tduration;
249 u_int8_tmac1[6]; 249 u_int8_tmac1[6];
250 u_int8_tmac2[6]; 250 u_int8_tmac2[6];
251 u_int8_tmac3[6]; 251 u_int8_tmac3[6];
252 u_int16_tSeqCtl; 252 u_int16_tSeqCtl;
253 u_int8_tmac4[6]; 253 u_int8_tmac4[6];
254 // u_int16_tgapLen; 254 // u_int16_tgapLen;
255 // u_int8_tgap[8]; 255 // u_int8_tgap[8];
256}; 256};
257 257
258struct ieee_802_11_control_header {
259 u_int16_tframe_control;
260 u_int16_tduration;
261 u_int8_tmac1[6];
262 u_int8_tmac2[6];
263 u_int8_tmac3[6];
264 u_int16_tSeqCtl;
265 u_int8_tmac4[6];
266 // u_int16_tgapLen;
267 // u_int8_tgap[8];
268};
269
258#define CAPABILITY_ESS(cap) ((cap) & 0x0001) 270#define CAPABILITY_ESS(cap) ((cap) & 0x0001)
259#define CAPABILITY_IBSS(cap) ((cap) & 0x0002) 271#define CAPABILITY_IBSS(cap) ((cap) & 0x0002)
260#define CAPABILITY_CFP(cap) ((cap) & 0x0004) 272#define CAPABILITY_CFP(cap) ((cap) & 0x0004)
261#define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008) 273#define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008)
262#define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010) 274#define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010)
263 275
264struct ssid_t { 276struct ssid_t {
265 u_int8_telement_id; 277 u_int8_telement_id;
266 u_int8_tlength; 278 u_int8_tlength;
267 u_char ssid[33]; /* 32 + 1 for null */ 279 u_char ssid[33]; /* 32 + 1 for null */
268}; 280};
269 281
270 282
271struct rates_t { 283struct rates_t {
272 u_int8_telement_id; 284 u_int8_telement_id;
273 u_int8_tlength; 285 u_int8_tlength;
274 u_int8_trate[8]; 286 u_int8_trate[8];
275}; 287};
276 288
277 289
278struct challenge_t { 290struct challenge_t {
279 u_int8_telement_id; 291 u_int8_telement_id;
280 u_int8_tlength; 292 u_int8_tlength;
281 u_int8_ttext[254]; /* 1-253 + 1 for null */ 293 u_int8_ttext[254]; /* 1-253 + 1 for null */
@@ -341,48 +353,52 @@ struct ieee_802_11_mgmt_body {
341 u_int8_t timestamp[8]; 353 u_int8_t timestamp[8];
342 u_int16_t beacon_interval; 354 u_int16_t beacon_interval;
343 // u_int16_t listen_interval; 355 // u_int16_t listen_interval;
344 // u_int16_t status_code; 356 // u_int16_t status_code;
345 // u_int16_t aid; 357 // u_int16_t aid;
346 // u_char ap[6]; 358 // u_char ap[6];
347 // u_int16_treason_code; 359 // u_int16_treason_code;
348 // u_int16_tauth_alg; 360 // u_int16_tauth_alg;
349 // u_int16_tauth_trans_seq_num; 361 // u_int16_tauth_trans_seq_num;
350// struct challenge_t challenge; 362// struct challenge_t challenge;
351 u_int16_t capability_info; 363 u_int16_t capability_info;
352 // struct ssid_tssid; 364 // struct ssid_tssid;
353 // struct rates_t rates; 365 // struct rates_t rates;
354 // struct ds_tds; 366 // struct ds_tds;
355 // struct cf_tcf; 367 // struct cf_tcf;
356 // struct fh_tfh; 368 // struct fh_tfh;
357 // struct tim_ttim; 369 // struct tim_ttim;
358}; 370};
359 371
360 372
361struct ieee_802_11_data_body { 373struct ieee_802_11_data_body {
362//FIXME 374//FIXME
363}; 375};
364 376
377struct ieee_802_11_control_body {
378//FIXME
379};
380
365struct ctrl_rts_t { 381struct ctrl_rts_t {
366 u_int16_tfc; 382 u_int16_tfc;
367 u_int16_tduration; 383 u_int16_tduration;
368 u_int8_tra[6]; 384 u_int8_tra[6];
369 u_int8_tta[6]; 385 u_int8_tta[6];
370 u_int8_tfcs[4]; 386 u_int8_tfcs[4];
371}; 387};
372 388
373 #define CTRL_RTS_LEN(2+2+6+6+4) 389 #define CTRL_RTS_LEN(2+2+6+6+4)
374 390
375struct ctrl_cts_t { 391struct ctrl_cts_t {
376 u_int16_tfc; 392 u_int16_tfc;
377 u_int16_tduration; 393 u_int16_tduration;
378 u_int8_tra[6]; 394 u_int8_tra[6];
379 u_int8_tfcs[4]; 395 u_int8_tfcs[4];
380}; 396};
381 397
382 #define CTRL_CTS_LEN(2+2+6+4) 398 #define CTRL_CTS_LEN(2+2+6+4)
383 399
384struct ctrl_ack_t { 400struct ctrl_ack_t {
385 u_int16_tfc; 401 u_int16_tfc;
386 u_int16_tduration; 402 u_int16_tduration;
387 u_int8_tra[6]; 403 u_int8_tra[6];
388 u_int8_tfcs[4]; 404 u_int8_tfcs[4];
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 40aac2c..5c464cf 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -23,80 +23,79 @@
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/opcap.h> 36#include <opie2/opcap.h>
37 37
38/* QT */ 38/* QT */
39 39
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
47OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* parent ) 47OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
48 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 48 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
49{ 49{
50 qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 50 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
51 51
52 _end = (unsigned char*) data + header.len; 52 _end = (unsigned char*) data + header.len;
53 qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 53 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
54 54
55 if ( packetCapturer()->dataLink() == DLT_EN10MB ) 55 switch ( datalink )
56 { 56 {
57 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); 57 case DLT_EN10MB:
58 new OEthernetPacket( _end, (const struct ether_header*) data, this ); 58 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
59 } 59 new OEthernetPacket( _end, (const struct ether_header*) data, this );
60 else 60 break;
61 { 61
62 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); 62 case DLT_IEEE802_11:
63 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); 63 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
64 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
65 break;
66
67 default:
68 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink );
64 } 69 }
65} 70}
66 71
67 72
68OPacket::~OPacket() 73OPacket::~OPacket()
69{ 74{
70} 75}
71 76
72 77
73OPacketCapturer* OPacket::packetCapturer() const
74{
75 return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0;
76}
77
78
79timevalstruct OPacket::timeval() const 78timevalstruct OPacket::timeval() const
80{ 79{
81 return _hdr.ts; 80 return _hdr.ts;
82} 81}
83 82
84 83
85int OPacket::caplen() const 84int OPacket::caplen() const
86{ 85{
87 return _hdr.caplen; 86 return _hdr.caplen;
88} 87}
89 88
90 89
91QString OPacket::dump( int bpl ) const 90QString OPacket::dump( int bpl ) const
92{ 91{
93 static int index = 0; 92 static int index = 0;
94 index++; 93 index++;
95 int len = _hdr.caplen; 94 int len = _hdr.caplen;
96 QString str; 95 QString str;
97 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); 96 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
98 str.append( "0000: " ); 97 str.append( "0000: " );
99 QString tmp; 98 QString tmp;
100 QString bytes; 99 QString bytes;
101 QString chars; 100 QString chars;
102 101
@@ -295,60 +294,60 @@ OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QOb
295 294
296{ 295{
297 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); 296 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." );
298} 297}
299 298
300OTCPPacket::~OTCPPacket() 299OTCPPacket::~OTCPPacket()
301{ 300{
302} 301}
303 302
304 303
305/*====================================================================================== 304/*======================================================================================
306 * OWaveLanPacket 305 * OWaveLanPacket
307 *======================================================================================*/ 306 *======================================================================================*/
308 307
309 308
310OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) 309OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent )
311 :QObject( parent, "802.11" ), _wlanhdr( data ) 310 :QObject( parent, "802.11" ), _wlanhdr( data )
312 311
313{ 312{
314 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); 313 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." );
315 qDebug( "type: %0X", type() ); 314 qDebug( "type: %0X", type() );
316 qDebug( "subType: %0X", subType() ); 315 qDebug( "subType: %0X", subType() );
317 qDebug( "duration: %d", duration() ); 316 qDebug( "duration: %d", duration() );
318 qDebug( "powermanagement: %d", usesPowerManagement() ); 317 qDebug( "powermanagement: %d", usesPowerManagement() );
319 qDebug( "wep: %d", usesWep() ); 318 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" );
320 qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); 319 qDebug( "MAC1: %s", (const char*) macAddress1().toString() );
321 qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); 320 qDebug( "MAC2: %s", (const char*) macAddress2().toString() );
322 qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); 321 qDebug( "MAC3: %s", (const char*) macAddress3().toString() );
323 qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); 322 qDebug( "MAC4: %s", (const char*) macAddress4().toString() );
324 323
325 switch ( type() ) 324 switch ( type() )
326 { 325 {
327 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; 326 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
328 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; 327 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break;
329 //case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_ctrl_header*) data, this ); break; 328 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break;
330 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" ); 329 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() );
331 } 330 }
332} 331}
333 332
334OWaveLanPacket::~OWaveLanPacket() 333OWaveLanPacket::~OWaveLanPacket()
335{ 334{
336} 335}
337 336
338 337
339int OWaveLanPacket::duration() const 338int OWaveLanPacket::duration() const
340{ 339{
341 return _wlanhdr->duration; 340 return _wlanhdr->duration;
342} 341}
343 342
344 343
345OMacAddress OWaveLanPacket::macAddress1() const 344OMacAddress OWaveLanPacket::macAddress1() const
346{ 345{
347 return OMacAddress( _wlanhdr->mac1 ); 346 return OMacAddress( _wlanhdr->mac1 );
348} 347}
349 348
350 349
351OMacAddress OWaveLanPacket::macAddress2() const 350OMacAddress OWaveLanPacket::macAddress2() const
352{ 351{
353 return OMacAddress( _wlanhdr->mac2 ); 352 return OMacAddress( _wlanhdr->mac2 );
354} 353}
@@ -396,83 +395,98 @@ bool OWaveLanPacket::toDS() const
396} 395}
397 396
398 397
399bool OWaveLanPacket::usesPowerManagement() const 398bool OWaveLanPacket::usesPowerManagement() const
400{ 399{
401 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 400 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
402} 401}
403 402
404 403
405bool OWaveLanPacket::usesWep() const 404bool OWaveLanPacket::usesWep() const
406{ 405{
407 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 406 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
408} 407}
409 408
410 409
411/*====================================================================================== 410/*======================================================================================
412 * OWaveLanManagementPacket 411 * OWaveLanManagementPacket
413 *======================================================================================*/ 412 *======================================================================================*/
414 413
415OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) 414OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
416 :QObject( parent, "802.11 Management" ), _header( data ), 415 :QObject( parent, "802.11 Management" ), _header( data ),
417 _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) 416 _body( (const struct ieee_802_11_mgmt_body*) (data+1) )
418{ 417{
419 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); 418 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." );
420 419 qDebug( "Detected subtype is '%s'", (const char*) managementType() );
421 switch ( ((OWaveLanPacket*) this->parent() )->subType() )
422 {
423 case ST_BEACON:
424 {
425 // nice, received a beacon...
426 }
427 }
428 420
429 // grab tagged values 421 // grab tagged values
430 const unsigned char* ptr = (const unsigned char*) (_body+1); 422 const unsigned char* ptr = (const unsigned char*) (_body+1);
431 while (ptr < end) 423 while (ptr < end)
432 { 424 {
433 switch ( *ptr ) 425 switch ( *ptr )
434 { 426 {
435 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; 427 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break;
436 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; 428 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break;
437 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; 429 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break;
438 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; 430 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break;
439 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; 431 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break;
440 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; 432 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break;
441 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; 433 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break;
442 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; 434 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break;
443 } 435 }
444 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value 436 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value
445 ptr+= 2; // skip tag ID and length 437 ptr+= 2; // skip tag ID and length
446 } 438 }
447} 439}
448 440
449 441
450OWaveLanManagementPacket::~OWaveLanManagementPacket() 442OWaveLanManagementPacket::~OWaveLanManagementPacket()
451{ 443{
452} 444}
453 445
454 446
447QString OWaveLanManagementPacket::managementType() const
448{
449 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) )
450 {
451 case ST_ASSOC_REQUEST: return "AssociationRequest"; break;
452 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break;
453 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break;
454 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break;
455 case ST_PROBE_REQUEST: return "ProbeRequest"; break;
456 case ST_PROBE_RESPONSE: return "ProbeResponse"; break;
457 case ST_BEACON: return "Beacon"; break;
458 case ST_ATIM: return "Atim"; break;
459 case ST_DISASSOC: return "Disassociation"; break;
460 case ST_AUTH: return "Authentication"; break;
461 case ST_DEAUTH: return "Deathentication"; break;
462 default:
463 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) );
464 return "Unknown";
465 }
466}
467
468
455int OWaveLanManagementPacket::beaconInterval() const 469int OWaveLanManagementPacket::beaconInterval() const
456{ 470{
457 return EXTRACT_LE_16BITS( &_body->beacon_interval ); 471 return EXTRACT_LE_16BITS( &_body->beacon_interval );
458} 472}
459 473
460 474
461int OWaveLanManagementPacket::capabilities() const 475int OWaveLanManagementPacket::capabilities() const
462{ 476{
463 return EXTRACT_LE_16BITS( &_body->capability_info ); 477 return EXTRACT_LE_16BITS( &_body->capability_info );
464} 478}
465 479
466 480
467bool OWaveLanManagementPacket::canESS() const 481bool OWaveLanManagementPacket::canESS() const
468{ 482{
469 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 483 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) );
470} 484}
471 485
472 486
473bool OWaveLanManagementPacket::canIBSS() const 487bool OWaveLanManagementPacket::canIBSS() const
474{ 488{
475 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 489 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) );
476} 490}
477 491
478 492
@@ -661,48 +675,66 @@ OWaveLanDataPacket::~OWaveLanDataPacket()
661 675
662OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) 676OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
663 :QObject( parent, "802.11 LLC" ), _header( data ) 677 :QObject( parent, "802.11 LLC" ), _header( data )
664{ 678{
665 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); 679 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." );
666 680
667 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) 681 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
668 { 682 {
669 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 683 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) );
670 684
671 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h 685 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
672 { 686 {
673 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 687 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
674 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); 688 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" );
675 } 689 }
676 690
677 } 691 }
678} 692}
679 693
680 694
681OLLCPacket::~OLLCPacket() 695OLLCPacket::~OLLCPacket()
682{ 696{
683} 697}
684 698
699
700/*======================================================================================
701 * OWaveLanControlPacket
702 *======================================================================================*/
703
704OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent )
705 :QObject( parent, "802.11 Data" ), _header( data )
706{
707 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." );
708 //TODO: Implement this
709}
710
711
712OWaveLanControlPacket::~OWaveLanControlPacket()
713{
714}
715
716
685/*====================================================================================== 717/*======================================================================================
686 * OPacketCapturer 718 * OPacketCapturer
687 *======================================================================================*/ 719 *======================================================================================*/
688 720
689OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 721OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
690 :QObject( parent, name ), _name( QString::null ), _open( false ), 722 :QObject( parent, name ), _name( QString::null ), _open( false ),
691 _pch( 0 ), _sn( 0 ) 723 _pch( 0 ), _sn( 0 )
692{ 724{
693} 725}
694 726
695 727
696OPacketCapturer::~OPacketCapturer() 728OPacketCapturer::~OPacketCapturer()
697{ 729{
698 if ( _open ) 730 if ( _open )
699 { 731 {
700 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 732 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
701 close(); 733 close();
702 } 734 }
703} 735}
704 736
705 737
706void OPacketCapturer::setBlocking( bool b ) 738void OPacketCapturer::setBlocking( bool b )
707{ 739{
708 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 740 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
@@ -749,51 +781,59 @@ int OPacketCapturer::dataLink() const
749} 781}
750 782
751 783
752int OPacketCapturer::fileno() const 784int OPacketCapturer::fileno() const
753{ 785{
754 if ( _open ) 786 if ( _open )
755 { 787 {
756 return pcap_fileno( _pch ); 788 return pcap_fileno( _pch );
757 } 789 }
758 else 790 else
759 { 791 {
760 return -1; 792 return -1;
761 } 793 }
762} 794}
763 795
764 796
765OPacket* OPacketCapturer::next() 797OPacket* OPacketCapturer::next()
766{ 798{
767 packetheaderstruct header; 799 packetheaderstruct header;
768 qDebug( "==> OPacketCapturer::next()" ); 800 qDebug( "==> OPacketCapturer::next()" );
769 const unsigned char* pdata = pcap_next( _pch, &header ); 801 const unsigned char* pdata = pcap_next( _pch, &header );
770 qDebug( "<== OPacketCapturer::next()" ); 802 qDebug( "<== OPacketCapturer::next()" );
771 803
772 if ( header.len ) 804 if ( header.len )
773 return new OPacket( header, pdata, this ); 805 {
806 return new OPacket( dataLink(), header, pdata, 0 );
807 // packets shouldn't be inserted in the QObject child-parent hierarchy,
808 // because due to memory constraints they will be deleted as soon
809 // as possible - that is right after they have been processed
810 // by emit() [ see below ]
811 }
774 else 812 else
813 {
775 return 0; 814 return 0;
815 }
776} 816}
777 817
778 818
779bool OPacketCapturer::open( const QString& name ) 819bool OPacketCapturer::open( const QString& name )
780{ 820{
781 if ( _open ) 821 if ( _open )
782 { 822 {
783 if ( name == _name ) // ignore opening an already openend device 823 if ( name == _name ) // ignore opening an already openend device
784 { 824 {
785 return true; 825 return true;
786 } 826 }
787 else // close the last opened device 827 else // close the last opened device
788 { 828 {
789 close(); 829 close();
790 } 830 }
791 } 831 }
792 832
793 _name = name; 833 _name = name;
794 834
795 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 835 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
796 836
797 if ( handle ) 837 if ( handle )
798 { 838 {
799 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 839 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
@@ -806,27 +846,30 @@ bool OPacketCapturer::open( const QString& name )
806 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 846 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
807 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 847 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
808 } 848 }
809 849
810 return true; 850 return true;
811 } 851 }
812 else 852 else
813 { 853 {
814 qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf ); 854 qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf );
815 return false; 855 return false;
816 } 856 }
817 857
818} 858}
819 859
820 860
821bool OPacketCapturer::isOpen() const 861bool OPacketCapturer::isOpen() const
822{ 862{
823 return _open; 863 return _open;
824} 864}
825 865
826 866
827void OPacketCapturer::readyToReceive() 867void OPacketCapturer::readyToReceive()
828{ 868{
829 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" ); 869 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" );
830 emit receivedPacket( next() ); 870 OPacket* p = next();
871 emit receivedPacket( p );
872 // emit is synchronous - packet has been dealt with, now it's safe to delete
873 delete p;
831} 874}
832 875
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index 04d22ff..ddef278 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -50,55 +50,53 @@ extern "C" // work around a bpf/pcap conflict in recent headers
50#include <qobject.h> 50#include <qobject.h>
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 */
58typedef struct timeval timevalstruct; 58typedef struct timeval timevalstruct;
59typedef struct pcap_pkthdr packetheaderstruct; 59typedef struct pcap_pkthdr packetheaderstruct;
60 60
61/* FORWARDS */ 61/* FORWARDS */
62class OPacketCapturer; 62class OPacketCapturer;
63class QSocketNotifier; 63class QSocketNotifier;
64 64
65/*====================================================================================== 65/*======================================================================================
66 * OPacket - A frame on the wire 66 * OPacket - A frame on the wire
67 *======================================================================================*/ 67 *======================================================================================*/
68 68
69class OPacket : public QObject 69class OPacket : public QObject
70{ 70{
71 Q_OBJECT 71 Q_OBJECT
72 72
73 public: 73 public:
74 OPacket( packetheaderstruct, const unsigned char*, QObject* parent ); 74 OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent );
75 virtual ~OPacket(); 75 virtual ~OPacket();
76 76
77 timevalstruct timeval() const; 77 timevalstruct timeval() const;
78 78
79 OPacketCapturer* packetCapturer() const;
80
81 int caplen() const; 79 int caplen() const;
82 int len() const; 80 int len() const;
83 QString dump( int = 32 ) const; 81 QString dump( int = 32 ) const;
84 82
85 private: 83 private:
86 const packetheaderstruct _hdr; // pcap packet header 84 const packetheaderstruct _hdr; // pcap packet header
87 const unsigned char* _data; // pcap packet data 85 const unsigned char* _data; // pcap packet data
88 const unsigned char* _end; // end of pcap packet data 86 const unsigned char* _end; // end of pcap packet data
89}; 87};
90 88
91/*====================================================================================== 89/*======================================================================================
92 * OEthernetPacket - DLT_EN10MB frame 90 * OEthernetPacket - DLT_EN10MB frame
93 *======================================================================================*/ 91 *======================================================================================*/
94 92
95class OEthernetPacket : public QObject 93class OEthernetPacket : public QObject
96{ 94{
97 Q_OBJECT 95 Q_OBJECT
98 96
99 public: 97 public:
100 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); 98 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 );
101 virtual ~OEthernetPacket(); 99 virtual ~OEthernetPacket();
102 100
103 OMacAddress sourceAddress() const; 101 OMacAddress sourceAddress() const;
104 OMacAddress destinationAddress() const; 102 OMacAddress destinationAddress() const;
@@ -130,48 +128,50 @@ class OWaveLanPacket : public QObject
130 virtual OMacAddress macAddress4() const; 128 virtual OMacAddress macAddress4() const;
131 bool usesPowerManagement() const; 129 bool usesPowerManagement() const;
132 int type() const; 130 int type() const;
133 int subType() const; 131 int subType() const;
134 int version() const; 132 int version() const;
135 bool usesWep() const; 133 bool usesWep() const;
136 134
137 private: 135 private:
138 const struct ieee_802_11_header* _wlanhdr; 136 const struct ieee_802_11_header* _wlanhdr;
139}; 137};
140 138
141 139
142/*====================================================================================== 140/*======================================================================================
143 * OWaveLanManagementPacket - type: management (T_MGMT) 141 * OWaveLanManagementPacket - type: management (T_MGMT)
144 *======================================================================================*/ 142 *======================================================================================*/
145 143
146class OWaveLanManagementPacket : public QObject 144class OWaveLanManagementPacket : public QObject
147{ 145{
148 Q_OBJECT 146 Q_OBJECT
149 147
150 public: 148 public:
151 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); 149 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 );
152 virtual ~OWaveLanManagementPacket(); 150 virtual ~OWaveLanManagementPacket();
153 151
152 QString managementType() const;
153
154 int beaconInterval() const; 154 int beaconInterval() const;
155 int capabilities() const; // generic 155 int capabilities() const; // generic
156 156
157 bool canESS() const; 157 bool canESS() const;
158 bool canIBSS() const; 158 bool canIBSS() const;
159 bool canCFP() const; 159 bool canCFP() const;
160 bool canCFP_REQ() const; 160 bool canCFP_REQ() const;
161 bool canPrivacy() const; 161 bool canPrivacy() const;
162 162
163 private: 163 private:
164 const struct ieee_802_11_mgmt_header* _header; 164 const struct ieee_802_11_mgmt_header* _header;
165 const struct ieee_802_11_mgmt_body* _body; 165 const struct ieee_802_11_mgmt_body* _body;
166}; 166};
167 167
168 168
169/*====================================================================================== 169/*======================================================================================
170 * OWaveLanManagementSSID 170 * OWaveLanManagementSSID
171 *======================================================================================*/ 171 *======================================================================================*/
172 172
173class OWaveLanManagementSSID : public QObject 173class OWaveLanManagementSSID : public QObject
174{ 174{
175 Q_OBJECT 175 Q_OBJECT
176 176
177 public: 177 public:
@@ -294,48 +294,64 @@ class OWaveLanManagementChallenge : public QObject
294 OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); 294 OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 );
295 virtual ~OWaveLanManagementChallenge(); 295 virtual ~OWaveLanManagementChallenge();
296 296
297 private: 297 private:
298 const struct challenge_t* _data; 298 const struct challenge_t* _data;
299}; 299};
300 300
301/*====================================================================================== 301/*======================================================================================
302 * OWaveLanDataPacket - type: data (T_DATA) 302 * OWaveLanDataPacket - type: data (T_DATA)
303 *======================================================================================*/ 303 *======================================================================================*/
304 304
305class OWaveLanDataPacket : public QObject 305class OWaveLanDataPacket : public QObject
306{ 306{
307 Q_OBJECT 307 Q_OBJECT
308 308
309 public: 309 public:
310 OWaveLanDataPacket( const unsigned char*, 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 );
311 virtual ~OWaveLanDataPacket(); 311 virtual ~OWaveLanDataPacket();
312 312
313 private: 313 private:
314 const struct ieee_802_11_data_header* _header; 314 const struct ieee_802_11_data_header* _header;
315}; 315};
316 316
317/*====================================================================================== 317/*======================================================================================
318 * OWaveLanControlPacket - type: control (T_CTRL)
319 *======================================================================================*/
320
321class OWaveLanControlPacket : public QObject
322{
323 Q_OBJECT
324
325 public:
326 OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 );
327 virtual ~OWaveLanControlPacket();
328
329 private:
330 const struct ieee_802_11_control_header* _header;
331};
332
333/*======================================================================================
318 * OLLCPacket - IEEE 802.2 Link Level Control 334 * OLLCPacket - IEEE 802.2 Link Level Control
319 *======================================================================================*/ 335 *======================================================================================*/
320 336
321class OLLCPacket : public QObject 337class OLLCPacket : public QObject
322{ 338{
323 Q_OBJECT 339 Q_OBJECT
324 340
325 public: 341 public:
326 OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); 342 OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 );
327 virtual ~OLLCPacket(); 343 virtual ~OLLCPacket();
328 344
329 private: 345 private:
330 const struct ieee_802_11_802_2_header* _header; 346 const struct ieee_802_11_802_2_header* _header;
331}; 347};
332 348
333/*====================================================================================== 349/*======================================================================================
334 * OIPPacket 350 * OIPPacket
335 *======================================================================================*/ 351 *======================================================================================*/
336 352
337class OIPPacket : public QObject 353class OIPPacket : public QObject
338{ 354{
339 Q_OBJECT 355 Q_OBJECT
340 356
341 public: 357 public: