author | mickeyl <mickeyl> | 2003-10-23 17:51:00 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-23 17:51:00 (UTC) |
commit | a9eddd4cd428dd844d8693e98e4df8e365e75da8 (patch) (unidiff) | |
tree | 21b5957143ad30b0efb505694505985ca65d3850 | |
parent | a61c014e1fb43e36aa7454ce4b3cb9a7a706c6fa (diff) | |
download | opie-a9eddd4cd428dd844d8693e98e4df8e365e75da8.zip opie-a9eddd4cd428dd844d8693e98e4df8e365e75da8.tar.gz opie-a9eddd4cd428dd844d8693e98e4df8e365e75da8.tar.bz2 |
misc changes
-rw-r--r-- | libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp | 16 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 30 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.h | 7 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 91 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 5 | ||||
-rw-r--r-- | libopie2/opienet/ostation.cpp | 15 | ||||
-rw-r--r-- | libopie2/opienet/ostation.h | 17 |
7 files changed, 115 insertions, 66 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp index fc2026f..21026e1 100644 --- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp +++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <opie2/onetwork.h> | 1 | #include <opie2/onetwork.h> |
2 | #include <opie2/ostation.h> | ||
2 | #include <opie2/omanufacturerdb.h> | 3 | #include <opie2/omanufacturerdb.h> |
3 | 4 | ||
@@ -28,5 +29,5 @@ int main( int argc, char** argv ) | |||
28 | //if ( iface->mode() == OWirelessNetworkInterface::adhoc ) | 29 | //if ( iface->mode() == OWirelessNetworkInterface::adhoc ) |
29 | //{ | 30 | //{ |
30 | qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() ); | 31 | qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP().toString() ); |
31 | //} | 32 | //} |
32 | 33 | ||
@@ -59,9 +60,16 @@ int main( int argc, char** argv ) | |||
59 | // network scan | 60 | // network scan |
60 | 61 | ||
61 | int stations = iface->scanNetwork(); | 62 | OStationList* stations = iface->scanNetwork(); |
62 | if ( stations != -1 ) | 63 | if ( stations ) |
63 | { | 64 | { |
64 | qDebug( "DEMO: # of stations around = %d", stations ); | 65 | qDebug( "DEMO: # of stations around = %d", stations->count() ); |
66 | OStation* station; | ||
67 | for ( station = stations->first(); station != 0; station = stations->next() ) | ||
68 | { | ||
69 | qDebug( "DEMO: station dump following..." ); | ||
70 | station->dump(); | ||
71 | } | ||
65 | } | 72 | } |
73 | |||
66 | else | 74 | else |
67 | { | 75 | { |
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index ad0e89d..ce147c5 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp | |||
@@ -35,5 +35,5 @@ | |||
35 | 35 | ||
36 | #include <net/if.h> | 36 | #include <net/if.h> |
37 | 37 | #include <cassert> | |
38 | #include <cstdio> | 38 | #include <cstdio> |
39 | using namespace std; | 39 | using namespace std; |
@@ -214,2 +214,30 @@ void dumpBytes( const unsigned char* data, int num ) | |||
214 | } | 214 | } |
215 | 215 | ||
216 | |||
217 | int stringToMode( const QString& mode ) | ||
218 | { | ||
219 | if ( mode == "auto" ) return IW_MODE_AUTO; | ||
220 | else if ( mode == "adhoc" ) return IW_MODE_ADHOC; | ||
221 | else if ( mode == "managed" ) return IW_MODE_INFRA; | ||
222 | else if ( mode == "master" ) return IW_MODE_MASTER; | ||
223 | else if ( mode == "repeater" ) return IW_MODE_REPEAT; | ||
224 | else if ( mode == "secondary" ) return IW_MODE_SECOND; | ||
225 | else if ( mode == "monitor" ) return IW_MODE_MONITOR; | ||
226 | else assert( 0 ); | ||
227 | } | ||
228 | |||
229 | |||
230 | QString modeToString( int mode ) | ||
231 | { | ||
232 | switch ( mode ) | ||
233 | { | ||
234 | case IW_MODE_AUTO: return "auto"; | ||
235 | case IW_MODE_ADHOC: return "adhoc"; | ||
236 | case IW_MODE_INFRA: return "managed"; | ||
237 | case IW_MODE_MASTER: return "master"; | ||
238 | case IW_MODE_REPEAT: return "repeater"; | ||
239 | case IW_MODE_SECOND: return "second"; | ||
240 | case IW_MODE_MONITOR: return "monitor"; | ||
241 | default: assert( 0 ); | ||
242 | } | ||
243 | } | ||
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h index 18731ba..541c5ab 100644 --- a/libopie2/opienet/onetutils.h +++ b/libopie2/opienet/onetutils.h | |||
@@ -85,7 +85,8 @@ bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); | |||
85 | class OHostAddress : public QHostAddress | 85 | class OHostAddress : public QHostAddress |
86 | { | 86 | { |
87 | public: | 87 | /*public: |
88 | OHostAddress(); | 88 | OHostAddress(); |
89 | ~OHostAddress(); | 89 | ~OHostAddress(); |
90 | */ | ||
90 | }; | 91 | }; |
91 | 92 | ||
@@ -121,7 +122,7 @@ class OPrivateIOCTL : public QObject | |||
121 | *======================================================================================*/ | 122 | *======================================================================================*/ |
122 | 123 | ||
123 | /* dump bytes */ | ||
124 | |||
125 | void dumpBytes( const unsigned char* data, int num ); | 124 | void dumpBytes( const unsigned char* data, int num ); |
125 | QString modeToString( int ); | ||
126 | int stringToMode( const QString& ); | ||
126 | 127 | ||
127 | /* Network to host order macros */ | 128 | /* Network to host order macros */ |
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index a85a510..50c6679 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -257,4 +257,5 @@ QString ONetworkInterface::ipV4Address() const | |||
257 | else | 257 | else |
258 | return "<unknown>"; | 258 | return "<unknown>"; |
259 | |||
259 | } | 260 | } |
260 | 261 | ||
@@ -475,28 +476,14 @@ bool OWirelessNetworkInterface::isAssociated() const | |||
475 | { | 476 | { |
476 | //FIXME: handle different modes | 477 | //FIXME: handle different modes |
477 | return associatedAP() != "44:44:44:44:44:44"; | 478 | return !(associatedAP() == OMacAddress::unknown); |
478 | } | 479 | } |
479 | 480 | ||
480 | 481 | ||
481 | QString OWirelessNetworkInterface::associatedAP() const | 482 | OMacAddress OWirelessNetworkInterface::associatedAP() const |
482 | { | 483 | { |
483 | //FIXME: use OMacAddress | ||
484 | QString mac; | ||
485 | |||
486 | if ( ioctl( SIOCGIWAP ) ) | 484 | if ( ioctl( SIOCGIWAP ) ) |
487 | { | 485 | return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; |
488 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | ||
489 | _ifr.ifr_hwaddr.sa_data[0]&0xff, | ||
490 | _ifr.ifr_hwaddr.sa_data[1]&0xff, | ||
491 | _ifr.ifr_hwaddr.sa_data[2]&0xff, | ||
492 | _ifr.ifr_hwaddr.sa_data[3]&0xff, | ||
493 | _ifr.ifr_hwaddr.sa_data[4]&0xff, | ||
494 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); | ||
495 | } | ||
496 | else | 486 | else |
497 | { | 487 | return OMacAddress::unknown; |
498 | mac = "<Unknown>"; | ||
499 | } | ||
500 | return mac; | ||
501 | } | 488 | } |
502 | 489 | ||
@@ -689,16 +676,5 @@ OChannelHopper* OWirelessNetworkInterface::channelHopper() const | |||
689 | void OWirelessNetworkInterface::setMode( const QString& mode ) | 676 | void OWirelessNetworkInterface::setMode( const QString& mode ) |
690 | { | 677 | { |
691 | if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; | 678 | _iwr.u.mode = stringToMode( mode ); |
692 | else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; | ||
693 | else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; | ||
694 | else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; | ||
695 | else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; | ||
696 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; | ||
697 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; | ||
698 | else | ||
699 | { | ||
700 | qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); | ||
701 | return; | ||
702 | } | ||
703 | wioctl( SIOCSIWMODE ); | 679 | wioctl( SIOCSIWMODE ); |
704 | } | 680 | } |
@@ -711,15 +687,5 @@ QString OWirelessNetworkInterface::mode() const | |||
711 | return "<unknown>"; | 687 | return "<unknown>"; |
712 | } | 688 | } |
713 | switch ( _iwr.u.mode ) | 689 | return modeToString( _iwr.u.mode ); |
714 | { | ||
715 | case IW_MODE_AUTO: return "auto"; | ||
716 | case IW_MODE_ADHOC: return "adhoc"; | ||
717 | case IW_MODE_INFRA: return "managed"; | ||
718 | case IW_MODE_MASTER: return "master"; | ||
719 | case IW_MODE_REPEAT: return "repeater"; | ||
720 | case IW_MODE_SECOND: return "secondary"; | ||
721 | case IW_MODE_MONITOR: return "monitor"; | ||
722 | default: assert( 0 ); // shouldn't happen | ||
723 | } | ||
724 | } | 690 | } |
725 | 691 | ||
@@ -831,5 +797,5 @@ void OWirelessNetworkInterface::setSSID( const QString& ssid ) | |||
831 | 797 | ||
832 | 798 | ||
833 | int OWirelessNetworkInterface::scanNetwork() | 799 | OStationList* OWirelessNetworkInterface::scanNetwork() |
834 | { | 800 | { |
835 | _iwr.u.param.flags = IW_SCAN_DEFAULT; | 801 | _iwr.u.param.flags = IW_SCAN_DEFAULT; |
@@ -837,7 +803,9 @@ int OWirelessNetworkInterface::scanNetwork() | |||
837 | if ( !wioctl( SIOCSIWSCAN ) ) | 803 | if ( !wioctl( SIOCSIWSCAN ) ) |
838 | { | 804 | { |
839 | return -1; | 805 | return 0; |
840 | } | 806 | } |
841 | 807 | ||
808 | OStationList* stations = new OStationList(); | ||
809 | |||
842 | int timeout = 1000000; | 810 | int timeout = 1000000; |
843 | 811 | ||
@@ -887,5 +855,5 @@ int OWirelessNetworkInterface::scanNetwork() | |||
887 | { | 855 | { |
888 | qDebug( " - no results (empty neighbourhood)" ); | 856 | qDebug( " - no results (empty neighbourhood)" ); |
889 | return 0; | 857 | return stations; |
890 | } | 858 | } |
891 | 859 | ||
@@ -893,6 +861,4 @@ int OWirelessNetworkInterface::scanNetwork() | |||
893 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); | 861 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); |
894 | 862 | ||
895 | int stations = 0; | ||
896 | |||
897 | // parse results | 863 | // parse results |
898 | 864 | ||
@@ -907,8 +873,29 @@ int OWirelessNetworkInterface::scanNetwork() | |||
907 | switch (we->cmd) | 873 | switch (we->cmd) |
908 | { | 874 | { |
909 | case SIOCGIWAP: qDebug( "SIOCGIWAP" ); stations++; break; | 875 | case SIOCGIWAP: |
910 | case SIOCGIWMODE: qDebug( "SIOCGIWMODE" ); break; | 876 | { |
911 | case SIOCGIWFREQ: qDebug( "SIOCGIWFREQ" ); break; | 877 | qDebug( "SIOCGIWAP" ); |
912 | case SIOCGIWESSID: qDebug( "SIOCGIWESSID" ); break; | 878 | stations->append( new OStation() ); |
879 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; | ||
880 | break; | ||
881 | } | ||
882 | case SIOCGIWMODE: | ||
883 | { | ||
884 | qDebug( "SIOCGIWMODE" ); | ||
885 | stations->last()->type = modeToString( we->u.mode ); | ||
886 | break; | ||
887 | } | ||
888 | case SIOCGIWFREQ: | ||
889 | { | ||
890 | qDebug( "SIOCGIWFREQ" ); | ||
891 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; | ||
892 | break; | ||
893 | } | ||
894 | case SIOCGIWESSID: | ||
895 | { | ||
896 | qDebug( "SIOCGIWESSID" ); | ||
897 | stations->last()->ssid = we->u.essid.pointer; | ||
898 | break; | ||
899 | } | ||
913 | case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break; | 900 | case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break; |
914 | case SIOCGIWENCODE: qDebug( "SIOCGIWENCODE" ); break; | 901 | case SIOCGIWENCODE: qDebug( "SIOCGIWENCODE" ); break; |
@@ -925,9 +912,11 @@ int OWirelessNetworkInterface::scanNetwork() | |||
925 | } | 912 | } |
926 | 913 | ||
914 | return stations; | ||
915 | |||
927 | } | 916 | } |
928 | else | 917 | else |
929 | { | 918 | { |
930 | qDebug( " - no results (timeout) :(" ); | 919 | qDebug( " - no results (timeout) :(" ); |
931 | return 0; | 920 | return stations; |
932 | } | 921 | } |
933 | } | 922 | } |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index e1545dd..0eb4542 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -40,4 +40,5 @@ | |||
40 | 40 | ||
41 | #include <opie2/onetutils.h> | 41 | #include <opie2/onetutils.h> |
42 | #include <opie2/ostation.h> | ||
42 | 43 | ||
43 | /* QT */ | 44 | /* QT */ |
@@ -407,5 +408,5 @@ class OWirelessNetworkInterface : public ONetworkInterface | |||
407 | * @returns a (more or less random) cell ID address if the device is in adhoc mode. | 408 | * @returns a (more or less random) cell ID address if the device is in adhoc mode. |
408 | */ | 409 | */ |
409 | virtual QString associatedAP() const; | 410 | virtual OMacAddress associatedAP() const; |
410 | /** | 411 | /** |
411 | * Set the @a ssid (Service Set ID) string. This is used to decide | 412 | * Set the @a ssid (Service Set ID) string. This is used to decide |
@@ -421,5 +422,5 @@ class OWirelessNetworkInterface : public ONetworkInterface | |||
421 | * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! | 422 | * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! |
422 | */ | 423 | */ |
423 | virtual int scanNetwork(); | 424 | virtual OStationList* scanNetwork(); |
424 | 425 | ||
425 | protected: | 426 | protected: |
diff --git a/libopie2/opienet/ostation.cpp b/libopie2/opienet/ostation.cpp index 3817b31..ba1e4f6 100644 --- a/libopie2/opienet/ostation.cpp +++ b/libopie2/opienet/ostation.cpp | |||
@@ -39,4 +39,11 @@ OStation::OStation() | |||
39 | { | 39 | { |
40 | qDebug( "OStation::OStation()" ); | 40 | qDebug( "OStation::OStation()" ); |
41 | |||
42 | type = "<unknown>"; | ||
43 | macAddress = OMacAddress::unknown; | ||
44 | ssid = "<unknown>"; | ||
45 | channel = 0; | ||
46 | apAddress = OMacAddress::unknown; | ||
47 | |||
41 | } | 48 | } |
42 | 49 | ||
@@ -48,2 +55,10 @@ OStation::~OStation() | |||
48 | 55 | ||
49 | 56 | ||
57 | void OStation::dump() | ||
58 | { | ||
59 | qDebug( "------- OStation::dump() ------------" ); | ||
60 | qDebug( "type: %s", (const char*) type ); | ||
61 | qDebug( "mac: %s", (const char*) macAddress.toString() ); | ||
62 | qDebug( "ap: %s", (const char*) apAddress.toString() ); | ||
63 | qDebug( "ip: %s", (const char*) ipAddress.toString() ); | ||
64 | } | ||
diff --git a/libopie2/opienet/ostation.h b/libopie2/opienet/ostation.h index f61570b..a6956c9 100644 --- a/libopie2/opienet/ostation.h +++ b/libopie2/opienet/ostation.h | |||
@@ -35,6 +35,5 @@ | |||
35 | #include <opie2/onetutils.h> | 35 | #include <opie2/onetutils.h> |
36 | 36 | ||
37 | #include <qdict.h> | 37 | #include <qlist.h> |
38 | #include <qmap.h> | ||
39 | #include <qstring.h> | 38 | #include <qstring.h> |
40 | #include <qhostaddress.h> | 39 | #include <qhostaddress.h> |
@@ -45,5 +44,5 @@ | |||
45 | class OStation; | 44 | class OStation; |
46 | 45 | ||
47 | typedef QDict<OStation> OStationDict; | 46 | typedef QList<OStation> OStationList; |
48 | 47 | ||
49 | /*====================================================================================== | 48 | /*====================================================================================== |
@@ -57,11 +56,19 @@ class OStation | |||
57 | ~OStation(); | 56 | ~OStation(); |
58 | 57 | ||
59 | private: | 58 | void dump(); |
59 | |||
60 | /* Ethernet */ | ||
61 | QString type; | ||
60 | OMacAddress macAddress; | 62 | OMacAddress macAddress; |
61 | QHostAddress ipAddress; | 63 | QHostAddress ipAddress; |
64 | |||
65 | /* WaveLan */ | ||
62 | QString ssid; | 66 | QString ssid; |
63 | QString type; | 67 | OMacAddress apAddress; |
68 | int channel; | ||
69 | bool encrypted; | ||
64 | }; | 70 | }; |
65 | 71 | ||
72 | |||
66 | #endif // OSTATION_H | 73 | #endif // OSTATION_H |
67 | 74 | ||