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