summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 04b1bb1..e362883 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -319,648 +319,649 @@ OTCPPacket::~OTCPPacket()
319 * OWaveLanPacket 319 * OWaveLanPacket
320 *======================================================================================*/ 320 *======================================================================================*/
321 321
322 322
323OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) 323OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent )
324 :QObject( parent, "802.11" ), _wlanhdr( data ) 324 :QObject( parent, "802.11" ), _wlanhdr( data )
325 325
326{ 326{
327 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); 327 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." );
328 qDebug( "type: %0X", type() ); 328 qDebug( "type: %0X", type() );
329 qDebug( "subType: %0X", subType() ); 329 qDebug( "subType: %0X", subType() );
330 qDebug( "duration: %d", duration() ); 330 qDebug( "duration: %d", duration() );
331 qDebug( "powermanagement: %d", usesPowerManagement() ); 331 qDebug( "powermanagement: %d", usesPowerManagement() );
332 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); 332 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" );
333 qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); 333 qDebug( "MAC1: %s", (const char*) macAddress1().toString() );
334 qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); 334 qDebug( "MAC2: %s", (const char*) macAddress2().toString() );
335 qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); 335 qDebug( "MAC3: %s", (const char*) macAddress3().toString() );
336 qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); 336 qDebug( "MAC4: %s", (const char*) macAddress4().toString() );
337 337
338 switch ( type() ) 338 switch ( type() )
339 { 339 {
340 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; 340 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
341 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; 341 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break;
342 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; 342 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break;
343 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); 343 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() );
344 } 344 }
345} 345}
346 346
347OWaveLanPacket::~OWaveLanPacket() 347OWaveLanPacket::~OWaveLanPacket()
348{ 348{
349} 349}
350 350
351 351
352int OWaveLanPacket::duration() const 352int OWaveLanPacket::duration() const
353{ 353{
354 return _wlanhdr->duration; 354 return _wlanhdr->duration;
355} 355}
356 356
357 357
358OMacAddress OWaveLanPacket::macAddress1() const 358OMacAddress OWaveLanPacket::macAddress1() const
359{ 359{
360 return OMacAddress( _wlanhdr->mac1 ); 360 return OMacAddress( _wlanhdr->mac1 );
361} 361}
362 362
363 363
364OMacAddress OWaveLanPacket::macAddress2() const 364OMacAddress OWaveLanPacket::macAddress2() const
365{ 365{
366 return OMacAddress( _wlanhdr->mac2 ); 366 return OMacAddress( _wlanhdr->mac2 );
367} 367}
368 368
369 369
370OMacAddress OWaveLanPacket::macAddress3() const 370OMacAddress OWaveLanPacket::macAddress3() const
371{ 371{
372 return OMacAddress( _wlanhdr->mac3 ); 372 return OMacAddress( _wlanhdr->mac3 );
373} 373}
374 374
375 375
376OMacAddress OWaveLanPacket::macAddress4() const 376OMacAddress OWaveLanPacket::macAddress4() const
377{ 377{
378 return OMacAddress( _wlanhdr->mac4 ); 378 return OMacAddress( _wlanhdr->mac4 );
379} 379}
380 380
381 381
382int OWaveLanPacket::subType() const 382int OWaveLanPacket::subType() const
383{ 383{
384 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 384 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
385} 385}
386 386
387 387
388int OWaveLanPacket::type() const 388int OWaveLanPacket::type() const
389{ 389{
390 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 390 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
391} 391}
392 392
393 393
394int OWaveLanPacket::version() const 394int OWaveLanPacket::version() const
395{ 395{
396 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 396 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
397} 397}
398 398
399 399
400bool OWaveLanPacket::fromDS() const 400bool OWaveLanPacket::fromDS() const
401{ 401{
402 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 402 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
403} 403}
404 404
405 405
406bool OWaveLanPacket::toDS() const 406bool OWaveLanPacket::toDS() const
407{ 407{
408 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 408 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
409} 409}
410 410
411 411
412bool OWaveLanPacket::usesPowerManagement() const 412bool OWaveLanPacket::usesPowerManagement() const
413{ 413{
414 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 414 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
415} 415}
416 416
417 417
418bool OWaveLanPacket::usesWep() const 418bool OWaveLanPacket::usesWep() const
419{ 419{
420 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 420 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
421} 421}
422 422
423 423
424/*====================================================================================== 424/*======================================================================================
425 * OWaveLanManagementPacket 425 * OWaveLanManagementPacket
426 *======================================================================================*/ 426 *======================================================================================*/
427 427
428OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) 428OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
429 :QObject( parent, "802.11 Management" ), _header( data ), 429 :QObject( parent, "802.11 Management" ), _header( data ),
430 _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) 430 _body( (const struct ieee_802_11_mgmt_body*) (data+1) )
431{ 431{
432 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); 432 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." );
433 qDebug( "Detected subtype is '%s'", (const char*) managementType() ); 433 qDebug( "Detected subtype is '%s'", (const char*) managementType() );
434 434
435 // grab tagged values 435 // grab tagged values
436 const unsigned char* ptr = (const unsigned char*) (_body+1); 436 const unsigned char* ptr = (const unsigned char*) (_body+1);
437 while (ptr < end) 437 while (ptr < end)
438 { 438 {
439 switch ( *ptr ) 439 switch ( *ptr )
440 { 440 {
441 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; 441 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break;
442 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; 442 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break;
443 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; 443 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break;
444 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; 444 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break;
445 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; 445 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break;
446 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; 446 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break;
447 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; 447 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break;
448 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; 448 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break;
449 } 449 }
450 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value 450 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value
451 ptr+= 2; // skip tag ID and length 451 ptr+= 2; // skip tag ID and length
452 } 452 }
453} 453}
454 454
455 455
456OWaveLanManagementPacket::~OWaveLanManagementPacket() 456OWaveLanManagementPacket::~OWaveLanManagementPacket()
457{ 457{
458} 458}
459 459
460 460
461QString OWaveLanManagementPacket::managementType() const 461QString OWaveLanManagementPacket::managementType() const
462{ 462{
463 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) 463 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) )
464 { 464 {
465 case ST_ASSOC_REQUEST: return "AssociationRequest"; break; 465 case ST_ASSOC_REQUEST: return "AssociationRequest"; break;
466 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; 466 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break;
467 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; 467 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break;
468 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; 468 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break;
469 case ST_PROBE_REQUEST: return "ProbeRequest"; break; 469 case ST_PROBE_REQUEST: return "ProbeRequest"; break;
470 case ST_PROBE_RESPONSE: return "ProbeResponse"; break; 470 case ST_PROBE_RESPONSE: return "ProbeResponse"; break;
471 case ST_BEACON: return "Beacon"; break; 471 case ST_BEACON: return "Beacon"; break;
472 case ST_ATIM: return "Atim"; break; 472 case ST_ATIM: return "Atim"; break;
473 case ST_DISASSOC: return "Disassociation"; break; 473 case ST_DISASSOC: return "Disassociation"; break;
474 case ST_AUTH: return "Authentication"; break; 474 case ST_AUTH: return "Authentication"; break;
475 case ST_DEAUTH: return "Deathentication"; break; 475 case ST_DEAUTH: return "Deathentication"; break;
476 default: 476 default:
477 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); 477 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) );
478 return "Unknown"; 478 return "Unknown";
479 } 479 }
480} 480}
481 481
482 482
483int OWaveLanManagementPacket::beaconInterval() const 483int OWaveLanManagementPacket::beaconInterval() const
484{ 484{
485 return EXTRACT_LE_16BITS( &_body->beacon_interval ); 485 return EXTRACT_LE_16BITS( &_body->beacon_interval );
486} 486}
487 487
488 488
489int OWaveLanManagementPacket::capabilities() const 489int OWaveLanManagementPacket::capabilities() const
490{ 490{
491 return EXTRACT_LE_16BITS( &_body->capability_info ); 491 return EXTRACT_LE_16BITS( &_body->capability_info );
492} 492}
493 493
494 494
495bool OWaveLanManagementPacket::canESS() const 495bool OWaveLanManagementPacket::canESS() const
496{ 496{
497 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 497 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) );
498} 498}
499 499
500 500
501bool OWaveLanManagementPacket::canIBSS() const 501bool OWaveLanManagementPacket::canIBSS() const
502{ 502{
503 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 503 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) );
504} 504}
505 505
506 506
507bool OWaveLanManagementPacket::canCFP() const 507bool OWaveLanManagementPacket::canCFP() const
508{ 508{
509 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); 509 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) );
510} 510}
511 511
512 512
513bool OWaveLanManagementPacket::canCFP_REQ() const 513bool OWaveLanManagementPacket::canCFP_REQ() const
514{ 514{
515 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); 515 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) );
516} 516}
517 517
518 518
519bool OWaveLanManagementPacket::canPrivacy() const 519bool OWaveLanManagementPacket::canPrivacy() const
520{ 520{
521 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); 521 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) );
522} 522}
523 523
524 524
525/*====================================================================================== 525/*======================================================================================
526 * OWaveLanManagementSSID 526 * OWaveLanManagementSSID
527 *======================================================================================*/ 527 *======================================================================================*/
528 528
529OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) 529OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent )
530 :QObject( parent, "802.11 SSID" ), _data( data ) 530 :QObject( parent, "802.11 SSID" ), _data( data )
531{ 531{
532 qDebug( "OWaveLanManagementSSID()" ); 532 qDebug( "OWaveLanManagementSSID()" );
533} 533}
534 534
535 535
536OWaveLanManagementSSID::~OWaveLanManagementSSID() 536OWaveLanManagementSSID::~OWaveLanManagementSSID()
537{ 537{
538} 538}
539 539
540 540
541QString OWaveLanManagementSSID::ID() const 541QString OWaveLanManagementSSID::ID() const
542{ 542{
543 int length = _data->length; 543 int length = _data->length;
544 if ( length > 32 ) length = 32; 544 if ( length > 32 ) length = 32;
545 char essid[length+1]; 545 char essid[length+1];
546 memcpy( &essid, &_data->ssid, length ); 546 memcpy( &essid, &_data->ssid, length );
547 essid[length] = 0x0; 547 essid[length] = 0x0;
548 return essid; 548 return essid;
549} 549}
550 550
551 551
552/*====================================================================================== 552/*======================================================================================
553 * OWaveLanManagementRates 553 * OWaveLanManagementRates
554 *======================================================================================*/ 554 *======================================================================================*/
555 555
556OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) 556OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent )
557 :QObject( parent, "802.11 Rates" ), _data( data ) 557 :QObject( parent, "802.11 Rates" ), _data( data )
558{ 558{
559 qDebug( "OWaveLanManagementRates()" ); 559 qDebug( "OWaveLanManagementRates()" );
560} 560}
561 561
562 562
563OWaveLanManagementRates::~OWaveLanManagementRates() 563OWaveLanManagementRates::~OWaveLanManagementRates()
564{ 564{
565} 565}
566 566
567/*====================================================================================== 567/*======================================================================================
568 * OWaveLanManagementCF 568 * OWaveLanManagementCF
569 *======================================================================================*/ 569 *======================================================================================*/
570 570
571OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) 571OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent )
572 :QObject( parent, "802.11 CF" ), _data( data ) 572 :QObject( parent, "802.11 CF" ), _data( data )
573{ 573{
574 qDebug( "OWaveLanManagementCF()" ); 574 qDebug( "OWaveLanManagementCF()" );
575} 575}
576 576
577 577
578OWaveLanManagementCF::~OWaveLanManagementCF() 578OWaveLanManagementCF::~OWaveLanManagementCF()
579{ 579{
580} 580}
581 581
582/*====================================================================================== 582/*======================================================================================
583 * OWaveLanManagementFH 583 * OWaveLanManagementFH
584 *======================================================================================*/ 584 *======================================================================================*/
585 585
586OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) 586OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
587 :QObject( parent, "802.11 FH" ), _data( data ) 587 :QObject( parent, "802.11 FH" ), _data( data )
588{ 588{
589 qDebug( "OWaveLanManagementFH()" ); 589 qDebug( "OWaveLanManagementFH()" );
590} 590}
591 591
592 592
593OWaveLanManagementFH::~OWaveLanManagementFH() 593OWaveLanManagementFH::~OWaveLanManagementFH()
594{ 594{
595} 595}
596 596
597/*====================================================================================== 597/*======================================================================================
598 * OWaveLanManagementDS 598 * OWaveLanManagementDS
599 *======================================================================================*/ 599 *======================================================================================*/
600 600
601OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) 601OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
602 :QObject( parent, "802.11 DS" ), _data( data ) 602 :QObject( parent, "802.11 DS" ), _data( data )
603{ 603{
604 qDebug( "OWaveLanManagementDS()" ); 604 qDebug( "OWaveLanManagementDS()" );
605} 605}
606 606
607 607
608OWaveLanManagementDS::~OWaveLanManagementDS() 608OWaveLanManagementDS::~OWaveLanManagementDS()
609{ 609{
610} 610}
611 611
612 612
613int OWaveLanManagementDS::channel() const 613int OWaveLanManagementDS::channel() const
614{ 614{
615 return _data->channel; 615 return _data->channel;
616} 616}
617 617
618/*====================================================================================== 618/*======================================================================================
619 * OWaveLanManagementTim 619 * OWaveLanManagementTim
620 *======================================================================================*/ 620 *======================================================================================*/
621 621
622OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) 622OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
623 :QObject( parent, "802.11 Tim" ), _data( data ) 623 :QObject( parent, "802.11 Tim" ), _data( data )
624{ 624{
625 qDebug( "OWaveLanManagementTim()" ); 625 qDebug( "OWaveLanManagementTim()" );
626} 626}
627 627
628 628
629OWaveLanManagementTim::~OWaveLanManagementTim() 629OWaveLanManagementTim::~OWaveLanManagementTim()
630{ 630{
631} 631}
632 632
633/*====================================================================================== 633/*======================================================================================
634 * OWaveLanManagementIBSS 634 * OWaveLanManagementIBSS
635 *======================================================================================*/ 635 *======================================================================================*/
636 636
637OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) 637OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
638 :QObject( parent, "802.11 IBSS" ), _data( data ) 638 :QObject( parent, "802.11 IBSS" ), _data( data )
639{ 639{
640 qDebug( "OWaveLanManagementIBSS()" ); 640 qDebug( "OWaveLanManagementIBSS()" );
641} 641}
642 642
643 643
644OWaveLanManagementIBSS::~OWaveLanManagementIBSS() 644OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
645{ 645{
646} 646}
647 647
648/*====================================================================================== 648/*======================================================================================
649 * OWaveLanManagementChallenge 649 * OWaveLanManagementChallenge
650 *======================================================================================*/ 650 *======================================================================================*/
651 651
652OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) 652OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
653 :QObject( parent, "802.11 Challenge" ), _data( data ) 653 :QObject( parent, "802.11 Challenge" ), _data( data )
654{ 654{
655 qDebug( "OWaveLanManagementChallenge()" ); 655 qDebug( "OWaveLanManagementChallenge()" );
656} 656}
657 657
658 658
659OWaveLanManagementChallenge::~OWaveLanManagementChallenge() 659OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
660{ 660{
661} 661}
662 662
663/*====================================================================================== 663/*======================================================================================
664 * OWaveLanDataPacket 664 * OWaveLanDataPacket
665 *======================================================================================*/ 665 *======================================================================================*/
666 666
667OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) 667OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
668 :QObject( parent, "802.11 Data" ), _header( data ) 668 :QObject( parent, "802.11 Data" ), _header( data )
669{ 669{
670 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); 670 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." );
671 671
672 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); 672 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header );
673 673
674 #warning The next line works for most cases, but can not be correct generally! 674 #warning The next line works for most cases, but can not be correct generally!
675 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address 675 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address
676 676
677 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); 677 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
678} 678}
679 679
680 680
681OWaveLanDataPacket::~OWaveLanDataPacket() 681OWaveLanDataPacket::~OWaveLanDataPacket()
682{ 682{
683} 683}
684 684
685 685
686/*====================================================================================== 686/*======================================================================================
687 * OLLCPacket 687 * OLLCPacket
688 *======================================================================================*/ 688 *======================================================================================*/
689 689
690OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) 690OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
691 :QObject( parent, "802.11 LLC" ), _header( data ) 691 :QObject( parent, "802.11 LLC" ), _header( data )
692{ 692{
693 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); 693 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." );
694 694
695 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) 695 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
696 { 696 {
697 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 697 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) );
698 698
699 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h 699 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
700 { 700 {
701 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 701 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
702 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); 702 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" );
703 } 703 }
704 704
705 } 705 }
706} 706}
707 707
708 708
709OLLCPacket::~OLLCPacket() 709OLLCPacket::~OLLCPacket()
710{ 710{
711} 711}
712 712
713 713
714/*====================================================================================== 714/*======================================================================================
715 * OWaveLanControlPacket 715 * OWaveLanControlPacket
716 *======================================================================================*/ 716 *======================================================================================*/
717 717
718OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) 718OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent )
719 :QObject( parent, "802.11 Data" ), _header( data ) 719 :QObject( parent, "802.11 Data" ), _header( data )
720{ 720{
721 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); 721 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." );
722 //TODO: Implement this 722 //TODO: Implement this
723} 723}
724 724
725 725
726OWaveLanControlPacket::~OWaveLanControlPacket() 726OWaveLanControlPacket::~OWaveLanControlPacket()
727{ 727{
728} 728}
729 729
730 730
731/*====================================================================================== 731/*======================================================================================
732 * OPacketCapturer 732 * OPacketCapturer
733 *======================================================================================*/ 733 *======================================================================================*/
734 734
735OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 735OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
736 :QObject( parent, name ), _name( QString::null ), _open( false ), 736 :QObject( parent, name ), _name( QString::null ), _open( false ),
737 _pch( 0 ), _pcd( 0 ), _sn( 0 ) 737 _pch( 0 ), _pcd( 0 ), _sn( 0 )
738{ 738{
739} 739}
740 740
741 741
742OPacketCapturer::~OPacketCapturer() 742OPacketCapturer::~OPacketCapturer()
743{ 743{
744 if ( _open ) 744 if ( _open )
745 { 745 {
746 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 746 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
747 close(); 747 close();
748 } 748 }
749} 749}
750 750
751 751
752void OPacketCapturer::setBlocking( bool b ) 752void OPacketCapturer::setBlocking( bool b )
753{ 753{
754 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 754 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
755 { 755 {
756 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 756 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
757 } 757 }
758 else 758 else
759 { 759 {
760 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 760 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
761 } 761 }
762} 762}
763 763
764 764
765bool OPacketCapturer::blocking() const 765bool OPacketCapturer::blocking() const
766{ 766{
767 int b = pcap_getnonblock( _pch, _errbuf ); 767 int b = pcap_getnonblock( _pch, _errbuf );
768 if ( b == -1 ) 768 if ( b == -1 )
769 { 769 {
770 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 770 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
771 return -1; 771 return -1;
772 } 772 }
773 return !b; 773 return !b;
774} 774}
775 775
776 776
777void OPacketCapturer::close() 777void OPacketCapturer::close()
778{ 778{
779 if ( _open ) 779 if ( _open )
780 { 780 {
781 if ( _sn ) 781 if ( _sn )
782 { 782 {
783 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 783 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
784 delete _sn; 784 delete _sn;
785 } 785 }
786 if ( _pcd ) 786 if ( _pcd )
787 { 787 {
788 pcap_dump_close( _pcd ); 788 pcap_dump_close( _pcd );
789 _pcd = 0; 789 _pcd = 0;
790 } 790 }
791 pcap_close( _pch ); 791 pcap_close( _pch );
792 _open = false; 792 _open = false;
793 } 793 }
794 794
795 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); 795 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
796 qDebug( "--------------------------------------------------" ); 796 qDebug( "--------------------------------------------------" );
797 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) 797 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
798 qDebug( "%s : %d", (const char*) it.key(), it.data() ); 798 qDebug( "%s : %d", (const char*) it.key(), it.data() );
799 qDebug( "--------------------------------------------------" ); 799 qDebug( "--------------------------------------------------" );
800 800
801} 801}
802 802
803 803
804int OPacketCapturer::dataLink() const 804int OPacketCapturer::dataLink() const
805{ 805{
806 return pcap_datalink( _pch ); 806 return pcap_datalink( _pch );
807} 807}
808 808
809 809
810int OPacketCapturer::fileno() const 810int OPacketCapturer::fileno() const
811{ 811{
812 if ( _open ) 812 if ( _open )
813 { 813 {
814 return pcap_fileno( _pch ); 814 return pcap_fileno( _pch );
815 } 815 }
816 else 816 else
817 { 817 {
818 return -1; 818 return -1;
819 } 819 }
820} 820}
821 821
822OPacket* OPacketCapturer::next() 822OPacket* OPacketCapturer::next()
823{ 823{
824 packetheaderstruct header; 824 packetheaderstruct header;
825 qDebug( "==> OPacketCapturer::next()" ); 825 qDebug( "==> OPacketCapturer::next()" );
826 const unsigned char* pdata = pcap_next( _pch, &header ); 826 const unsigned char* pdata = pcap_next( _pch, &header );
827 qDebug( "<== OPacketCapturer::next()" ); 827 qDebug( "<== OPacketCapturer::next()" );
828 if ( _pcd ) 828 if ( _pcd )
829 pcap_dump( (u_char*) _pcd, &header, pdata ); 829 pcap_dump( (u_char*) _pcd, &header, pdata );
830 830
831 if ( header.len ) 831 if ( pdata && header.len )
832 { 832 {
833 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 833 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
834 // packets shouldn't be inserted in the QObject child-parent hierarchy, 834 // packets shouldn't be inserted in the QObject child-parent hierarchy,
835 // because due to memory constraints they will be deleted as soon 835 // because due to memory constraints they will be deleted as soon
836 // as possible - that is right after they have been processed 836 // as possible - that is right after they have been processed
837 // by emit() [ see below ] 837 // by emit() [ see below ]
838 //TODO: make gathering statistics optional, because it takes time 838 //TODO: make gathering statistics optional, because it takes time
839 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 839 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
840 840
841 return p; 841 return p;
842 } 842 }
843 else 843 else
844 { 844 {
845 qWarning( "OPacketCapturer::next() - no packet received!" );
845 return 0; 846 return 0;
846 } 847 }
847} 848}
848 849
849 850
850bool OPacketCapturer::open( const QString& name, const QString& filename ) 851bool OPacketCapturer::open( const QString& name, const QString& filename )
851{ 852{
852 if ( _open ) 853 if ( _open )
853 { 854 {
854 if ( name == _name ) // ignore opening an already openend device 855 if ( name == _name ) // ignore opening an already openend device
855 { 856 {
856 return true; 857 return true;
857 } 858 }
858 else // close the last opened device 859 else // close the last opened device
859 { 860 {
860 close(); 861 close();
861 } 862 }
862 } 863 }
863 864
864 _name = name; 865 _name = name;
865 866
866 // open libpcap 867 // open libpcap
867 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 868 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
868 869
869 if ( !handle ) 870 if ( !handle )
870 { 871 {
871 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 872 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
872 return false; 873 return false;
873 } 874 }
874 875
875 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); 876 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
876 _pch = handle; 877 _pch = handle;
877 _open = true; 878 _open = true;
878 _stats.clear(); 879 _stats.clear();
879 880
880 // in case we have an application object, create a socket notifier 881 // in case we have an application object, create a socket notifier
881 if ( qApp ) //TODO: I don't like this here... 882 if ( qApp ) //TODO: I don't like this here...
882 { 883 {
883 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 884 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
884 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 885 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
885 } 886 }
886 887
887 // if requested, open a dump 888 // if requested, open a dump
888 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); 889 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
889 if ( !dump ) 890 if ( !dump )
890 { 891 {
891 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); 892 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );
892 return false; 893 return false;
893 } 894 }
894 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); 895 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename );
895 _pcd = dump; 896 _pcd = dump;
896 897
897 return true; 898 return true;
898} 899}
899 900
900 901
901bool OPacketCapturer::open( const QFile& file ) 902bool OPacketCapturer::open( const QFile& file )
902{ 903{
903 QString name = file.name(); 904 QString name = file.name();
904 905
905 if ( _open ) 906 if ( _open )
906 { 907 {
907 close(); 908 close();
908 if ( name == _name ) // ignore opening an already openend device 909 if ( name == _name ) // ignore opening an already openend device
909 { 910 {
910 return true; 911 return true;
911 } 912 }
912 else // close the last opened device 913 else // close the last opened device
913 { 914 {
914 close(); 915 close();
915 } 916 }
916 } 917 }
917 918
918 _name = name; 919 _name = name;
919 920
920 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); 921 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] );
921 922
922 if ( handle ) 923 if ( handle )
923 { 924 {
924 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 925 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
925 _pch = handle; 926 _pch = handle;
926 _open = true; 927 _open = true;
927 928
928 // in case we have an application object, create a socket notifier 929 // in case we have an application object, create a socket notifier
929 if ( qApp ) 930 if ( qApp )
930 { 931 {
931 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 932 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
932 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 933 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
933 } 934 }
934 935
935 return true; 936 return true;
936 } 937 }
937 else 938 else
938 { 939 {
939 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 940 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
940 return false; 941 return false;
941 } 942 }
942 943
943} 944}
944 945
945 946
946bool OPacketCapturer::isOpen() const 947bool OPacketCapturer::isOpen() const
947{ 948{
948 return _open; 949 return _open;
949} 950}
950 951
951 952
952void OPacketCapturer::readyToReceive() 953void OPacketCapturer::readyToReceive()
953{ 954{
954 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); 955 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" );
955 OPacket* p = next(); 956 OPacket* p = next();
956 emit receivedPacket( p ); 957 emit receivedPacket( p );
957 // emit is synchronous - packet has been dealt with, now it's safe to delete 958 // emit is synchronous - packet has been dealt with, now it's safe to delete
958 delete p; 959 delete p;
959} 960}
960 961
961 962
962const QMap<QString,int>& OPacketCapturer::statistics() const 963const QMap<QString,int>& OPacketCapturer::statistics() const
963{ 964{
964 return _stats; 965 return _stats;
965} 966}
966 967