author | mickeyl <mickeyl> | 2003-04-04 13:45:49 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-04 13:45:49 (UTC) |
commit | b2153d44e64c1ade3ee141ea24075add1fd33777 (patch) (unidiff) | |
tree | 6164d2eeef1c0ee79fcf4da85f2c8ed88aa0ecb3 | |
parent | 089385bb8ab768fbf6f394f326e565e3589163fc (diff) | |
download | opie-b2153d44e64c1ade3ee141ea24075add1fd33777.zip opie-b2153d44e64c1ade3ee141ea24075add1fd33777.tar.gz opie-b2153d44e64c1ade3ee141ea24075add1fd33777.tar.bz2 |
reliable strategy to see if we're in monitor mode by looking at the MAC address family
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 55 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 2 |
2 files changed, 24 insertions, 33 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 789e8ca..6a363d7 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,925 +1,916 @@ | |||
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 | /* OPIE */ | 34 | /* OPIE */ |
35 | 35 | ||
36 | #include <opie2/onetwork.h> | 36 | #include <opie2/onetwork.h> |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | 39 | ||
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | 42 | ||
43 | /* UNIX */ | 43 | /* UNIX */ |
44 | 44 | ||
45 | #include <arpa/inet.h> | 45 | #include <arpa/inet.h> |
46 | #include <cerrno> | 46 | #include <cerrno> |
47 | #include <cstring> | 47 | #include <cstring> |
48 | #include <cstdlib> | 48 | #include <cstdlib> |
49 | #include <math.h> | 49 | #include <math.h> |
50 | #include <sys/ioctl.h> | 50 | #include <sys/ioctl.h> |
51 | #include <sys/socket.h> | 51 | #include <sys/socket.h> |
52 | #include <sys/types.h> | 52 | #include <sys/types.h> |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #include <linux/sockios.h> | 54 | #include <linux/sockios.h> |
55 | #include <net/if_arp.h> | ||
55 | #include <stdarg.h> | 56 | #include <stdarg.h> |
56 | 57 | ||
57 | using namespace std; | 58 | using namespace std; |
58 | 59 | ||
59 | /*====================================================================================== | 60 | /*====================================================================================== |
60 | * ONetwork | 61 | * ONetwork |
61 | *======================================================================================*/ | 62 | *======================================================================================*/ |
62 | 63 | ||
63 | ONetwork* ONetwork::_instance = 0; | 64 | ONetwork* ONetwork::_instance = 0; |
64 | 65 | ||
65 | ONetwork::ONetwork() | 66 | ONetwork::ONetwork() |
66 | { | 67 | { |
67 | qDebug( "ONetwork::ONetwork()" ); | 68 | qDebug( "ONetwork::ONetwork()" ); |
68 | synchronize(); | 69 | synchronize(); |
69 | } | 70 | } |
70 | 71 | ||
71 | void ONetwork::synchronize() | 72 | void ONetwork::synchronize() |
72 | { | 73 | { |
73 | // gather available interfaces by inspecting /proc/net/dev | 74 | // gather available interfaces by inspecting /proc/net/dev |
74 | // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 75 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
76 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | ||
75 | 77 | ||
76 | _interfaces.clear(); | 78 | _interfaces.clear(); |
77 | QString str; | 79 | QString str; |
78 | QFile f( "/proc/net/dev" ); | 80 | QFile f( "/proc/net/dev" ); |
79 | bool hasFile = f.open( IO_ReadOnly ); | 81 | bool hasFile = f.open( IO_ReadOnly ); |
80 | if ( !hasFile ) | 82 | if ( !hasFile ) |
81 | { | 83 | { |
82 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); | 84 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); |
83 | return; | 85 | return; |
84 | } | 86 | } |
85 | QTextStream s( &f ); | 87 | QTextStream s( &f ); |
86 | s.readLine(); | 88 | s.readLine(); |
87 | s.readLine(); | 89 | s.readLine(); |
88 | while ( !s.atEnd() ) | 90 | while ( !s.atEnd() ) |
89 | { | 91 | { |
90 | s >> str; | 92 | s >> str; |
91 | str.truncate( str.find( ':' ) ); | 93 | str.truncate( str.find( ':' ) ); |
92 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); | 94 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); |
93 | ONetworkInterface* iface; | 95 | ONetworkInterface* iface; |
94 | if ( isWirelessInterface( str ) ) | 96 | if ( isWirelessInterface( str ) ) |
95 | { | 97 | { |
96 | iface = new OWirelessNetworkInterface( this, str ); | 98 | iface = new OWirelessNetworkInterface( this, str ); |
97 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 99 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); |
98 | } | 100 | } |
99 | else | 101 | else |
100 | { | 102 | { |
101 | iface = new ONetworkInterface( this, str ); | 103 | iface = new ONetworkInterface( this, str ); |
102 | } | 104 | } |
103 | _interfaces.insert( str, iface ); | 105 | _interfaces.insert( str, iface ); |
104 | s.readLine(); | 106 | s.readLine(); |
105 | } | 107 | } |
106 | } | 108 | } |
107 | 109 | ||
108 | 110 | ||
109 | ONetworkInterface* ONetwork::interface( QString iface ) const | 111 | ONetworkInterface* ONetwork::interface( QString iface ) const |
110 | { | 112 | { |
111 | return _interfaces[iface]; | 113 | return _interfaces[iface]; |
112 | } | 114 | } |
113 | 115 | ||
114 | 116 | ||
115 | ONetwork* ONetwork::instance() | 117 | ONetwork* ONetwork::instance() |
116 | { | 118 | { |
117 | if ( !_instance ) _instance = new ONetwork(); | 119 | if ( !_instance ) _instance = new ONetwork(); |
118 | return _instance; | 120 | return _instance; |
119 | } | 121 | } |
120 | 122 | ||
121 | 123 | ||
122 | ONetwork::InterfaceIterator ONetwork::iterator() const | 124 | ONetwork::InterfaceIterator ONetwork::iterator() const |
123 | { | 125 | { |
124 | return ONetwork::InterfaceIterator( _interfaces ); | 126 | return ONetwork::InterfaceIterator( _interfaces ); |
125 | } | 127 | } |
126 | 128 | ||
127 | 129 | ||
128 | bool ONetwork::isWirelessInterface( const char* name ) const | 130 | bool ONetwork::isWirelessInterface( const char* name ) const |
129 | { | 131 | { |
130 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 132 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
131 | struct iwreq iwr; | 133 | struct iwreq iwr; |
132 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 134 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
133 | strcpy( (char*) &iwr.ifr_name, name ); | 135 | strcpy( (char*) &iwr.ifr_name, name ); |
134 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 136 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
135 | if ( result == -1 ) | 137 | return result != -1; |
136 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); | ||
137 | else | ||
138 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); | ||
139 | return ( result != -1 ); | ||
140 | } | 138 | } |
141 | 139 | ||
142 | /*====================================================================================== | 140 | /*====================================================================================== |
143 | * ONetworkInterface | 141 | * ONetworkInterface |
144 | *======================================================================================*/ | 142 | *======================================================================================*/ |
145 | 143 | ||
146 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 144 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
147 | :QObject( parent, name ), | 145 | :QObject( parent, name ), |
148 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 146 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
149 | { | 147 | { |
150 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 148 | qDebug( "ONetworkInterface::ONetworkInterface()" ); |
151 | init(); | 149 | init(); |
152 | } | 150 | } |
153 | 151 | ||
154 | 152 | ||
155 | struct ifreq& ONetworkInterface::ifr() const | 153 | struct ifreq& ONetworkInterface::ifr() const |
156 | { | 154 | { |
157 | return _ifr; | 155 | return _ifr; |
158 | } | 156 | } |
159 | 157 | ||
160 | 158 | ||
161 | void ONetworkInterface::init() | 159 | void ONetworkInterface::init() |
162 | { | 160 | { |
163 | qDebug( "ONetworkInterface::init()" ); | 161 | qDebug( "ONetworkInterface::init()" ); |
164 | 162 | ||
165 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 163 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
166 | 164 | ||
167 | if ( _sfd == -1 ) | 165 | if ( _sfd == -1 ) |
168 | { | 166 | { |
169 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); | 167 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); |
170 | return; | 168 | return; |
171 | } | 169 | } |
172 | } | 170 | } |
173 | 171 | ||
174 | 172 | ||
175 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 173 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
176 | { | 174 | { |
177 | int result = ::ioctl( _sfd, call, &ifreq ); | 175 | int result = ::ioctl( _sfd, call, &ifreq ); |
178 | if ( result == -1 ) | 176 | if ( result == -1 ) |
179 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); | 177 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); |
180 | else | 178 | else |
181 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); | 179 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); |
182 | return ( result != -1 ); | 180 | return ( result != -1 ); |
183 | } | 181 | } |
184 | 182 | ||
185 | 183 | ||
186 | bool ONetworkInterface::ioctl( int call ) const | 184 | bool ONetworkInterface::ioctl( int call ) const |
187 | { | 185 | { |
188 | strcpy( _ifr.ifr_name, name() ); | 186 | strcpy( _ifr.ifr_name, name() ); |
189 | return ioctl( call, _ifr ); | 187 | return ioctl( call, _ifr ); |
190 | } | 188 | } |
191 | 189 | ||
192 | 190 | ||
193 | bool ONetworkInterface::isLoopback() const | 191 | bool ONetworkInterface::isLoopback() const |
194 | { | 192 | { |
195 | ioctl( SIOCGIFFLAGS ); | 193 | ioctl( SIOCGIFFLAGS ); |
196 | return _ifr.ifr_flags & IFF_LOOPBACK; | 194 | return _ifr.ifr_flags & IFF_LOOPBACK; |
197 | } | 195 | } |
198 | 196 | ||
199 | 197 | ||
200 | bool ONetworkInterface::setUp( bool b ) | 198 | bool ONetworkInterface::setUp( bool b ) |
201 | { | 199 | { |
202 | ioctl( SIOCGIFFLAGS ); | 200 | ioctl( SIOCGIFFLAGS ); |
203 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 201 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
204 | else _ifr.ifr_flags &= (~IFF_UP); | 202 | else _ifr.ifr_flags &= (~IFF_UP); |
205 | return ioctl( SIOCSIFFLAGS ); | 203 | return ioctl( SIOCSIFFLAGS ); |
206 | } | 204 | } |
207 | 205 | ||
208 | 206 | ||
209 | bool ONetworkInterface::isUp() const | 207 | bool ONetworkInterface::isUp() const |
210 | { | 208 | { |
211 | ioctl( SIOCGIFFLAGS ); | 209 | ioctl( SIOCGIFFLAGS ); |
212 | return _ifr.ifr_flags & IFF_UP; | 210 | return _ifr.ifr_flags & IFF_UP; |
213 | } | 211 | } |
214 | 212 | ||
215 | 213 | ||
216 | QString ONetworkInterface::ipV4Address() const | 214 | QString ONetworkInterface::ipV4Address() const |
217 | { | 215 | { |
218 | if ( ioctl( SIOCGIFADDR ) ) | 216 | if ( ioctl( SIOCGIFADDR ) ) |
219 | { | 217 | { |
220 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 218 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
221 | //FIXME: Use QHostAddress here | 219 | //FIXME: Use QHostAddress here |
222 | return QString( inet_ntoa( sa->sin_addr ) ); | 220 | return QString( inet_ntoa( sa->sin_addr ) ); |
223 | } | 221 | } |
224 | else | 222 | else |
225 | return "<unknown>"; | 223 | return "<unknown>"; |
226 | } | 224 | } |
227 | 225 | ||
228 | 226 | ||
229 | OMacAddress ONetworkInterface::macAddress() const | 227 | OMacAddress ONetworkInterface::macAddress() const |
230 | { | 228 | { |
231 | if ( ioctl( SIOCGIFHWADDR ) ) | 229 | if ( ioctl( SIOCGIFHWADDR ) ) |
232 | { | 230 | { |
233 | return OMacAddress( _ifr ); | 231 | return OMacAddress( _ifr ); |
234 | } | 232 | } |
235 | else | 233 | else |
236 | { | 234 | { |
237 | return OMacAddress::unknown; | 235 | return OMacAddress::unknown; |
238 | } | 236 | } |
239 | } | 237 | } |
240 | 238 | ||
241 | 239 | ||
240 | int ONetworkInterface::dataLinkType() const | ||
241 | { | ||
242 | if ( ioctl( SIOCGIFHWADDR ) ) | ||
243 | { | ||
244 | return _ifr.ifr_hwaddr.sa_family; | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | return -1; | ||
249 | } | ||
250 | } | ||
251 | |||
252 | |||
242 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 253 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
243 | { | 254 | { |
244 | _mon = m; | 255 | _mon = m; |
245 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); | 256 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); |
246 | } | 257 | } |
247 | 258 | ||
248 | 259 | ||
249 | OMonitoringInterface* ONetworkInterface::monitoring() const | 260 | OMonitoringInterface* ONetworkInterface::monitoring() const |
250 | { | 261 | { |
251 | return _mon; | 262 | return _mon; |
252 | } | 263 | } |
253 | 264 | ||
254 | 265 | ||
255 | ONetworkInterface::~ONetworkInterface() | 266 | ONetworkInterface::~ONetworkInterface() |
256 | { | 267 | { |
257 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); | 268 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); |
258 | if ( _sfd != -1 ) ::close( _sfd ); | 269 | if ( _sfd != -1 ) ::close( _sfd ); |
259 | } | 270 | } |
260 | 271 | ||
261 | 272 | ||
262 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 273 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
263 | { | 274 | { |
264 | ioctl( SIOCGIFFLAGS ); | 275 | ioctl( SIOCGIFFLAGS ); |
265 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 276 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
266 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 277 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
267 | return ioctl( SIOCSIFFLAGS ); | 278 | return ioctl( SIOCSIFFLAGS ); |
268 | } | 279 | } |
269 | 280 | ||
270 | 281 | ||
271 | bool ONetworkInterface::promiscuousMode() const | 282 | bool ONetworkInterface::promiscuousMode() const |
272 | { | 283 | { |
273 | ioctl( SIOCGIFFLAGS ); | 284 | ioctl( SIOCGIFFLAGS ); |
274 | return _ifr.ifr_flags & IFF_PROMISC; | 285 | return _ifr.ifr_flags & IFF_PROMISC; |
275 | } | 286 | } |
276 | 287 | ||
277 | 288 | ||
278 | bool ONetworkInterface::isWireless() const | 289 | bool ONetworkInterface::isWireless() const |
279 | { | 290 | { |
280 | return ioctl( SIOCGIWNAME ); | 291 | return ioctl( SIOCGIWNAME ); |
281 | } | 292 | } |
282 | 293 | ||
283 | 294 | ||
284 | /*====================================================================================== | 295 | /*====================================================================================== |
285 | * OChannelHopper | 296 | * OChannelHopper |
286 | *======================================================================================*/ | 297 | *======================================================================================*/ |
287 | 298 | ||
288 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 299 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
289 | :QObject( 0, "Mickey's funky hopper" ), | 300 | :QObject( 0, "Mickey's funky hopper" ), |
290 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 301 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
291 | { | 302 | { |
292 | int _maxChannel = iface->channels()+1; | 303 | int _maxChannel = iface->channels()+1; |
293 | // generate fancy hopping sequence honoring the device capabilities | 304 | // generate fancy hopping sequence honoring the device capabilities |
294 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 305 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
295 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 306 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
296 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 307 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
297 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 308 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
298 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 309 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
299 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 310 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
300 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 311 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
301 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 312 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
302 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 313 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
303 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 314 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
304 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 315 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
305 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 316 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
306 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 317 | if ( _maxChannel >= 6 ) _channels.append( 6 ); |
307 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 318 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
308 | _channel = _channels.begin(); | 319 | _channel = _channels.begin(); |
309 | 320 | ||
310 | } | 321 | } |
311 | 322 | ||
312 | 323 | ||
313 | OChannelHopper::~OChannelHopper() | 324 | OChannelHopper::~OChannelHopper() |
314 | { | 325 | { |
315 | } | 326 | } |
316 | 327 | ||
317 | 328 | ||
318 | bool OChannelHopper::isActive() const | 329 | bool OChannelHopper::isActive() const |
319 | { | 330 | { |
320 | return _tid; | 331 | return _tid; |
321 | } | 332 | } |
322 | 333 | ||
323 | 334 | ||
324 | int OChannelHopper::channel() const | 335 | int OChannelHopper::channel() const |
325 | { | 336 | { |
326 | return *_channel; | 337 | return *_channel; |
327 | } | 338 | } |
328 | 339 | ||
329 | 340 | ||
330 | void OChannelHopper::timerEvent( QTimerEvent* ) | 341 | void OChannelHopper::timerEvent( QTimerEvent* ) |
331 | { | 342 | { |
332 | _iface->setChannel( *_channel ); | 343 | _iface->setChannel( *_channel ); |
333 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 344 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", |
334 | *_channel, (const char*) _iface->name() ); | 345 | *_channel, (const char*) _iface->name() ); |
335 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 346 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
336 | } | 347 | } |
337 | 348 | ||
338 | 349 | ||
339 | void OChannelHopper::setInterval( int interval ) | 350 | void OChannelHopper::setInterval( int interval ) |
340 | { | 351 | { |
341 | if ( interval == _interval ) | 352 | if ( interval == _interval ) |
342 | return; | 353 | return; |
343 | 354 | ||
344 | if ( _interval ) | 355 | if ( _interval ) |
345 | killTimer( _tid ); | 356 | killTimer( _tid ); |
346 | 357 | ||
347 | _tid = 0; | 358 | _tid = 0; |
348 | _interval = interval; | 359 | _interval = interval; |
349 | 360 | ||
350 | if ( _interval ) | 361 | if ( _interval ) |
351 | { | 362 | { |
352 | _tid = startTimer( interval ); | 363 | _tid = startTimer( interval ); |
353 | } | 364 | } |
354 | } | 365 | } |
355 | 366 | ||
356 | 367 | ||
357 | int OChannelHopper::interval() const | 368 | int OChannelHopper::interval() const |
358 | { | 369 | { |
359 | return _interval; | 370 | return _interval; |
360 | } | 371 | } |
361 | 372 | ||
362 | 373 | ||
363 | /*====================================================================================== | 374 | /*====================================================================================== |
364 | * OWirelessNetworkInterface | 375 | * OWirelessNetworkInterface |
365 | *======================================================================================*/ | 376 | *======================================================================================*/ |
366 | 377 | ||
367 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 378 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
368 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 379 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
369 | { | 380 | { |
370 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 381 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); |
371 | init(); | 382 | init(); |
372 | } | 383 | } |
373 | 384 | ||
374 | 385 | ||
375 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 386 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
376 | { | 387 | { |
377 | } | 388 | } |
378 | 389 | ||
379 | 390 | ||
380 | struct iwreq& OWirelessNetworkInterface::iwr() const | 391 | struct iwreq& OWirelessNetworkInterface::iwr() const |
381 | { | 392 | { |
382 | return _iwr; | 393 | return _iwr; |
383 | } | 394 | } |
384 | 395 | ||
385 | 396 | ||
386 | void OWirelessNetworkInterface::init() | 397 | void OWirelessNetworkInterface::init() |
387 | { | 398 | { |
388 | qDebug( "OWirelessNetworkInterface::init()" ); | 399 | qDebug( "OWirelessNetworkInterface::init()" ); |
389 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 400 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
390 | buildChannelList(); | 401 | buildChannelList(); |
391 | buildPrivateList(); | 402 | buildPrivateList(); |
392 | } | 403 | } |
393 | 404 | ||
394 | 405 | ||
395 | QString OWirelessNetworkInterface::associatedAP() const | 406 | QString OWirelessNetworkInterface::associatedAP() const |
396 | { | 407 | { |
397 | //FIXME: use OMacAddress | 408 | //FIXME: use OMacAddress |
398 | QString mac; | 409 | QString mac; |
399 | 410 | ||
400 | if ( ioctl( SIOCGIWAP ) ) | 411 | if ( ioctl( SIOCGIWAP ) ) |
401 | { | 412 | { |
402 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 413 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
403 | _ifr.ifr_hwaddr.sa_data[0]&0xff, | 414 | _ifr.ifr_hwaddr.sa_data[0]&0xff, |
404 | _ifr.ifr_hwaddr.sa_data[1]&0xff, | 415 | _ifr.ifr_hwaddr.sa_data[1]&0xff, |
405 | _ifr.ifr_hwaddr.sa_data[2]&0xff, | 416 | _ifr.ifr_hwaddr.sa_data[2]&0xff, |
406 | _ifr.ifr_hwaddr.sa_data[3]&0xff, | 417 | _ifr.ifr_hwaddr.sa_data[3]&0xff, |
407 | _ifr.ifr_hwaddr.sa_data[4]&0xff, | 418 | _ifr.ifr_hwaddr.sa_data[4]&0xff, |
408 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); | 419 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); |
409 | } | 420 | } |
410 | else | 421 | else |
411 | { | 422 | { |
412 | mac = "<Unknown>"; | 423 | mac = "<Unknown>"; |
413 | } | 424 | } |
414 | return mac; | 425 | return mac; |
415 | } | 426 | } |
416 | 427 | ||
417 | 428 | ||
418 | void OWirelessNetworkInterface::buildChannelList() | 429 | void OWirelessNetworkInterface::buildChannelList() |
419 | { | 430 | { |
420 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 431 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
421 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | 432 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete |
422 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 433 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
423 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | 434 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate |
424 | //ML: _too much_ space. This is damn shitty crap *sigh* | 435 | //ML: _too much_ space. This is damn shitty crap *sigh* |
425 | //ML: We allocate a large memory region in RAM and check whether the | 436 | //ML: We allocate a large memory region in RAM and check whether the |
426 | //ML: driver pollutes this extra space. The complaint will be made on stdout, | 437 | //ML: driver pollutes this extra space. The complaint will be made on stdout, |
427 | //ML: so please forward this... | 438 | //ML: so please forward this... |
428 | 439 | ||
429 | struct iwreq wrq; | 440 | struct iwreq wrq; |
430 | int len = sizeof( struct iw_range )*2; | 441 | int len = sizeof( struct iw_range )*2; |
431 | char *buffer = (char*) malloc( len ); | 442 | char *buffer = (char*) malloc( len ); |
432 | //FIXME: Validate if we actually got the memory block | 443 | //FIXME: Validate if we actually got the memory block |
433 | memset( buffer, 0, len ); | 444 | memset( buffer, 0, len ); |
434 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | 445 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); |
435 | wrq.u.data.pointer = (caddr_t) buffer; | 446 | wrq.u.data.pointer = (caddr_t) buffer; |
436 | wrq.u.data.length = sizeof( struct iw_range ); | 447 | wrq.u.data.length = sizeof( struct iw_range ); |
437 | wrq.u.data.flags = 0; | 448 | wrq.u.data.flags = 0; |
438 | 449 | ||
439 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 450 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
440 | { | 451 | { |
441 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); | 452 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); |
442 | _channels.insert( 2412, 1 ); // 2.412 GHz | 453 | _channels.insert( 2412, 1 ); // 2.412 GHz |
443 | _channels.insert( 2417, 2 ); // 2.417 GHz | 454 | _channels.insert( 2417, 2 ); // 2.417 GHz |
444 | _channels.insert( 2422, 3 ); // 2.422 GHz | 455 | _channels.insert( 2422, 3 ); // 2.422 GHz |
445 | _channels.insert( 2427, 4 ); // 2.427 GHz | 456 | _channels.insert( 2427, 4 ); // 2.427 GHz |
446 | _channels.insert( 2432, 5 ); // 2.432 GHz | 457 | _channels.insert( 2432, 5 ); // 2.432 GHz |
447 | _channels.insert( 2437, 6 ); // 2.437 GHz | 458 | _channels.insert( 2437, 6 ); // 2.437 GHz |
448 | _channels.insert( 2442, 7 ); // 2.442 GHz | 459 | _channels.insert( 2442, 7 ); // 2.442 GHz |
449 | _channels.insert( 2447, 8 ); // 2.447 GHz | 460 | _channels.insert( 2447, 8 ); // 2.447 GHz |
450 | _channels.insert( 2452, 9 ); // 2.452 GHz | 461 | _channels.insert( 2452, 9 ); // 2.452 GHz |
451 | _channels.insert( 2457, 10 ); // 2.457 GHz | 462 | _channels.insert( 2457, 10 ); // 2.457 GHz |
452 | _channels.insert( 2462, 11 ); // 2.462 GHz | 463 | _channels.insert( 2462, 11 ); // 2.462 GHz |
453 | } | 464 | } |
454 | else | 465 | else |
455 | { | 466 | { |
456 | // <check if the driver overwrites stuff> | 467 | // <check if the driver overwrites stuff> |
457 | int max = 0; | 468 | int max = 0; |
458 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 469 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
459 | if (buffer[r] != 0) | 470 | if (buffer[r] != 0) |
460 | max = r; | 471 | max = r; |
461 | if (max > 0) | 472 | if (max > 0) |
462 | { | 473 | { |
463 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" | 474 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" |
464 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); | 475 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); |
465 | } | 476 | } |
466 | // </check if the driver overwrites stuff> | 477 | // </check if the driver overwrites stuff> |
467 | 478 | ||
468 | struct iw_range range; | 479 | struct iw_range range; |
469 | memcpy( &range, buffer, sizeof range ); | 480 | memcpy( &range, buffer, sizeof range ); |
470 | 481 | ||
471 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | 482 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); |
472 | for ( int i = 0; i < range.num_frequency; ++i ) | 483 | for ( int i = 0; i < range.num_frequency; ++i ) |
473 | { | 484 | { |
474 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 485 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
475 | _channels.insert( freq, i+1 ); | 486 | _channels.insert( freq, i+1 ); |
476 | } | 487 | } |
477 | } | 488 | } |
478 | 489 | ||
479 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); | 490 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); |
480 | free(buffer); | 491 | free(buffer); |
481 | } | 492 | } |
482 | 493 | ||
483 | 494 | ||
484 | void OWirelessNetworkInterface::buildPrivateList() | 495 | void OWirelessNetworkInterface::buildPrivateList() |
485 | { | 496 | { |
486 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | 497 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); |
487 | 498 | ||
488 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 499 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
489 | 500 | ||
490 | _iwr.u.data.pointer = (char*) &priv; | 501 | _iwr.u.data.pointer = (char*) &priv; |
491 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | 502 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself |
492 | _iwr.u.data.flags = 0; | 503 | _iwr.u.data.flags = 0; |
493 | 504 | ||
494 | if ( !wioctl( SIOCGIWPRIV ) ) | 505 | if ( !wioctl( SIOCGIWPRIV ) ) |
495 | { | 506 | { |
496 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); | 507 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); |
497 | return; | 508 | return; |
498 | } | 509 | } |
499 | 510 | ||
500 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 511 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
501 | { | 512 | { |
502 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 513 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
503 | } | 514 | } |
504 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); | 515 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); |
505 | } | 516 | } |
506 | 517 | ||
507 | 518 | ||
508 | int OWirelessNetworkInterface::channel() const | 519 | int OWirelessNetworkInterface::channel() const |
509 | { | 520 | { |
510 | //FIXME: When monitoring enabled, then use it | 521 | //FIXME: When monitoring enabled, then use it |
511 | //FIXME: to gather the current RF channel | 522 | //FIXME: to gather the current RF channel |
512 | //FIXME: Until then, get active channel from hopper. | 523 | //FIXME: Until then, get active channel from hopper. |
513 | if ( _hopper && _hopper->isActive() ) | 524 | if ( _hopper && _hopper->isActive() ) |
514 | return _hopper->channel(); | 525 | return _hopper->channel(); |
515 | 526 | ||
516 | if ( !wioctl( SIOCGIWFREQ ) ) | 527 | if ( !wioctl( SIOCGIWFREQ ) ) |
517 | { | 528 | { |
518 | return -1; | 529 | return -1; |
519 | } | 530 | } |
520 | else | 531 | else |
521 | { | 532 | { |
522 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; | 533 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; |
523 | } | 534 | } |
524 | } | 535 | } |
525 | 536 | ||
526 | 537 | ||
527 | void OWirelessNetworkInterface::setChannel( int c ) const | 538 | void OWirelessNetworkInterface::setChannel( int c ) const |
528 | { | 539 | { |
529 | if ( !_mon ) | 540 | if ( !_mon ) |
530 | { | 541 | { |
531 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 542 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
532 | _iwr.u.freq.m = c; | 543 | _iwr.u.freq.m = c; |
533 | _iwr.u.freq.e = 0; | 544 | _iwr.u.freq.e = 0; |
534 | wioctl( SIOCSIWFREQ ); | 545 | wioctl( SIOCSIWFREQ ); |
535 | } | 546 | } |
536 | else | 547 | else |
537 | { | 548 | { |
538 | _mon->setChannel( c ); | 549 | _mon->setChannel( c ); |
539 | } | 550 | } |
540 | } | 551 | } |
541 | 552 | ||
542 | 553 | ||
543 | double OWirelessNetworkInterface::frequency() const | 554 | double OWirelessNetworkInterface::frequency() const |
544 | { | 555 | { |
545 | if ( !wioctl( SIOCGIWFREQ ) ) | 556 | if ( !wioctl( SIOCGIWFREQ ) ) |
546 | { | 557 | { |
547 | return -1.0; | 558 | return -1.0; |
548 | } | 559 | } |
549 | else | 560 | else |
550 | { | 561 | { |
551 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 562 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
552 | } | 563 | } |
553 | } | 564 | } |
554 | 565 | ||
555 | 566 | ||
556 | int OWirelessNetworkInterface::channels() const | 567 | int OWirelessNetworkInterface::channels() const |
557 | { | 568 | { |
558 | return _channels.count(); | 569 | return _channels.count(); |
559 | } | 570 | } |
560 | 571 | ||
561 | 572 | ||
562 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 573 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
563 | { | 574 | { |
564 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 575 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
565 | _hopper->setInterval( interval ); | 576 | _hopper->setInterval( interval ); |
566 | //FIXME: When and by whom will the channel hopper be deleted? | 577 | //FIXME: When and by whom will the channel hopper be deleted? |
567 | //TODO: rely on QObject hierarchy | 578 | //TODO: rely on QObject hierarchy |
568 | } | 579 | } |
569 | 580 | ||
570 | 581 | ||
571 | int OWirelessNetworkInterface::channelHopping() const | 582 | int OWirelessNetworkInterface::channelHopping() const |
572 | { | 583 | { |
573 | return _hopper->interval(); | 584 | return _hopper->interval(); |
574 | } | 585 | } |
575 | 586 | ||
576 | 587 | ||
577 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 588 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
578 | { | 589 | { |
579 | if ( _mon ) | 590 | if ( _mon ) |
580 | _mon->setEnabled( b ); | 591 | _mon->setEnabled( b ); |
581 | else | 592 | else |
582 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 593 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
583 | } | 594 | } |
584 | 595 | ||
585 | 596 | ||
586 | bool OWirelessNetworkInterface::monitorMode() const | 597 | bool OWirelessNetworkInterface::monitorMode() const |
587 | { | 598 | { |
588 | return _mon ? _mon->enabled() : false; | 599 | qDebug( "dataLinkType = %d", dataLinkType() ); |
600 | return dataLinkType() == ARPHRD_IEEE80211; | ||
589 | } | 601 | } |
590 | 602 | ||
591 | 603 | ||
592 | QString OWirelessNetworkInterface::nickName() const | 604 | QString OWirelessNetworkInterface::nickName() const |
593 | { | 605 | { |
594 | char str[IW_ESSID_MAX_SIZE]; | 606 | char str[IW_ESSID_MAX_SIZE]; |
595 | _iwr.u.data.pointer = &str[0]; | 607 | _iwr.u.data.pointer = &str[0]; |
596 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 608 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
597 | if ( !wioctl( SIOCGIWNICKN ) ) | 609 | if ( !wioctl( SIOCGIWNICKN ) ) |
598 | { | 610 | { |
599 | return "<unknown>"; | 611 | return "<unknown>"; |
600 | } | 612 | } |
601 | else | 613 | else |
602 | { | 614 | { |
603 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 615 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
604 | return str; | 616 | return str; |
605 | } | 617 | } |
606 | } | 618 | } |
607 | 619 | ||
608 | 620 | ||
609 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 621 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
610 | { | 622 | { |
611 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 623 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
612 | if ( !priv ) | 624 | if ( !priv ) |
613 | { | 625 | { |
614 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); | 626 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); |
615 | return; | 627 | return; |
616 | } | 628 | } |
617 | if ( priv->numberSetArgs() != numargs ) | 629 | if ( priv->numberSetArgs() != numargs ) |
618 | { | 630 | { |
619 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); | 631 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); |
620 | return; | 632 | return; |
621 | } | 633 | } |
622 | 634 | ||
623 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); | 635 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); |
624 | memset( &_iwr, 0, sizeof _iwr ); | 636 | memset( &_iwr, 0, sizeof _iwr ); |
625 | va_list argp; | 637 | va_list argp; |
626 | va_start( argp, numargs ); | 638 | va_start( argp, numargs ); |
627 | for ( int i = 0; i < numargs; ++i ) | 639 | for ( int i = 0; i < numargs; ++i ) |
628 | { | 640 | { |
629 | priv->setParameter( i, va_arg( argp, int ) ); | 641 | priv->setParameter( i, va_arg( argp, int ) ); |
630 | } | 642 | } |
631 | va_end( argp ); | 643 | va_end( argp ); |
632 | priv->invoke(); | 644 | priv->invoke(); |
633 | } | 645 | } |
634 | 646 | ||
635 | 647 | ||
636 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 648 | void OWirelessNetworkInterface::getPrivate( const QString& call ) |
637 | { | 649 | { |
638 | } | 650 | } |
639 | 651 | ||
640 | 652 | ||
641 | QString OWirelessNetworkInterface::SSID() const | 653 | QString OWirelessNetworkInterface::SSID() const |
642 | { | 654 | { |
643 | char str[IW_ESSID_MAX_SIZE]; | 655 | char str[IW_ESSID_MAX_SIZE]; |
644 | _iwr.u.essid.pointer = &str[0]; | 656 | _iwr.u.essid.pointer = &str[0]; |
645 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 657 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
646 | if ( !wioctl( SIOCGIWESSID ) ) | 658 | if ( !wioctl( SIOCGIWESSID ) ) |
647 | { | 659 | { |
648 | return "<unknown>"; | 660 | return "<unknown>"; |
649 | } | 661 | } |
650 | else | 662 | else |
651 | { | 663 | { |
652 | return str; | 664 | return str; |
653 | } | 665 | } |
654 | } | 666 | } |
655 | 667 | ||
656 | 668 | ||
657 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 669 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
658 | { | 670 | { |
659 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 671 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
660 | _iwr.u.essid.length = ssid.length(); | 672 | _iwr.u.essid.length = ssid.length(); |
661 | wioctl( SIOCSIWESSID ); | 673 | wioctl( SIOCSIWESSID ); |
662 | } | 674 | } |
663 | 675 | ||
664 | 676 | ||
665 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 677 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
666 | { | 678 | { |
667 | int result = ::ioctl( _sfd, call, &iwreq ); | 679 | int result = ::ioctl( _sfd, call, &iwreq ); |
668 | if ( result == -1 ) | 680 | if ( result == -1 ) |
669 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); | 681 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); |
670 | else | 682 | else |
671 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); | 683 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); |
672 | return ( result != -1 ); | 684 | return ( result != -1 ); |
673 | } | 685 | } |
674 | 686 | ||
675 | 687 | ||
676 | bool OWirelessNetworkInterface::wioctl( int call ) const | 688 | bool OWirelessNetworkInterface::wioctl( int call ) const |
677 | { | 689 | { |
678 | strcpy( _iwr.ifr_name, name() ); | 690 | strcpy( _iwr.ifr_name, name() ); |
679 | return wioctl( call, _iwr ); | 691 | return wioctl( call, _iwr ); |
680 | } | 692 | } |
681 | 693 | ||
682 | 694 | ||
683 | /*====================================================================================== | 695 | /*====================================================================================== |
684 | * OMonitoringInterface | 696 | * OMonitoringInterface |
685 | *======================================================================================*/ | 697 | *======================================================================================*/ |
686 | 698 | ||
687 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) | 699 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) |
688 | :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) | 700 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) |
689 | { | 701 | { |
690 | } | 702 | } |
691 | 703 | ||
692 | 704 | ||
693 | OMonitoringInterface::~OMonitoringInterface() | 705 | OMonitoringInterface::~OMonitoringInterface() |
694 | { | 706 | { |
695 | } | 707 | } |
696 | 708 | ||
697 | 709 | ||
698 | void OMonitoringInterface::setChannel( int c ) | 710 | void OMonitoringInterface::setChannel( int c ) |
699 | { | 711 | { |
700 | // use standard WE channel switching protocol | 712 | // use standard WE channel switching protocol |
701 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 713 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
702 | _if->_iwr.u.freq.m = c; | 714 | _if->_iwr.u.freq.m = c; |
703 | _if->_iwr.u.freq.e = 0; | 715 | _if->_iwr.u.freq.e = 0; |
704 | _if->wioctl( SIOCSIWFREQ ); | 716 | _if->wioctl( SIOCSIWFREQ ); |
705 | } | 717 | } |
706 | 718 | ||
707 | 719 | ||
708 | bool OMonitoringInterface::enabled() const | 720 | bool OMonitoringInterface::enabled() const |
709 | { | 721 | { |
710 | return _enabled; | 722 | return _if->monitorMode(); |
711 | } | 723 | } |
712 | 724 | ||
725 | |||
713 | void OMonitoringInterface::setEnabled( bool b ) | 726 | void OMonitoringInterface::setEnabled( bool b ) |
714 | { | 727 | { |
715 | // open a packet capturer here or leave this to | ||
716 | // the client code? | ||
717 | |||
718 | /* | ||
719 | |||
720 | if ( b ) | ||
721 | { | ||
722 | OPacketCapturer* opcap = new OPacketCapturer(); | ||
723 | opcap->open( _if->name() ); | ||
724 | } | ||
725 | */ | ||
726 | |||
727 | _enabled = b; | ||
728 | |||
729 | } | 728 | } |
730 | 729 | ||
730 | |||
731 | /*====================================================================================== | 731 | /*====================================================================================== |
732 | * OCiscoMonitoringInterface | 732 | * OCiscoMonitoringInterface |
733 | *======================================================================================*/ | 733 | *======================================================================================*/ |
734 | 734 | ||
735 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) | 735 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) |
736 | :OMonitoringInterface( iface ) | 736 | :OMonitoringInterface( iface ) |
737 | { | 737 | { |
738 | iface->setMonitoring( this ); | 738 | iface->setMonitoring( this ); |
739 | } | 739 | } |
740 | 740 | ||
741 | 741 | ||
742 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 742 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
743 | { | 743 | { |
744 | } | 744 | } |
745 | 745 | ||
746 | 746 | ||
747 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 747 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
748 | { | 748 | { |
749 | QString fname; | 749 | QString fname; |
750 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 750 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
751 | QFile f( fname ); | 751 | QFile f( fname ); |
752 | if ( !f.exists() ) return; | 752 | if ( !f.exists() ) return; |
753 | 753 | ||
754 | if ( f.open( IO_WriteOnly ) ) | 754 | if ( f.open( IO_WriteOnly ) ) |
755 | { | 755 | { |
756 | QTextStream s( &f ); | 756 | QTextStream s( &f ); |
757 | s << "Mode: r"; | 757 | s << "Mode: r"; |
758 | s << "Mode: y"; | 758 | s << "Mode: y"; |
759 | s << "XmitPower: 1"; | 759 | s << "XmitPower: 1"; |
760 | |||
761 | OMonitoringInterface::setEnabled( b ); | ||
762 | |||
763 | } | 760 | } |
764 | 761 | ||
765 | // flushing and closing will be done automatically when f goes out of scope | 762 | // flushing and closing will be done automatically when f goes out of scope |
766 | } | 763 | } |
767 | 764 | ||
768 | 765 | ||
769 | QString OCiscoMonitoringInterface::name() const | 766 | QString OCiscoMonitoringInterface::name() const |
770 | { | 767 | { |
771 | return "cisco"; | 768 | return "cisco"; |
772 | } | 769 | } |
773 | 770 | ||
774 | 771 | ||
775 | void OCiscoMonitoringInterface::setChannel( int ) | 772 | void OCiscoMonitoringInterface::setChannel( int ) |
776 | { | 773 | { |
777 | // cisco devices automatically switch channels when in monitor mode | 774 | // cisco devices automatically switch channels when in monitor mode |
778 | } | 775 | } |
779 | 776 | ||
780 | 777 | ||
781 | /*====================================================================================== | 778 | /*====================================================================================== |
782 | * OWlanNGMonitoringInterface | 779 | * OWlanNGMonitoringInterface |
783 | *======================================================================================*/ | 780 | *======================================================================================*/ |
784 | 781 | ||
785 | 782 | ||
786 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) | 783 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) |
787 | :OMonitoringInterface( iface ) | 784 | :OMonitoringInterface( iface ) |
788 | { | 785 | { |
789 | iface->setMonitoring( this ); | 786 | iface->setMonitoring( this ); |
790 | } | 787 | } |
791 | 788 | ||
792 | 789 | ||
793 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 790 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
794 | { | 791 | { |
795 | } | 792 | } |
796 | 793 | ||
797 | 794 | ||
798 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 795 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
799 | { | 796 | { |
800 | //FIXME: do nothing if its already in the same mode | 797 | //FIXME: do nothing if its already in the same mode |
801 | 798 | ||
802 | QString enable = b ? "true" : "false"; | 799 | QString enable = b ? "true" : "false"; |
803 | QString cmd; | 800 | QString cmd; |
804 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); | 801 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); |
805 | system( cmd ); | 802 | system( cmd ); |
806 | |||
807 | OMonitoringInterface::setEnabled( b ); | ||
808 | } | 803 | } |
809 | 804 | ||
810 | 805 | ||
811 | QString OWlanNGMonitoringInterface::name() const | 806 | QString OWlanNGMonitoringInterface::name() const |
812 | { | 807 | { |
813 | return "wlan-ng"; | 808 | return "wlan-ng"; |
814 | } | 809 | } |
815 | 810 | ||
816 | 811 | ||
817 | void OWlanNGMonitoringInterface::setChannel( int ) | 812 | void OWlanNGMonitoringInterface::setChannel( int ) |
818 | { | 813 | { |
819 | // wlan-ng devices automatically switch channels when in monitor mode | 814 | // wlan-ng devices automatically switch channels when in monitor mode |
820 | } | 815 | } |
821 | 816 | ||
822 | 817 | ||
823 | /*====================================================================================== | 818 | /*====================================================================================== |
824 | * OHostAPMonitoringInterface | 819 | * OHostAPMonitoringInterface |
825 | *======================================================================================*/ | 820 | *======================================================================================*/ |
826 | 821 | ||
827 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) | 822 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) |
828 | :OMonitoringInterface( iface ) | 823 | :OMonitoringInterface( iface ) |
829 | { | 824 | { |
830 | iface->setMonitoring( this ); | 825 | iface->setMonitoring( this ); |
831 | } | 826 | } |
832 | 827 | ||
833 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 828 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
834 | { | 829 | { |
835 | } | 830 | } |
836 | 831 | ||
837 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 832 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
838 | { | 833 | { |
839 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 834 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
840 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 835 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
841 | 836 | ||
842 | if ( b ) | 837 | if ( b ) |
843 | { | 838 | { |
844 | #if WIRELESS_EXT > 14 | 839 | #if WIRELESS_EXT > 14 |
845 | _if->_iwr.u.mode = IW_MODE_MONITOR; | 840 | _if->_iwr.u.mode = IW_MODE_MONITOR; |
846 | _if->wioctl( SIOCSIWMODE ); | 841 | _if->wioctl( SIOCSIWMODE ); |
847 | #else | 842 | #else |
848 | int* args = (int*) &_if->_iwr.u.name; | 843 | int* args = (int*) &_if->_iwr.u.name; |
849 | args[0] = 2; | 844 | args[0] = 2; |
850 | args[1] = 0; | 845 | args[1] = 0; |
851 | _if->wioctl( SIOCDEVPRIVATE ); | 846 | _if->wioctl( SIOCDEVPRIVATE ); |
852 | #endif | 847 | #endif |
853 | } | 848 | } |
854 | else | 849 | else |
855 | { | 850 | { |
856 | #if WIRELESS_EXT > 14 | 851 | #if WIRELESS_EXT > 14 |
857 | _if->_iwr.u.mode = IW_MODE_INFRA; | 852 | _if->_iwr.u.mode = IW_MODE_INFRA; |
858 | _if->wioctl( SIOCSIWMODE ); | 853 | _if->wioctl( SIOCSIWMODE ); |
859 | #else | 854 | #else |
860 | int* args = (int*) &_if->_iwr.u.name; | 855 | int* args = (int*) &_if->_iwr.u.name; |
861 | args[0] = 0; | 856 | args[0] = 0; |
862 | args[1] = 0; | 857 | args[1] = 0; |
863 | _if->wioctl( SIOCDEVPRIVATE ); | 858 | _if->wioctl( SIOCDEVPRIVATE ); |
864 | #endif | 859 | #endif |
865 | } | 860 | } |
866 | |||
867 | OMonitoringInterface::setEnabled( b ); | ||
868 | } | 861 | } |
869 | 862 | ||
870 | 863 | ||
871 | QString OHostAPMonitoringInterface::name() const | 864 | QString OHostAPMonitoringInterface::name() const |
872 | { | 865 | { |
873 | return "hostap"; | 866 | return "hostap"; |
874 | } | 867 | } |
875 | 868 | ||
876 | 869 | ||
877 | /*====================================================================================== | 870 | /*====================================================================================== |
878 | * OOrinocoNetworkInterface | 871 | * OOrinocoNetworkInterface |
879 | *======================================================================================*/ | 872 | *======================================================================================*/ |
880 | 873 | ||
881 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) | 874 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) |
882 | :OMonitoringInterface( iface ) | 875 | :OMonitoringInterface( iface ) |
883 | { | 876 | { |
884 | iface->setMonitoring( this ); | 877 | iface->setMonitoring( this ); |
885 | } | 878 | } |
886 | 879 | ||
887 | 880 | ||
888 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 881 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
889 | { | 882 | { |
890 | } | 883 | } |
891 | 884 | ||
892 | 885 | ||
893 | void OOrinocoMonitoringInterface::setChannel( int c ) | 886 | void OOrinocoMonitoringInterface::setChannel( int c ) |
894 | { | 887 | { |
895 | // call iwpriv <device> monitor 2 <channel> | 888 | // call iwpriv <device> monitor 2 <channel> |
896 | int* args = (int*) &_if->_iwr.u.name; | 889 | int* args = (int*) &_if->_iwr.u.name; |
897 | args[0] = 2; | 890 | args[0] = 2; |
898 | args[1] = c; | 891 | args[1] = c; |
899 | _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); | 892 | _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); |
900 | } | 893 | } |
901 | 894 | ||
902 | 895 | ||
903 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 896 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
904 | { | 897 | { |
905 | if ( b ) | 898 | if ( b ) |
906 | { | 899 | { |
907 | setChannel( 1 ); | 900 | setChannel( 1 ); |
908 | } | 901 | } |
909 | else | 902 | else |
910 | { | 903 | { |
911 | // call iwpriv <device> monitor 0 0 | 904 | // call iwpriv <device> monitor 0 0 |
912 | int* args = (int*) &_if->_iwr.u.name; | 905 | int* args = (int*) &_if->_iwr.u.name; |
913 | args[0] = 0; | 906 | args[0] = 0; |
914 | args[1] = 0; | 907 | args[1] = 0; |
915 | _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); | 908 | _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); |
916 | } | 909 | } |
917 | |||
918 | OMonitoringInterface::setEnabled( b ); | ||
919 | } | 910 | } |
920 | 911 | ||
921 | 912 | ||
922 | QString OOrinocoMonitoringInterface::name() const | 913 | QString OOrinocoMonitoringInterface::name() const |
923 | { | 914 | { |
924 | return "orinoco"; | 915 | return "orinoco"; |
925 | } | 916 | } |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 509c3db..4cadbeb 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -1,324 +1,324 @@ | |||
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 | /* QT */ | 37 | /* QT */ |
38 | 38 | ||
39 | #include <qvaluelist.h> | 39 | #include <qvaluelist.h> |
40 | #include <qdict.h> | 40 | #include <qdict.h> |
41 | #include <qmap.h> | 41 | #include <qmap.h> |
42 | #include <qobject.h> | 42 | #include <qobject.h> |
43 | #include <qhostaddress.h> | 43 | #include <qhostaddress.h> |
44 | 44 | ||
45 | /* OPIE */ | 45 | /* OPIE */ |
46 | 46 | ||
47 | #include <opie2/onetutils.h> | 47 | #include <opie2/onetutils.h> |
48 | 48 | ||
49 | #ifndef IFNAMSIZ | 49 | #ifndef IFNAMSIZ |
50 | #define IFNAMSIZ 16 | 50 | #define IFNAMSIZ 16 |
51 | #endif | 51 | #endif |
52 | #ifndef IW_MAX_PRIV_DEF | 52 | #ifndef IW_MAX_PRIV_DEF |
53 | #define IW_MAX_PRIV_DEF 128 | 53 | #define IW_MAX_PRIV_DEF 128 |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | // ML: Yeah, I hate to include kernel headers, but it's necessary here | 56 | // ML: Yeah, I hate to include kernel headers, but it's necessary here |
57 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> | 57 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> |
58 | // ML: which conflicts with the user header <net/if.h> | 58 | // ML: which conflicts with the user header <net/if.h> |
59 | // ML: We really a user header for the Wireless Extensions, something like <net/wireless.h> | 59 | // ML: We really a user header for the Wireless Extensions, something like <net/wireless.h> |
60 | // ML: I will drop Jean an mail on that subject | 60 | // ML: I will drop Jean an mail on that subject |
61 | 61 | ||
62 | #include <net/if.h> | 62 | #include <net/if.h> |
63 | #define _LINUX_IF_H | 63 | #define _LINUX_IF_H |
64 | #include <linux/wireless.h> | 64 | #include <linux/wireless.h> |
65 | 65 | ||
66 | #ifndef SIOCIWFIRSTPRIV | 66 | #ifndef SIOCIWFIRSTPRIV |
67 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE | 67 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE |
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | class ONetworkInterface; | 70 | class ONetworkInterface; |
71 | class OWirelessNetworkInterface; | 71 | class OWirelessNetworkInterface; |
72 | class OChannelHopper; | 72 | class OChannelHopper; |
73 | class OMonitoringInterface; | 73 | class OMonitoringInterface; |
74 | 74 | ||
75 | /*====================================================================================== | 75 | /*====================================================================================== |
76 | * ONetwork | 76 | * ONetwork |
77 | *======================================================================================*/ | 77 | *======================================================================================*/ |
78 | 78 | ||
79 | class ONetwork : public QObject | 79 | class ONetwork : public QObject |
80 | { | 80 | { |
81 | Q_OBJECT | 81 | Q_OBJECT |
82 | 82 | ||
83 | public: | 83 | public: |
84 | typedef QDict<ONetworkInterface> InterfaceMap; | 84 | typedef QDict<ONetworkInterface> InterfaceMap; |
85 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; | 85 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; |
86 | 86 | ||
87 | public: | 87 | public: |
88 | static ONetwork* instance(); | 88 | static ONetwork* instance(); |
89 | InterfaceIterator iterator() const; | 89 | InterfaceIterator iterator() const; |
90 | bool isWirelessInterface( const char* ) const; | 90 | bool isWirelessInterface( const char* ) const; |
91 | ONetworkInterface* interface( QString ) const; | 91 | ONetworkInterface* interface( QString ) const; |
92 | 92 | ||
93 | protected: | 93 | protected: |
94 | ONetwork(); | 94 | ONetwork(); |
95 | void synchronize(); | 95 | void synchronize(); |
96 | 96 | ||
97 | private: | 97 | private: |
98 | static ONetwork* _instance; | 98 | static ONetwork* _instance; |
99 | InterfaceMap _interfaces; | 99 | InterfaceMap _interfaces; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | 102 | ||
103 | /*====================================================================================== | 103 | /*====================================================================================== |
104 | * ONetworkInterface | 104 | * ONetworkInterface |
105 | *======================================================================================*/ | 105 | *======================================================================================*/ |
106 | 106 | ||
107 | class ONetworkInterface : public QObject | 107 | class ONetworkInterface : public QObject |
108 | { | 108 | { |
109 | friend class OMonitoringInterface; | 109 | friend class OMonitoringInterface; |
110 | friend class OCiscoMonitoringInterface; | 110 | friend class OCiscoMonitoringInterface; |
111 | friend class OWlanNGMonitoringInterface; | 111 | friend class OWlanNGMonitoringInterface; |
112 | friend class OHostAPMonitoringInterface; | 112 | friend class OHostAPMonitoringInterface; |
113 | friend class OOrinocoMonitoringInterface; | 113 | friend class OOrinocoMonitoringInterface; |
114 | 114 | ||
115 | public: | 115 | public: |
116 | ONetworkInterface( QObject* parent, const char* name ); | 116 | ONetworkInterface( QObject* parent, const char* name ); |
117 | virtual ~ONetworkInterface(); | 117 | virtual ~ONetworkInterface(); |
118 | 118 | ||
119 | void setMonitoring( OMonitoringInterface* ); | 119 | void setMonitoring( OMonitoringInterface* ); |
120 | OMonitoringInterface* monitoring() const; | 120 | OMonitoringInterface* monitoring() const; |
121 | bool setPromiscuousMode( bool ); | 121 | bool setPromiscuousMode( bool ); |
122 | bool promiscuousMode() const; | 122 | bool promiscuousMode() const; |
123 | bool setUp( bool ); | 123 | bool setUp( bool ); |
124 | bool isUp() const; | 124 | bool isUp() const; |
125 | bool isLoopback() const; | 125 | bool isLoopback() const; |
126 | bool isWireless() const; | 126 | bool isWireless() const; |
127 | QString ipV4Address() const; | 127 | QString ipV4Address() const; |
128 | OMacAddress macAddress() const; | 128 | OMacAddress macAddress() const; |
129 | int dataLinkType() const; | ||
129 | 130 | ||
130 | protected: | 131 | protected: |
131 | const int _sfd; | 132 | const int _sfd; |
132 | mutable ifreq _ifr; | 133 | mutable ifreq _ifr; |
133 | OMonitoringInterface* _mon; | 134 | OMonitoringInterface* _mon; |
134 | 135 | ||
135 | protected: | 136 | protected: |
136 | struct ifreq& ifr() const; | 137 | struct ifreq& ifr() const; |
137 | virtual void init(); | 138 | virtual void init(); |
138 | bool ioctl( int call ) const; | 139 | bool ioctl( int call ) const; |
139 | bool ioctl( int call, struct ifreq& ) const; | 140 | bool ioctl( int call, struct ifreq& ) const; |
140 | }; | 141 | }; |
141 | 142 | ||
142 | /*====================================================================================== | 143 | /*====================================================================================== |
143 | * OChannelHopper | 144 | * OChannelHopper |
144 | *======================================================================================*/ | 145 | *======================================================================================*/ |
145 | 146 | ||
146 | class OChannelHopper : public QObject | 147 | class OChannelHopper : public QObject |
147 | { | 148 | { |
148 | public: | 149 | public: |
149 | OChannelHopper( OWirelessNetworkInterface* ); | 150 | OChannelHopper( OWirelessNetworkInterface* ); |
150 | virtual ~OChannelHopper(); | 151 | virtual ~OChannelHopper(); |
151 | bool isActive() const; | 152 | bool isActive() const; |
152 | int channel() const; | 153 | int channel() const; |
153 | virtual void timerEvent( QTimerEvent* ); | 154 | virtual void timerEvent( QTimerEvent* ); |
154 | void setInterval( int ); | 155 | void setInterval( int ); |
155 | int interval() const; | 156 | int interval() const; |
156 | 157 | ||
157 | private: | 158 | private: |
158 | OWirelessNetworkInterface* _iface; | 159 | OWirelessNetworkInterface* _iface; |
159 | int _interval; | 160 | int _interval; |
160 | int _tid; | 161 | int _tid; |
161 | QValueList<int> _channels; | 162 | QValueList<int> _channels; |
162 | QValueList<int>::Iterator _channel; | 163 | QValueList<int>::Iterator _channel; |
163 | 164 | ||
164 | }; | 165 | }; |
165 | 166 | ||
166 | 167 | ||
167 | /*====================================================================================== | 168 | /*====================================================================================== |
168 | * OWirelessNetworkInterface | 169 | * OWirelessNetworkInterface |
169 | *======================================================================================*/ | 170 | *======================================================================================*/ |
170 | 171 | ||
171 | class OWirelessNetworkInterface : public ONetworkInterface | 172 | class OWirelessNetworkInterface : public ONetworkInterface |
172 | { | 173 | { |
173 | friend class OMonitoringInterface; | 174 | friend class OMonitoringInterface; |
174 | friend class OCiscoMonitoringInterface; | 175 | friend class OCiscoMonitoringInterface; |
175 | friend class OWlanNGMonitoringInterface; | 176 | friend class OWlanNGMonitoringInterface; |
176 | friend class OHostAPMonitoringInterface; | 177 | friend class OHostAPMonitoringInterface; |
177 | friend class OOrinocoMonitoringInterface; | 178 | friend class OOrinocoMonitoringInterface; |
178 | 179 | ||
179 | friend class OPrivateIOCTL; | 180 | friend class OPrivateIOCTL; |
180 | 181 | ||
181 | public: | 182 | public: |
182 | enum Mode { AdHoc, Managed, Monitor }; | 183 | enum Mode { AdHoc, Managed, Monitor }; |
183 | 184 | ||
184 | OWirelessNetworkInterface( QObject* parent, const char* name ); | 185 | OWirelessNetworkInterface( QObject* parent, const char* name ); |
185 | virtual ~OWirelessNetworkInterface(); | 186 | virtual ~OWirelessNetworkInterface(); |
186 | 187 | ||
187 | virtual void setChannel( int ) const; | 188 | virtual void setChannel( int ) const; |
188 | virtual int channel() const; | 189 | virtual int channel() const; |
189 | virtual double frequency() const; | 190 | virtual double frequency() const; |
190 | virtual int channels() const; | 191 | virtual int channels() const; |
191 | //virtual double frequency(int) const; | 192 | //virtual double frequency(int) const; |
192 | 193 | ||
193 | virtual void setMode( Mode ) {}; | 194 | virtual void setMode( Mode ) {}; |
194 | virtual bool mode() const {}; | 195 | virtual bool mode() const {}; |
195 | 196 | ||
196 | virtual void setMonitorMode( bool ); | 197 | virtual void setMonitorMode( bool ); |
197 | virtual bool monitorMode() const; | 198 | virtual bool monitorMode() const; |
198 | 199 | ||
199 | virtual void setChannelHopping( int interval = 0 ); | 200 | virtual void setChannelHopping( int interval = 0 ); |
200 | virtual int channelHopping() const; | 201 | virtual int channelHopping() const; |
201 | 202 | ||
202 | virtual void setNickName( const QString& ) {}; | 203 | virtual void setNickName( const QString& ) {}; |
203 | virtual QString nickName() const; | 204 | virtual QString nickName() const; |
204 | 205 | ||
205 | virtual void setPrivate( const QString&, int, ... ); | 206 | virtual void setPrivate( const QString&, int, ... ); |
206 | virtual void getPrivate( const QString& ); | 207 | virtual void getPrivate( const QString& ); |
207 | 208 | ||
208 | virtual bool isAssociated() const {}; | 209 | virtual bool isAssociated() const {}; |
209 | virtual QString associatedAP() const; | 210 | virtual QString associatedAP() const; |
210 | 211 | ||
211 | virtual void setSSID( const QString& ); | 212 | virtual void setSSID( const QString& ); |
212 | virtual QString SSID() const; | 213 | virtual QString SSID() const; |
213 | 214 | ||
214 | protected: | 215 | protected: |
215 | void buildChannelList(); | 216 | void buildChannelList(); |
216 | void buildPrivateList(); | 217 | void buildPrivateList(); |
217 | virtual void init(); | 218 | virtual void init(); |
218 | struct iwreq& iwr() const; | 219 | struct iwreq& iwr() const; |
219 | bool wioctl( int call ) const; | 220 | bool wioctl( int call ) const; |
220 | bool wioctl( int call, struct iwreq& ) const; | 221 | bool wioctl( int call, struct iwreq& ) const; |
221 | 222 | ||
222 | protected: | 223 | protected: |
223 | mutable struct iwreq _iwr; | 224 | mutable struct iwreq _iwr; |
224 | QMap<int,int> _channels; | 225 | QMap<int,int> _channels; |
225 | 226 | ||
226 | private: | 227 | private: |
227 | OChannelHopper* _hopper; | 228 | OChannelHopper* _hopper; |
228 | }; | 229 | }; |
229 | 230 | ||
230 | 231 | ||
231 | /*====================================================================================== | 232 | /*====================================================================================== |
232 | * OMonitoringInterface | 233 | * OMonitoringInterface |
233 | *======================================================================================*/ | 234 | *======================================================================================*/ |
234 | 235 | ||
235 | 236 | ||
236 | class OMonitoringInterface | 237 | class OMonitoringInterface |
237 | { | 238 | { |
238 | public: | 239 | public: |
239 | OMonitoringInterface(); | 240 | OMonitoringInterface(); |
240 | OMonitoringInterface( ONetworkInterface* ); | 241 | OMonitoringInterface( ONetworkInterface* ); |
241 | virtual ~OMonitoringInterface(); | 242 | virtual ~OMonitoringInterface(); |
242 | 243 | ||
243 | public: | 244 | public: |
244 | virtual void setEnabled( bool ); | 245 | virtual void setEnabled( bool ); |
245 | virtual bool enabled() const; | 246 | virtual bool enabled() const; |
246 | virtual void setChannel( int ); | 247 | virtual void setChannel( int ); |
247 | 248 | ||
248 | virtual QString name() const = 0; | 249 | virtual QString name() const = 0; |
249 | 250 | ||
250 | protected: | 251 | protected: |
251 | bool _enabled; | ||
252 | const OWirelessNetworkInterface* _if; | 252 | const OWirelessNetworkInterface* _if; |
253 | 253 | ||
254 | }; | 254 | }; |
255 | 255 | ||
256 | 256 | ||
257 | /*====================================================================================== | 257 | /*====================================================================================== |
258 | * OCiscoMonitoring | 258 | * OCiscoMonitoring |
259 | *======================================================================================*/ | 259 | *======================================================================================*/ |
260 | 260 | ||
261 | 261 | ||
262 | class OCiscoMonitoringInterface : public OMonitoringInterface | 262 | class OCiscoMonitoringInterface : public OMonitoringInterface |
263 | { | 263 | { |
264 | public: | 264 | public: |
265 | OCiscoMonitoringInterface( ONetworkInterface* ); | 265 | OCiscoMonitoringInterface( ONetworkInterface* ); |
266 | virtual ~OCiscoMonitoringInterface(); | 266 | virtual ~OCiscoMonitoringInterface(); |
267 | 267 | ||
268 | virtual void setEnabled( bool ); | 268 | virtual void setEnabled( bool ); |
269 | virtual QString name() const; | 269 | virtual QString name() const; |
270 | virtual void setChannel( int ); | 270 | virtual void setChannel( int ); |
271 | 271 | ||
272 | }; | 272 | }; |
273 | 273 | ||
274 | /*====================================================================================== | 274 | /*====================================================================================== |
275 | * OWlanNGMonitoringInterface | 275 | * OWlanNGMonitoringInterface |
276 | *======================================================================================*/ | 276 | *======================================================================================*/ |
277 | 277 | ||
278 | class OWlanNGMonitoringInterface : public OMonitoringInterface | 278 | class OWlanNGMonitoringInterface : public OMonitoringInterface |
279 | { | 279 | { |
280 | public: | 280 | public: |
281 | OWlanNGMonitoringInterface( ONetworkInterface* ); | 281 | OWlanNGMonitoringInterface( ONetworkInterface* ); |
282 | virtual ~OWlanNGMonitoringInterface(); | 282 | virtual ~OWlanNGMonitoringInterface(); |
283 | 283 | ||
284 | public: | 284 | public: |
285 | virtual void setEnabled( bool ); | 285 | virtual void setEnabled( bool ); |
286 | virtual QString name() const; | 286 | virtual QString name() const; |
287 | virtual void setChannel( int ); | 287 | virtual void setChannel( int ); |
288 | 288 | ||
289 | }; | 289 | }; |
290 | 290 | ||
291 | /*====================================================================================== | 291 | /*====================================================================================== |
292 | * OHostAPMonitoringInterface | 292 | * OHostAPMonitoringInterface |
293 | *======================================================================================*/ | 293 | *======================================================================================*/ |
294 | 294 | ||
295 | class OHostAPMonitoringInterface : public OMonitoringInterface | 295 | class OHostAPMonitoringInterface : public OMonitoringInterface |
296 | { | 296 | { |
297 | public: | 297 | public: |
298 | OHostAPMonitoringInterface( ONetworkInterface* ); | 298 | OHostAPMonitoringInterface( ONetworkInterface* ); |
299 | virtual ~OHostAPMonitoringInterface(); | 299 | virtual ~OHostAPMonitoringInterface(); |
300 | 300 | ||
301 | public: | 301 | public: |
302 | virtual void setEnabled( bool ); | 302 | virtual void setEnabled( bool ); |
303 | virtual QString name() const; | 303 | virtual QString name() const; |
304 | }; | 304 | }; |
305 | 305 | ||
306 | /*====================================================================================== | 306 | /*====================================================================================== |
307 | * OOrinocoMonitoringInterface | 307 | * OOrinocoMonitoringInterface |
308 | *======================================================================================*/ | 308 | *======================================================================================*/ |
309 | 309 | ||
310 | class OOrinocoMonitoringInterface : public OMonitoringInterface | 310 | class OOrinocoMonitoringInterface : public OMonitoringInterface |
311 | { | 311 | { |
312 | public: | 312 | public: |
313 | OOrinocoMonitoringInterface( ONetworkInterface* ); | 313 | OOrinocoMonitoringInterface( ONetworkInterface* ); |
314 | virtual ~OOrinocoMonitoringInterface(); | 314 | virtual ~OOrinocoMonitoringInterface(); |
315 | 315 | ||
316 | public: | 316 | public: |
317 | virtual void setChannel( int ); | 317 | virtual void setChannel( int ); |
318 | virtual void setEnabled( bool ); | 318 | virtual void setEnabled( bool ); |
319 | virtual QString name() const; | 319 | virtual QString name() const; |
320 | 320 | ||
321 | }; | 321 | }; |
322 | 322 | ||
323 | #endif // ONETWORK_H | 323 | #endif // ONETWORK_H |
324 | 324 | ||