author | mickeyl <mickeyl> | 2003-04-16 22:24:29 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-16 22:24:29 (UTC) |
commit | 0ac702419b3b8450b689e0ee2500f34b577f1a72 (patch) (unidiff) | |
tree | ef9e8101430c1429992b43a780bd68ca10daa77f | |
parent | 14db7d7d1ea99b8d9715f11daaa3ca9f4d8a554a (diff) | |
download | opie-0ac702419b3b8450b689e0ee2500f34b577f1a72.zip opie-0ac702419b3b8450b689e0ee2500f34b577f1a72.tar.gz opie-0ac702419b3b8450b689e0ee2500f34b577f1a72.tar.bz2 |
add some missing APIs to ONetworkInterface
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 41 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 49 |
2 files changed, 75 insertions, 15 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index f0094c7..be2736a 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,759 +1,798 @@ | |||
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 <net/if_arp.h> |
56 | #include <stdarg.h> | 56 | #include <stdarg.h> |
57 | 57 | ||
58 | using namespace std; | 58 | using namespace std; |
59 | 59 | ||
60 | /*====================================================================================== | 60 | /*====================================================================================== |
61 | * ONetwork | 61 | * ONetwork |
62 | *======================================================================================*/ | 62 | *======================================================================================*/ |
63 | 63 | ||
64 | ONetwork* ONetwork::_instance = 0; | 64 | ONetwork* ONetwork::_instance = 0; |
65 | 65 | ||
66 | ONetwork::ONetwork() | 66 | ONetwork::ONetwork() |
67 | { | 67 | { |
68 | qDebug( "ONetwork::ONetwork()" ); | 68 | qDebug( "ONetwork::ONetwork()" ); |
69 | synchronize(); | 69 | synchronize(); |
70 | } | 70 | } |
71 | 71 | ||
72 | void ONetwork::synchronize() | 72 | void ONetwork::synchronize() |
73 | { | 73 | { |
74 | // gather available interfaces by inspecting /proc/net/dev | 74 | // gather available interfaces by inspecting /proc/net/dev |
75 | //FIXME: 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 | 76 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
77 | 77 | ||
78 | _interfaces.clear(); | 78 | _interfaces.clear(); |
79 | QString str; | 79 | QString str; |
80 | QFile f( "/proc/net/dev" ); | 80 | QFile f( "/proc/net/dev" ); |
81 | bool hasFile = f.open( IO_ReadOnly ); | 81 | bool hasFile = f.open( IO_ReadOnly ); |
82 | if ( !hasFile ) | 82 | if ( !hasFile ) |
83 | { | 83 | { |
84 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); | 84 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); |
85 | return; | 85 | return; |
86 | } | 86 | } |
87 | QTextStream s( &f ); | 87 | QTextStream s( &f ); |
88 | s.readLine(); | 88 | s.readLine(); |
89 | s.readLine(); | 89 | s.readLine(); |
90 | while ( !s.atEnd() ) | 90 | while ( !s.atEnd() ) |
91 | { | 91 | { |
92 | s >> str; | 92 | s >> str; |
93 | str.truncate( str.find( ':' ) ); | 93 | str.truncate( str.find( ':' ) ); |
94 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); | 94 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); |
95 | ONetworkInterface* iface; | 95 | ONetworkInterface* iface; |
96 | if ( isWirelessInterface( str ) ) | 96 | if ( isWirelessInterface( str ) ) |
97 | { | 97 | { |
98 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 98 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
99 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 99 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); |
100 | } | 100 | } |
101 | else | 101 | else |
102 | { | 102 | { |
103 | iface = new ONetworkInterface( this, (const char*) str ); | 103 | iface = new ONetworkInterface( this, (const char*) str ); |
104 | } | 104 | } |
105 | _interfaces.insert( str, iface ); | 105 | _interfaces.insert( str, iface ); |
106 | s.readLine(); | 106 | s.readLine(); |
107 | } | 107 | } |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | int ONetwork::count() const | ||
112 | { | ||
113 | return _interfaces.count(); | ||
114 | } | ||
115 | |||
116 | |||
111 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 117 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
112 | { | 118 | { |
113 | return _interfaces[iface]; | 119 | return _interfaces[iface]; |
114 | } | 120 | } |
115 | 121 | ||
116 | 122 | ||
117 | ONetwork* ONetwork::instance() | 123 | ONetwork* ONetwork::instance() |
118 | { | 124 | { |
119 | if ( !_instance ) _instance = new ONetwork(); | 125 | if ( !_instance ) _instance = new ONetwork(); |
120 | return _instance; | 126 | return _instance; |
121 | } | 127 | } |
122 | 128 | ||
123 | 129 | ||
124 | ONetwork::InterfaceIterator ONetwork::iterator() const | 130 | ONetwork::InterfaceIterator ONetwork::iterator() const |
125 | { | 131 | { |
126 | return ONetwork::InterfaceIterator( _interfaces ); | 132 | return ONetwork::InterfaceIterator( _interfaces ); |
127 | } | 133 | } |
128 | 134 | ||
129 | 135 | ||
130 | bool ONetwork::isWirelessInterface( const char* name ) const | 136 | bool ONetwork::isWirelessInterface( const char* name ) const |
131 | { | 137 | { |
132 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 138 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
133 | struct iwreq iwr; | 139 | struct iwreq iwr; |
134 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 140 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
135 | strcpy( (char*) &iwr.ifr_name, name ); | 141 | strcpy( (char*) &iwr.ifr_name, name ); |
136 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 142 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
137 | return result != -1; | 143 | return result != -1; |
138 | } | 144 | } |
139 | 145 | ||
140 | /*====================================================================================== | 146 | /*====================================================================================== |
141 | * ONetworkInterface | 147 | * ONetworkInterface |
142 | *======================================================================================*/ | 148 | *======================================================================================*/ |
143 | 149 | ||
144 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 150 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
145 | :QObject( parent, name ), | 151 | :QObject( parent, name ), |
146 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 152 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
147 | { | 153 | { |
148 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 154 | qDebug( "ONetworkInterface::ONetworkInterface()" ); |
149 | init(); | 155 | init(); |
150 | } | 156 | } |
151 | 157 | ||
152 | 158 | ||
153 | struct ifreq& ONetworkInterface::ifr() const | 159 | struct ifreq& ONetworkInterface::ifr() const |
154 | { | 160 | { |
155 | return _ifr; | 161 | return _ifr; |
156 | } | 162 | } |
157 | 163 | ||
158 | 164 | ||
159 | void ONetworkInterface::init() | 165 | void ONetworkInterface::init() |
160 | { | 166 | { |
161 | qDebug( "ONetworkInterface::init()" ); | 167 | qDebug( "ONetworkInterface::init()" ); |
162 | 168 | ||
163 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 169 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
164 | 170 | ||
165 | if ( _sfd == -1 ) | 171 | if ( _sfd == -1 ) |
166 | { | 172 | { |
167 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); | 173 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); |
168 | return; | 174 | return; |
169 | } | 175 | } |
170 | } | 176 | } |
171 | 177 | ||
172 | 178 | ||
173 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 179 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
174 | { | 180 | { |
175 | int result = ::ioctl( _sfd, call, &ifreq ); | 181 | int result = ::ioctl( _sfd, call, &ifreq ); |
176 | if ( result == -1 ) | 182 | if ( result == -1 ) |
177 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 183 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); |
178 | else | 184 | else |
179 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); | 185 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); |
180 | return ( result != -1 ); | 186 | return ( result != -1 ); |
181 | } | 187 | } |
182 | 188 | ||
183 | 189 | ||
184 | bool ONetworkInterface::ioctl( int call ) const | 190 | bool ONetworkInterface::ioctl( int call ) const |
185 | { | 191 | { |
186 | strcpy( _ifr.ifr_name, name() ); | 192 | strcpy( _ifr.ifr_name, name() ); |
187 | return ioctl( call, _ifr ); | 193 | return ioctl( call, _ifr ); |
188 | } | 194 | } |
189 | 195 | ||
190 | 196 | ||
191 | bool ONetworkInterface::isLoopback() const | 197 | bool ONetworkInterface::isLoopback() const |
192 | { | 198 | { |
193 | ioctl( SIOCGIFFLAGS ); | 199 | ioctl( SIOCGIFFLAGS ); |
194 | return _ifr.ifr_flags & IFF_LOOPBACK; | 200 | return _ifr.ifr_flags & IFF_LOOPBACK; |
195 | } | 201 | } |
196 | 202 | ||
197 | 203 | ||
198 | bool ONetworkInterface::setUp( bool b ) | 204 | bool ONetworkInterface::setUp( bool b ) |
199 | { | 205 | { |
200 | ioctl( SIOCGIFFLAGS ); | 206 | ioctl( SIOCGIFFLAGS ); |
201 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 207 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
202 | else _ifr.ifr_flags &= (~IFF_UP); | 208 | else _ifr.ifr_flags &= (~IFF_UP); |
203 | return ioctl( SIOCSIFFLAGS ); | 209 | return ioctl( SIOCSIFFLAGS ); |
204 | } | 210 | } |
205 | 211 | ||
206 | 212 | ||
207 | bool ONetworkInterface::isUp() const | 213 | bool ONetworkInterface::isUp() const |
208 | { | 214 | { |
209 | ioctl( SIOCGIFFLAGS ); | 215 | ioctl( SIOCGIFFLAGS ); |
210 | return _ifr.ifr_flags & IFF_UP; | 216 | return _ifr.ifr_flags & IFF_UP; |
211 | } | 217 | } |
212 | 218 | ||
213 | 219 | ||
220 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) | ||
221 | { | ||
222 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | ||
223 | sa->sin_family = AF_INET; | ||
224 | sa->sin_port = 0; | ||
225 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | ||
226 | ioctl( SIOCSIFADDR ); | ||
227 | } | ||
228 | |||
229 | |||
214 | QString ONetworkInterface::ipV4Address() const | 230 | QString ONetworkInterface::ipV4Address() const |
215 | { | 231 | { |
216 | if ( ioctl( SIOCGIFADDR ) ) | 232 | if ( ioctl( SIOCGIFADDR ) ) |
217 | { | 233 | { |
218 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 234 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
219 | //FIXME: Use QHostAddress here | 235 | //FIXME: Use QHostAddress here |
220 | return QString( inet_ntoa( sa->sin_addr ) ); | 236 | return QString( inet_ntoa( sa->sin_addr ) ); |
221 | } | 237 | } |
222 | else | 238 | else |
223 | return "<unknown>"; | 239 | return "<unknown>"; |
224 | } | 240 | } |
225 | 241 | ||
226 | 242 | ||
227 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) | 243 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) |
228 | { | 244 | { |
229 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | 245 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
230 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); | 246 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); |
231 | ioctl( SIOCSIFHWADDR ); | 247 | ioctl( SIOCSIFHWADDR ); |
232 | } | 248 | } |
233 | 249 | ||
234 | 250 | ||
235 | OMacAddress ONetworkInterface::macAddress() const | 251 | OMacAddress ONetworkInterface::macAddress() const |
236 | { | 252 | { |
237 | if ( ioctl( SIOCGIFHWADDR ) ) | 253 | if ( ioctl( SIOCGIFHWADDR ) ) |
238 | { | 254 | { |
239 | return OMacAddress( _ifr ); | 255 | return OMacAddress( _ifr ); |
240 | } | 256 | } |
241 | else | 257 | else |
242 | { | 258 | { |
243 | return OMacAddress::unknown; | 259 | return OMacAddress::unknown; |
244 | } | 260 | } |
245 | } | 261 | } |
246 | 262 | ||
247 | 263 | ||
264 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) | ||
265 | { | ||
266 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | ||
267 | sa->sin_family = AF_INET; | ||
268 | sa->sin_port = 0; | ||
269 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | ||
270 | ioctl( SIOCSIFNETMASK ); | ||
271 | } | ||
272 | |||
273 | |||
274 | QString ONetworkInterface::ipV4Netmask() const | ||
275 | { | ||
276 | if ( ioctl( SIOCGIFNETMASK ) ) | ||
277 | { | ||
278 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | ||
279 | //FIXME: Use QHostAddress here | ||
280 | return QString( inet_ntoa( sa->sin_addr ) ); | ||
281 | } | ||
282 | else | ||
283 | return "<unknown>"; | ||
284 | } | ||
285 | |||
286 | |||
248 | int ONetworkInterface::dataLinkType() const | 287 | int ONetworkInterface::dataLinkType() const |
249 | { | 288 | { |
250 | if ( ioctl( SIOCGIFHWADDR ) ) | 289 | if ( ioctl( SIOCGIFHWADDR ) ) |
251 | { | 290 | { |
252 | return _ifr.ifr_hwaddr.sa_family; | 291 | return _ifr.ifr_hwaddr.sa_family; |
253 | } | 292 | } |
254 | else | 293 | else |
255 | { | 294 | { |
256 | return -1; | 295 | return -1; |
257 | } | 296 | } |
258 | } | 297 | } |
259 | 298 | ||
260 | 299 | ||
261 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 300 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
262 | { | 301 | { |
263 | _mon = m; | 302 | _mon = m; |
264 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); | 303 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); |
265 | } | 304 | } |
266 | 305 | ||
267 | 306 | ||
268 | OMonitoringInterface* ONetworkInterface::monitoring() const | 307 | OMonitoringInterface* ONetworkInterface::monitoring() const |
269 | { | 308 | { |
270 | return _mon; | 309 | return _mon; |
271 | } | 310 | } |
272 | 311 | ||
273 | 312 | ||
274 | ONetworkInterface::~ONetworkInterface() | 313 | ONetworkInterface::~ONetworkInterface() |
275 | { | 314 | { |
276 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); | 315 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); |
277 | if ( _sfd != -1 ) ::close( _sfd ); | 316 | if ( _sfd != -1 ) ::close( _sfd ); |
278 | } | 317 | } |
279 | 318 | ||
280 | 319 | ||
281 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 320 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
282 | { | 321 | { |
283 | ioctl( SIOCGIFFLAGS ); | 322 | ioctl( SIOCGIFFLAGS ); |
284 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 323 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
285 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 324 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
286 | return ioctl( SIOCSIFFLAGS ); | 325 | return ioctl( SIOCSIFFLAGS ); |
287 | } | 326 | } |
288 | 327 | ||
289 | 328 | ||
290 | bool ONetworkInterface::promiscuousMode() const | 329 | bool ONetworkInterface::promiscuousMode() const |
291 | { | 330 | { |
292 | ioctl( SIOCGIFFLAGS ); | 331 | ioctl( SIOCGIFFLAGS ); |
293 | return _ifr.ifr_flags & IFF_PROMISC; | 332 | return _ifr.ifr_flags & IFF_PROMISC; |
294 | } | 333 | } |
295 | 334 | ||
296 | 335 | ||
297 | bool ONetworkInterface::isWireless() const | 336 | bool ONetworkInterface::isWireless() const |
298 | { | 337 | { |
299 | return ioctl( SIOCGIWNAME ); | 338 | return ioctl( SIOCGIWNAME ); |
300 | } | 339 | } |
301 | 340 | ||
302 | 341 | ||
303 | /*====================================================================================== | 342 | /*====================================================================================== |
304 | * OChannelHopper | 343 | * OChannelHopper |
305 | *======================================================================================*/ | 344 | *======================================================================================*/ |
306 | 345 | ||
307 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 346 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
308 | :QObject( 0, "Mickey's funky hopper" ), | 347 | :QObject( 0, "Mickey's funky hopper" ), |
309 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 348 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
310 | { | 349 | { |
311 | int _maxChannel = iface->channels()+1; | 350 | int _maxChannel = iface->channels()+1; |
312 | // generate fancy hopping sequence honoring the device capabilities | 351 | // generate fancy hopping sequence honoring the device capabilities |
313 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 352 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
314 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 353 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
315 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 354 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
316 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 355 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
317 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 356 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
318 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 357 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
319 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 358 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
320 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 359 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
321 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 360 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
322 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 361 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
323 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 362 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
324 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 363 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
325 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 364 | if ( _maxChannel >= 6 ) _channels.append( 6 ); |
326 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 365 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
327 | _channel = _channels.begin(); | 366 | _channel = _channels.begin(); |
328 | 367 | ||
329 | } | 368 | } |
330 | 369 | ||
331 | 370 | ||
332 | OChannelHopper::~OChannelHopper() | 371 | OChannelHopper::~OChannelHopper() |
333 | { | 372 | { |
334 | } | 373 | } |
335 | 374 | ||
336 | 375 | ||
337 | bool OChannelHopper::isActive() const | 376 | bool OChannelHopper::isActive() const |
338 | { | 377 | { |
339 | return _tid; | 378 | return _tid; |
340 | } | 379 | } |
341 | 380 | ||
342 | 381 | ||
343 | int OChannelHopper::channel() const | 382 | int OChannelHopper::channel() const |
344 | { | 383 | { |
345 | return *_channel; | 384 | return *_channel; |
346 | } | 385 | } |
347 | 386 | ||
348 | 387 | ||
349 | void OChannelHopper::timerEvent( QTimerEvent* ) | 388 | void OChannelHopper::timerEvent( QTimerEvent* ) |
350 | { | 389 | { |
351 | _iface->setChannel( *_channel ); | 390 | _iface->setChannel( *_channel ); |
352 | emit( hopped( *_channel ) ); | 391 | emit( hopped( *_channel ) ); |
353 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 392 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", |
354 | *_channel, (const char*) _iface->name() ); | 393 | *_channel, (const char*) _iface->name() ); |
355 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 394 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
356 | } | 395 | } |
357 | 396 | ||
358 | 397 | ||
359 | void OChannelHopper::setInterval( int interval ) | 398 | void OChannelHopper::setInterval( int interval ) |
360 | { | 399 | { |
361 | if ( interval == _interval ) | 400 | if ( interval == _interval ) |
362 | return; | 401 | return; |
363 | 402 | ||
364 | if ( _interval ) | 403 | if ( _interval ) |
365 | killTimer( _tid ); | 404 | killTimer( _tid ); |
366 | 405 | ||
367 | _tid = 0; | 406 | _tid = 0; |
368 | _interval = interval; | 407 | _interval = interval; |
369 | 408 | ||
370 | if ( _interval ) | 409 | if ( _interval ) |
371 | { | 410 | { |
372 | _tid = startTimer( interval ); | 411 | _tid = startTimer( interval ); |
373 | } | 412 | } |
374 | } | 413 | } |
375 | 414 | ||
376 | 415 | ||
377 | int OChannelHopper::interval() const | 416 | int OChannelHopper::interval() const |
378 | { | 417 | { |
379 | return _interval; | 418 | return _interval; |
380 | } | 419 | } |
381 | 420 | ||
382 | 421 | ||
383 | /*====================================================================================== | 422 | /*====================================================================================== |
384 | * OWirelessNetworkInterface | 423 | * OWirelessNetworkInterface |
385 | *======================================================================================*/ | 424 | *======================================================================================*/ |
386 | 425 | ||
387 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 426 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
388 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 427 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
389 | { | 428 | { |
390 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 429 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); |
391 | init(); | 430 | init(); |
392 | } | 431 | } |
393 | 432 | ||
394 | 433 | ||
395 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 434 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
396 | { | 435 | { |
397 | } | 436 | } |
398 | 437 | ||
399 | 438 | ||
400 | struct iwreq& OWirelessNetworkInterface::iwr() const | 439 | struct iwreq& OWirelessNetworkInterface::iwr() const |
401 | { | 440 | { |
402 | return _iwr; | 441 | return _iwr; |
403 | } | 442 | } |
404 | 443 | ||
405 | 444 | ||
406 | void OWirelessNetworkInterface::init() | 445 | void OWirelessNetworkInterface::init() |
407 | { | 446 | { |
408 | qDebug( "OWirelessNetworkInterface::init()" ); | 447 | qDebug( "OWirelessNetworkInterface::init()" ); |
409 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 448 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
410 | buildChannelList(); | 449 | buildChannelList(); |
411 | buildPrivateList(); | 450 | buildPrivateList(); |
412 | } | 451 | } |
413 | 452 | ||
414 | 453 | ||
415 | QString OWirelessNetworkInterface::associatedAP() const | 454 | QString OWirelessNetworkInterface::associatedAP() const |
416 | { | 455 | { |
417 | //FIXME: use OMacAddress | 456 | //FIXME: use OMacAddress |
418 | QString mac; | 457 | QString mac; |
419 | 458 | ||
420 | if ( ioctl( SIOCGIWAP ) ) | 459 | if ( ioctl( SIOCGIWAP ) ) |
421 | { | 460 | { |
422 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 461 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
423 | _ifr.ifr_hwaddr.sa_data[0]&0xff, | 462 | _ifr.ifr_hwaddr.sa_data[0]&0xff, |
424 | _ifr.ifr_hwaddr.sa_data[1]&0xff, | 463 | _ifr.ifr_hwaddr.sa_data[1]&0xff, |
425 | _ifr.ifr_hwaddr.sa_data[2]&0xff, | 464 | _ifr.ifr_hwaddr.sa_data[2]&0xff, |
426 | _ifr.ifr_hwaddr.sa_data[3]&0xff, | 465 | _ifr.ifr_hwaddr.sa_data[3]&0xff, |
427 | _ifr.ifr_hwaddr.sa_data[4]&0xff, | 466 | _ifr.ifr_hwaddr.sa_data[4]&0xff, |
428 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); | 467 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); |
429 | } | 468 | } |
430 | else | 469 | else |
431 | { | 470 | { |
432 | mac = "<Unknown>"; | 471 | mac = "<Unknown>"; |
433 | } | 472 | } |
434 | return mac; | 473 | return mac; |
435 | } | 474 | } |
436 | 475 | ||
437 | 476 | ||
438 | void OWirelessNetworkInterface::buildChannelList() | 477 | void OWirelessNetworkInterface::buildChannelList() |
439 | { | 478 | { |
440 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 479 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
441 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | 480 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete |
442 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 481 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
443 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | 482 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate |
444 | //ML: _too much_ space. This is damn shitty crap *sigh* | 483 | //ML: _too much_ space. This is damn shitty crap *sigh* |
445 | //ML: We allocate a large memory region in RAM and check whether the | 484 | //ML: We allocate a large memory region in RAM and check whether the |
446 | //ML: driver pollutes this extra space. The complaint will be made on stdout, | 485 | //ML: driver pollutes this extra space. The complaint will be made on stdout, |
447 | //ML: so please forward this... | 486 | //ML: so please forward this... |
448 | 487 | ||
449 | struct iwreq wrq; | 488 | struct iwreq wrq; |
450 | int len = sizeof( struct iw_range )*2; | 489 | int len = sizeof( struct iw_range )*2; |
451 | char *buffer = (char*) malloc( len ); | 490 | char *buffer = (char*) malloc( len ); |
452 | //FIXME: Validate if we actually got the memory block | 491 | //FIXME: Validate if we actually got the memory block |
453 | memset( buffer, 0, len ); | 492 | memset( buffer, 0, len ); |
454 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | 493 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); |
455 | wrq.u.data.pointer = (caddr_t) buffer; | 494 | wrq.u.data.pointer = (caddr_t) buffer; |
456 | wrq.u.data.length = sizeof( struct iw_range ); | 495 | wrq.u.data.length = sizeof( struct iw_range ); |
457 | wrq.u.data.flags = 0; | 496 | wrq.u.data.flags = 0; |
458 | 497 | ||
459 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 498 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
460 | { | 499 | { |
461 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); | 500 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); |
462 | _channels.insert( 2412, 1 ); // 2.412 GHz | 501 | _channels.insert( 2412, 1 ); // 2.412 GHz |
463 | _channels.insert( 2417, 2 ); // 2.417 GHz | 502 | _channels.insert( 2417, 2 ); // 2.417 GHz |
464 | _channels.insert( 2422, 3 ); // 2.422 GHz | 503 | _channels.insert( 2422, 3 ); // 2.422 GHz |
465 | _channels.insert( 2427, 4 ); // 2.427 GHz | 504 | _channels.insert( 2427, 4 ); // 2.427 GHz |
466 | _channels.insert( 2432, 5 ); // 2.432 GHz | 505 | _channels.insert( 2432, 5 ); // 2.432 GHz |
467 | _channels.insert( 2437, 6 ); // 2.437 GHz | 506 | _channels.insert( 2437, 6 ); // 2.437 GHz |
468 | _channels.insert( 2442, 7 ); // 2.442 GHz | 507 | _channels.insert( 2442, 7 ); // 2.442 GHz |
469 | _channels.insert( 2447, 8 ); // 2.447 GHz | 508 | _channels.insert( 2447, 8 ); // 2.447 GHz |
470 | _channels.insert( 2452, 9 ); // 2.452 GHz | 509 | _channels.insert( 2452, 9 ); // 2.452 GHz |
471 | _channels.insert( 2457, 10 ); // 2.457 GHz | 510 | _channels.insert( 2457, 10 ); // 2.457 GHz |
472 | _channels.insert( 2462, 11 ); // 2.462 GHz | 511 | _channels.insert( 2462, 11 ); // 2.462 GHz |
473 | } | 512 | } |
474 | else | 513 | else |
475 | { | 514 | { |
476 | // <check if the driver overwrites stuff> | 515 | // <check if the driver overwrites stuff> |
477 | int max = 0; | 516 | int max = 0; |
478 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 517 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
479 | if (buffer[r] != 0) | 518 | if (buffer[r] != 0) |
480 | max = r; | 519 | max = r; |
481 | if (max > 0) | 520 | if (max > 0) |
482 | { | 521 | { |
483 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" | 522 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" |
484 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); | 523 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); |
485 | } | 524 | } |
486 | // </check if the driver overwrites stuff> | 525 | // </check if the driver overwrites stuff> |
487 | 526 | ||
488 | struct iw_range range; | 527 | struct iw_range range; |
489 | memcpy( &range, buffer, sizeof range ); | 528 | memcpy( &range, buffer, sizeof range ); |
490 | 529 | ||
491 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | 530 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); |
492 | for ( int i = 0; i < range.num_frequency; ++i ) | 531 | for ( int i = 0; i < range.num_frequency; ++i ) |
493 | { | 532 | { |
494 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 533 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
495 | _channels.insert( freq, i+1 ); | 534 | _channels.insert( freq, i+1 ); |
496 | } | 535 | } |
497 | } | 536 | } |
498 | 537 | ||
499 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); | 538 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); |
500 | free(buffer); | 539 | free(buffer); |
501 | } | 540 | } |
502 | 541 | ||
503 | 542 | ||
504 | void OWirelessNetworkInterface::buildPrivateList() | 543 | void OWirelessNetworkInterface::buildPrivateList() |
505 | { | 544 | { |
506 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | 545 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); |
507 | 546 | ||
508 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 547 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
509 | 548 | ||
510 | _iwr.u.data.pointer = (char*) &priv; | 549 | _iwr.u.data.pointer = (char*) &priv; |
511 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | 550 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself |
512 | _iwr.u.data.flags = 0; | 551 | _iwr.u.data.flags = 0; |
513 | 552 | ||
514 | if ( !wioctl( SIOCGIWPRIV ) ) | 553 | if ( !wioctl( SIOCGIWPRIV ) ) |
515 | { | 554 | { |
516 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); | 555 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); |
517 | return; | 556 | return; |
518 | } | 557 | } |
519 | 558 | ||
520 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 559 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
521 | { | 560 | { |
522 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 561 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
523 | } | 562 | } |
524 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); | 563 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); |
525 | } | 564 | } |
526 | 565 | ||
527 | 566 | ||
528 | int OWirelessNetworkInterface::channel() const | 567 | int OWirelessNetworkInterface::channel() const |
529 | { | 568 | { |
530 | //FIXME: When monitoring enabled, then use it | 569 | //FIXME: When monitoring enabled, then use it |
531 | //FIXME: to gather the current RF channel | 570 | //FIXME: to gather the current RF channel |
532 | //FIXME: Until then, get active channel from hopper. | 571 | //FIXME: Until then, get active channel from hopper. |
533 | if ( _hopper && _hopper->isActive() ) | 572 | if ( _hopper && _hopper->isActive() ) |
534 | return _hopper->channel(); | 573 | return _hopper->channel(); |
535 | 574 | ||
536 | if ( !wioctl( SIOCGIWFREQ ) ) | 575 | if ( !wioctl( SIOCGIWFREQ ) ) |
537 | { | 576 | { |
538 | return -1; | 577 | return -1; |
539 | } | 578 | } |
540 | else | 579 | else |
541 | { | 580 | { |
542 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; | 581 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; |
543 | } | 582 | } |
544 | } | 583 | } |
545 | 584 | ||
546 | 585 | ||
547 | void OWirelessNetworkInterface::setChannel( int c ) const | 586 | void OWirelessNetworkInterface::setChannel( int c ) const |
548 | { | 587 | { |
549 | if ( !_mon ) | 588 | if ( !_mon ) |
550 | { | 589 | { |
551 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 590 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
552 | _iwr.u.freq.m = c; | 591 | _iwr.u.freq.m = c; |
553 | _iwr.u.freq.e = 0; | 592 | _iwr.u.freq.e = 0; |
554 | wioctl( SIOCSIWFREQ ); | 593 | wioctl( SIOCSIWFREQ ); |
555 | } | 594 | } |
556 | else | 595 | else |
557 | { | 596 | { |
558 | _mon->setChannel( c ); | 597 | _mon->setChannel( c ); |
559 | } | 598 | } |
560 | } | 599 | } |
561 | 600 | ||
562 | 601 | ||
563 | double OWirelessNetworkInterface::frequency() const | 602 | double OWirelessNetworkInterface::frequency() const |
564 | { | 603 | { |
565 | if ( !wioctl( SIOCGIWFREQ ) ) | 604 | if ( !wioctl( SIOCGIWFREQ ) ) |
566 | { | 605 | { |
567 | return -1.0; | 606 | return -1.0; |
568 | } | 607 | } |
569 | else | 608 | else |
570 | { | 609 | { |
571 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 610 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
572 | } | 611 | } |
573 | } | 612 | } |
574 | 613 | ||
575 | 614 | ||
576 | int OWirelessNetworkInterface::channels() const | 615 | int OWirelessNetworkInterface::channels() const |
577 | { | 616 | { |
578 | return _channels.count(); | 617 | return _channels.count(); |
579 | } | 618 | } |
580 | 619 | ||
581 | 620 | ||
582 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 621 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
583 | { | 622 | { |
584 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 623 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
585 | _hopper->setInterval( interval ); | 624 | _hopper->setInterval( interval ); |
586 | //FIXME: When and by whom will the channel hopper be deleted? | 625 | //FIXME: When and by whom will the channel hopper be deleted? |
587 | //TODO: rely on QObject hierarchy | 626 | //TODO: rely on QObject hierarchy |
588 | } | 627 | } |
589 | 628 | ||
590 | 629 | ||
591 | int OWirelessNetworkInterface::channelHopping() const | 630 | int OWirelessNetworkInterface::channelHopping() const |
592 | { | 631 | { |
593 | return _hopper->interval(); | 632 | return _hopper->interval(); |
594 | } | 633 | } |
595 | 634 | ||
596 | 635 | ||
597 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const | 636 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const |
598 | { | 637 | { |
599 | return _hopper; | 638 | return _hopper; |
600 | } | 639 | } |
601 | 640 | ||
602 | 641 | ||
603 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 642 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
604 | { | 643 | { |
605 | if ( _mon ) | 644 | if ( _mon ) |
606 | _mon->setEnabled( b ); | 645 | _mon->setEnabled( b ); |
607 | else | 646 | else |
608 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 647 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
609 | } | 648 | } |
610 | 649 | ||
611 | 650 | ||
612 | bool OWirelessNetworkInterface::monitorMode() const | 651 | bool OWirelessNetworkInterface::monitorMode() const |
613 | { | 652 | { |
614 | qDebug( "dataLinkType = %d", dataLinkType() ); | 653 | qDebug( "dataLinkType = %d", dataLinkType() ); |
615 | return dataLinkType() == ARPHRD_IEEE80211; | 654 | return dataLinkType() == ARPHRD_IEEE80211; |
616 | } | 655 | } |
617 | 656 | ||
618 | 657 | ||
619 | QString OWirelessNetworkInterface::nickName() const | 658 | QString OWirelessNetworkInterface::nickName() const |
620 | { | 659 | { |
621 | char str[IW_ESSID_MAX_SIZE]; | 660 | char str[IW_ESSID_MAX_SIZE]; |
622 | _iwr.u.data.pointer = &str[0]; | 661 | _iwr.u.data.pointer = &str[0]; |
623 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 662 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
624 | if ( !wioctl( SIOCGIWNICKN ) ) | 663 | if ( !wioctl( SIOCGIWNICKN ) ) |
625 | { | 664 | { |
626 | return "<unknown>"; | 665 | return "<unknown>"; |
627 | } | 666 | } |
628 | else | 667 | else |
629 | { | 668 | { |
630 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 669 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
631 | return str; | 670 | return str; |
632 | } | 671 | } |
633 | } | 672 | } |
634 | 673 | ||
635 | 674 | ||
636 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 675 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
637 | { | 676 | { |
638 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 677 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
639 | if ( !priv ) | 678 | if ( !priv ) |
640 | { | 679 | { |
641 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); | 680 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); |
642 | return; | 681 | return; |
643 | } | 682 | } |
644 | if ( priv->numberSetArgs() != numargs ) | 683 | if ( priv->numberSetArgs() != numargs ) |
645 | { | 684 | { |
646 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); | 685 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); |
647 | return; | 686 | return; |
648 | } | 687 | } |
649 | 688 | ||
650 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); | 689 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); |
651 | memset( &_iwr, 0, sizeof _iwr ); | 690 | memset( &_iwr, 0, sizeof _iwr ); |
652 | va_list argp; | 691 | va_list argp; |
653 | va_start( argp, numargs ); | 692 | va_start( argp, numargs ); |
654 | for ( int i = 0; i < numargs; ++i ) | 693 | for ( int i = 0; i < numargs; ++i ) |
655 | { | 694 | { |
656 | priv->setParameter( i, va_arg( argp, int ) ); | 695 | priv->setParameter( i, va_arg( argp, int ) ); |
657 | } | 696 | } |
658 | va_end( argp ); | 697 | va_end( argp ); |
659 | priv->invoke(); | 698 | priv->invoke(); |
660 | } | 699 | } |
661 | 700 | ||
662 | 701 | ||
663 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 702 | void OWirelessNetworkInterface::getPrivate( const QString& call ) |
664 | { | 703 | { |
665 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); | 704 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); |
666 | } | 705 | } |
667 | 706 | ||
668 | 707 | ||
669 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | 708 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) |
670 | { | 709 | { |
671 | return child( (const char*) call ); | 710 | return child( (const char*) call ); |
672 | } | 711 | } |
673 | 712 | ||
674 | 713 | ||
675 | QString OWirelessNetworkInterface::SSID() const | 714 | QString OWirelessNetworkInterface::SSID() const |
676 | { | 715 | { |
677 | char str[IW_ESSID_MAX_SIZE]; | 716 | char str[IW_ESSID_MAX_SIZE]; |
678 | _iwr.u.essid.pointer = &str[0]; | 717 | _iwr.u.essid.pointer = &str[0]; |
679 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 718 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
680 | if ( !wioctl( SIOCGIWESSID ) ) | 719 | if ( !wioctl( SIOCGIWESSID ) ) |
681 | { | 720 | { |
682 | return "<unknown>"; | 721 | return "<unknown>"; |
683 | } | 722 | } |
684 | else | 723 | else |
685 | { | 724 | { |
686 | return str; | 725 | return str; |
687 | } | 726 | } |
688 | } | 727 | } |
689 | 728 | ||
690 | 729 | ||
691 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 730 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
692 | { | 731 | { |
693 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 732 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
694 | _iwr.u.essid.length = ssid.length(); | 733 | _iwr.u.essid.length = ssid.length(); |
695 | wioctl( SIOCSIWESSID ); | 734 | wioctl( SIOCSIWESSID ); |
696 | } | 735 | } |
697 | 736 | ||
698 | 737 | ||
699 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 738 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
700 | { | 739 | { |
701 | int result = ::ioctl( _sfd, call, &iwreq ); | 740 | int result = ::ioctl( _sfd, call, &iwreq ); |
702 | if ( result == -1 ) | 741 | if ( result == -1 ) |
703 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 742 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); |
704 | else | 743 | else |
705 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); | 744 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); |
706 | return ( result != -1 ); | 745 | return ( result != -1 ); |
707 | } | 746 | } |
708 | 747 | ||
709 | 748 | ||
710 | bool OWirelessNetworkInterface::wioctl( int call ) const | 749 | bool OWirelessNetworkInterface::wioctl( int call ) const |
711 | { | 750 | { |
712 | strcpy( _iwr.ifr_name, name() ); | 751 | strcpy( _iwr.ifr_name, name() ); |
713 | return wioctl( call, _iwr ); | 752 | return wioctl( call, _iwr ); |
714 | } | 753 | } |
715 | 754 | ||
716 | 755 | ||
717 | /*====================================================================================== | 756 | /*====================================================================================== |
718 | * OMonitoringInterface | 757 | * OMonitoringInterface |
719 | *======================================================================================*/ | 758 | *======================================================================================*/ |
720 | 759 | ||
721 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) | 760 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) |
722 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) | 761 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) |
723 | { | 762 | { |
724 | } | 763 | } |
725 | 764 | ||
726 | 765 | ||
727 | OMonitoringInterface::~OMonitoringInterface() | 766 | OMonitoringInterface::~OMonitoringInterface() |
728 | { | 767 | { |
729 | } | 768 | } |
730 | 769 | ||
731 | 770 | ||
732 | void OMonitoringInterface::setChannel( int c ) | 771 | void OMonitoringInterface::setChannel( int c ) |
733 | { | 772 | { |
734 | // use standard WE channel switching protocol | 773 | // use standard WE channel switching protocol |
735 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 774 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
736 | _if->_iwr.u.freq.m = c; | 775 | _if->_iwr.u.freq.m = c; |
737 | _if->_iwr.u.freq.e = 0; | 776 | _if->_iwr.u.freq.e = 0; |
738 | _if->wioctl( SIOCSIWFREQ ); | 777 | _if->wioctl( SIOCSIWFREQ ); |
739 | } | 778 | } |
740 | 779 | ||
741 | 780 | ||
742 | bool OMonitoringInterface::enabled() const | 781 | bool OMonitoringInterface::enabled() const |
743 | { | 782 | { |
744 | return _if->monitorMode(); | 783 | return _if->monitorMode(); |
745 | } | 784 | } |
746 | 785 | ||
747 | 786 | ||
748 | void OMonitoringInterface::setEnabled( bool b ) | 787 | void OMonitoringInterface::setEnabled( bool b ) |
749 | { | 788 | { |
750 | } | 789 | } |
751 | 790 | ||
752 | 791 | ||
753 | /*====================================================================================== | 792 | /*====================================================================================== |
754 | * OCiscoMonitoringInterface | 793 | * OCiscoMonitoringInterface |
755 | *======================================================================================*/ | 794 | *======================================================================================*/ |
756 | 795 | ||
757 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) | 796 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) |
758 | :OMonitoringInterface( iface ) | 797 | :OMonitoringInterface( iface ) |
759 | { | 798 | { |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index db8e702..2348bbc 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -1,472 +1,493 @@ | |||
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 need 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 a 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 | class ONetworkInterface; | 66 | class ONetworkInterface; |
67 | class OWirelessNetworkInterface; | 67 | class OWirelessNetworkInterface; |
68 | class OChannelHopper; | 68 | class OChannelHopper; |
69 | class OMonitoringInterface; | 69 | class OMonitoringInterface; |
70 | 70 | ||
71 | /*====================================================================================== | 71 | /*====================================================================================== |
72 | * ONetwork | 72 | * ONetwork |
73 | *======================================================================================*/ | 73 | *======================================================================================*/ |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * @brief A container class for all network devices. | 76 | * @brief A container class for all network interfaces |
77 | * | 77 | * |
78 | * This class provides access to all available network devices of your computer. | 78 | * This class provides access to all available network interfaces of your computer. |
79 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 79 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
80 | */ | 80 | */ |
81 | class ONetwork : public QObject | 81 | class ONetwork : public QObject |
82 | { | 82 | { |
83 | Q_OBJECT | 83 | Q_OBJECT |
84 | 84 | ||
85 | public: | 85 | public: |
86 | typedef QDict<ONetworkInterface> InterfaceMap; | 86 | typedef QDict<ONetworkInterface> InterfaceMap; |
87 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; | 87 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; |
88 | 88 | ||
89 | public: | 89 | public: |
90 | /** | 90 | /** |
91 | * @returns the number of available interfaces | ||
92 | */ | ||
93 | int count() const; | ||
94 | /** | ||
91 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 95 | * @returns a pointer to the (one and only) @ref ONetwork instance. |
92 | */ | 96 | */ |
93 | static ONetwork* instance(); | 97 | static ONetwork* instance(); |
94 | /** | 98 | /** |
95 | * @returns an iterator usable for iterating through all network interfaces. | 99 | * @returns an iterator usable for iterating through all network interfaces. |
96 | */ | 100 | */ |
97 | InterfaceIterator iterator() const; | 101 | InterfaceIterator iterator() const; |
98 | /** | 102 | /** |
99 | * @returns true, if the @p interface supports the wireless extension protocol. | 103 | * @returns true, if the @p interface supports the wireless extension protocol. |
100 | */ | 104 | */ |
101 | // FIXME QString? -zecke | 105 | // FIXME QString? -zecke |
102 | bool isWirelessInterface( const char* interface ) const; | 106 | bool isWirelessInterface( const char* interface ) const; |
103 | /** | 107 | /** |
104 | * @returns a pointer to the @ref ONetworkInterface object for the specified @p interface or 0, if not found | 108 | * @returns a pointer to the @ref ONetworkInterface object for the specified @p interface or 0, if not found |
105 | * @see ONetworkInterface | 109 | * @see ONetworkInterface |
106 | */ | 110 | */ |
107 | // FIXME: const QString& is prefered over QString!!! -zecke | 111 | // FIXME: const QString& is prefered over QString!!! -zecke |
108 | ONetworkInterface* interface( const QString& interface ) const; | 112 | ONetworkInterface* interface( const QString& interface ) const; |
113 | /** | ||
114 | * @internal Rebuild the internal interface database | ||
115 | * @note Sometimes it might be useful to call this from client code, | ||
116 | * e.g. after cardctl insert | ||
117 | */ | ||
118 | void synchronize(); | ||
109 | 119 | ||
110 | protected: | 120 | protected: |
111 | ONetwork(); | 121 | ONetwork(); |
112 | void synchronize(); | ||
113 | 122 | ||
114 | private: | 123 | private: |
115 | static ONetwork* _instance; | 124 | static ONetwork* _instance; |
116 | InterfaceMap _interfaces; | 125 | InterfaceMap _interfaces; |
117 | }; | 126 | }; |
118 | 127 | ||
119 | 128 | ||
120 | /*====================================================================================== | 129 | /*====================================================================================== |
121 | * ONetworkInterface | 130 | * ONetworkInterface |
122 | *======================================================================================*/ | 131 | *======================================================================================*/ |
123 | 132 | ||
124 | /** | 133 | /** |
125 | * @brief A network interface wrapper. | 134 | * @brief A network interface wrapper. |
126 | * | 135 | * |
127 | * This class provides a wrapper for a network interface. All the cumbersume details of | 136 | * This class provides a wrapper for a network interface. All the cumbersume details of |
128 | * Linux ioctls are hidden under a convenient high-level interface. | 137 | * Linux ioctls are hidden under a convenient high-level interface. |
129 | * @warning Most of the setting methods contained in this class require the appropriate | 138 | * @warning Most of the setting methods contained in this class require the appropriate |
130 | * process permissions to work. | 139 | * process permissions to work. |
131 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 140 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
132 | */ | 141 | */ |
133 | class ONetworkInterface : public QObject | 142 | class ONetworkInterface : public QObject |
134 | { | 143 | { |
135 | friend class OMonitoringInterface; | 144 | friend class OMonitoringInterface; |
136 | friend class OCiscoMonitoringInterface; | 145 | friend class OCiscoMonitoringInterface; |
137 | friend class OWlanNGMonitoringInterface; | 146 | friend class OWlanNGMonitoringInterface; |
138 | friend class OHostAPMonitoringInterface; | 147 | friend class OHostAPMonitoringInterface; |
139 | friend class OOrinocoMonitoringInterface; | 148 | friend class OOrinocoMonitoringInterface; |
140 | 149 | ||
141 | public: | 150 | public: |
142 | /** | 151 | /** |
143 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, | 152 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, |
144 | * but access them via @ref ONetwork::interface(). | 153 | * but access them via @ref ONetwork::interface(). |
145 | */ | 154 | */ |
146 | ONetworkInterface( QObject* parent, const char* name ); | 155 | ONetworkInterface( QObject* parent, const char* name ); |
147 | /** | 156 | /** |
148 | * Destructor. | 157 | * Destructor. |
149 | */ | 158 | */ |
150 | virtual ~ONetworkInterface(); | 159 | virtual ~ONetworkInterface(); |
151 | /** | 160 | /** |
152 | * Associates a @a monitoring interface with this network interface. | 161 | * Associates a @a monitoring interface with this network interface. |
153 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. | 162 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. |
154 | */ | 163 | */ |
155 | void setMonitoring( OMonitoringInterface* monitoring ); | 164 | void setMonitoring( OMonitoringInterface* monitoring ); |
156 | /** | 165 | /** |
157 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. | 166 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. |
158 | */ | 167 | */ |
159 | OMonitoringInterface* monitoring() const; | 168 | OMonitoringInterface* monitoring() const; |
160 | /** | 169 | /** |
161 | * Setting an interface to promiscuous mode enables the device to receive | 170 | * Setting an interface to promiscuous mode enables the device to receive |
162 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. | 171 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. |
163 | */ | 172 | */ |
164 | bool setPromiscuousMode( bool ); | 173 | bool setPromiscuousMode( bool ); |
165 | /** | 174 | /** |
166 | * @returns true if the interface is set to promiscuous mode. | 175 | * @returns true if the interface is set to promiscuous mode. |
167 | */ | 176 | */ |
168 | bool promiscuousMode() const; | 177 | bool promiscuousMode() const; |
169 | /** | 178 | /** |
170 | * Setting an interface to up enables it to receive packets. | 179 | * Setting an interface to up enables it to receive packets. |
171 | */ | 180 | */ |
172 | bool setUp( bool ); | 181 | bool setUp( bool ); |
173 | /** | 182 | /** |
174 | * @returns true if the interface is up. | 183 | * @returns true if the interface is up. |
175 | */ | 184 | */ |
176 | bool isUp() const; | 185 | bool isUp() const; |
177 | /* | 186 | /** |
178 | * @returns true if the interface is a loopback interface. | 187 | * @returns true if the interface is a loopback interface. |
179 | */ | 188 | */ |
180 | bool isLoopback() const; | 189 | bool isLoopback() const; |
181 | /* | 190 | /** |
182 | * @returns true if the interface is featuring supports the wireless extension protocol. | 191 | * @returns true if the interface is featuring supports the wireless extension protocol. |
183 | */ | 192 | */ |
184 | bool isWireless() const; | 193 | bool isWireless() const; |
185 | /* | 194 | /** |
186 | * @returns the IPv4 address associated with this interface. | 195 | * Associate the IP address @ addr with the interface. |
196 | */ | ||
197 | void setIPV4Address( const QHostAddress& addr ); | ||
198 | /** | ||
199 | * @returns the IPv4 address associated with the interface. | ||
187 | */ | 200 | */ |
188 | QString ipV4Address() const; | 201 | QString ipV4Address() const; |
189 | /* | 202 | /** |
190 | * Associate the MAC address @a addr with the interface. | 203 | * Associate the MAC address @a addr with the interface. |
191 | * @note It can be necessary to shut down the interface prior to calling this method. | 204 | * @note It can be necessary to shut down the interface prior to calling this method. |
192 | * @warning This is not supported by all drivers. | 205 | * @warning This is not supported by all drivers. |
193 | */ | 206 | */ |
194 | void setMacAddress( const OMacAddress& addr ); | 207 | void setMacAddress( const OMacAddress& addr ); |
195 | /* | 208 | /** |
196 | * @returns the MAC address associated with this interface. | 209 | * @returns the MAC address associated with the interface. |
197 | */ | 210 | */ |
198 | OMacAddress macAddress() const; | 211 | OMacAddress macAddress() const; |
199 | /* | 212 | /** |
200 | * @returns the data link type currently associated with this interface. | 213 | * Associate the IPv4 @a netmask with the interface. |
214 | */ | ||
215 | void setIPV4Netmask( const QHostAddress& netmask ); | ||
216 | /** | ||
217 | * @returns the IPv4 netmask associated with the interface. | ||
218 | */ | ||
219 | QString ipV4Netmask() const; | ||
220 | /** | ||
221 | * @returns the data link type currently associated with the interface. | ||
201 | * @see #include <net/if_arp.h> for possible values. | 222 | * @see #include <net/if_arp.h> for possible values. |
202 | */ | 223 | */ |
203 | int dataLinkType() const; | 224 | int dataLinkType() const; |
204 | 225 | ||
205 | protected: | 226 | protected: |
206 | const int _sfd; | 227 | const int _sfd; |
207 | mutable ifreq _ifr; | 228 | mutable ifreq _ifr; |
208 | OMonitoringInterface* _mon; | 229 | OMonitoringInterface* _mon; |
209 | 230 | ||
210 | protected: | 231 | protected: |
211 | struct ifreq& ifr() const; | 232 | struct ifreq& ifr() const; |
212 | virtual void init(); | 233 | virtual void init(); |
213 | bool ioctl( int call ) const; | 234 | bool ioctl( int call ) const; |
214 | bool ioctl( int call, struct ifreq& ) const; | 235 | bool ioctl( int call, struct ifreq& ) const; |
215 | }; | 236 | }; |
216 | 237 | ||
217 | /*====================================================================================== | 238 | /*====================================================================================== |
218 | * OChannelHopper | 239 | * OChannelHopper |
219 | *======================================================================================*/ | 240 | *======================================================================================*/ |
220 | 241 | ||
221 | /** | 242 | /** |
222 | * @brief A radio frequency channel hopper. | 243 | * @brief A radio frequency channel hopper. |
223 | * | 244 | * |
224 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently | 245 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently |
225 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. | 246 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. |
226 | * This is necessary when in monitoring mode and scanning for other devices, because | 247 | * This is necessary when in monitoring mode and scanning for other devices, because |
227 | * the radio frequency hardware can only detect packets sent on the same frequency. | 248 | * the radio frequency hardware can only detect packets sent on the same frequency. |
228 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 249 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
229 | */ | 250 | */ |
230 | class OChannelHopper : public QObject | 251 | class OChannelHopper : public QObject |
231 | { | 252 | { |
232 | Q_OBJECT | 253 | Q_OBJECT |
233 | 254 | ||
234 | public: | 255 | public: |
235 | OChannelHopper( OWirelessNetworkInterface* ); | 256 | OChannelHopper( OWirelessNetworkInterface* ); |
236 | virtual ~OChannelHopper(); | 257 | virtual ~OChannelHopper(); |
237 | bool isActive() const; | 258 | bool isActive() const; |
238 | int channel() const; | 259 | int channel() const; |
239 | virtual void timerEvent( QTimerEvent* ); | 260 | virtual void timerEvent( QTimerEvent* ); |
240 | void setInterval( int ); | 261 | void setInterval( int ); |
241 | int interval() const; | 262 | int interval() const; |
242 | 263 | ||
243 | signals: | 264 | signals: |
244 | void hopped( int ); | 265 | void hopped( int ); |
245 | 266 | ||
246 | private: | 267 | private: |
247 | OWirelessNetworkInterface* _iface; | 268 | OWirelessNetworkInterface* _iface; |
248 | int _interval; | 269 | int _interval; |
249 | int _tid; | 270 | int _tid; |
250 | QValueList<int> _channels; | 271 | QValueList<int> _channels; |
251 | QValueList<int>::Iterator _channel; | 272 | QValueList<int>::Iterator _channel; |
252 | }; | 273 | }; |
253 | 274 | ||
254 | 275 | ||
255 | /*====================================================================================== | 276 | /*====================================================================================== |
256 | * OWirelessNetworkInterface | 277 | * OWirelessNetworkInterface |
257 | *======================================================================================*/ | 278 | *======================================================================================*/ |
258 | 279 | ||
259 | /** | 280 | /** |
260 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. | 281 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. |
261 | * | 282 | * |
262 | * This class provides a high-level encapsulation of the Linux wireless extension API. | 283 | * This class provides a high-level encapsulation of the Linux wireless extension API. |
263 | */ | 284 | */ |
264 | class OWirelessNetworkInterface : public ONetworkInterface | 285 | class OWirelessNetworkInterface : public ONetworkInterface |
265 | { | 286 | { |
266 | friend class OMonitoringInterface; | 287 | friend class OMonitoringInterface; |
267 | friend class OCiscoMonitoringInterface; | 288 | friend class OCiscoMonitoringInterface; |
268 | friend class OWlanNGMonitoringInterface; | 289 | friend class OWlanNGMonitoringInterface; |
269 | friend class OHostAPMonitoringInterface; | 290 | friend class OHostAPMonitoringInterface; |
270 | friend class OOrinocoMonitoringInterface; | 291 | friend class OOrinocoMonitoringInterface; |
271 | 292 | ||
272 | friend class OPrivateIOCTL; | 293 | friend class OPrivateIOCTL; |
273 | 294 | ||
274 | public: | 295 | public: |
275 | enum Mode { AdHoc, Managed, Monitor }; | 296 | enum Mode { AdHoc, Managed, Monitor }; |
276 | 297 | ||
277 | /** | 298 | /** |
278 | * Constructor. | 299 | * Constructor. |
279 | */ | 300 | */ |
280 | OWirelessNetworkInterface( QObject* parent, const char* name ); | 301 | OWirelessNetworkInterface( QObject* parent, const char* name ); |
281 | /** | 302 | /** |
282 | * Destructor. | 303 | * Destructor. |
283 | */ | 304 | */ |
284 | virtual ~OWirelessNetworkInterface(); | 305 | virtual ~OWirelessNetworkInterface(); |
285 | /** | 306 | /** |
286 | * Setting the @a channel of the interface changes the radio frequency (RF) | 307 | * Setting the @a channel of the interface changes the radio frequency (RF) |
287 | * of the corresponding wireless network device. | 308 | * of the corresponding wireless network device. |
288 | */ | 309 | */ |
289 | virtual void setChannel( int channel ) const; | 310 | virtual void setChannel( int channel ) const; |
290 | /** | 311 | /** |
291 | * @returns the channel index of the current radio frequency. | 312 | * @returns the channel index of the current radio frequency. |
292 | */ | 313 | */ |
293 | virtual int channel() const; | 314 | virtual int channel() const; |
294 | /** | 315 | /** |
295 | * @returns the current radio frequency (in MHz). | 316 | * @returns the current radio frequency (in MHz). |
296 | */ | 317 | */ |
297 | virtual double frequency() const; | 318 | virtual double frequency() const; |
298 | /** | 319 | /** |
299 | * @returns the number of radio frequency channels for the | 320 | * @returns the number of radio frequency channels for the |
300 | * corresponding wireless network device. | 321 | * corresponding wireless network device. |
301 | * @note European devices usually have 14 channels, while American typically feature 11 channels. | 322 | * @note European devices usually have 14 channels, while American typically feature 11 channels. |
302 | */ | 323 | */ |
303 | virtual int channels() const; | 324 | virtual int channels() const; |
304 | //virtual double frequency(int) const; | 325 | //virtual double frequency(int) const; |
305 | 326 | ||
306 | virtual void setMode( Mode ) {}; //FIXME: Implement and document this | 327 | virtual void setMode( Mode ) {}; //FIXME: Implement and document this |
307 | virtual bool mode() const {}; //FIXME: Implement and document this | 328 | virtual bool mode() const {}; //FIXME: Implement and document this |
308 | 329 | ||
309 | /** | 330 | /** |
310 | * Setting the monitor mode on a wireless network interface enables | 331 | * Setting the monitor mode on a wireless network interface enables |
311 | * listening to IEEE 802.11 data and management frames which normally | 332 | * listening to IEEE 802.11 data and management frames which normally |
312 | * are handled by the device firmware. This can be used to detect | 333 | * are handled by the device firmware. This can be used to detect |
313 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. | 334 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. |
314 | * @warning Standard wireless network drives don't support the monitor mode. | 335 | * @warning Standard wireless network drives don't support the monitor mode. |
315 | * @warning You need a patched driver for this to work. | 336 | * @warning You need a patched driver for this to work. |
316 | * @note Enabling the monitor mode is highly driver dependent and requires | 337 | * @note Enabling the monitor mode is highly driver dependent and requires |
317 | * the proper @ref OMonitoringInterface to be associated with the interface. | 338 | * the proper @ref OMonitoringInterface to be associated with the interface. |
318 | * @see OMonitoringInterface | 339 | * @see OMonitoringInterface |
319 | */ | 340 | */ |
320 | virtual void setMonitorMode( bool ); | 341 | virtual void setMonitorMode( bool ); |
321 | /** | 342 | /** |
322 | * @returns true if the device is listening in IEEE 802.11 monitor mode | 343 | * @returns true if the device is listening in IEEE 802.11 monitor mode |
323 | */ | 344 | */ |
324 | virtual bool monitorMode() const; | 345 | virtual bool monitorMode() const; |
325 | /** | 346 | /** |
326 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. | 347 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. |
327 | * @see OChannelHopper | 348 | * @see OChannelHopper |
328 | */ | 349 | */ |
329 | virtual void setChannelHopping( int interval = 0 ); | 350 | virtual void setChannelHopping( int interval = 0 ); |
330 | /** | 351 | /** |
331 | * @returns the channel hopping interval or 0, if channel hopping is disabled. | 352 | * @returns the channel hopping interval or 0, if channel hopping is disabled. |
332 | */ | 353 | */ |
333 | virtual int channelHopping() const; | 354 | virtual int channelHopping() const; |
334 | /** | 355 | /** |
335 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before | 356 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before |
336 | */ | 357 | */ |
337 | virtual OChannelHopper* channelHopper() const; | 358 | virtual OChannelHopper* channelHopper() const; |
338 | /** | 359 | /** |
339 | * Set the station @a nickname. | 360 | * Set the station @a nickname. |
340 | */ | 361 | */ |
341 | virtual void setNickName( const QString& nickname ) {}; //FIXME: Implement this | 362 | virtual void setNickName( const QString& nickname ) {}; //FIXME: Implement this |
342 | /** | 363 | /** |
343 | * @returns the current station nickname. | 364 | * @returns the current station nickname. |
344 | */ | 365 | */ |
345 | virtual QString nickName() const; | 366 | virtual QString nickName() const; |
346 | /** | 367 | /** |
347 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. | 368 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. |
348 | * @see OPrivateIOCTL | 369 | * @see OPrivateIOCTL |
349 | */ | 370 | */ |
350 | virtual void setPrivate( const QString& command, int number, ... ); | 371 | virtual void setPrivate( const QString& command, int number, ... ); |
351 | /** | 372 | /** |
352 | * @returns true if the interface is featuring the private IOCTL @command. | 373 | * @returns true if the interface is featuring the private IOCTL @command. |
353 | */ | 374 | */ |
354 | virtual bool hasPrivate( const QString& command ); | 375 | virtual bool hasPrivate( const QString& command ); |
355 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this | 376 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this |
356 | 377 | ||
357 | virtual bool isAssociated() const {}; //FIXME: Implement and document this | 378 | virtual bool isAssociated() const {}; //FIXME: Implement and document this |
358 | virtual QString associatedAP() const; //FIXME: Implement and document this | 379 | virtual QString associatedAP() const; //FIXME: Implement and document this |
359 | 380 | ||
360 | virtual void setSSID( const QString& ); | 381 | virtual void setSSID( const QString& ); |
361 | virtual QString SSID() const; | 382 | virtual QString SSID() const; |
362 | 383 | ||
363 | protected: | 384 | protected: |
364 | void buildChannelList(); | 385 | void buildChannelList(); |
365 | void buildPrivateList(); | 386 | void buildPrivateList(); |
366 | virtual void init(); | 387 | virtual void init(); |
367 | struct iwreq& iwr() const; | 388 | struct iwreq& iwr() const; |
368 | bool wioctl( int call ) const; | 389 | bool wioctl( int call ) const; |
369 | bool wioctl( int call, struct iwreq& ) const; | 390 | bool wioctl( int call, struct iwreq& ) const; |
370 | 391 | ||
371 | protected: | 392 | protected: |
372 | mutable struct iwreq _iwr; | 393 | mutable struct iwreq _iwr; |
373 | QMap<int,int> _channels; | 394 | QMap<int,int> _channels; |
374 | 395 | ||
375 | private: | 396 | private: |
376 | OChannelHopper* _hopper; | 397 | OChannelHopper* _hopper; |
377 | }; | 398 | }; |
378 | 399 | ||
379 | 400 | ||
380 | /*====================================================================================== | 401 | /*====================================================================================== |
381 | * OMonitoringInterface | 402 | * OMonitoringInterface |
382 | *======================================================================================*/ | 403 | *======================================================================================*/ |
383 | 404 | ||
384 | 405 | ||
385 | class OMonitoringInterface | 406 | class OMonitoringInterface |
386 | { | 407 | { |
387 | public: | 408 | public: |
388 | OMonitoringInterface(); | 409 | OMonitoringInterface(); |
389 | OMonitoringInterface( ONetworkInterface* ); | 410 | OMonitoringInterface( ONetworkInterface* ); |
390 | virtual ~OMonitoringInterface(); | 411 | virtual ~OMonitoringInterface(); |
391 | 412 | ||
392 | public: | 413 | public: |
393 | virtual void setEnabled( bool ); | 414 | virtual void setEnabled( bool ); |
394 | virtual bool enabled() const; | 415 | virtual bool enabled() const; |
395 | virtual void setChannel( int ); | 416 | virtual void setChannel( int ); |
396 | 417 | ||
397 | virtual QString name() const = 0; | 418 | virtual QString name() const = 0; |
398 | 419 | ||
399 | protected: | 420 | protected: |
400 | OWirelessNetworkInterface* _if; | 421 | OWirelessNetworkInterface* _if; |
401 | 422 | ||
402 | }; | 423 | }; |
403 | 424 | ||
404 | 425 | ||
405 | /*====================================================================================== | 426 | /*====================================================================================== |
406 | * OCiscoMonitoring | 427 | * OCiscoMonitoring |
407 | *======================================================================================*/ | 428 | *======================================================================================*/ |
408 | 429 | ||
409 | 430 | ||
410 | class OCiscoMonitoringInterface : public OMonitoringInterface | 431 | class OCiscoMonitoringInterface : public OMonitoringInterface |
411 | { | 432 | { |
412 | public: | 433 | public: |
413 | OCiscoMonitoringInterface( ONetworkInterface* ); | 434 | OCiscoMonitoringInterface( ONetworkInterface* ); |
414 | virtual ~OCiscoMonitoringInterface(); | 435 | virtual ~OCiscoMonitoringInterface(); |
415 | 436 | ||
416 | virtual void setEnabled( bool ); | 437 | virtual void setEnabled( bool ); |
417 | virtual QString name() const; | 438 | virtual QString name() const; |
418 | virtual void setChannel( int ); | 439 | virtual void setChannel( int ); |
419 | 440 | ||
420 | }; | 441 | }; |
421 | 442 | ||
422 | /*====================================================================================== | 443 | /*====================================================================================== |
423 | * OWlanNGMonitoringInterface | 444 | * OWlanNGMonitoringInterface |
424 | *======================================================================================*/ | 445 | *======================================================================================*/ |
425 | 446 | ||
426 | class OWlanNGMonitoringInterface : public OMonitoringInterface | 447 | class OWlanNGMonitoringInterface : public OMonitoringInterface |
427 | { | 448 | { |
428 | public: | 449 | public: |
429 | OWlanNGMonitoringInterface( ONetworkInterface* ); | 450 | OWlanNGMonitoringInterface( ONetworkInterface* ); |
430 | virtual ~OWlanNGMonitoringInterface(); | 451 | virtual ~OWlanNGMonitoringInterface(); |
431 | 452 | ||
432 | public: | 453 | public: |
433 | virtual void setEnabled( bool ); | 454 | virtual void setEnabled( bool ); |
434 | virtual QString name() const; | 455 | virtual QString name() const; |
435 | virtual void setChannel( int ); | 456 | virtual void setChannel( int ); |
436 | 457 | ||
437 | }; | 458 | }; |
438 | 459 | ||
439 | /*====================================================================================== | 460 | /*====================================================================================== |
440 | * OHostAPMonitoringInterface | 461 | * OHostAPMonitoringInterface |
441 | *======================================================================================*/ | 462 | *======================================================================================*/ |
442 | 463 | ||
443 | class OHostAPMonitoringInterface : public OMonitoringInterface | 464 | class OHostAPMonitoringInterface : public OMonitoringInterface |
444 | { | 465 | { |
445 | public: | 466 | public: |
446 | OHostAPMonitoringInterface( ONetworkInterface* ); | 467 | OHostAPMonitoringInterface( ONetworkInterface* ); |
447 | virtual ~OHostAPMonitoringInterface(); | 468 | virtual ~OHostAPMonitoringInterface(); |
448 | 469 | ||
449 | public: | 470 | public: |
450 | virtual void setEnabled( bool ); | 471 | virtual void setEnabled( bool ); |
451 | virtual QString name() const; | 472 | virtual QString name() const; |
452 | }; | 473 | }; |
453 | 474 | ||
454 | /*====================================================================================== | 475 | /*====================================================================================== |
455 | * OOrinocoMonitoringInterface | 476 | * OOrinocoMonitoringInterface |
456 | *======================================================================================*/ | 477 | *======================================================================================*/ |
457 | 478 | ||
458 | class OOrinocoMonitoringInterface : public OMonitoringInterface | 479 | class OOrinocoMonitoringInterface : public OMonitoringInterface |
459 | { | 480 | { |
460 | public: | 481 | public: |
461 | OOrinocoMonitoringInterface( ONetworkInterface* ); | 482 | OOrinocoMonitoringInterface( ONetworkInterface* ); |
462 | virtual ~OOrinocoMonitoringInterface(); | 483 | virtual ~OOrinocoMonitoringInterface(); |
463 | 484 | ||
464 | public: | 485 | public: |
465 | virtual void setChannel( int ); | 486 | virtual void setChannel( int ); |
466 | virtual void setEnabled( bool ); | 487 | virtual void setEnabled( bool ); |
467 | virtual QString name() const; | 488 | virtual QString name() const; |
468 | 489 | ||
469 | }; | 490 | }; |
470 | 491 | ||
471 | #endif // ONETWORK_H | 492 | #endif // ONETWORK_H |
472 | 493 | ||