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.
This commit is contained in:
Jouni Malinen 2008-12-16 23:43:08 +02:00
parent a92c421d1a
commit 0ede75ae58
6 changed files with 171 additions and 120 deletions

View file

@ -44,6 +44,7 @@ NetworkConfig::NetworkConfig(QWidget *parent, const char *, bool, Qt::WFlags)
connect(removeButton, SIGNAL(clicked()), this, SLOT(removeNetwork())); connect(removeButton, SIGNAL(clicked()), this, SLOT(removeNetwork()));
connect(eapSelect, SIGNAL(activated(int)), this, connect(eapSelect, SIGNAL(activated(int)), this,
SLOT(eapChanged(int))); SLOT(eapChanged(int)));
connect(useWpsButton, SIGNAL(clicked()), this, SLOT(useWps()));
wpagui = NULL; wpagui = NULL;
new_network = false; new_network = false;
@ -98,6 +99,10 @@ void NetworkConfig::paramsFromScanResults(QTreeWidgetItem *sel)
wepEnabled(auth == AUTH_NONE && encr == 1); wepEnabled(auth == AUTH_NONE && encr == 1);
getEapCapa(); 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(' ')); QStringList types = res.split(QChar(' '));
eapSelect->insertItems(-1, types); eapSelect->insertItems(-1, types);
} }
void NetworkConfig::useWps()
{
if (wpagui == NULL)
return;
wpagui->setBssFromScan(bssid);
wpagui->wpsDialog();
close();
}

View file

@ -43,6 +43,7 @@ public slots:
virtual void writeWepKey(int network_id, QLineEdit *edit, int id); virtual void writeWepKey(int network_id, QLineEdit *edit, int id);
virtual void removeNetwork(); virtual void removeNetwork();
virtual void eapChanged(int sel); virtual void eapChanged(int sel);
virtual void useWps();
protected slots: protected slots:
virtual void languageChange(); virtual void languageChange();
@ -51,6 +52,7 @@ private:
WpaGui *wpagui; WpaGui *wpagui;
int edit_network_id; int edit_network_id;
bool new_network; bool new_network;
QString bssid;
virtual void wepEnabled(bool enabled); virtual void wepEnabled(bool enabled);
virtual void getEapCapa(); virtual void getEapCapa();

View file

@ -349,14 +349,14 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="1" column="1" > <item row="1" column="2" >
<widget class="QPushButton" name="addButton" > <widget class="QPushButton" name="addButton" >
<property name="text" > <property name="text" >
<string>Add</string> <string>Add</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="2" > <item row="1" column="3" >
<widget class="QPushButton" name="removeButton" > <widget class="QPushButton" name="removeButton" >
<property name="enabled" > <property name="enabled" >
<bool>false</bool> <bool>false</bool>
@ -379,6 +379,16 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="1" column="1" >
<widget class="QPushButton" name="useWpsButton" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>WPS</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<layoutdefault spacing="6" margin="11" /> <layoutdefault spacing="6" margin="11" />

View file

@ -91,6 +91,9 @@ WpaGui::WpaGui(QWidget *parent, const char *, Qt::WFlags)
SLOT(tabChanged(int))); SLOT(tabChanged(int)));
connect(wpsPbcButton, SIGNAL(clicked()), this, SLOT(wpsPbc())); connect(wpsPbcButton, SIGNAL(clicked()), this, SLOT(wpsPbc()));
connect(wpsPinButton, SIGNAL(clicked()), this, SLOT(wpsGeneratePin())); 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; eh = NULL;
scanres = NULL; scanres = NULL;
@ -614,14 +617,7 @@ void WpaGui::disconnect()
char reply[10]; char reply[10];
size_t reply_len = sizeof(reply); size_t reply_len = sizeof(reply);
ctrlRequest("DISCONNECT", reply, &reply_len); ctrlRequest("DISCONNECT", reply, &reply_len);
stopWpsRun(false);
if (wpsRunning)
wpsStatusText->setText("Stopped");
else
wpsStatusText->setText("");
wpsPinEdit->setEnabled(false);
wpsInstructions->setText("");
wpsRunning = false;
} }
@ -769,12 +765,7 @@ void WpaGui::processMsg(char *msg)
showTrayMessage(QSystemTrayIcon::Information, 3, showTrayMessage(QSystemTrayIcon::Information, 3,
"Connection to network established."); "Connection to network established.");
QTimer::singleShot(5 * 1000, this, SLOT(showTrayStatus())); QTimer::singleShot(5 * 1000, this, SLOT(showTrayStatus()));
if (wpsRunning) { stopWpsRun(true);
wpsStatusText->setText("Connected to the network");
wpsPinEdit->setEnabled(false);
wpsInstructions->setText("");
wpsRunning = false;
}
} else if (str_match(pos, WPS_EVENT_AP_AVAILABLE_PBC)) { } else if (str_match(pos, WPS_EVENT_AP_AVAILABLE_PBC)) {
showTrayMessage(QSystemTrayIcon::Information, 3, showTrayMessage(QSystemTrayIcon::Information, 3,
"Wi-Fi Protected Setup (WPS) AP\n" "Wi-Fi Protected Setup (WPS) AP\n"
@ -877,14 +868,7 @@ void WpaGui::selectNetwork( const QString &sel )
cmd.prepend("SELECT_NETWORK "); cmd.prepend("SELECT_NETWORK ");
ctrlRequest(cmd.toAscii().constData(), reply, &reply_len); ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
triggerUpdate(); triggerUpdate();
stopWpsRun(false);
if (wpsRunning)
wpsStatusText->setText("Stopped");
else
wpsStatusText->setText("");
wpsPinEdit->setEnabled(false);
wpsInstructions->setText("");
wpsRunning = false;
} }
@ -1372,8 +1356,9 @@ void WpaGui::tabChanged(int index)
if (wpsRunning) if (wpsRunning)
return; return;
/* TODO: Update WPS status based on latest scan results and wpsApPinEdit->setEnabled(!bssFromScan.isEmpty());
* availability of WPS APs */ if (bssFromScan.isEmpty())
wpsApPinButton->setEnabled(false);
} }
@ -1417,3 +1402,51 @@ void WpaGui::wpsGeneratePin()
wpsStatusText->setText("Waiting for Registrar"); wpsStatusText->setText("Waiting for Registrar");
wpsRunning = true; 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);
}

