summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp16
-rw-r--r--libopie2/opienet/onetutils.cpp30
-rw-r--r--libopie2/opienet/onetutils.h7
-rw-r--r--libopie2/opienet/onetwork.cpp91
-rw-r--r--libopie2/opienet/onetwork.h5
-rw-r--r--libopie2/opienet/ostation.cpp15
-rw-r--r--libopie2/opienet/ostation.h17
7 files changed, 115 insertions, 66 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
index fc2026f..21026e1 100644
--- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -1,89 +1,97 @@
1#include <opie2/onetwork.h> 1#include <opie2/onetwork.h>
2#include <opie2/ostation.h>
2#include <opie2/omanufacturerdb.h> 3#include <opie2/omanufacturerdb.h>
3 4
4int main( int argc, char** argv ) 5int main( int argc, char** argv )
5{ 6{
6 qDebug( "OPIE Network Demo" ); 7 qDebug( "OPIE Network Demo" );
7 8
8 ONetwork* net = ONetwork::instance(); 9 ONetwork* net = ONetwork::instance();
9 10
10 ONetwork::InterfaceIterator it = net->iterator(); 11 ONetwork::InterfaceIterator it = net->iterator();
11 12
12 while ( it.current() ) 13 while ( it.current() )
13 { 14 {
14 qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() ); 15 qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() );
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() );
16 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) ); 17 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() ); 18 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" ) ); 19 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" ) ); 20 qDebug( "DEMO: Manufacturertest2 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) );
20 qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() ); 21 qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() );
21 if ( it.current()->isWireless() ) 22 if ( it.current()->isWireless() )
22 { 23 {
23 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() ); 24 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
24 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() ); 25 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() );
25 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() ); 26 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() ); 27 qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() );
27 28
28 //if ( iface->mode() == OWirelessNetworkInterface::adhoc ) 29 //if ( iface->mode() == OWirelessNetworkInterface::adhoc )
29 //{ 30 //{
30 qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() ); 31 qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP().toString() );
31 //} 32 //}
32 33
33 // nickname 34 // nickname
34 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() ); 35 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
35 iface->setNickName( "MyNickName" ); 36 iface->setNickName( "MyNickName" );
36 if ( iface->nickName() != "MyNickName" ) 37 if ( iface->nickName() != "MyNickName" )
37 qDebug( "DEMO: Warning! Can't change nickname" ); 38 qDebug( "DEMO: Warning! Can't change nickname" );
38 else 39 else
39 qDebug( "DEMO: Nickname change successful." ); 40 qDebug( "DEMO: Nickname change successful." );
40 41
41 // operation mode 42 // operation mode
42 qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() ); 43 qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() );
43 iface->setMode( "adhoc" ); 44 iface->setMode( "adhoc" );
44 if ( iface->mode() != "adhoc" ) 45 if ( iface->mode() != "adhoc" )
45 qDebug( "DEMO: Warning! Can't change operation mode" ); 46 qDebug( "DEMO: Warning! Can't change operation mode" );
46 else 47 else
47 qDebug( "DEMO: Operation Mode change successful." ); 48 qDebug( "DEMO: Operation Mode change successful." );
48 49
49 // RF channel 50 // RF channel
50 qDebug( "DEMO: Current Channel is '%d'", iface->channel() ); 51 qDebug( "DEMO: Current Channel is '%d'", iface->channel() );
51 iface->setChannel( 1 ); 52 iface->setChannel( 1 );
52 if ( iface->channel() != 1 ) 53 if ( iface->channel() != 1 )
53 qDebug( "DEMO: Warning! Can't change RF channel" ); 54 qDebug( "DEMO: Warning! Can't change RF channel" );
54 else 55 else
55 qDebug( "DEMO: RF channel change successful." ); 56 qDebug( "DEMO: RF channel change successful." );
56 57
57 iface->setMode( "managed" ); 58 iface->setMode( "managed" );
58 59
59 // network scan 60 // network scan
60 61
61 int stations = iface->scanNetwork(); 62 OStationList* stations = iface->scanNetwork();
62 if ( stations != -1 ) 63 if ( stations )
63 { 64 {
64 qDebug( "DEMO: # of stations around = %d", stations ); 65 qDebug( "DEMO: # of stations around = %d", stations->count() );
66 OStation* station;
67 for ( station = stations->first(); station != 0; station = stations->next() )
68 {
69 qDebug( "DEMO: station dump following..." );
70 station->dump();
71 }
65 } 72 }
73
66 else 74 else
67 { 75 {
68 qDebug( "DEMO: Warning! Scan didn't work!" ); 76 qDebug( "DEMO: Warning! Scan didn't work!" );
69 } 77 }
70 78
71 /* 79 /*
72 80
73 // first some wrong calls to check if this is working 81 // first some wrong calls to check if this is working
74 iface->setPrivate( "seppel", 10 ); 82 iface->setPrivate( "seppel", 10 );
75 iface->setPrivate( "monitor", 0 ); 83 iface->setPrivate( "monitor", 0 );
76 84
77 // now the real deal 85 // now the real deal
78 iface->setPrivate( "monitor", 2, 2, 3 ); 86 iface->setPrivate( "monitor", 2, 2, 3 );
79 87
80 // trying to set hw address to 12:34:56:AB:CD:EF 88 // trying to set hw address to 12:34:56:AB:CD:EF
81 89
82 /* 90 /*
83 91
84 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" ); 92 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" );
85 iface->setUp( false ); 93 iface->setUp( false );
86 iface->setMacAddress( addr ); 94 iface->setMacAddress( addr );
87 iface->setUp( true ); 95 iface->setUp( true );
88 qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() ); 96 qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() );
89 97
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index ad0e89d..ce147c5 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -13,49 +13,49 @@
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include <opie2/onetutils.h> 32#include <opie2/onetutils.h>
33#include <opie2/onetwork.h> 33#include <opie2/onetwork.h>
34#include <opie2/omanufacturerdb.h> 34#include <opie2/omanufacturerdb.h>
35 35
36#include <net/if.h> 36#include <net/if.h>
37 37#include <cassert>
38#include <cstdio> 38#include <cstdio>
39using namespace std; 39using namespace std;
40 40
41#define IW_PRIV_TYPE_MASK 0x7000 41#define IW_PRIV_TYPE_MASK 0x7000
42#define IW_PRIV_TYPE_NONE 0x0000 42#define IW_PRIV_TYPE_NONE 0x0000
43#define IW_PRIV_TYPE_BYTE 0x1000 43#define IW_PRIV_TYPE_BYTE 0x1000
44#define IW_PRIV_TYPE_CHAR 0x2000 44#define IW_PRIV_TYPE_CHAR 0x2000
45#define IW_PRIV_TYPE_INT 0x4000 45#define IW_PRIV_TYPE_INT 0x4000
46#define IW_PRIV_TYPE_FLOAT 0x5000 46#define IW_PRIV_TYPE_FLOAT 0x5000
47#define IW_PRIV_TYPE_ADDR 0x6000 47#define IW_PRIV_TYPE_ADDR 0x6000
48#define IW_PRIV_SIZE_FIXED 0x0800 48#define IW_PRIV_SIZE_FIXED 0x0800
49#define IW_PRIV_SIZE_MASK 0x07FF 49#define IW_PRIV_SIZE_MASK 0x07FF
50 50
51/*====================================================================================== 51/*======================================================================================
52 * OMacAddress 52 * OMacAddress
53 *======================================================================================*/ 53 *======================================================================================*/
54 54
55// static initializer for broadcast and unknown MAC Adresses 55// static initializer for broadcast and unknown MAC Adresses
56const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 56const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
57const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); 57const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast );
58const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; 58const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 };
59const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); 59const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown );
60 60
61//TODO: Incorporate Ethernet Manufacturer database here! (inline or so) 61//TODO: Incorporate Ethernet Manufacturer database here! (inline or so)
@@ -192,24 +192,52 @@ void OPrivateIOCTL::invoke() const
192 192
193void OPrivateIOCTL::setParameter( int num, u_int32_t value ) 193void OPrivateIOCTL::setParameter( int num, u_int32_t value )
194{ 194{
195 u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; 195 u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name;
196 arglist[num] = value; 196 arglist[num] = value;
197} 197}
198 198
199/*====================================================================================== 199/*======================================================================================
200 * assorted functions 200 * assorted functions
201 *======================================================================================*/ 201 *======================================================================================*/
202 202
203void dumpBytes( const unsigned char* data, int num ) 203void dumpBytes( const unsigned char* data, int num )
204{ 204{
205 printf( "Dumping %d bytes @ %0x", num, data ); 205 printf( "Dumping %d bytes @ %0x", num, data );
206 printf( "-------------------------------------------\n" ); 206 printf( "-------------------------------------------\n" );
207 207
208 for ( int i = 0; i < num; ++i ) 208 for ( int i = 0; i < num; ++i )
209 { 209 {
210 printf( "%02x ", data[i] ); 210 printf( "%02x ", data[i] );
211 if ( !((i+1) % 32) ) printf( "\n" ); 211 if ( !((i+1) % 32) ) printf( "\n" );
212 } 212 }
213 printf( "\n\n" ); 213 printf( "\n\n" );
214} 214}
215 215
216
217int stringToMode( const QString& mode )
218{
219 if ( mode == "auto" ) return IW_MODE_AUTO;
220 else if ( mode == "adhoc" ) return IW_MODE_ADHOC;
221 else if ( mode == "managed" ) return IW_MODE_INFRA;
222 else if ( mode == "master" ) return IW_MODE_MASTER;
223 else if ( mode == "repeater" ) return IW_MODE_REPEAT;
224 else if ( mode == "secondary" ) return IW_MODE_SECOND;
225 else if ( mode == "monitor" ) return IW_MODE_MONITOR;
226 else assert( 0 );
227}
228
229
230QString modeToString( int mode )
231{
232 switch ( mode )
233 {
234 case IW_MODE_AUTO: return "auto";
235 case IW_MODE_ADHOC: return "adhoc";
236 case IW_MODE_INFRA: return "managed";
237 case IW_MODE_MASTER: return "master";
238 case IW_MODE_REPEAT: return "repeater";
239 case IW_MODE_SECOND: return "second";
240 case IW_MODE_MONITOR: return "monitor";
241 default: assert( 0 );
242 }
243}
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h
index 18731ba..541c5ab 100644
--- a/libopie2/opienet/onetutils.h
+++ b/libopie2/opienet/onetutils.h
@@ -63,87 +63,88 @@ class OMacAddress
63 63
64 // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem? 64 // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem?
65 static OMacAddress fromString( const QString& ); 65 static OMacAddress fromString( const QString& );
66 66
67 public: 67 public:
68 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff 68 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff
69 static const OMacAddress& unknown; // 44:44:44:44:44:44 69 static const OMacAddress& unknown; // 44:44:44:44:44:44
70 70
71 private: 71 private:
72 unsigned char _bytes[6]; 72 unsigned char _bytes[6];
73 73
74 friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); 74 friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
75 75
76}; 76};
77 77
78bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); 78bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
79 79
80 80
81/*====================================================================================== 81/*======================================================================================
82 * OHostAddress 82 * OHostAddress
83 *======================================================================================*/ 83 *======================================================================================*/
84 84
85class OHostAddress : public QHostAddress 85class OHostAddress : public QHostAddress
86{ 86{
87 public: 87 /*public:
88 OHostAddress(); 88 OHostAddress();
89 ~OHostAddress(); 89 ~OHostAddress();
90 */
90}; 91};
91 92
92 93
93/*====================================================================================== 94/*======================================================================================
94 * OPrivateIOCTL 95 * OPrivateIOCTL
95 *======================================================================================*/ 96 *======================================================================================*/
96 97
97class OPrivateIOCTL : public QObject 98class OPrivateIOCTL : public QObject
98{ 99{
99 public: 100 public:
100 OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ); 101 OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs );
101 ~OPrivateIOCTL(); 102 ~OPrivateIOCTL();
102 103
103 int numberGetArgs() const; 104 int numberGetArgs() const;
104 int typeGetArgs() const; 105 int typeGetArgs() const;
105 int numberSetArgs() const; 106 int numberSetArgs() const;
106 int typeSetArgs() const; 107 int typeSetArgs() const;
107 108
108 // FIXME return int? as ::ioctl does? -zecke 109 // FIXME return int? as ::ioctl does? -zecke
109 void invoke() const; 110 void invoke() const;
110 void setParameter( int, u_int32_t ); 111 void setParameter( int, u_int32_t );
111 112
112 private: 113 private:
113 u_int32_t _ioctl; 114 u_int32_t _ioctl;
114 u_int16_t _getargs; 115 u_int16_t _getargs;
115 u_int16_t _setargs; 116 u_int16_t _setargs;
116 117
117}; 118};
118 119
119 /*====================================================================================== 120 /*======================================================================================
120 * Miscellaneous 121 * Miscellaneous
121 *======================================================================================*/ 122 *======================================================================================*/
122 123
123/* dump bytes */
124
125void dumpBytes( const unsigned char* data, int num ); 124void dumpBytes( const unsigned char* data, int num );
125QString modeToString( int );
126int stringToMode( const QString& );
126 127
127/* Network to host order macros */ 128/* Network to host order macros */
128 129
129#ifdef LBL_ALIGN 130#ifdef LBL_ALIGN
130#define EXTRACT_16BITS(p) \ 131#define EXTRACT_16BITS(p) \
131 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ 132 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \
132 (u_int16_t)*((const u_int8_t *)(p) + 1))) 133 (u_int16_t)*((const u_int8_t *)(p) + 1)))
133#define EXTRACT_32BITS(p) \ 134#define EXTRACT_32BITS(p) \
134 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ 135 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \
135 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ 136 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \
136 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ 137 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \
137 (u_int32_t)*((const u_int8_t *)(p) + 3))) 138 (u_int32_t)*((const u_int8_t *)(p) + 3)))
138#else 139#else
139#define EXTRACT_16BITS(p) \ 140#define EXTRACT_16BITS(p) \
140 ((u_int16_t)ntohs(*(const u_int16_t *)(p))) 141 ((u_int16_t)ntohs(*(const u_int16_t *)(p)))
141#define EXTRACT_32BITS(p) \ 142#define EXTRACT_32BITS(p) \
142 ((u_int32_t)ntohl(*(const u_int32_t *)(p))) 143 ((u_int32_t)ntohl(*(const u_int32_t *)(p)))
143#endif 144#endif
144 145
145#define EXTRACT_24BITS(p) \ 146#define EXTRACT_24BITS(p) \
146 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ 147 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \
147 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ 148 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
148 (u_int32_t)*((const u_int8_t *)(p) + 2))) 149 (u_int32_t)*((const u_int8_t *)(p) + 2)))
149 150
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index a85a510..50c6679 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -235,48 +235,49 @@ bool ONetworkInterface::isUp() const
235 return _ifr.ifr_flags & IFF_UP; 235 return _ifr.ifr_flags & IFF_UP;
236} 236}
237 237
238 238
239void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) 239void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
240{ 240{
241 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 241 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
242 sa->sin_family = AF_INET; 242 sa->sin_family = AF_INET;
243 sa->sin_port = 0; 243 sa->sin_port = 0;
244 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 244 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
245 ioctl( SIOCSIFADDR ); 245 ioctl( SIOCSIFADDR );
246} 246}
247 247
248 248
249QString ONetworkInterface::ipV4Address() const 249QString ONetworkInterface::ipV4Address() const
250{ 250{
251 if ( ioctl( SIOCGIFADDR ) ) 251 if ( ioctl( SIOCGIFADDR ) )
252 { 252 {
253 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; 253 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
254 //FIXME: Use QHostAddress here 254 //FIXME: Use QHostAddress here
255 return QString( inet_ntoa( sa->sin_addr ) ); 255 return QString( inet_ntoa( sa->sin_addr ) );
256 } 256 }
257 else 257 else
258 return "<unknown>"; 258 return "<unknown>";
259
259} 260}
260 261
261 262
262void ONetworkInterface::setMacAddress( const OMacAddress& addr ) 263void ONetworkInterface::setMacAddress( const OMacAddress& addr )
263{ 264{
264 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 265 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
265 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); 266 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
266 ioctl( SIOCSIFHWADDR ); 267 ioctl( SIOCSIFHWADDR );
267} 268}
268 269
269 270
270OMacAddress ONetworkInterface::macAddress() const 271OMacAddress ONetworkInterface::macAddress() const
271{ 272{
272 if ( ioctl( SIOCGIFHWADDR ) ) 273 if ( ioctl( SIOCGIFHWADDR ) )
273 { 274 {
274 return OMacAddress( _ifr ); 275 return OMacAddress( _ifr );
275 } 276 }
276 else 277 else
277 { 278 {
278 return OMacAddress::unknown; 279 return OMacAddress::unknown;
279 } 280 }
280} 281}
281 282
282 283
@@ -453,72 +454,58 @@ OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const cha
453OWirelessNetworkInterface::~OWirelessNetworkInterface() 454OWirelessNetworkInterface::~OWirelessNetworkInterface()
454{ 455{
455} 456}
456 457
457 458
458struct iwreq& OWirelessNetworkInterface::iwr() const 459struct iwreq& OWirelessNetworkInterface::iwr() const
459{ 460{
460 return _iwr; 461 return _iwr;
461} 462}
462 463
463 464
464void OWirelessNetworkInterface::init() 465void OWirelessNetworkInterface::init()
465{ 466{
466 qDebug( "OWirelessNetworkInterface::init()" ); 467 qDebug( "OWirelessNetworkInterface::init()" );
467 memset( &_iwr, 0, sizeof( struct iwreq ) ); 468 memset( &_iwr, 0, sizeof( struct iwreq ) );
468 buildInformation(); 469 buildInformation();
469 buildPrivateList(); 470 buildPrivateList();
470 dumpInformation(); 471 dumpInformation();
471} 472}
472 473
473 474
474bool OWirelessNetworkInterface::isAssociated() const 475bool OWirelessNetworkInterface::isAssociated() const
475{ 476{
476 //FIXME: handle different modes 477 //FIXME: handle different modes
477 return associatedAP() != "44:44:44:44:44:44"; 478 return !(associatedAP() == OMacAddress::unknown);
478} 479}
479 480
480 481
481QString OWirelessNetworkInterface::associatedAP() const 482OMacAddress OWirelessNetworkInterface::associatedAP() const
482{ 483{
483 //FIXME: use OMacAddress
484 QString mac;
485
486 if ( ioctl( SIOCGIWAP ) ) 484 if ( ioctl( SIOCGIWAP ) )
487 { 485 return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0];
488 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
489 _ifr.ifr_hwaddr.sa_data[0]&0xff,
490 _ifr.ifr_hwaddr.sa_data[1]&0xff,
491 _ifr.ifr_hwaddr.sa_data[2]&0xff,
492 _ifr.ifr_hwaddr.sa_data[3]&0xff,
493 _ifr.ifr_hwaddr.sa_data[4]&0xff,
494 _ifr.ifr_hwaddr.sa_data[5]&0xff );
495 }
496 else 486 else
497 { 487 return OMacAddress::unknown;
498 mac = "<Unknown>";
499 }
500 return mac;
501} 488}
502 489
503 490
504void OWirelessNetworkInterface::buildInformation() 491void OWirelessNetworkInterface::buildInformation()
505{ 492{
506 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 493 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
507 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 494 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
508 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 495 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
509 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 496 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
510 //ML: _too much_ space. This is damn shitty crap *sigh* 497 //ML: _too much_ space. This is damn shitty crap *sigh*
511 //ML: We allocate a large memory region in RAM and check whether the 498 //ML: We allocate a large memory region in RAM and check whether the
512 //ML: driver pollutes this extra space. The complaint will be made on stdout, 499 //ML: driver pollutes this extra space. The complaint will be made on stdout,
513 //ML: so please forward this... 500 //ML: so please forward this...
514 501
515 struct iwreq wrq; 502 struct iwreq wrq;
516 int len = sizeof( struct iw_range )*2; 503 int len = sizeof( struct iw_range )*2;
517 char *buffer = (char*) malloc( len ); 504 char *buffer = (char*) malloc( len );
518 //FIXME: Validate if we actually got the memory block 505 //FIXME: Validate if we actually got the memory block
519 memset( buffer, 0, len ); 506 memset( buffer, 0, len );
520 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 507 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
521 wrq.u.data.pointer = (caddr_t) buffer; 508 wrq.u.data.pointer = (caddr_t) buffer;
522 wrq.u.data.length = sizeof( struct iw_range ); 509 wrq.u.data.length = sizeof( struct iw_range );
523 wrq.u.data.flags = 0; 510 wrq.u.data.flags = 0;
524 511
@@ -667,81 +654,60 @@ int OWirelessNetworkInterface::channels() const
667 654
668void OWirelessNetworkInterface::setChannelHopping( int interval ) 655void OWirelessNetworkInterface::setChannelHopping( int interval )
669{ 656{
670 if ( !_hopper ) _hopper = new OChannelHopper( this ); 657 if ( !_hopper ) _hopper = new OChannelHopper( this );
671 _hopper->setInterval( interval ); 658 _hopper->setInterval( interval );
672 //FIXME: When and by whom will the channel hopper be deleted? 659 //FIXME: When and by whom will the channel hopper be deleted?
673 //TODO: rely on QObject hierarchy 660 //TODO: rely on QObject hierarchy
674} 661}
675 662
676 663
677int OWirelessNetworkInterface::channelHopping() const 664int OWirelessNetworkInterface::channelHopping() const
678{ 665{
679 return _hopper->interval(); 666 return _hopper->interval();
680} 667}
681 668
682 669
683OChannelHopper* OWirelessNetworkInterface::channelHopper() const 670OChannelHopper* OWirelessNetworkInterface::channelHopper() const
684{ 671{
685 return _hopper; 672 return _hopper;
686} 673}
687 674
688 675
689void OWirelessNetworkInterface::setMode( const QString& mode ) 676void OWirelessNetworkInterface::setMode( const QString& mode )
690{ 677{
691 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; 678 _iwr.u.mode = stringToMode( mode );
692 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC;
693 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA;
694 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER;
695 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT;
696 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND;
697 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
698 else
699 {
700 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
701 return;
702 }
703 wioctl( SIOCSIWMODE ); 679 wioctl( SIOCSIWMODE );
704} 680}
705 681
706 682
707QString OWirelessNetworkInterface::mode() const 683QString OWirelessNetworkInterface::mode() const
708{ 684{
709 if ( !wioctl( SIOCGIWMODE ) ) 685 if ( !wioctl( SIOCGIWMODE ) )
710 { 686 {
711 return "<unknown>"; 687 return "<unknown>";
712 } 688 }
713 switch ( _iwr.u.mode ) 689 return modeToString( _iwr.u.mode );
714 {
715 case IW_MODE_AUTO: return "auto";
716 case IW_MODE_ADHOC: return "adhoc";
717 case IW_MODE_INFRA: return "managed";
718 case IW_MODE_MASTER: return "master";
719 case IW_MODE_REPEAT: return "repeater";
720 case IW_MODE_SECOND: return "secondary";
721 case IW_MODE_MONITOR: return "monitor";
722 default: assert( 0 ); // shouldn't happen
723 }
724} 690}
725 691
726 692
727void OWirelessNetworkInterface::setMonitorMode( bool b ) 693void OWirelessNetworkInterface::setMonitorMode( bool b )
728{ 694{
729 if ( _mon ) 695 if ( _mon )
730 _mon->setEnabled( b ); 696 _mon->setEnabled( b );
731 else 697 else
732 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 698 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
733} 699}
734 700
735 701
736bool OWirelessNetworkInterface::monitorMode() const 702bool OWirelessNetworkInterface::monitorMode() const
737{ 703{
738 qDebug( "dataLinkType = %d", dataLinkType() ); 704 qDebug( "dataLinkType = %d", dataLinkType() );
739 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); 705 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
740 //FIXME: 802 is the header type for PRISM - Linux support for this is pending... 706 //FIXME: 802 is the header type for PRISM - Linux support for this is pending...
741 //FIXME: What is 119, by the way? 707 //FIXME: What is 119, by the way?
742} 708}
743 709
744 710
745void OWirelessNetworkInterface::setNickName( const QString& nickname ) 711void OWirelessNetworkInterface::setNickName( const QString& nickname )
746{ 712{
747 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); 713 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
@@ -809,147 +775,170 @@ bool OWirelessNetworkInterface::hasPrivate( const QString& call )
809QString OWirelessNetworkInterface::SSID() const 775QString OWirelessNetworkInterface::SSID() const
810{ 776{
811 char str[IW_ESSID_MAX_SIZE]; 777 char str[IW_ESSID_MAX_SIZE];
812 _iwr.u.essid.pointer = &str[0]; 778 _iwr.u.essid.pointer = &str[0];
813 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 779 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
814 if ( !wioctl( SIOCGIWESSID ) ) 780 if ( !wioctl( SIOCGIWESSID ) )
815 { 781 {
816 return "<unknown>"; 782 return "<unknown>";
817 } 783 }
818 else 784 else
819 { 785 {
820 return str; 786 return str;
821 } 787 }
822} 788}
823 789
824 790
825void OWirelessNetworkInterface::setSSID( const QString& ssid ) 791void OWirelessNetworkInterface::setSSID( const QString& ssid )
826{ 792{
827 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 793 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
828 _iwr.u.essid.length = ssid.length(); 794 _iwr.u.essid.length = ssid.length();
829 wioctl( SIOCSIWESSID ); 795 wioctl( SIOCSIWESSID );
830} 796}
831 797
832 798
833int OWirelessNetworkInterface::scanNetwork() 799OStationList* OWirelessNetworkInterface::scanNetwork()
834{ 800{
835 _iwr.u.param.flags = IW_SCAN_DEFAULT; 801 _iwr.u.param.flags = IW_SCAN_DEFAULT;
836 _iwr.u.param.value = 0; 802 _iwr.u.param.value = 0;
837 if ( !wioctl( SIOCSIWSCAN ) ) 803 if ( !wioctl( SIOCSIWSCAN ) )
838 { 804 {
839 return -1; 805 return 0;
840 } 806 }
841 807
808 OStationList* stations = new OStationList();
809
842 int timeout = 1000000; 810 int timeout = 1000000;
843 811
844 qDebug( "ONetworkInterface::scanNetwork() - scan started." ); 812 qDebug( "ONetworkInterface::scanNetwork() - scan started." );
845 813
846 bool results = false; 814 bool results = false;
847 struct timeval tv; 815 struct timeval tv;
848 tv.tv_sec = 0; 816 tv.tv_sec = 0;
849 tv.tv_usec = 250000; // initial timeout ~ 250ms 817 tv.tv_usec = 250000; // initial timeout ~ 250ms
850 char buffer[IW_SCAN_MAX_DATA]; 818 char buffer[IW_SCAN_MAX_DATA];
851 819
852 while ( !results && timeout > 0 ) 820 while ( !results && timeout > 0 )
853 { 821 {
854 timeout -= tv.tv_usec; 822 timeout -= tv.tv_usec;
855 select( 0, 0, 0, 0, &tv ); 823 select( 0, 0, 0, 0, &tv );
856 824
857 _iwr.u.data.pointer = &buffer[0]; 825 _iwr.u.data.pointer = &buffer[0];
858 _iwr.u.data.flags = 0; 826 _iwr.u.data.flags = 0;
859 _iwr.u.data.length = sizeof buffer; 827 _iwr.u.data.length = sizeof buffer;
860 if ( wioctl( SIOCGIWSCAN ) ) 828 if ( wioctl( SIOCGIWSCAN ) )
861 { 829 {
862 results = true; 830 results = true;
863 continue; 831 continue;
864 } 832 }
865 else if ( errno == EAGAIN) 833 else if ( errno == EAGAIN)
866 { 834 {
867 qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." ); 835 qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." );
868 #if 0 836 #if 0
869 if ( qApp ) 837 if ( qApp )
870 { 838 {
871 qApp->processEvents( 100 ); 839 qApp->processEvents( 100 );
872 continue; 840 continue;
873 } 841 }
874 #endif 842 #endif
875 tv.tv_sec = 0; 843 tv.tv_sec = 0;
876 tv.tv_usec = 100000; 844 tv.tv_usec = 100000;
877 continue; 845 continue;
878 } 846 }
879 } 847 }
880 848
881 qDebug( "ONetworkInterface::scanNetwork() - scan finished." ); 849 qDebug( "ONetworkInterface::scanNetwork() - scan finished." );
882 850
883 if ( results ) 851 if ( results )
884 { 852 {
885 qDebug( " - result length = %d", _iwr.u.data.length ); 853 qDebug( " - result length = %d", _iwr.u.data.length );
886 if ( !_iwr.u.data.length ) 854 if ( !_iwr.u.data.length )
887 { 855 {
888 qDebug( " - no results (empty neighbourhood)" ); 856 qDebug( " - no results (empty neighbourhood)" );
889 return 0; 857 return stations;
890 } 858 }
891 859
892 qDebug( " - results are in!" ); 860 qDebug( " - results are in!" );
893 dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); 861 dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length );
894 862
895 int stations = 0;
896
897 // parse results 863 // parse results
898 864
899 int offset = 0; 865 int offset = 0;
900 struct iw_event* we = (struct iw_event*) &buffer[0]; 866 struct iw_event* we = (struct iw_event*) &buffer[0];
901 867
902 while ( offset < _iwr.u.data.length ) 868 while ( offset < _iwr.u.data.length )
903 { 869 {
904 //const char* cmd = *(*_ioctlmap)[we->cmd]; 870 //const char* cmd = *(*_ioctlmap)[we->cmd];
905 //if ( !cmd ) cmd = "<unknown>"; 871 //if ( !cmd ) cmd = "<unknown>";
906 qDebug( "reading next event... cmd=%d, len=%d", we->cmd, we->len ); 872 qDebug( "reading next event... cmd=%d, len=%d", we->cmd, we->len );
907 switch (we->cmd) 873 switch (we->cmd)
908 { 874 {
909 case SIOCGIWAP: qDebug( "SIOCGIWAP" ); stations++; break; 875 case SIOCGIWAP:
910 case SIOCGIWMODE: qDebug( "SIOCGIWMODE" ); break; 876 {
911 case SIOCGIWFREQ: qDebug( "SIOCGIWFREQ" ); break; 877 qDebug( "SIOCGIWAP" );
912 case SIOCGIWESSID: qDebug( "SIOCGIWESSID" ); break; 878 stations->append( new OStation() );
879 stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0];
880 break;
881 }
882 case SIOCGIWMODE:
883 {
884 qDebug( "SIOCGIWMODE" );
885 stations->last()->type = modeToString( we->u.mode );
886 break;
887 }
888 case SIOCGIWFREQ:
889 {
890 qDebug( "SIOCGIWFREQ" );
891 stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ];
892 break;
893 }
894 case SIOCGIWESSID:
895 {
896 qDebug( "SIOCGIWESSID" );
897 stations->last()->ssid = we->u.essid.pointer;
898 break;
899 }
913 case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break; 900 case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break;
914 case SIOCGIWENCODE: qDebug( "SIOCGIWENCODE" ); break; 901 case SIOCGIWENCODE: qDebug( "SIOCGIWENCODE" ); break;
915 case IWEVTXDROP: qDebug( "IWEVTXDROP" ); break; /* Packet dropped to excessive retry */ 902 case IWEVTXDROP: qDebug( "IWEVTXDROP" ); break; /* Packet dropped to excessive retry */
916 case IWEVQUAL: qDebug( "IWEVQUAL" ); break; /* Quality part of statistics (scan) */ 903 case IWEVQUAL: qDebug( "IWEVQUAL" ); break; /* Quality part of statistics (scan) */
917 case IWEVCUSTOM: qDebug( "IWEVCUSTOM" ); break; /* Driver specific ascii string */ 904 case IWEVCUSTOM: qDebug( "IWEVCUSTOM" ); break; /* Driver specific ascii string */
918 case IWEVREGISTERED: qDebug( "IWEVREGISTERED" ); break; /* Discovered a new node (AP mode) */ 905 case IWEVREGISTERED: qDebug( "IWEVREGISTERED" ); break; /* Discovered a new node (AP mode) */
919 case IWEVEXPIRED: qDebug( "IWEVEXPIRED" ); break; /* Expired a node (AP mode) */ 906 case IWEVEXPIRED: qDebug( "IWEVEXPIRED" ); break; /* Expired a node (AP mode) */
920 default: qDebug( "unhandled event" ); 907 default: qDebug( "unhandled event" );
921 } 908 }
922 909
923 offset += we->len; 910 offset += we->len;
924 we = (struct iw_event*) &buffer[offset]; 911 we = (struct iw_event*) &buffer[offset];
925 } 912 }
926 913
914 return stations;
915
927 } 916 }
928 else 917 else
929 { 918 {
930 qDebug( " - no results (timeout) :(" ); 919 qDebug( " - no results (timeout) :(" );
931 return 0; 920 return stations;
932 } 921 }
933} 922}
934 923
935 924
936bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 925bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
937{ 926{
938 #ifndef NODEBUG 927 #ifndef NODEBUG
939 int result = ::ioctl( _sfd, call, &iwreq ); 928 int result = ::ioctl( _sfd, call, &iwreq );
940 if ( result == -1 ) 929 if ( result == -1 )
941 qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) *(*_ioctlmap)[call], call, result, strerror( errno ) ); 930 qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) *(*_ioctlmap)[call], call, result, strerror( errno ) );
942 else 931 else
943 qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) *(*_ioctlmap)[call], call ); 932 qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) *(*_ioctlmap)[call], call );
944 return ( result != -1 ); 933 return ( result != -1 );
945 #else 934 #else
946 return ::ioctl( _sfd, call, &iwreq ) != -1; 935 return ::ioctl( _sfd, call, &iwreq ) != -1;
947 #endif 936 #endif
948} 937}
949 938
950 939
951bool OWirelessNetworkInterface::wioctl( int call ) const 940bool OWirelessNetworkInterface::wioctl( int call ) const
952{ 941{
953 strcpy( _iwr.ifr_name, name() ); 942 strcpy( _iwr.ifr_name, name() );
954 return wioctl( call, _iwr ); 943 return wioctl( call, _iwr );
955} 944}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index e1545dd..0eb4542 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -18,48 +18,49 @@
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#include <opie2/ostation.h>
42 43
43/* QT */ 44/* QT */
44 45
45#include <qvaluelist.h> 46#include <qvaluelist.h>
46#include <qdict.h> 47#include <qdict.h>
47#include <qmap.h> 48#include <qmap.h>
48#include <qobject.h> 49#include <qobject.h>
49#include <qhostaddress.h> 50#include <qhostaddress.h>
50 51
51class ONetworkInterface; 52class ONetworkInterface;
52class OWirelessNetworkInterface; 53class OWirelessNetworkInterface;
53class OChannelHopper; 54class OChannelHopper;
54class OMonitoringInterface; 55class OMonitoringInterface;
55 56
56/*====================================================================================== 57/*======================================================================================
57 * ONetwork 58 * ONetwork
58 *======================================================================================*/ 59 *======================================================================================*/
59 60
60/** 61/**
61 * @brief A container class for all network interfaces 62 * @brief A container class for all network interfaces
62 * 63 *
63 * This class provides access to all available network interfaces of your computer. 64 * This class provides access to all available network interfaces of your computer.
64 * 65 *
65 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 66 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
@@ -385,63 +386,63 @@ class OWirelessNetworkInterface : public ONetworkInterface
385 virtual void setNickName( const QString& nickname ); 386 virtual void setNickName( const QString& nickname );
386 /** 387 /**
387 * @returns the current station nickname. 388 * @returns the current station nickname.
388 */ 389 */
389 virtual QString nickName() const; 390 virtual QString nickName() const;
390 /** 391 /**
391 * Invoke the private IOCTL @a command with a @number of parameters on the network interface. 392 * Invoke the private IOCTL @a command with a @number of parameters on the network interface.
392 * @see OPrivateIOCTL 393 * @see OPrivateIOCTL
393 */ 394 */
394 virtual void setPrivate( const QString& command, int number, ... ); 395 virtual void setPrivate( const QString& command, int number, ... );
395 /** 396 /**
396 * @returns true if the interface is featuring the private IOCTL @command. 397 * @returns true if the interface is featuring the private IOCTL @command.
397 */ 398 */
398 virtual bool hasPrivate( const QString& command ); 399 virtual bool hasPrivate( const QString& command );
399 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this 400 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this
400 /** 401 /**
401 * @returns true if the interface is associated to an access point 402 * @returns true if the interface is associated to an access point
402 * @note: This information is only valid if the interface is in managed mode. 403 * @note: This information is only valid if the interface is in managed mode.
403 */ 404 */
404 virtual bool isAssociated() const; 405 virtual bool isAssociated() const;
405 /** 406 /**
406 * @returns the MAC address of the Access Point if the device is in infrastructure mode. 407 * @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. 408 * @returns a (more or less random) cell ID address if the device is in adhoc mode.
408 */ 409 */
409 virtual QString associatedAP() const; 410 virtual OMacAddress associatedAP() const;
410 /** 411 /**
411 * Set the @a ssid (Service Set ID) string. This is used to decide 412 * Set the @a ssid (Service Set ID) string. This is used to decide
412 * which network to associate with (use "any" to let the driver decide). 413 * which network to associate with (use "any" to let the driver decide).
413 */ 414 */
414 virtual void setSSID( const QString& ssid ); 415 virtual void setSSID( const QString& ssid );
415 /** 416 /**
416 * @returns the current SSID (Service Set ID). 417 * @returns the current SSID (Service Set ID).
417 */ 418 */
418 virtual QString SSID() const; 419 virtual QString SSID() const;
419 /** 420 /**
420 * Perform scanning the wireless network neighbourhood. 421 * Perform scanning the wireless network neighbourhood.
421 * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! 422 * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE!
422 */ 423 */
423 virtual int scanNetwork(); 424 virtual OStationList* scanNetwork();
424 425
425 protected: 426 protected:
426 void buildInformation(); 427 void buildInformation();
427 void buildPrivateList(); 428 void buildPrivateList();
428 void dumpInformation() const; 429 void dumpInformation() const;
429 virtual void init(); 430 virtual void init();
430 struct iwreq& iwr() const; 431 struct iwreq& iwr() const;
431 bool wioctl( int call ) const; 432 bool wioctl( int call ) const;
432 bool wioctl( int call, struct iwreq& ) const; 433 bool wioctl( int call, struct iwreq& ) const;
433 434
434 protected: 435 protected:
435 mutable struct iwreq _iwr; 436 mutable struct iwreq _iwr;
436 QMap<int,int> _channels; 437 QMap<int,int> _channels;
437 struct iw_range _range; 438 struct iw_range _range;
438 439
439 private: 440 private:
440 OChannelHopper* _hopper; 441 OChannelHopper* _hopper;
441}; 442};
442 443
443 444
444/*====================================================================================== 445/*======================================================================================
445 * OMonitoringInterface 446 * OMonitoringInterface
446 *======================================================================================*/ 447 *======================================================================================*/
447 448
diff --git a/libopie2/opienet/ostation.cpp b/libopie2/opienet/ostation.cpp
index 3817b31..ba1e4f6 100644
--- a/libopie2/opienet/ostation.cpp
+++ b/libopie2/opienet/ostation.cpp
@@ -17,33 +17,48 @@
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include <opie2/ostation.h> 32#include <opie2/ostation.h>
33 33
34/*====================================================================================== 34/*======================================================================================
35 * OStation 35 * OStation
36 *======================================================================================*/ 36 *======================================================================================*/
37 37
38OStation::OStation() 38OStation::OStation()
39{ 39{
40 qDebug( "OStation::OStation()" ); 40 qDebug( "OStation::OStation()" );
41
42 type = "<unknown>";
43 macAddress = OMacAddress::unknown;
44 ssid = "<unknown>";
45 channel = 0;
46 apAddress = OMacAddress::unknown;
47
41} 48}
42 49
43 50
44OStation::~OStation() 51OStation::~OStation()
45{ 52{
46 qDebug( "OStation::~OStation()" ); 53 qDebug( "OStation::~OStation()" );
47} 54}
48 55
49 56
57void OStation::dump()
58{
59 qDebug( "------- OStation::dump() ------------" );
60 qDebug( "type: %s", (const char*) type );
61 qDebug( "mac: %s", (const char*) macAddress.toString() );
62 qDebug( "ap: %s", (const char*) apAddress.toString() );
63 qDebug( "ip: %s", (const char*) ipAddress.toString() );
64}
diff --git a/libopie2/opienet/ostation.h b/libopie2/opienet/ostation.h
index f61570b..a6956c9 100644
--- a/libopie2/opienet/ostation.h
+++ b/libopie2/opienet/ostation.h
@@ -13,55 +13,62 @@
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef OSTATION_H 32#ifndef OSTATION_H
33#define OSTATION_H 33#define OSTATION_H
34 34
35#include <opie2/onetutils.h> 35#include <opie2/onetutils.h>
36 36
37#include <qdict.h> 37#include <qlist.h>
38#include <qmap.h>
39#include <qstring.h> 38#include <qstring.h>
40#include <qhostaddress.h> 39#include <qhostaddress.h>
41#include <qobject.h> 40#include <qobject.h>
42 41
43#include <sys/types.h> 42#include <sys/types.h>
44 43
45class OStation; 44class OStation;
46 45
47typedef QDict<OStation> OStationDict; 46typedef QList<OStation> OStationList;
48 47
49/*====================================================================================== 48/*======================================================================================
50 * OStation 49 * OStation
51 *======================================================================================*/ 50 *======================================================================================*/
52 51
53class OStation 52class OStation
54{ 53{
55 public: 54 public:
56 OStation(); 55 OStation();
57 ~OStation(); 56 ~OStation();
58 57
59 private: 58 void dump();
59
60 /* Ethernet */
61 QString type;
60 OMacAddress macAddress; 62 OMacAddress macAddress;
61 QHostAddress ipAddress; 63 QHostAddress ipAddress;
64
65 /* WaveLan */
62 QString ssid; 66 QString ssid;
63 QString type; 67 OMacAddress apAddress;
68 int channel;
69 bool encrypted;
64}; 70};
65 71
72
66#endif // OSTATION_H 73#endif // OSTATION_H
67 74