summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-10-28 19:13:34 (UTC)
committer mickeyl <mickeyl>2003-10-28 19:13:34 (UTC)
commitd5d9b307e950d9038215e4d63e64bc9cd5d85352 (patch) (unidiff)
treeccef170352625a48c9c7ff0e7ff119f8d23e2331
parent5acd7ce51829c317f6218ff059d0d2f63cdb0871 (diff)
downloadopie-d5d9b307e950d9038215e4d63e64bc9cd5d85352.zip
opie-d5d9b307e950d9038215e4d63e64bc9cd5d85352.tar.gz
opie-d5d9b307e950d9038215e4d63e64bc9cd5d85352.tar.bz2
catch up with API changes in libopienet
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp2.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/noncore/settings/networksettings/wlan/wlanimp2.cpp b/noncore/settings/networksettings/wlan/wlanimp2.cpp
index 7ce096f..e7d6ff5 100644
--- a/noncore/settings/networksettings/wlan/wlanimp2.cpp
+++ b/noncore/settings/networksettings/wlan/wlanimp2.cpp
@@ -1,490 +1,490 @@
1#include "wlanimp2.h" 1#include "wlanimp2.h"
2#include "keyedit.h" 2#include "keyedit.h"
3#include "interfacesetupimp.h" 3#include "interfacesetupimp.h"
4 4
5#include "../interfaces/interface.h" 5#include "../interfaces/interface.h"
6 6
7#include <assert.h> 7#include <assert.h>
8#include <errno.h> 8#include <errno.h>
9#include <string.h> 9#include <string.h>
10 10
11#include <qapplication.h> 11#include <qapplication.h>
12#include <qfile.h> 12#include <qfile.h>
13#include <qdir.h> 13#include <qdir.h>
14#include <qdialog.h> 14#include <qdialog.h>
15#include <qtextstream.h> 15#include <qtextstream.h>
16#include <qmessagebox.h> 16#include <qmessagebox.h>
17#include <qlineedit.h> 17#include <qlineedit.h>
18#include <qlabel.h> 18#include <qlabel.h>
19#include <qspinbox.h> 19#include <qspinbox.h>
20#include <qradiobutton.h> 20#include <qradiobutton.h>
21#include <qpushbutton.h> 21#include <qpushbutton.h>
22#include <qcheckbox.h> 22#include <qcheckbox.h>
23#include <qtabwidget.h> 23#include <qtabwidget.h>
24#include <qcombobox.h> 24#include <qcombobox.h>
25#include <qlistview.h> 25#include <qlistview.h>
26#include <qvbox.h> 26#include <qvbox.h>
27#include <qprogressbar.h> 27#include <qprogressbar.h>
28 28
29#ifdef QWS 29#ifdef QWS
30 #include <qpe/resource.h> 30 #include <qpe/resource.h>
31 #include <opie/oprocess.h> 31 #include <opie/oprocess.h>
32 #include <opie2/onetwork.h> 32 #include <opie2/onetwork.h>
33 #include <opie2/opcap.h> 33 #include <opie2/opcap.h>
34#else 34#else
35 #define OProcess KProcess 35 #define OProcess KProcess
36 #include <kprocess.h> 36 #include <kprocess.h>
37#endif 37#endif
38 38
39#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" 39#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts"
40#define PREUP "/etc/network/if-pre-up.d/wireless-tools" 40#define PREUP "/etc/network/if-pre-up.d/wireless-tools"
41 41
42/** 42/**
43 * Constructor, read in the wireless.opts file for parsing later. 43 * Constructor, read in the wireless.opts file for parsing later.
44 */ 44 */
45WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") { 45WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") {
46 interfaces = new Interfaces(); 46 interfaces = new Interfaces();
47 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces); 47 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces);
48 tabWidget->insertTab(interfaceSetup, "TCP/IP"); 48 tabWidget->insertTab(interfaceSetup, "TCP/IP");
49 49
50 // Check sanity - the existance of the wireless-tools if-pre-up script 50 // Check sanity - the existance of the wireless-tools if-pre-up script
51 QFile file(QString(PREUP)); 51 QFile file(QString(PREUP));
52 if (file.exists()) { 52 if (file.exists()) {
53 qWarning(QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools")); 53 qWarning(QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools"));
54 } 54 }
55 55
56 connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) ); 56 connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) );
57 connect( netView, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectNetwork( QListViewItem* ) ) ); 57 connect( netView, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectNetwork( QListViewItem* ) ) );
58 netView->setColumnAlignment( col_chn, AlignCenter ); 58 netView->setColumnAlignment( col_chn, AlignCenter );
59 netView->setItemMargin( 3 ); 59 netView->setItemMargin( 3 );
60 netView->setAllColumnsShowFocus( true ); 60 netView->setAllColumnsShowFocus( true );
61 61
62} 62}
63 63
64WLANImp::~WLANImp() { 64WLANImp::~WLANImp() {
65//FIXME: delete interfaces; 65//FIXME: delete interfaces;
66} 66}
67 67
68/** 68/**
69 * Change the profile for both wireless settings and network settings. 69 * Change the profile for both wireless settings and network settings.
70 */ 70 */
71void WLANImp::setProfile(const QString &profile){ 71void WLANImp::setProfile(const QString &profile){
72 interfaceSetup->setProfile(profile); 72 interfaceSetup->setProfile(profile);
73 parseOpts(); 73 parseOpts();
74} 74}
75 75
76void WLANImp::parseOpts() { 76void WLANImp::parseOpts() {
77 bool error; 77 bool error;
78 QString opt; 78 QString opt;
79 79
80 if (! interfaces->isInterfaceSet()) 80 if (! interfaces->isInterfaceSet())
81 return; 81 return;
82 82
83 83
84 opt = interfaces->getInterfaceOption("wireless_essid", error); 84 opt = interfaces->getInterfaceOption("wireless_essid", error);
85 if(opt == "any" || opt == "off" || opt.isNull()){ 85 if(opt == "any" || opt == "off" || opt.isNull()){
86 essid->setEditText("any"); 86 essid->setEditText("any");
87 } else { 87 } else {
88 essid->setEditText(opt); 88 essid->setEditText(opt);
89 } 89 }
90 90
91 opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace(); 91 opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace();
92 92
93 for ( int i = 0; i < mode->count(); i++) 93 for ( int i = 0; i < mode->count(); i++)
94 if ( mode->text( i ) == opt ) mode->setCurrentItem( i ); 94 if ( mode->text( i ) == opt ) mode->setCurrentItem( i );
95 95
96 opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace(); 96 opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace();
97 if (! opt.isNull()) { 97 if (! opt.isNull()) {
98 specifyAp->setChecked(true); 98 specifyAp->setChecked(true);
99 macEdit->setText(opt); 99 macEdit->setText(opt);
100 } 100 }
101 101
102 opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace(); 102 opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace();
103 if (! opt.isNull()) { 103 if (! opt.isNull()) {
104 specifyChan->setChecked(true); 104 specifyChan->setChecked(true);
105 networkChannel->setValue(opt.toInt()); 105 networkChannel->setValue(opt.toInt());
106 } 106 }
107 107
108 opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace(); 108 opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace();
109 if (opt.isNull()) 109 if (opt.isNull())
110 opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace(); 110 opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace();
111 parseKeyStr(opt); 111 parseKeyStr(opt);
112} 112}
113 113
114void WLANImp::parseKeyStr(QString keystr) { 114void WLANImp::parseKeyStr(QString keystr) {
115 int loc = 0; 115 int loc = 0;
116 int index = 1; 116 int index = 1;
117 QString key; 117 QString key;
118 QStringList keys = QStringList::split(QRegExp("\\s+"), keystr); 118 QStringList keys = QStringList::split(QRegExp("\\s+"), keystr);
119 int enc = -1; // encryption state 119 int enc = -1; // encryption state
120 120
121 for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { 121 for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) {
122 if ((*it).left(3) == "off") { 122 if ((*it).left(3) == "off") {
123 // encryption disabled 123 // encryption disabled
124 enc = 0; 124 enc = 0;
125 } else if ((*it).left(2) == "on") { 125 } else if ((*it).left(2) == "on") {
126 // encryption enabled 126 // encryption enabled
127 enc = 1; 127 enc = 1;
128 } else if ((*it).left(4) == "open") { 128 } else if ((*it).left(4) == "open") {
129 // open mode, accept non encrypted packets 129 // open mode, accept non encrypted packets
130 acceptNonEnc->setChecked(true); 130 acceptNonEnc->setChecked(true);
131 } else if ((*it).left(10) == "restricted") { 131 } else if ((*it).left(10) == "restricted") {
132 // restricted mode, only accept encrypted packets 132 // restricted mode, only accept encrypted packets
133 rejectNonEnc->setChecked(true); 133 rejectNonEnc->setChecked(true);
134 } else if ((*it).left(3) == "key") { 134 } else if ((*it).left(3) == "key") {
135 // new set of options 135 // new set of options
136 } else if ((*it).left(1) == "[") { 136 } else if ((*it).left(1) == "[") {
137 index = (*it).mid(1, 1).toInt(); 137 index = (*it).mid(1, 1).toInt();
138 // switch current key to index 138 // switch current key to index
139 switch (index) { 139 switch (index) {
140 case 1: 140 case 1:
141 keyRadio0->setChecked(true); 141 keyRadio0->setChecked(true);
142 break; 142 break;
143 case 2: 143 case 2:
144 keyRadio1->setChecked(true); 144 keyRadio1->setChecked(true);
145 break; 145 break;
146 case 3: 146 case 3:
147 keyRadio2->setChecked(true); 147 keyRadio2->setChecked(true);
148 break; 148 break;
149 case 4: 149 case 4:
150 keyRadio3->setChecked(true); 150 keyRadio3->setChecked(true);
151 break; 151 break;
152 } 152 }
153 } else { 153 } else {
154 // key 154 // key
155 key = (*it); 155 key = (*it);
156 } 156 }
157 if (! key.isNull()) { 157 if (! key.isNull()) {
158 if (enc == -1) 158 if (enc == -1)
159 enc = 1; 159 enc = 1;
160 QStringList::Iterator next = ++it; 160 QStringList::Iterator next = ++it;
161 if (it == keys.end()) { 161 if (it == keys.end()) {
162 break; 162 break;
163 } 163 }
164 if ((*(next)).left(1) == "[") { 164 if ((*(next)).left(1) == "[") {
165 // set key at index 165 // set key at index
166 index = (*(next)).mid(1, 1).toInt(); 166 index = (*(next)).mid(1, 1).toInt();
167 } else { 167 } else {
168 index = 1; 168 index = 1;
169 } 169 }
170 switch (index) { 170 switch (index) {
171 case 1: 171 case 1:
172 keyLineEdit0->setText(key); 172 keyLineEdit0->setText(key);
173 break; 173 break;
174 case 2: 174 case 2:
175 keyLineEdit1->setText(key); 175 keyLineEdit1->setText(key);
176 break; 176 break;
177 case 3: 177 case 3:
178 keyLineEdit2->setText(key); 178 keyLineEdit2->setText(key);
179 break; 179 break;
180 case 4: 180 case 4:
181 keyLineEdit3->setText(key); 181 keyLineEdit3->setText(key);
182 break; 182 break;
183 } 183 }
184 key = QString::null; 184 key = QString::null;
185 } 185 }
186 } 186 }
187 if (enc == 1) { 187 if (enc == 1) {
188 wepEnabled->setChecked(true); 188 wepEnabled->setChecked(true);
189 } else { 189 } else {
190 wepEnabled->setChecked(false); 190 wepEnabled->setChecked(false);
191 } 191 }
192} 192}
193 193
194/** 194/**
195 * Check to see if the current config is valid 195 * Check to see if the current config is valid
196 * Save interfaces 196 * Save interfaces
197 */ 197 */
198void WLANImp::accept() { 198void WLANImp::accept() {
199 if (wepEnabled->isChecked()) { 199 if (wepEnabled->isChecked()) {
200 if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) || 200 if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) ||
201 (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) || 201 (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) ||
202 (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) || 202 (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) ||
203 (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) { 203 (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) {
204 QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok); 204 QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok);
205 return; 205 return;
206 } 206 }
207 } 207 }
208 208
209 if (essid->currentText().isEmpty()) { 209 if (essid->currentText().isEmpty()) {
210 QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok); 210 QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok);
211 return; 211 return;
212 } 212 }
213 213
214 if (specifyAp->isChecked() && macEdit->text().isEmpty()) { 214 if (specifyAp->isChecked() && macEdit->text().isEmpty()) {
215 QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok); 215 QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok);
216 return; 216 return;
217 } 217 }
218 218
219 // Try to save the interfaces settings. 219 // Try to save the interfaces settings.
220 writeOpts(); 220 writeOpts();
221 221
222 // Close out the dialog 222 // Close out the dialog
223// FIXME: QDialog::accept(); 223// FIXME: QDialog::accept();
224} 224}
225 225
226void WLANImp::writeOpts() { 226void WLANImp::writeOpts() {
227 // eh can't really do anything about it other then return. :-D 227 // eh can't really do anything about it other then return. :-D
228 if(!interfaces->isInterfaceSet()){ 228 if(!interfaces->isInterfaceSet()){
229 QMessageBox::warning(0,"Inface not set","should not happen!!!"); 229 QMessageBox::warning(0,"Inface not set","should not happen!!!");
230 return; 230 return;
231 } 231 }
232 bool error = false; 232 bool error = false;
233 233
234 qDebug("setting wlan interface %s", interfaces->getInterfaceName( error ).latin1() ); 234 qDebug("setting wlan interface %s", interfaces->getInterfaceName( error ).latin1() );
235 235
236 if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!"); 236 if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!");
237 237
238 interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText()); 238 interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText());
239 interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText()); 239 interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText());
240 240
241 if (specifyAp->isChecked()) { 241 if (specifyAp->isChecked()) {
242 interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text()); 242 interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text());
243 } else { 243 } else {
244 interfaces->removeInterfaceOption(QString("wireless_ap")); 244 interfaces->removeInterfaceOption(QString("wireless_ap"));
245 } 245 }
246 246
247 if (specifyChan->isChecked()) { 247 if (specifyChan->isChecked()) {
248 interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text()); 248 interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text());
249 } else { 249 } else {
250 interfaces->removeInterfaceOption(QString("wireless_channel")); 250 interfaces->removeInterfaceOption(QString("wireless_channel"));
251 } 251 }
252 252
253 if (wepEnabled->isChecked()) { 253 if (wepEnabled->isChecked()) {
254 QStringList keyList; 254 QStringList keyList;
255 255
256 if (! keyLineEdit0->text().isNull()) { 256 if (! keyLineEdit0->text().isNull()) {
257 keyList += keyLineEdit0->text(); 257 keyList += keyLineEdit0->text();
258 keyList += "[1]"; 258 keyList += "[1]";
259 } //else 259 } //else
260 if (! keyLineEdit1->text().isNull()) { 260 if (! keyLineEdit1->text().isNull()) {
261 keyList += keyLineEdit1->text(); 261 keyList += keyLineEdit1->text();
262 keyList += "[2]"; 262 keyList += "[2]";
263 } //else 263 } //else
264 if (! keyLineEdit2->text().isNull()) { 264 if (! keyLineEdit2->text().isNull()) {
265 keyList += keyLineEdit2->text(); 265 keyList += keyLineEdit2->text();
266 keyList += "[3]"; 266 keyList += "[3]";
267 } //else 267 } //else
268 if (! keyLineEdit3->text().isNull()) { 268 if (! keyLineEdit3->text().isNull()) {
269 keyList += keyLineEdit3->text(); 269 keyList += keyLineEdit3->text();
270 keyList += "[4]"; 270 keyList += "[4]";
271 } 271 }
272 if (acceptNonEnc->isChecked()) { 272 if (acceptNonEnc->isChecked()) {
273 keyList += "open"; 273 keyList += "open";
274 } else { 274 } else {
275 keyList += "restricted"; 275 keyList += "restricted";
276 } 276 }
277 277
278 keyList += "key"; 278 keyList += "key";
279 if (keyRadio0->isChecked()) { 279 if (keyRadio0->isChecked()) {
280 keyList += "[1]"; 280 keyList += "[1]";
281 } else if (keyRadio1->isChecked()) { 281 } else if (keyRadio1->isChecked()) {
282 keyList += "[2]"; 282 keyList += "[2]";
283 } else if (keyRadio2->isChecked()) { 283 } else if (keyRadio2->isChecked()) {
284 keyList += "[3]"; 284 keyList += "[3]";
285 } else if (keyRadio3->isChecked()) { 285 } else if (keyRadio3->isChecked()) {
286 keyList += "[4]"; 286 keyList += "[4]";
287 } 287 }
288 interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" "))); 288 interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" ")));
289 } else { 289 } else {
290 interfaces->removeInterfaceOption(QString("wireless_key")); 290 interfaces->removeInterfaceOption(QString("wireless_key"));
291 } 291 }
292 interfaces->removeInterfaceOption(QString("wireless_enc")); 292 interfaces->removeInterfaceOption(QString("wireless_enc"));
293 293
294 if(!interfaceSetup->saveChanges()) 294 if(!interfaceSetup->saveChanges())
295 return; 295 return;
296 296
297 QDialog::accept(); 297 QDialog::accept();
298} 298}
299 299
300/* 300/*
301 * Scan for possible wireless networks around... 301 * Scan for possible wireless networks around...
302 * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org> 302 * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org>
303 */ 303 */
304 304
305void WLANImp::rescanNeighbourhood() 305void WLANImp::rescanNeighbourhood()
306{ 306{
307 QString name = interface->getInterfaceName(); 307 QString name = interface->getInterfaceName();
308 qDebug( "rescanNeighbourhood via '%s'", (const char*) name ); 308 qDebug( "rescanNeighbourhood via '%s'", (const char*) name );
309 309
310 OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( ONetwork::instance()->interface( name ) ); 310 OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( ONetwork::instance()->interface( name ) );
311 assert( wiface ); 311 assert( wiface );
312 312
313 // try to guess device type 313 // try to guess device type
314 QString devicetype; 314 QString devicetype;
315 QFile m( "/proc/modules" ); 315 QFile m( "/proc/modules" );
316 if ( m.open( IO_ReadOnly ) ) 316 if ( m.open( IO_ReadOnly ) )
317 { 317 {
318 QString line; 318 QString line;
319 QTextStream modules( &m ); 319 QTextStream modules( &m );
320 while( !modules.atEnd() && !devicetype ) 320 while( !modules.atEnd() && !devicetype )
321 { 321 {
322 modules >> line; 322 modules >> line;
323 if ( line.contains( "cisco" ) ) devicetype = "cisco"; 323 if ( line.contains( "cisco" ) ) devicetype = "cisco";
324 else if ( line.contains( "hostap" ) ) devicetype = "hostap"; 324 else if ( line.contains( "hostap" ) ) devicetype = "hostap";
325 else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */ 325 else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */
326 else if ( line.contains( "orinoco" ) ) devicetype = "orinoco"; 326 else if ( line.contains( "orinoco" ) ) devicetype = "orinoco";
327 } 327 }
328 } 328 }
329 if ( devicetype.isEmpty() ) 329 if ( devicetype.isEmpty() )
330 { 330 {
331 qWarning( "rescanNeighbourhood(): couldn't guess device type :(" ); 331 qWarning( "rescanNeighbourhood(): couldn't guess device type :(" );
332 return; 332 return;
333 } 333 }
334 else 334 else
335 { 335 {
336 qDebug( "rescanNeighbourhood(): device type seems to be '%s'", (const char*) devicetype ); 336 qDebug( "rescanNeighbourhood(): device type seems to be '%s'", (const char*) devicetype );
337 } 337 }
338 338
339 // configure interface to receive 802.11 management frames 339 // configure interface to receive 802.11 management frames
340 340
341 wiface->setUp( true ); 341 wiface->setUp( true );
342 wiface->setPromiscuousMode( true ); 342 wiface->setPromiscuousMode( true );
343 343
344 if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) ); 344 if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) );
345 else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) ); 345 else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) );
346 else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) ); 346 else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) );
347 else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) ); 347 else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) );
348 else 348 else
349 { 349 {
350 qDebug( "rescanNeighbourhood(): unsupported device type for monitoring :(" ); 350 qDebug( "rescanNeighbourhood(): unsupported device type for monitoring :(" );
351 return; 351 return;
352 } 352 }
353 353
354 wiface->setMonitorMode( true ); 354 wiface->setMode( "monitor" );
355 if ( !wiface->monitorMode() ) 355 if ( wiface->mode() != "monitor" )
356 { 356 {
357 qWarning( "rescanNeighbourhood(): Unable to bring device into monitor mode (%s).", strerror( errno ) ); 357 qWarning( "rescanNeighbourhood(): Unable to bring device into monitor mode (%s).", strerror( errno ) );
358 return; 358 return;
359 } 359 }
360 360
361 // open a packet capturer 361 // open a packet capturer
362 OPacketCapturer* cap = new OPacketCapturer(); 362 OPacketCapturer* cap = new OPacketCapturer();
363 cap->open( name ); 363 cap->open( name );
364 if ( !cap->isOpen() ) 364 if ( !cap->isOpen() )
365 { 365 {
366 qWarning( "rescanNeighbourhood(): Unable to open libpcap (%s).", strerror( errno ) ); 366 qWarning( "rescanNeighbourhood(): Unable to open libpcap (%s).", strerror( errno ) );
367 return; 367 return;
368 } 368 }
369 369
370 // display splash screen 370 // display splash screen
371 QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize ); 371 QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize );
372 splash->setLineWidth( 2 ); 372 splash->setLineWidth( 2 );
373 splash->setFrameStyle( QFrame::Panel | QFrame::Raised ); 373 splash->setFrameStyle( QFrame::Panel | QFrame::Raised );
374 QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 ); 374 QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 );
375 QLabel* lab = new QLabel( "<center><b>Scanning...</b><br>Please Wait...</center>", splash ); 375 QLabel* lab = new QLabel( "<center><b>Scanning...</b><br>Please Wait...</center>", splash );
376 QProgressBar* pb = new QProgressBar( wiface->channels(), splash ); 376 QProgressBar* pb = new QProgressBar( wiface->channels(), splash );
377 vbox->addWidget( lab ); 377 vbox->addWidget( lab );
378 vbox->addWidget( pb ); 378 vbox->addWidget( pb );
379 pb->setCenterIndicator( true ); 379 pb->setCenterIndicator( true );
380 pb->setFixedHeight( pb->sizeHint().height() ); 380 pb->setFixedHeight( pb->sizeHint().height() );
381 QWidget* widgetDesktop = qApp->desktop(); 381 QWidget* widgetDesktop = qApp->desktop();
382 int dw = widgetDesktop->width(); 382 int dw = widgetDesktop->width();
383 int dh = widgetDesktop->height(); 383 int dh = widgetDesktop->height();
384 int pw = vbox->sizeHint().width(); 384 int pw = vbox->sizeHint().width();
385 int ph = vbox->sizeHint().height(); 385 int ph = vbox->sizeHint().height();
386 splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph); 386 splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph);
387 splash->show(); 387 splash->show();
388 splash->raise(); 388 splash->raise();
389 qApp->processEvents(); 389 qApp->processEvents();
390 390
391 // set capturer to non-blocking mode 391 // set capturer to non-blocking mode
392 cap->setBlocking( false ); 392 cap->setBlocking( false );
393 393
394 for ( int i = 1; i <= wiface->channels(); ++i ) 394 for ( int i = 1; i <= wiface->channels(); ++i )
395 { 395 {
396 wiface->setChannel( i ); 396 wiface->setChannel( i );
397 pb->setProgress( i ); 397 pb->setProgress( i );
398 qApp->processEvents(); 398 qApp->processEvents();
399 qDebug( "rescanNeighbourhood(): listening on channel %d...", i ); 399 qDebug( "rescanNeighbourhood(): listening on channel %d...", i );
400 OPacket* p = cap->next( 1000 ); 400 OPacket* p = cap->next( 1000 );
401 if ( !p ) 401 if ( !p )
402 { 402 {
403 qDebug( "rescanNeighbourhood(): nothing received on channel %d", i ); 403 qDebug( "rescanNeighbourhood(): nothing received on channel %d", i );
404 } 404 }
405 else 405 else
406 { 406 {
407 qDebug( "rescanNeighbourhood(): TADAA - something came in on channel %d", i ); 407 qDebug( "rescanNeighbourhood(): TADAA - something came in on channel %d", i );
408 handlePacket( p ); 408 handlePacket( p );
409 } 409 }
410 } 410 }
411 411
412 cap->close(); 412 cap->close();
413 wiface->setMonitorMode( false ); 413 wiface->setMode( "managed" ); // TODO: use previous mode
414 wiface->setPromiscuousMode( true ); 414 wiface->setPromiscuousMode( false );
415 415
416 splash->hide(); 416 splash->hide();
417 delete splash; 417 delete splash;
418 418
419} 419}
420 420
421void WLANImp::handlePacket( OPacket* p ) 421void WLANImp::handlePacket( OPacket* p )
422{ 422{
423 423
424 // check if we received a beacon frame 424 // check if we received a beacon frame
425 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) ); 425 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) );
426 if ( beacon && beacon->managementType() == "Beacon" ) 426 if ( beacon && beacon->managementType() == "Beacon" )
427 { 427 {
428 428
429 QString type; 429 QString type;
430 if ( beacon->canIBSS() ) 430 if ( beacon->canIBSS() )
431 { 431 {
432 type = "adhoc"; 432 type = "adhoc";
433 } 433 }
434 else if ( beacon->canESS() ) 434 else if ( beacon->canESS() )
435 { 435 {
436 type = "managed"; 436 type = "managed";
437 } 437 }
438 else 438 else
439 { 439 {
440 qWarning( "handlePacket(): invalid frame [possibly noise] detected!" ); 440 qWarning( "handlePacket(): invalid frame [possibly noise] detected!" );
441 return; 441 return;
442 } 442 }
443 443
444 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 444 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
445 QString essid = ssid ? ssid->ID() : QString("<unknown>"); 445 QString essid = ssid ? ssid->ID() : QString("<unknown>");
446 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); 446 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
447 int channel = ds ? ds->channel() : -1; 447 int channel = ds ? ds->channel() : -1;
448 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 448 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
449 displayFoundNetwork( type, channel, essid, header->macAddress2() ); 449 displayFoundNetwork( type, channel, essid, header->macAddress2() );
450 } 450 }
451} 451}
452 452
453 453
454void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac ) 454void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac )
455{ 455{
456 456
457 qDebug( "found network: <%s>, chn %d, ssid '%s', mac '%s'", (const char*) mode, channel, 457 qDebug( "found network: <%s>, chn %d, ssid '%s', mac '%s'", (const char*) mode, channel,
458 (const char*) ssid, 458 (const char*) ssid,
459 (const char*) mac.toString() ); 459 (const char*) mac.toString() );
460 460
461 QListViewItemIterator it( netView ); 461 QListViewItemIterator it( netView );
462 while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it; 462 while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it;
463 if ( !it.current() ) // ssid didn't show up yet 463 if ( !it.current() ) // ssid didn't show up yet
464 { 464 {
465 QListViewItem* item = new QListViewItem( netView, mode.left( 1 ).upper(), ssid, QString::number( channel ), mac.toString() ); 465 QListViewItem* item = new QListViewItem( netView, mode.left( 1 ).upper(), ssid, QString::number( channel ), mac.toString() );
466 QString name; 466 QString name;
467 name.sprintf( "networksettings/%s", (const char*) mode ); 467 name.sprintf( "networksettings/%s", (const char*) mode );
468 item->setPixmap( col_mode, Resource::loadPixmap( name ) ); 468 item->setPixmap( col_mode, Resource::loadPixmap( name ) );
469 qApp->processEvents(); 469 qApp->processEvents();
470 } 470 }
471 471
472} 472}
473 473
474 474
475void WLANImp::selectNetwork( QListViewItem* item ) 475void WLANImp::selectNetwork( QListViewItem* item )
476{ 476{
477 bool ok; 477 bool ok;
478 if ( item ) 478 if ( item )
479 { 479 {
480 specifyAp->setChecked(true); 480 specifyAp->setChecked(true);
481 macEdit->setText( item->text( col_mac ) ); 481 macEdit->setText( item->text( col_mac ) );
482 specifyChan->setChecked( item->text( col_mode ) == "A" ); 482 specifyChan->setChecked( item->text( col_mode ) == "A" );
483 networkChannel->setValue( item->text( col_chn ).toInt( &ok ) ); 483 networkChannel->setValue( item->text( col_chn ).toInt( &ok ) );
484 essid->setEditText( item->text( col_ssid ) ); 484 essid->setEditText( item->text( col_ssid ) );
485 if ( item->text( col_mode ) == "A" ) 485 if ( item->text( col_mode ) == "A" )
486 mode->setCurrentItem( 3 ); 486 mode->setCurrentItem( 3 );
487 else 487 else
488 mode->setCurrentItem( 2 ); 488 mode->setCurrentItem( 2 );
489 } 489 }
490} 490}