summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp12
-rw-r--r--libopie2/opienet/onetwork.cpp113
-rw-r--r--libopie2/opienet/onetwork.h29
3 files changed, 131 insertions, 23 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
index 607d8f1..fc2026f 100644
--- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -1,87 +1,99 @@
1#include <opie2/onetwork.h> 1#include <opie2/onetwork.h>
2#include <opie2/omanufacturerdb.h> 2#include <opie2/omanufacturerdb.h>
3 3
4int main( int argc, char** argv ) 4int main( int argc, char** argv )
5{ 5{
6 qDebug( "OPIE Network Demo" ); 6 qDebug( "OPIE Network Demo" );
7 7
8 ONetwork* net = ONetwork::instance(); 8 ONetwork* net = ONetwork::instance();
9 9
10 ONetwork::InterfaceIterator it = net->iterator(); 10 ONetwork::InterfaceIterator it = net->iterator();
11 11
12 while ( it.current() ) 12 while ( it.current() )
13 { 13 {
14 qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() ); 14 qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() );
15 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() ); 15 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() );
16 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) ); 16 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) );
17 qDebug( "DEMO: MAC Manufacturer seems to be '%s'", (const char*) it.current()->macAddress().manufacturer() ); 17 qDebug( "DEMO: MAC Manufacturer seems to be '%s'", (const char*) it.current()->macAddress().manufacturer() );
18 qDebug( "DEMO: Manufacturertest1 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "08:00:87" ) ); 18 qDebug( "DEMO: Manufacturertest1 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "08:00:87" ) );
19 qDebug( "DEMO: Manufacturertest2 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) ); 19 qDebug( "DEMO: Manufacturertest2 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) );
20 qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() ); 20 qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() );
21 if ( it.current()->isWireless() ) 21 if ( it.current()->isWireless() )
22 { 22 {
23 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() ); 23 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
24 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() ); 24 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() );
25 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() ); 25 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() );
26 qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() ); 26 qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() );
27 27
28 //if ( iface->mode() == OWirelessNetworkInterface::adhoc ) 28 //if ( iface->mode() == OWirelessNetworkInterface::adhoc )
29 //{ 29 //{
30 qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() ); 30 qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() );
31 //} 31 //}
32 32
33 // nickname 33 // nickname
34 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() ); 34 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
35 iface->setNickName( "MyNickName" ); 35 iface->setNickName( "MyNickName" );
36 if ( iface->nickName() != "MyNickName" ) 36 if ( iface->nickName() != "MyNickName" )
37 qDebug( "DEMO: Warning! Can't change nickname" ); 37 qDebug( "DEMO: Warning! Can't change nickname" );
38 else 38 else
39 qDebug( "DEMO: Nickname change successful." ); 39 qDebug( "DEMO: Nickname change successful." );
40 40
41 // operation mode 41 // operation mode
42 qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() ); 42 qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() );
43 iface->setMode( "adhoc" ); 43 iface->setMode( "adhoc" );
44 if ( iface->mode() != "adhoc" ) 44 if ( iface->mode() != "adhoc" )
45 qDebug( "DEMO: Warning! Can't change operation mode" ); 45 qDebug( "DEMO: Warning! Can't change operation mode" );
46 else 46 else
47 qDebug( "DEMO: Operation Mode change successful." ); 47 qDebug( "DEMO: Operation Mode change successful." );
48 48
49 // RF channel 49 // RF channel
50 qDebug( "DEMO: Current Channel is '%d'", iface->channel() ); 50 qDebug( "DEMO: Current Channel is '%d'", iface->channel() );
51 iface->setChannel( 1 ); 51 iface->setChannel( 1 );
52 if ( iface->channel() != 1 ) 52 if ( iface->channel() != 1 )
53 qDebug( "DEMO: Warning! Can't change RF channel" ); 53 qDebug( "DEMO: Warning! Can't change RF channel" );
54 else 54 else
55 qDebug( "DEMO: RF channel change successful." ); 55 qDebug( "DEMO: RF channel change successful." );
56 56
57 iface->setMode( "managed" ); 57 iface->setMode( "managed" );
58 58
59 // network scan
60
61 int stations = iface->scanNetwork();
62 if ( stations != -1 )
63 {
64 qDebug( "DEMO: # of stations around = %d", stations );
65 }
66 else
67 {
68 qDebug( "DEMO: Warning! Scan didn't work!" );
69 }
70
59 /* 71 /*
60 72
61 // first some wrong calls to check if this is working 73 // first some wrong calls to check if this is working
62 iface->setPrivate( "seppel", 10 ); 74 iface->setPrivate( "seppel", 10 );
63 iface->setPrivate( "monitor", 0 ); 75 iface->setPrivate( "monitor", 0 );
64 76
65 // now the real deal 77 // now the real deal
66 iface->setPrivate( "monitor", 2, 2, 3 ); 78 iface->setPrivate( "monitor", 2, 2, 3 );
67 79
68 // trying to set hw address to 12:34:56:AB:CD:EF 80 // trying to set hw address to 12:34:56:AB:CD:EF
69 81
70 /* 82 /*
71 83
72 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" ); 84 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" );
73 iface->setUp( false ); 85 iface->setUp( false );
74 iface->setMacAddress( addr ); 86 iface->setMacAddress( addr );
75 iface->setUp( true ); 87 iface->setUp( true );
76 qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() ); 88 qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() );
77 89
78 */ 90 */
79 91
80 92
81 } 93 }
82 ++it; 94 ++it;
83 } 95 }
84 96
85 return 0; 97 return 0;
86 98
87} 99}
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index dc2e388..be45924 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,1048 +1,1129 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/onetwork.h> 36#include <opie2/onetwork.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qfile.h> 40#include <qfile.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42 42
43/* UNIX */ 43/* UNIX */
44 44
45#include <assert.h> 45#include <assert.h>
46#include <arpa/inet.h> 46#include <arpa/inet.h>
47#include <cerrno> 47#include <cerrno>
48#include <cstring> 48#include <cstring>
49#include <cstdlib> 49#include <cstdlib>
50#include <math.h> 50#include <math.h>
51#include <sys/ioctl.h> 51#include <sys/ioctl.h>
52#include <sys/socket.h> 52#include <sys/socket.h>
53#include <sys/types.h> 53#include <sys/types.h>
54#include <unistd.h> 54#include <unistd.h>
55#include <linux/sockios.h> 55#include <linux/sockios.h>
56#include <net/if_arp.h> 56#include <net/if_arp.h>
57#include <stdarg.h> 57#include <stdarg.h>
58 58
59using namespace std; 59using namespace std;
60 60
61/*====================================================================================== 61/*======================================================================================
62 * ONetwork 62 * ONetwork
63 *======================================================================================*/ 63 *======================================================================================*/
64 64
65ONetwork* ONetwork::_instance = 0; 65ONetwork* ONetwork::_instance = 0;
66 66
67ONetwork::ONetwork() 67ONetwork::ONetwork()
68{ 68{
69 qDebug( "ONetwork::ONetwork()" ); 69 qDebug( "ONetwork::ONetwork()" );
70 qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT ); 70 qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT );
71 synchronize(); 71 synchronize();
72} 72}
73 73
74void ONetwork::synchronize() 74void ONetwork::synchronize()
75{ 75{
76 // gather available interfaces by inspecting /proc/net/dev 76 // gather available interfaces by inspecting /proc/net/dev
77 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 77 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
78 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 78 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
79 //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev
79 80
80 _interfaces.clear(); 81 _interfaces.clear();
81 QString str; 82 QString str;
82 QFile f( "/proc/net/dev" ); 83 QFile f( "/proc/net/dev" );
83 bool hasFile = f.open( IO_ReadOnly ); 84 bool hasFile = f.open( IO_ReadOnly );
84 if ( !hasFile ) 85 if ( !hasFile )
85 { 86 {
86 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); 87 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
87 return; 88 return;
88 } 89 }
89 QTextStream s( &f ); 90 QTextStream s( &f );
90 s.readLine(); 91 s.readLine();
91 s.readLine(); 92 s.readLine();
92 while ( !s.atEnd() ) 93 while ( !s.atEnd() )
93 { 94 {
94 s >> str; 95 s >> str;
95 str.truncate( str.find( ':' ) ); 96 str.truncate( str.find( ':' ) );
96 qDebug( "ONetwork: found interface '%s'", (const char*) str ); 97 qDebug( "ONetwork: found interface '%s'", (const char*) str );
97 ONetworkInterface* iface; 98 ONetworkInterface* iface;
98 if ( isWirelessInterface( str ) ) 99 if ( isWirelessInterface( str ) )
99 { 100 {
100 iface = new OWirelessNetworkInterface( this, (const char*) str ); 101 iface = new OWirelessNetworkInterface( this, (const char*) str );
101 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); 102 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str );
102 } 103 }
103 else 104 else
104 { 105 {
105 iface = new ONetworkInterface( this, (const char*) str ); 106 iface = new ONetworkInterface( this, (const char*) str );
106 } 107 }
107 _interfaces.insert( str, iface ); 108 _interfaces.insert( str, iface );
108 s.readLine(); 109 s.readLine();
109 } 110 }
110} 111}
111 112
112 113
113short ONetwork::wirelessExtensionVersion() 114short ONetwork::wirelessExtensionVersion()
114{ 115{
115 return WIRELESS_EXT; 116 return WIRELESS_EXT;
116} 117}
117 118
118 119
119int ONetwork::count() const 120int ONetwork::count() const
120{ 121{
121 return _interfaces.count(); 122 return _interfaces.count();
122} 123}
123 124
124 125
125ONetworkInterface* ONetwork::interface( const QString& iface ) const 126ONetworkInterface* ONetwork::interface( const QString& iface ) const
126{ 127{
127 return _interfaces[iface]; 128 return _interfaces[iface];
128} 129}
129 130
130 131
131ONetwork* ONetwork::instance() 132ONetwork* ONetwork::instance()
132{ 133{
133 if ( !_instance ) _instance = new ONetwork(); 134 if ( !_instance ) _instance = new ONetwork();
134 return _instance; 135 return _instance;
135} 136}
136 137
137 138
138ONetwork::InterfaceIterator ONetwork::iterator() const 139ONetwork::InterfaceIterator ONetwork::iterator() const
139{ 140{
140 return ONetwork::InterfaceIterator( _interfaces ); 141 return ONetwork::InterfaceIterator( _interfaces );
141} 142}
142 143
143 144
144bool ONetwork::isWirelessInterface( const char* name ) const 145bool ONetwork::isWirelessInterface( const char* name ) const
145{ 146{
146 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 147 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
147 struct iwreq iwr; 148 struct iwreq iwr;
148 memset( &iwr, 0, sizeof( struct iwreq ) ); 149 memset( &iwr, 0, sizeof( struct iwreq ) );
149 strcpy( (char*) &iwr.ifr_name, name ); 150 strcpy( (char*) &iwr.ifr_name, name );
150 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 151 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
151 return result != -1; 152 return result != -1;
152} 153}
153 154
154/*====================================================================================== 155/*======================================================================================
155 * ONetworkInterface 156 * ONetworkInterface
156 *======================================================================================*/ 157 *======================================================================================*/
157 158
158ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) 159ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
159 :QObject( parent, name ), 160 :QObject( parent, name ),
160 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 161 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
161{ 162{
162 qDebug( "ONetworkInterface::ONetworkInterface()" ); 163 qDebug( "ONetworkInterface::ONetworkInterface()" );
163 init(); 164 init();
164} 165}
165 166
166 167
167struct ifreq& ONetworkInterface::ifr() const 168struct ifreq& ONetworkInterface::ifr() const
168{ 169{
169 return _ifr; 170 return _ifr;
170} 171}
171 172
172 173
173void ONetworkInterface::init() 174void ONetworkInterface::init()
174{ 175{
175 qDebug( "ONetworkInterface::init()" ); 176 qDebug( "ONetworkInterface::init()" );
176 177
177 memset( &_ifr, 0, sizeof( struct ifreq ) ); 178 memset( &_ifr, 0, sizeof( struct ifreq ) );
178 179
179 if ( _sfd == -1 ) 180 if ( _sfd == -1 )
180 { 181 {
181 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); 182 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() );
182 return; 183 return;
183 } 184 }
184} 185}
185 186
186 187
187bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const 188bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
188{ 189{
189 int result = ::ioctl( _sfd, call, &ifreq ); 190 int result = ::ioctl( _sfd, call, &ifreq );
190 if ( result == -1 ) 191 if ( result == -1 )
191 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 192 qDebug( "ONetworkInterface::ioctl (%s) call %d (0x%04X) - Status: Failed: %d (%s)", name(), call, call, result, strerror( errno ) );
192 else 193 else
193 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); 194 qDebug( "ONetworkInterface::ioctl (%s) call %d (0x%04X) - Status: Ok.", name(), call, call );
194 return ( result != -1 ); 195 return ( result != -1 );
195} 196}
196 197
197 198
198bool ONetworkInterface::ioctl( int call ) const 199bool ONetworkInterface::ioctl( int call ) const
199{ 200{
200 strcpy( _ifr.ifr_name, name() ); 201 strcpy( _ifr.ifr_name, name() );
201 return ioctl( call, _ifr ); 202 return ioctl( call, _ifr );
202} 203}
203 204
204 205
205bool ONetworkInterface::isLoopback() const 206bool ONetworkInterface::isLoopback() const
206{ 207{
207 ioctl( SIOCGIFFLAGS ); 208 ioctl( SIOCGIFFLAGS );
208 return _ifr.ifr_flags & IFF_LOOPBACK; 209 return _ifr.ifr_flags & IFF_LOOPBACK;
209} 210}
210 211
211 212
212bool ONetworkInterface::setUp( bool b ) 213bool ONetworkInterface::setUp( bool b )
213{ 214{
214 ioctl( SIOCGIFFLAGS ); 215 ioctl( SIOCGIFFLAGS );
215 if ( b ) _ifr.ifr_flags |= IFF_UP; 216 if ( b ) _ifr.ifr_flags |= IFF_UP;
216 else _ifr.ifr_flags &= (~IFF_UP); 217 else _ifr.ifr_flags &= (~IFF_UP);
217 return ioctl( SIOCSIFFLAGS ); 218 return ioctl( SIOCSIFFLAGS );
218} 219}
219 220
220 221
221bool ONetworkInterface::isUp() const 222bool ONetworkInterface::isUp() const
222{ 223{
223 ioctl( SIOCGIFFLAGS ); 224 ioctl( SIOCGIFFLAGS );
224 return _ifr.ifr_flags & IFF_UP; 225 return _ifr.ifr_flags & IFF_UP;
225} 226}
226 227
227 228
228void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) 229void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
229{ 230{
230 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 231 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
231 sa->sin_family = AF_INET; 232 sa->sin_family = AF_INET;
232 sa->sin_port = 0; 233 sa->sin_port = 0;
233 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 234 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
234 ioctl( SIOCSIFADDR ); 235 ioctl( SIOCSIFADDR );
235} 236}
236 237
237 238
238QString ONetworkInterface::ipV4Address() const 239QString ONetworkInterface::ipV4Address() const
239{ 240{
240 if ( ioctl( SIOCGIFADDR ) ) 241 if ( ioctl( SIOCGIFADDR ) )
241 { 242 {
242 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; 243 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
243 //FIXME: Use QHostAddress here 244 //FIXME: Use QHostAddress here
244 return QString( inet_ntoa( sa->sin_addr ) ); 245 return QString( inet_ntoa( sa->sin_addr ) );
245 } 246 }
246 else 247 else
247 return "<unknown>"; 248 return "<unknown>";
248} 249}
249 250
250 251
251void ONetworkInterface::setMacAddress( const OMacAddress& addr ) 252void ONetworkInterface::setMacAddress( const OMacAddress& addr )
252{ 253{
253 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 254 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
254 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); 255 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
255 ioctl( SIOCSIFHWADDR ); 256 ioctl( SIOCSIFHWADDR );
256} 257}
257 258
258 259
259OMacAddress ONetworkInterface::macAddress() const 260OMacAddress ONetworkInterface::macAddress() const
260{ 261{
261 if ( ioctl( SIOCGIFHWADDR ) ) 262 if ( ioctl( SIOCGIFHWADDR ) )
262 { 263 {
263 return OMacAddress( _ifr ); 264 return OMacAddress( _ifr );
264 } 265 }
265 else 266 else
266 { 267 {
267 return OMacAddress::unknown; 268 return OMacAddress::unknown;
268 } 269 }
269} 270}
270 271
271 272
272void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) 273void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr )
273{ 274{
274 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 275 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
275 sa->sin_family = AF_INET; 276 sa->sin_family = AF_INET;
276 sa->sin_port = 0; 277 sa->sin_port = 0;
277 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 278 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
278 ioctl( SIOCSIFNETMASK ); 279 ioctl( SIOCSIFNETMASK );
279} 280}
280 281
281 282
282QString ONetworkInterface::ipV4Netmask() const 283QString ONetworkInterface::ipV4Netmask() const
283{ 284{
284 if ( ioctl( SIOCGIFNETMASK ) ) 285 if ( ioctl( SIOCGIFNETMASK ) )
285 { 286 {
286 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; 287 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
287 //FIXME: Use QHostAddress here 288 //FIXME: Use QHostAddress here
288 return QString( inet_ntoa( sa->sin_addr ) ); 289 return QString( inet_ntoa( sa->sin_addr ) );
289 } 290 }
290 else 291 else
291 return "<unknown>"; 292 return "<unknown>";
292} 293}
293 294
294 295
295int ONetworkInterface::dataLinkType() const 296int ONetworkInterface::dataLinkType() const
296{ 297{
297 if ( ioctl( SIOCGIFHWADDR ) ) 298 if ( ioctl( SIOCGIFHWADDR ) )
298 { 299 {
299 return _ifr.ifr_hwaddr.sa_family; 300 return _ifr.ifr_hwaddr.sa_family;
300 } 301 }
301 else 302 else
302 { 303 {
303 return -1; 304 return -1;
304 } 305 }
305} 306}
306 307
307 308
308void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 309void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
309{ 310{
310 _mon = m; 311 _mon = m;
311 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); 312 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() );
312} 313}
313 314
314 315
315OMonitoringInterface* ONetworkInterface::monitoring() const 316OMonitoringInterface* ONetworkInterface::monitoring() const
316{ 317{
317 return _mon; 318 return _mon;
318} 319}
319 320
320 321
321ONetworkInterface::~ONetworkInterface() 322ONetworkInterface::~ONetworkInterface()
322{ 323{
323 qDebug( "ONetworkInterface::~ONetworkInterface()" ); 324 qDebug( "ONetworkInterface::~ONetworkInterface()" );
324 if ( _sfd != -1 ) ::close( _sfd ); 325 if ( _sfd != -1 ) ::close( _sfd );
325} 326}
326 327
327 328
328bool ONetworkInterface::setPromiscuousMode( bool b ) 329bool ONetworkInterface::setPromiscuousMode( bool b )
329{ 330{
330 ioctl( SIOCGIFFLAGS ); 331 ioctl( SIOCGIFFLAGS );
331 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 332 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
332 else _ifr.ifr_flags &= (~IFF_PROMISC); 333 else _ifr.ifr_flags &= (~IFF_PROMISC);
333 return ioctl( SIOCSIFFLAGS ); 334 return ioctl( SIOCSIFFLAGS );
334} 335}
335 336
336 337
337bool ONetworkInterface::promiscuousMode() const 338bool ONetworkInterface::promiscuousMode() const
338{ 339{
339 ioctl( SIOCGIFFLAGS ); 340 ioctl( SIOCGIFFLAGS );
340 return _ifr.ifr_flags & IFF_PROMISC; 341 return _ifr.ifr_flags & IFF_PROMISC;
341} 342}
342 343
343 344
344bool ONetworkInterface::isWireless() const 345bool ONetworkInterface::isWireless() const
345{ 346{
346 return ioctl( SIOCGIWNAME ); 347 return ioctl( SIOCGIWNAME );
347} 348}
348 349
349 350
350/*====================================================================================== 351/*======================================================================================
351 * OChannelHopper 352 * OChannelHopper
352 *======================================================================================*/ 353 *======================================================================================*/
353 354
354OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 355OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
355 :QObject( 0, "Mickey's funky hopper" ), 356 :QObject( 0, "Mickey's funky hopper" ),
356 _iface( iface ), _interval( 0 ), _tid( 0 ) 357 _iface( iface ), _interval( 0 ), _tid( 0 )
357{ 358{
358 int _maxChannel = iface->channels()+1; 359 int _maxChannel = iface->channels()+1;
359 // generate fancy hopping sequence honoring the device capabilities 360 // generate fancy hopping sequence honoring the device capabilities
360 if ( _maxChannel >= 1 ) _channels.append( 1 ); 361 if ( _maxChannel >= 1 ) _channels.append( 1 );
361 if ( _maxChannel >= 7 ) _channels.append( 7 ); 362 if ( _maxChannel >= 7 ) _channels.append( 7 );
362 if ( _maxChannel >= 13 ) _channels.append( 13 ); 363 if ( _maxChannel >= 13 ) _channels.append( 13 );
363 if ( _maxChannel >= 2 ) _channels.append( 2 ); 364 if ( _maxChannel >= 2 ) _channels.append( 2 );
364 if ( _maxChannel >= 8 ) _channels.append( 8 ); 365 if ( _maxChannel >= 8 ) _channels.append( 8 );
365 if ( _maxChannel >= 3 ) _channels.append( 3 ); 366 if ( _maxChannel >= 3 ) _channels.append( 3 );
366 if ( _maxChannel >= 14 ) _channels.append( 14 ); 367 if ( _maxChannel >= 14 ) _channels.append( 14 );
367 if ( _maxChannel >= 9 ) _channels.append( 9 ); 368 if ( _maxChannel >= 9 ) _channels.append( 9 );
368 if ( _maxChannel >= 4 ) _channels.append( 4 ); 369 if ( _maxChannel >= 4 ) _channels.append( 4 );
369 if ( _maxChannel >= 10 ) _channels.append( 10 ); 370 if ( _maxChannel >= 10 ) _channels.append( 10 );
370 if ( _maxChannel >= 5 ) _channels.append( 5 ); 371 if ( _maxChannel >= 5 ) _channels.append( 5 );
371 if ( _maxChannel >= 11 ) _channels.append( 11 ); 372 if ( _maxChannel >= 11 ) _channels.append( 11 );
372 if ( _maxChannel >= 6 ) _channels.append( 6 ); 373 if ( _maxChannel >= 6 ) _channels.append( 6 );
373 if ( _maxChannel >= 12 ) _channels.append( 12 ); 374 if ( _maxChannel >= 12 ) _channels.append( 12 );
374 _channel = _channels.begin(); 375 _channel = _channels.begin();
375 376
376} 377}
377 378
378 379
379OChannelHopper::~OChannelHopper() 380OChannelHopper::~OChannelHopper()
380{ 381{
381} 382}
382 383
383 384
384bool OChannelHopper::isActive() const 385bool OChannelHopper::isActive() const
385{ 386{
386 return _tid; 387 return _tid;
387} 388}
388 389
389 390
390int OChannelHopper::channel() const 391int OChannelHopper::channel() const
391{ 392{
392 return *_channel; 393 return *_channel;
393} 394}
394 395
395 396
396void OChannelHopper::timerEvent( QTimerEvent* ) 397void OChannelHopper::timerEvent( QTimerEvent* )
397{ 398{
398 _iface->setChannel( *_channel ); 399 _iface->setChannel( *_channel );
399 emit( hopped( *_channel ) ); 400 emit( hopped( *_channel ) );
400 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", 401 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
401 *_channel, (const char*) _iface->name() ); 402 *_channel, (const char*) _iface->name() );
402 if ( ++_channel == _channels.end() ) _channel = _channels.begin(); 403 if ( ++_channel == _channels.end() ) _channel = _channels.begin();
403} 404}
404 405
405 406
406void OChannelHopper::setInterval( int interval ) 407void OChannelHopper::setInterval( int interval )
407{ 408{
408 if ( interval == _interval ) 409 if ( interval == _interval )
409 return; 410 return;
410 411
411 if ( _interval ) 412 if ( _interval )
412 killTimer( _tid ); 413 killTimer( _tid );
413 414
414 _tid = 0; 415 _tid = 0;
415 _interval = interval; 416 _interval = interval;
416 417
417 if ( _interval ) 418 if ( _interval )
418 { 419 {
419 _tid = startTimer( interval ); 420 _tid = startTimer( interval );
420 } 421 }
421} 422}
422 423
423 424
424int OChannelHopper::interval() const 425int OChannelHopper::interval() const
425{ 426{
426 return _interval; 427 return _interval;
427} 428}
428 429
429 430
430/*====================================================================================== 431/*======================================================================================
431 * OWirelessNetworkInterface 432 * OWirelessNetworkInterface
432 *======================================================================================*/ 433 *======================================================================================*/
433 434
434OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) 435OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name )
435 :ONetworkInterface( parent, name ), _hopper( 0 ) 436 :ONetworkInterface( parent, name ), _hopper( 0 )
436{ 437{
437 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 438 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
438 init(); 439 init();
439} 440}
440 441
441 442
442OWirelessNetworkInterface::~OWirelessNetworkInterface() 443OWirelessNetworkInterface::~OWirelessNetworkInterface()
443{ 444{
444} 445}
445 446
446 447
447struct iwreq& OWirelessNetworkInterface::iwr() const 448struct iwreq& OWirelessNetworkInterface::iwr() const
448{ 449{
449 return _iwr; 450 return _iwr;
450} 451}
451 452
452 453
453void OWirelessNetworkInterface::init() 454void OWirelessNetworkInterface::init()
454{ 455{
455 qDebug( "OWirelessNetworkInterface::init()" ); 456 qDebug( "OWirelessNetworkInterface::init()" );
456 memset( &_iwr, 0, sizeof( struct iwreq ) ); 457 memset( &_iwr, 0, sizeof( struct iwreq ) );
457 buildChannelList(); 458 buildInformation();
458 buildPrivateList(); 459 buildPrivateList();
460 dumpInformation();
461}
462
463
464bool OWirelessNetworkInterface::isAssociated() const
465{
466 //FIXME: handle different modes
467 return associatedAP() != "44:44:44:44:44:44";
459} 468}
460 469
461 470
462QString OWirelessNetworkInterface::associatedAP() const 471QString OWirelessNetworkInterface::associatedAP() const
463{ 472{
464 //FIXME: use OMacAddress 473 //FIXME: use OMacAddress
465 QString mac; 474 QString mac;
466 475
467 if ( ioctl( SIOCGIWAP ) ) 476 if ( ioctl( SIOCGIWAP ) )
468 { 477 {
469 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 478 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
470 _ifr.ifr_hwaddr.sa_data[0]&0xff, 479 _ifr.ifr_hwaddr.sa_data[0]&0xff,
471 _ifr.ifr_hwaddr.sa_data[1]&0xff, 480 _ifr.ifr_hwaddr.sa_data[1]&0xff,
472 _ifr.ifr_hwaddr.sa_data[2]&0xff, 481 _ifr.ifr_hwaddr.sa_data[2]&0xff,
473 _ifr.ifr_hwaddr.sa_data[3]&0xff, 482 _ifr.ifr_hwaddr.sa_data[3]&0xff,
474 _ifr.ifr_hwaddr.sa_data[4]&0xff, 483 _ifr.ifr_hwaddr.sa_data[4]&0xff,
475 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 484 _ifr.ifr_hwaddr.sa_data[5]&0xff );
476 } 485 }
477 else 486 else
478 { 487 {
479 mac = "<Unknown>"; 488 mac = "<Unknown>";
480 } 489 }
481 return mac; 490 return mac;
482} 491}
483 492
484 493
485void OWirelessNetworkInterface::buildChannelList() 494void OWirelessNetworkInterface::buildInformation()
486{ 495{
487 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 496 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
488 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 497 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
489 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 498 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
490 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 499 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
491 //ML: _too much_ space. This is damn shitty crap *sigh* 500 //ML: _too much_ space. This is damn shitty crap *sigh*
492 //ML: We allocate a large memory region in RAM and check whether the 501 //ML: We allocate a large memory region in RAM and check whether the
493 //ML: driver pollutes this extra space. The complaint will be made on stdout, 502 //ML: driver pollutes this extra space. The complaint will be made on stdout,
494 //ML: so please forward this... 503 //ML: so please forward this...
495 504
496 struct iwreq wrq; 505 struct iwreq wrq;
497 int len = sizeof( struct iw_range )*2; 506 int len = sizeof( struct iw_range )*2;
498 char *buffer = (char*) malloc( len ); 507 char *buffer = (char*) malloc( len );
499 //FIXME: Validate if we actually got the memory block 508 //FIXME: Validate if we actually got the memory block
500 memset( buffer, 0, len ); 509 memset( buffer, 0, len );
501 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 510 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
502 wrq.u.data.pointer = (caddr_t) buffer; 511 wrq.u.data.pointer = (caddr_t) buffer;
503 wrq.u.data.length = sizeof( struct iw_range ); 512 wrq.u.data.length = sizeof( struct iw_range );
504 wrq.u.data.flags = 0; 513 wrq.u.data.flags = 0;
505 514
506 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 515 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
507 { 516 {
508 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); 517 qDebug( "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (%s) - using default values.", strerror( errno ) );
509 _channels.insert( 2412, 1 ); // 2.412 GHz 518 _channels.insert( 2412, 1 ); // 2.412 GHz
510 _channels.insert( 2417, 2 ); // 2.417 GHz 519 _channels.insert( 2417, 2 ); // 2.417 GHz
511 _channels.insert( 2422, 3 ); // 2.422 GHz 520 _channels.insert( 2422, 3 ); // 2.422 GHz
512 _channels.insert( 2427, 4 ); // 2.427 GHz 521 _channels.insert( 2427, 4 ); // 2.427 GHz
513 _channels.insert( 2432, 5 ); // 2.432 GHz 522 _channels.insert( 2432, 5 ); // 2.432 GHz
514 _channels.insert( 2437, 6 ); // 2.437 GHz 523 _channels.insert( 2437, 6 ); // 2.437 GHz
515 _channels.insert( 2442, 7 ); // 2.442 GHz 524 _channels.insert( 2442, 7 ); // 2.442 GHz
516 _channels.insert( 2447, 8 ); // 2.447 GHz 525 _channels.insert( 2447, 8 ); // 2.447 GHz
517 _channels.insert( 2452, 9 ); // 2.452 GHz 526 _channels.insert( 2452, 9 ); // 2.452 GHz
518 _channels.insert( 2457, 10 ); // 2.457 GHz 527 _channels.insert( 2457, 10 ); // 2.457 GHz
519 _channels.insert( 2462, 11 ); // 2.462 GHz 528 _channels.insert( 2462, 11 ); // 2.462 GHz
529
530 memset( &_range, 0, sizeof( struct iw_range ) );
520 } 531 }
521 else 532 else
522 { 533 {
523 // <check if the driver overwrites stuff> 534 // <check if the driver overwrites stuff>
524 int max = 0; 535 int max = 0;
525 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 536 for ( int r = sizeof( struct iw_range ); r < len; r++ )
526 if (buffer[r] != 0) 537 if (buffer[r] != 0)
527 max = r; 538 max = r;
528 if (max > 0) 539 if (max > 0)
529 { 540 {
530 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" 541 qWarning( "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '%s' sucks!\n"
531 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); 542 "It overwrote the buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
532 } 543 }
533 // </check if the driver overwrites stuff> 544 // </check if the driver overwrites stuff>
534 545
535 struct iw_range range; 546 struct iw_range range;
536 memcpy( &range, buffer, sizeof range ); 547 memcpy( &range, buffer, sizeof range );
537 548
538 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); 549 qDebug( "OWirelessNetworkInterface::buildInformation(): Interface %s reported to have %d channels.", name(), range.num_frequency );
539 for ( int i = 0; i < range.num_frequency; ++i ) 550 for ( int i = 0; i < range.num_frequency; ++i )
540 { 551 {
541 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 552 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
542 _channels.insert( freq, i+1 ); 553 _channels.insert( freq, i+1 );
543 } 554 }
544 } 555 }
545 556
546 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); 557 memcpy( &_range, buffer, sizeof( struct iw_range ) );
558 qDebug( "OWirelessNetworkInterface::buildInformation(): Information block constructed." );
547 free(buffer); 559 free(buffer);
548} 560}
549 561
550 562
551void OWirelessNetworkInterface::buildPrivateList() 563void OWirelessNetworkInterface::buildPrivateList()
552{ 564{
553 qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); 565 qDebug( "OWirelessNetworkInterface::buildPrivateList()" );
554 566
555 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 567 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
556 568
557 _iwr.u.data.pointer = (char*) &priv; 569 _iwr.u.data.pointer = (char*) &priv;
558 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 570 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
559 _iwr.u.data.flags = 0; 571 _iwr.u.data.flags = 0;
560 572
561 if ( !wioctl( SIOCGIWPRIV ) ) 573 if ( !wioctl( SIOCGIWPRIV ) )
562 { 574 {
563 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); 575 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) );
564 return; 576 return;
565 } 577 }
566 578
567 for ( int i = 0; i < _iwr.u.data.length; ++i ) 579 for ( int i = 0; i < _iwr.u.data.length; ++i )
568 { 580 {
569 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 581 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
570 } 582 }
571 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); 583 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
572} 584}
573 585
574 586
587void OWirelessNetworkInterface::dumpInformation() const
588{
589 qDebug( "OWirelessNetworkInterface::() -------------- dumping information block ----------------" );
590
591 qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 );
592 qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source );
593
594 qDebug( "OWirelessNetworkInterface::() ---------------------------------------------------------" );
595}
596
597
575int OWirelessNetworkInterface::channel() const 598int OWirelessNetworkInterface::channel() const
576{ 599{
577 //FIXME: When monitoring enabled, then use it 600 //FIXME: When monitoring enabled, then use it
578 //FIXME: to gather the current RF channel 601 //FIXME: to gather the current RF channel
579 //FIXME: Until then, get active channel from hopper. 602 //FIXME: Until then, get active channel from hopper.
580 if ( _hopper && _hopper->isActive() ) 603 if ( _hopper && _hopper->isActive() )
581 return _hopper->channel(); 604 return _hopper->channel();
582 605
583 if ( !wioctl( SIOCGIWFREQ ) ) 606 if ( !wioctl( SIOCGIWFREQ ) )
584 { 607 {
585 return -1; 608 return -1;
586 } 609 }
587 else 610 else
588 { 611 {
589 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 612 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
590 } 613 }
591} 614}
592 615
593 616
594void OWirelessNetworkInterface::setChannel( int c ) const 617void OWirelessNetworkInterface::setChannel( int c ) const
595{ 618{
596 if ( !c ) 619 if ( !c )
597 { 620 {
598 qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" ); 621 qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" );
599 return; 622 return;
600 } 623 }
601 624
602 if ( !_mon ) 625 if ( !_mon )
603 { 626 {
604 memset( &_iwr, 0, sizeof( struct iwreq ) ); 627 memset( &_iwr, 0, sizeof( struct iwreq ) );
605 _iwr.u.freq.m = c; 628 _iwr.u.freq.m = c;
606 _iwr.u.freq.e = 0; 629 _iwr.u.freq.e = 0;
607 wioctl( SIOCSIWFREQ ); 630 wioctl( SIOCSIWFREQ );
608 } 631 }
609 else 632 else
610 { 633 {
611 _mon->setChannel( c ); 634 _mon->setChannel( c );
612 } 635 }
613} 636}
614 637
615 638
616double OWirelessNetworkInterface::frequency() const 639double OWirelessNetworkInterface::frequency() const
617{ 640{
618 if ( !wioctl( SIOCGIWFREQ ) ) 641 if ( !wioctl( SIOCGIWFREQ ) )
619 { 642 {
620 return -1.0; 643 return -1.0;
621 } 644 }
622 else 645 else
623 { 646 {
624 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 647 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
625 } 648 }
626} 649}
627 650
628 651
629int OWirelessNetworkInterface::channels() const 652int OWirelessNetworkInterface::channels() const
630{ 653{
631 return _channels.count(); 654 return _channels.count();
632} 655}
633 656
634 657
635void OWirelessNetworkInterface::setChannelHopping( int interval ) 658void OWirelessNetworkInterface::setChannelHopping( int interval )
636{ 659{
637 if ( !_hopper ) _hopper = new OChannelHopper( this ); 660 if ( !_hopper ) _hopper = new OChannelHopper( this );
638 _hopper->setInterval( interval ); 661 _hopper->setInterval( interval );
639 //FIXME: When and by whom will the channel hopper be deleted? 662 //FIXME: When and by whom will the channel hopper be deleted?
640 //TODO: rely on QObject hierarchy 663 //TODO: rely on QObject hierarchy
641} 664}
642 665
643 666
644int OWirelessNetworkInterface::channelHopping() const 667int OWirelessNetworkInterface::channelHopping() const
645{ 668{
646 return _hopper->interval(); 669 return _hopper->interval();
647} 670}
648 671
649 672
650OChannelHopper* OWirelessNetworkInterface::channelHopper() const 673OChannelHopper* OWirelessNetworkInterface::channelHopper() const
651{ 674{
652 return _hopper; 675 return _hopper;
653} 676}
654 677
655 678
656void OWirelessNetworkInterface::setMode( const QString& mode ) 679void OWirelessNetworkInterface::setMode( const QString& mode )
657{ 680{
658 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; 681 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO;
659 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; 682 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC;
660 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; 683 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA;
661 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; 684 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER;
662 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; 685 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT;
663 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; 686 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND;
664 #if WIRELESS_EXT > 14
665 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; 687 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
666 #endif
667 else 688 else
668 { 689 {
669 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); 690 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
670 return; 691 return;
671 } 692 }
672 wioctl( SIOCSIWMODE ); 693 wioctl( SIOCSIWMODE );
673} 694}
674 695
675 696
676QString OWirelessNetworkInterface::mode() const 697QString OWirelessNetworkInterface::mode() const
677{ 698{
678 if ( !wioctl( SIOCGIWMODE ) ) 699 if ( !wioctl( SIOCGIWMODE ) )
679 { 700 {
680 return "<unknown>"; 701 return "<unknown>";
681 } 702 }
682 switch ( _iwr.u.mode ) 703 switch ( _iwr.u.mode )
683 { 704 {
684 case IW_MODE_AUTO: return "auto"; 705 case IW_MODE_AUTO: return "auto";
685 case IW_MODE_ADHOC: return "adhoc"; 706 case IW_MODE_ADHOC: return "adhoc";
686 case IW_MODE_INFRA: return "managed"; 707 case IW_MODE_INFRA: return "managed";
687 case IW_MODE_MASTER: return "master"; 708 case IW_MODE_MASTER: return "master";
688 case IW_MODE_REPEAT: return "repeater"; 709 case IW_MODE_REPEAT: return "repeater";
689 case IW_MODE_SECOND: return "secondary"; 710 case IW_MODE_SECOND: return "secondary";
690 #if WIRELESS_EXT > 14
691 case IW_MODE_MONITOR: return "monitor"; 711 case IW_MODE_MONITOR: return "monitor";
692 #endif
693 default: assert( 0 ); // shouldn't happen 712 default: assert( 0 ); // shouldn't happen
694 } 713 }
695} 714}
696 715
697 716
698void OWirelessNetworkInterface::setMonitorMode( bool b ) 717void OWirelessNetworkInterface::setMonitorMode( bool b )
699{ 718{
700 if ( _mon ) 719 if ( _mon )
701 _mon->setEnabled( b ); 720 _mon->setEnabled( b );
702 else 721 else
703 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 722 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
704} 723}
705 724
706 725
707bool OWirelessNetworkInterface::monitorMode() const 726bool OWirelessNetworkInterface::monitorMode() const
708{ 727{
709 qDebug( "dataLinkType = %d", dataLinkType() ); 728 qDebug( "dataLinkType = %d", dataLinkType() );
710 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); 729 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
711 // 802 is the header type for PRISM - Linux support for this is pending... 730 //FIXME: 802 is the header type for PRISM - Linux support for this is pending...
731 //FIXME: What is 119, by the way?
712} 732}
713 733
714 734
715void OWirelessNetworkInterface::setNickName( const QString& nickname ) 735void OWirelessNetworkInterface::setNickName( const QString& nickname )
716{ 736{
717 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); 737 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
718 _iwr.u.essid.length = nickname.length(); 738 _iwr.u.essid.length = nickname.length();
719 wioctl( SIOCSIWNICKN ); 739 wioctl( SIOCSIWNICKN );
720} 740}
721 741
722 742
723QString OWirelessNetworkInterface::nickName() const 743QString OWirelessNetworkInterface::nickName() const
724{ 744{
725 char str[IW_ESSID_MAX_SIZE]; 745 char str[IW_ESSID_MAX_SIZE];
726 _iwr.u.data.pointer = &str[0]; 746 _iwr.u.data.pointer = &str[0];
727 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 747 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
728 if ( !wioctl( SIOCGIWNICKN ) ) 748 if ( !wioctl( SIOCGIWNICKN ) )
729 { 749 {
730 return "<unknown>"; 750 return "<unknown>";
731 } 751 }
732 else 752 else
733 { 753 {
734 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 754 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
735 return str; 755 return str;
736 } 756 }
737} 757}
738 758
739 759
740void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 760void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
741{ 761{
742 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 762 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
743 if ( !priv ) 763 if ( !priv )
744 { 764 {
745 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); 765 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
746 return; 766 return;
747 } 767 }
748 if ( priv->numberSetArgs() != numargs ) 768 if ( priv->numberSetArgs() != numargs )
749 { 769 {
750 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); 770 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs );
751 return; 771 return;
752 } 772 }
753 773
754 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); 774 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() );
755 memset( &_iwr, 0, sizeof _iwr ); 775 memset( &_iwr, 0, sizeof _iwr );
756 va_list argp; 776 va_list argp;
757 va_start( argp, numargs ); 777 va_start( argp, numargs );
758 for ( int i = 0; i < numargs; ++i ) 778 for ( int i = 0; i < numargs; ++i )
759 { 779 {
760 priv->setParameter( i, va_arg( argp, int ) ); 780 priv->setParameter( i, va_arg( argp, int ) );
761 } 781 }
762 va_end( argp ); 782 va_end( argp );
763 priv->invoke(); 783 priv->invoke();
764} 784}
765 785
766 786
767void OWirelessNetworkInterface::getPrivate( const QString& call ) 787void OWirelessNetworkInterface::getPrivate( const QString& call )
768{ 788{
769 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); 789 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
770} 790}
771 791
772 792
773bool OWirelessNetworkInterface::hasPrivate( const QString& call ) 793bool OWirelessNetworkInterface::hasPrivate( const QString& call )
774{ 794{
775 return child( (const char*) call ); 795 return child( (const char*) call );
776} 796}
777 797
778 798
779QString OWirelessNetworkInterface::SSID() const 799QString OWirelessNetworkInterface::SSID() const
780{ 800{
781 char str[IW_ESSID_MAX_SIZE]; 801 char str[IW_ESSID_MAX_SIZE];
782 _iwr.u.essid.pointer = &str[0]; 802 _iwr.u.essid.pointer = &str[0];
783 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 803 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
784 if ( !wioctl( SIOCGIWESSID ) ) 804 if ( !wioctl( SIOCGIWESSID ) )
785 { 805 {
786 return "<unknown>"; 806 return "<unknown>";
787 } 807 }
788 else 808 else
789 { 809 {
790 return str; 810 return str;
791 } 811 }
792} 812}
793 813
794 814
795void OWirelessNetworkInterface::setSSID( const QString& ssid ) 815void OWirelessNetworkInterface::setSSID( const QString& ssid )
796{ 816{
797 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 817 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
798 _iwr.u.essid.length = ssid.length(); 818 _iwr.u.essid.length = ssid.length();
799 wioctl( SIOCSIWESSID ); 819 wioctl( SIOCSIWESSID );
800} 820}
801 821
802 822
823int OWirelessNetworkInterface::scanNetwork()
824{
825 _iwr.u.param.flags = IW_SCAN_DEFAULT;
826 _iwr.u.param.value = 0;
827 if ( !wioctl( SIOCSIWSCAN ) )
828 {
829 return -1;
830 }
831
832 int timeout = 1000000;
833
834 qDebug( "ONetworkInterface::scanNetwork() - scan started." );
835
836 bool results = false;
837 struct timeval tv;
838 tv.tv_sec = 0;
839 tv.tv_usec = 250000; // initial timeout ~ 250ms
840 char buffer[IW_SCAN_MAX_DATA];
841
842 while ( !results && timeout > 0 )
843 {
844 timeout -= tv.tv_usec;
845 select( 0, 0, 0, 0, &tv );
846
847 _iwr.u.data.pointer = &buffer[0];
848 _iwr.u.data.flags = 0;
849 _iwr.u.data.length = sizeof buffer;
850 if ( wioctl( SIOCGIWSCAN ) )
851 {
852 results = true;
853 continue;
854 }
855 else if ( errno == EAGAIN)
856 {
857 qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." );
858 #if 0
859 if ( qApp )
860 {
861 qApp->processEvents( 100 );
862 continue;
863 }
864 #endif
865 tv.tv_sec = 0;
866 tv.tv_usec = 100000;
867 continue;
868 }
869 }
870
871 qDebug( "ONetworkInterface::scanNetwork() - scan finished." );
872
873 if ( results )
874 {
875 qDebug( " - results are in!" );
876 }
877 else
878 {
879 qDebug( " - no results :(" );
880 }
881}
882
883
803bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 884bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
804{ 885{
805 int result = ::ioctl( _sfd, call, &iwreq ); 886 int result = ::ioctl( _sfd, call, &iwreq );
806 if ( result == -1 ) 887 if ( result == -1 )
807 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 888 qDebug( "ONetworkInterface::wioctl (%s) call %d (0x%04X) - Status: Failed: %d (%s)", name(), call, call, result, strerror( errno ) );
808 else 889 else
809 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); 890 qDebug( "ONetworkInterface::wioctl (%s) call %d (0x%04X) - Status: Ok.", name(), call, call );
810 return ( result != -1 ); 891 return ( result != -1 );
811} 892}
812 893
813 894
814bool OWirelessNetworkInterface::wioctl( int call ) const 895bool OWirelessNetworkInterface::wioctl( int call ) const
815{ 896{
816 strcpy( _iwr.ifr_name, name() ); 897 strcpy( _iwr.ifr_name, name() );
817 return wioctl( call, _iwr ); 898 return wioctl( call, _iwr );
818} 899}
819 900
820 901
821/*====================================================================================== 902/*======================================================================================
822 * OMonitoringInterface 903 * OMonitoringInterface
823 *======================================================================================*/ 904 *======================================================================================*/
824 905
825OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 906OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
826 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) 907 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader )
827{ 908{
828} 909}
829 910
830 911
831OMonitoringInterface::~OMonitoringInterface() 912OMonitoringInterface::~OMonitoringInterface()
832{ 913{
833} 914}
834 915
835 916
836void OMonitoringInterface::setChannel( int c ) 917void OMonitoringInterface::setChannel( int c )
837{ 918{
838 // use standard WE channel switching protocol 919 // use standard WE channel switching protocol
839 memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); 920 memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
840 _if->_iwr.u.freq.m = c; 921 _if->_iwr.u.freq.m = c;
841 _if->_iwr.u.freq.e = 0; 922 _if->_iwr.u.freq.e = 0;
842 _if->wioctl( SIOCSIWFREQ ); 923 _if->wioctl( SIOCSIWFREQ );
843} 924}
844 925
845 926
846bool OMonitoringInterface::enabled() const 927bool OMonitoringInterface::enabled() const
847{ 928{
848 return _if->monitorMode(); 929 return _if->monitorMode();
849} 930}
850 931
851 932
852void OMonitoringInterface::setEnabled( bool b ) 933void OMonitoringInterface::setEnabled( bool b )
853{ 934{
854} 935}
855 936
856 937
857/*====================================================================================== 938/*======================================================================================
858 * OCiscoMonitoringInterface 939 * OCiscoMonitoringInterface
859 *======================================================================================*/ 940 *======================================================================================*/
860 941
861OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 942OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
862 :OMonitoringInterface( iface, prismHeader ) 943 :OMonitoringInterface( iface, prismHeader )
863{ 944{
864 iface->setMonitoring( this ); 945 iface->setMonitoring( this );
865} 946}
866 947
867 948
868OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 949OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
869{ 950{
870} 951}
871 952
872 953
873void OCiscoMonitoringInterface::setEnabled( bool b ) 954void OCiscoMonitoringInterface::setEnabled( bool b )
874{ 955{
875 QString fname; 956 QString fname;
876 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 957 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
877 QFile f( fname ); 958 QFile f( fname );
878 if ( !f.exists() ) return; 959 if ( !f.exists() ) return;
879 960
880 if ( f.open( IO_WriteOnly ) ) 961 if ( f.open( IO_WriteOnly ) )
881 { 962 {
882 QTextStream s( &f ); 963 QTextStream s( &f );
883 s << "Mode: r"; 964 s << "Mode: r";
884 s << "Mode: y"; 965 s << "Mode: y";
885 s << "XmitPower: 1"; 966 s << "XmitPower: 1";
886 } 967 }
887 968
888 // flushing and closing will be done automatically when f goes out of scope 969 // flushing and closing will be done automatically when f goes out of scope
889} 970}
890 971
891 972
892QString OCiscoMonitoringInterface::name() const 973QString OCiscoMonitoringInterface::name() const
893{ 974{
894 return "cisco"; 975 return "cisco";
895} 976}
896 977
897 978
898void OCiscoMonitoringInterface::setChannel( int ) 979void OCiscoMonitoringInterface::setChannel( int )
899{ 980{
900 // cisco devices automatically switch channels when in monitor mode 981 // cisco devices automatically switch channels when in monitor mode
901} 982}
902 983
903 984
904/*====================================================================================== 985/*======================================================================================
905 * OWlanNGMonitoringInterface 986 * OWlanNGMonitoringInterface
906 *======================================================================================*/ 987 *======================================================================================*/
907 988
908 989
909OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 990OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
910 :OMonitoringInterface( iface, prismHeader ) 991 :OMonitoringInterface( iface, prismHeader )
911{ 992{
912 iface->setMonitoring( this ); 993 iface->setMonitoring( this );
913} 994}
914 995
915 996
916OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 997OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
917{ 998{
918} 999}
919 1000
920 1001
921void OWlanNGMonitoringInterface::setEnabled( bool b ) 1002void OWlanNGMonitoringInterface::setEnabled( bool b )
922{ 1003{
923 //FIXME: do nothing if its already in the same mode 1004 //FIXME: do nothing if its already in the same mode
924 1005
925 QString enable = b ? "true" : "false"; 1006 QString enable = b ? "true" : "false";
926 QString prism = _prismHeader ? "true" : "false"; 1007 QString prism = _prismHeader ? "true" : "false";
927 QString cmd; 1008 QString cmd;
928 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", 1009 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
929 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); 1010 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism );
930 system( cmd ); 1011 system( cmd );
931} 1012}
932 1013
933 1014
934QString OWlanNGMonitoringInterface::name() const 1015QString OWlanNGMonitoringInterface::name() const
935{ 1016{
936 return "wlan-ng"; 1017 return "wlan-ng";
937} 1018}
938 1019
939 1020
940void OWlanNGMonitoringInterface::setChannel( int c ) 1021void OWlanNGMonitoringInterface::setChannel( int c )
941{ 1022{
942 //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. 1023 //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't.
943 1024
944 QString enable = "true"; //_if->monitorMode() ? "true" : "false"; 1025 QString enable = "true"; //_if->monitorMode() ? "true" : "false";
945 QString prism = _prismHeader ? "true" : "false"; 1026 QString prism = _prismHeader ? "true" : "false";
946 QString cmd; 1027 QString cmd;
947 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", 1028 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
948 (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); 1029 (const char*) _if->name(), c, (const char*) enable, (const char*) prism );
949 system( cmd ); 1030 system( cmd );
950} 1031}
951 1032
952 1033
953/*====================================================================================== 1034/*======================================================================================
954 * OHostAPMonitoringInterface 1035 * OHostAPMonitoringInterface
955 *======================================================================================*/ 1036 *======================================================================================*/
956 1037
957OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1038OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
958 :OMonitoringInterface( iface, prismHeader ) 1039 :OMonitoringInterface( iface, prismHeader )
959{ 1040{
960 iface->setMonitoring( this ); 1041 iface->setMonitoring( this );
961} 1042}
962 1043
963OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 1044OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
964{ 1045{
965} 1046}
966 1047
967void OHostAPMonitoringInterface::setEnabled( bool b ) 1048void OHostAPMonitoringInterface::setEnabled( bool b )
968{ 1049{
969 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 1050 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
970 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 1051 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
971 1052
972 #if WIRELESS_EXT > 14 1053 #if WIRELESS_EXT > 14
973 if ( b ) 1054 if ( b )
974 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header 1055 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header
975 else 1056 else
976 _if->setMode( "managed" ); 1057 _if->setMode( "managed" );
977 #else 1058 #else
978 int monitorCode = _prismHeader ? 1 : 2; 1059 int monitorCode = _prismHeader ? 1 : 2;
979 if ( b ) 1060 if ( b )
980 { 1061 {
981 _if->setPrivate( "monitor", 1, monitorCode ); 1062 _if->setPrivate( "monitor", 1, monitorCode );
982 } 1063 }
983 else 1064 else
984 { 1065 {
985 _if->setPrivate( "monitor", 1, 0 ); 1066 _if->setPrivate( "monitor", 1, 0 );
986 } 1067 }
987 #endif 1068 #endif
988} 1069}
989 1070
990 1071
991QString OHostAPMonitoringInterface::name() const 1072QString OHostAPMonitoringInterface::name() const
992{ 1073{
993 return "hostap"; 1074 return "hostap";
994} 1075}
995 1076
996 1077
997/*====================================================================================== 1078/*======================================================================================
998 * OOrinocoNetworkInterface 1079 * OOrinocoNetworkInterface
999 *======================================================================================*/ 1080 *======================================================================================*/
1000 1081
1001OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1082OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
1002 :OMonitoringInterface( iface, prismHeader ) 1083 :OMonitoringInterface( iface, prismHeader )
1003{ 1084{
1004 iface->setMonitoring( this ); 1085 iface->setMonitoring( this );
1005} 1086}
1006 1087
1007 1088
1008OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 1089OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
1009{ 1090{
1010} 1091}
1011 1092
1012 1093
1013void OOrinocoMonitoringInterface::setChannel( int c ) 1094void OOrinocoMonitoringInterface::setChannel( int c )
1014{ 1095{
1015 int monitorCode = _prismHeader ? 1 : 2; 1096 int monitorCode = _prismHeader ? 1 : 2;
1016 _if->setPrivate( "monitor", 2, monitorCode, c ); 1097 _if->setPrivate( "monitor", 2, monitorCode, c );
1017} 1098}
1018 1099
1019 1100
1020void OOrinocoMonitoringInterface::setEnabled( bool b ) 1101void OOrinocoMonitoringInterface::setEnabled( bool b )
1021{ 1102{
1022 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 1103 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
1023 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 1104 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
1024 // However, as of recent orinoco drivers, IW_MODE_MONITOR is still not supported 1105 // However, as of recent orinoco drivers, IW_MODE_MONITOR is still not supported
1025 1106
1026 #if 0 1107 #if 0
1027 //#if WIRELESS_EXT > 14 1108 //#if WIRELESS_EXT > 14
1028 if ( b ) 1109 if ( b )
1029 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header 1110 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header
1030 else 1111 else
1031 _if->setMode( "managed" ); 1112 _if->setMode( "managed" );
1032 #else 1113 #else
1033 if ( b ) 1114 if ( b )
1034 { 1115 {
1035 setChannel( 1 ); 1116 setChannel( 1 );
1036 } 1117 }
1037 else 1118 else
1038 { 1119 {
1039 _if->setPrivate( "monitor", 2, 0, 0 ); 1120 _if->setPrivate( "monitor", 2, 0, 0 );
1040 } 1121 }
1041 #endif 1122 #endif
1042} 1123}
1043 1124
1044 1125
1045QString OOrinocoMonitoringInterface::name() const 1126QString OOrinocoMonitoringInterface::name() const
1046{ 1127{
1047 return "orinoco"; 1128 return "orinoco";
1048} 1129}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index b170ea2..e1545dd 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -1,528 +1,543 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef ONETWORK_H 34#ifndef ONETWORK_H
35#define ONETWORK_H 35#define ONETWORK_H
36 36
37#include "wireless.h" 37#include "wireless.h"
38 38
39/* OPIE */ 39/* OPIE */
40 40
41#include <opie2/onetutils.h> 41#include <opie2/onetutils.h>
42 42
43/* QT */ 43/* QT */
44 44
45#include <qvaluelist.h> 45#include <qvaluelist.h>
46#include <qdict.h> 46#include <qdict.h>
47#include <qmap.h> 47#include <qmap.h>
48#include <qobject.h> 48#include <qobject.h>
49#include <qhostaddress.h> 49#include <qhostaddress.h>
50 50
51class ONetworkInterface; 51class ONetworkInterface;
52class OWirelessNetworkInterface; 52class OWirelessNetworkInterface;
53class OChannelHopper; 53class OChannelHopper;
54class OMonitoringInterface; 54class OMonitoringInterface;
55 55
56/*====================================================================================== 56/*======================================================================================
57 * ONetwork 57 * ONetwork
58 *======================================================================================*/ 58 *======================================================================================*/
59 59
60/** 60/**
61 * @brief A container class for all network interfaces 61 * @brief A container class for all network interfaces
62 * 62 *
63 * This class provides access to all available network interfaces of your computer. 63 * This class provides access to all available network interfaces of your computer.
64 * 64 *
65 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 65 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
66 */ 66 */
67class ONetwork : public QObject 67class ONetwork : public QObject
68{ 68{
69 Q_OBJECT 69 Q_OBJECT
70 70
71 public: 71 public:
72 typedef QDict<ONetworkInterface> InterfaceMap; 72 typedef QDict<ONetworkInterface> InterfaceMap;
73 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 73 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
74 74
75 public: 75 public:
76 /** 76 /**
77 * @returns the number of available interfaces 77 * @returns the number of available interfaces
78 */ 78 */
79 int count() const; 79 int count() const;
80 /** 80 /**
81 * @returns a pointer to the (one and only) @ref ONetwork instance. 81 * @returns a pointer to the (one and only) @ref ONetwork instance.
82 */ 82 */
83 static ONetwork* instance(); 83 static ONetwork* instance();
84 /** 84 /**
85 * @returns an iterator usable for iterating through all network interfaces. 85 * @returns an iterator usable for iterating through all network interfaces.
86 */ 86 */
87 InterfaceIterator iterator() const; 87 InterfaceIterator iterator() const;
88 /** 88 /**
89 * @returns true, if the @a interface supports the wireless extension protocol. 89 * @returns true, if the @a interface supports the wireless extension protocol.
90 */ 90 */
91 bool isWirelessInterface( const char* interface ) const; 91 bool isWirelessInterface( const char* interface ) const;
92 /** 92 /**
93 * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. 93 * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found.
94 * @see ONetworkInterface 94 * @see ONetworkInterface
95 */ 95 */
96 ONetworkInterface* interface( const QString& interface ) const; 96 ONetworkInterface* interface( const QString& interface ) const;
97 /** 97 /**
98 * @internal Rebuild the internal interface database 98 * @internal Rebuild the internal interface database
99 * @note Sometimes it might be useful to call this from client code, 99 * @note Sometimes it might be useful to call this from client code,
100 * e.g. after issuing a cardctl insert 100 * e.g. after issuing a cardctl insert
101 */ 101 */
102 void synchronize(); 102 void synchronize();
103 /** 103 /**
104 * @returns the wireless extension version used at compile time. 104 * @returns the wireless extension version used at compile time.
105 **/ 105 **/
106 static short wirelessExtensionVersion(); 106 static short wirelessExtensionVersion();
107 107
108 protected: 108 protected:
109 ONetwork(); 109 ONetwork();
110 110
111 private: 111 private:
112 static ONetwork* _instance; 112 static ONetwork* _instance;
113 InterfaceMap _interfaces; 113 InterfaceMap _interfaces;
114}; 114};
115 115
116 116
117/*====================================================================================== 117/*======================================================================================
118 * ONetworkInterface 118 * ONetworkInterface
119 *======================================================================================*/ 119 *======================================================================================*/
120 120
121/** 121/**
122 * @brief A network interface wrapper. 122 * @brief A network interface wrapper.
123 * 123 *
124 * This class provides a wrapper for a network interface. All the cumbersume details of 124 * This class provides a wrapper for a network interface. All the cumbersume details of
125 * Linux ioctls are hidden under a convenient high-level interface. 125 * Linux ioctls are hidden under a convenient high-level interface.
126 * @warning Most of the setting methods contained in this class require the appropriate 126 * @warning Most of the setting methods contained in this class require the appropriate
127 * process permissions to work. 127 * process permissions to work.
128 * 128 *
129 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 129 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
130 */ 130 */
131class ONetworkInterface : public QObject 131class ONetworkInterface : public QObject
132{ 132{
133 friend class OMonitoringInterface; 133 friend class OMonitoringInterface;
134 friend class OCiscoMonitoringInterface; 134 friend class OCiscoMonitoringInterface;
135 friend class OWlanNGMonitoringInterface; 135 friend class OWlanNGMonitoringInterface;
136 friend class OHostAPMonitoringInterface; 136 friend class OHostAPMonitoringInterface;
137 friend class OOrinocoMonitoringInterface; 137 friend class OOrinocoMonitoringInterface;
138 138
139 public: 139 public:
140 /** 140 /**
141 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, 141 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself,
142 * but access them via @ref ONetwork::interface(). 142 * but access them via @ref ONetwork::interface().
143 */ 143 */
144 ONetworkInterface( QObject* parent, const char* name ); 144 ONetworkInterface( QObject* parent, const char* name );
145 /** 145 /**
146 * Destructor. 146 * Destructor.
147 */ 147 */
148 virtual ~ONetworkInterface(); 148 virtual ~ONetworkInterface();
149 /** 149 /**
150 * Associates a @a monitoring interface with this network interface. 150 * Associates a @a monitoring interface with this network interface.
151 * @note This is currently only useful with @ref OWirelessNetworkInterface objects. 151 * @note This is currently only useful with @ref OWirelessNetworkInterface objects.
152 */ 152 */
153 void setMonitoring( OMonitoringInterface* monitoring ); 153 void setMonitoring( OMonitoringInterface* monitoring );
154 /** 154 /**
155 * @returns the currently associated monitoring interface or 0, if no monitoring is associated. 155 * @returns the currently associated monitoring interface or 0, if no monitoring is associated.
156 */ 156 */
157 OMonitoringInterface* monitoring() const; 157 OMonitoringInterface* monitoring() const;
158 /** 158 /**
159 * Setting an interface to promiscuous mode enables the device to receive 159 * Setting an interface to promiscuous mode enables the device to receive
160 * all packets on the shared medium - as opposed to packets which are addressed to this interface. 160 * all packets on the shared medium - as opposed to packets which are addressed to this interface.
161 */ 161 */
162 bool setPromiscuousMode( bool ); 162 bool setPromiscuousMode( bool );
163 /** 163 /**
164 * @returns true if the interface is set to promiscuous mode. 164 * @returns true if the interface is set to promiscuous mode.
165 */ 165 */
166 bool promiscuousMode() const; 166 bool promiscuousMode() const;
167 /** 167 /**
168 * Setting an interface to up enables it to receive packets. 168 * Setting an interface to up enables it to receive packets.
169 */ 169 */
170 bool setUp( bool ); 170 bool setUp( bool );
171 /** 171 /**
172 * @returns true if the interface is up. 172 * @returns true if the interface is up.
173 */ 173 */
174 bool isUp() const; 174 bool isUp() const;
175 /** 175 /**
176 * @returns true if the interface is a loopback interface. 176 * @returns true if the interface is a loopback interface.
177 */ 177 */
178 bool isLoopback() const; 178 bool isLoopback() const;
179 /** 179 /**
180 * @returns true if the interface is featuring supports the wireless extension protocol. 180 * @returns true if the interface is featuring supports the wireless extension protocol.
181 */ 181 */
182 bool isWireless() const; 182 bool isWireless() const;
183 /** 183 /**
184 * Associate the IP address @ addr with the interface. 184 * Associate the IP address @ addr with the interface.
185 */ 185 */
186 void setIPV4Address( const QHostAddress& addr ); 186 void setIPV4Address( const QHostAddress& addr );
187 /** 187 /**
188 * @returns the IPv4 address associated with the interface. 188 * @returns the IPv4 address associated with the interface.
189 */ 189 */
190 QString ipV4Address() const; //TODO: make this return an OHostAddress 190 QString ipV4Address() const; //TODO: make this return an OHostAddress
191 /** 191 /**
192 * Associate the MAC address @a addr with the interface. 192 * Associate the MAC address @a addr with the interface.
193 * @note It can be necessary to shut down the interface prior to calling this method. 193 * @note It can be necessary to shut down the interface prior to calling this method.
194 * @warning This is not supported by all drivers. 194 * @warning This is not supported by all drivers.
195 */ 195 */
196 void setMacAddress( const OMacAddress& addr ); 196 void setMacAddress( const OMacAddress& addr );
197 /** 197 /**
198 * @returns the MAC address associated with the interface. 198 * @returns the MAC address associated with the interface.
199 */ 199 */
200 OMacAddress macAddress() const; 200 OMacAddress macAddress() const;
201 /** 201 /**
202 * Associate the IPv4 @a netmask with the interface. 202 * Associate the IPv4 @a netmask with the interface.
203 */ 203 */
204 void setIPV4Netmask( const QHostAddress& netmask ); 204 void setIPV4Netmask( const QHostAddress& netmask );
205 /** 205 /**
206 * @returns the IPv4 netmask associated with the interface. 206 * @returns the IPv4 netmask associated with the interface.
207 */ 207 */
208 QString ipV4Netmask() const; //TODO: make this return an OHostAddress 208 QString ipV4Netmask() const; //TODO: make this return an OHostAddress
209 /** 209 /**
210 * @returns the data link type currently associated with the interface. 210 * @returns the data link type currently associated with the interface.
211 * @see #include <net/if_arp.h> for possible values. 211 * @see #include <net/if_arp.h> for possible values.
212 */ 212 */
213 int dataLinkType() const; 213 int dataLinkType() const;
214 214
215 protected: 215 protected:
216 const int _sfd; 216 const int _sfd;
217 mutable ifreq _ifr; 217 mutable ifreq _ifr;
218 OMonitoringInterface* _mon; 218 OMonitoringInterface* _mon;
219 219
220 protected: 220 protected:
221 struct ifreq& ifr() const; 221 struct ifreq& ifr() const;
222 virtual void init(); 222 virtual void init();
223 bool ioctl( int call ) const; 223 bool ioctl( int call ) const;
224 bool ioctl( int call, struct ifreq& ) const; 224 bool ioctl( int call, struct ifreq& ) const;
225}; 225};
226 226
227/*====================================================================================== 227/*======================================================================================
228 * OChannelHopper 228 * OChannelHopper
229 *======================================================================================*/ 229 *======================================================================================*/
230 230
231/** 231/**
232 * @brief A radio frequency channel hopper. 232 * @brief A radio frequency channel hopper.
233 * 233 *
234 * This class provides a channel hopper for radio frequencies. A channel hopper frequently 234 * This class provides a channel hopper for radio frequencies. A channel hopper frequently
235 * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. 235 * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface.
236 * This is necessary when in monitoring mode and scanning for other devices, because 236 * This is necessary when in monitoring mode and scanning for other devices, because
237 * the radio frequency hardware can only detect packets sent on the same frequency. 237 * the radio frequency hardware can only detect packets sent on the same frequency.
238 * 238 *
239 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 239 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
240 */ 240 */
241class OChannelHopper : public QObject 241class OChannelHopper : public QObject
242{ 242{
243 Q_OBJECT 243 Q_OBJECT
244 244
245 public: 245 public:
246 /** 246 /**
247 * Constructor. 247 * Constructor.
248 */ 248 */
249 OChannelHopper( OWirelessNetworkInterface* ); 249 OChannelHopper( OWirelessNetworkInterface* );
250 /** 250 /**
251 * Destructor. 251 * Destructor.
252 */ 252 */
253 virtual ~OChannelHopper(); 253 virtual ~OChannelHopper();
254 /** 254 /**
255 * @returns true, if the channel hopper is hopping channels 255 * @returns true, if the channel hopper is hopping channels
256 */ 256 */
257 bool isActive() const; 257 bool isActive() const;
258 /** 258 /**
259 * @returns the last hopped channel 259 * @returns the last hopped channel
260 */ 260 */
261 int channel() const; 261 int channel() const;
262 /** 262 /**
263 * Set the channel hopping @a interval. 263 * Set the channel hopping @a interval.
264 * An interval of 0 deactivates the channel hopper. 264 * An interval of 0 deactivates the channel hopper.
265 */ 265 */
266 void setInterval( int interval ); 266 void setInterval( int interval );
267 /** 267 /**
268 * @returns the channel hopping interval 268 * @returns the channel hopping interval
269 */ 269 */
270 int interval() const; 270 int interval() const;
271 271
272 signals: 272 signals:
273 /** 273 /**
274 * This signal is emitted right after the channel hopper performed a hop 274 * This signal is emitted right after the channel hopper performed a hop
275 */ 275 */
276 void hopped( int ); 276 void hopped( int );
277 277
278 protected: 278 protected:
279 virtual void timerEvent( QTimerEvent* ); 279 virtual void timerEvent( QTimerEvent* );
280 280
281 private: 281 private:
282 OWirelessNetworkInterface* _iface; 282 OWirelessNetworkInterface* _iface;
283 int _interval; 283 int _interval;
284 int _tid; 284 int _tid;
285 QValueList<int> _channels; 285 QValueList<int> _channels;
286 QValueList<int>::Iterator _channel; 286 QValueList<int>::Iterator _channel;
287}; 287};
288 288
289 289
290/*====================================================================================== 290/*======================================================================================
291 * OWirelessNetworkInterface 291 * OWirelessNetworkInterface
292 *======================================================================================*/ 292 *======================================================================================*/
293 293
294/** 294/**
295 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. 295 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol.
296 * 296 *
297 * This class provides a high-level encapsulation of the Linux wireless extension API. 297 * This class provides a high-level encapsulation of the Linux wireless extension API.
298 * 298 *
299 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 299 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
300 */ 300 */
301class OWirelessNetworkInterface : public ONetworkInterface 301class OWirelessNetworkInterface : public ONetworkInterface
302{ 302{
303 friend class OMonitoringInterface; 303 friend class OMonitoringInterface;
304 friend class OCiscoMonitoringInterface; 304 friend class OCiscoMonitoringInterface;
305 friend class OWlanNGMonitoringInterface; 305 friend class OWlanNGMonitoringInterface;
306 friend class OHostAPMonitoringInterface; 306 friend class OHostAPMonitoringInterface;
307 friend class OOrinocoMonitoringInterface; 307 friend class OOrinocoMonitoringInterface;
308 308
309 friend class OPrivateIOCTL; 309 friend class OPrivateIOCTL;
310 310
311 public: 311 public:
312 /** 312 /**
313 * Constructor. 313 * Constructor.
314 */ 314 */
315 OWirelessNetworkInterface( QObject* parent, const char* name ); 315 OWirelessNetworkInterface( QObject* parent, const char* name );
316 /** 316 /**
317 * Destructor. 317 * Destructor.
318 */ 318 */
319 virtual ~OWirelessNetworkInterface(); 319 virtual ~OWirelessNetworkInterface();
320 /** 320 /**
321 * Setting the @a channel of the interface changes the radio frequency (RF) 321 * Setting the @a channel of the interface changes the radio frequency (RF)
322 * of the corresponding wireless network device. 322 * of the corresponding wireless network device.
323 * @note Common channel range is within [1-14]. A value of 0 is not allowed. 323 * @note Common channel range is within [1-14]. A value of 0 is not allowed.
324 * @see channels() 324 * @see channels()
325 */ 325 */
326 virtual void setChannel( int channel ) const; 326 virtual void setChannel( int channel ) const;
327 /** 327 /**
328 * @returns the channel index of the current radio frequency. 328 * @returns the channel index of the current radio frequency.
329 */ 329 */
330 virtual int channel() const; 330 virtual int channel() const;
331 /** 331 /**
332 * @returns the current radio frequency (in MHz). 332 * @returns the current radio frequency (in MHz).
333 */ 333 */
334 virtual double frequency() const; 334 virtual double frequency() const;
335 /** 335 /**
336 * @returns the number of radio frequency channels for the 336 * @returns the number of radio frequency channels for the
337 * corresponding wireless network device. 337 * corresponding wireless network device.
338 * @note European devices usually have 14 channels, while American typically feature 11 channels. 338 * @note European devices usually have 14 channels, while American typically feature 11 channels.
339 */ 339 */
340 virtual int channels() const; 340 virtual int channels() const;
341 /** 341 /**
342 * Set the IEEE 802.11 operation @a mode. 342 * Set the IEEE 802.11 operation @a mode.
343 * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master 343 * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master
344 * @warning Not all drivers support the all modes. 344 * @warning Not all drivers support the all modes.
345 * @note You might have to change the SSID to get the operation mode change into effect. 345 * @note You might have to change the SSID to get the operation mode change into effect.
346 */ 346 */
347 virtual void setMode( const QString& mode ); 347 virtual void setMode( const QString& mode );
348 /** 348 /**
349 * @returns the current IEEE 802.11 operation mode. 349 * @returns the current IEEE 802.11 operation mode.
350 * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown 350 * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown
351 */ 351 */
352 virtual QString mode() const; 352 virtual QString mode() const;
353 /** 353 /**
354 * Setting the monitor mode on a wireless network interface enables 354 * Setting the monitor mode on a wireless network interface enables
355 * listening to IEEE 802.11 data and management frames which normally 355 * listening to IEEE 802.11 data and management frames which normally
356 * are handled by the device firmware. This can be used to detect 356 * are handled by the device firmware. This can be used to detect
357 * other wireless network devices, e.g. Access Points or Ad-hoc stations. 357 * other wireless network devices, e.g. Access Points or Ad-hoc stations.
358 * @warning Standard wireless network drives don't support the monitor mode. 358 * @warning Standard wireless network drives don't support the monitor mode.
359 * @warning You need a patched driver for this to work. 359 * @warning You need a patched driver for this to work.
360 * @note Enabling the monitor mode is highly driver dependent and requires 360 * @note Enabling the monitor mode is highly driver dependent and requires
361 * the proper @ref OMonitoringInterface to be associated with the interface. 361 * the proper @ref OMonitoringInterface to be associated with the interface.
362 * @see OMonitoringInterface 362 * @see OMonitoringInterface
363 */ 363 */
364 virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); 364 virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); Use IW_MONITOR first, if this doesn't work, then use iwpriv!
365 /** 365 /**
366 * @returns true if the device is listening in IEEE 802.11 monitor mode 366 * @returns true if the device is listening in IEEE 802.11 monitor mode
367 */ 367 */
368 virtual bool monitorMode() const; //FIXME: ==> mode() 368 virtual bool monitorMode() const; //FIXME: ==> mode()
369 /** 369 /**
370 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. 370 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping.
371 * @see OChannelHopper 371 * @see OChannelHopper
372 */ 372 */
373 virtual void setChannelHopping( int interval = 0 ); 373 virtual void setChannelHopping( int interval = 0 );
374 /** 374 /**
375 * @returns the channel hopping interval or 0, if channel hopping is disabled. 375 * @returns the channel hopping interval or 0, if channel hopping is disabled.
376 */ 376 */
377 virtual int channelHopping() const; 377 virtual int channelHopping() const;
378 /** 378 /**
379 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before 379 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before
380 */ 380 */
381 virtual OChannelHopper* channelHopper() const; 381 virtual OChannelHopper* channelHopper() const;
382 /** 382 /**
383 * Set the station @a nickname. 383 * Set the station @a nickname.
384 */ 384 */
385 virtual void setNickName( const QString& nickname ); 385 virtual void setNickName( const QString& nickname );
386 /** 386 /**
387 * @returns the current station nickname. 387 * @returns the current station nickname.
388 */ 388 */
389 virtual QString nickName() const; 389 virtual QString nickName() const;
390 /** 390 /**
391 * Invoke the private IOCTL @a command with a @number of parameters on the network interface. 391 * Invoke the private IOCTL @a command with a @number of parameters on the network interface.
392 * @see OPrivateIOCTL 392 * @see OPrivateIOCTL
393 */ 393 */
394 virtual void setPrivate( const QString& command, int number, ... ); 394 virtual void setPrivate( const QString& command, int number, ... );
395 /** 395 /**
396 * @returns true if the interface is featuring the private IOCTL @command. 396 * @returns true if the interface is featuring the private IOCTL @command.
397 */ 397 */
398 virtual bool hasPrivate( const QString& command ); 398 virtual bool hasPrivate( const QString& command );
399 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this 399 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this
400
401 virtual bool isAssociated() const {}; //FIXME: Implement and document this
402 /** 400 /**
403 * @returns the MAC address of the Access Point if the 401 * @returns true if the interface is associated to an access point
404 * device is in infrastructure mode. @returns a (more or less random) CELL 402 * @note: This information is only valid if the interface is in managed mode.
405 * address if the device is in adhoc mode. 403 */
404 virtual bool isAssociated() const;
405 /**
406 * @returns the MAC address of the Access Point if the device is in infrastructure mode.
407 * @returns a (more or less random) cell ID address if the device is in adhoc mode.
406 */ 408 */
407 virtual QString associatedAP() const; 409 virtual QString associatedAP() const;
408 /** 410 /**
409 * Set the @a ssid (Service Set ID) string. This is used to decide 411 * Set the @a ssid (Service Set ID) string. This is used to decide
410 * which network to associate with (use "any" to let the driver decide). 412 * which network to associate with (use "any" to let the driver decide).
411 */ 413 */
412 virtual void setSSID( const QString& ssid ); 414 virtual void setSSID( const QString& ssid );
413 /** 415 /**
414 * @returns the current SSID (Service Set ID). 416 * @returns the current SSID (Service Set ID).
415 */ 417 */
416 virtual QString SSID() const; 418 virtual QString SSID() const;
419 /**
420 * Perform scanning the wireless network neighbourhood.
421 * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE!
422 */
423 virtual int scanNetwork();
417 424
418 protected: 425 protected:
419 void buildChannelList(); 426 void buildInformation();
420 void buildPrivateList(); 427 void buildPrivateList();
428 void dumpInformation() const;
421 virtual void init(); 429 virtual void init();
422 struct iwreq& iwr() const; 430 struct iwreq& iwr() const;
423 bool wioctl( int call ) const; 431 bool wioctl( int call ) const;
424 bool wioctl( int call, struct iwreq& ) const; 432 bool wioctl( int call, struct iwreq& ) const;
425 433
426 protected: 434 protected:
427 mutable struct iwreq _iwr; 435 mutable struct iwreq _iwr;
428 QMap<int,int> _channels; 436 QMap<int,int> _channels;
437 struct iw_range _range;
429 438
430 private: 439 private:
431 OChannelHopper* _hopper; 440 OChannelHopper* _hopper;
432}; 441};
433 442
434 443
435/*====================================================================================== 444/*======================================================================================
436 * OMonitoringInterface 445 * OMonitoringInterface
437 *======================================================================================*/ 446 *======================================================================================*/
438 447
439 448
440class OMonitoringInterface 449class OMonitoringInterface
441{ 450{
442 public: 451 public:
443 OMonitoringInterface(); 452 OMonitoringInterface();
444 OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 453 OMonitoringInterface( ONetworkInterface*, bool _prismHeader );
445 virtual ~OMonitoringInterface(); 454 virtual ~OMonitoringInterface();
446 455
447 public: 456 public:
448 virtual void setEnabled( bool ); 457 virtual void setEnabled( bool );
449 virtual bool enabled() const; 458 virtual bool enabled() const;
450 virtual void setChannel( int ); 459 virtual void setChannel( int );
451 460
452 virtual QString name() const = 0; 461 virtual QString name() const = 0;
453 462
454 protected: 463 protected:
455 OWirelessNetworkInterface* _if; 464 OWirelessNetworkInterface* _if;
456 bool _prismHeader; 465 bool _prismHeader;
457 466
458}; 467};
459 468
460 469
461/*====================================================================================== 470/*======================================================================================
462 * OCiscoMonitoring 471 * OCiscoMonitoring
463 *======================================================================================*/ 472 *======================================================================================*/
464 473
465 474
466class OCiscoMonitoringInterface : public OMonitoringInterface 475class OCiscoMonitoringInterface : public OMonitoringInterface
467{ 476{
468 public: 477 public:
469 OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 478 OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader );
470 virtual ~OCiscoMonitoringInterface(); 479 virtual ~OCiscoMonitoringInterface();
471 480
472 virtual void setEnabled( bool ); 481 virtual void setEnabled( bool );
473 virtual QString name() const; 482 virtual QString name() const;
474 virtual void setChannel( int ); 483 virtual void setChannel( int );
475 484
476}; 485};
477 486
487
478/*====================================================================================== 488/*======================================================================================
479 * OWlanNGMonitoringInterface 489 * OWlanNGMonitoringInterface
480 *======================================================================================*/ 490 *======================================================================================*/
481 491
492
482class OWlanNGMonitoringInterface : public OMonitoringInterface 493class OWlanNGMonitoringInterface : public OMonitoringInterface
483{ 494{
484 public: 495 public:
485 OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 496 OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader );
486 virtual ~OWlanNGMonitoringInterface(); 497 virtual ~OWlanNGMonitoringInterface();
487 498
488 public: 499 public:
489 virtual void setEnabled( bool ); 500 virtual void setEnabled( bool );
490 virtual QString name() const; 501 virtual QString name() const;
491 virtual void setChannel( int ); 502 virtual void setChannel( int );
492 503
493}; 504};
494 505
506
495/*====================================================================================== 507/*======================================================================================
496 * OHostAPMonitoringInterface 508 * OHostAPMonitoringInterface
497 *======================================================================================*/ 509 *======================================================================================*/
498 510
511
499class OHostAPMonitoringInterface : public OMonitoringInterface 512class OHostAPMonitoringInterface : public OMonitoringInterface
500{ 513{
501 public: 514 public:
502 OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 515 OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader );
503 virtual ~OHostAPMonitoringInterface(); 516 virtual ~OHostAPMonitoringInterface();
504 517
505 public: 518 public:
506 virtual void setEnabled( bool ); 519 virtual void setEnabled( bool );
507 virtual QString name() const; 520 virtual QString name() const;
508 }; 521 };
509 522
523
510/*====================================================================================== 524/*======================================================================================
511 * OOrinocoMonitoringInterface 525 * OOrinocoMonitoringInterface
512 *======================================================================================*/ 526 *======================================================================================*/
513 527
528
514class OOrinocoMonitoringInterface : public OMonitoringInterface 529class OOrinocoMonitoringInterface : public OMonitoringInterface
515{ 530{
516 public: 531 public:
517 OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 532 OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader );
518 virtual ~OOrinocoMonitoringInterface(); 533 virtual ~OOrinocoMonitoringInterface();
519 534
520 public: 535 public:
521 virtual void setChannel( int ); 536 virtual void setChannel( int );
522 virtual void setEnabled( bool ); 537 virtual void setEnabled( bool );
523 virtual QString name() const; 538 virtual QString name() const;
524 539
525}; 540};
526 541
527#endif // ONETWORK_H 542#endif // ONETWORK_H
528 543