From 0ede75ae58523d456ea93121f8a1d2d13ac3c517 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 16 Dec 2008 23:43:08 +0200 Subject: [PATCH] WPS: Added wpa_gui-qt4 support for BSS selection and AP PIN use The specific AP (BSSID) can now be selected through scan results for WPS (WPS pushbutton on the network configuration dialog). When a BSSID is selected, AP device PIN (e.g., from a label) can be used to configure the AP by acting as a Registrar. --- wpa_supplicant/wpa_gui-qt4/networkconfig.cpp | 15 ++ wpa_supplicant/wpa_gui-qt4/networkconfig.h | 2 + wpa_supplicant/wpa_gui-qt4/networkconfig.ui | 14 +- wpa_supplicant/wpa_gui-qt4/wpagui.cpp | 81 ++++++--- wpa_supplicant/wpa_gui-qt4/wpagui.h | 7 + wpa_supplicant/wpa_gui-qt4/wpagui.ui | 172 +++++++++---------- 6 files changed, 171 insertions(+), 120 deletions(-) diff --git a/wpa_supplicant/wpa_gui-qt4/networkconfig.cpp b/wpa_supplicant/wpa_gui-qt4/networkconfig.cpp index b963a7e36..a176d056e 100644 --- a/wpa_supplicant/wpa_gui-qt4/networkconfig.cpp +++ b/wpa_supplicant/wpa_gui-qt4/networkconfig.cpp @@ -44,6 +44,7 @@ NetworkConfig::NetworkConfig(QWidget *parent, const char *, bool, Qt::WFlags) connect(removeButton, SIGNAL(clicked()), this, SLOT(removeNetwork())); connect(eapSelect, SIGNAL(activated(int)), this, SLOT(eapChanged(int))); + connect(useWpsButton, SIGNAL(clicked()), this, SLOT(useWps())); wpagui = NULL; new_network = false; @@ -98,6 +99,10 @@ void NetworkConfig::paramsFromScanResults(QTreeWidgetItem *sel) wepEnabled(auth == AUTH_NONE && encr == 1); getEapCapa(); + + if (flags.indexOf("[WPS") >= 0) + useWpsButton->setEnabled(true); + bssid = sel->text(1); } @@ -806,3 +811,13 @@ void NetworkConfig::getEapCapa() QStringList types = res.split(QChar(' ')); eapSelect->insertItems(-1, types); } + + +void NetworkConfig::useWps() +{ + if (wpagui == NULL) + return; + wpagui->setBssFromScan(bssid); + wpagui->wpsDialog(); + close(); +} diff --git a/wpa_supplicant/wpa_gui-qt4/networkconfig.h b/wpa_supplicant/wpa_gui-qt4/networkconfig.h index d37eed325..0ceeb417f 100644 --- a/wpa_supplicant/wpa_gui-qt4/networkconfig.h +++ b/wpa_supplicant/wpa_gui-qt4/networkconfig.h @@ -43,6 +43,7 @@ public slots: virtual void writeWepKey(int network_id, QLineEdit *edit, int id); virtual void removeNetwork(); virtual void eapChanged(int sel); + virtual void useWps(); protected slots: virtual void languageChange(); @@ -51,6 +52,7 @@ private: WpaGui *wpagui; int edit_network_id; bool new_network; + QString bssid; virtual void wepEnabled(bool enabled); virtual void getEapCapa(); diff --git a/wpa_supplicant/wpa_gui-qt4/networkconfig.ui b/wpa_supplicant/wpa_gui-qt4/networkconfig.ui index bd5dd7587..ede462f67 100644 --- a/wpa_supplicant/wpa_gui-qt4/networkconfig.ui +++ b/wpa_supplicant/wpa_gui-qt4/networkconfig.ui @@ -349,14 +349,14 @@ - + Add - + false @@ -379,6 +379,16 @@ + + + + false + + + WPS + + + diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.cpp b/wpa_supplicant/wpa_gui-qt4/wpagui.cpp index 670fb6bc5..829e3c1c9 100644 --- a/wpa_supplicant/wpa_gui-qt4/wpagui.cpp +++ b/wpa_supplicant/wpa_gui-qt4/wpagui.cpp @@ -91,6 +91,9 @@ WpaGui::WpaGui(QWidget *parent, const char *, Qt::WFlags) SLOT(tabChanged(int))); connect(wpsPbcButton, SIGNAL(clicked()), this, SLOT(wpsPbc())); connect(wpsPinButton, SIGNAL(clicked()), this, SLOT(wpsGeneratePin())); + connect(wpsApPinEdit, SIGNAL(textChanged(const QString &)), this, + SLOT(wpsApPinChanged(const QString &))); + connect(wpsApPinButton, SIGNAL(clicked()), this, SLOT(wpsApPin())); eh = NULL; scanres = NULL; @@ -614,14 +617,7 @@ void WpaGui::disconnect() char reply[10]; size_t reply_len = sizeof(reply); ctrlRequest("DISCONNECT", reply, &reply_len); - - if (wpsRunning) - wpsStatusText->setText("Stopped"); - else - wpsStatusText->setText(""); - wpsPinEdit->setEnabled(false); - wpsInstructions->setText(""); - wpsRunning = false; + stopWpsRun(false); } @@ -769,12 +765,7 @@ void WpaGui::processMsg(char *msg) showTrayMessage(QSystemTrayIcon::Information, 3, "Connection to network established."); QTimer::singleShot(5 * 1000, this, SLOT(showTrayStatus())); - if (wpsRunning) { - wpsStatusText->setText("Connected to the network"); - wpsPinEdit->setEnabled(false); - wpsInstructions->setText(""); - wpsRunning = false; - } + stopWpsRun(true); } else if (str_match(pos, WPS_EVENT_AP_AVAILABLE_PBC)) { showTrayMessage(QSystemTrayIcon::Information, 3, "Wi-Fi Protected Setup (WPS) AP\n" @@ -877,14 +868,7 @@ void WpaGui::selectNetwork( const QString &sel ) cmd.prepend("SELECT_NETWORK "); ctrlRequest(cmd.toAscii().constData(), reply, &reply_len); triggerUpdate(); - - if (wpsRunning) - wpsStatusText->setText("Stopped"); - else - wpsStatusText->setText(""); - wpsPinEdit->setEnabled(false); - wpsInstructions->setText(""); - wpsRunning = false; + stopWpsRun(false); } @@ -1372,8 +1356,9 @@ void WpaGui::tabChanged(int index) if (wpsRunning) return; - /* TODO: Update WPS status based on latest scan results and - * availability of WPS APs */ + wpsApPinEdit->setEnabled(!bssFromScan.isEmpty()); + if (bssFromScan.isEmpty()) + wpsApPinButton->setEnabled(false); } @@ -1417,3 +1402,51 @@ void WpaGui::wpsGeneratePin() wpsStatusText->setText("Waiting for Registrar"); wpsRunning = true; } + + +void WpaGui::setBssFromScan(const QString &bssid) +{ + bssFromScan = bssid; + wpsApPinEdit->setEnabled(!bssFromScan.isEmpty()); + wpsApPinButton->setEnabled(wpsApPinEdit->text().length() == 8); + wpsStatusText->setText("WPS AP selected from scan results"); + wpsInstructions->setText("If you want to use an AP device PIN, e.g., " + "from a label in the device, enter the eight " + "digit AP PIN and click Use AP PIN button."); +} + + +void WpaGui::wpsApPinChanged(const QString &text) +{ + wpsApPinButton->setEnabled(text.length() == 8); +} + + +void WpaGui::wpsApPin() +{ + char reply[20]; + size_t reply_len = sizeof(reply); + + QString cmd("WPS_REG " + bssFromScan + " " + wpsApPinEdit->text()); + if (ctrlRequest(cmd.toAscii().constData(), reply, &reply_len) < 0) + return; + + wpsStatusText->setText("Waiting for AP/Enrollee"); + wpsRunning = true; +} + + +void WpaGui::stopWpsRun(bool success) +{ + if (wpsRunning) + wpsStatusText->setText(success ? "Connected to the network" : + "Stopped"); + else + wpsStatusText->setText(""); + wpsPinEdit->setEnabled(false); + wpsInstructions->setText(""); + wpsRunning = false; + bssFromScan = ""; + wpsApPinEdit->setEnabled(false); + wpsApPinButton->setEnabled(false); +} diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.h b/wpa_supplicant/wpa_gui-qt4/wpagui.h index c805962c7..5aa7a9a9f 100644 --- a/wpa_supplicant/wpa_gui-qt4/wpagui.h +++ b/wpa_supplicant/wpa_gui-qt4/wpagui.h @@ -38,6 +38,7 @@ public: virtual void enableNetwork(const QString &sel); virtual void disableNetwork(const QString &sel); virtual int getNetworkDisabled(const QString &sel); + void setBssFromScan(const QString &bssid); public slots: virtual void parse_argv(); @@ -75,6 +76,8 @@ public slots: virtual void tabChanged(int index); virtual void wpsPbc(); virtual void wpsGeneratePin(); + virtual void wpsApPinChanged(const QString &text); + virtual void wpsApPin(); protected slots: virtual void languageChange(); @@ -111,6 +114,10 @@ private: int openCtrlConnection(const char *ifname); bool wpsRunning; + + QString bssFromScan; + + void stopWpsRun(bool success); }; #endif /* WPAGUI_H */ diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.ui b/wpa_supplicant/wpa_gui-qt4/wpagui.ui index 71e62a922..77a931b8b 100644 --- a/wpa_supplicant/wpa_gui-qt4/wpagui.ui +++ b/wpa_supplicant/wpa_gui-qt4/wpagui.ui @@ -293,100 +293,84 @@ WPS - - - - 10 - 40 - 141 - 28 - - - - PBC - push button - - - - - - 10 - 90 - 141 - 28 - - - - Generate PIN - - - - - - 160 - 100 - 21 - 18 - - - - PIN - - - - - false - - - - 190 - 90 - 113 - 28 - - - - true - - - - - - 10 - 10 - 41 - 18 - - - - Status: - - - - - - 70 - 10 - 231 - 18 - - - - - - - - - - 10 - 130 - 301 - 91 - - - - true - - + + + + + Status: + + + + + + + + + + + + + + PBC - push button + + + + + + + Generate PIN + + + + + + + PIN: + + + + + + + false + + + true + + + + + + + false + + + Use AP PIN + + + + + + + AP PIN: + + + + + + + false + + + + + + + true + + + +