View file

@ -38,6 +38,7 @@ public:
virtual void enableNetwork(const QString &sel); virtual void enableNetwork(const QString &sel);
virtual void disableNetwork(const QString &sel); virtual void disableNetwork(const QString &sel);
virtual int getNetworkDisabled(const QString &sel); virtual int getNetworkDisabled(const QString &sel);
void setBssFromScan(const QString &bssid);
public slots: public slots:
virtual void parse_argv(); virtual void parse_argv();
@ -75,6 +76,8 @@ public slots:
virtual void tabChanged(int index); virtual void tabChanged(int index);
virtual void wpsPbc(); virtual void wpsPbc();
virtual void wpsGeneratePin(); virtual void wpsGeneratePin();
virtual void wpsApPinChanged(const QString &text);
virtual void wpsApPin();
protected slots: protected slots:
virtual void languageChange(); virtual void languageChange();
@ -111,6 +114,10 @@ private:
int openCtrlConnection(const char *ifname); int openCtrlConnection(const char *ifname);
bool wpsRunning; bool wpsRunning;
QString bssFromScan;
void stopWpsRun(bool success);
}; };
#endif /* WPAGUI_H */ #endif /* WPAGUI_H */

View file

@ -293,100 +293,84 @@
<attribute name="title" > <attribute name="title" >
<string>WPS</string> <string>WPS</string>
</attribute> </attribute>
<widget class="QPushButton" name="wpsPbcButton" > <layout class="QGridLayout" name="gridLayout" >
<property name="geometry" > <item row="0" column="0" >
<rect> <widget class="QLabel" name="label_2" >
<x>10</x> <property name="text" >
<y>40</y> <string>Status:</string>
<width>141</width> </property>
<height>28</height> </widget>
</rect> </item>
</property> <item row="0" column="1" colspan="3" >
<property name="text" > <widget class="QLabel" name="wpsStatusText" >
<string>PBC - push button</string> <property name="text" >
</property> <string/>
</widget> </property>
<widget class="QPushButton" name="wpsPinButton" > </widget>
<property name="geometry" > </item>
<rect> <item row="1" column="0" colspan="2" >
<x>10</x> <widget class="QPushButton" name="wpsPbcButton" >
<y>90</y> <property name="text" >
<width>141</width> <string>PBC - push button</string>
<height>28</height> </property>
</rect> </widget>
</property> </item>
<property name="text" > <item row="2" column="0" colspan="2" >
<string>Generate PIN</string> <widget class="QPushButton" name="wpsPinButton" >
</property> <property name="text" >
</widget> <string>Generate PIN</string>
<widget class="QLabel" name="label" > </property>
<property name="geometry" > </widget>
<rect> </item>
<x>160</x> <item row="2" column="2" >
<y>100</y> <widget class="QLabel" name="label" >
<width>21</width> <property name="text" >
<height>18</height> <string>PIN:</string>
</rect> </property>
</property> </widget>
<property name="text" > </item>
<string>PIN</string> <item row="2" column="3" >
</property> <widget class="QLineEdit" name="wpsPinEdit" >
</widget> <property name="enabled" >
<widget class="QLineEdit" name="wpsPinEdit" > <bool>false</bool>
<property name="enabled" > </property>
<bool>false</bool> <property name="readOnly" >
</property> <bool>true</bool>
<property name="geometry" > </property>
<rect> </widget>
<x>190</x> </item>
<y>90</y> <item row="3" column="0" colspan="2" >
<width>113</width> <widget class="QPushButton" name="wpsApPinButton" >
<height>28</height> <property name="enabled" >
</rect> <bool>false</bool>
</property> </property>
<property name="readOnly" > <property name="text" >
<bool>true</bool> <string>Use AP PIN</string>
</property> </property>
</widget> </widget>
<widget class="QLabel" name="label_2" > </item>
<property name="geometry" > <item row="3" column="2" >
<rect> <widget class="QLabel" name="label_3" >
<x>10</x> <property name="text" >
<y>10</y> <string>AP PIN:</string>
<width>41</width> </property>
<height>18</height> </widget>
</rect> </item>
</property> <item row="3" column="3" >
<property name="text" > <widget class="QLineEdit" name="wpsApPinEdit" >
<string>Status:</string> <property name="enabled" >
</property> <bool>false</bool>
</widget> </property>
<widget class="QLabel" name="wpsStatusText" > </widget>
<property name="geometry" > </item>
<rect> <item row="4" column="0" colspan="4" >
<x>70</x> <widget class="QTextEdit" name="wpsInstructions" >
<y>10</y> <property name="readOnly" >
<width>231</width> <bool>true</bool>
<height>18</height> </property>
</rect> </widget>
</property> </item>
<property name="text" > </layout>
<string/>
</property>
</widget>
<widget class="QTextEdit" name="wpsInstructions" >
<property name="geometry" >
<rect>
<x>10</x>
<y>130</y>
<width>301</width>
<height>91</height>
</rect>
</property>
<property name="readOnly" >
<bool>true</bool>
</property>
</widget>
</widget> </widget>
</widget> </widget>
</item> </item>