[PATCH 3/3]: wpa_gui-qt4: use bss ctrl interface command to get scan results

Kel Modderman kel
Wed Jan 30 10:28:00 PST 2008


Use new ctrl interface bss command get scan results for display iteratively.

Is [2048] likely to be enough for these messages in future? I wasn't quite
sure how much would be sane/future proof.

Signed-off-by: Kel Modderman <kel at otaku42.de>
---
--- a/wpa_supplicant/wpa_gui-qt4/scanresults.cpp
+++ b/wpa_supplicant/wpa_gui-qt4/scanresults.cpp
@@ -56,36 +56,43 @@
 
 void ScanResults::updateResults()
 {
-	char reply[8192];
+	char reply[2048];
 	size_t reply_len;
     
-	if (wpagui == NULL)
-		return;
-
-	reply_len = sizeof(reply) - 1;
-	if (wpagui->ctrlRequest("SCAN_RESULTS", reply, &reply_len) < 0)
-		return;
-	reply[reply_len] = '\0';
-
 	scanResultsWidget->clear();
+	QString cmd("BSS first");
 
-	QString res(reply);
-	QStringList lines = res.split(QChar('\n'));
-	bool first = true;
-	for (QStringList::Iterator it = lines.begin(); it != lines.end(); it++)
-	{
-		if (first) {
-			first = false;
-			continue;
-		}
+	while (wpagui) {
+		reply_len = sizeof(reply) - 1;
+		if (wpagui->ctrlRequest(cmd.toAscii().constData(), reply,
+		    &reply_len) < 0)
+			break;
+		reply[reply_len] = '\0';
+
+		QString bss(reply);
+		if (bss.isEmpty() || bss.startsWith("FAIL"))
+			break;
 
-		QStringList cols = (*it).split(QChar('\t'));
 		QString ssid, bssid, freq, signal, flags;
-		bssid = cols.count() > 0 ? cols[0] : "";
-		freq = cols.count() > 1 ? cols[1] : "";
-		signal = cols.count() > 2 ? cols[2] : "";
-		flags = cols.count() > 3 ? cols[3] : "";
-		ssid = cols.count() > 4 ? cols[4] : "";
+
+		QStringList lines = bss.split(QRegExp("\\n"));
+		for (QStringList::Iterator it = lines.begin();
+		     it != lines.end(); it++) {
+			int pos = (*it).indexOf('=') + 1;
+			if (!pos)
+				continue;
+
+			if ((*it).startsWith("bssid="))
+				bssid = (*it).mid(pos);
+			else if ((*it).startsWith("freq="))
+				freq = (*it).mid(pos);
+			else if ((*it).startsWith("qual="))
+				signal = (*it).mid(pos);
+			else if ((*it).startsWith("flags="))
+				flags = (*it).mid(pos);
+			else if ((*it).startsWith("ssid="))
+				ssid = (*it).mid(pos);
+		}
 
 		QTreeWidgetItem *item = new QTreeWidgetItem(scanResultsWidget);
 		if (item) {
@@ -95,6 +102,12 @@
 			item->setText(3, signal);
 			item->setText(4, flags);
 		}
+
+		if (bssid.isEmpty())
+			break;
+
+		cmd = "BSS next ";
+		cmd.append(bssid);
 	}
 }
 
---



More information about the Hostap mailing list