summaryrefslogtreecommitdiff
Unidiff
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
@@ -162,329 +162,329 @@ void WLANImp::parseKeyStr(QString keystr) {
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}