summaryrefslogtreecommitdiff
path: root/libopie2/opienet
authormickeyl <mickeyl>2005-05-06 09:27:12 (UTC)
committer mickeyl <mickeyl>2005-05-06 09:27:12 (UTC)
commit543d9d7c58c9601dba6f47b3a4011313d1d75499 (patch) (unidiff)
tree6b9d259a91b220264c961d542e25b69fe070320f /libopie2/opienet
parentc199fa0b0ef971c3a121af6c31a9a9822561a1be (diff)
downloadopie-543d9d7c58c9601dba6f47b3a4011313d1d75499.zip
opie-543d9d7c58c9601dba6f47b3a4011313d1d75499.tar.gz
opie-543d9d7c58c9601dba6f47b3a4011313d1d75499.tar.bz2
- OManufacturerDB: check if there is a QApplication before calling Global::statusMessage or qApp->processEvents()
- ONetwork: skip hostap control interfaces 'wifi*' - OWirelessNetworkInterface: set \0 in SSID() and nickName() to work around (buggy) drivers not returning a zero-terminated string
Diffstat (limited to 'libopie2/opienet') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/omanufacturerdb.cpp17
-rw-r--r--libopie2/opienet/onetwork.cpp9
-rw-r--r--libopie2/opienet/opienet.pro2
3 files changed, 13 insertions, 15 deletions
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp
index 123aee8..3af3d4c 100644
--- a/libopie2/opienet/omanufacturerdb.cpp
+++ b/libopie2/opienet/omanufacturerdb.cpp
@@ -1,143 +1,134 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. 4 .=l.
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; version 2 of the License. 10 - .   .-<_>     .<> Foundation; version 2 of the License.
11     ._= =}       : 11     ._= =}       :
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20 :     =  ...= . :.=- 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27*/ 27*/
28 28
29#include "omanufacturerdb.h" 29#include "omanufacturerdb.h"
30 30
31#define OPIE_IMPROVE_GUI_LATENCY 1
32
33/* OPIE */ 31/* OPIE */
34#include <opie2/odebug.h> 32#include <opie2/odebug.h>
35#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
36#ifdef OPIE_IMPROVE_GUI_LATENCY 34#ifdef OPIE_IMPROVE_GUI_LATENCY
37#include <qpe/global.h> 35#include <qpe/global.h>
38#endif 36#endif
39 37
40 38
41 39
42/* QT */ 40/* QT */
43#include <qapplication.h> 41#include <qapplication.h>
44#include <qfile.h> 42#include <qfile.h>
45#include <qtextstream.h> 43#include <qtextstream.h>
46 44
47using namespace Opie::Core; 45using namespace Opie::Core;
48namespace Opie { 46namespace Opie {
49namespace Net { 47namespace Net {
50 48
51OManufacturerDB* OManufacturerDB::_instance = 0; 49OManufacturerDB* OManufacturerDB::_instance = 0;
52 50
53OManufacturerDB* OManufacturerDB::instance() 51OManufacturerDB* OManufacturerDB::instance()
54{ 52{
55 if ( !OManufacturerDB::_instance ) 53 if ( !OManufacturerDB::_instance )
56 { 54 {
57 odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl; 55 odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl;
58 _instance = new OManufacturerDB(); 56 _instance = new OManufacturerDB();
59 } 57 }
60 return _instance; 58 return _instance;
61} 59}
62 60
63 61
64OManufacturerDB::OManufacturerDB() 62OManufacturerDB::OManufacturerDB()
65{ 63{
66 #ifdef OPIE_IMPROVE_GUI_LATENCY 64 if ( qApp ) Global::statusMessage( "Reading Manufacturers..." );
67 Global::statusMessage( "Reading Manufacturers..." );
68 #endif
69 QString filename( "/etc/manufacturers" ); 65 QString filename( "/etc/manufacturers" );
70 odebug << "OManufacturerDB: trying to read " << filename << oendl; 66 odebug << "OManufacturerDB: trying to read " << filename << oendl;
71 if ( !QFile::exists( filename ) ) 67 if ( !QFile::exists( filename ) )
72 { 68 {
73 filename = QPEApplication::qpeDir()+"etc/manufacturers"; 69 filename = QPEApplication::qpeDir()+"etc/manufacturers";
74 odebug << "OManufacturerDB: trying to read " << filename << oendl; 70 odebug << "OManufacturerDB: trying to read " << filename << oendl;
75 if ( !QFile::exists( filename ) ) 71 if ( !QFile::exists( filename ) )
76 { 72 {
77 filename = "/usr/share/wellenreiter/manufacturers"; 73 filename = "/usr/share/wellenreiter/manufacturers";
78 odebug << "OManufacturerDB: trying to read " << filename << oendl; 74 odebug << "OManufacturerDB: trying to read " << filename << oendl;
79 } 75 }
80 } 76 }
81 77
82 QFile file( filename ); 78 QFile file( filename );
83 bool hasFile = file.open( IO_ReadOnly ); 79 bool hasFile = file.open( IO_ReadOnly );
84 if (!hasFile) 80 if (!hasFile)
85 { 81 {
86 owarn << "OManufacturerDB: no valid manufacturer list found." << oendl; 82 owarn << "OManufacturerDB: no valid manufacturer list found." << oendl;
87 } 83 }
88 else 84 else
89 { 85 {
90 odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl; 86 odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl;
91 QTextStream s( &file ); 87 QTextStream s( &file );
92 QString addr; 88 QString addr;
93 QString manu; 89 QString manu;
94 QString extManu; 90 QString extManu;
95 #ifdef OPIE_IMPROVE_GUI_LATENCY
96 int counter = 0; 91 int counter = 0;
97 #endif 92
98 while (!s.atEnd()) 93 while (!s.atEnd())
99 { 94 {
100 s >> addr; 95 s >> addr;
101 s >> manu; 96 s >> manu;
102 s >> extManu; 97 s >> extManu;
103 98
104 manufacturers.insert( addr, manu ); 99 manufacturers.insert( addr, manu );
105 manufacturersExt.insert( addr, extManu ); 100 manufacturersExt.insert( addr, extManu );
106 // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl; 101 // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl;
107 #ifdef OPIE_IMPROVE_GUI_LATENCY
108 counter++; 102 counter++;
109 if ( counter == 50 ) 103 if ( counter == 50 )
110 { 104 {
111 qApp->processEvents(); 105 if ( qApp ) qApp->processEvents();
112 counter = 0; 106 counter = 0;
113 } 107 }
114 #endif
115 } 108 }
116 odebug << "OManufacturerDB: manufacturer list completed." << oendl; 109 odebug << "OManufacturerDB: manufacturer list completed." << oendl;
117 #ifdef OPIE_IMPROVE_GUI_LATENCY 110 if ( qApp ) Global::statusMessage( "Manufacturers Complete..." );
118 Global::statusMessage( "Manufacturers Complete..." );
119 #endif
120 } 111 }
121} 112}
122 113
123 114
124OManufacturerDB::~OManufacturerDB() 115OManufacturerDB::~OManufacturerDB()
125{ 116{
126} 117}
127 118
128 119
129const QString& OManufacturerDB::lookup( const QString& macaddr ) const 120const QString& OManufacturerDB::lookup( const QString& macaddr ) const
130{ 121{
131 return manufacturers[macaddr.upper().left(8)]; 122 return manufacturers[macaddr.upper().left(8)];
132} 123}
133 124
134 125
135const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const 126const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const
136{ 127{
137 QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); 128 QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) );
138 return it == manufacturersExt.end() ? lookup( macaddr ) : *it; 129 return it == manufacturersExt.end() ? lookup( macaddr ) : *it;
139} 130}
140 131
141} 132}
142} 133}
143 134
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 0a74019..f4bdbe0 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -11,192 +11,198 @@
11 - .   .-<_>     .<> Foundation; version 2 of the License. 11 - .   .-<_>     .<> Foundation; version 2 of the License.
12     ._= =}       : 12     ._= =}       :
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31/* OPIE */ 31/* OPIE */
32 32
33#include <opie2/onetwork.h> 33#include <opie2/onetwork.h>
34#include <opie2/ostation.h> 34#include <opie2/ostation.h>
35#include <opie2/odebug.h> 35#include <opie2/odebug.h>
36 36
37/* QT */ 37/* QT */
38 38
39#include <qfile.h> 39#include <qfile.h>
40#include <qtextstream.h> 40#include <qtextstream.h>
41#include <qapplication.h> 41#include <qapplication.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 <errno.h> 47#include <errno.h>
48#include <string.h> 48#include <string.h>
49#include <stdlib.h> 49#include <stdlib.h>
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 <net/ethernet.h> 57#include <net/ethernet.h>
58#include <stdarg.h> 58#include <stdarg.h>
59 59
60#ifndef NODEBUG 60#ifndef NODEBUG
61#include <opie2/odebugmapper.h> 61#include <opie2/odebugmapper.h>
62 62
63using namespace Opie::Core; 63using namespace Opie::Core;
64using namespace Opie::Net::Internal; 64using namespace Opie::Net::Internal;
65DebugMapper* debugmapper = new DebugMapper(); 65DebugMapper* debugmapper = new DebugMapper();
66#endif 66#endif
67 67
68/*====================================================================================== 68/*======================================================================================
69 * ONetwork 69 * ONetwork
70 *======================================================================================*/ 70 *======================================================================================*/
71 71
72namespace Opie { 72namespace Opie {
73namespace Net { 73namespace Net {
74ONetwork* ONetwork::_instance = 0; 74ONetwork* ONetwork::_instance = 0;
75 75
76ONetwork::ONetwork() 76ONetwork::ONetwork()
77{ 77{
78 odebug << "ONetwork::ONetwork()" << oendl; 78 odebug << "ONetwork::ONetwork()" << oendl;
79 odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; 79 odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl;
80 synchronize(); 80 synchronize();
81} 81}
82 82
83void ONetwork::synchronize() 83void ONetwork::synchronize()
84{ 84{
85 // gather available interfaces by inspecting /proc/net/dev 85 // gather available interfaces by inspecting /proc/net/dev
86 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 86 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
87 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 87 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
88 //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev 88 //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev
89 89
90 _interfaces.clear(); 90 _interfaces.clear();
91 QString str; 91 QString str;
92 QFile f( "/proc/net/dev" ); 92 QFile f( "/proc/net/dev" );
93 bool hasFile = f.open( IO_ReadOnly ); 93 bool hasFile = f.open( IO_ReadOnly );
94 if ( !hasFile ) 94 if ( !hasFile )
95 { 95 {
96 odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; 96 odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl;
97 return; 97 return;
98 } 98 }
99 QTextStream s( &f ); 99 QTextStream s( &f );
100 s.readLine(); 100 s.readLine();
101 s.readLine(); 101 s.readLine();
102 while ( !s.atEnd() ) 102 while ( !s.atEnd() )
103 { 103 {
104 s >> str; 104 s >> str;
105 str.truncate( str.find( ':' ) ); 105 str.truncate( str.find( ':' ) );
106 odebug << "ONetwork: found interface '" << str << "'" << oendl; 106 odebug << "ONetwork: found interface '" << str << "'" << oendl;
107 if ( str.startsWith( "wifi" ) )
108 {
109 odebug << "ONetwork: ignoring hostap control interface" << oendl;
110 s.readLine();
111 continue;
112 }
107 ONetworkInterface* iface = 0; 113 ONetworkInterface* iface = 0;
108 if ( isWirelessInterface( str ) ) 114 if ( isWirelessInterface( str ) )
109 { 115 {
110 iface = new OWirelessNetworkInterface( this, (const char*) str ); 116 iface = new OWirelessNetworkInterface( this, (const char*) str );
111 odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; 117 odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl;
112 } 118 }
113 else 119 else
114 { 120 {
115 iface = new ONetworkInterface( this, (const char*) str ); 121 iface = new ONetworkInterface( this, (const char*) str );
116 } 122 }
117 _interfaces.insert( str, iface ); 123 _interfaces.insert( str, iface );
118 s.readLine(); 124 s.readLine();
119 } 125 }
120} 126}
121 127
122 128
123short ONetwork::wirelessExtensionCompileVersion() 129short ONetwork::wirelessExtensionCompileVersion()
124{ 130{
125 return WIRELESS_EXT; 131 return WIRELESS_EXT;
126} 132}
127 133
128 134
129int ONetwork::count() const 135int ONetwork::count() const
130{ 136{
131 return _interfaces.count(); 137 return _interfaces.count();
132} 138}
133 139
134 140
135ONetworkInterface* ONetwork::interface( const QString& iface ) const 141ONetworkInterface* ONetwork::interface( const QString& iface ) const
136{ 142{
137 return _interfaces[iface]; 143 return _interfaces[iface];
138} 144}
139 145
140 146
141ONetwork* ONetwork::instance() 147ONetwork* ONetwork::instance()
142{ 148{
143 if ( !_instance ) _instance = new ONetwork(); 149 if ( !_instance ) _instance = new ONetwork();
144 return _instance; 150 return _instance;
145} 151}
146 152
147 153
148ONetwork::InterfaceIterator ONetwork::iterator() const 154ONetwork::InterfaceIterator ONetwork::iterator() const
149{ 155{
150 return ONetwork::InterfaceIterator( _interfaces ); 156 return ONetwork::InterfaceIterator( _interfaces );
151} 157}
152 158
153 159
154bool ONetwork::isPresent( const char* name ) const 160bool ONetwork::isPresent( const char* name ) const
155{ 161{
156 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 162 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
157 struct ifreq ifr; 163 struct ifreq ifr;
158 memset( &ifr, 0, sizeof( struct ifreq ) ); 164 memset( &ifr, 0, sizeof( struct ifreq ) );
159 strcpy( (char*) &ifr.ifr_name, name ); 165 strcpy( (char*) &ifr.ifr_name, name );
160 int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr ); 166 int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr );
161 return result != -1; 167 return result != -1;
162} 168}
163 169
164 170
165bool ONetwork::isWirelessInterface( const char* name ) const 171bool ONetwork::isWirelessInterface( const char* name ) const
166{ 172{
167 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 173 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
168 struct iwreq iwr; 174 struct iwreq iwr;
169 memset( &iwr, 0, sizeof( struct iwreq ) ); 175 memset( &iwr, 0, sizeof( struct iwreq ) );
170 strcpy( (char*) &iwr.ifr_name, name ); 176 strcpy( (char*) &iwr.ifr_name, name );
171 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 177 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
172 return result != -1; 178 return result != -1;
173} 179}
174 180
175/*====================================================================================== 181/*======================================================================================
176 * ONetworkInterface 182 * ONetworkInterface
177 *======================================================================================*/ 183 *======================================================================================*/
178 184
179ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) 185ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
180 :QObject( parent, name ), 186 :QObject( parent, name ),
181 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 187 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
182{ 188{
183 odebug << "ONetworkInterface::ONetworkInterface()" << oendl; 189 odebug << "ONetworkInterface::ONetworkInterface()" << oendl;
184 init(); 190 init();
185} 191}
186 192
187 193
188struct ifreq& ONetworkInterface::ifr() const 194struct ifreq& ONetworkInterface::ifr() const
189{ 195{
190 return _ifr; 196 return _ifr;
191} 197}
192 198
193 199
194void ONetworkInterface::init() 200void ONetworkInterface::init()
195{ 201{
196 odebug << "ONetworkInterface::init()" << oendl; 202 odebug << "ONetworkInterface::init()" << oendl;
197 203
198 memset( &_ifr, 0, sizeof( struct ifreq ) ); 204 memset( &_ifr, 0, sizeof( struct ifreq ) );
199 205
200 if ( _sfd == -1 ) 206 if ( _sfd == -1 )
201 { 207 {
202 odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; 208 odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl;
@@ -715,250 +721,251 @@ OChannelHopper* OWirelessNetworkInterface::channelHopper() const
715void OWirelessNetworkInterface::commit() const 721void OWirelessNetworkInterface::commit() const
716{ 722{
717 wioctl( SIOCSIWCOMMIT ); 723 wioctl( SIOCSIWCOMMIT );
718} 724}
719 725
720 726
721void OWirelessNetworkInterface::setMode( const QString& newMode ) 727void OWirelessNetworkInterface::setMode( const QString& newMode )
722{ 728{
723 #ifdef FINALIZE 729 #ifdef FINALIZE
724 QString currentMode = mode(); 730 QString currentMode = mode();
725 if ( currentMode == newMode ) return; 731 if ( currentMode == newMode ) return;
726 #endif 732 #endif
727 733
728 odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl; 734 odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl;
729 735
730 _iwr.u.mode = stringToMode( newMode ); 736 _iwr.u.mode = stringToMode( newMode );
731 737
732 if ( _iwr.u.mode != IW_MODE_MONITOR ) 738 if ( _iwr.u.mode != IW_MODE_MONITOR )
733 { 739 {
734 // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! 740 // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP!
735 _iwr.u.mode = stringToMode( newMode ); 741 _iwr.u.mode = stringToMode( newMode );
736 wioctl( SIOCSIWMODE ); 742 wioctl( SIOCSIWMODE );
737 743
738 // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) 744 // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now)
739 745
740 if ( mode() == "monitor" ) 746 if ( mode() == "monitor" )
741 { 747 {
742 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl; 748 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl;
743 if ( _mon ) 749 if ( _mon )
744 _mon->setEnabled( false ); 750 _mon->setEnabled( false );
745 else 751 else
746 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; 752 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl;
747 } 753 }
748 754
749 } 755 }
750 else // special iwpriv fallback for monitor mode 756 else // special iwpriv fallback for monitor mode
751 { 757 {
752 if ( wioctl( SIOCSIWMODE ) ) 758 if ( wioctl( SIOCSIWMODE ) )
753 { 759 {
754 odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl; 760 odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl;
755 } 761 }
756 else 762 else
757 { 763 {
758 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl; 764 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl;
759 765
760 if ( _mon ) 766 if ( _mon )
761 _mon->setEnabled( true ); 767 _mon->setEnabled( true );
762 else 768 else
763 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; 769 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl;
764 } 770 }
765 } 771 }
766} 772}
767 773
768 774
769QString OWirelessNetworkInterface::mode() const 775QString OWirelessNetworkInterface::mode() const
770{ 776{
771 memset( &_iwr, 0, sizeof( struct iwreq ) ); 777 memset( &_iwr, 0, sizeof( struct iwreq ) );
772 778
773 if ( !wioctl( SIOCGIWMODE ) ) 779 if ( !wioctl( SIOCGIWMODE ) )
774 { 780 {
775 return "<unknown>"; 781 return "<unknown>";
776 } 782 }
777 783
778 odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl; 784 odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl;
779 785
780 // legacy compatible monitor mode check 786 // legacy compatible monitor mode check
781 787
782 if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) 788 if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 )
783 { 789 {
784 return "monitor"; 790 return "monitor";
785 } 791 }
786 else 792 else
787 { 793 {
788 return modeToString( _iwr.u.mode ); 794 return modeToString( _iwr.u.mode );
789 } 795 }
790} 796}
791 797
792void OWirelessNetworkInterface::setNickName( const QString& nickname ) 798void OWirelessNetworkInterface::setNickName( const QString& nickname )
793{ 799{
794 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); 800 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
795 _iwr.u.essid.length = nickname.length(); 801 _iwr.u.essid.length = nickname.length();
796 wioctl( SIOCSIWNICKN ); 802 wioctl( SIOCSIWNICKN );
797} 803}
798 804
799 805
800QString OWirelessNetworkInterface::nickName() const 806QString OWirelessNetworkInterface::nickName() const
801{ 807{
802 char str[IW_ESSID_MAX_SIZE]; 808 char str[IW_ESSID_MAX_SIZE];
803 _iwr.u.data.pointer = &str[0]; 809 _iwr.u.data.pointer = &str[0];
804 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 810 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
805 if ( !wioctl( SIOCGIWNICKN ) ) 811 if ( !wioctl( SIOCGIWNICKN ) )
806 { 812 {
807 return "<unknown>"; 813 return "<unknown>";
808 } 814 }
809 else 815 else
810 { 816 {
811 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 817 str[_iwr.u.data.length] = '\0'; // some drivers don't zero-terminate the string
812 return str; 818 return str;
813 } 819 }
814} 820}
815 821
816 822
817void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 823void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
818{ 824{
819 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 825 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
820 if ( !priv ) 826 if ( !priv )
821 { 827 {
822 owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name() 828 owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name()
823 << "' does not support private ioctl '" << call << "'" << oendl; 829 << "' does not support private ioctl '" << call << "'" << oendl;
824 return; 830 return;
825 } 831 }
826 if ( priv->numberSetArgs() != numargs ) 832 if ( priv->numberSetArgs() != numargs )
827 { 833 {
828 owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '" 834 owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '"
829 << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl; 835 << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl;
830 return; 836 return;
831 } 837 }
832 838
833 odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl; 839 odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl;
834 memset( &_iwr, 0, sizeof _iwr ); 840 memset( &_iwr, 0, sizeof _iwr );
835 va_list argp; 841 va_list argp;
836 va_start( argp, numargs ); 842 va_start( argp, numargs );
837 for ( int i = 0; i < numargs; ++i ) 843 for ( int i = 0; i < numargs; ++i )
838 { 844 {
839 priv->setParameter( i, va_arg( argp, int ) ); 845 priv->setParameter( i, va_arg( argp, int ) );
840 } 846 }
841 va_end( argp ); 847 va_end( argp );
842 priv->invoke(); 848 priv->invoke();
843} 849}
844 850
845 851
846void OWirelessNetworkInterface::getPrivate( const QString& ) 852void OWirelessNetworkInterface::getPrivate( const QString& )
847{ 853{
848 oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl; 854 oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl;
849} 855}
850 856
851 857
852bool OWirelessNetworkInterface::hasPrivate( const QString& call ) 858bool OWirelessNetworkInterface::hasPrivate( const QString& call )
853{ 859{
854 return child( call.local8Bit() ); 860 return child( call.local8Bit() );
855} 861}
856 862
857 863
858QString OWirelessNetworkInterface::SSID() const 864QString OWirelessNetworkInterface::SSID() const
859{ 865{
860 char str[IW_ESSID_MAX_SIZE]; 866 char str[IW_ESSID_MAX_SIZE];
861 _iwr.u.essid.pointer = &str[0]; 867 _iwr.u.essid.pointer = &str[0];
862 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 868 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
863 if ( !wioctl( SIOCGIWESSID ) ) 869 if ( !wioctl( SIOCGIWESSID ) )
864 { 870 {
865 return "<unknown>"; 871 return "<unknown>";
866 } 872 }
867 else 873 else
868 { 874 {
875 str[_iwr.u.essid.length] = '\0'; // some drivers don't zero-terminate the string
869 return str; 876 return str;
870 } 877 }
871} 878}
872 879
873 880
874void OWirelessNetworkInterface::setSSID( const QString& ssid ) 881void OWirelessNetworkInterface::setSSID( const QString& ssid )
875{ 882{
876 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 883 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
877 _iwr.u.essid.length = ssid.length()+1; // zero byte 884 _iwr.u.essid.length = ssid.length()+1; // zero byte
878 wioctl( SIOCSIWESSID ); 885 wioctl( SIOCSIWESSID );
879} 886}
880 887
881 888
882OStationList* OWirelessNetworkInterface::scanNetwork() 889OStationList* OWirelessNetworkInterface::scanNetwork()
883{ 890{
884 _iwr.u.param.flags = IW_SCAN_DEFAULT; 891 _iwr.u.param.flags = IW_SCAN_DEFAULT;
885 _iwr.u.param.value = 0; 892 _iwr.u.param.value = 0;
886 if ( !wioctl( SIOCSIWSCAN ) ) 893 if ( !wioctl( SIOCSIWSCAN ) )
887 { 894 {
888 return 0; 895 return 0;
889 } 896 }
890 897
891 OStationList* stations = new OStationList(); 898 OStationList* stations = new OStationList();
892 899
893 int timeout = 10000000; 900 int timeout = 10000000;
894 901
895 odebug << "ONetworkInterface::scanNetwork() - scan started." << oendl; 902 odebug << "ONetworkInterface::scanNetwork() - scan started." << oendl;
896 903
897 bool results = false; 904 bool results = false;
898 struct timeval tv; 905 struct timeval tv;
899 tv.tv_sec = 0; 906 tv.tv_sec = 0;
900 tv.tv_usec = 250000; // initial timeout ~ 250ms 907 tv.tv_usec = 250000; // initial timeout ~ 250ms
901 char buffer[IW_SCAN_MAX_DATA]; 908 char buffer[IW_SCAN_MAX_DATA];
902 909
903 while ( !results && timeout > 0 ) 910 while ( !results && timeout > 0 )
904 { 911 {
905 timeout -= tv.tv_usec; 912 timeout -= tv.tv_usec;
906 select( 0, 0, 0, 0, &tv ); 913 select( 0, 0, 0, 0, &tv );
907 914
908 _iwr.u.data.pointer = &buffer[0]; 915 _iwr.u.data.pointer = &buffer[0];
909 _iwr.u.data.flags = 0; 916 _iwr.u.data.flags = 0;
910 _iwr.u.data.length = sizeof buffer; 917 _iwr.u.data.length = sizeof buffer;
911 if ( wioctl( SIOCGIWSCAN ) ) 918 if ( wioctl( SIOCGIWSCAN ) )
912 { 919 {
913 results = true; 920 results = true;
914 continue; 921 continue;
915 } 922 }
916 else if ( errno == EAGAIN) 923 else if ( errno == EAGAIN)
917 { 924 {
918 odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl; 925 odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl;
919 if ( qApp ) 926 if ( qApp )
920 { 927 {
921 qApp->processEvents( 100 ); 928 qApp->processEvents( 100 );
922 continue; 929 continue;
923 } 930 }
924 tv.tv_sec = 0; 931 tv.tv_sec = 0;
925 tv.tv_usec = 100000; 932 tv.tv_usec = 100000;
926 continue; 933 continue;
927 } 934 }
928 } 935 }
929 936
930 odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; 937 odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl;
931 938
932 if ( results ) 939 if ( results )
933 { 940 {
934 odebug << " - result length = " << _iwr.u.data.length << oendl; 941 odebug << " - result length = " << _iwr.u.data.length << oendl;
935 if ( !_iwr.u.data.length ) 942 if ( !_iwr.u.data.length )
936 { 943 {
937 odebug << " - no results (empty neighbourhood)" << oendl; 944 odebug << " - no results (empty neighbourhood)" << oendl;
938 return stations; 945 return stations;
939 } 946 }
940 947
941 odebug << " - results are in!" << oendl; 948 odebug << " - results are in!" << oendl;
942 dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); 949 dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length );
943 950
944 // parse results 951 // parse results
945 struct iw_event iwe; 952 struct iw_event iwe;
946 struct iw_stream_descr stream; 953 struct iw_stream_descr stream;
947 unsigned int cmd_index, event_type, event_len; 954 unsigned int cmd_index, event_type, event_len;
948 char *pointer; 955 char *pointer;
949 956
950 const char standard_ioctl_hdr[] = { 957 const char standard_ioctl_hdr[] = {
951 IW_HEADER_TYPE_NULL, /* SIOCSIWCOMMIT */ 958 IW_HEADER_TYPE_NULL, /* SIOCSIWCOMMIT */
952 IW_HEADER_TYPE_CHAR, /* SIOCGIWNAME */ 959 IW_HEADER_TYPE_CHAR, /* SIOCGIWNAME */
953 IW_HEADER_TYPE_PARAM, /* SIOCSIWNWID */ 960 IW_HEADER_TYPE_PARAM, /* SIOCSIWNWID */
954 IW_HEADER_TYPE_PARAM, /* SIOCGIWNWID */ 961 IW_HEADER_TYPE_PARAM, /* SIOCGIWNWID */
955 IW_HEADER_TYPE_FREQ, /* SIOCSIWFREQ */ 962 IW_HEADER_TYPE_FREQ, /* SIOCSIWFREQ */
956 IW_HEADER_TYPE_FREQ, /* SIOCGIWFREQ */ 963 IW_HEADER_TYPE_FREQ, /* SIOCGIWFREQ */
957 IW_HEADER_TYPE_UINT, /* SIOCSIWMODE */ 964 IW_HEADER_TYPE_UINT, /* SIOCSIWMODE */
958 IW_HEADER_TYPE_UINT, /* SIOCGIWMODE */ 965 IW_HEADER_TYPE_UINT, /* SIOCGIWMODE */
959 IW_HEADER_TYPE_PARAM, /* SIOCSIWSENS */ 966 IW_HEADER_TYPE_PARAM, /* SIOCSIWSENS */
960 IW_HEADER_TYPE_PARAM, /* SIOCGIWSENS */ 967 IW_HEADER_TYPE_PARAM, /* SIOCGIWSENS */
961 IW_HEADER_TYPE_NULL, /* SIOCSIWRANGE */ 968 IW_HEADER_TYPE_NULL, /* SIOCSIWRANGE */
962 IW_HEADER_TYPE_POINT, /* SIOCGIWRANGE */ 969 IW_HEADER_TYPE_POINT, /* SIOCGIWRANGE */
963 IW_HEADER_TYPE_NULL, /* SIOCSIWPRIV */ 970 IW_HEADER_TYPE_NULL, /* SIOCSIWPRIV */
964 IW_HEADER_TYPE_POINT, /* SIOCGIWPRIV */ 971 IW_HEADER_TYPE_POINT, /* SIOCGIWPRIV */
diff --git a/libopie2/opienet/opienet.pro b/libopie2/opienet/opienet.pro
index a10a949..460de0a 100644
--- a/libopie2/opienet/opienet.pro
+++ b/libopie2/opienet/opienet.pro
@@ -1,40 +1,40 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
4HEADERS = 802_11_user.h \ 4HEADERS = 802_11_user.h \
5 dhcp.h \ 5 dhcp.h \
6 udp_ports.h \ 6 udp_ports.h \
7 odebugmapper.h \ 7 odebugmapper.h \
8 omanufacturerdb.h \ 8 omanufacturerdb.h \
9 onetutils.h \ 9 onetutils.h \
10 onetwork.h \ 10 onetwork.h \
11 opcap.h \ 11 opcap.h \
12 ostation.h 12 ostation.h
13SOURCES = odebugmapper.cpp \ 13SOURCES = odebugmapper.cpp \
14 omanufacturerdb.cpp \ 14 omanufacturerdb.cpp \
15 onetutils.cpp \ 15 onetutils.cpp \
16 onetwork.cpp \ 16 onetwork.cpp \
17 opcap.cpp \ 17 opcap.cpp \
18 ostation.cpp 18 ostation.cpp
19INTERFACES = 19INTERFACES =
20TARGET = opienet2 20TARGET = opienet2
21VERSION = 1.8.5 21VERSION = 1.8.6
22INCLUDEPATH += $(OPIEDIR)/include 22INCLUDEPATH += $(OPIEDIR)/include
23DEPENDPATH += $(OPIEDIR)/include 23DEPENDPATH += $(OPIEDIR)/include
24LIBS += -lpcap 24LIBS += -lpcap
25 25
26 26
27!contains( platform, x11 ) { 27!contains( platform, x11 ) {
28 include( $(OPIEDIR)/include.pro ) 28 include( $(OPIEDIR)/include.pro )
29} 29}
30 30
31contains( platform, x11 ) { 31contains( platform, x11 ) {
32 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib 32 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib
33} 33}
34 34
35!isEmpty( LIBPCAP_INC_DIR ) { 35!isEmpty( LIBPCAP_INC_DIR ) {
36 INCLUDEPATH = $$LIBPCAP_INC_DIR $$INCLUDEPATH 36 INCLUDEPATH = $$LIBPCAP_INC_DIR $$INCLUDEPATH
37} 37}
38!isEmpty( LIBPCAP_LIB_DIR ) { 38!isEmpty( LIBPCAP_LIB_DIR ) {
39 LIBS = -L$$LIBPCAP_LIB_DIR $$LIBS 39 LIBS = -L$$LIBPCAP_LIB_DIR $$LIBS
40} 40}