WPS: Added wpa_gui-qt4 support for BSS selection and AP PIN use
authorJouni Malinen <j@w1.fi>
Tue, 16 Dec 2008 21:43:08 +0000 (23:43 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 16 Dec 2008 21:43:08 +0000 (23:43 +0200)
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
wpa_supplicant/wpa_gui-qt4/networkconfig.h
wpa_supplicant/wpa_gui-qt4/networkconfig.ui
wpa_supplicant/wpa_gui-qt4/wpagui.cpp
wpa_supplicant/wpa_gui-qt4/wpagui.h
wpa_supplicant/wpa_gui-qt4/wpagui.ui

index b963a7e..a176d05 100644 (file)
@@ -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();
+}
index d37eed3..0ceeb41 100644 (file)
@@ -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();
index bd5dd75..ede462f 100644 (file)
      </layout>
     </widget>
    </item>
-   <item row="1" column="1" >
+   <item row="1" column="2" >
     <widget class="QPushButton" name="addButton" >
      <property name="text" >
       <string>Add</string>
      </property>
     </widget>
    </item>
-   <item row="1" column="2" >
+   <item row="1" column="3" >
     <widget class="QPushButton" name="removeButton" >
      <property name="enabled" >
       <bool>false</bool>
      </property>
     </spacer>
    </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>
  </widget>
  <layoutdefault spacing="6" margin="11" />
index 670fb6b..829e3c1 100644 (file)
@@ -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);
+}
index c805962..5aa7a9a 100644 (file)
@@ -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 */
index 71e62a9..77a931b 100644 (file)
        <attribute name="title" >
         <string>WPS</string>
        </attribute>
-       <widget class="QPushButton" name="wpsPbcButton" >
-        <property name="geometry" >
-         <rect>
-          <x>10</x>
-          <y>40</y>
-          <width>141</width>
-          <height>28</height>
-         </rect>
-        </property>
-        <property name="text" >
-         <string>PBC - push button</string>
-        </property>
-       </widget>
-       <widget class="QPushButton" name="wpsPinButton" >
-        <property name="geometry" >
-         <rect>
-          <x>10</x>
-          <y>90</y>
-          <width>141</width>
-          <height>28</height>
-         </rect>
-        </property>
-        <property name="text" >
-         <string>Generate PIN</string>
-        </property>
-       </widget>
-       <widget class="QLabel" name="label" >
-        <property name="geometry" >
-         <rect>
-          <x>160</x>
-          <y>100</y>
-          <width>21</width>
-          <height>18</height>
-         </rect>
-        </property>
-        <property name="text" >
-         <string>PIN</string>
-        </property>
-       </widget>
-       <widget class="QLineEdit" name="wpsPinEdit" >
-        <property name="enabled" >
-         <bool>false</bool>
-        </property>
-        <property name="geometry" >
-         <rect>
-          <x>190</x>
-          <y>90</y>
-          <width>113</width>
-          <height>28</height>
-         </rect>
-        </property>
-        <property name="readOnly" >
-         <bool>true</bool>
-        </property>
-       </widget>
-       <widget class="QLabel" name="label_2" >
-        <property name="geometry" >
-         <rect>
-          <x>10</x>
-          <y>10</y>
-          <width>41</width>
-          <height>18</height>
-         </rect>
-        </property>
-        <property name="text" >
-         <string>Status:</string>
-        </property>
-       </widget>
-       <widget class="QLabel" name="wpsStatusText" >
-        <property name="geometry" >
-         <rect>
-          <x>70</x>
-          <y>10</y>
-          <width>231</width>
-          <height>18</height>
-         </rect>
-        </property>
-        <property name="text" >
-         <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>
+       <layout class="QGridLayout" name="gridLayout" >
+        <item row="0" column="0" >
+         <widget class="QLabel" name="label_2" >
+          <property name="text" >
+           <string>Status:</string>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="1" colspan="3" >
+         <widget class="QLabel" name="wpsStatusText" >
+          <property name="text" >
+           <string/>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="0" colspan="2" >
+         <widget class="QPushButton" name="wpsPbcButton" >
+          <property name="text" >
+           <string>PBC - push button</string>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="0" colspan="2" >
+         <widget class="QPushButton" name="wpsPinButton" >
+          <property name="text" >
+           <string>Generate PIN</string>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="2" >
+         <widget class="QLabel" name="label" >
+          <property name="text" >
+           <string>PIN:</string>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="3" >
+         <widget class="QLineEdit" name="wpsPinEdit" >
+          <property name="enabled" >
+           <bool>false</bool>
+          </property>
+          <property name="readOnly" >
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+        <item row="3" column="0" colspan="2" >
+         <widget class="QPushButton" name="wpsApPinButton" >
+          <property name="enabled" >
+           <bool>false</bool>
+          </property>
+          <property name="text" >
+           <string>Use AP PIN</string>
+          </property>
+         </widget>
+        </item>
+        <item row="3" column="2" >
+         <widget class="QLabel" name="label_3" >
+          <property name="text" >
+           <string>AP PIN:</string>
+          </property>
+         </widget>
+        </item>
+        <item row="3" column="3" >
+         <widget class="QLineEdit" name="wpsApPinEdit" >
+          <property name="enabled" >
+           <bool>false</bool>
+          </property>
+         </widget>
+        </item>
+        <item row="4" column="0" colspan="4" >
+         <widget class="QTextEdit" name="wpsInstructions" >
+          <property name="readOnly" >
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+       </layout>
       </widget>
      </widget>
     </item>