author | mickeyl <mickeyl> | 2003-12-20 00:43:12 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-12-20 00:43:12 (UTC) |
commit | 11c6b3b8ba56b28b160965387b4ffeffe2a2f143 (patch) (unidiff) | |
tree | 4da82e0b0f7120ec493644af44ac84e801cc4b9b | |
parent | 56762e511d9709c7141a504e609f7b850a5304f7 (diff) | |
download | opie-11c6b3b8ba56b28b160965387b4ffeffe2a2f143.zip opie-11c6b3b8ba56b28b160965387b4ffeffe2a2f143.tar.gz opie-11c6b3b8ba56b28b160965387b4ffeffe2a2f143.tar.bz2 |
libopienet2 now uses the fancy odebug classes, no longer qdebug
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 2384 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 2637 | ||||
-rw-r--r-- | libopie2/opienet/ostation.cpp | 7 |
3 files changed, 2517 insertions, 2511 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 6a9280f..d918193 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,1188 +1,1196 @@ | |||
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 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | 32 | ||
33 | #include <opie2/onetwork.h> | 33 | #include <opie2/onetwork.h> |
34 | #include <opie2/ostation.h> | 34 | #include <opie2/ostation.h> |
35 | 35 | #include <opie2/odebug.h> | |
36 | /* QT */ | 36 | |
37 | 37 | /* QT */ | |
38 | #include <qfile.h> | 38 | |
39 | #include <qtextstream.h> | 39 | #include <qfile.h> |
40 | 40 | #include <qtextstream.h> | |
41 | /* UNIX */ | 41 | |
42 | 42 | /* UNIX */ | |
43 | #include <assert.h> | 43 | |
44 | #include <arpa/inet.h> | 44 | #include <assert.h> |
45 | #include <errno.h> | 45 | #include <arpa/inet.h> |
46 | #include <string.h> | 46 | #include <errno.h> |
47 | #include <stdlib.h> | 47 | #include <string.h> |
48 | #include <math.h> | 48 | #include <stdlib.h> |
49 | #include <sys/ioctl.h> | 49 | #include <math.h> |
50 | #include <sys/socket.h> | 50 | #include <sys/ioctl.h> |
51 | #include <sys/types.h> | 51 | #include <sys/socket.h> |
52 | #include <unistd.h> | 52 | #include <sys/types.h> |
53 | #include <linux/sockios.h> | 53 | #include <unistd.h> |
54 | #include <net/if_arp.h> | 54 | #include <linux/sockios.h> |
55 | #include <stdarg.h> | 55 | #include <net/if_arp.h> |
56 | 56 | #include <stdarg.h> | |
57 | #ifndef NODEBUG | 57 | |
58 | #include <opie2/odebugmapper.h> | 58 | #ifndef NODEBUG |
59 | DebugMapper* debugmapper = new DebugMapper(); | 59 | #include <opie2/odebugmapper.h> |
60 | #endif | 60 | DebugMapper* debugmapper = new DebugMapper(); |
61 | 61 | #endif | |
62 | /*====================================================================================== | 62 | |
63 | * ONetwork | 63 | /*====================================================================================== |
64 | *======================================================================================*/ | 64 | * ONetwork |
65 | 65 | *======================================================================================*/ | |
66 | ONetwork* ONetwork::_instance = 0; | 66 | |
67 | 67 | ONetwork* ONetwork::_instance = 0; | |
68 | ONetwork::ONetwork() | 68 | |
69 | { | 69 | ONetwork::ONetwork() |
70 | qDebug( "ONetwork::ONetwork()" ); | 70 | { |
71 | qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT ); | 71 | odebug << "ONetwork::ONetwork()" << oendl; |
72 | synchronize(); | 72 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; |
73 | } | 73 | synchronize(); |
74 | 74 | } | |
75 | void ONetwork::synchronize() | 75 | |
76 | { | 76 | void ONetwork::synchronize() |
77 | // gather available interfaces by inspecting /proc/net/dev | 77 | { |
78 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 78 | // gather available interfaces by inspecting /proc/net/dev |
79 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 79 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
80 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev | 80 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
81 | 81 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev | |
82 | _interfaces.clear(); | 82 | |
83 | QString str; | 83 | _interfaces.clear(); |
84 | QFile f( "/proc/net/dev" ); | 84 | QString str; |
85 | bool hasFile = f.open( IO_ReadOnly ); | 85 | QFile f( "/proc/net/dev" ); |
86 | if ( !hasFile ) | 86 | bool hasFile = f.open( IO_ReadOnly ); |
87 | { | 87 | if ( !hasFile ) |
88 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); | 88 | { |
89 | return; | 89 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; |
90 | } | 90 | return; |
91 | QTextStream s( &f ); | 91 | } |
92 | s.readLine(); | 92 | QTextStream s( &f ); |
93 | s.readLine(); | 93 | s.readLine(); |
94 | while ( !s.atEnd() ) | 94 | s.readLine(); |
95 | { | 95 | while ( !s.atEnd() ) |
96 | s >> str; | 96 | { |
97 | str.truncate( str.find( ':' ) ); | 97 | s >> str; |
98 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); | 98 | str.truncate( str.find( ':' ) ); |
99 | ONetworkInterface* iface; | 99 | odebug << "ONetwork: found interface '" << str << "'" << oendl; |
100 | if ( isWirelessInterface( str ) ) | 100 | ONetworkInterface* iface; |
101 | { | 101 | if ( isWirelessInterface( str ) ) |
102 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 102 | { |
103 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 103 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
104 | } | 104 | odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; |
105 | else | 105 | } |
106 | { | 106 | else |
107 | iface = new ONetworkInterface( this, (const char*) str ); | 107 | { |
108 | } | 108 | iface = new ONetworkInterface( this, (const char*) str ); |
109 | _interfaces.insert( str, iface ); | 109 | } |
110 | s.readLine(); | 110 | _interfaces.insert( str, iface ); |
111 | } | 111 | s.readLine(); |
112 | } | 112 | } |
113 | 113 | } | |
114 | 114 | ||
115 | short ONetwork::wirelessExtensionVersion() | 115 | |
116 | { | 116 | short ONetwork::wirelessExtensionVersion() |
117 | return WIRELESS_EXT; | 117 | { |
118 | } | 118 | return WIRELESS_EXT; |
119 | 119 | } | |
120 | 120 | ||
121 | int ONetwork::count() const | 121 | |
122 | { | 122 | int ONetwork::count() const |
123 | return _interfaces.count(); | 123 | { |
124 | } | 124 | return _interfaces.count(); |
125 | 125 | } | |
126 | 126 | ||
127 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 127 | |
128 | { | 128 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
129 | return _interfaces[iface]; | 129 | { |
130 | } | 130 | return _interfaces[iface]; |
131 | 131 | } | |
132 | 132 | ||
133 | ONetwork* ONetwork::instance() | 133 | |
134 | { | 134 | ONetwork* ONetwork::instance() |
135 | if ( !_instance ) _instance = new ONetwork(); | 135 | { |
136 | return _instance; | 136 | if ( !_instance ) _instance = new ONetwork(); |
137 | } | 137 | return _instance; |
138 | 138 | } | |
139 | 139 | ||
140 | ONetwork::InterfaceIterator ONetwork::iterator() const | 140 | |
141 | { | 141 | ONetwork::InterfaceIterator ONetwork::iterator() const |
142 | return ONetwork::InterfaceIterator( _interfaces ); | 142 | { |
143 | } | 143 | return ONetwork::InterfaceIterator( _interfaces ); |
144 | 144 | } | |
145 | 145 | ||
146 | bool ONetwork::isWirelessInterface( const char* name ) const | 146 | |
147 | { | 147 | bool ONetwork::isWirelessInterface( const char* name ) const |
148 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 148 | { |
149 | struct iwreq iwr; | 149 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
150 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 150 | struct iwreq iwr; |
151 | strcpy( (char*) &iwr.ifr_name, name ); | 151 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
152 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 152 | strcpy( (char*) &iwr.ifr_name, name ); |
153 | return result != -1; | 153 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
154 | } | 154 | return result != -1; |
155 | 155 | } | |
156 | /*====================================================================================== | 156 | |
157 | * ONetworkInterface | 157 | /*====================================================================================== |
158 | *======================================================================================*/ | 158 | * ONetworkInterface |
159 | 159 | *======================================================================================*/ | |
160 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 160 | |
161 | :QObject( parent, name ), | 161 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
162 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 162 | :QObject( parent, name ), |
163 | { | 163 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
164 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 164 | { |
165 | init(); | 165 | odebug << "ONetworkInterface::ONetworkInterface()" << oendl; |
166 | } | 166 | init(); |
167 | 167 | } | |
168 | 168 | ||
169 | struct ifreq& ONetworkInterface::ifr() const | 169 | |
170 | { | 170 | struct ifreq& ONetworkInterface::ifr() const |
171 | return _ifr; | 171 | { |
172 | } | 172 | return _ifr; |
173 | 173 | } | |
174 | 174 | ||
175 | void ONetworkInterface::init() | 175 | |
176 | { | 176 | void ONetworkInterface::init() |
177 | qDebug( "ONetworkInterface::init()" ); | 177 | { |
178 | 178 | odebug << "ONetworkInterface::init()" << oendl; | |
179 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 179 | |
180 | 180 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | |
181 | if ( _sfd == -1 ) | 181 | |
182 | { | 182 | if ( _sfd == -1 ) |
183 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); | 183 | { |
184 | return; | 184 | odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; |
185 | } | 185 | return; |
186 | } | 186 | } |
187 | 187 | } | |
188 | 188 | ||
189 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 189 | |
190 | { | 190 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
191 | #ifndef NODEBUG | 191 | { |
192 | int result = ::ioctl( _sfd, call, &ifreq ); | 192 | #ifndef NODEBUG |
193 | if ( result == -1 ) | 193 | int result = ::ioctl( _sfd, call, &ifreq ); |
194 | qDebug( "ONetworkInterface::ioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) debugmapper->map( call ), call, result, strerror( errno ) ); | 194 | if ( result == -1 ) |
195 | else | 195 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) |
196 | qDebug( "ONetworkInterface::ioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) debugmapper->map( call ), call ); | 196 | << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; |
197 | return ( result != -1 ); | 197 | else |
198 | #else | 198 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) |
199 | return ::ioctl( _sfd, call, &ifreq ) != -1; | 199 | << "' - Status: Ok." << oendl; |
200 | #endif | 200 | return ( result != -1 ); |
201 | } | 201 | #else |
202 | 202 | return ::ioctl( _sfd, call, &ifreq ) != -1; | |
203 | 203 | #endif | |
204 | bool ONetworkInterface::ioctl( int call ) const | 204 | } |
205 | { | 205 | |
206 | strcpy( _ifr.ifr_name, name() ); | 206 | |
207 | return ioctl( call, _ifr ); | 207 | bool ONetworkInterface::ioctl( int call ) const |
208 | } | 208 | { |
209 | 209 | strcpy( _ifr.ifr_name, name() ); | |
210 | 210 | return ioctl( call, _ifr ); | |
211 | bool ONetworkInterface::isLoopback() const | 211 | } |
212 | { | 212 | |
213 | ioctl( SIOCGIFFLAGS ); | 213 | |
214 | return _ifr.ifr_flags & IFF_LOOPBACK; | 214 | bool ONetworkInterface::isLoopback() const |
215 | } | 215 | { |
216 | 216 | ioctl( SIOCGIFFLAGS ); | |
217 | 217 | return _ifr.ifr_flags & IFF_LOOPBACK; | |
218 | bool ONetworkInterface::setUp( bool b ) | 218 | } |
219 | { | 219 | |
220 | ioctl( SIOCGIFFLAGS ); | 220 | |
221 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 221 | bool ONetworkInterface::setUp( bool b ) |
222 | else _ifr.ifr_flags &= (~IFF_UP); | 222 | { |
223 | return ioctl( SIOCSIFFLAGS ); | 223 | ioctl( SIOCGIFFLAGS ); |
224 | } | 224 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
225 | 225 | else _ifr.ifr_flags &= (~IFF_UP); | |
226 | 226 | return ioctl( SIOCSIFFLAGS ); | |
227 | bool ONetworkInterface::isUp() const | 227 | } |
228 | { | 228 | |
229 | ioctl( SIOCGIFFLAGS ); | 229 | |
230 | return _ifr.ifr_flags & IFF_UP; | 230 | bool ONetworkInterface::isUp() const |
231 | } | 231 | { |
232 | 232 | ioctl( SIOCGIFFLAGS ); | |
233 | 233 | return _ifr.ifr_flags & IFF_UP; | |
234 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) | 234 | } |
235 | { | 235 | |
236 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 236 | |
237 | sa->sin_family = AF_INET; | 237 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) |
238 | sa->sin_port = 0; | 238 | { |
239 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 239 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
240 | ioctl( SIOCSIFADDR ); | 240 | sa->sin_family = AF_INET; |
241 | } | 241 | sa->sin_port = 0; |
242 | 242 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | |
243 | 243 | ioctl( SIOCSIFADDR ); | |
244 | QString ONetworkInterface::ipV4Address() const | 244 | } |
245 | { | 245 | |
246 | if ( ioctl( SIOCGIFADDR ) ) | 246 | |
247 | { | 247 | QString ONetworkInterface::ipV4Address() const |
248 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 248 | { |
249 | //FIXME: Use QHostAddress here | 249 | if ( ioctl( SIOCGIFADDR ) ) |
250 | return QString( inet_ntoa( sa->sin_addr ) ); | 250 | { |
251 | } | 251 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
252 | else | 252 | //FIXME: Use QHostAddress here |
253 | return "<unknown>"; | 253 | return QString( inet_ntoa( sa->sin_addr ) ); |
254 | 254 | } | |
255 | } | 255 | else |
256 | 256 | return "<unknown>"; | |
257 | 257 | ||
258 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) | 258 | } |
259 | { | 259 | |
260 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | 260 | |
261 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); | 261 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) |
262 | ioctl( SIOCSIFHWADDR ); | 262 | { |
263 | } | 263 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
264 | 264 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); | |
265 | 265 | ioctl( SIOCSIFHWADDR ); | |
266 | OMacAddress ONetworkInterface::macAddress() const | 266 | } |
267 | { | 267 | |
268 | if ( ioctl( SIOCGIFHWADDR ) ) | 268 | |
269 | { | 269 | OMacAddress ONetworkInterface::macAddress() const |
270 | return OMacAddress( _ifr ); | 270 | { |
271 | } | 271 | if ( ioctl( SIOCGIFHWADDR ) ) |
272 | else | 272 | { |
273 | { | 273 | return OMacAddress( _ifr ); |
274 | return OMacAddress::unknown; | 274 | } |
275 | } | 275 | else |
276 | } | 276 | { |
277 | 277 | return OMacAddress::unknown; | |
278 | 278 | } | |
279 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) | 279 | } |
280 | { | 280 | |
281 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 281 | |
282 | sa->sin_family = AF_INET; | 282 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) |
283 | sa->sin_port = 0; | 283 | { |
284 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 284 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
285 | ioctl( SIOCSIFNETMASK ); | 285 | sa->sin_family = AF_INET; |
286 | } | 286 | sa->sin_port = 0; |
287 | 287 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | |
288 | 288 | ioctl( SIOCSIFNETMASK ); | |
289 | QString ONetworkInterface::ipV4Netmask() const | 289 | } |
290 | { | 290 | |
291 | if ( ioctl( SIOCGIFNETMASK ) ) | 291 | |
292 | { | 292 | QString ONetworkInterface::ipV4Netmask() const |
293 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 293 | { |
294 | //FIXME: Use QHostAddress here | 294 | if ( ioctl( SIOCGIFNETMASK ) ) |
295 | return QString( inet_ntoa( sa->sin_addr ) ); | 295 | { |
296 | } | 296 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
297 | else | 297 | //FIXME: Use QHostAddress here |
298 | return "<unknown>"; | 298 | return QString( inet_ntoa( sa->sin_addr ) ); |
299 | } | 299 | } |
300 | 300 | else | |
301 | 301 | return "<unknown>"; | |
302 | int ONetworkInterface::dataLinkType() const | 302 | } |
303 | { | 303 | |
304 | if ( ioctl( SIOCGIFHWADDR ) ) | 304 | |
305 | { | 305 | int ONetworkInterface::dataLinkType() const |
306 | return _ifr.ifr_hwaddr.sa_family; | 306 | { |
307 | } | 307 | if ( ioctl( SIOCGIFHWADDR ) ) |
308 | else | 308 | { |
309 | { | 309 | return _ifr.ifr_hwaddr.sa_family; |
310 | return -1; | 310 | } |
311 | } | 311 | else |
312 | } | 312 | { |
313 | 313 | return -1; | |
314 | 314 | } | |
315 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 315 | } |
316 | { | 316 | |
317 | _mon = m; | 317 | |
318 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); | 318 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
319 | } | 319 | { |
320 | 320 | _mon = m; | |
321 | 321 | odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl; | |
322 | OMonitoringInterface* ONetworkInterface::monitoring() const | 322 | } |
323 | { | 323 | |
324 | return _mon; | 324 | |
325 | } | 325 | OMonitoringInterface* ONetworkInterface::monitoring() const |
326 | 326 | { | |
327 | 327 | return _mon; | |
328 | ONetworkInterface::~ONetworkInterface() | 328 | } |
329 | { | 329 | |
330 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); | 330 | |
331 | if ( _sfd != -1 ) ::close( _sfd ); | 331 | ONetworkInterface::~ONetworkInterface() |
332 | } | 332 | { |
333 | 333 | odebug << "ONetworkInterface::~ONetworkInterface()" << oendl; | |
334 | 334 | if ( _sfd != -1 ) ::close( _sfd ); | |
335 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 335 | } |
336 | { | 336 | |
337 | ioctl( SIOCGIFFLAGS ); | 337 | |
338 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 338 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
339 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 339 | { |
340 | return ioctl( SIOCSIFFLAGS ); | 340 | ioctl( SIOCGIFFLAGS ); |
341 | } | 341 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
342 | 342 | else _ifr.ifr_flags &= (~IFF_PROMISC); | |
343 | 343 | return ioctl( SIOCSIFFLAGS ); | |
344 | bool ONetworkInterface::promiscuousMode() const | 344 | } |
345 | { | 345 | |
346 | ioctl( SIOCGIFFLAGS ); | 346 | |
347 | return _ifr.ifr_flags & IFF_PROMISC; | 347 | bool ONetworkInterface::promiscuousMode() const |
348 | } | 348 | { |
349 | 349 | ioctl( SIOCGIFFLAGS ); | |
350 | 350 | return _ifr.ifr_flags & IFF_PROMISC; | |
351 | bool ONetworkInterface::isWireless() const | 351 | } |
352 | { | 352 | |
353 | return ioctl( SIOCGIWNAME ); | 353 | |
354 | } | 354 | bool ONetworkInterface::isWireless() const |
355 | 355 | { | |
356 | 356 | return ioctl( SIOCGIWNAME ); | |
357 | /*====================================================================================== | 357 | } |
358 | * OChannelHopper | 358 | |
359 | *======================================================================================*/ | 359 | |
360 | 360 | /*====================================================================================== | |
361 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 361 | * OChannelHopper |
362 | :QObject( 0, "Mickey's funky hopper" ), | 362 | *======================================================================================*/ |
363 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 363 | |
364 | { | 364 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
365 | int _maxChannel = iface->channels()+1; | 365 | :QObject( 0, "Mickey's funky hopper" ), |
366 | // generate fancy hopping sequence honoring the device capabilities | 366 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
367 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 367 | { |
368 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 368 | int _maxChannel = iface->channels()+1; |
369 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 369 | // generate fancy hopping sequence honoring the device capabilities |
370 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 370 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
371 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 371 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
372 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 372 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
373 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 373 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
374 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 374 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
375 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 375 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
376 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 376 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
377 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 377 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
378 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 378 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
379 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 379 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
380 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 380 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
381 | _channel = _channels.begin(); | 381 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
382 | 382 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | |
383 | } | 383 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
384 | 384 | _channel = _channels.begin(); | |
385 | 385 | ||
386 | OChannelHopper::~OChannelHopper() | 386 | } |
387 | { | 387 | |
388 | } | 388 | |
389 | 389 | OChannelHopper::~OChannelHopper() | |
390 | 390 | { | |
391 | bool OChannelHopper::isActive() const | 391 | } |
392 | { | 392 | |
393 | return _tid; | 393 | |
394 | } | 394 | bool OChannelHopper::isActive() const |
395 | 395 | { | |
396 | 396 | return _tid; | |
397 | int OChannelHopper::channel() const | 397 | } |
398 | { | 398 | |
399 | return *_channel; | 399 | |
400 | } | 400 | int OChannelHopper::channel() const |
401 | 401 | { | |
402 | 402 | return *_channel; | |
403 | void OChannelHopper::timerEvent( QTimerEvent* ) | 403 | } |
404 | { | 404 | |
405 | _iface->setChannel( *_channel ); | 405 | |
406 | emit( hopped( *_channel ) ); | 406 | void OChannelHopper::timerEvent( QTimerEvent* ) |
407 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 407 | { |
408 | *_channel, (const char*) _iface->name() ); | 408 | _iface->setChannel( *_channel ); |
409 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 409 | emit( hopped( *_channel ) ); |
410 | } | 410 | odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl; |
411 | 411 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | |
412 | 412 | } | |
413 | void OChannelHopper::setInterval( int interval ) | 413 | |
414 | { | 414 | |
415 | if ( interval == _interval ) | 415 | void OChannelHopper::setInterval( int interval ) |
416 | return; | 416 | { |
417 | 417 | if ( interval == _interval ) | |
418 | if ( _interval ) | 418 | return; |
419 | killTimer( _tid ); | 419 | |
420 | 420 | if ( _interval ) | |
421 | _tid = 0; | 421 | killTimer( _tid ); |
422 | _interval = interval; | 422 | |
423 | 423 | _tid = 0; | |
424 | if ( _interval ) | 424 | _interval = interval; |
425 | { | 425 | |
426 | _tid = startTimer( interval ); | 426 | if ( _interval ) |
427 | } | 427 | { |
428 | } | 428 | _tid = startTimer( interval ); |
429 | 429 | } | |
430 | 430 | } | |
431 | int OChannelHopper::interval() const | 431 | |
432 | { | 432 | |
433 | return _interval; | 433 | int OChannelHopper::interval() const |
434 | } | 434 | { |
435 | 435 | return _interval; | |
436 | 436 | } | |
437 | /*====================================================================================== | 437 | |
438 | * OWirelessNetworkInterface | 438 | |
439 | *======================================================================================*/ | 439 | /*====================================================================================== |
440 | 440 | * OWirelessNetworkInterface | |
441 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 441 | *======================================================================================*/ |
442 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 442 | |
443 | { | 443 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
444 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 444 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
445 | init(); | 445 | { |
446 | } | 446 | odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl; |
447 | 447 | init(); | |
448 | 448 | } | |
449 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 449 | |
450 | { | 450 | |
451 | } | 451 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
452 | 452 | { | |
453 | 453 | } | |
454 | struct iwreq& OWirelessNetworkInterface::iwr() const | 454 | |
455 | { | 455 | |
456 | return _iwr; | 456 | struct iwreq& OWirelessNetworkInterface::iwr() const |
457 | } | 457 | { |
458 | 458 | return _iwr; | |
459 | 459 | } | |
460 | void OWirelessNetworkInterface::init() | 460 | |
461 | { | 461 | |
462 | qDebug( "OWirelessNetworkInterface::init()" ); | 462 | void OWirelessNetworkInterface::init() |
463 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 463 | { |
464 | buildInformation(); | 464 | odebug << "OWirelessNetworkInterface::init()" << oendl; |
465 | buildPrivateList(); | 465 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
466 | dumpInformation(); | 466 | buildInformation(); |
467 | } | 467 | buildPrivateList(); |
468 | 468 | dumpInformation(); | |
469 | 469 | } | |
470 | bool OWirelessNetworkInterface::isAssociated() const | 470 | |
471 | { | 471 | |
472 | //FIXME: handle different modes | 472 | bool OWirelessNetworkInterface::isAssociated() const |
473 | return !(associatedAP() == OMacAddress::unknown); | 473 | { |
474 | } | 474 | //FIXME: handle different modes |
475 | 475 | return !(associatedAP() == OMacAddress::unknown); | |
476 | 476 | } | |
477 | OMacAddress OWirelessNetworkInterface::associatedAP() const | 477 | |
478 | { | 478 | |
479 | if ( ioctl( SIOCGIWAP ) ) | 479 | OMacAddress OWirelessNetworkInterface::associatedAP() const |
480 | return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; | 480 | { |
481 | else | 481 | if ( ioctl( SIOCGIWAP ) ) |
482 | return OMacAddress::unknown; | 482 | return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; |
483 | } | 483 | else |
484 | 484 | return OMacAddress::unknown; | |
485 | 485 | } | |
486 | void OWirelessNetworkInterface::buildInformation() | 486 | |
487 | { | 487 | |
488 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 488 | void OWirelessNetworkInterface::buildInformation() |
489 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | 489 | { |
490 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 490 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
491 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | 491 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete |
492 | //ML: _too much_ space. This is damn shitty crap *sigh* | 492 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
493 | //ML: We allocate a large memory region in RAM and check whether the | 493 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate |
494 | //ML: driver pollutes this extra space. The complaint will be made on stdout, | 494 | //ML: _too much_ space. This is damn shitty crap *sigh* |
495 | //ML: so please forward this... | 495 | //ML: We allocate a large memory region in RAM and check whether the |
496 | 496 | //ML: driver pollutes this extra space. The complaint will be made on stdout, | |
497 | struct iwreq wrq; | 497 | //ML: so please forward this... |
498 | int len = sizeof( struct iw_range )*2; | 498 | |
499 | char *buffer = (char*) malloc( len ); | 499 | struct iwreq wrq; |
500 | //FIXME: Validate if we actually got the memory block | 500 | int len = sizeof( struct iw_range )*2; |
501 | memset( buffer, 0, len ); | 501 | char *buffer = (char*) malloc( len ); |
502 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | 502 | //FIXME: Validate if we actually got the memory block |
503 | wrq.u.data.pointer = (caddr_t) buffer; | 503 | memset( buffer, 0, len ); |
504 | wrq.u.data.length = sizeof( struct iw_range ); | 504 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); |
505 | wrq.u.data.flags = 0; | 505 | wrq.u.data.pointer = (caddr_t) buffer; |
506 | 506 | wrq.u.data.length = sizeof( struct iw_range ); | |
507 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 507 | wrq.u.data.flags = 0; |
508 | { | 508 | |
509 | qDebug( "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (%s) - using default values.", strerror( errno ) ); | 509 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
510 | _channels.insert( 2412, 1 ); // 2.412 GHz | 510 | { |
511 | _channels.insert( 2417, 2 ); // 2.417 GHz | 511 | owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl; |
512 | _channels.insert( 2422, 3 ); // 2.422 GHz | 512 | _channels.insert( 2412, 1 ); // 2.412 GHz |
513 | _channels.insert( 2427, 4 ); // 2.427 GHz | 513 | _channels.insert( 2417, 2 ); // 2.417 GHz |
514 | _channels.insert( 2432, 5 ); // 2.432 GHz | 514 | _channels.insert( 2422, 3 ); // 2.422 GHz |
515 | _channels.insert( 2437, 6 ); // 2.437 GHz | 515 | _channels.insert( 2427, 4 ); // 2.427 GHz |
516 | _channels.insert( 2442, 7 ); // 2.442 GHz | 516 | _channels.insert( 2432, 5 ); // 2.432 GHz |
517 | _channels.insert( 2447, 8 ); // 2.447 GHz | 517 | _channels.insert( 2437, 6 ); // 2.437 GHz |
518 | _channels.insert( 2452, 9 ); // 2.452 GHz | 518 | _channels.insert( 2442, 7 ); // 2.442 GHz |
519 | _channels.insert( 2457, 10 ); // 2.457 GHz | 519 | _channels.insert( 2447, 8 ); // 2.447 GHz |
520 | _channels.insert( 2462, 11 ); // 2.462 GHz | 520 | _channels.insert( 2452, 9 ); // 2.452 GHz |
521 | 521 | _channels.insert( 2457, 10 ); // 2.457 GHz | |
522 | memset( &_range, 0, sizeof( struct iw_range ) ); | 522 | _channels.insert( 2462, 11 ); // 2.462 GHz |
523 | } | 523 | |
524 | else | 524 | memset( &_range, 0, sizeof( struct iw_range ) ); |
525 | { | 525 | } |
526 | // <check if the driver overwrites stuff> | 526 | else |
527 | int max = 0; | 527 | { |
528 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 528 | // <check if the driver overwrites stuff> |
529 | if (buffer[r] != 0) | 529 | int max = 0; |
530 | max = r; | 530 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
531 | if (max > 0) | 531 | if (buffer[r] != 0) |
532 | { | 532 | max = r; |
533 | qWarning( "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '%s' sucks!\n" | 533 | if (max > 0) |
534 | "It overwrote the buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); | 534 | { |
535 | } | 535 | owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() |
536 | // </check if the driver overwrites stuff> | 536 | << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; |
537 | 537 | } | |
538 | struct iw_range range; | 538 | // </check if the driver overwrites stuff> |
539 | memcpy( &range, buffer, sizeof range ); | 539 | |
540 | 540 | struct iw_range range; | |
541 | qDebug( "OWirelessNetworkInterface::buildInformation(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | 541 | memcpy( &range, buffer, sizeof range ); |
542 | for ( int i = 0; i < range.num_frequency; ++i ) | 542 | |
543 | { | 543 | odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; |
544 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 544 | for ( int i = 0; i < range.num_frequency; ++i ) |
545 | _channels.insert( freq, i+1 ); | 545 | { |
546 | } | 546 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
547 | } | 547 | _channels.insert( freq, i+1 ); |
548 | 548 | } | |
549 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); | 549 | } |
550 | qDebug( "OWirelessNetworkInterface::buildInformation(): Information block constructed." ); | 550 | |
551 | free(buffer); | 551 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); |
552 | } | 552 | odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; |
553 | 553 | free(buffer); | |
554 | 554 | } | |
555 | void OWirelessNetworkInterface::buildPrivateList() | 555 | |
556 | { | 556 | |
557 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | 557 | void OWirelessNetworkInterface::buildPrivateList() |
558 | 558 | { | |
559 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 559 | odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; |
560 | 560 | ||
561 | _iwr.u.data.pointer = (char*) &priv; | 561 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
562 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | 562 | |
563 | _iwr.u.data.flags = 0; | 563 | _iwr.u.data.pointer = (char*) &priv; |
564 | 564 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | |
565 | if ( !wioctl( SIOCGIWPRIV ) ) | 565 | _iwr.u.data.flags = 0; |
566 | { | 566 | |
567 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); | 567 | if ( !wioctl( SIOCGIWPRIV ) ) |
568 | return; | 568 | { |
569 | } | 569 | owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; |
570 | 570 | return; | |
571 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 571 | } |
572 | { | 572 | |
573 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 573 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
574 | } | 574 | { |
575 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); | 575 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
576 | } | 576 | } |
577 | 577 | odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; | |
578 | 578 | } | |
579 | void OWirelessNetworkInterface::dumpInformation() const | 579 | |
580 | { | 580 | |
581 | qDebug( "OWirelessNetworkInterface::() -------------- dumping information block ----------------" ); | 581 | void OWirelessNetworkInterface::dumpInformation() const |
582 | 582 | { | |
583 | qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ); | 583 | odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; |
584 | qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source ); | 584 | |
585 | 585 | qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ); | |
586 | qDebug( "OWirelessNetworkInterface::() ---------------------------------------------------------" ); | 586 | qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source ); |
587 | } | 587 | |
588 | 588 | odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; | |
589 | 589 | } | |
590 | int OWirelessNetworkInterface::channel() const | 590 | |
591 | { | 591 | |
592 | //FIXME: When monitoring enabled, then use it | 592 | int OWirelessNetworkInterface::channel() const |
593 | //FIXME: to gather the current RF channel | 593 | { |
594 | //FIXME: Until then, get active channel from hopper. | 594 | //FIXME: When monitoring enabled, then use it |
595 | if ( _hopper && _hopper->isActive() ) | 595 | //FIXME: to gather the current RF channel |
596 | return _hopper->channel(); | 596 | //FIXME: Until then, get active channel from hopper. |
597 | 597 | if ( _hopper && _hopper->isActive() ) | |
598 | if ( !wioctl( SIOCGIWFREQ ) ) | 598 | return _hopper->channel(); |
599 | { | 599 | |
600 | return -1; | 600 | if ( !wioctl( SIOCGIWFREQ ) ) |
601 | } | 601 | { |
602 | else | 602 | return -1; |
603 | { | 603 | } |
604 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; | 604 | else |
605 | } | 605 | { |
606 | } | 606 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; |
607 | 607 | } | |
608 | 608 | } | |
609 | void OWirelessNetworkInterface::setChannel( int c ) const | 609 | |
610 | { | 610 | |
611 | if ( !c ) | 611 | void OWirelessNetworkInterface::setChannel( int c ) const |
612 | { | 612 | { |
613 | qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" ); | 613 | if ( !c ) |
614 | return; | 614 | { |
615 | } | 615 | oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl; |
616 | 616 | return; | |
617 | if ( !_mon ) | 617 | } |
618 | { | 618 | |
619 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 619 | if ( !_mon ) |
620 | _iwr.u.freq.m = c; | 620 | { |
621 | _iwr.u.freq.e = 0; | 621 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
622 | wioctl( SIOCSIWFREQ ); | 622 | _iwr.u.freq.m = c; |
623 | } | 623 | _iwr.u.freq.e = 0; |
624 | else | 624 | wioctl( SIOCSIWFREQ ); |
625 | { | 625 | } |
626 | _mon->setChannel( c ); | 626 | else |
627 | } | 627 | { |
628 | } | 628 | _mon->setChannel( c ); |
629 | 629 | } | |
630 | 630 | } | |
631 | double OWirelessNetworkInterface::frequency() const | 631 | |
632 | { | 632 | |
633 | if ( !wioctl( SIOCGIWFREQ ) ) | 633 | double OWirelessNetworkInterface::frequency() const |
634 | { | 634 | { |
635 | return -1.0; | 635 | if ( !wioctl( SIOCGIWFREQ ) ) |
636 | } | 636 | { |
637 | else | 637 | return -1.0; |
638 | { | 638 | } |
639 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 639 | else |
640 | } | 640 | { |
641 | } | 641 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
642 | 642 | } | |
643 | 643 | } | |
644 | int OWirelessNetworkInterface::channels() const | 644 | |
645 | { | 645 | |
646 | return _channels.count(); | 646 | int OWirelessNetworkInterface::channels() const |
647 | } | 647 | { |
648 | 648 | return _channels.count(); | |
649 | 649 | } | |
650 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 650 | |
651 | { | 651 | |
652 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 652 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
653 | _hopper->setInterval( interval ); | 653 | { |
654 | //FIXME: When and by whom will the channel hopper be deleted? | 654 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
655 | //TODO: rely on QObject hierarchy | 655 | _hopper->setInterval( interval ); |
656 | } | 656 | //FIXME: When and by whom will the channel hopper be deleted? |
657 | 657 | //TODO: rely on QObject hierarchy | |
658 | 658 | } | |
659 | int OWirelessNetworkInterface::channelHopping() const | 659 | |
660 | { | 660 | |
661 | return _hopper->interval(); | 661 | int OWirelessNetworkInterface::channelHopping() const |
662 | } | 662 | { |
663 | 663 | return _hopper->interval(); | |
664 | 664 | } | |
665 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const | 665 | |
666 | { | 666 | |
667 | return _hopper; | 667 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const |
668 | } | 668 | { |
669 | 669 | return _hopper; | |
670 | 670 | } | |
671 | void OWirelessNetworkInterface::commit() const | 671 | |
672 | { | 672 | |
673 | wioctl( SIOCSIWCOMMIT ); | 673 | void OWirelessNetworkInterface::commit() const |
674 | } | 674 | { |
675 | 675 | wioctl( SIOCSIWCOMMIT ); | |
676 | 676 | } | |
677 | void OWirelessNetworkInterface::setMode( const QString& newMode ) | 677 | |
678 | { | 678 | |
679 | #ifdef FINALIZE | 679 | void OWirelessNetworkInterface::setMode( const QString& newMode ) |
680 | QString currentMode = mode(); | 680 | { |
681 | if ( currentMode == newMode ) return; | 681 | #ifdef FINALIZE |
682 | #endif | 682 | QString currentMode = mode(); |
683 | 683 | if ( currentMode == newMode ) return; | |
684 | qDebug( "OWirelessNetworkInterface::setMode(): trying to set mode '%s' (%d)", (const char*) newMode, stringToMode( newMode ) ); | 684 | #endif |
685 | 685 | ||
686 | _iwr.u.mode = stringToMode( newMode ); | 686 | odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl; |
687 | 687 | ||
688 | if ( _iwr.u.mode != IW_MODE_MONITOR ) | 688 | _iwr.u.mode = stringToMode( newMode ); |
689 | { | 689 | |
690 | // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! | 690 | if ( _iwr.u.mode != IW_MODE_MONITOR ) |
691 | _iwr.u.mode = stringToMode( newMode ); | 691 | { |
692 | wioctl( SIOCSIWMODE ); | 692 | // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! |
693 | 693 | _iwr.u.mode = stringToMode( newMode ); | |
694 | // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) | 694 | wioctl( SIOCSIWMODE ); |
695 | 695 | ||
696 | if ( mode() == "monitor" ) | 696 | // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) |
697 | { | 697 | |
698 | qDebug( "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." ); | 698 | if ( mode() == "monitor" ) |
699 | if ( _mon ) | 699 | { |
700 | _mon->setEnabled( false ); | 700 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl; |
701 | else | 701 | if ( _mon ) |
702 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 702 | _mon->setEnabled( false ); |
703 | } | 703 | else |
704 | 704 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; | |
705 | } | 705 | } |
706 | else // special iwpriv fallback for monitor mode | 706 | |
707 | { | 707 | } |
708 | if ( wioctl( SIOCSIWMODE ) ) | 708 | else // special iwpriv fallback for monitor mode |
709 | { | 709 | { |
710 | qDebug( "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" ); | 710 | if ( wioctl( SIOCSIWMODE ) ) |
711 | } | 711 | { |
712 | else | 712 | odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl; |
713 | { | 713 | } |
714 | qDebug( "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." ); | 714 | else |
715 | 715 | { | |
716 | if ( _mon ) | 716 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl; |
717 | _mon->setEnabled( true ); | 717 | |
718 | else | 718 | if ( _mon ) |
719 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 719 | _mon->setEnabled( true ); |
720 | } | 720 | else |
721 | } | 721 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; |
722 | } | 722 | } |
723 | 723 | } | |
724 | 724 | } | |
725 | QString OWirelessNetworkInterface::mode() const | 725 | |
726 | { | 726 | |
727 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 727 | QString OWirelessNetworkInterface::mode() const |
728 | 728 | { | |
729 | if ( !wioctl( SIOCGIWMODE ) ) | 729 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
730 | { | 730 | |
731 | return "<unknown>"; | 731 | if ( !wioctl( SIOCGIWMODE ) ) |
732 | } | 732 | { |
733 | 733 | return "<unknown>"; | |
734 | qDebug( "DEBUG: WE's idea of current mode seems to be '%s'", (const char*) modeToString( _iwr.u.mode ) ); | 734 | } |
735 | 735 | ||
736 | // legacy compatible monitor mode check | 736 | odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl; |
737 | 737 | ||
738 | if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) | 738 | // legacy compatible monitor mode check |
739 | { | 739 | |
740 | return "monitor"; | 740 | if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) |
741 | } | 741 | { |
742 | else | 742 | return "monitor"; |
743 | { | 743 | } |
744 | return modeToString( _iwr.u.mode ); | 744 | else |
745 | } | 745 | { |
746 | } | 746 | return modeToString( _iwr.u.mode ); |
747 | 747 | } | |
748 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) | 748 | } |
749 | { | 749 | |
750 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); | 750 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) |
751 | _iwr.u.essid.length = nickname.length(); | 751 | { |
752 | wioctl( SIOCSIWNICKN ); | 752 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); |
753 | } | 753 | _iwr.u.essid.length = nickname.length(); |
754 | 754 | wioctl( SIOCSIWNICKN ); | |
755 | 755 | } | |
756 | QString OWirelessNetworkInterface::nickName() const | 756 | |
757 | { | 757 | |
758 | char str[IW_ESSID_MAX_SIZE]; | 758 | QString OWirelessNetworkInterface::nickName() const |
759 | _iwr.u.data.pointer = &str[0]; | 759 | { |
760 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 760 | char str[IW_ESSID_MAX_SIZE]; |
761 | if ( !wioctl( SIOCGIWNICKN ) ) | 761 | _iwr.u.data.pointer = &str[0]; |
762 | { | 762 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
763 | return "<unknown>"; | 763 | if ( !wioctl( SIOCGIWNICKN ) ) |
764 | } | 764 | { |
765 | else | 765 | return "<unknown>"; |
766 | { | 766 | } |
767 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 767 | else |
768 | return str; | 768 | { |
769 | } | 769 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
770 | } | 770 | return str; |
771 | 771 | } | |
772 | 772 | } | |
773 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 773 | |
774 | { | 774 | |
775 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 775 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
776 | if ( !priv ) | 776 | { |
777 | { | 777 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
778 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); | 778 | if ( !priv ) |
779 | return; | 779 | { |
780 | } | 780 | owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name() |
781 | if ( priv->numberSetArgs() != numargs ) | 781 | << "' does not support private ioctl '" << call << "'" << oendl; |
782 | { | 782 | return; |
783 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); | 783 | } |
784 | return; | 784 | if ( priv->numberSetArgs() != numargs ) |
785 | } | 785 | { |
786 | 786 | owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '" | |
787 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); | 787 | << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl; |
788 | memset( &_iwr, 0, sizeof _iwr ); | 788 | return; |
789 | va_list argp; | 789 | } |
790 | va_start( argp, numargs ); | 790 | |
791 | for ( int i = 0; i < numargs; ++i ) | 791 | odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl; |
792 | { | 792 | memset( &_iwr, 0, sizeof _iwr ); |
793 | priv->setParameter( i, va_arg( argp, int ) ); | 793 | va_list argp; |
794 | } | 794 | va_start( argp, numargs ); |
795 | va_end( argp ); | 795 | for ( int i = 0; i < numargs; ++i ) |
796 | priv->invoke(); | 796 | { |
797 | } | 797 | priv->setParameter( i, va_arg( argp, int ) ); |
798 | 798 | } | |
799 | 799 | va_end( argp ); | |
800 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 800 | priv->invoke(); |
801 | { | 801 | } |
802 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); | 802 | |
803 | } | 803 | |
804 | 804 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | |
805 | 805 | { | |
806 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | 806 | oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl; |
807 | { | 807 | } |
808 | return child( (const char*) call ); | 808 | |
809 | } | 809 | |
810 | 810 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | |
811 | 811 | { | |
812 | QString OWirelessNetworkInterface::SSID() const | 812 | return child( (const char*) call ); |
813 | { | 813 | } |
814 | char str[IW_ESSID_MAX_SIZE]; | 814 | |
815 | _iwr.u.essid.pointer = &str[0]; | 815 | |
816 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 816 | QString OWirelessNetworkInterface::SSID() const |
817 | if ( !wioctl( SIOCGIWESSID ) ) | 817 | { |
818 | { | 818 | char str[IW_ESSID_MAX_SIZE]; |
819 | return "<unknown>"; | 819 | _iwr.u.essid.pointer = &str[0]; |
820 | } | 820 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
821 | else | 821 | if ( !wioctl( SIOCGIWESSID ) ) |
822 | { | 822 | { |
823 | return str; | 823 | return "<unknown>"; |
824 | } | 824 | } |
825 | } | 825 | else |
826 | 826 | { | |
827 | 827 | return str; | |
828 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 828 | } |
829 | { | 829 | } |
830 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 830 | |
831 | _iwr.u.essid.length = ssid.length(); | 831 | |
832 | wioctl( SIOCSIWESSID ); | 832 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
833 | } | 833 | { |
834 | 834 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | |
835 | 835 | _iwr.u.essid.length = ssid.length(); | |
836 | OStationList* OWirelessNetworkInterface::scanNetwork() | 836 | wioctl( SIOCSIWESSID ); |
837 | { | 837 | } |
838 | _iwr.u.param.flags = IW_SCAN_DEFAULT; | 838 | |
839 | _iwr.u.param.value = 0; | 839 | |
840 | if ( !wioctl( SIOCSIWSCAN ) ) | 840 | OStationList* OWirelessNetworkInterface::scanNetwork() |
841 | { | 841 | { |
842 | return 0; | 842 | _iwr.u.param.flags = IW_SCAN_DEFAULT; |
843 | } | 843 | _iwr.u.param.value = 0; |
844 | 844 | if ( !wioctl( SIOCSIWSCAN ) ) | |
845 | OStationList* stations = new OStationList(); | 845 | { |
846 | 846 | return 0; | |
847 | int timeout = 1000000; | 847 | } |
848 | 848 | ||
849 | qDebug( "ONetworkInterface::scanNetwork() - scan started." ); | 849 | OStationList* stations = new OStationList(); |
850 | 850 | ||
851 | bool results = false; | 851 | int timeout = 1000000; |
852 | struct timeval tv; | 852 | |
853 | tv.tv_sec = 0; | 853 | odebug << "ONetworkInterface::scanNetwork() - scan started." << oendl; |
854 | tv.tv_usec = 250000; // initial timeout ~ 250ms | 854 | |
855 | char buffer[IW_SCAN_MAX_DATA]; | 855 | bool results = false; |
856 | 856 | struct timeval tv; | |
857 | while ( !results && timeout > 0 ) | 857 | tv.tv_sec = 0; |
858 | { | 858 | tv.tv_usec = 250000; // initial timeout ~ 250ms |
859 | timeout -= tv.tv_usec; | 859 | char buffer[IW_SCAN_MAX_DATA]; |
860 | select( 0, 0, 0, 0, &tv ); | 860 | |
861 | 861 | while ( !results && timeout > 0 ) | |
862 | _iwr.u.data.pointer = &buffer[0]; | 862 | { |
863 | _iwr.u.data.flags = 0; | 863 | timeout -= tv.tv_usec; |
864 | _iwr.u.data.length = sizeof buffer; | 864 | select( 0, 0, 0, 0, &tv ); |
865 | if ( wioctl( SIOCGIWSCAN ) ) | 865 | |
866 | { | 866 | _iwr.u.data.pointer = &buffer[0]; |
867 | results = true; | 867 | _iwr.u.data.flags = 0; |
868 | continue; | 868 | _iwr.u.data.length = sizeof buffer; |
869 | } | 869 | if ( wioctl( SIOCGIWSCAN ) ) |
870 | else if ( errno == EAGAIN) | 870 | { |
871 | { | 871 | results = true; |
872 | qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." ); | 872 | continue; |
873 | #if 0 | 873 | } |
874 | if ( qApp ) | 874 | else if ( errno == EAGAIN) |
875 | { | 875 | { |
876 | qApp->processEvents( 100 ); | 876 | odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl; |
877 | continue; | 877 | #if 0 |
878 | } | 878 | if ( qApp ) |
879 | #endif | 879 | { |
880 | tv.tv_sec = 0; | 880 | qApp->processEvents( 100 ); |
881 | tv.tv_usec = 100000; | 881 | continue; |
882 | continue; | 882 | } |
883 | } | 883 | #endif |
884 | } | 884 | tv.tv_sec = 0; |
885 | 885 | tv.tv_usec = 100000; | |
886 | qDebug( "ONetworkInterface::scanNetwork() - scan finished." ); | 886 | continue; |
887 | 887 | } | |
888 | if ( results ) | 888 | } |
889 | { | 889 | |
890 | qDebug( " - result length = %d", _iwr.u.data.length ); | 890 | odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; |
891 | if ( !_iwr.u.data.length ) | 891 | |
892 | { | 892 | if ( results ) |
893 | qDebug( " - no results (empty neighbourhood)" ); | 893 | { |
894 | return stations; | 894 | odebug << " - result length = " << _iwr.u.data.length << oendl; |
895 | } | 895 | if ( !_iwr.u.data.length ) |
896 | 896 | { | |
897 | qDebug( " - results are in!" ); | 897 | odebug << " - no results (empty neighbourhood)" << oendl; |
898 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); | 898 | return stations; |
899 | 899 | } | |
900 | // parse results | 900 | |
901 | 901 | odebug << " - results are in!" << oendl; | |
902 | int offset = 0; | 902 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); |
903 | struct iw_event* we = (struct iw_event*) &buffer[0]; | 903 | |
904 | 904 | // parse results | |
905 | while ( offset < _iwr.u.data.length ) | 905 | |
906 | { | 906 | int offset = 0; |
907 | //const char* cmd = *(*_ioctlmap)[we->cmd]; | 907 | struct iw_event* we = (struct iw_event*) &buffer[0]; |
908 | //if ( !cmd ) cmd = "<unknown>"; | 908 | |
909 | qDebug( "reading next event... cmd=%d, len=%d", we->cmd, we->len ); | 909 | while ( offset < _iwr.u.data.length ) |
910 | switch (we->cmd) | 910 | { |
911 | { | 911 | //const char* cmd = *(*_ioctlmap)[we->cmd]; |
912 | case SIOCGIWAP: | 912 | //if ( !cmd ) cmd = "<unknown>"; |
913 | { | 913 | odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl; |
914 | qDebug( "SIOCGIWAP" ); | 914 | switch (we->cmd) |
915 | stations->append( new OStation() ); | 915 | { |
916 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; | 916 | case SIOCGIWAP: |
917 | break; | 917 | { |
918 | } | 918 | odebug << "SIOCGIWAP" << oendl; |
919 | case SIOCGIWMODE: | 919 | stations->append( new OStation() ); |
920 | { | 920 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; |
921 | qDebug( "SIOCGIWMODE" ); | 921 | break; |
922 | stations->last()->type = modeToString( we->u.mode ); | 922 | } |
923 | break; | 923 | case SIOCGIWMODE: |
924 | } | 924 | { |
925 | case SIOCGIWFREQ: | 925 | odebug << "SIOCGIWMODE" << oendl; |
926 | { | 926 | stations->last()->type = modeToString( we->u.mode ); |
927 | qDebug( "SIOCGIWFREQ" ); | 927 | break; |
928 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; | 928 | } |
929 | break; | 929 | case SIOCGIWFREQ: |
930 | } | 930 | { |
931 | case SIOCGIWESSID: | 931 | odebug << "SIOCGIWFREQ" << oendl; |
932 | { | 932 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; |
933 | qDebug( "SIOCGIWESSID" ); | 933 | break; |
934 | stations->last()->ssid = we->u.essid.pointer; | 934 | } |
935 | break; | 935 | case SIOCGIWESSID: |
936 | } | 936 | { |
937 | case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break; | 937 | odebug << "SIOCGIWESSID" << oendl; |
938 | case SIOCGIWENCODE: qDebug( "SIOCGIWENCODE" ); break; | 938 | stations->last()->ssid = we->u.essid.pointer; |
939 | case IWEVTXDROP: qDebug( "IWEVTXDROP" ); break; /* Packet dropped to excessive retry */ | 939 | break; |
940 | case IWEVQUAL: qDebug( "IWEVQUAL" ); break; /* Quality part of statistics (scan) */ | 940 | } |
941 | case IWEVCUSTOM: qDebug( "IWEVCUSTOM" ); break; /* Driver specific ascii string */ | 941 | case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; |
942 | case IWEVREGISTERED: qDebug( "IWEVREGISTERED" ); break; /* Discovered a new node (AP mode) */ | 942 | case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break; |
943 | case IWEVEXPIRED: qDebug( "IWEVEXPIRED" ); break; /* Expired a node (AP mode) */ | 943 | case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ |
944 | default: qDebug( "unhandled event" ); | 944 | case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */ |
945 | } | 945 | case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ |
946 | 946 | case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ | |
947 | offset += we->len; | 947 | case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ |
948 | we = (struct iw_event*) &buffer[offset]; | 948 | default: odebug << "unhandled event" << oendl; |
949 | } | 949 | } |
950 | return stations; | 950 | |
951 | 951 | offset += we->len; | |
952 | return stations; | 952 | we = (struct iw_event*) &buffer[offset]; |
953 | 953 | } | |
954 | } | 954 | return stations; |
955 | else | 955 | |
956 | { | 956 | return stations; |
957 | qDebug( " - no results (timeout) :(" ); | 957 | |
958 | return stations; | 958 | } |
959 | } | 959 | else |
960 | } | 960 | { |
961 | 961 | odebug << " - no results (timeout) :(" << oendl; | |
962 | 962 | return stations; | |
963 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 963 | } |
964 | { | 964 | } |
965 | #ifndef NODEBUG | 965 | |
966 | int result = ::ioctl( _sfd, call, &iwreq ); | 966 | |
967 | if ( result == -1 ) | 967 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
968 | qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) debugmapper->map( call ), call, result, strerror( errno ) ); | 968 | { |
969 | else | 969 | #ifndef NODEBUG |
970 | qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) debugmapper->map( call ), call ); | 970 | int result = ::ioctl( _sfd, call, &iwreq ); |
971 | return ( result != -1 ); | 971 | |
972 | #else | 972 | if ( result == -1 ) |
973 | return ::ioctl( _sfd, call, &iwreq ) != -1; | 973 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
974 | #endif | 974 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; |
975 | } | 975 | else |
976 | 976 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | |
977 | 977 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; | |
978 | bool OWirelessNetworkInterface::wioctl( int call ) const | 978 | |
979 | { | 979 | return ( result != -1 ); |
980 | strcpy( _iwr.ifr_name, name() ); | 980 | #else |
981 | return wioctl( call, _iwr ); | 981 | return ::ioctl( _sfd, call, &iwreq ) != -1; |
982 | } | 982 | #endif |
983 | 983 | } | |
984 | 984 | ||
985 | /*====================================================================================== | 985 | |
986 | * OMonitoringInterface | 986 | bool OWirelessNetworkInterface::wioctl( int call ) const |
987 | *======================================================================================*/ | 987 | { |
988 | 988 | strcpy( _iwr.ifr_name, name() ); | |
989 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 989 | return wioctl( call, _iwr ); |
990 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) | 990 | } |
991 | { | 991 | |
992 | } | 992 | |
993 | 993 | /*====================================================================================== | |
994 | 994 | * OMonitoringInterface | |
995 | OMonitoringInterface::~OMonitoringInterface() | 995 | *======================================================================================*/ |
996 | { | 996 | |
997 | } | 997 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
998 | 998 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) | |
999 | 999 | { | |
1000 | void OMonitoringInterface::setChannel( int c ) | 1000 | } |
1001 | { | 1001 | |
1002 | // use standard WE channel switching protocol | 1002 | |
1003 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 1003 | OMonitoringInterface::~OMonitoringInterface() |
1004 | _if->_iwr.u.freq.m = c; | 1004 | { |
1005 | _if->_iwr.u.freq.e = 0; | 1005 | } |
1006 | _if->wioctl( SIOCSIWFREQ ); | 1006 | |
1007 | } | 1007 | |
1008 | 1008 | void OMonitoringInterface::setChannel( int c ) | |
1009 | 1009 | { | |
1010 | void OMonitoringInterface::setEnabled( bool b ) | 1010 | // use standard WE channel switching protocol |
1011 | { | 1011 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
1012 | } | 1012 | _if->_iwr.u.freq.m = c; |
1013 | 1013 | _if->_iwr.u.freq.e = 0; | |
1014 | 1014 | _if->wioctl( SIOCSIWFREQ ); | |
1015 | /*====================================================================================== | 1015 | } |
1016 | * OCiscoMonitoringInterface | 1016 | |
1017 | *======================================================================================*/ | 1017 | |
1018 | 1018 | void OMonitoringInterface::setEnabled( bool b ) | |
1019 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1019 | { |
1020 | :OMonitoringInterface( iface, prismHeader ) | 1020 | } |
1021 | { | 1021 | |
1022 | iface->setMonitoring( this ); | 1022 | |
1023 | } | 1023 | /*====================================================================================== |
1024 | 1024 | * OCiscoMonitoringInterface | |
1025 | 1025 | *======================================================================================*/ | |
1026 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 1026 | |
1027 | { | 1027 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1028 | } | 1028 | :OMonitoringInterface( iface, prismHeader ) |
1029 | 1029 | { | |
1030 | 1030 | iface->setMonitoring( this ); | |
1031 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 1031 | } |
1032 | { | 1032 | |
1033 | QString fname; | 1033 | |
1034 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 1034 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
1035 | QFile f( fname ); | 1035 | { |
1036 | if ( !f.exists() ) return; | 1036 | } |
1037 | 1037 | ||
1038 | if ( f.open( IO_WriteOnly ) ) | 1038 | |
1039 | { | 1039 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
1040 | QTextStream s( &f ); | 1040 | { |
1041 | s << "Mode: r"; | 1041 | QString fname; |
1042 | s << "Mode: y"; | 1042 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
1043 | s << "XmitPower: 1"; | 1043 | QFile f( fname ); |
1044 | } | 1044 | if ( !f.exists() ) return; |
1045 | 1045 | ||
1046 | // flushing and closing will be done automatically when f goes out of scope | 1046 | if ( f.open( IO_WriteOnly ) ) |
1047 | } | 1047 | { |
1048 | 1048 | QTextStream s( &f ); | |
1049 | 1049 | s << "Mode: r"; | |
1050 | QString OCiscoMonitoringInterface::name() const | 1050 | s << "Mode: y"; |
1051 | { | 1051 | s << "XmitPower: 1"; |
1052 | return "cisco"; | 1052 | } |
1053 | } | 1053 | |
1054 | 1054 | // flushing and closing will be done automatically when f goes out of scope | |
1055 | 1055 | } | |
1056 | void OCiscoMonitoringInterface::setChannel( int ) | 1056 | |
1057 | { | 1057 | |
1058 | // cisco devices automatically switch channels when in monitor mode | 1058 | QString OCiscoMonitoringInterface::name() const |
1059 | } | 1059 | { |
1060 | 1060 | return "cisco"; | |
1061 | 1061 | } | |
1062 | /*====================================================================================== | 1062 | |
1063 | * OWlanNGMonitoringInterface | 1063 | |
1064 | *======================================================================================*/ | 1064 | void OCiscoMonitoringInterface::setChannel( int ) |
1065 | 1065 | { | |
1066 | 1066 | // cisco devices automatically switch channels when in monitor mode | |
1067 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1067 | } |
1068 | :OMonitoringInterface( iface, prismHeader ) | 1068 | |
1069 | { | 1069 | |
1070 | iface->setMonitoring( this ); | 1070 | /*====================================================================================== |
1071 | } | 1071 | * OWlanNGMonitoringInterface |
1072 | 1072 | *======================================================================================*/ | |
1073 | 1073 | ||
1074 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 1074 | |
1075 | { | 1075 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1076 | } | 1076 | :OMonitoringInterface( iface, prismHeader ) |
1077 | 1077 | { | |
1078 | 1078 | iface->setMonitoring( this ); | |
1079 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 1079 | } |
1080 | { | 1080 | |
1081 | //FIXME: do nothing if its already in the same mode | 1081 | |
1082 | 1082 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | |
1083 | QString enable = b ? "true" : "false"; | 1083 | { |
1084 | QString prism = _prismHeader ? "true" : "false"; | 1084 | } |
1085 | QString cmd; | 1085 | |
1086 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 1086 | |
1087 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); | 1087 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
1088 | system( cmd ); | 1088 | { |
1089 | } | 1089 | //FIXME: do nothing if its already in the same mode |
1090 | 1090 | ||
1091 | 1091 | QString enable = b ? "true" : "false"; | |
1092 | QString OWlanNGMonitoringInterface::name() const | 1092 | QString prism = _prismHeader ? "true" : "false"; |
1093 | { | 1093 | QString cmd; |
1094 | return "wlan-ng"; | 1094 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
1095 | } | 1095 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); |
1096 | 1096 | system( cmd ); | |
1097 | 1097 | } | |
1098 | void OWlanNGMonitoringInterface::setChannel( int c ) | 1098 | |
1099 | { | 1099 | |
1100 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. | 1100 | QString OWlanNGMonitoringInterface::name() const |
1101 | 1101 | { | |
1102 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; | 1102 | return "wlan-ng"; |
1103 | QString prism = _prismHeader ? "true" : "false"; | 1103 | } |
1104 | QString cmd; | 1104 | |
1105 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 1105 | |
1106 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); | 1106 | void OWlanNGMonitoringInterface::setChannel( int c ) |
1107 | system( cmd ); | 1107 | { |
1108 | } | 1108 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. |
1109 | 1109 | ||
1110 | 1110 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; | |
1111 | /*====================================================================================== | 1111 | QString prism = _prismHeader ? "true" : "false"; |
1112 | * OHostAPMonitoringInterface | 1112 | QString cmd; |
1113 | *======================================================================================*/ | 1113 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
1114 | 1114 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); | |
1115 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1115 | system( cmd ); |
1116 | :OMonitoringInterface( iface, prismHeader ) | 1116 | } |
1117 | { | 1117 | |
1118 | iface->setMonitoring( this ); | 1118 | |
1119 | } | 1119 | /*====================================================================================== |
1120 | 1120 | * OHostAPMonitoringInterface | |
1121 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 1121 | *======================================================================================*/ |
1122 | { | 1122 | |
1123 | } | 1123 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1124 | 1124 | :OMonitoringInterface( iface, prismHeader ) | |
1125 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 1125 | { |
1126 | { | 1126 | iface->setMonitoring( this ); |
1127 | int monitorCode = _prismHeader ? 1 : 2; | 1127 | } |
1128 | if ( b ) | 1128 | |
1129 | { | 1129 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
1130 | _if->setPrivate( "monitor", 1, monitorCode ); | 1130 | { |
1131 | } | 1131 | } |
1132 | else | 1132 | |
1133 | { | 1133 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
1134 | _if->setPrivate( "monitor", 1, 0 ); | 1134 | { |
1135 | } | 1135 | int monitorCode = _prismHeader ? 1 : 2; |
1136 | } | 1136 | if ( b ) |
1137 | 1137 | { | |
1138 | 1138 | _if->setPrivate( "monitor", 1, monitorCode ); | |
1139 | QString OHostAPMonitoringInterface::name() const | 1139 | } |
1140 | { | 1140 | else |
1141 | return "hostap"; | 1141 | { |
1142 | } | 1142 | _if->setPrivate( "monitor", 1, 0 ); |
1143 | 1143 | } | |
1144 | 1144 | } | |
1145 | /*====================================================================================== | 1145 | |
1146 | * OOrinocoNetworkInterface | 1146 | |
1147 | *======================================================================================*/ | 1147 | QString OHostAPMonitoringInterface::name() const |
1148 | 1148 | { | |
1149 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1149 | return "hostap"; |
1150 | :OMonitoringInterface( iface, prismHeader ) | 1150 | } |
1151 | { | 1151 | |
1152 | iface->setMonitoring( this ); | 1152 | |
1153 | } | 1153 | /*====================================================================================== |
1154 | 1154 | * OOrinocoNetworkInterface | |
1155 | 1155 | *======================================================================================*/ | |
1156 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 1156 | |
1157 | { | 1157 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1158 | } | 1158 | :OMonitoringInterface( iface, prismHeader ) |
1159 | 1159 | { | |
1160 | 1160 | iface->setMonitoring( this ); | |
1161 | void OOrinocoMonitoringInterface::setChannel( int c ) | 1161 | } |
1162 | { | 1162 | |
1163 | int monitorCode = _prismHeader ? 1 : 2; | 1163 | |
1164 | _if->setPrivate( "monitor", 2, monitorCode, c ); | 1164 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
1165 | } | 1165 | { |
1166 | 1166 | } | |
1167 | 1167 | ||
1168 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 1168 | |
1169 | { | 1169 | void OOrinocoMonitoringInterface::setChannel( int c ) |
1170 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 1170 | { |
1171 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 1171 | int monitorCode = _prismHeader ? 1 : 2; |
1172 | // However, as of recent orinoco drivers, IW_MODE_MONITOR is still not supported | 1172 | _if->setPrivate( "monitor", 2, monitorCode, c ); |
1173 | 1173 | } | |
1174 | if ( b ) | 1174 | |
1175 | { | 1175 | |
1176 | setChannel( 1 ); | 1176 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
1177 | } | 1177 | { |
1178 | else | 1178 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
1179 | { | 1179 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
1180 | _if->setPrivate( "monitor", 2, 0, 0 ); | 1180 | // However, as of recent orinoco drivers, IW_MODE_MONITOR is still not supported |
1181 | } | 1181 | |
1182 | } | 1182 | if ( b ) |
1183 | 1183 | { | |
1184 | 1184 | setChannel( 1 ); | |
1185 | QString OOrinocoMonitoringInterface::name() const | 1185 | } |
1186 | { | 1186 | else |
1187 | return "orinoco"; | 1187 | { |
1188 | } | 1188 | _if->setPrivate( "monitor", 2, 0, 0 ); |
1189 | } | ||
1190 | } | ||
1191 | |||
1192 | |||
1193 | QString OOrinocoMonitoringInterface::name() const | ||
1194 | { | ||
1195 | return "orinoco"; | ||
1196 | } | ||
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 635224c..e9b3b2c 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,1320 +1,1317 @@ | |||
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 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | #include <opie2/opcap.h> | 32 | #include <opie2/opcap.h> |
33 | 33 | #include <opie2/odebug.h> | |
34 | /* QT */ | 34 | |
35 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) | 35 | /* QT */ |
36 | #include <qsocketnotifier.h> | 36 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) |
37 | #include <qobjectlist.h> | 37 | #include <qsocketnotifier.h> |
38 | 38 | #include <qobjectlist.h> | |
39 | /* SYSTEM */ | 39 | |
40 | #include <sys/time.h> | 40 | /* SYSTEM */ |
41 | #include <sys/types.h> | 41 | #include <sys/time.h> |
42 | #include <unistd.h> | 42 | #include <sys/types.h> |
43 | 43 | #include <unistd.h> | |
44 | /* LOCAL */ | 44 | |
45 | #include "udp_ports.h" | 45 | /* LOCAL */ |
46 | 46 | #include "udp_ports.h" | |
47 | /*====================================================================================== | 47 | |
48 | * OPacket | 48 | /*====================================================================================== |
49 | *======================================================================================*/ | 49 | * OPacket |
50 | 50 | *======================================================================================*/ | |
51 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) | 51 | |
52 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) | 52 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) |
53 | { | 53 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) |
54 | //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | 54 | { |
55 | 55 | //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | |
56 | _end = (unsigned char*) data + header.len; | 56 | |
57 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | 57 | _end = (unsigned char*) data + header.len; |
58 | 58 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | |
59 | switch ( datalink ) | 59 | |
60 | { | 60 | switch ( datalink ) |
61 | case DLT_EN10MB: | 61 | { |
62 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); | 62 | case DLT_EN10MB: |
63 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); | 63 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; |
64 | break; | 64 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); |
65 | 65 | break; | |
66 | case DLT_IEEE802_11: | 66 | |
67 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); | 67 | case DLT_IEEE802_11: |
68 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); | 68 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; |
69 | break; | 69 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); |
70 | 70 | break; | |
71 | case DLT_PRISM_HEADER: | 71 | |
72 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" ); | 72 | case DLT_PRISM_HEADER: |
73 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); | 73 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; |
74 | break; | 74 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); |
75 | 75 | break; | |
76 | default: | 76 | |
77 | qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink ); | 77 | default: |
78 | } | 78 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; |
79 | } | 79 | } |
80 | 80 | } | |
81 | 81 | ||
82 | OPacket::~OPacket() | 82 | |
83 | { | 83 | OPacket::~OPacket() |
84 | } | 84 | { |
85 | 85 | } | |
86 | 86 | ||
87 | timevalstruct OPacket::timeval() const | 87 | |
88 | { | 88 | timevalstruct OPacket::timeval() const |
89 | return _hdr.ts; | 89 | { |
90 | } | 90 | return _hdr.ts; |
91 | 91 | } | |
92 | 92 | ||
93 | int OPacket::caplen() const | 93 | |
94 | { | 94 | int OPacket::caplen() const |
95 | return _hdr.caplen; | 95 | { |
96 | } | 96 | return _hdr.caplen; |
97 | 97 | } | |
98 | 98 | ||
99 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 99 | |
100 | { | 100 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
101 | if (!l) return; | 101 | { |
102 | QObject* o = l->first(); | 102 | if (!l) return; |
103 | while ( o ) | 103 | QObject* o = l->first(); |
104 | { | 104 | while ( o ) |
105 | stats[o->name()]++; | 105 | { |
106 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | 106 | stats[o->name()]++; |
107 | o = l->next(); | 107 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); |
108 | } | 108 | o = l->next(); |
109 | } | 109 | } |
110 | 110 | } | |
111 | 111 | ||
112 | void OPacket::dumpStructure( QObjectList* l ) | 112 | |
113 | { | 113 | void OPacket::dumpStructure( QObjectList* l ) |
114 | QString packetString( "[ |" + _dumpStructure( l ) + " ]" ); | 114 | { |
115 | qDebug( "OPacket::dumpStructure: %s", (const char*) packetString ); | 115 | QString packetString( "[ |" + _dumpStructure( l ) + " ]" ); |
116 | } | 116 | odebug << "OPacket::dumpStructure: " << packetString << oendl; |
117 | 117 | } | |
118 | 118 | ||
119 | QString OPacket::_dumpStructure( QObjectList* l ) | 119 | |
120 | { | 120 | QString OPacket::_dumpStructure( QObjectList* l ) |
121 | if (!l) return QString::null; | 121 | { |
122 | QObject* o = l->first(); | 122 | if (!l) return QString::null; |
123 | QString str(" "); | 123 | QObject* o = l->first(); |
124 | 124 | QString str(" "); | |
125 | while ( o ) | 125 | |
126 | { | 126 | while ( o ) |
127 | str.append( o->name() ); | 127 | { |
128 | str.append( " |" ); | 128 | str.append( o->name() ); |
129 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); | 129 | str.append( " |" ); |
130 | o = l->next(); | 130 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); |
131 | } | 131 | o = l->next(); |
132 | return str; | 132 | } |
133 | } | 133 | return str; |
134 | 134 | } | |
135 | QString OPacket::dump( int bpl ) const | 135 | |
136 | { | 136 | QString OPacket::dump( int bpl ) const |
137 | static int index = 0; | 137 | { |
138 | index++; | 138 | static int index = 0; |
139 | int len = _hdr.caplen; | 139 | index++; |
140 | QString str; | 140 | int len = _hdr.caplen; |
141 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); | 141 | QString str; |
142 | str.append( "0000: " ); | 142 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); |
143 | QString tmp; | 143 | str.append( "0000: " ); |
144 | QString bytes; | 144 | QString tmp; |
145 | QString chars; | 145 | QString bytes; |
146 | 146 | QString chars; | |
147 | for ( int i = 0; i < len; ++i ) | 147 | |
148 | { | 148 | for ( int i = 0; i < len; ++i ) |
149 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 149 | { |
150 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 150 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
151 | else chars.append( '.' ); | 151 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
152 | 152 | else chars.append( '.' ); | |
153 | if ( !((i+1) % bpl) ) | 153 | |
154 | { | 154 | if ( !((i+1) % bpl) ) |
155 | str.append( bytes ); | 155 | { |
156 | str.append( ' ' ); | 156 | str.append( bytes ); |
157 | str.append( chars ); | 157 | str.append( ' ' ); |
158 | str.append( '\n' ); | 158 | str.append( chars ); |
159 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); | 159 | str.append( '\n' ); |
160 | bytes = ""; | 160 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); |
161 | chars = ""; | 161 | bytes = ""; |
162 | } | 162 | chars = ""; |
163 | 163 | } | |
164 | } | 164 | |
165 | if ( (len % bpl) ) | 165 | } |
166 | { | 166 | if ( (len % bpl) ) |
167 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); | 167 | { |
168 | str.append( chars ); | 168 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
169 | } | 169 | str.append( chars ); |
170 | str.append( '\n' ); | 170 | } |
171 | return str; | 171 | str.append( '\n' ); |
172 | } | 172 | return str; |
173 | 173 | } | |
174 | 174 | ||
175 | int OPacket::len() const | 175 | |
176 | { | 176 | int OPacket::len() const |
177 | return _hdr.len; | 177 | { |
178 | } | 178 | return _hdr.len; |
179 | 179 | } | |
180 | 180 | ||
181 | /*====================================================================================== | 181 | |
182 | * OEthernetPacket | 182 | /*====================================================================================== |
183 | *======================================================================================*/ | 183 | * OEthernetPacket |
184 | 184 | *======================================================================================*/ | |
185 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 185 | |
186 | :QObject( parent, "Ethernet" ), _ether( data ) | 186 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
187 | { | 187 | :QObject( parent, "Ethernet" ), _ether( data ) |
188 | 188 | { | |
189 | qDebug( "Source = %s", (const char*) sourceAddress().toString() ); | 189 | |
190 | qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); | 190 | odebug << "Source = " << sourceAddress().toString(); |
191 | 191 | odebug << "Destination = " << destinationAddress().toString(); | |
192 | if ( sourceAddress() == OMacAddress::broadcast ) | 192 | |
193 | qDebug( "Source is broadcast address" ); | 193 | if ( sourceAddress() == OMacAddress::broadcast ) |
194 | if ( destinationAddress() == OMacAddress::broadcast ) | 194 | odebug << "Source is broadcast address" << oendl; |
195 | qDebug( "Destination is broadcast address" ); | 195 | if ( destinationAddress() == OMacAddress::broadcast ) |
196 | 196 | odebug << "Destination is broadcast address" << oendl; | |
197 | switch ( type() ) | 197 | |
198 | { | 198 | switch ( type() ) |
199 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 199 | { |
200 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 200 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
201 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } | 201 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
202 | default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); | 202 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } |
203 | } | 203 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; |
204 | 204 | } | |
205 | } | 205 | |
206 | 206 | } | |
207 | 207 | ||
208 | OEthernetPacket::~OEthernetPacket() | 208 | |
209 | { | 209 | OEthernetPacket::~OEthernetPacket() |
210 | } | 210 | { |
211 | 211 | } | |
212 | 212 | ||
213 | OMacAddress OEthernetPacket::sourceAddress() const | 213 | |
214 | { | 214 | OMacAddress OEthernetPacket::sourceAddress() const |
215 | return OMacAddress( _ether->ether_shost ); | 215 | { |
216 | } | 216 | return OMacAddress( _ether->ether_shost ); |
217 | 217 | } | |
218 | 218 | ||
219 | OMacAddress OEthernetPacket::destinationAddress() const | 219 | |
220 | { | 220 | OMacAddress OEthernetPacket::destinationAddress() const |
221 | return OMacAddress( _ether->ether_dhost ); | 221 | { |
222 | } | 222 | return OMacAddress( _ether->ether_dhost ); |
223 | 223 | } | |
224 | int OEthernetPacket::type() const | 224 | |
225 | { | 225 | int OEthernetPacket::type() const |
226 | return ntohs( _ether->ether_type ); | 226 | { |
227 | } | 227 | return ntohs( _ether->ether_type ); |
228 | 228 | } | |
229 | 229 | ||
230 | /*====================================================================================== | 230 | |
231 | * OIPPacket | 231 | /*====================================================================================== |
232 | *======================================================================================*/ | 232 | * OIPPacket |
233 | 233 | *======================================================================================*/ | |
234 | 234 | ||
235 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) | 235 | |
236 | :QObject( parent, "IP" ), _iphdr( data ) | 236 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
237 | { | 237 | :QObject( parent, "IP" ), _iphdr( data ) |
238 | qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); | 238 | { |
239 | 239 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; | |
240 | //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); | 240 | |
241 | //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); | 241 | odebug << "FromAddress = " << fromIPAddress().toString(); |
242 | 242 | odebug << " toAddress = " << toIPAddress().toString(); | |
243 | qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); | 243 | |
244 | qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); | 244 | switch ( protocol() ) |
245 | 245 | { | |
246 | switch ( protocol() ) | 246 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
247 | { | 247 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
248 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 248 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; |
249 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 249 | } |
250 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); | 250 | |
251 | } | 251 | } |
252 | 252 | ||
253 | } | 253 | OIPPacket::~OIPPacket() |
254 | 254 | { | |
255 | OIPPacket::~OIPPacket() | 255 | } |
256 | { | 256 | |
257 | } | 257 | |
258 | 258 | QHostAddress OIPPacket::fromIPAddress() const | |
259 | 259 | { | |
260 | QHostAddress OIPPacket::fromIPAddress() const | 260 | return EXTRACT_32BITS( &_iphdr->saddr ); |
261 | { | 261 | } |
262 | return EXTRACT_32BITS( &_iphdr->saddr ); | 262 | |
263 | } | 263 | |
264 | 264 | QHostAddress OIPPacket::toIPAddress() const | |
265 | 265 | { | |
266 | QHostAddress OIPPacket::toIPAddress() const | 266 | return EXTRACT_32BITS( &_iphdr->saddr ); |
267 | { | 267 | } |
268 | return EXTRACT_32BITS( &_iphdr->saddr ); | 268 | |
269 | } | 269 | |
270 | 270 | int OIPPacket::tos() const | |
271 | 271 | { | |
272 | int OIPPacket::tos() const | 272 | return _iphdr->tos; |
273 | { | 273 | } |
274 | return _iphdr->tos; | 274 | |
275 | } | 275 | |
276 | 276 | int OIPPacket::len() const | |
277 | 277 | { | |
278 | int OIPPacket::len() const | 278 | return EXTRACT_16BITS( &_iphdr->tot_len ); |
279 | { | 279 | } |
280 | return EXTRACT_16BITS( &_iphdr->tot_len ); | 280 | |
281 | } | 281 | |
282 | 282 | int OIPPacket::id() const | |
283 | 283 | { | |
284 | int OIPPacket::id() const | 284 | return EXTRACT_16BITS( &_iphdr->id ); |
285 | { | 285 | } |
286 | return EXTRACT_16BITS( &_iphdr->id ); | 286 | |
287 | } | 287 | |
288 | 288 | int OIPPacket::offset() const | |
289 | 289 | { | |
290 | int OIPPacket::offset() const | 290 | return EXTRACT_16BITS( &_iphdr->frag_off ); |
291 | { | 291 | } |
292 | return EXTRACT_16BITS( &_iphdr->frag_off ); | 292 | |
293 | } | 293 | |
294 | 294 | int OIPPacket::ttl() const | |
295 | 295 | { | |
296 | int OIPPacket::ttl() const | 296 | return _iphdr->ttl; |
297 | { | 297 | } |
298 | return _iphdr->ttl; | 298 | |
299 | } | 299 | |
300 | 300 | int OIPPacket::protocol() const | |
301 | 301 | { | |
302 | int OIPPacket::protocol() const | 302 | return _iphdr->protocol; |
303 | { | 303 | } |
304 | return _iphdr->protocol; | 304 | |
305 | } | 305 | |
306 | 306 | int OIPPacket::checksum() const | |
307 | 307 | { | |
308 | int OIPPacket::checksum() const | 308 | return EXTRACT_16BITS( &_iphdr->check ); |
309 | { | 309 | } |
310 | return EXTRACT_16BITS( &_iphdr->check ); | 310 | |
311 | } | 311 | /*====================================================================================== |
312 | 312 | * OARPPacket | |
313 | /*====================================================================================== | 313 | *======================================================================================*/ |
314 | * OARPPacket | 314 | |
315 | *======================================================================================*/ | 315 | |
316 | 316 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) | |
317 | 317 | :QObject( parent, "ARP" ), _arphdr( data ) | |
318 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) | 318 | { |
319 | :QObject( parent, "ARP" ), _arphdr( data ) | 319 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; |
320 | { | 320 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; |
321 | qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." ); | 321 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; |
322 | qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() ); | 322 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; |
323 | qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() ); | 323 | } |
324 | qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() ); | 324 | |
325 | } | 325 | |
326 | 326 | OARPPacket::~OARPPacket() | |
327 | 327 | { | |
328 | OARPPacket::~OARPPacket() | 328 | } |
329 | { | 329 | |
330 | } | 330 | |
331 | 331 | QString OARPPacket::type() const | |
332 | 332 | { | |
333 | QString OARPPacket::type() const | 333 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) |
334 | { | 334 | { |
335 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) | 335 | case 1: return "REQUEST"; |
336 | { | 336 | case 2: return "REPLY"; |
337 | case 1: return "REQUEST"; | 337 | case 3: return "RREQUEST"; |
338 | case 2: return "REPLY"; | 338 | case 4: return "RREPLY"; |
339 | case 3: return "RREQUEST"; | 339 | case 8: return "InREQUEST"; |
340 | case 4: return "RREPLY"; | 340 | case 9: return "InREPLY"; |
341 | case 8: return "InREQUEST"; | 341 | case 10: return "NAK"; |
342 | case 9: return "InREPLY"; | 342 | default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>"; |
343 | case 10: return "NAK"; | 343 | } |
344 | default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>"; | 344 | } |
345 | } | 345 | |
346 | } | 346 | |
347 | 347 | QHostAddress OARPPacket::senderIPV4Address() const | |
348 | 348 | { | |
349 | QHostAddress OARPPacket::senderIPV4Address() const | 349 | return EXTRACT_32BITS( &_arphdr->ar_sip ); |
350 | { | 350 | } |
351 | return EXTRACT_32BITS( &_arphdr->ar_sip ); | 351 | |
352 | } | 352 | |
353 | 353 | QHostAddress OARPPacket::targetIPV4Address() const | |
354 | 354 | { | |
355 | QHostAddress OARPPacket::targetIPV4Address() const | 355 | return EXTRACT_32BITS( &_arphdr->ar_tip ); |
356 | { | 356 | } |
357 | return EXTRACT_32BITS( &_arphdr->ar_tip ); | 357 | |
358 | } | 358 | |
359 | 359 | OMacAddress OARPPacket::senderMacAddress() const | |
360 | 360 | { | |
361 | OMacAddress OARPPacket::senderMacAddress() const | 361 | return OMacAddress( _arphdr->ar_sha ); |
362 | { | 362 | } |
363 | return OMacAddress( _arphdr->ar_sha ); | 363 | |
364 | } | 364 | |
365 | 365 | OMacAddress OARPPacket::targetMacAddress() const | |
366 | 366 | { | |
367 | OMacAddress OARPPacket::targetMacAddress() const | 367 | return OMacAddress( _arphdr->ar_tha ); |
368 | { | 368 | } |
369 | return OMacAddress( _arphdr->ar_tha ); | 369 | |
370 | } | 370 | |
371 | 371 | /*====================================================================================== | |
372 | 372 | * OUDPPacket | |
373 | /*====================================================================================== | 373 | *======================================================================================*/ |
374 | * OUDPPacket | 374 | |
375 | *======================================================================================*/ | 375 | |
376 | 376 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | |
377 | 377 | :QObject( parent, "UDP" ), _udphdr( data ) | |
378 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | 378 | |
379 | :QObject( parent, "UDP" ), _udphdr( data ) | 379 | { |
380 | 380 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; | |
381 | { | 381 | odebug << "fromPort = " << fromPort() << oendl; |
382 | qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); | 382 | odebug << " toPort = " << toPort() << oendl; |
383 | qDebug( "fromPort = %d", fromPort() ); | 383 | |
384 | qDebug( " toPort = %d", toPort() ); | 384 | // TODO: Make this a case or a hash if we know more udp protocols |
385 | 385 | ||
386 | // TODO: Make this a case or a hash if we know more udp protocols | 386 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || |
387 | 387 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) | |
388 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || | 388 | { |
389 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) | 389 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; |
390 | { | 390 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); |
391 | qDebug( "seems to be part of a DHCP conversation => creating DHCP packet." ); | 391 | } |
392 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); | 392 | } |
393 | } | 393 | |
394 | } | 394 | |
395 | 395 | OUDPPacket::~OUDPPacket() | |
396 | 396 | { | |
397 | OUDPPacket::~OUDPPacket() | 397 | } |
398 | { | 398 | |
399 | } | 399 | |
400 | 400 | int OUDPPacket::fromPort() const | |
401 | 401 | { | |
402 | int OUDPPacket::fromPort() const | 402 | return EXTRACT_16BITS( &_udphdr->source ); |
403 | { | 403 | } |
404 | return EXTRACT_16BITS( &_udphdr->source ); | 404 | |
405 | } | 405 | |
406 | 406 | int OUDPPacket::toPort() const | |
407 | 407 | { | |
408 | int OUDPPacket::toPort() const | 408 | return EXTRACT_16BITS( &_udphdr->dest ); |
409 | { | 409 | } |
410 | return EXTRACT_16BITS( &_udphdr->dest ); | 410 | |
411 | } | 411 | |
412 | 412 | int OUDPPacket::length() const | |
413 | 413 | { | |
414 | int OUDPPacket::length() const | 414 | return EXTRACT_16BITS( &_udphdr->len ); |
415 | { | 415 | } |
416 | return EXTRACT_16BITS( &_udphdr->len ); | 416 | |
417 | } | 417 | |
418 | 418 | int OUDPPacket::checksum() const | |
419 | 419 | { | |
420 | int OUDPPacket::checksum() const | 420 | return EXTRACT_16BITS( &_udphdr->check ); |
421 | { | 421 | } |
422 | return EXTRACT_16BITS( &_udphdr->check ); | 422 | |
423 | } | 423 | |
424 | 424 | /*====================================================================================== | |
425 | 425 | * ODHCPPacket | |
426 | /*====================================================================================== | 426 | *======================================================================================*/ |
427 | * ODHCPPacket | 427 | |
428 | *======================================================================================*/ | 428 | |
429 | 429 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) | |
430 | 430 | :QObject( parent, "DHCP" ), _dhcphdr( data ) | |
431 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) | 431 | |
432 | :QObject( parent, "DHCP" ), _dhcphdr( data ) | 432 | { |
433 | 433 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; | |
434 | { | 434 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; |
435 | qDebug( "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." ); | 435 | odebug << "clientAddress = " << clientAddress().toString() << oendl; |
436 | qDebug( "DHCP opcode seems to be %02d - '%s'", _dhcphdr->op, isRequest() ? "REQUEST" : "REPLY" ); | 436 | odebug << " yourAddress = " << yourAddress().toString() << oendl; |
437 | qDebug( "clientAddress: %s", (const char*) clientAddress().toString() ); | 437 | odebug << "serverAddress = " << serverAddress().toString() << oendl; |
438 | qDebug( " yourAddress: %s", (const char*) yourAddress().toString() ); | 438 | odebug << " relayAddress = " << relayAddress().toString() << oendl; |
439 | qDebug( "serverAddress: %s", (const char*) serverAddress().toString() ); | 439 | odebug << "parsing DHCP options..." << oendl; |
440 | qDebug( " relayAddress: %s", (const char*) relayAddress().toString() ); | 440 | |
441 | qDebug( "parsing DHCP options..." ); | 441 | _type = 0; |
442 | 442 | ||
443 | _type = 0; | 443 | const unsigned char* option = &_dhcphdr->options[4]; |
444 | 444 | char tag = -1; | |
445 | const unsigned char* option = &_dhcphdr->options[4]; | 445 | char len = -1; |
446 | char tag = -1; | 446 | |
447 | char len = -1; | 447 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) |
448 | 448 | { | |
449 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) | 449 | len = *option++; |
450 | { | 450 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; |
451 | len = *option++; | 451 | |
452 | qDebug( "recognized DHCP option #%d, length %d", tag, len ); | 452 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) |
453 | 453 | _type = *option; | |
454 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) | 454 | |
455 | _type = *option; | 455 | option += len; |
456 | 456 | if ( option >= end ) | |
457 | option += len; | 457 | { |
458 | if ( option >= end ) | 458 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; |
459 | { | 459 | break; |
460 | qWarning( "DHCP parsing ERROR: sanity check says the packet is at its end!" ); | 460 | } |
461 | break; | 461 | } |
462 | } | 462 | |
463 | } | 463 | odebug << "DHCP type seems to be << " << type() << oendl; |
464 | 464 | } | |
465 | qDebug( "DHCP type seems to be '%s'", (const char*) type() ); | 465 | |
466 | } | 466 | |
467 | 467 | ODHCPPacket::~ODHCPPacket() | |
468 | 468 | { | |
469 | ODHCPPacket::~ODHCPPacket() | 469 | } |
470 | { | 470 | |
471 | } | 471 | |
472 | 472 | bool ODHCPPacket::isRequest() const | |
473 | 473 | { | |
474 | bool ODHCPPacket::isRequest() const | 474 | return ( _dhcphdr->op == 01 ); |
475 | { | 475 | } |
476 | return ( _dhcphdr->op == 01 ); | 476 | |
477 | } | 477 | |
478 | 478 | bool ODHCPPacket::isReply() const | |
479 | 479 | { | |
480 | bool ODHCPPacket::isReply() const | 480 | return ( _dhcphdr->op == 02 ); |
481 | { | 481 | } |
482 | return ( _dhcphdr->op == 02 ); | 482 | |
483 | } | 483 | |
484 | 484 | QString ODHCPPacket::type() const | |
485 | 485 | { | |
486 | QString ODHCPPacket::type() const | 486 | switch ( _type ) |
487 | { | 487 | { |
488 | switch ( _type ) | 488 | case 1: return "DISCOVER"; |
489 | { | 489 | case 2: return "OFFER"; |
490 | case 1: return "DISCOVER"; | 490 | case 3: return "REQUEST"; |
491 | case 2: return "OFFER"; | 491 | case 4: return "DECLINE"; |
492 | case 3: return "REQUEST"; | 492 | case 5: return "ACK"; |
493 | case 4: return "DECLINE"; | 493 | case 6: return "NAK"; |
494 | case 5: return "ACK"; | 494 | case 7: return "RELEASE"; |
495 | case 6: return "NAK"; | 495 | case 8: return "INFORM"; |
496 | case 7: return "RELEASE"; | 496 | default: qWarning( "ODHCPPacket::type(): invalid DHCP type (%d) !", _dhcphdr->op ); return "<unknown>"; |
497 | case 8: return "INFORM"; | 497 | } |
498 | default: qWarning( "ODHCPPacket::type(): invalid DHCP type (%d) !", _dhcphdr->op ); return "<unknown>"; | 498 | } |
499 | } | 499 | |
500 | } | 500 | |
501 | 501 | QHostAddress ODHCPPacket::clientAddress() const | |
502 | 502 | { | |
503 | QHostAddress ODHCPPacket::clientAddress() const | 503 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); |
504 | { | 504 | } |
505 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); | 505 | |
506 | } | 506 | |
507 | 507 | QHostAddress ODHCPPacket::yourAddress() const | |
508 | 508 | { | |
509 | QHostAddress ODHCPPacket::yourAddress() const | 509 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); |
510 | { | 510 | } |
511 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); | 511 | |
512 | } | 512 | |
513 | 513 | QHostAddress ODHCPPacket::serverAddress() const | |
514 | 514 | { | |
515 | QHostAddress ODHCPPacket::serverAddress() const | 515 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); |
516 | { | 516 | } |
517 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); | 517 | |
518 | } | 518 | |
519 | 519 | QHostAddress ODHCPPacket::relayAddress() const | |
520 | 520 | { | |
521 | QHostAddress ODHCPPacket::relayAddress() const | 521 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); |
522 | { | 522 | } |
523 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); | 523 | |
524 | } | 524 | |
525 | 525 | OMacAddress ODHCPPacket::clientMacAddress() const | |
526 | 526 | { | |
527 | OMacAddress ODHCPPacket::clientMacAddress() const | 527 | return OMacAddress( _dhcphdr->chaddr ); |
528 | { | 528 | } |
529 | return OMacAddress( _dhcphdr->chaddr ); | 529 | |
530 | } | 530 | |
531 | 531 | /*====================================================================================== | |
532 | 532 | * OTCPPacket | |
533 | /*====================================================================================== | 533 | *======================================================================================*/ |
534 | * OTCPPacket | 534 | |
535 | *======================================================================================*/ | 535 | |
536 | 536 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) | |
537 | 537 | :QObject( parent, "TCP" ), _tcphdr( data ) | |
538 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) | 538 | |
539 | :QObject( parent, "TCP" ), _tcphdr( data ) | 539 | { |
540 | 540 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; | |
541 | { | 541 | } |
542 | qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); | 542 | |
543 | } | 543 | |
544 | 544 | OTCPPacket::~OTCPPacket() | |
545 | 545 | { | |
546 | OTCPPacket::~OTCPPacket() | 546 | } |
547 | { | 547 | |
548 | } | 548 | |
549 | 549 | int OTCPPacket::fromPort() const | |
550 | 550 | { | |
551 | int OTCPPacket::fromPort() const | 551 | return EXTRACT_16BITS( &_tcphdr->source ); |
552 | { | 552 | } |
553 | return EXTRACT_16BITS( &_tcphdr->source ); | 553 | |
554 | } | 554 | |
555 | 555 | int OTCPPacket::toPort() const | |
556 | 556 | { | |
557 | int OTCPPacket::toPort() const | 557 | return EXTRACT_16BITS( &_tcphdr->dest ); |
558 | { | 558 | } |
559 | return EXTRACT_16BITS( &_tcphdr->dest ); | 559 | |
560 | } | 560 | |
561 | 561 | int OTCPPacket::seq() const | |
562 | 562 | { | |
563 | int OTCPPacket::seq() const | 563 | return EXTRACT_16BITS( &_tcphdr->seq ); |
564 | { | 564 | } |
565 | return EXTRACT_16BITS( &_tcphdr->seq ); | 565 | |
566 | } | 566 | |
567 | 567 | int OTCPPacket::ack() const | |
568 | 568 | { | |
569 | int OTCPPacket::ack() const | 569 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); |
570 | { | 570 | } |
571 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); | 571 | |
572 | } | 572 | |
573 | 573 | int OTCPPacket::window() const | |
574 | 574 | { | |
575 | int OTCPPacket::window() const | 575 | return EXTRACT_16BITS( &_tcphdr->window ); |
576 | { | 576 | } |
577 | return EXTRACT_16BITS( &_tcphdr->window ); | 577 | |
578 | } | 578 | |
579 | 579 | int OTCPPacket::checksum() const | |
580 | 580 | { | |
581 | int OTCPPacket::checksum() const | 581 | return EXTRACT_16BITS( &_tcphdr->check ); |
582 | { | 582 | } |
583 | return EXTRACT_16BITS( &_tcphdr->check ); | 583 | |
584 | } | 584 | /*====================================================================================== |
585 | 585 | * OPrismHeaderPacket | |
586 | /*====================================================================================== | 586 | *======================================================================================*/ |
587 | * OPrismHeaderPacket | 587 | |
588 | *======================================================================================*/ | 588 | |
589 | 589 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) | |
590 | 590 | :QObject( parent, "Prism" ), _header( data ) | |
591 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) | 591 | |
592 | :QObject( parent, "Prism" ), _header( data ) | 592 | { |
593 | 593 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; | |
594 | { | 594 | |
595 | qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." ); | 595 | odebug << "Signal Strength = " << data->signal.data << oendl; |
596 | 596 | ||
597 | qDebug( "Signal Strength = %d", data->signal.data ); | 597 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); |
598 | 598 | } | |
599 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); | 599 | |
600 | } | 600 | OPrismHeaderPacket::~OPrismHeaderPacket() |
601 | 601 | { | |
602 | OPrismHeaderPacket::~OPrismHeaderPacket() | 602 | } |
603 | { | 603 | |
604 | } | 604 | |
605 | 605 | unsigned int OPrismHeaderPacket::signalStrength() const | |
606 | 606 | { | |
607 | unsigned int OPrismHeaderPacket::signalStrength() const | 607 | return _header->signal.data; |
608 | { | 608 | } |
609 | return _header->signal.data; | 609 | |
610 | } | 610 | /*====================================================================================== |
611 | 611 | * OWaveLanPacket | |
612 | /*====================================================================================== | 612 | *======================================================================================*/ |
613 | * OWaveLanPacket | 613 | |
614 | *======================================================================================*/ | 614 | |
615 | 615 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) | |
616 | 616 | :QObject( parent, "802.11" ), _wlanhdr( data ) | |
617 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) | 617 | |
618 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 618 | { |
619 | 619 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; | |
620 | { | 620 | odebug << "type = " << type() << oendl; |
621 | qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); | 621 | odebug << "subType = " << subType() << oendl; |
622 | qDebug( "type: %0X", type() ); | 622 | odebug << "duration = " << duration() << oendl; |
623 | qDebug( "subType: %0X", subType() ); | 623 | odebug << "powermanagement = " << usesPowerManagement() << oendl; |
624 | qDebug( "duration: %d", duration() ); | 624 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; |
625 | qDebug( "powermanagement: %d", usesPowerManagement() ); | 625 | odebug << "MAC1 = " << macAddress1().toString() << oendl; |
626 | qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); | 626 | odebug << "MAC2 = " << macAddress2().toString() << oendl; |
627 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); | 627 | odebug << "MAC3 = " << macAddress3().toString() << oendl; |
628 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); | 628 | odebug << "MAC4 = " << macAddress4().toString() << oendl; |
629 | qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); | 629 | |
630 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); | 630 | switch ( type() ) |
631 | 631 | { | |
632 | switch ( type() ) | 632 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
633 | { | 633 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
634 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 634 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
635 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 635 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; |
636 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; | 636 | } |
637 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); | 637 | } |
638 | } | 638 | |
639 | } | 639 | OWaveLanPacket::~OWaveLanPacket() |
640 | 640 | { | |
641 | OWaveLanPacket::~OWaveLanPacket() | 641 | } |
642 | { | 642 | |
643 | } | 643 | |
644 | 644 | int OWaveLanPacket::duration() const | |
645 | 645 | { | |
646 | int OWaveLanPacket::duration() const | 646 | return _wlanhdr->duration; |
647 | { | 647 | } |
648 | return _wlanhdr->duration; | 648 | |
649 | } | 649 | |
650 | 650 | OMacAddress OWaveLanPacket::macAddress1() const | |
651 | 651 | { | |
652 | OMacAddress OWaveLanPacket::macAddress1() const | 652 | return OMacAddress( _wlanhdr->mac1 ); |
653 | { | 653 | } |
654 | return OMacAddress( _wlanhdr->mac1 ); | 654 | |
655 | } | 655 | |
656 | 656 | OMacAddress OWaveLanPacket::macAddress2() const | |
657 | 657 | { | |
658 | OMacAddress OWaveLanPacket::macAddress2() const | 658 | return OMacAddress( _wlanhdr->mac2 ); |
659 | { | 659 | } |
660 | return OMacAddress( _wlanhdr->mac2 ); | 660 | |
661 | } | 661 | |
662 | 662 | OMacAddress OWaveLanPacket::macAddress3() const | |
663 | 663 | { | |
664 | OMacAddress OWaveLanPacket::macAddress3() const | 664 | return OMacAddress( _wlanhdr->mac3 ); |
665 | { | 665 | } |
666 | return OMacAddress( _wlanhdr->mac3 ); | 666 | |
667 | } | 667 | |
668 | 668 | OMacAddress OWaveLanPacket::macAddress4() const | |
669 | 669 | { | |
670 | OMacAddress OWaveLanPacket::macAddress4() const | 670 | return OMacAddress( _wlanhdr->mac4 ); |
671 | { | 671 | } |
672 | return OMacAddress( _wlanhdr->mac4 ); | 672 | |
673 | } | 673 | |
674 | 674 | int OWaveLanPacket::subType() const | |
675 | 675 | { | |
676 | int OWaveLanPacket::subType() const | 676 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
677 | { | 677 | } |
678 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 678 | |
679 | } | 679 | |
680 | 680 | int OWaveLanPacket::type() const | |
681 | 681 | { | |
682 | int OWaveLanPacket::type() const | 682 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
683 | { | 683 | } |
684 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 684 | |
685 | } | 685 | |
686 | 686 | int OWaveLanPacket::version() const | |
687 | 687 | { | |
688 | int OWaveLanPacket::version() const | 688 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
689 | { | 689 | } |
690 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 690 | |
691 | } | 691 | |
692 | 692 | bool OWaveLanPacket::fromDS() const | |
693 | 693 | { | |
694 | bool OWaveLanPacket::fromDS() const | 694 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
695 | { | 695 | } |
696 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 696 | |
697 | } | 697 | |
698 | 698 | bool OWaveLanPacket::toDS() const | |
699 | 699 | { | |
700 | bool OWaveLanPacket::toDS() const | 700 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
701 | { | 701 | } |
702 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 702 | |
703 | } | 703 | |
704 | 704 | bool OWaveLanPacket::usesPowerManagement() const | |
705 | 705 | { | |
706 | bool OWaveLanPacket::usesPowerManagement() const | 706 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
707 | { | 707 | } |
708 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 708 | |
709 | } | 709 | |
710 | 710 | bool OWaveLanPacket::usesWep() const | |
711 | 711 | { | |
712 | bool OWaveLanPacket::usesWep() const | 712 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
713 | { | 713 | } |
714 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 714 | |
715 | } | 715 | |
716 | 716 | /*====================================================================================== | |
717 | 717 | * OWaveLanManagementPacket | |
718 | /*====================================================================================== | 718 | *======================================================================================*/ |
719 | * OWaveLanManagementPacket | 719 | |
720 | *======================================================================================*/ | 720 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
721 | 721 | :QObject( parent, "802.11 Management" ), _header( data ), | |
722 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 722 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
723 | :QObject( parent, "802.11 Management" ), _header( data ), | 723 | { |
724 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 724 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; |
725 | { | 725 | odebug << "Detected subtype is " << managementType() << oendl; |
726 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); | 726 | |
727 | qDebug( "Detected subtype is '%s'", (const char*) managementType() ); | 727 | // grab tagged values |
728 | 728 | const unsigned char* ptr = (const unsigned char*) (_body+1); | |
729 | // grab tagged values | 729 | while (ptr < end) |
730 | const unsigned char* ptr = (const unsigned char*) (_body+1); | 730 | { |
731 | while (ptr < end) | 731 | switch ( *ptr ) |
732 | { | 732 | { |
733 | switch ( *ptr ) | 733 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; |
734 | { | 734 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; |
735 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | 735 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; |
736 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | 736 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; |
737 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | 737 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; |
738 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | 738 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; |
739 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | 739 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; |
740 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | 740 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; |
741 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | 741 | } |
742 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | 742 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value |
743 | } | 743 | ptr+= 2; // skip tag ID and length |
744 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | 744 | } |
745 | ptr+= 2; // skip tag ID and length | 745 | } |
746 | } | 746 | |
747 | } | 747 | |
748 | 748 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | |
749 | 749 | { | |
750 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 750 | } |
751 | { | 751 | |
752 | } | 752 | |
753 | 753 | QString OWaveLanManagementPacket::managementType() const | |
754 | 754 | { | |
755 | QString OWaveLanManagementPacket::managementType() const | 755 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
756 | { | 756 | { |
757 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 757 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; |
758 | { | 758 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; |
759 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | 759 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; |
760 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | 760 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; |
761 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | 761 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; |
762 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | 762 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; |
763 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | 763 | case ST_BEACON: return "Beacon"; break; |
764 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; | 764 | case ST_ATIM: return "Atim"; break; |
765 | case ST_BEACON: return "Beacon"; break; | 765 | case ST_DISASSOC: return "Disassociation"; break; |
766 | case ST_ATIM: return "Atim"; break; | 766 | case ST_AUTH: return "Authentication"; break; |
767 | case ST_DISASSOC: return "Disassociation"; break; | 767 | case ST_DEAUTH: return "Deathentication"; break; |
768 | case ST_AUTH: return "Authentication"; break; | 768 | default: |
769 | case ST_DEAUTH: return "Deathentication"; break; | 769 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); |
770 | default: | 770 | return "Unknown"; |
771 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); | 771 | } |
772 | return "Unknown"; | 772 | } |
773 | } | 773 | |
774 | } | 774 | |
775 | 775 | int OWaveLanManagementPacket::beaconInterval() const | |
776 | 776 | { | |
777 | int OWaveLanManagementPacket::beaconInterval() const | 777 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); |
778 | { | 778 | } |
779 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | 779 | |
780 | } | 780 | |
781 | 781 | int OWaveLanManagementPacket::capabilities() const | |
782 | 782 | { | |
783 | int OWaveLanManagementPacket::capabilities() const | 783 | return EXTRACT_LE_16BITS( &_body->capability_info ); |
784 | { | 784 | } |
785 | return EXTRACT_LE_16BITS( &_body->capability_info ); | 785 | |
786 | } | 786 | |
787 | 787 | bool OWaveLanManagementPacket::canESS() const | |
788 | 788 | { | |
789 | bool OWaveLanManagementPacket::canESS() const | 789 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
790 | { | 790 | } |
791 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 791 | |
792 | } | 792 | |
793 | 793 | bool OWaveLanManagementPacket::canIBSS() const | |
794 | 794 | { | |
795 | bool OWaveLanManagementPacket::canIBSS() const | 795 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
796 | { | 796 | } |
797 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 797 | |
798 | } | 798 | |
799 | 799 | bool OWaveLanManagementPacket::canCFP() const | |
800 | 800 | { | |
801 | bool OWaveLanManagementPacket::canCFP() const | 801 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
802 | { | 802 | } |
803 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 803 | |
804 | } | 804 | |
805 | 805 | bool OWaveLanManagementPacket::canCFP_REQ() const | |
806 | 806 | { | |
807 | bool OWaveLanManagementPacket::canCFP_REQ() const | 807 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
808 | { | 808 | } |
809 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 809 | |
810 | } | 810 | |
811 | 811 | bool OWaveLanManagementPacket::canPrivacy() const | |
812 | 812 | { | |
813 | bool OWaveLanManagementPacket::canPrivacy() const | 813 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
814 | { | 814 | } |
815 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 815 | |
816 | } | 816 | |
817 | 817 | /*====================================================================================== | |
818 | 818 | * OWaveLanManagementSSID | |
819 | /*====================================================================================== | 819 | *======================================================================================*/ |
820 | * OWaveLanManagementSSID | 820 | |
821 | *======================================================================================*/ | 821 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) |
822 | 822 | :QObject( parent, "802.11 SSID" ), _data( data ) | |
823 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | 823 | { |
824 | :QObject( parent, "802.11 SSID" ), _data( data ) | 824 | odebug << "OWaveLanManagementSSID()" << oendl; |
825 | { | 825 | } |
826 | qDebug( "OWaveLanManagementSSID()" ); | 826 | |
827 | } | 827 | |
828 | 828 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | |
829 | 829 | { | |
830 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | 830 | } |
831 | { | 831 | |
832 | } | 832 | |
833 | 833 | QString OWaveLanManagementSSID::ID() const | |
834 | 834 | { | |
835 | QString OWaveLanManagementSSID::ID() const | 835 | int length = _data->length; |
836 | { | 836 | if ( length > 32 ) length = 32; |
837 | int length = _data->length; | 837 | char essid[length+1]; |
838 | if ( length > 32 ) length = 32; | 838 | memcpy( &essid, &_data->ssid, length ); |
839 | char essid[length+1]; | 839 | essid[length] = 0x0; |
840 | memcpy( &essid, &_data->ssid, length ); | 840 | return essid; |
841 | essid[length] = 0x0; | 841 | } |
842 | return essid; | 842 | |
843 | } | 843 | |
844 | 844 | /*====================================================================================== | |
845 | 845 | * OWaveLanManagementRates | |
846 | /*====================================================================================== | 846 | *======================================================================================*/ |
847 | * OWaveLanManagementRates | 847 | |
848 | *======================================================================================*/ | 848 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) |
849 | 849 | :QObject( parent, "802.11 Rates" ), _data( data ) | |
850 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) | 850 | { |
851 | :QObject( parent, "802.11 Rates" ), _data( data ) | 851 | odebug << "OWaveLanManagementRates()" << oendl; |
852 | { | 852 | } |
853 | qDebug( "OWaveLanManagementRates()" ); | 853 | |
854 | } | 854 | |
855 | 855 | OWaveLanManagementRates::~OWaveLanManagementRates() | |
856 | 856 | { | |
857 | OWaveLanManagementRates::~OWaveLanManagementRates() | 857 | } |
858 | { | 858 | |
859 | } | 859 | /*====================================================================================== |
860 | 860 | * OWaveLanManagementCF | |
861 | /*====================================================================================== | 861 | *======================================================================================*/ |
862 | * OWaveLanManagementCF | 862 | |
863 | *======================================================================================*/ | 863 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) |
864 | 864 | :QObject( parent, "802.11 CF" ), _data( data ) | |
865 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) | 865 | { |
866 | :QObject( parent, "802.11 CF" ), _data( data ) | 866 | odebug << "OWaveLanManagementCF()" << oendl; |
867 | { | 867 | } |
868 | qDebug( "OWaveLanManagementCF()" ); | 868 | |
869 | } | 869 | |
870 | 870 | OWaveLanManagementCF::~OWaveLanManagementCF() | |
871 | 871 | { | |
872 | OWaveLanManagementCF::~OWaveLanManagementCF() | 872 | } |
873 | { | 873 | |
874 | } | 874 | /*====================================================================================== |
875 | 875 | * OWaveLanManagementFH | |
876 | /*====================================================================================== | 876 | *======================================================================================*/ |
877 | * OWaveLanManagementFH | 877 | |
878 | *======================================================================================*/ | 878 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) |
879 | 879 | :QObject( parent, "802.11 FH" ), _data( data ) | |
880 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | 880 | { |
881 | :QObject( parent, "802.11 FH" ), _data( data ) | 881 | odebug << "OWaveLanManagementFH()" << oendl; |
882 | { | 882 | } |
883 | qDebug( "OWaveLanManagementFH()" ); | 883 | |
884 | } | 884 | |
885 | 885 | OWaveLanManagementFH::~OWaveLanManagementFH() | |
886 | 886 | { | |
887 | OWaveLanManagementFH::~OWaveLanManagementFH() | 887 | } |
888 | { | 888 | |
889 | } | 889 | /*====================================================================================== |
890 | 890 | * OWaveLanManagementDS | |
891 | /*====================================================================================== | 891 | *======================================================================================*/ |
892 | * OWaveLanManagementDS | 892 | |
893 | *======================================================================================*/ | 893 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) |
894 | 894 | :QObject( parent, "802.11 DS" ), _data( data ) | |
895 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | 895 | { |
896 | :QObject( parent, "802.11 DS" ), _data( data ) | 896 | odebug << "OWaveLanManagementDS()" << oendl; |
897 | { | 897 | } |
898 | qDebug( "OWaveLanManagementDS()" ); | 898 | |
899 | } | 899 | |
900 | 900 | OWaveLanManagementDS::~OWaveLanManagementDS() | |
901 | 901 | { | |
902 | OWaveLanManagementDS::~OWaveLanManagementDS() | 902 | } |
903 | { | 903 | |
904 | } | 904 | |
905 | 905 | int OWaveLanManagementDS::channel() const | |
906 | 906 | { | |
907 | int OWaveLanManagementDS::channel() const | 907 | return _data->channel; |
908 | { | 908 | } |
909 | return _data->channel; | 909 | |
910 | } | 910 | /*====================================================================================== |
911 | 911 | * OWaveLanManagementTim | |
912 | /*====================================================================================== | 912 | *======================================================================================*/ |
913 | * OWaveLanManagementTim | 913 | |
914 | *======================================================================================*/ | 914 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) |
915 | 915 | :QObject( parent, "802.11 Tim" ), _data( data ) | |
916 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | 916 | { |
917 | :QObject( parent, "802.11 Tim" ), _data( data ) | 917 | odebug << "OWaveLanManagementTim()" << oendl; |
918 | { | 918 | } |
919 | qDebug( "OWaveLanManagementTim()" ); | 919 | |
920 | } | 920 | |
921 | 921 | OWaveLanManagementTim::~OWaveLanManagementTim() | |
922 | 922 | { | |
923 | OWaveLanManagementTim::~OWaveLanManagementTim() | 923 | } |
924 | { | 924 | |
925 | } | 925 | /*====================================================================================== |
926 | 926 | * OWaveLanManagementIBSS | |
927 | /*====================================================================================== | 927 | *======================================================================================*/ |
928 | * OWaveLanManagementIBSS | 928 | |
929 | *======================================================================================*/ | 929 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) |
930 | 930 | :QObject( parent, "802.11 IBSS" ), _data( data ) | |
931 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | 931 | { |
932 | :QObject( parent, "802.11 IBSS" ), _data( data ) | 932 | odebug << "OWaveLanManagementIBSS()" << oendl; |
933 | { | 933 | } |
934 | qDebug( "OWaveLanManagementIBSS()" ); | 934 | |
935 | } | 935 | |
936 | 936 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | |
937 | 937 | { | |
938 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | 938 | } |
939 | { | 939 | |
940 | } | 940 | /*====================================================================================== |
941 | 941 | * OWaveLanManagementChallenge | |
942 | /*====================================================================================== | 942 | *======================================================================================*/ |
943 | * OWaveLanManagementChallenge | 943 | |
944 | *======================================================================================*/ | 944 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) |
945 | 945 | :QObject( parent, "802.11 Challenge" ), _data( data ) | |
946 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | 946 | { |
947 | :QObject( parent, "802.11 Challenge" ), _data( data ) | 947 | odebug << "OWaveLanManagementChallenge()" << oendl; |
948 | { | 948 | } |
949 | qDebug( "OWaveLanManagementChallenge()" ); | 949 | |
950 | } | 950 | |
951 | 951 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | |
952 | 952 | { | |
953 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | 953 | } |
954 | { | 954 | |
955 | } | 955 | /*====================================================================================== |
956 | 956 | * OWaveLanDataPacket | |
957 | /*====================================================================================== | 957 | *======================================================================================*/ |
958 | * OWaveLanDataPacket | 958 | |
959 | *======================================================================================*/ | 959 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
960 | 960 | :QObject( parent, "802.11 Data" ), _header( data ) | |
961 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 961 | { |
962 | :QObject( parent, "802.11 Data" ), _header( data ) | 962 | odebug << "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." << oendl; |
963 | { | 963 | |
964 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); | 964 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
965 | 965 | ||
966 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 966 | #warning The next line works for most cases, but can not be correct generally! |
967 | 967 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | |
968 | #warning The next line works for most cases, but can not be correct generally! | 968 | |
969 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 969 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
970 | 970 | } | |
971 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); | 971 | |
972 | } | 972 | |
973 | 973 | OWaveLanDataPacket::~OWaveLanDataPacket() | |
974 | 974 | { | |
975 | OWaveLanDataPacket::~OWaveLanDataPacket() | 975 | } |
976 | { | 976 | |
977 | } | 977 | |
978 | 978 | /*====================================================================================== | |
979 | 979 | * OLLCPacket | |
980 | /*====================================================================================== | 980 | *======================================================================================*/ |
981 | * OLLCPacket | 981 | |
982 | *======================================================================================*/ | 982 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
983 | 983 | :QObject( parent, "802.11 LLC" ), _header( data ) | |
984 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 984 | { |
985 | :QObject( parent, "802.11 LLC" ), _header( data ) | 985 | odebug << "OLLCPacket::OLLCPacket(): decoding frame..." << oendl; |
986 | { | 986 | |
987 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); | 987 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
988 | 988 | { | |
989 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 989 | owarn << "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type = " << EXTRACT_16BITS( &_header->type ) << ")" << oendl; |
990 | { | 990 | |
991 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 991 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
992 | 992 | { | |
993 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 993 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
994 | { | 994 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
995 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 995 | default: owarn << "OLLCPacket::OLLCPacket(): Unknown Encapsulation type = " << EXTRACT_16BITS( &_header->type ) << oendl; |
996 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 996 | } |
997 | default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 997 | } |
998 | } | 998 | } |
999 | 999 | ||
1000 | } | 1000 | |
1001 | } | 1001 | OLLCPacket::~OLLCPacket() |
1002 | 1002 | { | |
1003 | 1003 | } | |
1004 | OLLCPacket::~OLLCPacket() | 1004 | |
1005 | { | 1005 | |
1006 | } | 1006 | /*====================================================================================== |
1007 | 1007 | * OWaveLanControlPacket | |
1008 | 1008 | *======================================================================================*/ | |
1009 | /*====================================================================================== | 1009 | |
1010 | * OWaveLanControlPacket | 1010 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) |
1011 | *======================================================================================*/ | 1011 | :QObject( parent, "802.11 Control" ), _header( data ) |
1012 | 1012 | { | |
1013 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | 1013 | odebug << "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." << oendl; |
1014 | :QObject( parent, "802.11 Control" ), _header( data ) | 1014 | //TODO: Implement this |
1015 | { | 1015 | } |
1016 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); | 1016 | |
1017 | //TODO: Implement this | 1017 | |
1018 | } | 1018 | OWaveLanControlPacket::~OWaveLanControlPacket() |
1019 | 1019 | { | |
1020 | 1020 | } | |
1021 | OWaveLanControlPacket::~OWaveLanControlPacket() | 1021 | |
1022 | { | 1022 | |
1023 | } | 1023 | /*====================================================================================== |
1024 | 1024 | * OPacketCapturer | |
1025 | 1025 | *======================================================================================*/ | |
1026 | /*====================================================================================== | 1026 | |
1027 | * OPacketCapturer | 1027 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
1028 | *======================================================================================*/ | 1028 | :QObject( parent, name ), _name( QString::null ), _open( false ), |
1029 | 1029 | _pch( 0 ), _pcd( 0 ), _sn( 0 ) | |
1030 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 1030 | { |
1031 | :QObject( parent, name ), _name( QString::null ), _open( false ), | 1031 | } |
1032 | _pch( 0 ), _pcd( 0 ), _sn( 0 ) | 1032 | |
1033 | { | 1033 | |
1034 | } | 1034 | OPacketCapturer::~OPacketCapturer() |
1035 | 1035 | { | |
1036 | 1036 | if ( _open ) | |
1037 | OPacketCapturer::~OPacketCapturer() | 1037 | { |
1038 | { | 1038 | odebug << "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." << oendl; |
1039 | if ( _open ) | 1039 | close(); |
1040 | { | 1040 | } |
1041 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); | 1041 | } |
1042 | close(); | 1042 | |
1043 | } | 1043 | |
1044 | } | 1044 | void OPacketCapturer::setBlocking( bool b ) |
1045 | 1045 | { | |
1046 | 1046 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | |
1047 | void OPacketCapturer::setBlocking( bool b ) | 1047 | { |
1048 | { | 1048 | odebug << "OPacketCapturer::setBlocking(): blocking mode changed successfully." << oendl; |
1049 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | 1049 | } |
1050 | { | 1050 | else |
1051 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); | 1051 | { |
1052 | } | 1052 | odebug << "OPacketCapturer::setBlocking(): can't change blocking mode: " << _errbuf << oendl; |
1053 | else | 1053 | } |
1054 | { | 1054 | } |
1055 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); | 1055 | |
1056 | } | 1056 | |
1057 | } | 1057 | bool OPacketCapturer::blocking() const |
1058 | 1058 | { | |
1059 | 1059 | int b = pcap_getnonblock( _pch, _errbuf ); | |
1060 | bool OPacketCapturer::blocking() const | 1060 | if ( b == -1 ) |
1061 | { | 1061 | { |
1062 | int b = pcap_getnonblock( _pch, _errbuf ); | 1062 | odebug << "OPacketCapturer::blocking(): can't get blocking mode: " << _errbuf << oendl; |
1063 | if ( b == -1 ) | 1063 | return -1; |
1064 | { | 1064 | } |
1065 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); | 1065 | return !b; |
1066 | return -1; | 1066 | } |
1067 | } | 1067 | |
1068 | return !b; | 1068 | |
1069 | } | 1069 | void OPacketCapturer::closeDumpFile() |
1070 | 1070 | { | |
1071 | 1071 | if ( _pcd ) | |
1072 | void OPacketCapturer::closeDumpFile() | 1072 | { |
1073 | { | 1073 | pcap_dump_close( _pcd ); |
1074 | if ( _pcd ) | 1074 | _pcd = 0; |
1075 | { | 1075 | } |
1076 | pcap_dump_close( _pcd ); | 1076 | pcap_close( _pch ); |
1077 | _pcd = 0; | 1077 | } |
1078 | } | 1078 | |
1079 | pcap_close( _pch ); | 1079 | |
1080 | } | 1080 | void OPacketCapturer::close() |
1081 | 1081 | { | |
1082 | 1082 | if ( _open ) | |
1083 | void OPacketCapturer::close() | 1083 | { |
1084 | { | 1084 | if ( _sn ) |
1085 | if ( _open ) | 1085 | { |
1086 | { | 1086 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1087 | if ( _sn ) | 1087 | delete _sn; |
1088 | { | 1088 | } |
1089 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1089 | closeDumpFile(); |
1090 | delete _sn; | 1090 | _open = false; |
1091 | } | 1091 | } |
1092 | closeDumpFile(); | 1092 | |
1093 | _open = false; | 1093 | odebug << "OPacketCapturer::close() --- dumping capturing statistics..." << oendl; |
1094 | } | 1094 | odebug << "--------------------------------------------------" << oendl; |
1095 | 1095 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) | |
1096 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); | 1096 | odebug << it.key() << " = " << it.data() << oendl; |
1097 | qDebug( "--------------------------------------------------" ); | 1097 | odebug << "--------------------------------------------------" << oendl; |
1098 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) | 1098 | |
1099 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); | 1099 | } |
1100 | qDebug( "--------------------------------------------------" ); | 1100 | |
1101 | 1101 | ||
1102 | } | 1102 | int OPacketCapturer::dataLink() const |
1103 | 1103 | { | |
1104 | 1104 | return pcap_datalink( _pch ); | |
1105 | int OPacketCapturer::dataLink() const | 1105 | } |
1106 | { | 1106 | |
1107 | return pcap_datalink( _pch ); | 1107 | |
1108 | } | 1108 | void OPacketCapturer::dump( OPacket* p ) |
1109 | 1109 | { | |
1110 | 1110 | if ( !_pcd ) | |
1111 | void OPacketCapturer::dump( OPacket* p ) | 1111 | { |
1112 | { | 1112 | qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" ); |
1113 | if ( !_pcd ) | 1113 | return; |
1114 | { | 1114 | } |
1115 | qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" ); | 1115 | pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); |
1116 | return; | 1116 | } |
1117 | } | 1117 | |
1118 | pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); | 1118 | |
1119 | } | 1119 | int OPacketCapturer::fileno() const |
1120 | 1120 | { | |
1121 | 1121 | if ( _open ) | |
1122 | int OPacketCapturer::fileno() const | 1122 | { |
1123 | { | 1123 | return pcap_fileno( _pch ); |
1124 | if ( _open ) | 1124 | } |
1125 | { | 1125 | else |
1126 | return pcap_fileno( _pch ); | 1126 | { |
1127 | } | 1127 | return -1; |
1128 | else | 1128 | } |
1129 | { | 1129 | } |
1130 | return -1; | 1130 | |
1131 | } | 1131 | |
1132 | } | 1132 | OPacket* OPacketCapturer::next( int time ) |
1133 | 1133 | { | |
1134 | 1134 | fd_set fds; | |
1135 | OPacket* OPacketCapturer::next( int time ) | 1135 | struct timeval tv; |
1136 | { | 1136 | FD_ZERO( &fds ); |
1137 | fd_set fds; | 1137 | FD_SET( pcap_fileno( _pch ), &fds ); |
1138 | struct timeval tv; | 1138 | tv.tv_sec = time / 1000; |
1139 | FD_ZERO( &fds ); | 1139 | tv.tv_usec = time % 1000; |
1140 | FD_SET( pcap_fileno( _pch ), &fds ); | 1140 | int retval = select( pcap_fileno( _pch )+1, &fds, NULL, NULL, &tv); |
1141 | tv.tv_sec = time / 1000; | 1141 | if ( retval > 0 ) // clear to read! |
1142 | tv.tv_usec = time % 1000; | 1142 | return next(); |
1143 | int retval = select( pcap_fileno( _pch )+1, &fds, NULL, NULL, &tv); | 1143 | else |
1144 | if ( retval > 0 ) // clear to read! | 1144 | return 0; |
1145 | return next(); | 1145 | } |
1146 | else | 1146 | |
1147 | return 0; | 1147 | |
1148 | } | 1148 | OPacket* OPacketCapturer::next() |
1149 | 1149 | { | |
1150 | 1150 | packetheaderstruct header; | |
1151 | OPacket* OPacketCapturer::next() | 1151 | odebug << "==> OPacketCapturer::next()" << oendl; |
1152 | { | 1152 | const unsigned char* pdata = pcap_next( _pch, &header ); |
1153 | packetheaderstruct header; | 1153 | odebug << "<== OPacketCapturer::next()" << oendl; |
1154 | qDebug( "==> OPacketCapturer::next()" ); | 1154 | |
1155 | const unsigned char* pdata = pcap_next( _pch, &header ); | 1155 | if ( pdata && header.len ) |
1156 | qDebug( "<== OPacketCapturer::next()" ); | 1156 | { |
1157 | 1157 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); | |
1158 | if ( pdata && header.len ) | 1158 | // packets shouldn't be inserted in the QObject child-parent hierarchy, |
1159 | { | 1159 | // because due to memory constraints they will be deleted as soon |
1160 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); | 1160 | // as possible - that is right after they have been processed |
1161 | // packets shouldn't be inserted in the QObject child-parent hierarchy, | 1161 | // by emit() [ see below ] |
1162 | // because due to memory constraints they will be deleted as soon | 1162 | //TODO: make gathering statistics optional, because it takes time |
1163 | // as possible - that is right after they have been processed | 1163 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); |
1164 | // by emit() [ see below ] | 1164 | #ifndef NODEBUG |
1165 | //TODO: make gathering statistics optional, because it takes time | 1165 | p->dumpStructure( const_cast<QObjectList*>( p->children() ) ); |
1166 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); | 1166 | #endif |
1167 | #ifndef NODEBUG | 1167 | return p; |
1168 | p->dumpStructure( const_cast<QObjectList*>( p->children() ) ); | 1168 | } |
1169 | #endif | 1169 | else |
1170 | return p; | 1170 | { |
1171 | } | 1171 | qWarning( "OPacketCapturer::next() - no packet received!" ); |
1172 | else | 1172 | return 0; |
1173 | { | 1173 | } |
1174 | qWarning( "OPacketCapturer::next() - no packet received!" ); | 1174 | } |
1175 | return 0; | 1175 | |
1176 | } | 1176 | |
1177 | } | 1177 | bool OPacketCapturer::open( const QString& name ) |
1178 | 1178 | { | |
1179 | 1179 | if ( _open ) | |
1180 | bool OPacketCapturer::open( const QString& name ) | 1180 | { |
1181 | { | 1181 | if ( name == _name ) // ignore opening an already openend device |
1182 | if ( _open ) | 1182 | { |
1183 | { | 1183 | return true; |
1184 | if ( name == _name ) // ignore opening an already openend device | 1184 | } |
1185 | { | 1185 | else // close the last opened device |
1186 | return true; | 1186 | { |
1187 | } | 1187 | close(); |
1188 | else // close the last opened device | 1188 | } |
1189 | { | 1189 | } |
1190 | close(); | 1190 | |
1191 | } | 1191 | _name = name; |
1192 | } | 1192 | |
1193 | 1193 | // open libpcap | |
1194 | _name = name; | 1194 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); |
1195 | 1195 | ||
1196 | // open libpcap | 1196 | if ( !handle ) |
1197 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); | 1197 | { |
1198 | 1198 | owarn << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; | |
1199 | if ( !handle ) | 1199 | return false; |
1200 | { | 1200 | } |
1201 | qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); | 1201 | |
1202 | return false; | 1202 | odebug << "OPacketCapturer::open(): libpcap [" << name << "] opened successfully." << oendl; |
1203 | } | 1203 | _pch = handle; |
1204 | 1204 | _open = true; | |
1205 | qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); | 1205 | _stats.clear(); |
1206 | _pch = handle; | 1206 | |
1207 | _open = true; | 1207 | // in case we have an application object, create a socket notifier |
1208 | _stats.clear(); | 1208 | if ( qApp ) //TODO: I don't like this here... |
1209 | 1209 | { | |
1210 | // in case we have an application object, create a socket notifier | 1210 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
1211 | if ( qApp ) //TODO: I don't like this here... | 1211 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1212 | { | 1212 | } |
1213 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1213 | |
1214 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1214 | return true; |
1215 | } | 1215 | } |
1216 | 1216 | ||
1217 | return true; | 1217 | |
1218 | } | 1218 | bool OPacketCapturer::openDumpFile( const QString& filename ) |
1219 | 1219 | { | |
1220 | 1220 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); | |
1221 | bool OPacketCapturer::openDumpFile( const QString& filename ) | 1221 | if ( !dump ) |
1222 | { | 1222 | { |
1223 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); | 1223 | owarn << "OPacketCapturer::open(): can't open dump with '" << filename << "': " << _errbuf << oendl; |
1224 | if ( !dump ) | 1224 | return false; |
1225 | { | 1225 | } |
1226 | qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); | 1226 | odebug << "OPacketCapturer::open(): dump [" << filename << "] opened successfully." << oendl; |
1227 | return false; | 1227 | _pcd = dump; |
1228 | } | 1228 | |
1229 | qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); | 1229 | return true; |
1230 | _pcd = dump; | 1230 | } |
1231 | 1231 | ||
1232 | return true; | 1232 | |
1233 | } | 1233 | bool OPacketCapturer::open( const QFile& file ) |
1234 | 1234 | { | |
1235 | 1235 | QString name = file.name(); | |
1236 | bool OPacketCapturer::open( const QFile& file ) | 1236 | |
1237 | { | 1237 | if ( _open ) |
1238 | QString name = file.name(); | 1238 | { |
1239 | 1239 | close(); | |
1240 | if ( _open ) | 1240 | if ( name == _name ) // ignore opening an already openend device |
1241 | { | 1241 | { |
1242 | close(); | 1242 | return true; |
1243 | if ( name == _name ) // ignore opening an already openend device | 1243 | } |
1244 | { | 1244 | else // close the last opened device |
1245 | return true; | 1245 | { |
1246 | } | 1246 | close(); |
1247 | else // close the last opened device | 1247 | } |
1248 | { | 1248 | } |
1249 | close(); | 1249 | |
1250 | } | 1250 | _name = name; |
1251 | } | 1251 | |
1252 | 1252 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); | |
1253 | _name = name; | 1253 | |
1254 | 1254 | if ( handle ) | |
1255 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); | 1255 | { |
1256 | 1256 | odebug << "OPacketCapturer::open(): libpcap opened successfully." << oendl; | |
1257 | if ( handle ) | 1257 | _pch = handle; |
1258 | { | 1258 | _open = true; |
1259 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); | 1259 | |
1260 | _pch = handle; | 1260 | // in case we have an application object, create a socket notifier |
1261 | _open = true; | 1261 | if ( qApp ) |
1262 | 1262 | { | |
1263 | // in case we have an application object, create a socket notifier | 1263 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
1264 | if ( qApp ) | 1264 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1265 | { | 1265 | } |
1266 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1266 | |
1267 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1267 | return true; |
1268 | } | 1268 | } |
1269 | 1269 | else | |
1270 | return true; | 1270 | { |
1271 | } | 1271 | odebug << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; |
1272 | else | 1272 | return false; |
1273 | { | 1273 | } |
1274 | qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); | 1274 | |
1275 | return false; | 1275 | } |
1276 | } | 1276 | |
1277 | 1277 | ||
1278 | } | 1278 | bool OPacketCapturer::isOpen() const |
1279 | 1279 | { | |
1280 | 1280 | return _open; | |
1281 | bool OPacketCapturer::isOpen() const | 1281 | } |
1282 | { | 1282 | |
1283 | return _open; | 1283 | |
1284 | } | 1284 | void OPacketCapturer::readyToReceive() |
1285 | 1285 | { | |
1286 | 1286 | odebug << "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" << oendl; | |
1287 | void OPacketCapturer::readyToReceive() | 1287 | OPacket* p = next(); |
1288 | { | 1288 | emit receivedPacket( p ); |
1289 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); | 1289 | // emit is synchronous - packet has been dealt with, now it's safe to delete |
1290 | OPacket* p = next(); | 1290 | delete p; |
1291 | emit receivedPacket( p ); | 1291 | } |
1292 | // emit is synchronous - packet has been dealt with, now it's safe to delete | 1292 | |
1293 | delete p; | 1293 | |
1294 | } | 1294 | const QMap<QString,int>& OPacketCapturer::statistics() const |
1295 | 1295 | { | |
1296 | 1296 | return _stats; | |
1297 | const QMap<QString,int>& OPacketCapturer::statistics() const | 1297 | } |
1298 | { | 1298 | |
1299 | return _stats; | 1299 | |
1300 | } | 1300 | int OPacketCapturer::snapShot() const |
1301 | 1301 | { | |
1302 | 1302 | return pcap_snapshot( _pch ); | |
1303 | int OPacketCapturer::snapShot() const | 1303 | } |
1304 | { | 1304 | |
1305 | return pcap_snapshot( _pch ); | 1305 | |
1306 | } | 1306 | bool OPacketCapturer::swapped() const |
1307 | 1307 | { | |
1308 | 1308 | return pcap_is_swapped( _pch ); | |
1309 | bool OPacketCapturer::swapped() const | 1309 | } |
1310 | { | 1310 | |
1311 | return pcap_is_swapped( _pch ); | 1311 | |
1312 | } | 1312 | QString OPacketCapturer::version() const |
1313 | 1313 | { | |
1314 | 1314 | return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); | |
1315 | QString OPacketCapturer::version() const | 1315 | } |
1316 | { | 1316 | |
1317 | return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); | 1317 | |
1318 | } | ||
1319 | |||
1320 | |||
diff --git a/libopie2/opienet/ostation.cpp b/libopie2/opienet/ostation.cpp index c363f0c..8c989d8 100644 --- a/libopie2/opienet/ostation.cpp +++ b/libopie2/opienet/ostation.cpp | |||
@@ -26,38 +26,39 @@ | |||
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <opie2/ostation.h> | 31 | #include <opie2/ostation.h> |
32 | #include <opie2/odebug.h> | ||
32 | 33 | ||
33 | /*====================================================================================== | 34 | /*====================================================================================== |
34 | * OStation | 35 | * OStation |
35 | *======================================================================================*/ | 36 | *======================================================================================*/ |
36 | 37 | ||
37 | OStation::OStation() | 38 | OStation::OStation() |
38 | { | 39 | { |
39 | qDebug( "OStation::OStation()" ); | 40 | odebug << "OStation::OStation()" << oendl; |
40 | 41 | ||
41 | type = "<unknown>"; | 42 | type = "<unknown>"; |
42 | macAddress = OMacAddress::unknown; | 43 | macAddress = OMacAddress::unknown; |
43 | ssid = "<unknown>"; | 44 | ssid = "<unknown>"; |
44 | channel = 0; | 45 | channel = 0; |
45 | apAddress = OMacAddress::unknown; | 46 | apAddress = OMacAddress::unknown; |
46 | 47 | ||
47 | } | 48 | } |
48 | 49 | ||
49 | 50 | ||
50 | OStation::~OStation() | 51 | OStation::~OStation() |
51 | { | 52 | { |
52 | qDebug( "OStation::~OStation()" ); | 53 | odebug << "OStation::~OStation()" << oendl; |
53 | } | 54 | } |
54 | 55 | ||
55 | 56 | ||
56 | void OStation::dump() | 57 | void OStation::dump() |
57 | { | 58 | { |
58 | qDebug( "------- OStation::dump() ------------" ); | 59 | odebug << "------- OStation::dump() ------------" << oendl; |
59 | qDebug( "type: %s", (const char*) type ); | 60 | qDebug( "type: %s", (const char*) type ); |
60 | qDebug( "mac: %s", (const char*) macAddress.toString() ); | 61 | qDebug( "mac: %s", (const char*) macAddress.toString() ); |
61 | qDebug( "ap: %s", (const char*) apAddress.toString() ); | 62 | qDebug( "ap: %s", (const char*) apAddress.toString() ); |
62 | qDebug( "ip: %s", (const char*) ipAddress.toString() ); | 63 | qDebug( "ip: %s", (const char*) ipAddress.toString() ); |
63 | } | 64 | } |