[PATCH 2/2]: wpa_gui-qt4: get bssid count before iterating through scan results

Kel Modderman kel
Fri Feb 1 02:54:32 PST 2008


Resending this patch, with improvements.

Use the new "BSS count" ctrl interface command to determine upper limit of
how many bssid's are expected to be in the scan results.

Use a for loop to iterate through the scan results, to ensure we have a finite
end point.

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,11 +56,30 @@
 {
 	char reply[2048];
 	size_t reply_len;
-    
+	int bss_count = 0;
+	int i;
+
 	scanResultsWidget->clear();
-	QString cmd("BSS first");
 
-	while (wpagui) {
+	QString cmd("BSS count");
+
+	reply_len = sizeof(reply) - 1;
+	if (wpagui->ctrlRequest(cmd.toAscii().constData(), reply, &reply_len)
+	    >= 0) {
+		reply[reply_len] = '\0';
+		if (memcmp(reply, "FAIL", 4) != 0)
+			bss_count = atoi(reply);
+	}
+
+	if (bss_count < 1)
+		return;
+
+	cmd = "BSS first";
+
+	for (i = 0; i < bss_count; i++) {
+		if (wpagui == NULL)
+			break;
+
 		reply_len = sizeof(reply) - 1;
 		if (wpagui->ctrlRequest(cmd.toAscii().constData(), reply,
 		    &reply_len) < 0)
@@ -92,6 +111,9 @@
 				ssid = (*it).mid(pos);
 		}
 
+		if (bssid.isEmpty())
+			break;
+
 		QTreeWidgetItem *item = new QTreeWidgetItem(scanResultsWidget);
 		if (item) {
 			item->setText(0, ssid);
@@ -101,9 +123,6 @@
 			item->setText(4, flags);
 		}
 
-		if (bssid.isEmpty())
-			break;
-
 		cmd = "BSS next ";
 		cmd.append(bssid);
 	}
---



More information about the Hostap mailing list