wpa_gui-qt4: Add pending WPS PIN queries into peer dialog
authorJouni Malinen <jouni.malinen@atheros.com>
Tue, 29 Sep 2009 20:16:21 +0000 (23:16 +0300)
committerJouni Malinen <j@w1.fi>
Tue, 29 Sep 2009 20:16:21 +0000 (23:16 +0300)
Whenever running wpa_supplicant in AP mode with WPS enabled, the
notifications of missing WPS PIN are now shown on the peer dialog
to make it easier to provide the PIN.

wpa_supplicant/wpa_gui-qt4/peers.cpp
wpa_supplicant/wpa_gui-qt4/peers.h
wpa_supplicant/wpa_gui-qt4/wpagui.cpp

index dc745c3..69bc1ee 100644 (file)
@@ -16,6 +16,7 @@
 #include <QImageReader>
 #include <QMessageBox>
 
+#include "wpa_ctrl.h"
 #include "wpagui.h"
 #include "stringquery.h"
 #include "peers.h"
@@ -26,7 +27,6 @@ static const int peer_role_type = Qt::UserRole + 2;
 
 /*
  * TODO:
- * - add pending WPS queries (from M1/PIN, PBC?)
  * - add current AP info (e.g., from WPS) in station mode
  * - different icons to indicate peer type
  */
@@ -35,6 +35,7 @@ enum peer_type {
        PEER_TYPE_ASSOCIATED_STATION,
        PEER_TYPE_AP,
        PEER_TYPE_AP_WPS,
+       PEER_TYPE_WPS_PIN_NEEDED,
 };
 
 
@@ -99,12 +100,16 @@ void Peers::context_menu(const QPoint &pos)
                case PEER_TYPE_AP_WPS:
                        title = tr("WPS AP");
                        break;
+               case PEER_TYPE_WPS_PIN_NEEDED:
+                       title = tr("WPS PIN needed");
+                       break;
                }
                menu->addAction(title)->setEnabled(false);
                menu->addSeparator();
 
                if (type == PEER_TYPE_ASSOCIATED_STATION ||
-                   type == PEER_TYPE_AP_WPS) {
+                   type == PEER_TYPE_AP_WPS ||
+                   type == PEER_TYPE_WPS_PIN_NEEDED) {
                        /* TODO: only for peers that are requesting WPS PIN
                         * method */
                        menu->addAction(QString("Enter WPS PIN"), this,
@@ -282,3 +287,57 @@ void Peers::update_peers()
        add_stations();
        add_scan_results();
 }
+
+
+QStandardItem * Peers::find_addr(QString addr)
+{
+       if (model.rowCount() == 0)
+               return NULL;
+
+       QModelIndexList lst = model.match(model.index(0, 0), peer_role_address,
+                                         addr);
+       if (lst.size() == 0)
+               return NULL;
+       return model.itemFromIndex(lst[0]);
+}
+
+
+void Peers::event_notify(WpaMsg msg)
+{
+       QString text = msg.getMsg();
+       if (text.startsWith(WPS_EVENT_PIN_NEEDED)) {
+               /*
+                * WPS-PIN-NEEDED 5a02a5fa-9199-5e7c-bc46-e183d3cb32f7
+                * 02:2a:c4:18:5b:f3
+                * [Wireless Client|Company|cmodel|123|12345|1-0050F204-1]
+                */
+               QStringList items = text.split(' ');
+               QString uuid = items[1];
+               QString addr = items[2];
+               QString name = "";
+
+               QStandardItem *item = find_addr(addr);
+               if (item)
+                       return;
+
+               int pos = text.indexOf('[');
+               if (pos >= 0) {
+                       int pos2 = text.lastIndexOf(']');
+                       if (pos2 >= pos) {
+                               items = text.mid(pos + 1, pos2 - pos - 1).
+                                       split('|');
+                               name = items[0];
+                               items.append(addr);
+                       }
+               }
+
+               item = new QStandardItem(*default_icon, name);
+               if (item) {
+                       item->setData(addr, peer_role_address);
+                       item->setData(PEER_TYPE_WPS_PIN_NEEDED,
+                                     peer_role_type);
+                       item->setToolTip(items.join(QString("\n")));
+                       model.appendRow(item);
+               }
+       }
+}
index 2ea29e2..18e4a44 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <QObject>
 #include <QStandardItemModel>
+#include "wpamsg.h"
 #include "ui_peers.h"
 
 class WpaGui;
@@ -30,6 +31,7 @@ public:
                    bool modal = false, Qt::WFlags fl = 0);
        ~Peers();
        void setWpaGui(WpaGui *_wpagui);
+       void event_notify(WpaMsg msg);
 
 public slots:
        virtual void context_menu(const QPoint &pos);
@@ -43,6 +45,7 @@ private:
        void add_stations();
        void add_scan_results();
        void update_peers();
+       QStandardItem * find_addr(QString addr);
 
        WpaGui *wpagui;
        QStandardItemModel model;
index 6371c8b..9f35795 100644 (file)
@@ -828,6 +828,8 @@ void WpaGui::processMsg(char *msg)
        WpaMsg wm(pos, priority);
        if (eh)
                eh->addEvent(wm);
+       if (peers)
+               peers->event_notify(wm);
        msgs.append(wm);
        while (msgs.count() > 100)
                msgs.pop_front();