summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/wellenreiter.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp
index 448b52b..79734a2 100644
--- a/noncore/net/wellenreiter/gui/wellenreiter.cpp
+++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp
@@ -298,216 +298,225 @@ void Wellenreiter::receivePacket( OPacket* p )
298 298
299} 299}
300 300
301 301
302void Wellenreiter::stopClicked() 302void Wellenreiter::stopClicked()
303{ 303{
304 if ( iface ) 304 if ( iface )
305 { 305 {
306 disconnect( SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); 306 disconnect( SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
307 disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) ); 307 disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
308 iface->setChannelHopping(); // stop hopping channels 308 iface->setChannelHopping(); // stop hopping channels
309 } 309 }
310 else 310 else
311 killTimers(); 311 killTimers();
312 312
313 pcap->close(); 313 pcap->close();
314 sniffing = false; 314 sniffing = false;
315 315
316 if ( iface ) 316 if ( iface )
317 { 317 {
318 // switch off monitor mode 318 // switch off monitor mode
319 iface->setMonitorMode( false ); 319 iface->setMonitorMode( false );
320 // switch off promisc flag 320 // switch off promisc flag
321 iface->setPromiscuousMode( false ); 321 iface->setPromiscuousMode( false );
322 322
323 system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess 323 system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess
324 } 324 }
325 325
326 logwindow->log( "(i) Stopped Scanning." ); 326 logwindow->log( "(i) Stopped Scanning." );
327 assert( parent() ); 327 assert( parent() );
328 ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" ); 328 ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" );
329 329
330 // message the user 330 // message the user
331 QMessageBox::information( this, "Wellenreiter II", 331 QMessageBox::information( this, "Wellenreiter II",
332 tr( "Your wireless card\nshould now be usable again." ) ); 332 tr( "Your wireless card\nshould now be usable again." ) );
333 333
334 sniffing = false; 334 sniffing = false;
335 emit( stoppedSniffing() ); 335 emit( stoppedSniffing() );
336 336
337 // print out statistics 337 // print out statistics
338 for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it ) 338 for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it )
339 statwindow->updateCounter( it.key(), it.data() ); 339 statwindow->updateCounter( it.key(), it.data() );
340} 340}
341 341
342 342
343void Wellenreiter::startClicked() 343void Wellenreiter::startClicked()
344{ 344{
345 // get configuration from config window 345 // get configuration from config window
346 346
347 const QString& interface = configwindow->interfaceName->currentText(); 347 const QString& interface = configwindow->interfaceName->currentText();
348 const int cardtype = configwindow->driverType(); 348 const int cardtype = configwindow->driverType();
349 const int interval = configwindow->hoppingInterval(); 349 const int interval = configwindow->hoppingInterval();
350 350
351 if ( ( interface == "" ) || ( cardtype == 0 ) ) 351 if ( ( interface == "" ) || ( cardtype == 0 ) )
352 { 352 {
353 QMessageBox::information( this, "Wellenreiter II", 353 QMessageBox::information( this, "Wellenreiter II",
354 tr( "Your device is not\nproperly configured. Please reconfigure!" ) ); 354 tr( "Your device is not\nproperly configured. Please reconfigure!" ) );
355 return; 355 return;
356 } 356 }
357 357
358 // configure device 358 // configure device
359 ONetwork* net = ONetwork::instance(); 359 ONetwork* net = ONetwork::instance();
360 iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); 360 iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface ));
361 361
362 // bring device UP 362 // bring device UP
363 iface->setUp( true ); 363 iface->setUp( true );
364 if ( !iface->isUp() ) 364 if ( !iface->isUp() )
365 { 365 {
366 QMessageBox::warning( this, "Wellenreiter II", 366 QMessageBox::warning( this, "Wellenreiter II",
367 tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) ); 367 tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) );
368 return; 368 return;
369 } 369 }
370 370
371 // set monitor mode 371 // set monitor mode
372 bool usePrism = configwindow->usePrismHeader(); 372 bool usePrism = configwindow->usePrismHeader();
373 373
374 switch ( cardtype ) 374 switch ( cardtype )
375 { 375 {
376 case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break; 376 case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break;
377 case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break; 377 case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break;
378 case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break; 378 case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break;
379 case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break; 379 case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break;
380 case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", tr( "Bring your device into\nmonitor mode now." ) ); break; 380 case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", tr( "Bring your device into\nmonitor mode now." ) ); break;
381 case DEVTYPE_FILE: qDebug( "Wellenreiter: Capturing from file '%s'", (const char*) interface ); break; 381 case DEVTYPE_FILE: qDebug( "Wellenreiter: Capturing from file '%s'", (const char*) interface ); break;
382 default: assert( 0 ); // shouldn't reach this 382 default: assert( 0 ); // shouldn't reach this
383 } 383 }
384 384
385 // switch device into monitor mode 385 // switch device into monitor mode
386 if ( cardtype < DEVTYPE_FILE ) 386 if ( cardtype < DEVTYPE_FILE )
387 { 387 {
388 if ( cardtype != DEVTYPE_MANUAL ) 388 if ( cardtype != DEVTYPE_MANUAL )
389 iface->setMonitorMode( true ); 389 iface->setMonitorMode( true );
390 if ( !iface->monitorMode() ) 390 if ( !iface->monitorMode() )
391 { 391 {
392 QMessageBox::warning( this, "Wellenreiter II", 392 QMessageBox::warning( this, "Wellenreiter II",
393 tr( "Can't set interface '%1'\ninto monitor mode:\n" ).arg( iface->name() ) + strerror( errno ) ); 393 tr( "Can't set interface '%1'\ninto monitor mode:\n" ).arg( iface->name() ) + strerror( errno ) );
394 return; 394 return;
395 } 395 }
396 } 396 }
397 397
398 // open pcap and start sniffing 398 // open pcap and start sniffing
399 if ( cardtype != DEVTYPE_FILE ) 399 if ( cardtype != DEVTYPE_FILE )
400 { 400 {
401 pcap->open( interface ); 401 pcap->open( interface );
402 402
403 if ( configwindow->writeCaptureFile->isOn() ) 403 if ( configwindow->writeCaptureFile->isOn() )
404 { 404 {
405 QString dumpname( configwindow->captureFileName->text() ); 405 QString dumpname( configwindow->captureFileName->text() );
406 dumpname.append( '-' ); 406 dumpname.append( '-' );
407 dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) ); 407 dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) );
408 dumpname.append( ".wellenreiter" ); 408 dumpname.append( ".wellenreiter" );
409 pcap->openDumpFile( dumpname ); 409 pcap->openDumpFile( dumpname );
410 } 410 }
411 else 411 else
412 { 412 {
413 pcap->open( interface ); 413 pcap->open( interface );
414 } 414 }
415 } 415 }
416 else 416 else
417 { 417 {
418 pcap->open( QFile( interface ) ); 418 pcap->open( QFile( interface ) );
419 } 419 }
420 420
421 if ( !pcap->isOpen() ) 421 if ( !pcap->isOpen() )
422 { 422 {
423 QMessageBox::warning( this, "Wellenreiter II", 423 QMessageBox::warning( this, "Wellenreiter II",
424 tr( "Can't open packet capturer for '%1':\n" ).arg( iface->name() ) + QString(strerror( errno ) )); 424 tr( "Can't open packet capturer for '%1':\n" ).arg( iface->name() ) + QString(strerror( errno ) ));
425 return; 425 return;
426 } 426 }
427 427
428 // set capturer to non-blocking mode 428 // set capturer to non-blocking mode
429 pcap->setBlocking( false ); 429 pcap->setBlocking( false );
430 430
431 // start channel hopper 431 // start channel hopper
432 if ( cardtype != DEVTYPE_FILE ) 432 if ( cardtype != DEVTYPE_FILE )
433 iface->setChannelHopping( 1000 ); //use interval from config window 433 iface->setChannelHopping( 1000 ); //use interval from config window
434 434
435 if ( cardtype != DEVTYPE_FILE ) 435 if ( cardtype != DEVTYPE_FILE )
436 { 436 {
437 // connect socket notifier and start channel hopper 437 // connect socket notifier and start channel hopper
438 connect( pcap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); 438 connect( pcap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
439 connect( iface->channelHopper(), SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) ); 439 connect( iface->channelHopper(), SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
440 } 440 }
441 else 441 else
442 { 442 {
443 // start timer for reading packets 443 // start timer for reading packets
444 startTimer( 100 ); 444 startTimer( 100 );
445 } 445 }
446 446
447 logwindow->log( "(i) Started Scanning." ); 447 logwindow->log( "(i) Started Scanning." );
448 sniffing = true; 448 sniffing = true;
449 emit( startedSniffing() ); 449 emit( startedSniffing() );
450 if ( cardtype != DEVTYPE_FILE ) channelHopped( 6 ); // set title 450 if ( cardtype != DEVTYPE_FILE ) channelHopped( 6 ); // set title
451 else 451 else
452 { 452 {
453 assert( parent() ); 453 assert( parent() );
454 ( (QMainWindow*) parent() )->setCaption( tr( "Wellenreiter II - replaying capture file..." ) ); 454 ( (QMainWindow*) parent() )->setCaption( tr( "Wellenreiter II - replaying capture file..." ) );
455 } 455 }
456} 456}
457 457
458 458
459void Wellenreiter::timerEvent( QTimerEvent* ) 459void Wellenreiter::timerEvent( QTimerEvent* )
460{ 460{
461 qDebug( "Wellenreiter::timerEvent()" ); 461 qDebug( "Wellenreiter::timerEvent()" );
462 OPacket* p = pcap->next(); 462 OPacket* p = pcap->next();
463 if ( !p ) // no more packets available 463 if ( !p ) // no more packets available
464 { 464 {
465 stopClicked(); 465 stopClicked();
466 } 466 }
467 else 467 else
468 { 468 {
469 receivePacket( p ); 469 receivePacket( p );
470 delete p; 470 delete p;
471 } 471 }
472} 472}
473 473
474 474
475void Wellenreiter::doAction( const QString& action, const QString& protocol, OPacket* p ) 475void Wellenreiter::doAction( const QString& action, const QString& protocol, OPacket* p )
476{ 476{
477 if ( action == "TouchSound" ) 477 if ( action == "TouchSound" )
478 ODevice::inst()->touchSound(); 478 ODevice::inst()->touchSound();
479 else if ( action == "AlarmSound" ) 479 else if ( action == "AlarmSound" )
480 ODevice::inst()->alarmSound(); 480 ODevice::inst()->alarmSound();
481 else if ( action == "KeySound" ) 481 else if ( action == "KeySound" )
482 ODevice::inst()->keySound(); 482 ODevice::inst()->keySound();
483 else if ( action == "LedOn" ) 483 else if ( action == "LedOn" )
484 ODevice::inst()->setLedState( Led_Mail, Led_On ); 484 ODevice::inst()->setLedState( Led_Mail, Led_On );
485 else if ( action == "LedOff" ) 485 else if ( action == "LedOff" )
486 ODevice::inst()->setLedState( Led_Mail, Led_Off ); 486 ODevice::inst()->setLedState( Led_Mail, Led_Off );
487 else if ( action == "LogMessage" ) 487 else if ( action == "LogMessage" )
488 logwindow->log( QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) ); 488 logwindow->log( QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) );
489 else if ( action == "MessageBox" ) 489 else if ( action == "MessageBox" )
490 QMessageBox::information ( this, "Notification!", 490 QMessageBox::information( this, "Notification!",
491 QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) ); 491 QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) );
492} 492}
493 493
494void Wellenreiter::joinNetwork(const QString& type, const QString& essid, int channel, const QString& macaddr) 494void Wellenreiter::joinNetwork(const QString& type, const QString& essid, int channel, const QString& macaddr)
495{ 495{
496 // we need the interface too: 496 if ( !iface )
497 const QString iface = "wlan0"; 497 {
498 qDebug( "joinNetwork() - %s, %s, %d, %s", 498 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "No wireless\ninterface available." ) );
499 return;
500 }
501
502 if ( sniffing )
503 {
504 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Stop sniffing before\njoining a net." ) );
505 return;
506 }
507
508 qDebug( "joinNetwork() with Interface %s: %s, %s, %d, %s",
509 (const char*) iface->name(),
499 (const char*) type, 510 (const char*) type,
500 (const char*) essid, 511 (const char*) essid,
501 channel, 512 channel,
502 (const char*) macaddr ); 513 (const char*) macaddr );
503 514
504 // TODO: Stop scanning here
505
506 QCopEnvelope msg( "QPE/Application/networksettings", "wlan(QString,QString,QString)" ); 515 QCopEnvelope msg( "QPE/Application/networksettings", "wlan(QString,QString,QString)" );
507 msg << iface << QString("Mode") << type; 516 msg << iface->name() << QString("Mode") << type;
508 msg << iface << QString("ESSID") << essid; 517 msg << iface->name() << QString("ESSID") << essid;
509 msg << iface << QString("Channel") << channel; 518 msg << iface->name() << QString("Channel") << channel;
510 msg << iface << QString("MacAddr") << macaddr; 519 msg << iface->name() << QString("MacAddr") << macaddr;
511 520
512} 521}
513 522