summaryrefslogtreecommitdiff
path: root/libopie2/opienet/onetwork.cpp
Unidiff
Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index be2736a..95e7043 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -558,193 +558,194 @@ void OWirelessNetworkInterface::buildPrivateList()
558 558
559 for ( int i = 0; i < _iwr.u.data.length; ++i ) 559 for ( int i = 0; i < _iwr.u.data.length; ++i )
560 { 560 {
561 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 561 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
562 } 562 }
563 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); 563 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
564} 564}
565 565
566 566
567int OWirelessNetworkInterface::channel() const 567int OWirelessNetworkInterface::channel() const
568{ 568{
569 //FIXME: When monitoring enabled, then use it 569 //FIXME: When monitoring enabled, then use it
570 //FIXME: to gather the current RF channel 570 //FIXME: to gather the current RF channel
571 //FIXME: Until then, get active channel from hopper. 571 //FIXME: Until then, get active channel from hopper.
572 if ( _hopper && _hopper->isActive() ) 572 if ( _hopper && _hopper->isActive() )
573 return _hopper->channel(); 573 return _hopper->channel();
574 574
575 if ( !wioctl( SIOCGIWFREQ ) ) 575 if ( !wioctl( SIOCGIWFREQ ) )
576 { 576 {
577 return -1; 577 return -1;
578 } 578 }
579 else 579 else
580 { 580 {
581 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 581 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
582 } 582 }
583} 583}
584 584
585 585
586void OWirelessNetworkInterface::setChannel( int c ) const 586void OWirelessNetworkInterface::setChannel( int c ) const
587{ 587{
588 if ( !_mon ) 588 if ( !_mon )
589 { 589 {
590 memset( &_iwr, 0, sizeof( struct iwreq ) ); 590 memset( &_iwr, 0, sizeof( struct iwreq ) );
591 _iwr.u.freq.m = c; 591 _iwr.u.freq.m = c;
592 _iwr.u.freq.e = 0; 592 _iwr.u.freq.e = 0;
593 wioctl( SIOCSIWFREQ ); 593 wioctl( SIOCSIWFREQ );
594 } 594 }
595 else 595 else
596 { 596 {
597 _mon->setChannel( c ); 597 _mon->setChannel( c );
598 } 598 }
599} 599}
600 600
601 601
602double OWirelessNetworkInterface::frequency() const 602double OWirelessNetworkInterface::frequency() const
603{ 603{
604 if ( !wioctl( SIOCGIWFREQ ) ) 604 if ( !wioctl( SIOCGIWFREQ ) )
605 { 605 {
606 return -1.0; 606 return -1.0;
607 } 607 }
608 else 608 else
609 { 609 {
610 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 610 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
611 } 611 }
612} 612}
613 613
614 614
615int OWirelessNetworkInterface::channels() const 615int OWirelessNetworkInterface::channels() const
616{ 616{
617 return _channels.count(); 617 return _channels.count();
618} 618}
619 619
620 620
621void OWirelessNetworkInterface::setChannelHopping( int interval ) 621void OWirelessNetworkInterface::setChannelHopping( int interval )
622{ 622{
623 if ( !_hopper ) _hopper = new OChannelHopper( this ); 623 if ( !_hopper ) _hopper = new OChannelHopper( this );
624 _hopper->setInterval( interval ); 624 _hopper->setInterval( interval );
625 //FIXME: When and by whom will the channel hopper be deleted? 625 //FIXME: When and by whom will the channel hopper be deleted?
626 //TODO: rely on QObject hierarchy 626 //TODO: rely on QObject hierarchy
627} 627}
628 628
629 629
630int OWirelessNetworkInterface::channelHopping() const 630int OWirelessNetworkInterface::channelHopping() const
631{ 631{
632 return _hopper->interval(); 632 return _hopper->interval();
633} 633}
634 634
635 635
636OChannelHopper* OWirelessNetworkInterface::channelHopper() const 636OChannelHopper* OWirelessNetworkInterface::channelHopper() const
637{ 637{
638 return _hopper; 638 return _hopper;
639} 639}
640 640
641 641
642void OWirelessNetworkInterface::setMonitorMode( bool b ) 642void OWirelessNetworkInterface::setMonitorMode( bool b )
643{ 643{
644 if ( _mon ) 644 if ( _mon )
645 _mon->setEnabled( b ); 645 _mon->setEnabled( b );
646 else 646 else
647 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 647 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
648} 648}
649 649
650 650
651bool OWirelessNetworkInterface::monitorMode() const 651bool OWirelessNetworkInterface::monitorMode() const
652{ 652{
653 qDebug( "dataLinkType = %d", dataLinkType() ); 653 qDebug( "dataLinkType = %d", dataLinkType() );
654 return dataLinkType() == ARPHRD_IEEE80211; 654 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
655 // 802 is the header type for PRISM - Linux support for this is pending...
655} 656}
656 657
657 658
658QString OWirelessNetworkInterface::nickName() const 659QString OWirelessNetworkInterface::nickName() const
659{ 660{
660 char str[IW_ESSID_MAX_SIZE]; 661 char str[IW_ESSID_MAX_SIZE];
661 _iwr.u.data.pointer = &str[0]; 662 _iwr.u.data.pointer = &str[0];
662 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 663 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
663 if ( !wioctl( SIOCGIWNICKN ) ) 664 if ( !wioctl( SIOCGIWNICKN ) )
664 { 665 {
665 return "<unknown>"; 666 return "<unknown>";
666 } 667 }
667 else 668 else
668 { 669 {
669 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 670 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
670 return str; 671 return str;
671 } 672 }
672} 673}
673 674
674 675
675void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 676void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
676{ 677{
677 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 678 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
678 if ( !priv ) 679 if ( !priv )
679 { 680 {
680 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); 681 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
681 return; 682 return;
682 } 683 }
683 if ( priv->numberSetArgs() != numargs ) 684 if ( priv->numberSetArgs() != numargs )
684 { 685 {
685 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); 686 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs );
686 return; 687 return;
687 } 688 }
688 689
689 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); 690 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() );
690 memset( &_iwr, 0, sizeof _iwr ); 691 memset( &_iwr, 0, sizeof _iwr );
691 va_list argp; 692 va_list argp;
692 va_start( argp, numargs ); 693 va_start( argp, numargs );
693 for ( int i = 0; i < numargs; ++i ) 694 for ( int i = 0; i < numargs; ++i )
694 { 695 {
695 priv->setParameter( i, va_arg( argp, int ) ); 696 priv->setParameter( i, va_arg( argp, int ) );
696 } 697 }
697 va_end( argp ); 698 va_end( argp );
698 priv->invoke(); 699 priv->invoke();
699} 700}
700 701
701 702
702void OWirelessNetworkInterface::getPrivate( const QString& call ) 703void OWirelessNetworkInterface::getPrivate( const QString& call )
703{ 704{
704 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); 705 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
705} 706}
706 707
707 708
708bool OWirelessNetworkInterface::hasPrivate( const QString& call ) 709bool OWirelessNetworkInterface::hasPrivate( const QString& call )
709{ 710{
710 return child( (const char*) call ); 711 return child( (const char*) call );
711} 712}
712 713
713 714
714QString OWirelessNetworkInterface::SSID() const 715QString OWirelessNetworkInterface::SSID() const
715{ 716{
716 char str[IW_ESSID_MAX_SIZE]; 717 char str[IW_ESSID_MAX_SIZE];
717 _iwr.u.essid.pointer = &str[0]; 718 _iwr.u.essid.pointer = &str[0];
718 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 719 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
719 if ( !wioctl( SIOCGIWESSID ) ) 720 if ( !wioctl( SIOCGIWESSID ) )
720 { 721 {
721 return "<unknown>"; 722 return "<unknown>";
722 } 723 }
723 else 724 else
724 { 725 {
725 return str; 726 return str;
726 } 727 }
727} 728}
728 729
729 730
730void OWirelessNetworkInterface::setSSID( const QString& ssid ) 731void OWirelessNetworkInterface::setSSID( const QString& ssid )
731{ 732{
732 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 733 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
733 _iwr.u.essid.length = ssid.length(); 734 _iwr.u.essid.length = ssid.length();
734 wioctl( SIOCSIWESSID ); 735 wioctl( SIOCSIWESSID );
735} 736}
736 737
737 738
738bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 739bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
739{ 740{
740 int result = ::ioctl( _sfd, call, &iwreq ); 741 int result = ::ioctl( _sfd, call, &iwreq );
741 if ( result == -1 ) 742 if ( result == -1 )
742 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 743 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
743 else 744 else
744 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); 745 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call );
745 return ( result != -1 ); 746 return ( result != -1 );
746} 747}
747 748
748 749
749bool OWirelessNetworkInterface::wioctl( int call ) const 750bool OWirelessNetworkInterface::wioctl( int call ) const
750{ 751{
@@ -840,117 +841,117 @@ void OCiscoMonitoringInterface::setChannel( int )
840 * OWlanNGMonitoringInterface 841 * OWlanNGMonitoringInterface
841 *======================================================================================*/ 842 *======================================================================================*/
842 843
843 844
844OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) 845OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface )
845 :OMonitoringInterface( iface ) 846 :OMonitoringInterface( iface )
846{ 847{
847 iface->setMonitoring( this ); 848 iface->setMonitoring( this );
848} 849}
849 850
850 851
851OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 852OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
852{ 853{
853} 854}
854 855
855 856
856void OWlanNGMonitoringInterface::setEnabled( bool b ) 857void OWlanNGMonitoringInterface::setEnabled( bool b )
857{ 858{
858 //FIXME: do nothing if its already in the same mode 859 //FIXME: do nothing if its already in the same mode
859 860
860 QString enable = b ? "true" : "false"; 861 QString enable = b ? "true" : "false";
861 QString cmd; 862 QString cmd;
862 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); 863 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable );
863 system( cmd ); 864 system( cmd );
864} 865}
865 866
866 867
867QString OWlanNGMonitoringInterface::name() const 868QString OWlanNGMonitoringInterface::name() const
868{ 869{
869 return "wlan-ng"; 870 return "wlan-ng";
870} 871}
871 872
872 873
873void OWlanNGMonitoringInterface::setChannel( int ) 874void OWlanNGMonitoringInterface::setChannel( int )
874{ 875{
875 // wlan-ng devices automatically switch channels when in monitor mode 876 // wlan-ng devices automatically switch channels when in monitor mode
876} 877}
877 878
878 879
879/*====================================================================================== 880/*======================================================================================
880 * OHostAPMonitoringInterface 881 * OHostAPMonitoringInterface
881 *======================================================================================*/ 882 *======================================================================================*/
882 883
883OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) 884OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface )
884 :OMonitoringInterface( iface ) 885 :OMonitoringInterface( iface )
885{ 886{
886 iface->setMonitoring( this ); 887 iface->setMonitoring( this );
887} 888}
888 889
889OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 890OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
890{ 891{
891} 892}
892 893
893void OHostAPMonitoringInterface::setEnabled( bool b ) 894void OHostAPMonitoringInterface::setEnabled( bool b )
894{ 895{
895 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 896 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
896 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 897 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
897 898
898 //TODO: check wireless extensions version on runtime and use 899 //TODO: check wireless extensions version on runtime and use
899 //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15 900 //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15
900 901
901 if ( b ) 902 if ( b )
902 { 903 {
903 _if->setPrivate( "monitor", 1, 2 ); 904 _if->setPrivate( "monitor", 1, 2 );
904 } 905 }
905 else 906 else
906 { 907 {
907 _if->setPrivate( "monitor", 1, 0 ); 908 _if->setPrivate( "monitor", 1, 0 );
908 } 909 }
909} 910}
910 911
911 912
912QString OHostAPMonitoringInterface::name() const 913QString OHostAPMonitoringInterface::name() const
913{ 914{
914 return "hostap"; 915 return "hostap";
915} 916}
916 917
917 918
918/*====================================================================================== 919/*======================================================================================
919 * OOrinocoNetworkInterface 920 * OOrinocoNetworkInterface
920 *======================================================================================*/ 921 *======================================================================================*/
921 922
922OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) 923OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface )
923 :OMonitoringInterface( iface ) 924 :OMonitoringInterface( iface )
924{ 925{
925 iface->setMonitoring( this ); 926 iface->setMonitoring( this );
926} 927}
927 928
928 929
929OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 930OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
930{ 931{
931} 932}
932 933
933 934
934void OOrinocoMonitoringInterface::setChannel( int c ) 935void OOrinocoMonitoringInterface::setChannel( int c )
935{ 936{
936 _if->setPrivate( "monitor", 2, 2, c ); 937 _if->setPrivate( "monitor", 2, 1, c );
937} 938}
938 939
939 940
940void OOrinocoMonitoringInterface::setEnabled( bool b ) 941void OOrinocoMonitoringInterface::setEnabled( bool b )
941{ 942{
942 if ( b ) 943 if ( b )
943 { 944 {
944 setChannel( 1 ); 945 setChannel( 1 );
945 } 946 }
946 else 947 else
947 { 948 {
948 _if->setPrivate( "monitor", 2, 0, 0 ); 949 _if->setPrivate( "monitor", 2, 0, 0 );
949 } 950 }
950} 951}
951 952
952 953
953QString OOrinocoMonitoringInterface::name() const 954QString OOrinocoMonitoringInterface::name() const
954{ 955{
955 return "orinoco"; 956 return "orinoco";
956} 957}