Parcourir la source

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.
Jouni Malinen il y a 15 ans
Parent
commit
b1078a4bfb
2 fichiers modifiés avec 115 ajouts et 8 suppressions
  1. 113 8
      wpa_supplicant/wpa_gui-qt4/peers.cpp
  2. 2 0
      wpa_supplicant/wpa_gui-qt4/peers.h

+ 113 - 8
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();
+}

+ 2 - 0
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;