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