author | mickeyl <mickeyl> | 2003-10-11 23:54:03 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-11 23:54:03 (UTC) |
commit | a8fe3ba1544ca2a2ad2559e3094acbb284cc7783 (patch) (unidiff) | |
tree | ef60fa83b396d16580f5ce7ab2b5c147fbceeabf /libopie2 | |
parent | e6273e146d3ef3f9387fbc3b6a214f9b3d08221e (diff) | |
download | opie-a8fe3ba1544ca2a2ad2559e3094acbb284cc7783.zip opie-a8fe3ba1544ca2a2ad2559e3094acbb284cc7783.tar.gz opie-a8fe3ba1544ca2a2ad2559e3094acbb284cc7783.tar.bz2 |
add scanning skeleton (wip)
-rw-r--r-- | libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp | 12 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 113 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 29 |
3 files changed, 131 insertions, 23 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp index 607d8f1..fc2026f 100644 --- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp +++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp | |||
@@ -58,2 +58,14 @@ int main( int argc, char** argv ) | |||
58 | 58 | ||
59 | // network scan | ||
60 | |||
61 | int stations = iface->scanNetwork(); | ||
62 | if ( stations != -1 ) | ||
63 | { | ||
64 | qDebug( "DEMO: # of stations around = %d", stations ); | ||
65 | } | ||
66 | else | ||
67 | { | ||
68 | qDebug( "DEMO: Warning! Scan didn't work!" ); | ||
69 | } | ||
70 | |||
59 | /* | 71 | /* |
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index dc2e388..be45924 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -78,2 +78,3 @@ void ONetwork::synchronize() | |||
78 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 78 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
79 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev | ||
79 | 80 | ||
@@ -190,5 +191,5 @@ bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | |||
190 | if ( result == -1 ) | 191 | if ( result == -1 ) |
191 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 192 | qDebug( "ONetworkInterface::ioctl (%s) call %d (0x%04X) - Status: Failed: %d (%s)", name(), call, call, result, strerror( errno ) ); |
192 | else | 193 | else |
193 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); | 194 | qDebug( "ONetworkInterface::ioctl (%s) call %d (0x%04X) - Status: Ok.", name(), call, call ); |
194 | return ( result != -1 ); | 195 | return ( result != -1 ); |
@@ -456,4 +457,12 @@ void OWirelessNetworkInterface::init() | |||
456 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 457 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
457 | buildChannelList(); | 458 | buildInformation(); |
458 | buildPrivateList(); | 459 | buildPrivateList(); |
460 | dumpInformation(); | ||
461 | } | ||
462 | |||
463 | |||
464 | bool OWirelessNetworkInterface::isAssociated() const | ||
465 | { | ||
466 | //FIXME: handle different modes | ||
467 | return associatedAP() != "44:44:44:44:44:44"; | ||
459 | } | 468 | } |
@@ -484,3 +493,3 @@ QString OWirelessNetworkInterface::associatedAP() const | |||
484 | 493 | ||
485 | void OWirelessNetworkInterface::buildChannelList() | 494 | void OWirelessNetworkInterface::buildInformation() |
486 | { | 495 | { |
@@ -507,3 +516,3 @@ void OWirelessNetworkInterface::buildChannelList() | |||
507 | { | 516 | { |
508 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); | 517 | qDebug( "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (%s) - using default values.", strerror( errno ) ); |
509 | _channels.insert( 2412, 1 ); // 2.412 GHz | 518 | _channels.insert( 2412, 1 ); // 2.412 GHz |
@@ -519,2 +528,4 @@ void OWirelessNetworkInterface::buildChannelList() | |||
519 | _channels.insert( 2462, 11 ); // 2.462 GHz | 528 | _channels.insert( 2462, 11 ); // 2.462 GHz |
529 | |||
530 | memset( &_range, 0, sizeof( struct iw_range ) ); | ||
520 | } | 531 | } |
@@ -529,4 +540,4 @@ void OWirelessNetworkInterface::buildChannelList() | |||
529 | { | 540 | { |
530 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" | 541 | qWarning( "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '%s' sucks!\n" |
531 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); | 542 | "It overwrote the buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); |
532 | } | 543 | } |
@@ -537,3 +548,3 @@ void OWirelessNetworkInterface::buildChannelList() | |||
537 | 548 | ||
538 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | 549 | qDebug( "OWirelessNetworkInterface::buildInformation(): Interface %s reported to have %d channels.", name(), range.num_frequency ); |
539 | for ( int i = 0; i < range.num_frequency; ++i ) | 550 | for ( int i = 0; i < range.num_frequency; ++i ) |
@@ -545,3 +556,4 @@ void OWirelessNetworkInterface::buildChannelList() | |||
545 | 556 | ||
546 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); | 557 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); |
558 | qDebug( "OWirelessNetworkInterface::buildInformation(): Information block constructed." ); | ||
547 | free(buffer); | 559 | free(buffer); |
@@ -574,2 +586,13 @@ void OWirelessNetworkInterface::buildPrivateList() | |||
574 | 586 | ||
587 | void OWirelessNetworkInterface::dumpInformation() const | ||
588 | { | ||
589 | qDebug( "OWirelessNetworkInterface::() -------------- dumping information block ----------------" ); | ||
590 | |||
591 | qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ); | ||
592 | qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source ); | ||
593 | |||
594 | qDebug( "OWirelessNetworkInterface::() ---------------------------------------------------------" ); | ||
595 | } | ||
596 | |||
597 | |||
575 | int OWirelessNetworkInterface::channel() const | 598 | int OWirelessNetworkInterface::channel() const |
@@ -663,5 +686,3 @@ void OWirelessNetworkInterface::setMode( const QString& mode ) | |||
663 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; | 686 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; |
664 | #if WIRELESS_EXT > 14 | ||
665 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; | 687 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; |
666 | #endif | ||
667 | else | 688 | else |
@@ -689,5 +710,3 @@ QString OWirelessNetworkInterface::mode() const | |||
689 | case IW_MODE_SECOND: return "secondary"; | 710 | case IW_MODE_SECOND: return "secondary"; |
690 | #if WIRELESS_EXT > 14 | ||
691 | case IW_MODE_MONITOR: return "monitor"; | 711 | case IW_MODE_MONITOR: return "monitor"; |
692 | #endif | ||
693 | default: assert( 0 ); // shouldn't happen | 712 | default: assert( 0 ); // shouldn't happen |
@@ -710,3 +729,4 @@ bool OWirelessNetworkInterface::monitorMode() const | |||
710 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); | 729 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); |
711 | // 802 is the header type for PRISM - Linux support for this is pending... | 730 | //FIXME: 802 is the header type for PRISM - Linux support for this is pending... |
731 | //FIXME: What is 119, by the way? | ||
712 | } | 732 | } |
@@ -802,2 +822,63 @@ void OWirelessNetworkInterface::setSSID( const QString& ssid ) | |||
802 | 822 | ||
823 | int OWirelessNetworkInterface::scanNetwork() | ||
824 | { | ||
825 | _iwr.u.param.flags = IW_SCAN_DEFAULT; | ||
826 | _iwr.u.param.value = 0; | ||
827 | if ( !wioctl( SIOCSIWSCAN ) ) | ||
828 | { | ||
829 | return -1; | ||
830 | } | ||
831 | |||
832 | int timeout = 1000000; | ||
833 | |||
834 | qDebug( "ONetworkInterface::scanNetwork() - scan started." ); | ||
835 | |||
836 | bool results = false; | ||
837 | struct timeval tv; | ||
838 | tv.tv_sec = 0; | ||
839 | tv.tv_usec = 250000; // initial timeout ~ 250ms | ||
840 | char buffer[IW_SCAN_MAX_DATA]; | ||
841 | |||
842 | while ( !results && timeout > 0 ) | ||
843 | { | ||
844 | timeout -= tv.tv_usec; | ||
845 | select( 0, 0, 0, 0, &tv ); | ||
846 | |||
847 | _iwr.u.data.pointer = &buffer[0]; | ||
848 | _iwr.u.data.flags = 0; | ||
849 | _iwr.u.data.length = sizeof buffer; | ||
850 | if ( wioctl( SIOCGIWSCAN ) ) | ||
851 | { | ||
852 | results = true; | ||
853 | continue; | ||
854 | } | ||
855 | else if ( errno == EAGAIN) | ||
856 | { | ||
857 | qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." ); | ||
858 | #if 0 | ||
859 | if ( qApp ) | ||
860 | { | ||
861 | qApp->processEvents( 100 ); | ||
862 | continue; | ||
863 | } | ||
864 | #endif | ||
865 | tv.tv_sec = 0; | ||
866 | tv.tv_usec = 100000; | ||
867 | continue; | ||
868 | } | ||
869 | } | ||
870 | |||
871 | qDebug( "ONetworkInterface::scanNetwork() - scan finished." ); | ||
872 | |||
873 | if ( results ) | ||
874 | { | ||
875 | qDebug( " - results are in!" ); | ||
876 | } | ||
877 | else | ||
878 | { | ||
879 | qDebug( " - no results :(" ); | ||
880 | } | ||
881 | } | ||
882 | |||
883 | |||
803 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 884 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
@@ -806,5 +887,5 @@ bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | |||
806 | if ( result == -1 ) | 887 | if ( result == -1 ) |
807 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 888 | qDebug( "ONetworkInterface::wioctl (%s) call %d (0x%04X) - Status: Failed: %d (%s)", name(), call, call, result, strerror( errno ) ); |
808 | else | 889 | else |
809 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); | 890 | qDebug( "ONetworkInterface::wioctl (%s) call %d (0x%04X) - Status: Ok.", name(), call, call ); |
810 | return ( result != -1 ); | 891 | return ( result != -1 ); |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index b170ea2..e1545dd 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -363,3 +363,3 @@ class OWirelessNetworkInterface : public ONetworkInterface | |||
363 | */ | 363 | */ |
364 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); | 364 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); Use IW_MONITOR first, if this doesn't work, then use iwpriv! |
365 | /** | 365 | /** |
@@ -399,8 +399,10 @@ class OWirelessNetworkInterface : public ONetworkInterface | |||
399 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this | 399 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this |
400 | |||
401 | virtual bool isAssociated() const {}; //FIXME: Implement and document this | ||
402 | /** | 400 | /** |
403 | * @returns the MAC address of the Access Point if the | 401 | * @returns true if the interface is associated to an access point |
404 | * device is in infrastructure mode. @returns a (more or less random) CELL | 402 | * @note: This information is only valid if the interface is in managed mode. |
405 | * address if the device is in adhoc mode. | 403 | */ |
404 | virtual bool isAssociated() const; | ||
405 | /** | ||
406 | * @returns the MAC address of the Access Point if the device is in infrastructure mode. | ||
407 | * @returns a (more or less random) cell ID address if the device is in adhoc mode. | ||
406 | */ | 408 | */ |
@@ -416,6 +418,12 @@ class OWirelessNetworkInterface : public ONetworkInterface | |||
416 | virtual QString SSID() const; | 418 | virtual QString SSID() const; |
419 | /** | ||
420 | * Perform scanning the wireless network neighbourhood. | ||
421 | * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! | ||
422 | */ | ||
423 | virtual int scanNetwork(); | ||
417 | 424 | ||
418 | protected: | 425 | protected: |
419 | void buildChannelList(); | 426 | void buildInformation(); |
420 | void buildPrivateList(); | 427 | void buildPrivateList(); |
428 | void dumpInformation() const; | ||
421 | virtual void init(); | 429 | virtual void init(); |
@@ -428,2 +436,3 @@ class OWirelessNetworkInterface : public ONetworkInterface | |||
428 | QMap<int,int> _channels; | 436 | QMap<int,int> _channels; |
437 | struct iw_range _range; | ||
429 | 438 | ||
@@ -477,2 +486,3 @@ class OCiscoMonitoringInterface : public OMonitoringInterface | |||
477 | 486 | ||
487 | |||
478 | /*====================================================================================== | 488 | /*====================================================================================== |
@@ -481,2 +491,3 @@ class OCiscoMonitoringInterface : public OMonitoringInterface | |||
481 | 491 | ||
492 | |||
482 | class OWlanNGMonitoringInterface : public OMonitoringInterface | 493 | class OWlanNGMonitoringInterface : public OMonitoringInterface |
@@ -494,2 +505,3 @@ class OWlanNGMonitoringInterface : public OMonitoringInterface | |||
494 | 505 | ||
506 | |||
495 | /*====================================================================================== | 507 | /*====================================================================================== |
@@ -498,2 +510,3 @@ class OWlanNGMonitoringInterface : public OMonitoringInterface | |||
498 | 510 | ||
511 | |||
499 | class OHostAPMonitoringInterface : public OMonitoringInterface | 512 | class OHostAPMonitoringInterface : public OMonitoringInterface |
@@ -509,2 +522,3 @@ class OHostAPMonitoringInterface : public OMonitoringInterface | |||
509 | 522 | ||
523 | |||
510 | /*====================================================================================== | 524 | /*====================================================================================== |
@@ -513,2 +527,3 @@ class OHostAPMonitoringInterface : public OMonitoringInterface | |||
513 | 527 | ||
528 | |||
514 | class OOrinocoMonitoringInterface : public OMonitoringInterface | 529 | class OOrinocoMonitoringInterface : public OMonitoringInterface |