summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/wlan/wlanimp2.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/wlan/wlanimp2.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp2.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/noncore/settings/networksettings/wlan/wlanimp2.cpp b/noncore/settings/networksettings/wlan/wlanimp2.cpp
index eeebe7f..e483efe 100644
--- a/noncore/settings/networksettings/wlan/wlanimp2.cpp
+++ b/noncore/settings/networksettings/wlan/wlanimp2.cpp
@@ -31,49 +31,49 @@
31 #include <opie2/oprocess.h> 31 #include <opie2/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 */
45using namespace Opie::Net; 45using namespace Opie::Net;
46using namespace Opie::Core; 46using namespace Opie::Core;
47WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") { 47WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") {
48 interfaces = new Interfaces(); 48 interfaces = new Interfaces();
49 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces); 49 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces);
50 tabWidget->insertTab(interfaceSetup, "TCP/IP"); 50 tabWidget->insertTab(interfaceSetup, "TCP/IP");
51 51
52 // Check sanity - the existance of the wireless-tools if-pre-up script 52 // Check sanity - the existance of the wireless-tools if-pre-up script
53 QFile file(QString(PREUP)); 53 QFile file(QString(PREUP));
54 if (file.exists()) { 54 if (file.exists()) {
55 qWarning(QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools")); 55 owarn << QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools") << oendl;
56 } 56 }
57 57
58 connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) ); 58 connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) );
59 connect( netView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( selectNetwork(QListViewItem*) ) ); 59 connect( netView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( selectNetwork(QListViewItem*) ) );
60 netView->setColumnAlignment( col_chn, AlignCenter ); 60 netView->setColumnAlignment( col_chn, AlignCenter );
61 netView->setItemMargin( 3 ); 61 netView->setItemMargin( 3 );
62 netView->setAllColumnsShowFocus( true ); 62 netView->setAllColumnsShowFocus( true );
63 63
64} 64}
65 65
66WLANImp::~WLANImp() { 66WLANImp::~WLANImp() {
67//FIXME: delete interfaces; 67//FIXME: delete interfaces;
68} 68}
69 69
70/** 70/**
71 * Change the profile for both wireless settings and network settings. 71 * Change the profile for both wireless settings and network settings.
72 */ 72 */
73void WLANImp::setProfile(const QString &profile){ 73void WLANImp::setProfile(const QString &profile){
74 interfaceSetup->setProfile(profile); 74 interfaceSetup->setProfile(profile);
75 parseOpts(); 75 parseOpts();
76} 76}
77 77
78void WLANImp::parseOpts() { 78void WLANImp::parseOpts() {
79 bool error; 79 bool error;
@@ -212,49 +212,49 @@ void WLANImp::accept() {
212 QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok); 212 QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok);
213 return; 213 return;
214 } 214 }
215 215
216 if (specifyAp->isChecked() && macEdit->text().isEmpty()) { 216 if (specifyAp->isChecked() && macEdit->text().isEmpty()) {
217 QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok); 217 QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok);
218 return; 218 return;
219 } 219 }
220 220
221 // Try to save the interfaces settings. 221 // Try to save the interfaces settings.
222 writeOpts(); 222 writeOpts();
223 223
224 // Close out the dialog 224 // Close out the dialog
225// FIXME: QDialog::accept(); 225// FIXME: QDialog::accept();
226} 226}
227 227
228void WLANImp::writeOpts() { 228void WLANImp::writeOpts() {
229 // eh can't really do anything about it other then return. :-D 229 // eh can't really do anything about it other then return. :-D
230 if(!interfaces->isInterfaceSet()){ 230 if(!interfaces->isInterfaceSet()){
231 QMessageBox::warning(0,"Inface not set","should not happen!!!"); 231 QMessageBox::warning(0,"Inface not set","should not happen!!!");
232 return; 232 return;
233 } 233 }
234 bool error = false; 234 bool error = false;
235 235
236 qDebug("setting wlan interface %s", interfaces->getInterfaceName( error ).latin1() ); 236 odebug << "setting wlan interface " << interfaces->getInterfaceName( error ).latin1() << "" << oendl;
237 237
238 if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!"); 238 if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!");
239 239
240 interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText()); 240 interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText());
241 interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText()); 241 interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText());
242 242
243 if (specifyAp->isChecked()) { 243 if (specifyAp->isChecked()) {
244 interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text()); 244 interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text());
245 } else { 245 } else {
246 interfaces->removeInterfaceOption(QString("wireless_ap")); 246 interfaces->removeInterfaceOption(QString("wireless_ap"));
247 } 247 }
248 248
249 if (specifyChan->isChecked()) { 249 if (specifyChan->isChecked()) {
250 interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text()); 250 interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text());
251 } else { 251 } else {
252 interfaces->removeInterfaceOption(QString("wireless_channel")); 252 interfaces->removeInterfaceOption(QString("wireless_channel"));
253 } 253 }
254 254
255 if (wepEnabled->isChecked()) { 255 if (wepEnabled->isChecked()) {
256 QStringList keyList; 256 QStringList keyList;
257 257
258 if (! keyLineEdit0->text().isNull()) { 258 if (! keyLineEdit0->text().isNull()) {
259 keyList += keyLineEdit0->text(); 259 keyList += keyLineEdit0->text();
260 keyList += "[1]"; 260 keyList += "[1]";
@@ -286,181 +286,181 @@ void WLANImp::writeOpts() {
286 keyList += "[3]"; 286 keyList += "[3]";
287 } else if (keyRadio3->isChecked()) { 287 } else if (keyRadio3->isChecked()) {
288 keyList += "[4]"; 288 keyList += "[4]";
289 } 289 }
290 interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" "))); 290 interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" ")));
291 } else { 291 } else {
292 interfaces->removeInterfaceOption(QString("wireless_key")); 292 interfaces->removeInterfaceOption(QString("wireless_key"));
293 } 293 }
294 interfaces->removeInterfaceOption(QString("wireless_enc")); 294 interfaces->removeInterfaceOption(QString("wireless_enc"));
295 295
296 if(!interfaceSetup->saveChanges()) 296 if(!interfaceSetup->saveChanges())
297 return; 297 return;
298 298
299 QDialog::accept(); 299 QDialog::accept();
300} 300}
301 301
302/* 302/*
303 * Scan for possible wireless networks around... 303 * Scan for possible wireless networks around...
304 * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org> 304 * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org>
305 */ 305 */
306 306
307void WLANImp::rescanNeighbourhood() 307void WLANImp::rescanNeighbourhood()
308{ 308{
309 QString name = interface->getInterfaceName(); 309 QString name = interface->getInterfaceName();
310 qDebug( "rescanNeighbourhood via '%s'", (const char*) name ); 310 odebug << "rescanNeighbourhood via '" << (const char*) name << "'" << oendl;
311 311
312 OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( ONetwork::instance()->interface( name ) ); 312 OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( ONetwork::instance()->interface( name ) );
313 assert( wiface ); 313 assert( wiface );
314 314
315 // try to guess device type 315 // try to guess device type
316 QString devicetype; 316 QString devicetype;
317 QFile m( "/proc/modules" ); 317 QFile m( "/proc/modules" );
318 if ( m.open( IO_ReadOnly ) ) 318 if ( m.open( IO_ReadOnly ) )
319 { 319 {
320 QString line; 320 QString line;
321 QTextStream modules( &m ); 321 QTextStream modules( &m );
322 while( !modules.atEnd() && !devicetype ) 322 while( !modules.atEnd() && !devicetype )
323 { 323 {
324 modules >> line; 324 modules >> line;
325 if ( line.contains( "cisco" ) ) devicetype = "cisco"; 325 if ( line.contains( "cisco" ) ) devicetype = "cisco";
326 else if ( line.contains( "hostap" ) ) devicetype = "hostap"; 326 else if ( line.contains( "hostap" ) ) devicetype = "hostap";
327 else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */ 327 else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */
328 else if ( line.contains( "orinoco" ) ) devicetype = "orinoco"; 328 else if ( line.contains( "orinoco" ) ) devicetype = "orinoco";
329 } 329 }
330 } 330 }
331 if ( devicetype.isEmpty() ) 331 if ( devicetype.isEmpty() )
332 { 332 {
333 qWarning( "rescanNeighbourhood(): couldn't guess device type :(" ); 333 owarn << "rescanNeighbourhood(): couldn't guess device type :(" << oendl;
334 return; 334 return;
335 } 335 }
336 else 336 else
337 { 337 {
338 qDebug( "rescanNeighbourhood(): device type seems to be '%s'", (const char*) devicetype ); 338 odebug << "rescanNeighbourhood(): device type seems to be '" << (const char*) devicetype << "'" << oendl;
339 } 339 }
340 340
341 // configure interface to receive 802.11 management frames 341 // configure interface to receive 802.11 management frames
342 342
343 wiface->setUp( true ); 343 wiface->setUp( true );
344 wiface->setPromiscuousMode( true ); 344 wiface->setPromiscuousMode( true );
345 345
346 if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) ); 346 if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) );
347 else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) ); 347 else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) );
348 else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) ); 348 else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) );
349 else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) ); 349 else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) );
350 else 350 else
351 { 351 {
352 qDebug( "rescanNeighbourhood(): unsupported device type for monitoring :(" ); 352 odebug << "rescanNeighbourhood(): unsupported device type for monitoring :(" << oendl;
353 return; 353 return;
354 } 354 }
355 355
356 wiface->setMode( "monitor" ); 356 wiface->setMode( "monitor" );
357 if ( wiface->mode() != "monitor" ) 357 if ( wiface->mode() != "monitor" )
358 { 358 {
359 qWarning( "rescanNeighbourhood(): Unable to bring device into monitor mode (%s).", strerror( errno ) ); 359 owarn << "rescanNeighbourhood(): Unable to bring device into monitor mode (" << strerror( errno ) << ")." << oendl;
360 return; 360 return;
361 } 361 }
362 362
363 // open a packet capturer 363 // open a packet capturer
364 OPacketCapturer* cap = new OPacketCapturer(); 364 OPacketCapturer* cap = new OPacketCapturer();
365 cap->open( name ); 365 cap->open( name );
366 if ( !cap->isOpen() ) 366 if ( !cap->isOpen() )
367 { 367 {
368 qWarning( "rescanNeighbourhood(): Unable to open libpcap (%s).", strerror( errno ) ); 368 owarn << "rescanNeighbourhood(): Unable to open libpcap (" << strerror( errno ) << ")." << oendl;
369 return; 369 return;
370 } 370 }
371 371
372 // display splash screen 372 // display splash screen
373 QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize ); 373 QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize );
374 splash->setLineWidth( 2 ); 374 splash->setLineWidth( 2 );
375 splash->setFrameStyle( QFrame::Panel | QFrame::Raised ); 375 splash->setFrameStyle( QFrame::Panel | QFrame::Raised );
376 QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 ); 376 QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 );
377 QLabel* lab = new QLabel( "<center><b>Scanning...</b><br>Please Wait...</center>", splash ); 377 QLabel* lab = new QLabel( "<center><b>Scanning...</b><br>Please Wait...</center>", splash );
378 QProgressBar* pb = new QProgressBar( wiface->channels(), splash ); 378 QProgressBar* pb = new QProgressBar( wiface->channels(), splash );
379 vbox->addWidget( lab ); 379 vbox->addWidget( lab );
380 vbox->addWidget( pb ); 380 vbox->addWidget( pb );
381 pb->setCenterIndicator( true ); 381 pb->setCenterIndicator( true );
382 pb->setFixedHeight( pb->sizeHint().height() ); 382 pb->setFixedHeight( pb->sizeHint().height() );
383 QWidget* widgetDesktop = qApp->desktop(); 383 QWidget* widgetDesktop = qApp->desktop();
384 int dw = widgetDesktop->width(); 384 int dw = widgetDesktop->width();
385 int dh = widgetDesktop->height(); 385 int dh = widgetDesktop->height();
386 int pw = vbox->sizeHint().width(); 386 int pw = vbox->sizeHint().width();
387 int ph = vbox->sizeHint().height(); 387 int ph = vbox->sizeHint().height();
388 splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph); 388 splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph);
389 splash->show(); 389 splash->show();
390 splash->raise(); 390 splash->raise();
391 qApp->processEvents(); 391 qApp->processEvents();
392 392
393 // set capturer to non-blocking mode 393 // set capturer to non-blocking mode
394 cap->setBlocking( false ); 394 cap->setBlocking( false );
395 395
396 for ( int i = 1; i <= wiface->channels(); ++i ) 396 for ( int i = 1; i <= wiface->channels(); ++i )
397 { 397 {
398 wiface->setChannel( i ); 398 wiface->setChannel( i );
399 pb->setProgress( i ); 399 pb->setProgress( i );
400 qApp->processEvents(); 400 qApp->processEvents();
401 qDebug( "rescanNeighbourhood(): listening on channel %d...", i ); 401 odebug << "rescanNeighbourhood(): listening on channel " << i << "..." << oendl;
402 OPacket* p = cap->next( 1000 ); 402 OPacket* p = cap->next( 1000 );
403 if ( !p ) 403 if ( !p )
404 { 404 {
405 qDebug( "rescanNeighbourhood(): nothing received on channel %d", i ); 405 odebug << "rescanNeighbourhood(): nothing received on channel " << i << "" << oendl;
406 } 406 }
407 else 407 else
408 { 408 {
409 qDebug( "rescanNeighbourhood(): TADAA - something came in on channel %d", i ); 409 odebug << "rescanNeighbourhood(): TADAA - something came in on channel " << i << "" << oendl;
410 handlePacket( p ); 410 handlePacket( p );
411 } 411 }
412 } 412 }
413 413
414 cap->close(); 414 cap->close();
415 wiface->setMode( "managed" ); // TODO: use previous mode 415 wiface->setMode( "managed" ); // TODO: use previous mode
416 wiface->setPromiscuousMode( false ); 416 wiface->setPromiscuousMode( false );
417 417
418 splash->hide(); 418 splash->hide();
419 delete splash; 419 delete splash;
420 420
421} 421}
422 422
423void WLANImp::handlePacket( OPacket* p ) 423void WLANImp::handlePacket( OPacket* p )
424{ 424{
425 425
426 // check if we received a beacon frame 426 // check if we received a beacon frame
427 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) ); 427 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) );
428 if ( beacon && beacon->managementType() == "Beacon" ) 428 if ( beacon && beacon->managementType() == "Beacon" )
429 { 429 {
430 430
431 QString type; 431 QString type;
432 if ( beacon->canIBSS() ) 432 if ( beacon->canIBSS() )
433 { 433 {
434 type = "adhoc"; 434 type = "adhoc";
435 } 435 }
436 else if ( beacon->canESS() ) 436 else if ( beacon->canESS() )
437 { 437 {
438 type = "managed"; 438 type = "managed";
439 } 439 }
440 else 440 else
441 { 441 {
442 qWarning( "handlePacket(): invalid frame [possibly noise] detected!" ); 442 owarn << "handlePacket(): invalid frame [possibly noise] detected!" << oendl;
443 return; 443 return;
444 } 444 }
445 445
446 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 446 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
447 QString essid = ssid ? ssid->ID() : QString("<unknown>"); 447 QString essid = ssid ? ssid->ID() : QString("<unknown>");
448 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); 448 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
449 int channel = ds ? ds->channel() : -1; 449 int channel = ds ? ds->channel() : -1;
450 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 450 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
451 displayFoundNetwork( type, channel, essid, header->macAddress2() ); 451 displayFoundNetwork( type, channel, essid, header->macAddress2() );
452 } 452 }
453} 453}
454 454
455 455
456void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac ) 456void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac )
457{ 457{
458 458
459 qDebug( "found network: <%s>, chn %d, ssid '%s', mac '%s'", (const char*) mode, channel, 459 qDebug( "found network: <%s>, chn %d, ssid '%s', mac '%s'", (const char*) mode, channel,
460 (const char*) ssid, 460 (const char*) ssid,
461 (const char*) mac.toString() ); 461 (const char*) mac.toString() );
462 462
463 QListViewItemIterator it( netView ); 463 QListViewItemIterator it( netView );
464 while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it; 464 while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it;
465 if ( !it.current() ) // ssid didn't show up yet 465 if ( !it.current() ) // ssid didn't show up yet
466 { 466 {