author | mickeyl <mickeyl> | 2003-10-10 02:24:48 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-10 02:24:48 (UTC) |
commit | 2b2620fee2bbd6f7045b237aa33c277c47512345 (patch) (side-by-side diff) | |
tree | 31f92a166da4ae596d55fe5079f058dd4a16fce4 | |
parent | c1a897e63513c9647666970794c1684b2439501e (diff) | |
download | opie-2b2620fee2bbd6f7045b237aa33c277c47512345.zip opie-2b2620fee2bbd6f7045b237aa33c277c47512345.tar.gz opie-2b2620fee2bbd6f7045b237aa33c277c47512345.tar.bz2 |
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
-rw-r--r-- | noncore/settings/networksettings/wlan/config.in | 4 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/opie-networksettingsplugin-wlan.control | 2 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlan.pro | 2 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlan.ui | 402 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanimp.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanimp2.cpp | 216 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanimp2.h | 15 | ||||
-rw-r--r-- | pics/networksettings/adhoc.png | bin | 0 -> 694 bytes | |||
-rw-r--r-- | pics/networksettings/managed.png | bin | 0 -> 410 bytes |
9 files changed, 446 insertions, 197 deletions
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 @@ -1,10 +1,10 @@ Package: opie-networksettingsplugin-wlan Files: plugins/networksettings/libwlan.so* Priority: optional Section: opie/settings Maintainer: Patrick S. Vogt <tille@handhelds.org> 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 @@ -1,28 +1,28 @@ # TEMPLATE = lib #TEMPLATE = app CONFIG += qt warn_on release #CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/plugins/networksettings 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 #CONFIG += wirelessopts wirelessopts { HEADERS += wlanimp.h SOURCES += wlanimp.cpp } ! wirelessopts { HEADERS += wlanimp2.h SOURCES += wlanimp2.cpp } include ( $(OPIEDIR)/include.pro ) 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 @@ -1,467 +1,485 @@ <!DOCTYPE UI><UI> <class>WLAN</class> <widget> <class>QDialog</class> <property stdset="1"> <name>name</name> <cstring>WLAN</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>247</width> - <height>299</height> + <width>216</width> + <height>342</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Wireless Configuration</string> </property> <property stdset="1"> <name>sizeGripEnabled</name> <bool>true</bool> </property> <property> <name>layoutMargin</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QTabWidget</class> <property stdset="1"> <name>name</name> <cstring>tabWidget</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>true</bool> </property> + <property> + <name>layoutMargin</name> + </property> + <property> + <name>layoutSpacing</name> + </property> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>ConfigPage</cstring> </property> <attribute> <name>title</name> <string>General</string> </attribute> - <spacer> - <property> + <vbox> + <property stdset="1"> + <name>margin</name> + <number>3</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>2</number> + </property> + <widget> + <class>QLayoutWidget</class> + <property stdset="1"> <name>name</name> - <cstring>Spacer31</cstring> + <cstring>Layout1</cstring> </property> + <grid> <property stdset="1"> - <name>orientation</name> - <enum>Vertical</enum> + <name>margin</name> + <number>0</number> </property> <property stdset="1"> - <name>sizeType</name> - <enum>Expanding</enum> + <name>spacing</name> + <number>6</number> </property> + <widget row="1" column="1" > + <class>QComboBox</class> + <item> <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> + <name>text</name> + <string>any</string> </property> - </spacer> - <widget> - <class>QLabel</class> + </item> <property stdset="1"> <name>name</name> - <cstring>modeLabel</cstring> + <cstring>essid</cstring> </property> <property stdset="1"> - <name>enabled</name> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>editable</name> <bool>true</bool> </property> <property stdset="1"> - <name>geometry</name> - <rect> - <x>11</x> - <y>11</y> - <width>84</width> - <height>29</height> - </rect> + <name>currentItem</name> + <number>0</number> </property> <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>1</hsizetype> - <vsizetype>1</vsizetype> - </sizepolicy> + <name>sizeLimit</name> + <number>5</number> </property> <property stdset="1"> - <name>text</name> - <string>Mode</string> + <name>autoCompletion</name> + <bool>true</bool> + </property> + <property stdset="1"> + <name>duplicatesEnabled</name> + <bool>false</bool> </property> </widget> - <widget> + <widget row="1" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>essidLabel</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>true</bool> </property> <property stdset="1"> - <name>geometry</name> - <rect> - <x>11</x> - <y>46</y> - <width>84</width> - <height>29</height> - </rect> - </property> - <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>1</hsizetype> <vsizetype>1</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> - <string>ESS-ID</string> + <string>SSID</string> </property> </widget> - <widget> - <class>QSpinBox</class> - <property stdset="1"> - <name>name</name> - <cstring>networkChannel</cstring> - </property> - <property stdset="1"> - <name>enabled</name> - <bool>false</bool> - </property> - <property stdset="1"> - <name>geometry</name> - <rect> - <x>146</x> - <y>139</y> - <width>58</width> - <height>25</height> - </rect> + <widget row="0" column="1" > + <class>QComboBox</class> + <item> + <property> + <name>text</name> + <string>Infrastructure</string> </property> - <property stdset="1"> - <name>maxValue</name> - <number>15</number> + </item> + <item> + <property> + <name>text</name> + <string>Auto</string> </property> - <property stdset="1"> - <name>minValue</name> - <number>1</number> + </item> + <item> + <property> + <name>text</name> + <string>Managed</string> </property> - <property stdset="1"> - <name>value</name> - <number>1</number> + </item> + <item> + <property> + <name>text</name> + <string>Ad-Hoc</string> </property> - </widget> - <widget> - <class>QLineEdit</class> + </item> <property stdset="1"> <name>name</name> - <cstring>macEdit</cstring> + <cstring>mode</cstring> </property> <property stdset="1"> <name>enabled</name> - <bool>false</bool> - </property> - <property stdset="1"> - <name>geometry</name> - <rect> - <x>56</x> - <y>108</y> - <width>182</width> - <height>25</height> - </rect> + <bool>true</bool> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> - <hsizetype>5</hsizetype> - <vsizetype>1</vsizetype> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> </sizepolicy> </property> </widget> - <widget> + <widget row="0" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>macLabel</cstring> + <cstring>modeLabel</cstring> </property> <property stdset="1"> <name>enabled</name> - <bool>false</bool> + <bool>true</bool> </property> <property stdset="1"> - <name>geometry</name> - <rect> - <x>11</x> - <y>108</y> - <width>39</width> - <height>25</height> - </rect> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> </property> <property stdset="1"> <name>text</name> - <string>MAC</string> + <string>Mode</string> </property> </widget> + </grid> + </widget> <widget> <class>QCheckBox</class> <property stdset="1"> <name>name</name> <cstring>specifyAp</cstring> </property> <property stdset="1"> - <name>geometry</name> - <rect> - <x>11</x> - <y>81</y> - <width>227</width> - <height>21</height> - </rect> - </property> - <property stdset="1"> <name>text</name> <string>Specify &Access Point</string> </property> </widget> <widget> - <class>QCheckBox</class> + <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>specifyChan</cstring> + <cstring>Layout3</cstring> </property> + <hbox> <property stdset="1"> - <name>geometry</name> - <rect> - <x>11</x> - <y>141</y> - <width>129</width> - <height>21</height> - </rect> + <name>margin</name> + <number>0</number> </property> <property stdset="1"> - <name>text</name> - <string>Specify &Channel</string> + <name>spacing</name> + <number>6</number> </property> - </widget> - <spacer> - <property> + <widget> + <class>QLabel</class> + <property stdset="1"> <name>name</name> - <cstring>Spacer10</cstring> + <cstring>macLabel</cstring> </property> <property stdset="1"> - <name>orientation</name> - <enum>Horizontal</enum> + <name>enabled</name> + <bool>false</bool> </property> <property stdset="1"> - <name>sizeType</name> - <enum>Expanding</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - <widget> - <class>QComboBox</class> - <item> - <property> <name>text</name> - <string>any</string> + <string>MAC</string> </property> - </item> + </widget> + <widget> + <class>QLineEdit</class> <property stdset="1"> <name>name</name> - <cstring>essid</cstring> + <cstring>macEdit</cstring> </property> <property stdset="1"> - <name>geometry</name> - <rect> - <x>101</x> - <y>46</y> - <width>103</width> - <height>29</height> - </rect> + <name>enabled</name> + <bool>false</bool> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> - <vsizetype>0</vsizetype> + <vsizetype>1</vsizetype> </sizepolicy> </property> + </widget> + </hbox> + </widget> + <widget> + <class>QLayoutWidget</class> <property stdset="1"> - <name>editable</name> - <bool>true</bool> + <name>name</name> + <cstring>Layout4</cstring> </property> + <hbox> <property stdset="1"> - <name>currentItem</name> + <name>margin</name> <number>0</number> </property> <property stdset="1"> - <name>sizeLimit</name> - <number>5</number> + <name>spacing</name> + <number>6</number> </property> + <widget> + <class>QCheckBox</class> <property stdset="1"> - <name>autoCompletion</name> - <bool>true</bool> + <name>name</name> + <cstring>specifyChan</cstring> </property> <property stdset="1"> - <name>duplicatesEnabled</name> + <name>text</name> + <string>Specify &Channel</string> + </property> + </widget> + <widget> + <class>QSpinBox</class> + <property stdset="1"> + <name>name</name> + <cstring>networkChannel</cstring> + </property> + <property stdset="1"> + <name>enabled</name> <bool>false</bool> </property> + <property stdset="1"> + <name>maxValue</name> + <number>15</number> + </property> + <property stdset="1"> + <name>minValue</name> + <number>1</number> + </property> + <property stdset="1"> + <name>value</name> + <number>1</number> + </property> + </widget> + </hbox> </widget> <widget> - <class>QComboBox</class> - <item> - <property> + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>rescanButton</cstring> + </property> + <property stdset="1"> <name>text</name> - <string>Infrastructure</string> + <string>Rescan Neighbourhood</string> </property> - </item> - <item> + </widget> + <widget> + <class>QListView</class> + <column> <property> <name>text</name> - <string>Auto</string> + <string></string> </property> - </item> - <item> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> <property> <name>text</name> - <string>Managed</string> + <string>SSID</string> </property> - </item> - <item> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> <property> <name>text</name> - <string>Ad-Hoc</string> + <string>Chn</string> </property> - </item> - <property stdset="1"> - <name>name</name> - <cstring>mode</cstring> + <property> + <name>clickable</name> + <bool>true</bool> </property> - <property stdset="1"> - <name>enabled</name> + <property> + <name>resizeable</name> <bool>true</bool> </property> - <property stdset="1"> - <name>geometry</name> - <rect> - <x>101</x> - <y>11</y> - <width>103</width> - <height>29</height> - </rect> + </column> + <column> + <property> + <name>text</name> + <string>MAC</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> </property> + </column> <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>1</hsizetype> - <vsizetype>0</vsizetype> - </sizepolicy> + <name>name</name> + <cstring>netView</cstring> </property> </widget> + </vbox> </widget> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>WepPage</cstring> </property> <attribute> <name>title</name> <string>Encryption</string> </attribute> <grid> <property stdset="1"> <name>margin</name> - <number>11</number> + <number>7</number> </property> <property stdset="1"> <name>spacing</name> - <number>6</number> + <number>3</number> </property> <widget row="0" column="0" > <class>QCheckBox</class> <property stdset="1"> <name>name</name> <cstring>wepEnabled</cstring> </property> <property stdset="1"> <name>text</name> <string>&Enable Encryption</string> </property> </widget> <widget row="1" column="0" > <class>QButtonGroup</class> <property stdset="1"> <name>name</name> <cstring>KeyButtonGroup</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>title</name> <string>&Key Setting</string> </property> <grid> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget row="0" column="0" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>keyRadio0</cstring> </property> <property stdset="1"> <name>text</name> <string>Key &1</string> </property> <property stdset="1"> <name>checked</name> <bool>true</bool> </property> </widget> <widget row="1" column="0" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>keyRadio1</cstring> </property> <property stdset="1"> <name>text</name> <string>Key &2</string> </property> </widget> <widget row="2" column="0" > <class>QRadioButton</class> <property stdset="1"> 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 @@ -157,88 +157,88 @@ void WLANImp::changeAndSaveSettingFile(){ QString line = (*it).simplifyWhiteSpace(); if(line.contains("case")) foundCase = true; // See if we found our scheme to write or the sceme couldn't be found if((foundCase && line.contains("esac") && !found) || (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ // write out scheme found = true; output = false; if(!line.contains("esac")) stream << line << "\n"; if(!essAny->isChecked() == true){ stream << "\tESSID=any\n"; stream << "\tMODE=Managed\n"; } else{ stream << "\tESSID=" << essSpecificLineEdit->text() << '\n'; stream << "\tMODE=" << ( networkType->currentItem() == 0 ? "Managed" : "ad-hoc") << '\n'; stream << "\tCHANNEL=" << networkChannel->value() << "\n"; } stream << "\t#KEY0=" << keyLineEdit0->text() << "\n"; stream << "\t#KEY1=" << keyLineEdit1->text() << "\n"; stream << "\t#KEY2=" << keyLineEdit2->text() << "\n"; stream << "\t#KEY3=" << keyLineEdit3->text() << "\n"; if(wepEnabled->isChecked()){ stream << "\tKEY=\""; if(keyRadio0->isChecked()) stream << keyLineEdit0->text(); if(keyRadio1->isChecked()) stream << keyLineEdit1->text(); if(keyRadio2->isChecked()) stream << keyLineEdit2->text(); if(keyRadio3->isChecked()) stream << keyLineEdit3->text(); if(authOpen->isChecked()) stream << " open"; else stream << " restricted"; stream << "\"\n"; } stream << "\tRATE=auto\n"; if(line.contains("esac")) stream << line << "\n"; } if(line.contains(";;")) output = true; if(output && (*it).length() ) stream << (*it) << '\n'; } file.close(); } /** * Check to see if the current config is valid * Save wireless.opts, save interfaces */ void WLANImp::accept(){ if(wepEnabled->isChecked()){ if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ){ QMessageBox::information(this, "Error", "Please enter a key for WEP.", QMessageBox::Ok); return; } } 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; } // Ok settings are good here, save changeAndSaveSettingFile(); // Try to save the interfaces settings. if(!interfaceSetup->saveChanges()) return; OProcess insert; insert << "sh"; insert << "-c"; insert << "cardctl eject && cardctl insert"; if (!insert.start(OProcess::DontCare, OProcess::NoCommunication) ) { qWarning("could not start cardctl"); } // Close out the dialog QDialog::accept(); } 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 @@ -1,103 +1,125 @@ #include "wlanimp2.h" #include "keyedit.h" #include "interfacesetupimp.h" +#include "../interfaces/interface.h" + +#include <assert.h> +#include <errno.h> +#include <string.h> + +#include <qapplication.h> #include <qfile.h> #include <qdir.h> +#include <qdialog.h> #include <qtextstream.h> #include <qmessagebox.h> #include <qlineedit.h> #include <qlabel.h> #include <qspinbox.h> #include <qradiobutton.h> +#include <qpushbutton.h> #include <qcheckbox.h> #include <qtabwidget.h> #include <qcombobox.h> +#include <qlistview.h> +#include <qvbox.h> +#include <qprogressbar.h> #ifdef QWS + #include <qpe/resource.h> #include <opie/oprocess.h> + #include <opie2/onetwork.h> + #include <opie2/opcap.h> #else #define OProcess KProcess #include <kprocess.h> #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. */ WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") { interfaces = new Interfaces(); interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces); tabWidget->insertTab(interfaceSetup, "TCP/IP"); // Check sanity - the existance of the wireless-tools if-pre-up script QFile file(QString(PREUP)); 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() { //FIXME: delete interfaces; } /** * Change the profile for both wireless settings and network settings. */ void WLANImp::setProfile(const QString &profile){ interfaceSetup->setProfile(profile); parseOpts(); } void WLANImp::parseOpts() { bool error; QString opt; if (! interfaces->isInterfaceSet()) return; opt = interfaces->getInterfaceOption("wireless_essid", error); if(opt == "any" || opt == "off" || opt.isNull()){ essid->setEditText("any"); } else { essid->setEditText(opt); } opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace(); for ( int i = 0; i < mode->count(); i++) if ( mode->text( i ) == opt ) mode->setCurrentItem( i ); opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace(); if (! opt.isNull()) { specifyAp->setChecked(true); macEdit->setText(opt); } opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace(); if (! opt.isNull()) { specifyChan->setChecked(true); networkChannel->setValue(opt.toInt()); } opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace(); if (opt.isNull()) opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace(); parseKeyStr(opt); } void WLANImp::parseKeyStr(QString keystr) { int loc = 0; int index = 1; QString key; QStringList keys = QStringList::split(QRegExp("\\s+"), keystr); int enc = -1; // encryption state for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { if ((*it).left(3) == "off") { // encryption disabled enc = 0; } else if ((*it).left(2) == "on") { @@ -213,64 +235,256 @@ void WLANImp::writeOpts() { if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!"); interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText()); interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText()); if (specifyAp->isChecked()) { interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text()); } else { interfaces->removeInterfaceOption(QString("wireless_ap")); } if (specifyChan->isChecked()) { interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text()); } else { interfaces->removeInterfaceOption(QString("wireless_channel")); } if (wepEnabled->isChecked()) { QStringList keyList; if (! keyLineEdit0->text().isNull()) { keyList += keyLineEdit0->text(); keyList += "[1]"; } //else if (! keyLineEdit1->text().isNull()) { keyList += keyLineEdit1->text(); keyList += "[2]"; } //else if (! keyLineEdit2->text().isNull()) { keyList += keyLineEdit2->text(); keyList += "[3]"; } //else if (! keyLineEdit3->text().isNull()) { keyList += keyLineEdit3->text(); keyList += "[4]"; } if (acceptNonEnc->isChecked()) { keyList += "open"; } else { keyList += "restricted"; } keyList += "key"; if (keyRadio0->isChecked()) { keyList += "[1]"; } else if (keyRadio1->isChecked()) { keyList += "[2]"; } else if (keyRadio2->isChecked()) { keyList += "[3]"; } else if (keyRadio3->isChecked()) { keyList += "[4]"; } interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" "))); } else { interfaces->removeInterfaceOption(QString("wireless_key")); } interfaces->removeInterfaceOption(QString("wireless_enc")); if(!interfaceSetup->saveChanges()) return; QDialog::accept(); } + +/* + * Scan for possible wireless networks around... + * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org> + */ + +void WLANImp::rescanNeighbourhood() +{ + QString name = interface->getInterfaceName(); + qDebug( "rescanNeighbourhood via '%s'", (const char*) name ); + + OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( 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( "<center><b>Scanning...</b><br>Please Wait...</center>", 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<OWaveLanManagementPacket*>( 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<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); + QString essid = ssid ? ssid->ID() : QString("<unknown>"); + OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); + int channel = ds ? ds->channel() : -1; + OWaveLanPacket* header = static_cast<OWaveLanPacket*>( 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 @@ -1,37 +1,52 @@ #ifndef WLANIMP_H #define WLANIMP_H #include "wlan.h" #include "interfaces.h" #include <qstringlist.h> +#include <opie2/onetutils.h> class InterfaceSetupImp; class Interface; class Config; +class OPacket; +class QListViewItem; + +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: WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); ~WLANImp(); void setProfile(const QString &profile); +public slots: + void rescanNeighbourhood(); + void selectNetwork( QListViewItem* ); + protected: void accept(); private: void parseOpts(); 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; QString currentProfile; }; #endif diff --git a/pics/networksettings/adhoc.png b/pics/networksettings/adhoc.png Binary files differnew file mode 100644 index 0000000..dcf5ad2 --- a/dev/null +++ b/pics/networksettings/adhoc.png diff --git a/pics/networksettings/managed.png b/pics/networksettings/managed.png Binary files differnew file mode 100644 index 0000000..4554533 --- a/dev/null +++ b/pics/networksettings/managed.png |