diff options
author | Jouni Malinen <jouni.malinen@atheros.com> | 2009-09-11 18:37:16 +0300 |
---|---|---|
committer | Jouni Malinen <j@w1.fi> | 2009-09-11 18:37:16 +0300 |
commit | b1078a4bfb81f96b0a6db8d847ec2955285fdd1b (patch) | |
tree | 57b4d5452738f7c8149ee8c929c97db0226fced0 /wpa_supplicant/wpa_gui-qt4 | |
parent | acd8ba74c061c964c01526c4e937fb8c31240ead (diff) | |
download | external_wpa_supplicant_8_ti-b1078a4bfb81f96b0a6db8d847ec2955285fdd1b.zip external_wpa_supplicant_8_ti-b1078a4bfb81f96b0a6db8d847ec2955285fdd1b.tar.gz external_wpa_supplicant_8_ti-b1078a4bfb81f96b0a6db8d847ec2955285fdd1b.tar.bz2 |
wpa_gui-qt4: Add scan results into the peer window
In addition, add a peer entry type for each peer entry. Currently,
this is only stored as an integer and visible in the context menu.
Eventually, different icons should be used based on this type.
Diffstat (limited to 'wpa_supplicant/wpa_gui-qt4')
-rw-r--r-- | wpa_supplicant/wpa_gui-qt4/peers.cpp | 121 | ||||
-rw-r--r-- | wpa_supplicant/wpa_gui-qt4/peers.h | 2 |
2 files changed, 115 insertions, 8 deletions
diff --git a/wpa_supplicant/wpa_gui-qt4/peers.cpp b/wpa_supplicant/wpa_gui-qt4/peers.cpp index a0ff7e4..9f330ab 100644 --- a/wpa_supplicant/wpa_gui-qt4/peers.cpp +++ b/wpa_supplicant/wpa_gui-qt4/peers.cpp @@ -22,6 +22,7 @@ static const int peer_role_address = Qt::UserRole + 1; +static const int peer_role_type = Qt::UserRole + 2; /* * TODO: @@ -30,6 +31,13 @@ static const int peer_role_address = Qt::UserRole + 1; * - different icons to indicate peer type */ +enum peer_type { + PEER_TYPE_ASSOCIATED_STATION, + PEER_TYPE_AP, + PEER_TYPE_AP_WPS, +}; + + Peers::Peers(QWidget *parent, const char *, bool, Qt::WFlags) : QDialog(parent) { @@ -79,9 +87,29 @@ void Peers::context_menu(const QPoint &pos) QModelIndex idx = peers->indexAt(pos); if (idx.isValid()) { ctx_item = model.itemFromIndex(idx); - /* TODO: only for peers that are requesting WPS PIN method */ - menu->addAction(QString("Enter WPS PIN"), this, - SLOT(enter_pin())); + int type = ctx_item->data(peer_role_type).toInt(); + QString title; + switch (type) { + case PEER_TYPE_ASSOCIATED_STATION: + title = tr("Associated station"); + break; + case PEER_TYPE_AP: + title = tr("AP"); + break; + case PEER_TYPE_AP_WPS: + title = tr("WPS AP"); + break; + } + menu->addAction(title)->setEnabled(false); + menu->addSeparator(); + + if (type == PEER_TYPE_ASSOCIATED_STATION || + type == PEER_TYPE_AP_WPS) { + /* TODO: only for peers that are requesting WPS PIN + * method */ + menu->addAction(QString("Enter WPS PIN"), this, + SLOT(enter_pin())); + } } else { ctx_item = NULL; menu->addAction(QString("Refresh"), this, SLOT(ctx_refresh())); @@ -123,17 +151,13 @@ void Peers::ctx_refresh() } -void Peers::update_peers() +void Peers::add_stations() { char reply[2048]; size_t reply_len; char cmd[20]; int res; - model.clear(); - if (wpagui == NULL) - return; - reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest("STA-FIRST", reply, &reply_len) < 0) return; @@ -168,6 +192,8 @@ void Peers::update_peers() QStandardItem *item = new QStandardItem(*default_icon, name); if (item) { item->setData(QString(reply), peer_role_address); + item->setData(PEER_TYPE_ASSOCIATED_STATION, + peer_role_type); item->setToolTip(info); model.appendRow(item); } @@ -177,3 +203,82 @@ void Peers::update_peers() res = wpagui->ctrlRequest(cmd, reply, &reply_len); } while (res >= 0); } + + +void Peers::add_scan_results() +{ + char reply[2048]; + size_t reply_len; + int index; + char cmd[20]; + + index = 0; + while (wpagui) { + snprintf(cmd, sizeof(cmd), "BSS %d", index++); + if (index > 1000) + break; + + reply_len = sizeof(reply) - 1; + if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) + break; + reply[reply_len] = '\0'; + + QString bss(reply); + if (bss.isEmpty() || bss.startsWith("FAIL")) + break; + + QString ssid, bssid, flags, wps_name; + + QStringList lines = bss.split(QRegExp("\\n")); + for (QStringList::Iterator it = lines.begin(); + it != lines.end(); it++) { + int pos = (*it).indexOf('=') + 1; + if (pos < 1) + continue; + + if ((*it).startsWith("bssid=")) + bssid = (*it).mid(pos); + else if ((*it).startsWith("flags=")) + flags = (*it).mid(pos); + else if ((*it).startsWith("ssid=")) + ssid = (*it).mid(pos); + else if ((*it).startsWith("wps_device_name=")) + wps_name = (*it).mid(pos); + } + + QString name = wps_name; + if (name.isEmpty()) + name = ssid + "\n" + bssid; + + QStandardItem *item = new QStandardItem(*default_icon, name); + if (item) { + item->setData(QString(reply), peer_role_address); + if (flags.contains("[WPS]")) + item->setData(PEER_TYPE_AP_WPS, + peer_role_type); + else + item->setData(PEER_TYPE_AP, peer_role_type); + + for (int i = 0; i < lines.size(); i++) { + if (lines[i].length() > 60) { + lines[i].remove( + 60, lines[i].length()); + lines[i] += ".."; + } + } + item->setToolTip(lines.join("\n")); + model.appendRow(item); + } + } +} + + +void Peers::update_peers() +{ + model.clear(); + if (wpagui == NULL) + return; + + add_stations(); + add_scan_results(); +} diff --git a/wpa_supplicant/wpa_gui-qt4/peers.h b/wpa_supplicant/wpa_gui-qt4/peers.h index b8c5056..2ea29e2 100644 --- a/wpa_supplicant/wpa_gui-qt4/peers.h +++ b/wpa_supplicant/wpa_gui-qt4/peers.h @@ -40,6 +40,8 @@ protected slots: virtual void languageChange(); private: + void add_stations(); + void add_scan_results(); void update_peers(); WpaGui *wpagui; |