summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings
authormickeyl <mickeyl>2005-05-10 10:14:38 (UTC)
committer mickeyl <mickeyl>2005-05-10 10:14:38 (UTC)
commitff1d0ce627f64fb757df48d4c4998cb82a024dbc (patch) (side-by-side diff)
tree332d07f028d216564ee287ddd2b642e0d314234e /noncore/settings/networksettings
parentce515e60ba66d4b1540879b17b2b31b5fac627d3 (diff)
downloadopie-ff1d0ce627f64fb757df48d4c4998cb82a024dbc.zip
opie-ff1d0ce627f64fb757df48d4c4998cb82a024dbc.tar.gz
opie-ff1d0ce627f64fb757df48d4c4998cb82a024dbc.tar.bz2
improve WEP key handling and add wlan-ng support. patch courtesy Dirk Opfer, thanks!
Diffstat (limited to 'noncore/settings/networksettings') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings/wlan/wextensions.cpp3
-rw-r--r--noncore/settings/networksettings/wlan/wlan.pro2
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp2.cpp141
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp2.h1
4 files changed, 142 insertions, 5 deletions
diff --git a/noncore/settings/networksettings/wlan/wextensions.cpp b/noncore/settings/networksettings/wlan/wextensions.cpp
index 8a9db66..64d8752 100644
--- a/noncore/settings/networksettings/wlan/wextensions.cpp
+++ b/noncore/settings/networksettings/wlan/wextensions.cpp
@@ -48,52 +48,55 @@ WExtensions::WExtensions(QString interfaceName): hasWirelessExtensions(false), i
/**
* @return QString the station name of the access point.
*/
QString WExtensions::station(){
if(!hasWirelessExtensions)
return QString();
const char* buffer[200];
iwr.u.data.pointer = (caddr_t) buffer;
iwr.u.data.length = IW_ESSID_MAX_SIZE;
iwr.u.data.flags = 0;
if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){
buffer[(unsigned int) iwr.u.data.length-1] = '\0';
return (const char*) buffer;
}
return QString::null;
}
/**
* @return QString the essid of the host 802.11 access point.
*/
QString WExtensions::essid(){
if(!hasWirelessExtensions)
return QString();
const char* buffer[200];
+ memset(buffer,0x00,200);
iwr.u.data.pointer = (caddr_t) buffer;
iwr.u.data.length = IW_ESSID_MAX_SIZE;
iwr.u.data.flags = 0;
if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){
+ if (iwr.u.essid.length > IW_ESSID_MAX_SIZE)
+ iwr.u.essid.length = IW_ESSID_MAX_SIZE;
buffer[(unsigned int) iwr.u.essid.length] = '\0';
return (const char*) buffer;
}
return QString::null;
}
/**
* @return QString the mode of interface
*/
QString WExtensions::mode(){
if(!hasWirelessExtensions)
return QString();
if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) )
return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed");
return QString();
}
/**
* Get the frequency that the interface is running at.
* @return int the frequency that the interfacae is running at.
*/
double WExtensions::frequency(){
if(!hasWirelessExtensions)
return 0;
diff --git a/noncore/settings/networksettings/wlan/wlan.pro b/noncore/settings/networksettings/wlan/wlan.pro
index eb9dd4f..3a064d3 100644
--- a/noncore/settings/networksettings/wlan/wlan.pro
+++ b/noncore/settings/networksettings/wlan/wlan.pro
@@ -1,32 +1,32 @@
TEMPLATE = lib
CONFIG += qt plugin warn_on
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 -lopiecore2 -lopienet2
INTERFACES = wlan.ui info.ui
TARGET = wlan
-VERSION = 1.0.1
+VERSION = 1.0.2
#CONFIG += wirelessopts
wirelessopts {
HEADERS += wlanimp.h
SOURCES += wlanimp.cpp
}
! wirelessopts {
HEADERS += wlanimp2.h
SOURCES += wlanimp2.cpp
}
include( $(OPIEDIR)/include.pro )
!isEmpty( LIBPCAP_INC_DIR ) {
INCLUDEPATH = $$LIBPCAP_INC_DIR $$INCLUDEPATH
}
!isEmpty( LIBPCAP_LIB_DIR ) {
LIBS = -L$$LIBPCAP_LIB_DIR $$LIBS
}
diff --git a/noncore/settings/networksettings/wlan/wlanimp2.cpp b/noncore/settings/networksettings/wlan/wlanimp2.cpp
index 11dfe74..2fd97c3 100644
--- a/noncore/settings/networksettings/wlan/wlanimp2.cpp
+++ b/noncore/settings/networksettings/wlan/wlanimp2.cpp
@@ -58,83 +58,137 @@ WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, W
}
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;
+ QString opt,key;
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_type", error).simplifyWhiteSpace();
+
+ if ( opt == "wlan-ng") {
+
+ //FIXME:Handle wlan_ng_priv_genstr
+
+ // get default key_id
+ opt = interfaces->getInterfaceOption("wlan_ng_default_key_id", error).simplifyWhiteSpace();
+
+ if (opt == "0")
+ keyRadio0->setChecked(true);
+ if (opt == "1")
+ keyRadio1->setChecked(true);
+ if (opt == "2")
+ keyRadio2->setChecked(true);
+ if (opt == "3")
+ keyRadio3->setChecked(true);
+
+ // get key0
+ key = interfaces->getInterfaceOption("wlan_ng_key0", error).simplifyWhiteSpace();
+ key.replace(QString(":"),QString(""));
+ keyLineEdit0->setText(key);
+
+ // get key1
+ key = interfaces->getInterfaceOption("wlan_ng_key1", error).simplifyWhiteSpace();
+ key.replace(QString(":"),QString(""));
+ keyLineEdit1->setText(key);
+
+ // get key2
+ key = interfaces->getInterfaceOption("wlan_ng_key2", error).simplifyWhiteSpace();
+ key.replace(QString(":"),QString(""));
+ keyLineEdit2->setText(key);
+
+ // get key3
+ key = interfaces->getInterfaceOption("wlan_ng_key3", error).simplifyWhiteSpace();
+ key.replace(QString(":"),QString(""));
+ keyLineEdit3->setText(key);
+
opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace();
+
+ // encryption on?
+ if(opt == "on"){
+ wepEnabled->setChecked(true);
+ } else {
+ wepEnabled->setChecked(false);
+ }
+
+ opt = interfaces->getInterfaceOption("wireless_keymode", error).simplifyWhiteSpace();
+
+ if(opt == "restricted"){
+ // restricted mode, only accept encrypted packets
+ rejectNonEnc->setChecked(true);
+ }
+ }
+ else {
+ opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace();
+
parseKeyStr(opt);
}
+}
void WLANImp::parseKeyStr(QString keystr) {
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") {
// encryption enabled
enc = 1;
} else if ((*it).left(4) == "open") {
// open mode, accept non encrypted packets
acceptNonEnc->setChecked(true);
} else if ((*it).left(10) == "restricted") {
// restricted mode, only accept encrypted packets
rejectNonEnc->setChecked(true);
} else if ((*it).left(3) == "key") {
// new set of options
} else if ((*it).left(1) == "[") {
index = (*it).mid(1, 1).toInt();
@@ -205,115 +259,194 @@ void WLANImp::accept() {
(keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) ||
(keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) {
QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok);
return;
}
}
if (essid->currentText().isEmpty()) {
QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok);
return;
}
if (specifyAp->isChecked() && macEdit->text().isEmpty()) {
QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok);
return;
}
// Try to save the interfaces settings.
writeOpts();
// Close out the dialog
// FIXME: QDialog::accept();
}
+QString WLANImp::formatKey(QString input)
+{
+ int len,r=0;
+
+ len = input.length();
+
+ if (!len)
+ return input;
+
+ for(int i=1;i<len/2;i++)
+ {
+ input.insert(r+i*2,QString(":"));
+ r++;
+ }
+
+ return input;
+}
+
void WLANImp::writeOpts() {
+ QString para, devicetype;
+
// eh can't really do anything about it other then return. :-D
if(!interfaces->isInterfaceSet()){
QMessageBox::warning(0,"Inface not set","should not happen!!!");
return;
}
bool error = false;
odebug << "setting wlan interface " << interfaces->getInterfaceName( error ).latin1() << "" << oendl;
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"));
}
+ devicetype = interfaces->getInterfaceOption("wireless_type", error).simplifyWhiteSpace();
+
+ if ( devicetype == "wlan-ng") {
+
+ // wlan-ng style
+ interfaces->removeInterfaceOption(QString("wireless_key"));
+
+ if (wepEnabled->isChecked()) {
+
+ interfaces->setInterfaceOption(QString("wireless_enc"),"on");
+
+ if (! keyLineEdit0->text().isNull()) {
+ interfaces->setInterfaceOption(QString("wlan_ng_key0"), formatKey(keyLineEdit0->text()));
+ } else
+ interfaces->removeInterfaceOption(QString("wlan_ng_key0"));
+ if (! keyLineEdit1->text().isNull()) {
+ interfaces->setInterfaceOption(QString("wlan_ng_key1"), formatKey(keyLineEdit1->text()));
+ } else
+ interfaces->removeInterfaceOption(QString("wlan_ng_key1"));
+ if (! keyLineEdit2->text().isNull()) {
+ interfaces->setInterfaceOption(QString("wlan_ng_key2"), formatKey(keyLineEdit2->text()));
+ } else
+ interfaces->removeInterfaceOption(QString("wlan_ng_key2"));
+ if (! keyLineEdit3->text().isNull()) {
+ interfaces->setInterfaceOption(QString("wlan_ng_key3"), formatKey(keyLineEdit3->text()));
+ } else
+ interfaces->removeInterfaceOption(QString("wlan_ng_key3"));
+
+ if (acceptNonEnc->isChecked())
+ interfaces->removeInterfaceOption(QString("wireless_keymode"));
+ else
+ interfaces->setInterfaceOption(QString("wireless_keymode"),"restricted");
+
+ para = "";
+ if (keyRadio0->isChecked()) {
+ para = "0";
+ } else if (keyRadio1->isChecked()) {
+ para = "1";
+ } else if (keyRadio2->isChecked()) {
+ para = "2";
+ } else if (keyRadio3->isChecked()) {
+ para = "3";
+ }
+
+ interfaces->setInterfaceOption(QString("wlan_ng_default_key_id"), para);
+
+ } else {
+ // No wep, remove all previous keys
+ interfaces->removeInterfaceOption(QString("wireless_enc"));
+ interfaces->removeInterfaceOption(QString("wlan_ng_default_key_id"));
+ interfaces->removeInterfaceOption(QString("wlan_ng_key0"));
+ interfaces->removeInterfaceOption(QString("wlan_ng_key1"));
+ interfaces->removeInterfaceOption(QString("wlan_ng_key2"));
+ interfaces->removeInterfaceOption(QString("wlan_ng_key3"));
+ }
+
+ } else {
+ // This is the old style
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();
odebug << "rescanNeighbourhood via '" << name << "'" << oendl;
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 ) )
diff --git a/noncore/settings/networksettings/wlan/wlanimp2.h b/noncore/settings/networksettings/wlan/wlanimp2.h
index c3d1eee..0e8d533 100644
--- a/noncore/settings/networksettings/wlan/wlanimp2.h
+++ b/noncore/settings/networksettings/wlan/wlanimp2.h
@@ -16,37 +16,38 @@ 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);
+ QString formatKey(QString input);
void handlePacket( Opie::Net::OPacket* );
void displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const Opie::Net::OMacAddress& mac );
InterfaceSetupImp *interfaceSetup;
Interfaces *interfaces;
Interface *interface;
QString currentProfile;
};
#endif