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 /libopie2 | |
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,99 +1,107 @@ | |||
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 | ||
4 | int main( int argc, char** argv ) | 5 | int main( int argc, char** argv ) |
5 | { | 6 | { |
6 | qDebug( "OPIE Network Demo" ); | 7 | qDebug( "OPIE Network Demo" ); |
7 | 8 | ||
8 | ONetwork* net = ONetwork::instance(); | 9 | ONetwork* net = ONetwork::instance(); |
9 | 10 | ||
10 | ONetwork::InterfaceIterator it = net->iterator(); | 11 | ONetwork::InterfaceIterator it = net->iterator(); |
11 | 12 | ||
12 | while ( it.current() ) | 13 | while ( it.current() ) |
13 | { | 14 | { |
14 | qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() ); | 15 | qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() ); |
15 | qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() ); | 16 | qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() ); |
16 | qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) ); | 17 | qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) ); |
17 | qDebug( "DEMO: MAC Manufacturer seems to be '%s'", (const char*) it.current()->macAddress().manufacturer() ); | 18 | qDebug( "DEMO: MAC Manufacturer seems to be '%s'", (const char*) it.current()->macAddress().manufacturer() ); |
18 | qDebug( "DEMO: Manufacturertest1 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "08:00:87" ) ); | 19 | qDebug( "DEMO: Manufacturertest1 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "08:00:87" ) ); |
19 | qDebug( "DEMO: Manufacturertest2 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) ); | 20 | qDebug( "DEMO: Manufacturertest2 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) ); |
20 | qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() ); | 21 | qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() ); |
21 | if ( it.current()->isWireless() ) | 22 | if ( it.current()->isWireless() ) |
22 | { | 23 | { |
23 | OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() ); | 24 | OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() ); |
24 | qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() ); | 25 | qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() ); |
25 | qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() ); | 26 | qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() ); |
26 | qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() ); | 27 | qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() ); |
27 | 28 | ||
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 | ||
33 | // nickname | 34 | // nickname |
34 | qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() ); | 35 | qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() ); |
35 | iface->setNickName( "MyNickName" ); | 36 | iface->setNickName( "MyNickName" ); |
36 | if ( iface->nickName() != "MyNickName" ) | 37 | if ( iface->nickName() != "MyNickName" ) |
37 | qDebug( "DEMO: Warning! Can't change nickname" ); | 38 | qDebug( "DEMO: Warning! Can't change nickname" ); |
38 | else | 39 | else |
39 | qDebug( "DEMO: Nickname change successful." ); | 40 | qDebug( "DEMO: Nickname change successful." ); |
40 | 41 | ||
41 | // operation mode | 42 | // operation mode |
42 | qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() ); | 43 | qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() ); |
43 | iface->setMode( "adhoc" ); | 44 | iface->setMode( "adhoc" ); |
44 | if ( iface->mode() != "adhoc" ) | 45 | if ( iface->mode() != "adhoc" ) |
45 | qDebug( "DEMO: Warning! Can't change operation mode" ); | 46 | qDebug( "DEMO: Warning! Can't change operation mode" ); |
46 | else | 47 | else |
47 | qDebug( "DEMO: Operation Mode change successful." ); | 48 | qDebug( "DEMO: Operation Mode change successful." ); |
48 | 49 | ||
49 | // RF channel | 50 | // RF channel |
50 | qDebug( "DEMO: Current Channel is '%d'", iface->channel() ); | 51 | qDebug( "DEMO: Current Channel is '%d'", iface->channel() ); |
51 | iface->setChannel( 1 ); | 52 | iface->setChannel( 1 ); |
52 | if ( iface->channel() != 1 ) | 53 | if ( iface->channel() != 1 ) |
53 | qDebug( "DEMO: Warning! Can't change RF channel" ); | 54 | qDebug( "DEMO: Warning! Can't change RF channel" ); |
54 | else | 55 | else |
55 | qDebug( "DEMO: RF channel change successful." ); | 56 | qDebug( "DEMO: RF channel change successful." ); |
56 | 57 | ||
57 | iface->setMode( "managed" ); | 58 | iface->setMode( "managed" ); |
58 | 59 | ||
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 | { |
68 | qDebug( "DEMO: Warning! Scan didn't work!" ); | 76 | qDebug( "DEMO: Warning! Scan didn't work!" ); |
69 | } | 77 | } |
70 | 78 | ||
71 | /* | 79 | /* |
72 | 80 | ||
73 | // first some wrong calls to check if this is working | 81 | // first some wrong calls to check if this is working |
74 | iface->setPrivate( "seppel", 10 ); | 82 | iface->setPrivate( "seppel", 10 ); |
75 | iface->setPrivate( "monitor", 0 ); | 83 | iface->setPrivate( "monitor", 0 ); |
76 | 84 | ||
77 | // now the real deal | 85 | // now the real deal |
78 | iface->setPrivate( "monitor", 2, 2, 3 ); | 86 | iface->setPrivate( "monitor", 2, 2, 3 ); |
79 | 87 | ||
80 | // trying to set hw address to 12:34:56:AB:CD:EF | 88 | // trying to set hw address to 12:34:56:AB:CD:EF |
81 | 89 | ||
82 | /* | 90 | /* |
83 | 91 | ||
84 | OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" ); | 92 | OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" ); |
85 | iface->setUp( false ); | 93 | iface->setUp( false ); |
86 | iface->setMacAddress( addr ); | 94 | iface->setMacAddress( addr ); |
87 | iface->setUp( true ); | 95 | iface->setUp( true ); |
88 | qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() ); | 96 | qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() ); |
89 | 97 | ||
90 | */ | 98 | */ |
91 | 99 | ||
92 | 100 | ||
93 | } | 101 | } |
94 | ++it; | 102 | ++it; |
95 | } | 103 | } |
96 | 104 | ||
97 | return 0; | 105 | return 0; |
98 | 106 | ||
99 | } | 107 | } |
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 | |||
@@ -1,215 +1,243 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <opie2/onetutils.h> | 32 | #include <opie2/onetutils.h> |
33 | #include <opie2/onetwork.h> | 33 | #include <opie2/onetwork.h> |
34 | #include <opie2/omanufacturerdb.h> | 34 | #include <opie2/omanufacturerdb.h> |
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; |
40 | 40 | ||
41 | #define IW_PRIV_TYPE_MASK 0x7000 | 41 | #define IW_PRIV_TYPE_MASK 0x7000 |
42 | #define IW_PRIV_TYPE_NONE 0x0000 | 42 | #define IW_PRIV_TYPE_NONE 0x0000 |
43 | #define IW_PRIV_TYPE_BYTE 0x1000 | 43 | #define IW_PRIV_TYPE_BYTE 0x1000 |
44 | #define IW_PRIV_TYPE_CHAR 0x2000 | 44 | #define IW_PRIV_TYPE_CHAR 0x2000 |
45 | #define IW_PRIV_TYPE_INT 0x4000 | 45 | #define IW_PRIV_TYPE_INT 0x4000 |
46 | #define IW_PRIV_TYPE_FLOAT 0x5000 | 46 | #define IW_PRIV_TYPE_FLOAT 0x5000 |
47 | #define IW_PRIV_TYPE_ADDR 0x6000 | 47 | #define IW_PRIV_TYPE_ADDR 0x6000 |
48 | #define IW_PRIV_SIZE_FIXED 0x0800 | 48 | #define IW_PRIV_SIZE_FIXED 0x0800 |
49 | #define IW_PRIV_SIZE_MASK 0x07FF | 49 | #define IW_PRIV_SIZE_MASK 0x07FF |
50 | 50 | ||
51 | /*====================================================================================== | 51 | /*====================================================================================== |
52 | * OMacAddress | 52 | * OMacAddress |
53 | *======================================================================================*/ | 53 | *======================================================================================*/ |
54 | 54 | ||
55 | // static initializer for broadcast and unknown MAC Adresses | 55 | // static initializer for broadcast and unknown MAC Adresses |
56 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | 56 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
57 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); | 57 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); |
58 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; | 58 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; |
59 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); | 59 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); |
60 | 60 | ||
61 | //TODO: Incorporate Ethernet Manufacturer database here! (inline or so) | 61 | //TODO: Incorporate Ethernet Manufacturer database here! (inline or so) |
62 | 62 | ||
63 | OMacAddress::OMacAddress() | 63 | OMacAddress::OMacAddress() |
64 | { | 64 | { |
65 | memcpy( _bytes, __unknown, 6 ); | 65 | memcpy( _bytes, __unknown, 6 ); |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | OMacAddress::OMacAddress( unsigned char* p ) | 69 | OMacAddress::OMacAddress( unsigned char* p ) |
70 | { | 70 | { |
71 | memcpy( _bytes, p, 6 ); | 71 | memcpy( _bytes, p, 6 ); |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
75 | OMacAddress::OMacAddress( const unsigned char* p ) | 75 | OMacAddress::OMacAddress( const unsigned char* p ) |
76 | { | 76 | { |
77 | memcpy( _bytes, p, 6 ); | 77 | memcpy( _bytes, p, 6 ); |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
81 | OMacAddress::OMacAddress( struct ifreq& ifr ) | 81 | OMacAddress::OMacAddress( struct ifreq& ifr ) |
82 | { | 82 | { |
83 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); | 83 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
87 | OMacAddress::~OMacAddress() | 87 | OMacAddress::~OMacAddress() |
88 | { | 88 | { |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | //#ifdef QT_NO_DEBUG | 92 | //#ifdef QT_NO_DEBUG |
93 | //inline | 93 | //inline |
94 | //#endif | 94 | //#endif |
95 | const unsigned char* OMacAddress::native() const | 95 | const unsigned char* OMacAddress::native() const |
96 | { | 96 | { |
97 | return (const unsigned char*) &_bytes; | 97 | return (const unsigned char*) &_bytes; |
98 | } | 98 | } |
99 | 99 | ||
100 | 100 | ||
101 | OMacAddress OMacAddress::fromString( const QString& str ) | 101 | OMacAddress OMacAddress::fromString( const QString& str ) |
102 | { | 102 | { |
103 | QString addr( str ); | 103 | QString addr( str ); |
104 | unsigned char buf[6]; | 104 | unsigned char buf[6]; |
105 | bool ok = true; | 105 | bool ok = true; |
106 | int index = 14; | 106 | int index = 14; |
107 | for ( int i = 5; i >= 0; --i ) | 107 | for ( int i = 5; i >= 0; --i ) |
108 | { | 108 | { |
109 | buf[i] = addr.right( 2 ).toUShort( &ok, 16 ); | 109 | buf[i] = addr.right( 2 ).toUShort( &ok, 16 ); |
110 | if ( !ok ) return OMacAddress::unknown; | 110 | if ( !ok ) return OMacAddress::unknown; |
111 | addr.truncate( index ); | 111 | addr.truncate( index ); |
112 | index -= 3; | 112 | index -= 3; |
113 | } | 113 | } |
114 | return (const unsigned char*) &buf; | 114 | return (const unsigned char*) &buf; |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | QString OMacAddress::toString( bool substitute ) const | 118 | QString OMacAddress::toString( bool substitute ) const |
119 | { | 119 | { |
120 | QString manu; | 120 | QString manu; |
121 | manu.sprintf( "%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff ); | 121 | manu.sprintf( "%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff ); |
122 | QString serial; | 122 | QString serial; |
123 | serial.sprintf( ":%.2X:%.2X:%.2X", _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); | 123 | serial.sprintf( ":%.2X:%.2X:%.2X", _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); |
124 | if ( !substitute ) return manu+serial; | 124 | if ( !substitute ) return manu+serial; |
125 | // fallback - if no vendor is found, just use the number | 125 | // fallback - if no vendor is found, just use the number |
126 | QString textmanu = OManufacturerDB::instance()->lookup( manu ); | 126 | QString textmanu = OManufacturerDB::instance()->lookup( manu ); |
127 | return textmanu.isNull() ? manu+serial : textmanu+serial; | 127 | return textmanu.isNull() ? manu+serial : textmanu+serial; |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | QString OMacAddress::manufacturer() const | 131 | QString OMacAddress::manufacturer() const |
132 | { | 132 | { |
133 | return OManufacturerDB::instance()->lookupExt( toString() ); | 133 | return OManufacturerDB::instance()->lookupExt( toString() ); |
134 | } | 134 | } |
135 | 135 | ||
136 | 136 | ||
137 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) | 137 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) |
138 | { | 138 | { |
139 | return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; | 139 | return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; |
140 | } | 140 | } |
141 | 141 | ||
142 | 142 | ||
143 | /*====================================================================================== | 143 | /*====================================================================================== |
144 | * OHostAddress | 144 | * OHostAddress |
145 | *======================================================================================*/ | 145 | *======================================================================================*/ |
146 | 146 | ||
147 | 147 | ||
148 | /*====================================================================================== | 148 | /*====================================================================================== |
149 | * OPrivateIOCTL | 149 | * OPrivateIOCTL |
150 | *======================================================================================*/ | 150 | *======================================================================================*/ |
151 | 151 | ||
152 | OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) | 152 | OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) |
153 | :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) | 153 | :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) |
154 | { | 154 | { |
155 | } | 155 | } |
156 | 156 | ||
157 | 157 | ||
158 | OPrivateIOCTL::~OPrivateIOCTL() | 158 | OPrivateIOCTL::~OPrivateIOCTL() |
159 | { | 159 | { |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | int OPrivateIOCTL::numberGetArgs() const | 163 | int OPrivateIOCTL::numberGetArgs() const |
164 | { | 164 | { |
165 | return _getargs & IW_PRIV_SIZE_MASK; | 165 | return _getargs & IW_PRIV_SIZE_MASK; |
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
169 | int OPrivateIOCTL::typeGetArgs() const | 169 | int OPrivateIOCTL::typeGetArgs() const |
170 | { | 170 | { |
171 | return _getargs & IW_PRIV_TYPE_MASK >> 12; | 171 | return _getargs & IW_PRIV_TYPE_MASK >> 12; |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | int OPrivateIOCTL::numberSetArgs() const | 175 | int OPrivateIOCTL::numberSetArgs() const |
176 | { | 176 | { |
177 | return _setargs & IW_PRIV_SIZE_MASK; | 177 | return _setargs & IW_PRIV_SIZE_MASK; |
178 | } | 178 | } |
179 | 179 | ||
180 | 180 | ||
181 | int OPrivateIOCTL::typeSetArgs() const | 181 | int OPrivateIOCTL::typeSetArgs() const |
182 | { | 182 | { |
183 | return _setargs & IW_PRIV_TYPE_MASK >> 12; | 183 | return _setargs & IW_PRIV_TYPE_MASK >> 12; |
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | void OPrivateIOCTL::invoke() const | 187 | void OPrivateIOCTL::invoke() const |
188 | { | 188 | { |
189 | ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl ); | 189 | ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl ); |
190 | } | 190 | } |
191 | 191 | ||
192 | 192 | ||
193 | void OPrivateIOCTL::setParameter( int num, u_int32_t value ) | 193 | void OPrivateIOCTL::setParameter( int num, u_int32_t value ) |
194 | { | 194 | { |
195 | u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; | 195 | u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; |
196 | arglist[num] = value; | 196 | arglist[num] = value; |
197 | } | 197 | } |
198 | 198 | ||
199 | /*====================================================================================== | 199 | /*====================================================================================== |
200 | * assorted functions | 200 | * assorted functions |
201 | *======================================================================================*/ | 201 | *======================================================================================*/ |
202 | 202 | ||
203 | void dumpBytes( const unsigned char* data, int num ) | 203 | void dumpBytes( const unsigned char* data, int num ) |
204 | { | 204 | { |
205 | printf( "Dumping %d bytes @ %0x", num, data ); | 205 | printf( "Dumping %d bytes @ %0x", num, data ); |
206 | printf( "-------------------------------------------\n" ); | 206 | printf( "-------------------------------------------\n" ); |
207 | 207 | ||
208 | for ( int i = 0; i < num; ++i ) | 208 | for ( int i = 0; i < num; ++i ) |
209 | { | 209 | { |
210 | printf( "%02x ", data[i] ); | 210 | printf( "%02x ", data[i] ); |
211 | if ( !((i+1) % 32) ) printf( "\n" ); | 211 | if ( !((i+1) % 32) ) printf( "\n" ); |
212 | } | 212 | } |
213 | printf( "\n\n" ); | 213 | printf( "\n\n" ); |
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 | |||
@@ -1,162 +1,163 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #ifndef ONETUTILS_H | 32 | #ifndef ONETUTILS_H |
33 | #define ONETUTILS_H | 33 | #define ONETUTILS_H |
34 | 34 | ||
35 | #include <qdict.h> | 35 | #include <qdict.h> |
36 | #include <qmap.h> | 36 | #include <qmap.h> |
37 | #include <qstring.h> | 37 | #include <qstring.h> |
38 | #include <qhostaddress.h> | 38 | #include <qhostaddress.h> |
39 | #include <qobject.h> | 39 | #include <qobject.h> |
40 | 40 | ||
41 | #include <sys/types.h> | 41 | #include <sys/types.h> |
42 | 42 | ||
43 | struct ifreq; | 43 | struct ifreq; |
44 | class OWirelessNetworkInterface; | 44 | class OWirelessNetworkInterface; |
45 | 45 | ||
46 | /*====================================================================================== | 46 | /*====================================================================================== |
47 | * OMacAddress | 47 | * OMacAddress |
48 | *======================================================================================*/ | 48 | *======================================================================================*/ |
49 | 49 | ||
50 | class OMacAddress | 50 | class OMacAddress |
51 | { | 51 | { |
52 | public: | 52 | public: |
53 | // QString c'tor? -zecke | 53 | // QString c'tor? -zecke |
54 | OMacAddress(); | 54 | OMacAddress(); |
55 | OMacAddress( unsigned char* ); | 55 | OMacAddress( unsigned char* ); |
56 | OMacAddress( const unsigned char* ); | 56 | OMacAddress( const unsigned char* ); |
57 | OMacAddress( struct ifreq& ); | 57 | OMacAddress( struct ifreq& ); |
58 | ~OMacAddress(); | 58 | ~OMacAddress(); |
59 | 59 | ||
60 | QString manufacturer() const; | 60 | QString manufacturer() const; |
61 | QString toString( bool substitute = false ) const; | 61 | QString toString( bool substitute = false ) const; |
62 | const unsigned char* native() const; | 62 | const unsigned char* native() const; |
63 | 63 | ||
64 | // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem? | 64 | // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem? |
65 | static OMacAddress fromString( const QString& ); | 65 | static OMacAddress fromString( const QString& ); |
66 | 66 | ||
67 | public: | 67 | public: |
68 | static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff | 68 | static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff |
69 | static const OMacAddress& unknown; // 44:44:44:44:44:44 | 69 | static const OMacAddress& unknown; // 44:44:44:44:44:44 |
70 | 70 | ||
71 | private: | 71 | private: |
72 | unsigned char _bytes[6]; | 72 | unsigned char _bytes[6]; |
73 | 73 | ||
74 | friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); | 74 | friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); |
75 | 75 | ||
76 | }; | 76 | }; |
77 | 77 | ||
78 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); | 78 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); |
79 | 79 | ||
80 | 80 | ||
81 | /*====================================================================================== | 81 | /*====================================================================================== |
82 | * OHostAddress | 82 | * OHostAddress |
83 | *======================================================================================*/ | 83 | *======================================================================================*/ |
84 | 84 | ||
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 | ||
92 | 93 | ||
93 | /*====================================================================================== | 94 | /*====================================================================================== |
94 | * OPrivateIOCTL | 95 | * OPrivateIOCTL |
95 | *======================================================================================*/ | 96 | *======================================================================================*/ |
96 | 97 | ||
97 | class OPrivateIOCTL : public QObject | 98 | class OPrivateIOCTL : public QObject |
98 | { | 99 | { |
99 | public: | 100 | public: |
100 | OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ); | 101 | OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ); |
101 | ~OPrivateIOCTL(); | 102 | ~OPrivateIOCTL(); |
102 | 103 | ||
103 | int numberGetArgs() const; | 104 | int numberGetArgs() const; |
104 | int typeGetArgs() const; | 105 | int typeGetArgs() const; |
105 | int numberSetArgs() const; | 106 | int numberSetArgs() const; |
106 | int typeSetArgs() const; | 107 | int typeSetArgs() const; |
107 | 108 | ||
108 | // FIXME return int? as ::ioctl does? -zecke | 109 | // FIXME return int? as ::ioctl does? -zecke |
109 | void invoke() const; | 110 | void invoke() const; |
110 | void setParameter( int, u_int32_t ); | 111 | void setParameter( int, u_int32_t ); |
111 | 112 | ||
112 | private: | 113 | private: |
113 | u_int32_t _ioctl; | 114 | u_int32_t _ioctl; |
114 | u_int16_t _getargs; | 115 | u_int16_t _getargs; |
115 | u_int16_t _setargs; | 116 | u_int16_t _setargs; |
116 | 117 | ||
117 | }; | 118 | }; |
118 | 119 | ||
119 | /*====================================================================================== | 120 | /*====================================================================================== |
120 | * Miscellaneous | 121 | * Miscellaneous |
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 */ |
128 | 129 | ||
129 | #ifdef LBL_ALIGN | 130 | #ifdef LBL_ALIGN |
130 | #define EXTRACT_16BITS(p) \ | 131 | #define EXTRACT_16BITS(p) \ |
131 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ | 132 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ |
132 | (u_int16_t)*((const u_int8_t *)(p) + 1))) | 133 | (u_int16_t)*((const u_int8_t *)(p) + 1))) |
133 | #define EXTRACT_32BITS(p) \ | 134 | #define EXTRACT_32BITS(p) \ |
134 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ | 135 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ |
135 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ | 136 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ |
136 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ | 137 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ |
137 | (u_int32_t)*((const u_int8_t *)(p) + 3))) | 138 | (u_int32_t)*((const u_int8_t *)(p) + 3))) |
138 | #else | 139 | #else |
139 | #define EXTRACT_16BITS(p) \ | 140 | #define EXTRACT_16BITS(p) \ |
140 | ((u_int16_t)ntohs(*(const u_int16_t *)(p))) | 141 | ((u_int16_t)ntohs(*(const u_int16_t *)(p))) |
141 | #define EXTRACT_32BITS(p) \ | 142 | #define EXTRACT_32BITS(p) \ |
142 | ((u_int32_t)ntohl(*(const u_int32_t *)(p))) | 143 | ((u_int32_t)ntohl(*(const u_int32_t *)(p))) |
143 | #endif | 144 | #endif |
144 | 145 | ||
145 | #define EXTRACT_24BITS(p) \ | 146 | #define EXTRACT_24BITS(p) \ |
146 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ | 147 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ |
147 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ | 148 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ |
148 | (u_int32_t)*((const u_int8_t *)(p) + 2))) | 149 | (u_int32_t)*((const u_int8_t *)(p) + 2))) |
149 | 150 | ||
150 | /* Little endian protocol host order macros */ | 151 | /* Little endian protocol host order macros */ |
151 | #define EXTRACT_LE_8BITS(p) (*(p)) | 152 | #define EXTRACT_LE_8BITS(p) (*(p)) |
152 | #define EXTRACT_LE_16BITS(p) \ | 153 | #define EXTRACT_LE_16BITS(p) \ |
153 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ | 154 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ |
154 | (u_int16_t)*((const u_int8_t *)(p) + 0))) | 155 | (u_int16_t)*((const u_int8_t *)(p) + 0))) |
155 | #define EXTRACT_LE_32BITS(p) \ | 156 | #define EXTRACT_LE_32BITS(p) \ |
156 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ | 157 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ |
157 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ | 158 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ |
158 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ | 159 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ |
159 | (u_int32_t)*((const u_int8_t *)(p) + 0))) | 160 | (u_int32_t)*((const u_int8_t *)(p) + 0))) |
160 | 161 | ||
161 | #endif // ONETUTILS_H | 162 | #endif // ONETUTILS_H |
162 | 163 | ||
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 | |||
@@ -67,1057 +67,1046 @@ IntStringMap* _ioctlmap = constructIoctlMap(); | |||
67 | /*====================================================================================== | 67 | /*====================================================================================== |
68 | * ONetwork | 68 | * ONetwork |
69 | *======================================================================================*/ | 69 | *======================================================================================*/ |
70 | 70 | ||
71 | ONetwork* ONetwork::_instance = 0; | 71 | ONetwork* ONetwork::_instance = 0; |
72 | 72 | ||
73 | ONetwork::ONetwork() | 73 | ONetwork::ONetwork() |
74 | { | 74 | { |
75 | qDebug( "ONetwork::ONetwork()" ); | 75 | qDebug( "ONetwork::ONetwork()" ); |
76 | qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT ); | 76 | qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT ); |
77 | synchronize(); | 77 | synchronize(); |
78 | } | 78 | } |
79 | 79 | ||
80 | void ONetwork::synchronize() | 80 | void ONetwork::synchronize() |
81 | { | 81 | { |
82 | // gather available interfaces by inspecting /proc/net/dev | 82 | // gather available interfaces by inspecting /proc/net/dev |
83 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 83 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
84 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 84 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
85 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev | 85 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev |
86 | 86 | ||
87 | _interfaces.clear(); | 87 | _interfaces.clear(); |
88 | QString str; | 88 | QString str; |
89 | QFile f( "/proc/net/dev" ); | 89 | QFile f( "/proc/net/dev" ); |
90 | bool hasFile = f.open( IO_ReadOnly ); | 90 | bool hasFile = f.open( IO_ReadOnly ); |
91 | if ( !hasFile ) | 91 | if ( !hasFile ) |
92 | { | 92 | { |
93 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); | 93 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); |
94 | return; | 94 | return; |
95 | } | 95 | } |
96 | QTextStream s( &f ); | 96 | QTextStream s( &f ); |
97 | s.readLine(); | 97 | s.readLine(); |
98 | s.readLine(); | 98 | s.readLine(); |
99 | while ( !s.atEnd() ) | 99 | while ( !s.atEnd() ) |
100 | { | 100 | { |
101 | s >> str; | 101 | s >> str; |
102 | str.truncate( str.find( ':' ) ); | 102 | str.truncate( str.find( ':' ) ); |
103 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); | 103 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); |
104 | ONetworkInterface* iface; | 104 | ONetworkInterface* iface; |
105 | if ( isWirelessInterface( str ) ) | 105 | if ( isWirelessInterface( str ) ) |
106 | { | 106 | { |
107 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 107 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
108 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 108 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); |
109 | } | 109 | } |
110 | else | 110 | else |
111 | { | 111 | { |
112 | iface = new ONetworkInterface( this, (const char*) str ); | 112 | iface = new ONetworkInterface( this, (const char*) str ); |
113 | } | 113 | } |
114 | _interfaces.insert( str, iface ); | 114 | _interfaces.insert( str, iface ); |
115 | s.readLine(); | 115 | s.readLine(); |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | short ONetwork::wirelessExtensionVersion() | 120 | short ONetwork::wirelessExtensionVersion() |
121 | { | 121 | { |
122 | return WIRELESS_EXT; | 122 | return WIRELESS_EXT; |
123 | } | 123 | } |
124 | 124 | ||
125 | 125 | ||
126 | int ONetwork::count() const | 126 | int ONetwork::count() const |
127 | { | 127 | { |
128 | return _interfaces.count(); | 128 | return _interfaces.count(); |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
132 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 132 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
133 | { | 133 | { |
134 | return _interfaces[iface]; | 134 | return _interfaces[iface]; |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | ONetwork* ONetwork::instance() | 138 | ONetwork* ONetwork::instance() |
139 | { | 139 | { |
140 | if ( !_instance ) _instance = new ONetwork(); | 140 | if ( !_instance ) _instance = new ONetwork(); |
141 | return _instance; | 141 | return _instance; |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | ONetwork::InterfaceIterator ONetwork::iterator() const | 145 | ONetwork::InterfaceIterator ONetwork::iterator() const |
146 | { | 146 | { |
147 | return ONetwork::InterfaceIterator( _interfaces ); | 147 | return ONetwork::InterfaceIterator( _interfaces ); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | bool ONetwork::isWirelessInterface( const char* name ) const | 151 | bool ONetwork::isWirelessInterface( const char* name ) const |
152 | { | 152 | { |
153 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 153 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
154 | struct iwreq iwr; | 154 | struct iwreq iwr; |
155 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 155 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
156 | strcpy( (char*) &iwr.ifr_name, name ); | 156 | strcpy( (char*) &iwr.ifr_name, name ); |
157 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 157 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
158 | return result != -1; | 158 | return result != -1; |
159 | } | 159 | } |
160 | 160 | ||
161 | /*====================================================================================== | 161 | /*====================================================================================== |
162 | * ONetworkInterface | 162 | * ONetworkInterface |
163 | *======================================================================================*/ | 163 | *======================================================================================*/ |
164 | 164 | ||
165 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 165 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
166 | :QObject( parent, name ), | 166 | :QObject( parent, name ), |
167 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 167 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
168 | { | 168 | { |
169 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 169 | qDebug( "ONetworkInterface::ONetworkInterface()" ); |
170 | init(); | 170 | init(); |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | struct ifreq& ONetworkInterface::ifr() const | 174 | struct ifreq& ONetworkInterface::ifr() const |
175 | { | 175 | { |
176 | return _ifr; | 176 | return _ifr; |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | void ONetworkInterface::init() | 180 | void ONetworkInterface::init() |
181 | { | 181 | { |
182 | qDebug( "ONetworkInterface::init()" ); | 182 | qDebug( "ONetworkInterface::init()" ); |
183 | 183 | ||
184 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 184 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
185 | 185 | ||
186 | if ( _sfd == -1 ) | 186 | if ( _sfd == -1 ) |
187 | { | 187 | { |
188 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); | 188 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); |
189 | return; | 189 | return; |
190 | } | 190 | } |
191 | } | 191 | } |
192 | 192 | ||
193 | 193 | ||
194 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 194 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
195 | { | 195 | { |
196 | #ifndef NODEBUG | 196 | #ifndef NODEBUG |
197 | int result = ::ioctl( _sfd, call, &ifreq ); | 197 | int result = ::ioctl( _sfd, call, &ifreq ); |
198 | if ( result == -1 ) | 198 | if ( result == -1 ) |
199 | qDebug( "ONetworkInterface::ioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) *(*_ioctlmap)[call], call, result, strerror( errno ) ); | 199 | qDebug( "ONetworkInterface::ioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) *(*_ioctlmap)[call], call, result, strerror( errno ) ); |
200 | else | 200 | else |
201 | qDebug( "ONetworkInterface::ioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) *(*_ioctlmap)[call], call ); | 201 | qDebug( "ONetworkInterface::ioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) *(*_ioctlmap)[call], call ); |
202 | return ( result != -1 ); | 202 | return ( result != -1 ); |
203 | #else | 203 | #else |
204 | return ::ioctl( _sfd, call, &ifreq ) != -1; | 204 | return ::ioctl( _sfd, call, &ifreq ) != -1; |
205 | #endif | 205 | #endif |
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | bool ONetworkInterface::ioctl( int call ) const | 209 | bool ONetworkInterface::ioctl( int call ) const |
210 | { | 210 | { |
211 | strcpy( _ifr.ifr_name, name() ); | 211 | strcpy( _ifr.ifr_name, name() ); |
212 | return ioctl( call, _ifr ); | 212 | return ioctl( call, _ifr ); |
213 | } | 213 | } |
214 | 214 | ||
215 | 215 | ||
216 | bool ONetworkInterface::isLoopback() const | 216 | bool ONetworkInterface::isLoopback() const |
217 | { | 217 | { |
218 | ioctl( SIOCGIFFLAGS ); | 218 | ioctl( SIOCGIFFLAGS ); |
219 | return _ifr.ifr_flags & IFF_LOOPBACK; | 219 | return _ifr.ifr_flags & IFF_LOOPBACK; |
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | bool ONetworkInterface::setUp( bool b ) | 223 | bool ONetworkInterface::setUp( bool b ) |
224 | { | 224 | { |
225 | ioctl( SIOCGIFFLAGS ); | 225 | ioctl( SIOCGIFFLAGS ); |
226 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 226 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
227 | else _ifr.ifr_flags &= (~IFF_UP); | 227 | else _ifr.ifr_flags &= (~IFF_UP); |
228 | return ioctl( SIOCSIFFLAGS ); | 228 | return ioctl( SIOCSIFFLAGS ); |
229 | } | 229 | } |
230 | 230 | ||
231 | 231 | ||
232 | bool ONetworkInterface::isUp() const | 232 | bool ONetworkInterface::isUp() const |
233 | { | 233 | { |
234 | ioctl( SIOCGIFFLAGS ); | 234 | ioctl( SIOCGIFFLAGS ); |
235 | return _ifr.ifr_flags & IFF_UP; | 235 | return _ifr.ifr_flags & IFF_UP; |
236 | } | 236 | } |
237 | 237 | ||
238 | 238 | ||
239 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) | 239 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) |
240 | { | 240 | { |
241 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 241 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
242 | sa->sin_family = AF_INET; | 242 | sa->sin_family = AF_INET; |
243 | sa->sin_port = 0; | 243 | sa->sin_port = 0; |
244 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 244 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
245 | ioctl( SIOCSIFADDR ); | 245 | ioctl( SIOCSIFADDR ); |
246 | } | 246 | } |
247 | 247 | ||
248 | 248 | ||
249 | QString ONetworkInterface::ipV4Address() const | 249 | QString ONetworkInterface::ipV4Address() const |
250 | { | 250 | { |
251 | if ( ioctl( SIOCGIFADDR ) ) | 251 | if ( ioctl( SIOCGIFADDR ) ) |
252 | { | 252 | { |
253 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 253 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
254 | //FIXME: Use QHostAddress here | 254 | //FIXME: Use QHostAddress here |
255 | return QString( inet_ntoa( sa->sin_addr ) ); | 255 | return QString( inet_ntoa( sa->sin_addr ) ); |
256 | } | 256 | } |
257 | else | 257 | else |
258 | return "<unknown>"; | 258 | return "<unknown>"; |
259 | |||
259 | } | 260 | } |
260 | 261 | ||
261 | 262 | ||
262 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) | 263 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) |
263 | { | 264 | { |
264 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | 265 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
265 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); | 266 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); |
266 | ioctl( SIOCSIFHWADDR ); | 267 | ioctl( SIOCSIFHWADDR ); |
267 | } | 268 | } |
268 | 269 | ||
269 | 270 | ||
270 | OMacAddress ONetworkInterface::macAddress() const | 271 | OMacAddress ONetworkInterface::macAddress() const |
271 | { | 272 | { |
272 | if ( ioctl( SIOCGIFHWADDR ) ) | 273 | if ( ioctl( SIOCGIFHWADDR ) ) |
273 | { | 274 | { |
274 | return OMacAddress( _ifr ); | 275 | return OMacAddress( _ifr ); |
275 | } | 276 | } |
276 | else | 277 | else |
277 | { | 278 | { |
278 | return OMacAddress::unknown; | 279 | return OMacAddress::unknown; |
279 | } | 280 | } |
280 | } | 281 | } |
281 | 282 | ||
282 | 283 | ||
283 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) | 284 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) |
284 | { | 285 | { |
285 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 286 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
286 | sa->sin_family = AF_INET; | 287 | sa->sin_family = AF_INET; |
287 | sa->sin_port = 0; | 288 | sa->sin_port = 0; |
288 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 289 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
289 | ioctl( SIOCSIFNETMASK ); | 290 | ioctl( SIOCSIFNETMASK ); |
290 | } | 291 | } |
291 | 292 | ||
292 | 293 | ||
293 | QString ONetworkInterface::ipV4Netmask() const | 294 | QString ONetworkInterface::ipV4Netmask() const |
294 | { | 295 | { |
295 | if ( ioctl( SIOCGIFNETMASK ) ) | 296 | if ( ioctl( SIOCGIFNETMASK ) ) |
296 | { | 297 | { |
297 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 298 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
298 | //FIXME: Use QHostAddress here | 299 | //FIXME: Use QHostAddress here |
299 | return QString( inet_ntoa( sa->sin_addr ) ); | 300 | return QString( inet_ntoa( sa->sin_addr ) ); |
300 | } | 301 | } |
301 | else | 302 | else |
302 | return "<unknown>"; | 303 | return "<unknown>"; |
303 | } | 304 | } |
304 | 305 | ||
305 | 306 | ||
306 | int ONetworkInterface::dataLinkType() const | 307 | int ONetworkInterface::dataLinkType() const |
307 | { | 308 | { |
308 | if ( ioctl( SIOCGIFHWADDR ) ) | 309 | if ( ioctl( SIOCGIFHWADDR ) ) |
309 | { | 310 | { |
310 | return _ifr.ifr_hwaddr.sa_family; | 311 | return _ifr.ifr_hwaddr.sa_family; |
311 | } | 312 | } |
312 | else | 313 | else |
313 | { | 314 | { |
314 | return -1; | 315 | return -1; |
315 | } | 316 | } |
316 | } | 317 | } |
317 | 318 | ||
318 | 319 | ||
319 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 320 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
320 | { | 321 | { |
321 | _mon = m; | 322 | _mon = m; |
322 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); | 323 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); |
323 | } | 324 | } |
324 | 325 | ||
325 | 326 | ||
326 | OMonitoringInterface* ONetworkInterface::monitoring() const | 327 | OMonitoringInterface* ONetworkInterface::monitoring() const |
327 | { | 328 | { |
328 | return _mon; | 329 | return _mon; |
329 | } | 330 | } |
330 | 331 | ||
331 | 332 | ||
332 | ONetworkInterface::~ONetworkInterface() | 333 | ONetworkInterface::~ONetworkInterface() |
333 | { | 334 | { |
334 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); | 335 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); |
335 | if ( _sfd != -1 ) ::close( _sfd ); | 336 | if ( _sfd != -1 ) ::close( _sfd ); |
336 | } | 337 | } |
337 | 338 | ||
338 | 339 | ||
339 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 340 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
340 | { | 341 | { |
341 | ioctl( SIOCGIFFLAGS ); | 342 | ioctl( SIOCGIFFLAGS ); |
342 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 343 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
343 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 344 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
344 | return ioctl( SIOCSIFFLAGS ); | 345 | return ioctl( SIOCSIFFLAGS ); |
345 | } | 346 | } |
346 | 347 | ||
347 | 348 | ||
348 | bool ONetworkInterface::promiscuousMode() const | 349 | bool ONetworkInterface::promiscuousMode() const |
349 | { | 350 | { |
350 | ioctl( SIOCGIFFLAGS ); | 351 | ioctl( SIOCGIFFLAGS ); |
351 | return _ifr.ifr_flags & IFF_PROMISC; | 352 | return _ifr.ifr_flags & IFF_PROMISC; |
352 | } | 353 | } |
353 | 354 | ||
354 | 355 | ||
355 | bool ONetworkInterface::isWireless() const | 356 | bool ONetworkInterface::isWireless() const |
356 | { | 357 | { |
357 | return ioctl( SIOCGIWNAME ); | 358 | return ioctl( SIOCGIWNAME ); |
358 | } | 359 | } |
359 | 360 | ||
360 | 361 | ||
361 | /*====================================================================================== | 362 | /*====================================================================================== |
362 | * OChannelHopper | 363 | * OChannelHopper |
363 | *======================================================================================*/ | 364 | *======================================================================================*/ |
364 | 365 | ||
365 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 366 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
366 | :QObject( 0, "Mickey's funky hopper" ), | 367 | :QObject( 0, "Mickey's funky hopper" ), |
367 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 368 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
368 | { | 369 | { |
369 | int _maxChannel = iface->channels()+1; | 370 | int _maxChannel = iface->channels()+1; |
370 | // generate fancy hopping sequence honoring the device capabilities | 371 | // generate fancy hopping sequence honoring the device capabilities |
371 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 372 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
372 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 373 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
373 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 374 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
374 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 375 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
375 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 376 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
376 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 377 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
377 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 378 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
378 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 379 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
379 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 380 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
380 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 381 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
381 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 382 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
382 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 383 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
383 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 384 | if ( _maxChannel >= 6 ) _channels.append( 6 ); |
384 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 385 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
385 | _channel = _channels.begin(); | 386 | _channel = _channels.begin(); |
386 | 387 | ||
387 | } | 388 | } |
388 | 389 | ||
389 | 390 | ||
390 | OChannelHopper::~OChannelHopper() | 391 | OChannelHopper::~OChannelHopper() |
391 | { | 392 | { |
392 | } | 393 | } |
393 | 394 | ||
394 | 395 | ||
395 | bool OChannelHopper::isActive() const | 396 | bool OChannelHopper::isActive() const |
396 | { | 397 | { |
397 | return _tid; | 398 | return _tid; |
398 | } | 399 | } |
399 | 400 | ||
400 | 401 | ||
401 | int OChannelHopper::channel() const | 402 | int OChannelHopper::channel() const |
402 | { | 403 | { |
403 | return *_channel; | 404 | return *_channel; |
404 | } | 405 | } |
405 | 406 | ||
406 | 407 | ||
407 | void OChannelHopper::timerEvent( QTimerEvent* ) | 408 | void OChannelHopper::timerEvent( QTimerEvent* ) |
408 | { | 409 | { |
409 | _iface->setChannel( *_channel ); | 410 | _iface->setChannel( *_channel ); |
410 | emit( hopped( *_channel ) ); | 411 | emit( hopped( *_channel ) ); |
411 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 412 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", |
412 | *_channel, (const char*) _iface->name() ); | 413 | *_channel, (const char*) _iface->name() ); |
413 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 414 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
414 | } | 415 | } |
415 | 416 | ||
416 | 417 | ||
417 | void OChannelHopper::setInterval( int interval ) | 418 | void OChannelHopper::setInterval( int interval ) |
418 | { | 419 | { |
419 | if ( interval == _interval ) | 420 | if ( interval == _interval ) |
420 | return; | 421 | return; |
421 | 422 | ||
422 | if ( _interval ) | 423 | if ( _interval ) |
423 | killTimer( _tid ); | 424 | killTimer( _tid ); |
424 | 425 | ||
425 | _tid = 0; | 426 | _tid = 0; |
426 | _interval = interval; | 427 | _interval = interval; |
427 | 428 | ||
428 | if ( _interval ) | 429 | if ( _interval ) |
429 | { | 430 | { |
430 | _tid = startTimer( interval ); | 431 | _tid = startTimer( interval ); |
431 | } | 432 | } |
432 | } | 433 | } |
433 | 434 | ||
434 | 435 | ||
435 | int OChannelHopper::interval() const | 436 | int OChannelHopper::interval() const |
436 | { | 437 | { |
437 | return _interval; | 438 | return _interval; |
438 | } | 439 | } |
439 | 440 | ||
440 | 441 | ||
441 | /*====================================================================================== | 442 | /*====================================================================================== |
442 | * OWirelessNetworkInterface | 443 | * OWirelessNetworkInterface |
443 | *======================================================================================*/ | 444 | *======================================================================================*/ |
444 | 445 | ||
445 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 446 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
446 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 447 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
447 | { | 448 | { |
448 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 449 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); |
449 | init(); | 450 | init(); |
450 | } | 451 | } |
451 | 452 | ||
452 | 453 | ||
453 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 454 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
454 | { | 455 | { |
455 | } | 456 | } |
456 | 457 | ||
457 | 458 | ||
458 | struct iwreq& OWirelessNetworkInterface::iwr() const | 459 | struct iwreq& OWirelessNetworkInterface::iwr() const |
459 | { | 460 | { |
460 | return _iwr; | 461 | return _iwr; |
461 | } | 462 | } |
462 | 463 | ||
463 | 464 | ||
464 | void OWirelessNetworkInterface::init() | 465 | void OWirelessNetworkInterface::init() |
465 | { | 466 | { |
466 | qDebug( "OWirelessNetworkInterface::init()" ); | 467 | qDebug( "OWirelessNetworkInterface::init()" ); |
467 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 468 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
468 | buildInformation(); | 469 | buildInformation(); |
469 | buildPrivateList(); | 470 | buildPrivateList(); |
470 | dumpInformation(); | 471 | dumpInformation(); |
471 | } | 472 | } |
472 | 473 | ||
473 | 474 | ||
474 | bool OWirelessNetworkInterface::isAssociated() const | 475 | 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 | ||
503 | 490 | ||
504 | void OWirelessNetworkInterface::buildInformation() | 491 | void OWirelessNetworkInterface::buildInformation() |
505 | { | 492 | { |
506 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 493 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
507 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | 494 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete |
508 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 495 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
509 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | 496 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate |
510 | //ML: _too much_ space. This is damn shitty crap *sigh* | 497 | //ML: _too much_ space. This is damn shitty crap *sigh* |
511 | //ML: We allocate a large memory region in RAM and check whether the | 498 | //ML: We allocate a large memory region in RAM and check whether the |
512 | //ML: driver pollutes this extra space. The complaint will be made on stdout, | 499 | //ML: driver pollutes this extra space. The complaint will be made on stdout, |
513 | //ML: so please forward this... | 500 | //ML: so please forward this... |
514 | 501 | ||
515 | struct iwreq wrq; | 502 | struct iwreq wrq; |
516 | int len = sizeof( struct iw_range )*2; | 503 | int len = sizeof( struct iw_range )*2; |
517 | char *buffer = (char*) malloc( len ); | 504 | char *buffer = (char*) malloc( len ); |
518 | //FIXME: Validate if we actually got the memory block | 505 | //FIXME: Validate if we actually got the memory block |
519 | memset( buffer, 0, len ); | 506 | memset( buffer, 0, len ); |
520 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | 507 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); |
521 | wrq.u.data.pointer = (caddr_t) buffer; | 508 | wrq.u.data.pointer = (caddr_t) buffer; |
522 | wrq.u.data.length = sizeof( struct iw_range ); | 509 | wrq.u.data.length = sizeof( struct iw_range ); |
523 | wrq.u.data.flags = 0; | 510 | wrq.u.data.flags = 0; |
524 | 511 | ||
525 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 512 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
526 | { | 513 | { |
527 | qDebug( "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (%s) - using default values.", strerror( errno ) ); | 514 | qDebug( "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (%s) - using default values.", strerror( errno ) ); |
528 | _channels.insert( 2412, 1 ); // 2.412 GHz | 515 | _channels.insert( 2412, 1 ); // 2.412 GHz |
529 | _channels.insert( 2417, 2 ); // 2.417 GHz | 516 | _channels.insert( 2417, 2 ); // 2.417 GHz |
530 | _channels.insert( 2422, 3 ); // 2.422 GHz | 517 | _channels.insert( 2422, 3 ); // 2.422 GHz |
531 | _channels.insert( 2427, 4 ); // 2.427 GHz | 518 | _channels.insert( 2427, 4 ); // 2.427 GHz |
532 | _channels.insert( 2432, 5 ); // 2.432 GHz | 519 | _channels.insert( 2432, 5 ); // 2.432 GHz |
533 | _channels.insert( 2437, 6 ); // 2.437 GHz | 520 | _channels.insert( 2437, 6 ); // 2.437 GHz |
534 | _channels.insert( 2442, 7 ); // 2.442 GHz | 521 | _channels.insert( 2442, 7 ); // 2.442 GHz |
535 | _channels.insert( 2447, 8 ); // 2.447 GHz | 522 | _channels.insert( 2447, 8 ); // 2.447 GHz |
536 | _channels.insert( 2452, 9 ); // 2.452 GHz | 523 | _channels.insert( 2452, 9 ); // 2.452 GHz |
537 | _channels.insert( 2457, 10 ); // 2.457 GHz | 524 | _channels.insert( 2457, 10 ); // 2.457 GHz |
538 | _channels.insert( 2462, 11 ); // 2.462 GHz | 525 | _channels.insert( 2462, 11 ); // 2.462 GHz |
539 | 526 | ||
540 | memset( &_range, 0, sizeof( struct iw_range ) ); | 527 | memset( &_range, 0, sizeof( struct iw_range ) ); |
541 | } | 528 | } |
542 | else | 529 | else |
543 | { | 530 | { |
544 | // <check if the driver overwrites stuff> | 531 | // <check if the driver overwrites stuff> |
545 | int max = 0; | 532 | int max = 0; |
546 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 533 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
547 | if (buffer[r] != 0) | 534 | if (buffer[r] != 0) |
548 | max = r; | 535 | max = r; |
549 | if (max > 0) | 536 | if (max > 0) |
550 | { | 537 | { |
551 | qWarning( "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '%s' sucks!\n" | 538 | qWarning( "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '%s' sucks!\n" |
552 | "It overwrote the buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); | 539 | "It overwrote the buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); |
553 | } | 540 | } |
554 | // </check if the driver overwrites stuff> | 541 | // </check if the driver overwrites stuff> |
555 | 542 | ||
556 | struct iw_range range; | 543 | struct iw_range range; |
557 | memcpy( &range, buffer, sizeof range ); | 544 | memcpy( &range, buffer, sizeof range ); |
558 | 545 | ||
559 | qDebug( "OWirelessNetworkInterface::buildInformation(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | 546 | qDebug( "OWirelessNetworkInterface::buildInformation(): Interface %s reported to have %d channels.", name(), range.num_frequency ); |
560 | for ( int i = 0; i < range.num_frequency; ++i ) | 547 | for ( int i = 0; i < range.num_frequency; ++i ) |
561 | { | 548 | { |
562 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 549 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
563 | _channels.insert( freq, i+1 ); | 550 | _channels.insert( freq, i+1 ); |
564 | } | 551 | } |
565 | } | 552 | } |
566 | 553 | ||
567 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); | 554 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); |
568 | qDebug( "OWirelessNetworkInterface::buildInformation(): Information block constructed." ); | 555 | qDebug( "OWirelessNetworkInterface::buildInformation(): Information block constructed." ); |
569 | free(buffer); | 556 | free(buffer); |
570 | } | 557 | } |
571 | 558 | ||
572 | 559 | ||
573 | void OWirelessNetworkInterface::buildPrivateList() | 560 | void OWirelessNetworkInterface::buildPrivateList() |
574 | { | 561 | { |
575 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | 562 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); |
576 | 563 | ||
577 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 564 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
578 | 565 | ||
579 | _iwr.u.data.pointer = (char*) &priv; | 566 | _iwr.u.data.pointer = (char*) &priv; |
580 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | 567 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself |
581 | _iwr.u.data.flags = 0; | 568 | _iwr.u.data.flags = 0; |
582 | 569 | ||
583 | if ( !wioctl( SIOCGIWPRIV ) ) | 570 | if ( !wioctl( SIOCGIWPRIV ) ) |
584 | { | 571 | { |
585 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); | 572 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); |
586 | return; | 573 | return; |
587 | } | 574 | } |
588 | 575 | ||
589 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 576 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
590 | { | 577 | { |
591 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 578 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
592 | } | 579 | } |
593 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); | 580 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); |
594 | } | 581 | } |
595 | 582 | ||
596 | 583 | ||
597 | void OWirelessNetworkInterface::dumpInformation() const | 584 | void OWirelessNetworkInterface::dumpInformation() const |
598 | { | 585 | { |
599 | qDebug( "OWirelessNetworkInterface::() -------------- dumping information block ----------------" ); | 586 | qDebug( "OWirelessNetworkInterface::() -------------- dumping information block ----------------" ); |
600 | 587 | ||
601 | 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 ); | 588 | 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 ); |
602 | qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source ); | 589 | qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source ); |
603 | 590 | ||
604 | qDebug( "OWirelessNetworkInterface::() ---------------------------------------------------------" ); | 591 | qDebug( "OWirelessNetworkInterface::() ---------------------------------------------------------" ); |
605 | } | 592 | } |
606 | 593 | ||
607 | 594 | ||
608 | int OWirelessNetworkInterface::channel() const | 595 | int OWirelessNetworkInterface::channel() const |
609 | { | 596 | { |
610 | //FIXME: When monitoring enabled, then use it | 597 | //FIXME: When monitoring enabled, then use it |
611 | //FIXME: to gather the current RF channel | 598 | //FIXME: to gather the current RF channel |
612 | //FIXME: Until then, get active channel from hopper. | 599 | //FIXME: Until then, get active channel from hopper. |
613 | if ( _hopper && _hopper->isActive() ) | 600 | if ( _hopper && _hopper->isActive() ) |
614 | return _hopper->channel(); | 601 | return _hopper->channel(); |
615 | 602 | ||
616 | if ( !wioctl( SIOCGIWFREQ ) ) | 603 | if ( !wioctl( SIOCGIWFREQ ) ) |
617 | { | 604 | { |
618 | return -1; | 605 | return -1; |
619 | } | 606 | } |
620 | else | 607 | else |
621 | { | 608 | { |
622 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; | 609 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; |
623 | } | 610 | } |
624 | } | 611 | } |
625 | 612 | ||
626 | 613 | ||
627 | void OWirelessNetworkInterface::setChannel( int c ) const | 614 | void OWirelessNetworkInterface::setChannel( int c ) const |
628 | { | 615 | { |
629 | if ( !c ) | 616 | if ( !c ) |
630 | { | 617 | { |
631 | qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" ); | 618 | qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" ); |
632 | return; | 619 | return; |
633 | } | 620 | } |
634 | 621 | ||
635 | if ( !_mon ) | 622 | if ( !_mon ) |
636 | { | 623 | { |
637 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 624 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
638 | _iwr.u.freq.m = c; | 625 | _iwr.u.freq.m = c; |
639 | _iwr.u.freq.e = 0; | 626 | _iwr.u.freq.e = 0; |
640 | wioctl( SIOCSIWFREQ ); | 627 | wioctl( SIOCSIWFREQ ); |
641 | } | 628 | } |
642 | else | 629 | else |
643 | { | 630 | { |
644 | _mon->setChannel( c ); | 631 | _mon->setChannel( c ); |
645 | } | 632 | } |
646 | } | 633 | } |
647 | 634 | ||
648 | 635 | ||
649 | double OWirelessNetworkInterface::frequency() const | 636 | double OWirelessNetworkInterface::frequency() const |
650 | { | 637 | { |
651 | if ( !wioctl( SIOCGIWFREQ ) ) | 638 | if ( !wioctl( SIOCGIWFREQ ) ) |
652 | { | 639 | { |
653 | return -1.0; | 640 | return -1.0; |
654 | } | 641 | } |
655 | else | 642 | else |
656 | { | 643 | { |
657 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 644 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
658 | } | 645 | } |
659 | } | 646 | } |
660 | 647 | ||
661 | 648 | ||
662 | int OWirelessNetworkInterface::channels() const | 649 | int OWirelessNetworkInterface::channels() const |
663 | { | 650 | { |
664 | return _channels.count(); | 651 | return _channels.count(); |
665 | } | 652 | } |
666 | 653 | ||
667 | 654 | ||
668 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 655 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
669 | { | 656 | { |
670 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 657 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
671 | _hopper->setInterval( interval ); | 658 | _hopper->setInterval( interval ); |
672 | //FIXME: When and by whom will the channel hopper be deleted? | 659 | //FIXME: When and by whom will the channel hopper be deleted? |
673 | //TODO: rely on QObject hierarchy | 660 | //TODO: rely on QObject hierarchy |
674 | } | 661 | } |
675 | 662 | ||
676 | 663 | ||
677 | int OWirelessNetworkInterface::channelHopping() const | 664 | int OWirelessNetworkInterface::channelHopping() const |
678 | { | 665 | { |
679 | return _hopper->interval(); | 666 | return _hopper->interval(); |
680 | } | 667 | } |
681 | 668 | ||
682 | 669 | ||
683 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const | 670 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const |
684 | { | 671 | { |
685 | return _hopper; | 672 | return _hopper; |
686 | } | 673 | } |
687 | 674 | ||
688 | 675 | ||
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 | } |
705 | 681 | ||
706 | 682 | ||
707 | QString OWirelessNetworkInterface::mode() const | 683 | QString OWirelessNetworkInterface::mode() const |
708 | { | 684 | { |
709 | if ( !wioctl( SIOCGIWMODE ) ) | 685 | if ( !wioctl( SIOCGIWMODE ) ) |
710 | { | 686 | { |
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 | ||
726 | 692 | ||
727 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 693 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
728 | { | 694 | { |
729 | if ( _mon ) | 695 | if ( _mon ) |
730 | _mon->setEnabled( b ); | 696 | _mon->setEnabled( b ); |
731 | else | 697 | else |
732 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 698 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
733 | } | 699 | } |
734 | 700 | ||
735 | 701 | ||
736 | bool OWirelessNetworkInterface::monitorMode() const | 702 | bool OWirelessNetworkInterface::monitorMode() const |
737 | { | 703 | { |
738 | qDebug( "dataLinkType = %d", dataLinkType() ); | 704 | qDebug( "dataLinkType = %d", dataLinkType() ); |
739 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); | 705 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); |
740 | //FIXME: 802 is the header type for PRISM - Linux support for this is pending... | 706 | //FIXME: 802 is the header type for PRISM - Linux support for this is pending... |
741 | //FIXME: What is 119, by the way? | 707 | //FIXME: What is 119, by the way? |
742 | } | 708 | } |
743 | 709 | ||
744 | 710 | ||
745 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) | 711 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) |
746 | { | 712 | { |
747 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); | 713 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); |
748 | _iwr.u.essid.length = nickname.length(); | 714 | _iwr.u.essid.length = nickname.length(); |
749 | wioctl( SIOCSIWNICKN ); | 715 | wioctl( SIOCSIWNICKN ); |
750 | } | 716 | } |
751 | 717 | ||
752 | 718 | ||
753 | QString OWirelessNetworkInterface::nickName() const | 719 | QString OWirelessNetworkInterface::nickName() const |
754 | { | 720 | { |
755 | char str[IW_ESSID_MAX_SIZE]; | 721 | char str[IW_ESSID_MAX_SIZE]; |
756 | _iwr.u.data.pointer = &str[0]; | 722 | _iwr.u.data.pointer = &str[0]; |
757 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 723 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
758 | if ( !wioctl( SIOCGIWNICKN ) ) | 724 | if ( !wioctl( SIOCGIWNICKN ) ) |
759 | { | 725 | { |
760 | return "<unknown>"; | 726 | return "<unknown>"; |
761 | } | 727 | } |
762 | else | 728 | else |
763 | { | 729 | { |
764 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 730 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
765 | return str; | 731 | return str; |
766 | } | 732 | } |
767 | } | 733 | } |
768 | 734 | ||
769 | 735 | ||
770 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 736 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
771 | { | 737 | { |
772 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 738 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
773 | if ( !priv ) | 739 | if ( !priv ) |
774 | { | 740 | { |
775 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); | 741 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); |
776 | return; | 742 | return; |
777 | } | 743 | } |
778 | if ( priv->numberSetArgs() != numargs ) | 744 | if ( priv->numberSetArgs() != numargs ) |
779 | { | 745 | { |
780 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); | 746 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); |
781 | return; | 747 | return; |
782 | } | 748 | } |
783 | 749 | ||
784 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); | 750 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); |
785 | memset( &_iwr, 0, sizeof _iwr ); | 751 | memset( &_iwr, 0, sizeof _iwr ); |
786 | va_list argp; | 752 | va_list argp; |
787 | va_start( argp, numargs ); | 753 | va_start( argp, numargs ); |
788 | for ( int i = 0; i < numargs; ++i ) | 754 | for ( int i = 0; i < numargs; ++i ) |
789 | { | 755 | { |
790 | priv->setParameter( i, va_arg( argp, int ) ); | 756 | priv->setParameter( i, va_arg( argp, int ) ); |
791 | } | 757 | } |
792 | va_end( argp ); | 758 | va_end( argp ); |
793 | priv->invoke(); | 759 | priv->invoke(); |
794 | } | 760 | } |
795 | 761 | ||
796 | 762 | ||
797 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 763 | void OWirelessNetworkInterface::getPrivate( const QString& call ) |
798 | { | 764 | { |
799 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); | 765 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); |
800 | } | 766 | } |
801 | 767 | ||
802 | 768 | ||
803 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | 769 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) |
804 | { | 770 | { |
805 | return child( (const char*) call ); | 771 | return child( (const char*) call ); |
806 | } | 772 | } |
807 | 773 | ||
808 | 774 | ||
809 | QString OWirelessNetworkInterface::SSID() const | 775 | QString OWirelessNetworkInterface::SSID() const |
810 | { | 776 | { |
811 | char str[IW_ESSID_MAX_SIZE]; | 777 | char str[IW_ESSID_MAX_SIZE]; |
812 | _iwr.u.essid.pointer = &str[0]; | 778 | _iwr.u.essid.pointer = &str[0]; |
813 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 779 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
814 | if ( !wioctl( SIOCGIWESSID ) ) | 780 | if ( !wioctl( SIOCGIWESSID ) ) |
815 | { | 781 | { |
816 | return "<unknown>"; | 782 | return "<unknown>"; |
817 | } | 783 | } |
818 | else | 784 | else |
819 | { | 785 | { |
820 | return str; | 786 | return str; |
821 | } | 787 | } |
822 | } | 788 | } |
823 | 789 | ||
824 | 790 | ||
825 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 791 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
826 | { | 792 | { |
827 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 793 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
828 | _iwr.u.essid.length = ssid.length(); | 794 | _iwr.u.essid.length = ssid.length(); |
829 | wioctl( SIOCSIWESSID ); | 795 | wioctl( SIOCSIWESSID ); |
830 | } | 796 | } |
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; |
836 | _iwr.u.param.value = 0; | 802 | _iwr.u.param.value = 0; |
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 | ||
844 | qDebug( "ONetworkInterface::scanNetwork() - scan started." ); | 812 | qDebug( "ONetworkInterface::scanNetwork() - scan started." ); |
845 | 813 | ||
846 | bool results = false; | 814 | bool results = false; |
847 | struct timeval tv; | 815 | struct timeval tv; |
848 | tv.tv_sec = 0; | 816 | tv.tv_sec = 0; |
849 | tv.tv_usec = 250000; // initial timeout ~ 250ms | 817 | tv.tv_usec = 250000; // initial timeout ~ 250ms |
850 | char buffer[IW_SCAN_MAX_DATA]; | 818 | char buffer[IW_SCAN_MAX_DATA]; |
851 | 819 | ||
852 | while ( !results && timeout > 0 ) | 820 | while ( !results && timeout > 0 ) |
853 | { | 821 | { |
854 | timeout -= tv.tv_usec; | 822 | timeout -= tv.tv_usec; |
855 | select( 0, 0, 0, 0, &tv ); | 823 | select( 0, 0, 0, 0, &tv ); |
856 | 824 | ||
857 | _iwr.u.data.pointer = &buffer[0]; | 825 | _iwr.u.data.pointer = &buffer[0]; |
858 | _iwr.u.data.flags = 0; | 826 | _iwr.u.data.flags = 0; |
859 | _iwr.u.data.length = sizeof buffer; | 827 | _iwr.u.data.length = sizeof buffer; |
860 | if ( wioctl( SIOCGIWSCAN ) ) | 828 | if ( wioctl( SIOCGIWSCAN ) ) |
861 | { | 829 | { |
862 | results = true; | 830 | results = true; |
863 | continue; | 831 | continue; |
864 | } | 832 | } |
865 | else if ( errno == EAGAIN) | 833 | else if ( errno == EAGAIN) |
866 | { | 834 | { |
867 | qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." ); | 835 | qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." ); |
868 | #if 0 | 836 | #if 0 |
869 | if ( qApp ) | 837 | if ( qApp ) |
870 | { | 838 | { |
871 | qApp->processEvents( 100 ); | 839 | qApp->processEvents( 100 ); |
872 | continue; | 840 | continue; |
873 | } | 841 | } |
874 | #endif | 842 | #endif |
875 | tv.tv_sec = 0; | 843 | tv.tv_sec = 0; |
876 | tv.tv_usec = 100000; | 844 | tv.tv_usec = 100000; |
877 | continue; | 845 | continue; |
878 | } | 846 | } |
879 | } | 847 | } |
880 | 848 | ||
881 | qDebug( "ONetworkInterface::scanNetwork() - scan finished." ); | 849 | qDebug( "ONetworkInterface::scanNetwork() - scan finished." ); |
882 | 850 | ||
883 | if ( results ) | 851 | if ( results ) |
884 | { | 852 | { |
885 | qDebug( " - result length = %d", _iwr.u.data.length ); | 853 | qDebug( " - result length = %d", _iwr.u.data.length ); |
886 | if ( !_iwr.u.data.length ) | 854 | if ( !_iwr.u.data.length ) |
887 | { | 855 | { |
888 | qDebug( " - no results (empty neighbourhood)" ); | 856 | qDebug( " - no results (empty neighbourhood)" ); |
889 | return 0; | 857 | return stations; |
890 | } | 858 | } |
891 | 859 | ||
892 | qDebug( " - results are in!" ); | 860 | qDebug( " - results are in!" ); |
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 | ||
899 | int offset = 0; | 865 | int offset = 0; |
900 | struct iw_event* we = (struct iw_event*) &buffer[0]; | 866 | struct iw_event* we = (struct iw_event*) &buffer[0]; |
901 | 867 | ||
902 | while ( offset < _iwr.u.data.length ) | 868 | while ( offset < _iwr.u.data.length ) |
903 | { | 869 | { |
904 | //const char* cmd = *(*_ioctlmap)[we->cmd]; | 870 | //const char* cmd = *(*_ioctlmap)[we->cmd]; |
905 | //if ( !cmd ) cmd = "<unknown>"; | 871 | //if ( !cmd ) cmd = "<unknown>"; |
906 | qDebug( "reading next event... cmd=%d, len=%d", we->cmd, we->len ); | 872 | qDebug( "reading next event... cmd=%d, len=%d", we->cmd, we->len ); |
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; |
915 | case IWEVTXDROP: qDebug( "IWEVTXDROP" ); break; /* Packet dropped to excessive retry */ | 902 | case IWEVTXDROP: qDebug( "IWEVTXDROP" ); break; /* Packet dropped to excessive retry */ |
916 | case IWEVQUAL: qDebug( "IWEVQUAL" ); break; /* Quality part of statistics (scan) */ | 903 | case IWEVQUAL: qDebug( "IWEVQUAL" ); break; /* Quality part of statistics (scan) */ |
917 | case IWEVCUSTOM: qDebug( "IWEVCUSTOM" ); break; /* Driver specific ascii string */ | 904 | case IWEVCUSTOM: qDebug( "IWEVCUSTOM" ); break; /* Driver specific ascii string */ |
918 | case IWEVREGISTERED: qDebug( "IWEVREGISTERED" ); break; /* Discovered a new node (AP mode) */ | 905 | case IWEVREGISTERED: qDebug( "IWEVREGISTERED" ); break; /* Discovered a new node (AP mode) */ |
919 | case IWEVEXPIRED: qDebug( "IWEVEXPIRED" ); break; /* Expired a node (AP mode) */ | 906 | case IWEVEXPIRED: qDebug( "IWEVEXPIRED" ); break; /* Expired a node (AP mode) */ |
920 | default: qDebug( "unhandled event" ); | 907 | default: qDebug( "unhandled event" ); |
921 | } | 908 | } |
922 | 909 | ||
923 | offset += we->len; | 910 | offset += we->len; |
924 | we = (struct iw_event*) &buffer[offset]; | 911 | we = (struct iw_event*) &buffer[offset]; |
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 | } |
934 | 923 | ||
935 | 924 | ||
936 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 925 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
937 | { | 926 | { |
938 | #ifndef NODEBUG | 927 | #ifndef NODEBUG |
939 | int result = ::ioctl( _sfd, call, &iwreq ); | 928 | int result = ::ioctl( _sfd, call, &iwreq ); |
940 | if ( result == -1 ) | 929 | if ( result == -1 ) |
941 | qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) *(*_ioctlmap)[call], call, result, strerror( errno ) ); | 930 | qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) *(*_ioctlmap)[call], call, result, strerror( errno ) ); |
942 | else | 931 | else |
943 | qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) *(*_ioctlmap)[call], call ); | 932 | qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) *(*_ioctlmap)[call], call ); |
944 | return ( result != -1 ); | 933 | return ( result != -1 ); |
945 | #else | 934 | #else |
946 | return ::ioctl( _sfd, call, &iwreq ) != -1; | 935 | return ::ioctl( _sfd, call, &iwreq ) != -1; |
947 | #endif | 936 | #endif |
948 | } | 937 | } |
949 | 938 | ||
950 | 939 | ||
951 | bool OWirelessNetworkInterface::wioctl( int call ) const | 940 | bool OWirelessNetworkInterface::wioctl( int call ) const |
952 | { | 941 | { |
953 | strcpy( _iwr.ifr_name, name() ); | 942 | strcpy( _iwr.ifr_name, name() ); |
954 | return wioctl( call, _iwr ); | 943 | return wioctl( call, _iwr ); |
955 | } | 944 | } |
956 | 945 | ||
957 | 946 | ||
958 | /*====================================================================================== | 947 | /*====================================================================================== |
959 | * OMonitoringInterface | 948 | * OMonitoringInterface |
960 | *======================================================================================*/ | 949 | *======================================================================================*/ |
961 | 950 | ||
962 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 951 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
963 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) | 952 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) |
964 | { | 953 | { |
965 | } | 954 | } |
966 | 955 | ||
967 | 956 | ||
968 | OMonitoringInterface::~OMonitoringInterface() | 957 | OMonitoringInterface::~OMonitoringInterface() |
969 | { | 958 | { |
970 | } | 959 | } |
971 | 960 | ||
972 | 961 | ||
973 | void OMonitoringInterface::setChannel( int c ) | 962 | void OMonitoringInterface::setChannel( int c ) |
974 | { | 963 | { |
975 | // use standard WE channel switching protocol | 964 | // use standard WE channel switching protocol |
976 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 965 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
977 | _if->_iwr.u.freq.m = c; | 966 | _if->_iwr.u.freq.m = c; |
978 | _if->_iwr.u.freq.e = 0; | 967 | _if->_iwr.u.freq.e = 0; |
979 | _if->wioctl( SIOCSIWFREQ ); | 968 | _if->wioctl( SIOCSIWFREQ ); |
980 | } | 969 | } |
981 | 970 | ||
982 | 971 | ||
983 | bool OMonitoringInterface::enabled() const | 972 | bool OMonitoringInterface::enabled() const |
984 | { | 973 | { |
985 | return _if->monitorMode(); | 974 | return _if->monitorMode(); |
986 | } | 975 | } |
987 | 976 | ||
988 | 977 | ||
989 | void OMonitoringInterface::setEnabled( bool b ) | 978 | void OMonitoringInterface::setEnabled( bool b ) |
990 | { | 979 | { |
991 | } | 980 | } |
992 | 981 | ||
993 | 982 | ||
994 | /*====================================================================================== | 983 | /*====================================================================================== |
995 | * OCiscoMonitoringInterface | 984 | * OCiscoMonitoringInterface |
996 | *======================================================================================*/ | 985 | *======================================================================================*/ |
997 | 986 | ||
998 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 987 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
999 | :OMonitoringInterface( iface, prismHeader ) | 988 | :OMonitoringInterface( iface, prismHeader ) |
1000 | { | 989 | { |
1001 | iface->setMonitoring( this ); | 990 | iface->setMonitoring( this ); |
1002 | } | 991 | } |
1003 | 992 | ||
1004 | 993 | ||
1005 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 994 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
1006 | { | 995 | { |
1007 | } | 996 | } |
1008 | 997 | ||
1009 | 998 | ||
1010 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 999 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
1011 | { | 1000 | { |
1012 | QString fname; | 1001 | QString fname; |
1013 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 1002 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
1014 | QFile f( fname ); | 1003 | QFile f( fname ); |
1015 | if ( !f.exists() ) return; | 1004 | if ( !f.exists() ) return; |
1016 | 1005 | ||
1017 | if ( f.open( IO_WriteOnly ) ) | 1006 | if ( f.open( IO_WriteOnly ) ) |
1018 | { | 1007 | { |
1019 | QTextStream s( &f ); | 1008 | QTextStream s( &f ); |
1020 | s << "Mode: r"; | 1009 | s << "Mode: r"; |
1021 | s << "Mode: y"; | 1010 | s << "Mode: y"; |
1022 | s << "XmitPower: 1"; | 1011 | s << "XmitPower: 1"; |
1023 | } | 1012 | } |
1024 | 1013 | ||
1025 | // flushing and closing will be done automatically when f goes out of scope | 1014 | // flushing and closing will be done automatically when f goes out of scope |
1026 | } | 1015 | } |
1027 | 1016 | ||
1028 | 1017 | ||
1029 | QString OCiscoMonitoringInterface::name() const | 1018 | QString OCiscoMonitoringInterface::name() const |
1030 | { | 1019 | { |
1031 | return "cisco"; | 1020 | return "cisco"; |
1032 | } | 1021 | } |
1033 | 1022 | ||
1034 | 1023 | ||
1035 | void OCiscoMonitoringInterface::setChannel( int ) | 1024 | void OCiscoMonitoringInterface::setChannel( int ) |
1036 | { | 1025 | { |
1037 | // cisco devices automatically switch channels when in monitor mode | 1026 | // cisco devices automatically switch channels when in monitor mode |
1038 | } | 1027 | } |
1039 | 1028 | ||
1040 | 1029 | ||
1041 | /*====================================================================================== | 1030 | /*====================================================================================== |
1042 | * OWlanNGMonitoringInterface | 1031 | * OWlanNGMonitoringInterface |
1043 | *======================================================================================*/ | 1032 | *======================================================================================*/ |
1044 | 1033 | ||
1045 | 1034 | ||
1046 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1035 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1047 | :OMonitoringInterface( iface, prismHeader ) | 1036 | :OMonitoringInterface( iface, prismHeader ) |
1048 | { | 1037 | { |
1049 | iface->setMonitoring( this ); | 1038 | iface->setMonitoring( this ); |
1050 | } | 1039 | } |
1051 | 1040 | ||
1052 | 1041 | ||
1053 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 1042 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
1054 | { | 1043 | { |
1055 | } | 1044 | } |
1056 | 1045 | ||
1057 | 1046 | ||
1058 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 1047 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
1059 | { | 1048 | { |
1060 | //FIXME: do nothing if its already in the same mode | 1049 | //FIXME: do nothing if its already in the same mode |
1061 | 1050 | ||
1062 | QString enable = b ? "true" : "false"; | 1051 | QString enable = b ? "true" : "false"; |
1063 | QString prism = _prismHeader ? "true" : "false"; | 1052 | QString prism = _prismHeader ? "true" : "false"; |
1064 | QString cmd; | 1053 | QString cmd; |
1065 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 1054 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
1066 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); | 1055 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); |
1067 | system( cmd ); | 1056 | system( cmd ); |
1068 | } | 1057 | } |
1069 | 1058 | ||
1070 | 1059 | ||
1071 | QString OWlanNGMonitoringInterface::name() const | 1060 | QString OWlanNGMonitoringInterface::name() const |
1072 | { | 1061 | { |
1073 | return "wlan-ng"; | 1062 | return "wlan-ng"; |
1074 | } | 1063 | } |
1075 | 1064 | ||
1076 | 1065 | ||
1077 | void OWlanNGMonitoringInterface::setChannel( int c ) | 1066 | void OWlanNGMonitoringInterface::setChannel( int c ) |
1078 | { | 1067 | { |
1079 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. | 1068 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. |
1080 | 1069 | ||
1081 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; | 1070 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; |
1082 | QString prism = _prismHeader ? "true" : "false"; | 1071 | QString prism = _prismHeader ? "true" : "false"; |
1083 | QString cmd; | 1072 | QString cmd; |
1084 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 1073 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
1085 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); | 1074 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); |
1086 | system( cmd ); | 1075 | system( cmd ); |
1087 | } | 1076 | } |
1088 | 1077 | ||
1089 | 1078 | ||
1090 | /*====================================================================================== | 1079 | /*====================================================================================== |
1091 | * OHostAPMonitoringInterface | 1080 | * OHostAPMonitoringInterface |
1092 | *======================================================================================*/ | 1081 | *======================================================================================*/ |
1093 | 1082 | ||
1094 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1083 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1095 | :OMonitoringInterface( iface, prismHeader ) | 1084 | :OMonitoringInterface( iface, prismHeader ) |
1096 | { | 1085 | { |
1097 | iface->setMonitoring( this ); | 1086 | iface->setMonitoring( this ); |
1098 | } | 1087 | } |
1099 | 1088 | ||
1100 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 1089 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
1101 | { | 1090 | { |
1102 | } | 1091 | } |
1103 | 1092 | ||
1104 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 1093 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
1105 | { | 1094 | { |
1106 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 1095 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
1107 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 1096 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
1108 | 1097 | ||
1109 | #if WIRELESS_EXT > 14 | 1098 | #if WIRELESS_EXT > 14 |
1110 | if ( b ) | 1099 | if ( b ) |
1111 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header | 1100 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header |
1112 | else | 1101 | else |
1113 | _if->setMode( "managed" ); | 1102 | _if->setMode( "managed" ); |
1114 | #else | 1103 | #else |
1115 | int monitorCode = _prismHeader ? 1 : 2; | 1104 | int monitorCode = _prismHeader ? 1 : 2; |
1116 | if ( b ) | 1105 | if ( b ) |
1117 | { | 1106 | { |
1118 | _if->setPrivate( "monitor", 1, monitorCode ); | 1107 | _if->setPrivate( "monitor", 1, monitorCode ); |
1119 | } | 1108 | } |
1120 | else | 1109 | else |
1121 | { | 1110 | { |
1122 | _if->setPrivate( "monitor", 1, 0 ); | 1111 | _if->setPrivate( "monitor", 1, 0 ); |
1123 | } | 1112 | } |
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 | |||
@@ -1,543 +1,544 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 by the Wellenreiter team: | 3 | Copyright (C) 2003 by the Wellenreiter team: |
4 | Martin J. Muench <mjm@remote-exploit.org> | 4 | Martin J. Muench <mjm@remote-exploit.org> |
5 | Max Moser <mmo@remote-exploit.org | 5 | Max Moser <mmo@remote-exploit.org |
6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
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 | #ifndef ONETWORK_H | 34 | #ifndef ONETWORK_H |
35 | #define ONETWORK_H | 35 | #define ONETWORK_H |
36 | 36 | ||
37 | #include "wireless.h" | 37 | #include "wireless.h" |
38 | 38 | ||
39 | /* OPIE */ | 39 | /* OPIE */ |
40 | 40 | ||
41 | #include <opie2/onetutils.h> | 41 | #include <opie2/onetutils.h> |
42 | #include <opie2/ostation.h> | ||
42 | 43 | ||
43 | /* QT */ | 44 | /* QT */ |
44 | 45 | ||
45 | #include <qvaluelist.h> | 46 | #include <qvaluelist.h> |
46 | #include <qdict.h> | 47 | #include <qdict.h> |
47 | #include <qmap.h> | 48 | #include <qmap.h> |
48 | #include <qobject.h> | 49 | #include <qobject.h> |
49 | #include <qhostaddress.h> | 50 | #include <qhostaddress.h> |
50 | 51 | ||
51 | class ONetworkInterface; | 52 | class ONetworkInterface; |
52 | class OWirelessNetworkInterface; | 53 | class OWirelessNetworkInterface; |
53 | class OChannelHopper; | 54 | class OChannelHopper; |
54 | class OMonitoringInterface; | 55 | class OMonitoringInterface; |
55 | 56 | ||
56 | /*====================================================================================== | 57 | /*====================================================================================== |
57 | * ONetwork | 58 | * ONetwork |
58 | *======================================================================================*/ | 59 | *======================================================================================*/ |
59 | 60 | ||
60 | /** | 61 | /** |
61 | * @brief A container class for all network interfaces | 62 | * @brief A container class for all network interfaces |
62 | * | 63 | * |
63 | * This class provides access to all available network interfaces of your computer. | 64 | * This class provides access to all available network interfaces of your computer. |
64 | * | 65 | * |
65 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 66 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
66 | */ | 67 | */ |
67 | class ONetwork : public QObject | 68 | class ONetwork : public QObject |
68 | { | 69 | { |
69 | Q_OBJECT | 70 | Q_OBJECT |
70 | 71 | ||
71 | public: | 72 | public: |
72 | typedef QDict<ONetworkInterface> InterfaceMap; | 73 | typedef QDict<ONetworkInterface> InterfaceMap; |
73 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; | 74 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; |
74 | 75 | ||
75 | public: | 76 | public: |
76 | /** | 77 | /** |
77 | * @returns the number of available interfaces | 78 | * @returns the number of available interfaces |
78 | */ | 79 | */ |
79 | int count() const; | 80 | int count() const; |
80 | /** | 81 | /** |
81 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 82 | * @returns a pointer to the (one and only) @ref ONetwork instance. |
82 | */ | 83 | */ |
83 | static ONetwork* instance(); | 84 | static ONetwork* instance(); |
84 | /** | 85 | /** |
85 | * @returns an iterator usable for iterating through all network interfaces. | 86 | * @returns an iterator usable for iterating through all network interfaces. |
86 | */ | 87 | */ |
87 | InterfaceIterator iterator() const; | 88 | InterfaceIterator iterator() const; |
88 | /** | 89 | /** |
89 | * @returns true, if the @a interface supports the wireless extension protocol. | 90 | * @returns true, if the @a interface supports the wireless extension protocol. |
90 | */ | 91 | */ |
91 | bool isWirelessInterface( const char* interface ) const; | 92 | bool isWirelessInterface( const char* interface ) const; |
92 | /** | 93 | /** |
93 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. | 94 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. |
94 | * @see ONetworkInterface | 95 | * @see ONetworkInterface |
95 | */ | 96 | */ |
96 | ONetworkInterface* interface( const QString& interface ) const; | 97 | ONetworkInterface* interface( const QString& interface ) const; |
97 | /** | 98 | /** |
98 | * @internal Rebuild the internal interface database | 99 | * @internal Rebuild the internal interface database |
99 | * @note Sometimes it might be useful to call this from client code, | 100 | * @note Sometimes it might be useful to call this from client code, |
100 | * e.g. after issuing a cardctl insert | 101 | * e.g. after issuing a cardctl insert |
101 | */ | 102 | */ |
102 | void synchronize(); | 103 | void synchronize(); |
103 | /** | 104 | /** |
104 | * @returns the wireless extension version used at compile time. | 105 | * @returns the wireless extension version used at compile time. |
105 | **/ | 106 | **/ |
106 | static short wirelessExtensionVersion(); | 107 | static short wirelessExtensionVersion(); |
107 | 108 | ||
108 | protected: | 109 | protected: |
109 | ONetwork(); | 110 | ONetwork(); |
110 | 111 | ||
111 | private: | 112 | private: |
112 | static ONetwork* _instance; | 113 | static ONetwork* _instance; |
113 | InterfaceMap _interfaces; | 114 | InterfaceMap _interfaces; |
114 | }; | 115 | }; |
115 | 116 | ||
116 | 117 | ||
117 | /*====================================================================================== | 118 | /*====================================================================================== |
118 | * ONetworkInterface | 119 | * ONetworkInterface |
119 | *======================================================================================*/ | 120 | *======================================================================================*/ |
120 | 121 | ||
121 | /** | 122 | /** |
122 | * @brief A network interface wrapper. | 123 | * @brief A network interface wrapper. |
123 | * | 124 | * |
124 | * This class provides a wrapper for a network interface. All the cumbersume details of | 125 | * This class provides a wrapper for a network interface. All the cumbersume details of |
125 | * Linux ioctls are hidden under a convenient high-level interface. | 126 | * Linux ioctls are hidden under a convenient high-level interface. |
126 | * @warning Most of the setting methods contained in this class require the appropriate | 127 | * @warning Most of the setting methods contained in this class require the appropriate |
127 | * process permissions to work. | 128 | * process permissions to work. |
128 | * | 129 | * |
129 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 130 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
130 | */ | 131 | */ |
131 | class ONetworkInterface : public QObject | 132 | class ONetworkInterface : public QObject |
132 | { | 133 | { |
133 | friend class OMonitoringInterface; | 134 | friend class OMonitoringInterface; |
134 | friend class OCiscoMonitoringInterface; | 135 | friend class OCiscoMonitoringInterface; |
135 | friend class OWlanNGMonitoringInterface; | 136 | friend class OWlanNGMonitoringInterface; |
136 | friend class OHostAPMonitoringInterface; | 137 | friend class OHostAPMonitoringInterface; |
137 | friend class OOrinocoMonitoringInterface; | 138 | friend class OOrinocoMonitoringInterface; |
138 | 139 | ||
139 | public: | 140 | public: |
140 | /** | 141 | /** |
141 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, | 142 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, |
142 | * but access them via @ref ONetwork::interface(). | 143 | * but access them via @ref ONetwork::interface(). |
143 | */ | 144 | */ |
144 | ONetworkInterface( QObject* parent, const char* name ); | 145 | ONetworkInterface( QObject* parent, const char* name ); |
145 | /** | 146 | /** |
146 | * Destructor. | 147 | * Destructor. |
147 | */ | 148 | */ |
148 | virtual ~ONetworkInterface(); | 149 | virtual ~ONetworkInterface(); |
149 | /** | 150 | /** |
150 | * Associates a @a monitoring interface with this network interface. | 151 | * Associates a @a monitoring interface with this network interface. |
151 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. | 152 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. |
152 | */ | 153 | */ |
153 | void setMonitoring( OMonitoringInterface* monitoring ); | 154 | void setMonitoring( OMonitoringInterface* monitoring ); |
154 | /** | 155 | /** |
155 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. | 156 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. |
156 | */ | 157 | */ |
157 | OMonitoringInterface* monitoring() const; | 158 | OMonitoringInterface* monitoring() const; |
158 | /** | 159 | /** |
159 | * Setting an interface to promiscuous mode enables the device to receive | 160 | * Setting an interface to promiscuous mode enables the device to receive |
160 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. | 161 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. |
161 | */ | 162 | */ |
162 | bool setPromiscuousMode( bool ); | 163 | bool setPromiscuousMode( bool ); |
163 | /** | 164 | /** |
164 | * @returns true if the interface is set to promiscuous mode. | 165 | * @returns true if the interface is set to promiscuous mode. |
165 | */ | 166 | */ |
166 | bool promiscuousMode() const; | 167 | bool promiscuousMode() const; |
167 | /** | 168 | /** |
168 | * Setting an interface to up enables it to receive packets. | 169 | * Setting an interface to up enables it to receive packets. |
169 | */ | 170 | */ |
170 | bool setUp( bool ); | 171 | bool setUp( bool ); |
171 | /** | 172 | /** |
172 | * @returns true if the interface is up. | 173 | * @returns true if the interface is up. |
173 | */ | 174 | */ |
174 | bool isUp() const; | 175 | bool isUp() const; |
175 | /** | 176 | /** |
176 | * @returns true if the interface is a loopback interface. | 177 | * @returns true if the interface is a loopback interface. |
177 | */ | 178 | */ |
178 | bool isLoopback() const; | 179 | bool isLoopback() const; |
179 | /** | 180 | /** |
180 | * @returns true if the interface is featuring supports the wireless extension protocol. | 181 | * @returns true if the interface is featuring supports the wireless extension protocol. |
181 | */ | 182 | */ |
182 | bool isWireless() const; | 183 | bool isWireless() const; |
183 | /** | 184 | /** |
184 | * Associate the IP address @ addr with the interface. | 185 | * Associate the IP address @ addr with the interface. |
185 | */ | 186 | */ |
186 | void setIPV4Address( const QHostAddress& addr ); | 187 | void setIPV4Address( const QHostAddress& addr ); |
187 | /** | 188 | /** |
188 | * @returns the IPv4 address associated with the interface. | 189 | * @returns the IPv4 address associated with the interface. |
189 | */ | 190 | */ |
190 | QString ipV4Address() const; //TODO: make this return an OHostAddress | 191 | QString ipV4Address() const; //TODO: make this return an OHostAddress |
191 | /** | 192 | /** |
192 | * Associate the MAC address @a addr with the interface. | 193 | * Associate the MAC address @a addr with the interface. |
193 | * @note It can be necessary to shut down the interface prior to calling this method. | 194 | * @note It can be necessary to shut down the interface prior to calling this method. |
194 | * @warning This is not supported by all drivers. | 195 | * @warning This is not supported by all drivers. |
195 | */ | 196 | */ |
196 | void setMacAddress( const OMacAddress& addr ); | 197 | void setMacAddress( const OMacAddress& addr ); |
197 | /** | 198 | /** |
198 | * @returns the MAC address associated with the interface. | 199 | * @returns the MAC address associated with the interface. |
199 | */ | 200 | */ |
200 | OMacAddress macAddress() const; | 201 | OMacAddress macAddress() const; |
201 | /** | 202 | /** |
202 | * Associate the IPv4 @a netmask with the interface. | 203 | * Associate the IPv4 @a netmask with the interface. |
203 | */ | 204 | */ |
204 | void setIPV4Netmask( const QHostAddress& netmask ); | 205 | void setIPV4Netmask( const QHostAddress& netmask ); |
205 | /** | 206 | /** |
206 | * @returns the IPv4 netmask associated with the interface. | 207 | * @returns the IPv4 netmask associated with the interface. |
207 | */ | 208 | */ |
208 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress | 209 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress |
209 | /** | 210 | /** |
210 | * @returns the data link type currently associated with the interface. | 211 | * @returns the data link type currently associated with the interface. |
211 | * @see #include <net/if_arp.h> for possible values. | 212 | * @see #include <net/if_arp.h> for possible values. |
212 | */ | 213 | */ |
213 | int dataLinkType() const; | 214 | int dataLinkType() const; |
214 | 215 | ||
215 | protected: | 216 | protected: |
216 | const int _sfd; | 217 | const int _sfd; |
217 | mutable ifreq _ifr; | 218 | mutable ifreq _ifr; |
218 | OMonitoringInterface* _mon; | 219 | OMonitoringInterface* _mon; |
219 | 220 | ||
220 | protected: | 221 | protected: |
221 | struct ifreq& ifr() const; | 222 | struct ifreq& ifr() const; |
222 | virtual void init(); | 223 | virtual void init(); |
223 | bool ioctl( int call ) const; | 224 | bool ioctl( int call ) const; |
224 | bool ioctl( int call, struct ifreq& ) const; | 225 | bool ioctl( int call, struct ifreq& ) const; |
225 | }; | 226 | }; |
226 | 227 | ||
227 | /*====================================================================================== | 228 | /*====================================================================================== |
228 | * OChannelHopper | 229 | * OChannelHopper |
229 | *======================================================================================*/ | 230 | *======================================================================================*/ |
230 | 231 | ||
231 | /** | 232 | /** |
232 | * @brief A radio frequency channel hopper. | 233 | * @brief A radio frequency channel hopper. |
233 | * | 234 | * |
234 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently | 235 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently |
235 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. | 236 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. |
236 | * This is necessary when in monitoring mode and scanning for other devices, because | 237 | * This is necessary when in monitoring mode and scanning for other devices, because |
237 | * the radio frequency hardware can only detect packets sent on the same frequency. | 238 | * the radio frequency hardware can only detect packets sent on the same frequency. |
238 | * | 239 | * |
239 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 240 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
240 | */ | 241 | */ |
241 | class OChannelHopper : public QObject | 242 | class OChannelHopper : public QObject |
242 | { | 243 | { |
243 | Q_OBJECT | 244 | Q_OBJECT |
244 | 245 | ||
245 | public: | 246 | public: |
246 | /** | 247 | /** |
247 | * Constructor. | 248 | * Constructor. |
248 | */ | 249 | */ |
249 | OChannelHopper( OWirelessNetworkInterface* ); | 250 | OChannelHopper( OWirelessNetworkInterface* ); |
250 | /** | 251 | /** |
251 | * Destructor. | 252 | * Destructor. |
252 | */ | 253 | */ |
253 | virtual ~OChannelHopper(); | 254 | virtual ~OChannelHopper(); |
254 | /** | 255 | /** |
255 | * @returns true, if the channel hopper is hopping channels | 256 | * @returns true, if the channel hopper is hopping channels |
256 | */ | 257 | */ |
257 | bool isActive() const; | 258 | bool isActive() const; |
258 | /** | 259 | /** |
259 | * @returns the last hopped channel | 260 | * @returns the last hopped channel |
260 | */ | 261 | */ |
261 | int channel() const; | 262 | int channel() const; |
262 | /** | 263 | /** |
263 | * Set the channel hopping @a interval. | 264 | * Set the channel hopping @a interval. |
264 | * An interval of 0 deactivates the channel hopper. | 265 | * An interval of 0 deactivates the channel hopper. |
265 | */ | 266 | */ |
266 | void setInterval( int interval ); | 267 | void setInterval( int interval ); |
267 | /** | 268 | /** |
268 | * @returns the channel hopping interval | 269 | * @returns the channel hopping interval |
269 | */ | 270 | */ |
270 | int interval() const; | 271 | int interval() const; |
271 | 272 | ||
272 | signals: | 273 | signals: |
273 | /** | 274 | /** |
274 | * This signal is emitted right after the channel hopper performed a hop | 275 | * This signal is emitted right after the channel hopper performed a hop |
275 | */ | 276 | */ |
276 | void hopped( int ); | 277 | void hopped( int ); |
277 | 278 | ||
278 | protected: | 279 | protected: |
279 | virtual void timerEvent( QTimerEvent* ); | 280 | virtual void timerEvent( QTimerEvent* ); |
280 | 281 | ||
281 | private: | 282 | private: |
282 | OWirelessNetworkInterface* _iface; | 283 | OWirelessNetworkInterface* _iface; |
283 | int _interval; | 284 | int _interval; |
284 | int _tid; | 285 | int _tid; |
285 | QValueList<int> _channels; | 286 | QValueList<int> _channels; |
286 | QValueList<int>::Iterator _channel; | 287 | QValueList<int>::Iterator _channel; |
287 | }; | 288 | }; |
288 | 289 | ||
289 | 290 | ||
290 | /*====================================================================================== | 291 | /*====================================================================================== |
291 | * OWirelessNetworkInterface | 292 | * OWirelessNetworkInterface |
292 | *======================================================================================*/ | 293 | *======================================================================================*/ |
293 | 294 | ||
294 | /** | 295 | /** |
295 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. | 296 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. |
296 | * | 297 | * |
297 | * This class provides a high-level encapsulation of the Linux wireless extension API. | 298 | * This class provides a high-level encapsulation of the Linux wireless extension API. |
298 | * | 299 | * |
299 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 300 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
300 | */ | 301 | */ |
301 | class OWirelessNetworkInterface : public ONetworkInterface | 302 | class OWirelessNetworkInterface : public ONetworkInterface |
302 | { | 303 | { |
303 | friend class OMonitoringInterface; | 304 | friend class OMonitoringInterface; |
304 | friend class OCiscoMonitoringInterface; | 305 | friend class OCiscoMonitoringInterface; |
305 | friend class OWlanNGMonitoringInterface; | 306 | friend class OWlanNGMonitoringInterface; |
306 | friend class OHostAPMonitoringInterface; | 307 | friend class OHostAPMonitoringInterface; |
307 | friend class OOrinocoMonitoringInterface; | 308 | friend class OOrinocoMonitoringInterface; |
308 | 309 | ||
309 | friend class OPrivateIOCTL; | 310 | friend class OPrivateIOCTL; |
310 | 311 | ||
311 | public: | 312 | public: |
312 | /** | 313 | /** |
313 | * Constructor. | 314 | * Constructor. |
314 | */ | 315 | */ |
315 | OWirelessNetworkInterface( QObject* parent, const char* name ); | 316 | OWirelessNetworkInterface( QObject* parent, const char* name ); |
316 | /** | 317 | /** |
317 | * Destructor. | 318 | * Destructor. |
318 | */ | 319 | */ |
319 | virtual ~OWirelessNetworkInterface(); | 320 | virtual ~OWirelessNetworkInterface(); |
320 | /** | 321 | /** |
321 | * Setting the @a channel of the interface changes the radio frequency (RF) | 322 | * Setting the @a channel of the interface changes the radio frequency (RF) |
322 | * of the corresponding wireless network device. | 323 | * of the corresponding wireless network device. |
323 | * @note Common channel range is within [1-14]. A value of 0 is not allowed. | 324 | * @note Common channel range is within [1-14]. A value of 0 is not allowed. |
324 | * @see channels() | 325 | * @see channels() |
325 | */ | 326 | */ |
326 | virtual void setChannel( int channel ) const; | 327 | virtual void setChannel( int channel ) const; |
327 | /** | 328 | /** |
328 | * @returns the channel index of the current radio frequency. | 329 | * @returns the channel index of the current radio frequency. |
329 | */ | 330 | */ |
330 | virtual int channel() const; | 331 | virtual int channel() const; |
331 | /** | 332 | /** |
332 | * @returns the current radio frequency (in MHz). | 333 | * @returns the current radio frequency (in MHz). |
333 | */ | 334 | */ |
334 | virtual double frequency() const; | 335 | virtual double frequency() const; |
335 | /** | 336 | /** |
336 | * @returns the number of radio frequency channels for the | 337 | * @returns the number of radio frequency channels for the |
337 | * corresponding wireless network device. | 338 | * corresponding wireless network device. |
338 | * @note European devices usually have 14 channels, while American typically feature 11 channels. | 339 | * @note European devices usually have 14 channels, while American typically feature 11 channels. |
339 | */ | 340 | */ |
340 | virtual int channels() const; | 341 | virtual int channels() const; |
341 | /** | 342 | /** |
342 | * Set the IEEE 802.11 operation @a mode. | 343 | * Set the IEEE 802.11 operation @a mode. |
343 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master | 344 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master |
344 | * @warning Not all drivers support the all modes. | 345 | * @warning Not all drivers support the all modes. |
345 | * @note You might have to change the SSID to get the operation mode change into effect. | 346 | * @note You might have to change the SSID to get the operation mode change into effect. |
346 | */ | 347 | */ |
347 | virtual void setMode( const QString& mode ); | 348 | virtual void setMode( const QString& mode ); |
348 | /** | 349 | /** |
349 | * @returns the current IEEE 802.11 operation mode. | 350 | * @returns the current IEEE 802.11 operation mode. |
350 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown | 351 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown |
351 | */ | 352 | */ |
352 | virtual QString mode() const; | 353 | virtual QString mode() const; |
353 | /** | 354 | /** |
354 | * Setting the monitor mode on a wireless network interface enables | 355 | * Setting the monitor mode on a wireless network interface enables |
355 | * listening to IEEE 802.11 data and management frames which normally | 356 | * listening to IEEE 802.11 data and management frames which normally |
356 | * are handled by the device firmware. This can be used to detect | 357 | * are handled by the device firmware. This can be used to detect |
357 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. | 358 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. |
358 | * @warning Standard wireless network drives don't support the monitor mode. | 359 | * @warning Standard wireless network drives don't support the monitor mode. |
359 | * @warning You need a patched driver for this to work. | 360 | * @warning You need a patched driver for this to work. |
360 | * @note Enabling the monitor mode is highly driver dependent and requires | 361 | * @note Enabling the monitor mode is highly driver dependent and requires |
361 | * the proper @ref OMonitoringInterface to be associated with the interface. | 362 | * the proper @ref OMonitoringInterface to be associated with the interface. |
362 | * @see OMonitoringInterface | 363 | * @see OMonitoringInterface |
363 | */ | 364 | */ |
364 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); Use IW_MONITOR first, if this doesn't work, then use iwpriv! | 365 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); Use IW_MONITOR first, if this doesn't work, then use iwpriv! |
365 | /** | 366 | /** |
366 | * @returns true if the device is listening in IEEE 802.11 monitor mode | 367 | * @returns true if the device is listening in IEEE 802.11 monitor mode |
367 | */ | 368 | */ |
368 | virtual bool monitorMode() const; //FIXME: ==> mode() | 369 | virtual bool monitorMode() const; //FIXME: ==> mode() |
369 | /** | 370 | /** |
370 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. | 371 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. |
371 | * @see OChannelHopper | 372 | * @see OChannelHopper |
372 | */ | 373 | */ |
373 | virtual void setChannelHopping( int interval = 0 ); | 374 | virtual void setChannelHopping( int interval = 0 ); |
374 | /** | 375 | /** |
375 | * @returns the channel hopping interval or 0, if channel hopping is disabled. | 376 | * @returns the channel hopping interval or 0, if channel hopping is disabled. |
376 | */ | 377 | */ |
377 | virtual int channelHopping() const; | 378 | virtual int channelHopping() const; |
378 | /** | 379 | /** |
379 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before | 380 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before |
380 | */ | 381 | */ |
381 | virtual OChannelHopper* channelHopper() const; | 382 | virtual OChannelHopper* channelHopper() const; |
382 | /** | 383 | /** |
383 | * Set the station @a nickname. | 384 | * Set the station @a nickname. |
384 | */ | 385 | */ |
385 | virtual void setNickName( const QString& nickname ); | 386 | virtual void setNickName( const QString& nickname ); |
386 | /** | 387 | /** |
387 | * @returns the current station nickname. | 388 | * @returns the current station nickname. |
388 | */ | 389 | */ |
389 | virtual QString nickName() const; | 390 | virtual QString nickName() const; |
390 | /** | 391 | /** |
391 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. | 392 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. |
392 | * @see OPrivateIOCTL | 393 | * @see OPrivateIOCTL |
393 | */ | 394 | */ |
394 | virtual void setPrivate( const QString& command, int number, ... ); | 395 | virtual void setPrivate( const QString& command, int number, ... ); |
395 | /** | 396 | /** |
396 | * @returns true if the interface is featuring the private IOCTL @command. | 397 | * @returns true if the interface is featuring the private IOCTL @command. |
397 | */ | 398 | */ |
398 | virtual bool hasPrivate( const QString& command ); | 399 | virtual bool hasPrivate( const QString& command ); |
399 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this | 400 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this |
400 | /** | 401 | /** |
401 | * @returns true if the interface is associated to an access point | 402 | * @returns true if the interface is associated to an access point |
402 | * @note: This information is only valid if the interface is in managed mode. | 403 | * @note: This information is only valid if the interface is in managed mode. |
403 | */ | 404 | */ |
404 | virtual bool isAssociated() const; | 405 | virtual bool isAssociated() const; |
405 | /** | 406 | /** |
406 | * @returns the MAC address of the Access Point if the device is in infrastructure mode. | 407 | * @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. | 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 |
412 | * which network to associate with (use "any" to let the driver decide). | 413 | * which network to associate with (use "any" to let the driver decide). |
413 | */ | 414 | */ |
414 | virtual void setSSID( const QString& ssid ); | 415 | virtual void setSSID( const QString& ssid ); |
415 | /** | 416 | /** |
416 | * @returns the current SSID (Service Set ID). | 417 | * @returns the current SSID (Service Set ID). |
417 | */ | 418 | */ |
418 | virtual QString SSID() const; | 419 | virtual QString SSID() const; |
419 | /** | 420 | /** |
420 | * Perform scanning the wireless network neighbourhood. | 421 | * Perform scanning the wireless network neighbourhood. |
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: |
426 | void buildInformation(); | 427 | void buildInformation(); |
427 | void buildPrivateList(); | 428 | void buildPrivateList(); |
428 | void dumpInformation() const; | 429 | void dumpInformation() const; |
429 | virtual void init(); | 430 | virtual void init(); |
430 | struct iwreq& iwr() const; | 431 | struct iwreq& iwr() const; |
431 | bool wioctl( int call ) const; | 432 | bool wioctl( int call ) const; |
432 | bool wioctl( int call, struct iwreq& ) const; | 433 | bool wioctl( int call, struct iwreq& ) const; |
433 | 434 | ||
434 | protected: | 435 | protected: |
435 | mutable struct iwreq _iwr; | 436 | mutable struct iwreq _iwr; |
436 | QMap<int,int> _channels; | 437 | QMap<int,int> _channels; |
437 | struct iw_range _range; | 438 | struct iw_range _range; |
438 | 439 | ||
439 | private: | 440 | private: |
440 | OChannelHopper* _hopper; | 441 | OChannelHopper* _hopper; |
441 | }; | 442 | }; |
442 | 443 | ||
443 | 444 | ||
444 | /*====================================================================================== | 445 | /*====================================================================================== |
445 | * OMonitoringInterface | 446 | * OMonitoringInterface |
446 | *======================================================================================*/ | 447 | *======================================================================================*/ |
447 | 448 | ||
448 | 449 | ||
449 | class OMonitoringInterface | 450 | class OMonitoringInterface |
450 | { | 451 | { |
451 | public: | 452 | public: |
452 | OMonitoringInterface(); | 453 | OMonitoringInterface(); |
453 | OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 454 | OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
454 | virtual ~OMonitoringInterface(); | 455 | virtual ~OMonitoringInterface(); |
455 | 456 | ||
456 | public: | 457 | public: |
457 | virtual void setEnabled( bool ); | 458 | virtual void setEnabled( bool ); |
458 | virtual bool enabled() const; | 459 | virtual bool enabled() const; |
459 | virtual void setChannel( int ); | 460 | virtual void setChannel( int ); |
460 | 461 | ||
461 | virtual QString name() const = 0; | 462 | virtual QString name() const = 0; |
462 | 463 | ||
463 | protected: | 464 | protected: |
464 | OWirelessNetworkInterface* _if; | 465 | OWirelessNetworkInterface* _if; |
465 | bool _prismHeader; | 466 | bool _prismHeader; |
466 | 467 | ||
467 | }; | 468 | }; |
468 | 469 | ||
469 | 470 | ||
470 | /*====================================================================================== | 471 | /*====================================================================================== |
471 | * OCiscoMonitoring | 472 | * OCiscoMonitoring |
472 | *======================================================================================*/ | 473 | *======================================================================================*/ |
473 | 474 | ||
474 | 475 | ||
475 | class OCiscoMonitoringInterface : public OMonitoringInterface | 476 | class OCiscoMonitoringInterface : public OMonitoringInterface |
476 | { | 477 | { |
477 | public: | 478 | public: |
478 | OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 479 | OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
479 | virtual ~OCiscoMonitoringInterface(); | 480 | virtual ~OCiscoMonitoringInterface(); |
480 | 481 | ||
481 | virtual void setEnabled( bool ); | 482 | virtual void setEnabled( bool ); |
482 | virtual QString name() const; | 483 | virtual QString name() const; |
483 | virtual void setChannel( int ); | 484 | virtual void setChannel( int ); |
484 | 485 | ||
485 | }; | 486 | }; |
486 | 487 | ||
487 | 488 | ||
488 | /*====================================================================================== | 489 | /*====================================================================================== |
489 | * OWlanNGMonitoringInterface | 490 | * OWlanNGMonitoringInterface |
490 | *======================================================================================*/ | 491 | *======================================================================================*/ |
491 | 492 | ||
492 | 493 | ||
493 | class OWlanNGMonitoringInterface : public OMonitoringInterface | 494 | class OWlanNGMonitoringInterface : public OMonitoringInterface |
494 | { | 495 | { |
495 | public: | 496 | public: |
496 | OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 497 | OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
497 | virtual ~OWlanNGMonitoringInterface(); | 498 | virtual ~OWlanNGMonitoringInterface(); |
498 | 499 | ||
499 | public: | 500 | public: |
500 | virtual void setEnabled( bool ); | 501 | virtual void setEnabled( bool ); |
501 | virtual QString name() const; | 502 | virtual QString name() const; |
502 | virtual void setChannel( int ); | 503 | virtual void setChannel( int ); |
503 | 504 | ||
504 | }; | 505 | }; |
505 | 506 | ||
506 | 507 | ||
507 | /*====================================================================================== | 508 | /*====================================================================================== |
508 | * OHostAPMonitoringInterface | 509 | * OHostAPMonitoringInterface |
509 | *======================================================================================*/ | 510 | *======================================================================================*/ |
510 | 511 | ||
511 | 512 | ||
512 | class OHostAPMonitoringInterface : public OMonitoringInterface | 513 | class OHostAPMonitoringInterface : public OMonitoringInterface |
513 | { | 514 | { |
514 | public: | 515 | public: |
515 | OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 516 | OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
516 | virtual ~OHostAPMonitoringInterface(); | 517 | virtual ~OHostAPMonitoringInterface(); |
517 | 518 | ||
518 | public: | 519 | public: |
519 | virtual void setEnabled( bool ); | 520 | virtual void setEnabled( bool ); |
520 | virtual QString name() const; | 521 | virtual QString name() const; |
521 | }; | 522 | }; |
522 | 523 | ||
523 | 524 | ||
524 | /*====================================================================================== | 525 | /*====================================================================================== |
525 | * OOrinocoMonitoringInterface | 526 | * OOrinocoMonitoringInterface |
526 | *======================================================================================*/ | 527 | *======================================================================================*/ |
527 | 528 | ||
528 | 529 | ||
529 | class OOrinocoMonitoringInterface : public OMonitoringInterface | 530 | class OOrinocoMonitoringInterface : public OMonitoringInterface |
530 | { | 531 | { |
531 | public: | 532 | public: |
532 | OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 533 | OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
533 | virtual ~OOrinocoMonitoringInterface(); | 534 | virtual ~OOrinocoMonitoringInterface(); |
534 | 535 | ||
535 | public: | 536 | public: |
536 | virtual void setChannel( int ); | 537 | virtual void setChannel( int ); |
537 | virtual void setEnabled( bool ); | 538 | virtual void setEnabled( bool ); |
538 | virtual QString name() const; | 539 | virtual QString name() const; |
539 | 540 | ||
540 | }; | 541 | }; |
541 | 542 | ||
542 | #endif // ONETWORK_H | 543 | #endif // ONETWORK_H |
543 | 544 | ||
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 | |||
@@ -1,49 +1,64 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <opie2/ostation.h> | 32 | #include <opie2/ostation.h> |
33 | 33 | ||
34 | /*====================================================================================== | 34 | /*====================================================================================== |
35 | * OStation | 35 | * OStation |
36 | *======================================================================================*/ | 36 | *======================================================================================*/ |
37 | 37 | ||
38 | OStation::OStation() | 38 | 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 | ||
43 | 50 | ||
44 | OStation::~OStation() | 51 | OStation::~OStation() |
45 | { | 52 | { |
46 | qDebug( "OStation::~OStation()" ); | 53 | qDebug( "OStation::~OStation()" ); |
47 | } | 54 | } |
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 | |||
@@ -1,67 +1,74 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #ifndef OSTATION_H | 32 | #ifndef OSTATION_H |
33 | #define OSTATION_H | 33 | #define OSTATION_H |
34 | 34 | ||
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> |
41 | #include <qobject.h> | 40 | #include <qobject.h> |
42 | 41 | ||
43 | #include <sys/types.h> | 42 | #include <sys/types.h> |
44 | 43 | ||
45 | class OStation; | 44 | class OStation; |
46 | 45 | ||
47 | typedef QDict<OStation> OStationDict; | 46 | typedef QList<OStation> OStationList; |
48 | 47 | ||
49 | /*====================================================================================== | 48 | /*====================================================================================== |
50 | * OStation | 49 | * OStation |
51 | *======================================================================================*/ | 50 | *======================================================================================*/ |
52 | 51 | ||
53 | class OStation | 52 | class OStation |
54 | { | 53 | { |
55 | public: | 54 | public: |
56 | OStation(); | 55 | 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 | ||