From 2b2620fee2bbd6f7045b237aa33c277c47512345 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Fri, 10 Oct 2003 02:24:48 +0000 Subject: This patch adds scanning the "network neighbourhood" in networksettings-wlan (powered by the Wellenreiter II scanning engine found in libopienet2). Detected networks are put in a list and you can select parameters by clicking on an entry in the list. See http://opie.net.wox.org/images/wlanplugin.png Two inherent drawbacks: 1.) networksettingsplugin-wlan now needs libopienet2. Well, my library work pays off. If you like to rewrite the stuff so that libopienet2 is not needed, then just go ahead ;) 2.) Scanning won't work on linux distributions without patched monitor mode drivers. I think we can live with these two "issues". Feel free to revert, if you don't like my work :D --- diff --git a/noncore/settings/networksettings/wlan/config.in b/noncore/settings/networksettings/wlan/config.in index 53bcb1e..e459788 100644 --- a/noncore/settings/networksettings/wlan/config.in +++ b/noncore/settings/networksettings/wlan/config.in @@ -1,4 +1,6 @@ config WLAN boolean "opie-networksettingsplugin-wlan (wireless LAN module)" default "n" if NETWORKSETUP - depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && NETWORKSETUP && NETWORKSETUP-CORE && INTERFACES + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && NETWORKSETUP && NETWORKSETUP-CORE && INTERFACES && LIBOPIE2NET + #comment "opie-networksettingsplugin-wlan needs libopie, libopie2net and networksetup" + #depends !( LIBOPIE2NET && LIBOPIE && NETWORKSETUP) \ No newline at end of file diff --git a/noncore/settings/networksettings/wlan/opie-networksettingsplugin-wlan.control b/noncore/settings/networksettings/wlan/opie-networksettingsplugin-wlan.control index 719337f..ec3078d 100644 --- a/noncore/settings/networksettings/wlan/opie-networksettingsplugin-wlan.control +++ b/noncore/settings/networksettings/wlan/opie-networksettingsplugin-wlan.control @@ -4,7 +4,7 @@ Priority: optional Section: opie/settings Maintainer: Patrick S. Vogt Architecture: arm -Depends: opie-networksettings +Depends: opie-networksettings, libopie2net (1.8.1) Description: Network settings wavelan plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings/wlan/wlan.pro b/noncore/settings/networksettings/wlan/wlan.pro index 552c669..82a5b2f 100644 --- a/noncore/settings/networksettings/wlan/wlan.pro +++ b/noncore/settings/networksettings/wlan/wlan.pro @@ -8,7 +8,7 @@ HEADERS = infoimp.h wlanmodule.h wextensions.h keyedit.h SOURCES = infoimp.cpp wlanmodule.cpp wextensions.cpp keyedit.cpp INCLUDEPATH += $(OPIEDIR)/include ../ ../interfaces/ DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe -L../interfaces/ -linterfaces +LIBS += -lqpe -L../interfaces/ -linterfaces -lopienet2 INTERFACES = wlan.ui info.ui TARGET = wlan VERSION = 1.0.0 diff --git a/noncore/settings/networksettings/wlan/wlan.ui b/noncore/settings/networksettings/wlan/wlan.ui index 7e39e23..195ead9 100644 --- a/noncore/settings/networksettings/wlan/wlan.ui +++ b/noncore/settings/networksettings/wlan/wlan.ui @@ -11,8 +11,8 @@ 0 0 - 247 - 299 + 216 + 342 @@ -45,6 +45,12 @@ enabled true + + layoutMargin + + + layoutSpacing + QWidget @@ -55,333 +61,345 @@ title General - - - name - Spacer31 - - - orientation - Vertical - - - sizeType - Expanding - - - sizeHint - - 20 - 20 - - - - - QLabel - - name - modeLabel - - - enabled - true - - - geometry - - 11 - 11 - 84 - 29 - - - - sizePolicy - - 1 - 1 - - - - text - Mode - - - - QLabel - - name - essidLabel - - - enabled - true - - - geometry - - 11 - 46 - 84 - 29 - - - - sizePolicy - - 1 - 1 - - - - text - ESS-ID - - - - QSpinBox - - name - networkChannel - - - enabled - false - - - geometry - - 146 - 139 - 58 - 25 - - - - maxValue - 15 - - - minValue - 1 - - - value - 1 - - - - QLineEdit - - name - macEdit - - - enabled - false - - - geometry - - 56 - 108 - 182 - 25 - - - - sizePolicy - - 5 - 1 - - - - - QLabel - - name - macLabel - - - enabled - false - - - geometry - - 11 - 108 - 39 - 25 - - - - text - MAC - - - - QCheckBox - - name - specifyAp - - - geometry - - 11 - 81 - 227 - 21 - - - - text - Specify &Access Point - - - - QCheckBox - - name - specifyChan - - - geometry - - 11 - 141 - 129 - 21 - - - - text - Specify &Channel - - - - - name - Spacer10 - + - orientation - Horizontal + margin + 3 - sizeType - Expanding - - - sizeHint - - 20 - 20 - + spacing + 2 - - - QComboBox - - - text - any + + QLayoutWidget + + name + Layout1 - - - name - essid - - - geometry - - 101 - 46 - 103 - 29 - - - - sizePolicy - - 7 - 0 - - - - editable - true - - - currentItem - 0 - - - sizeLimit - 5 - - - autoCompletion - true - - - duplicatesEnabled - false - - - - QComboBox - - - text - Infrastructure + + + margin + 0 + + + spacing + 6 + + + QComboBox + + + text + any + + + + name + essid + + + sizePolicy + + 7 + 0 + + + + editable + true + + + currentItem + 0 + + + sizeLimit + 5 + + + autoCompletion + true + + + duplicatesEnabled + false + + + + QLabel + + name + essidLabel + + + enabled + true + + + sizePolicy + + 1 + 1 + + + + text + SSID + + + + QComboBox + + + text + Infrastructure + + + + + text + Auto + + + + + text + Managed + + + + + text + Ad-Hoc + + + + name + mode + + + enabled + true + + + sizePolicy + + 7 + 0 + + + + + QLabel + + name + modeLabel + + + enabled + true + + + sizePolicy + + 1 + 1 + + + + text + Mode + + + + + + QCheckBox + + name + specifyAp - - - + text - Auto + Specify &Access Point - - - - text - Managed + + + QLayoutWidget + + name + Layout3 - - - + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + macLabel + + + enabled + false + + + text + MAC + + + + QLineEdit + + name + macEdit + + + enabled + false + + + sizePolicy + + 7 + 1 + + + + + + + QLayoutWidget + + name + Layout4 + + + + margin + 0 + + + spacing + 6 + + + QCheckBox + + name + specifyChan + + + text + Specify &Channel + + + + QSpinBox + + name + networkChannel + + + enabled + false + + + maxValue + 15 + + + minValue + 1 + + + value + 1 + + + + + + QPushButton + + name + rescanButton + + text - Ad-Hoc + Rescan Neighbourhood - - - name - mode - - - enabled - true - - - geometry - - 101 - 11 - 103 - 29 - - - - sizePolicy - - 1 - 0 - - - + + + QListView + + + text + + + + clickable + true + + + resizeable + true + + + + + text + SSID + + + clickable + true + + + resizeable + true + + + + + text + Chn + + + clickable + true + + + resizeable + true + + + + + text + MAC + + + clickable + true + + + resizeable + true + + + + name + netView + + + QWidget @@ -396,11 +414,11 @@ margin - 11 + 7 spacing - 6 + 3 QCheckBox diff --git a/noncore/settings/networksettings/wlan/wlanimp.cpp b/noncore/settings/networksettings/wlan/wlanimp.cpp index 8bf004f..719be1b 100644 --- a/noncore/settings/networksettings/wlan/wlanimp.cpp +++ b/noncore/settings/networksettings/wlan/wlanimp.cpp @@ -218,7 +218,7 @@ void WLANImp::accept(){ } if(essAny->isChecked() && essSpecificLineEdit->text().isEmpty()){ - QMessageBox::information(this, "Error", "Please enter a ESS-ID.", QMessageBox::Ok); + QMessageBox::information(this, "Error", "Please enter a SSID.", QMessageBox::Ok); return; } diff --git a/noncore/settings/networksettings/wlan/wlanimp2.cpp b/noncore/settings/networksettings/wlan/wlanimp2.cpp index 26e3aa9..7ce096f 100644 --- a/noncore/settings/networksettings/wlan/wlanimp2.cpp +++ b/noncore/settings/networksettings/wlan/wlanimp2.cpp @@ -2,27 +2,42 @@ #include "keyedit.h" #include "interfacesetupimp.h" +#include "../interfaces/interface.h" + +#include +#include +#include + +#include #include #include +#include #include #include #include #include #include #include +#include #include #include #include +#include +#include +#include #ifdef QWS + #include #include + #include + #include #else #define OProcess KProcess #include #endif #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" -#define PREUP "/etc/netwrok/if-pre-up.d/wireless-tools" +#define PREUP "/etc/network/if-pre-up.d/wireless-tools" /** * Constructor, read in the wireless.opts file for parsing later. @@ -37,6 +52,13 @@ WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, W if (file.exists()) { qWarning(QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools")); } + + connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) ); + connect( netView, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectNetwork( QListViewItem* ) ) ); + netView->setColumnAlignment( col_chn, AlignCenter ); + netView->setItemMargin( 3 ); + netView->setAllColumnsShowFocus( true ); + } WLANImp::~WLANImp() { @@ -274,3 +296,195 @@ void WLANImp::writeOpts() { QDialog::accept(); } + +/* + * Scan for possible wireless networks around... + * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer + */ + +void WLANImp::rescanNeighbourhood() +{ + QString name = interface->getInterfaceName(); + qDebug( "rescanNeighbourhood via '%s'", (const char*) name ); + + OWirelessNetworkInterface* wiface = static_cast( ONetwork::instance()->interface( name ) ); + assert( wiface ); + + // try to guess device type + QString devicetype; + QFile m( "/proc/modules" ); + if ( m.open( IO_ReadOnly ) ) + { + QString line; + QTextStream modules( &m ); + while( !modules.atEnd() && !devicetype ) + { + modules >> line; + if ( line.contains( "cisco" ) ) devicetype = "cisco"; + else if ( line.contains( "hostap" ) ) devicetype = "hostap"; + else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */ + else if ( line.contains( "orinoco" ) ) devicetype = "orinoco"; + } + } + if ( devicetype.isEmpty() ) + { + qWarning( "rescanNeighbourhood(): couldn't guess device type :(" ); + return; + } + else + { + qDebug( "rescanNeighbourhood(): device type seems to be '%s'", (const char*) devicetype ); + } + + // configure interface to receive 802.11 management frames + + wiface->setUp( true ); + wiface->setPromiscuousMode( true ); + + if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) ); + else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) ); + else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) ); + else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) ); + else + { + qDebug( "rescanNeighbourhood(): unsupported device type for monitoring :(" ); + return; + } + + wiface->setMonitorMode( true ); + if ( !wiface->monitorMode() ) + { + qWarning( "rescanNeighbourhood(): Unable to bring device into monitor mode (%s).", strerror( errno ) ); + return; + } + + // open a packet capturer + OPacketCapturer* cap = new OPacketCapturer(); + cap->open( name ); + if ( !cap->isOpen() ) + { + qWarning( "rescanNeighbourhood(): Unable to open libpcap (%s).", strerror( errno ) ); + return; + } + + // display splash screen + QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize ); + splash->setLineWidth( 2 ); + splash->setFrameStyle( QFrame::Panel | QFrame::Raised ); + QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 ); + QLabel* lab = new QLabel( "
Scanning...
Please Wait...
", splash ); + QProgressBar* pb = new QProgressBar( wiface->channels(), splash ); + vbox->addWidget( lab ); + vbox->addWidget( pb ); + pb->setCenterIndicator( true ); + pb->setFixedHeight( pb->sizeHint().height() ); + QWidget* widgetDesktop = qApp->desktop(); + int dw = widgetDesktop->width(); + int dh = widgetDesktop->height(); + int pw = vbox->sizeHint().width(); + int ph = vbox->sizeHint().height(); + splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph); + splash->show(); + splash->raise(); + qApp->processEvents(); + + // set capturer to non-blocking mode + cap->setBlocking( false ); + + for ( int i = 1; i <= wiface->channels(); ++i ) + { + wiface->setChannel( i ); + pb->setProgress( i ); + qApp->processEvents(); + qDebug( "rescanNeighbourhood(): listening on channel %d...", i ); + OPacket* p = cap->next( 1000 ); + if ( !p ) + { + qDebug( "rescanNeighbourhood(): nothing received on channel %d", i ); + } + else + { + qDebug( "rescanNeighbourhood(): TADAA - something came in on channel %d", i ); + handlePacket( p ); + } + } + + cap->close(); + wiface->setMonitorMode( false ); + wiface->setPromiscuousMode( true ); + + splash->hide(); + delete splash; + +} + +void WLANImp::handlePacket( OPacket* p ) +{ + + // check if we received a beacon frame + OWaveLanManagementPacket* beacon = static_cast( p->child( "802.11 Management" ) ); + if ( beacon && beacon->managementType() == "Beacon" ) + { + + QString type; + if ( beacon->canIBSS() ) + { + type = "adhoc"; + } + else if ( beacon->canESS() ) + { + type = "managed"; + } + else + { + qWarning( "handlePacket(): invalid frame [possibly noise] detected!" ); + return; + } + + OWaveLanManagementSSID* ssid = static_cast( p->child( "802.11 SSID" ) ); + QString essid = ssid ? ssid->ID() : QString(""); + OWaveLanManagementDS* ds = static_cast( p->child( "802.11 DS" ) ); + int channel = ds ? ds->channel() : -1; + OWaveLanPacket* header = static_cast( p->child( "802.11" ) ); + displayFoundNetwork( type, channel, essid, header->macAddress2() ); + } +} + + +void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac ) +{ + + qDebug( "found network: <%s>, chn %d, ssid '%s', mac '%s'", (const char*) mode, channel, + (const char*) ssid, + (const char*) mac.toString() ); + + QListViewItemIterator it( netView ); + while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it; + if ( !it.current() ) // ssid didn't show up yet + { + QListViewItem* item = new QListViewItem( netView, mode.left( 1 ).upper(), ssid, QString::number( channel ), mac.toString() ); + QString name; + name.sprintf( "networksettings/%s", (const char*) mode ); + item->setPixmap( col_mode, Resource::loadPixmap( name ) ); + qApp->processEvents(); + } + +} + + +void WLANImp::selectNetwork( QListViewItem* item ) +{ + bool ok; + if ( item ) + { + specifyAp->setChecked(true); + macEdit->setText( item->text( col_mac ) ); + specifyChan->setChecked( item->text( col_mode ) == "A" ); + networkChannel->setValue( item->text( col_chn ).toInt( &ok ) ); + essid->setEditText( item->text( col_ssid ) ); + if ( item->text( col_mode ) == "A" ) + mode->setCurrentItem( 3 ); + else + mode->setCurrentItem( 2 ); + } +} diff --git a/noncore/settings/networksettings/wlan/wlanimp2.h b/noncore/settings/networksettings/wlan/wlanimp2.h index 992d09a..a777203 100644 --- a/noncore/settings/networksettings/wlan/wlanimp2.h +++ b/noncore/settings/networksettings/wlan/wlanimp2.h @@ -4,12 +4,20 @@ #include "wlan.h" #include "interfaces.h" #include +#include class InterfaceSetupImp; class Interface; class Config; +class OPacket; +class QListViewItem; -class WLANImp : public WLAN { +const int col_mode= 0; +const int col_ssid = 1; +const int col_chn = 2; +const int col_mac = 3; + +class WLANImp : public WLAN { Q_OBJECT public: @@ -17,6 +25,10 @@ public: ~WLANImp(); void setProfile(const QString &profile); +public slots: + void rescanNeighbourhood(); + void selectNetwork( QListViewItem* ); + protected: void accept(); @@ -25,7 +37,10 @@ private: void writeOpts(); void parseKeyStr(QString keystr); - + + void handlePacket( OPacket* ); + void displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac ); + InterfaceSetupImp *interfaceSetup; Interfaces *interfaces; Interface *interface; @@ -34,4 +49,4 @@ private: }; #endif - + diff --git a/pics/networksettings/adhoc.png b/pics/networksettings/adhoc.png new file mode 100644 index 0000000..dcf5ad2 --- a/dev/null +++ b/pics/networksettings/adhoc.png Binary files differ diff --git a/pics/networksettings/managed.png b/pics/networksettings/managed.png new file mode 100644 index 0000000..4554533 --- a/dev/null +++ b/pics/networksettings/managed.png Binary files differ -- cgit v0.9.0.2