[PATCHv2] bgscan_learn: Load BSS entries from current SSID only

Jouni Malinen j
Tue Dec 25 10:47:55 PST 2012


On Mon, Jul 09, 2012 at 03:04:03PM +0300, Piotr.Nakraszewicz at tieto.com wrote:
> bgscan_learn wrongly loads BSS entries from data file even if
> we changed ESS we are connected to. To prevent that add SSID
> parameter (stored as a hexdump) to data file and compare it with
> current SSID before loading the entries.

The patch itself was relatively okay (needed to check data->ssid->ssid
!= NULL and a small typo in a comment) and I was about to apply this.
However, I was trying to figure out the case where there would be a case
where this is needed and couldn't come up with any.. The bgscan learn
data file is supposed to be pointing to a different file for each ssid
block and as such, this type of per-SSID filtering is implicitly handled
by wpa_supplicant restarting the bgscan module for each network. Why
would this need to be handled with an explicit SSID information with the
data file?

Even though I did not apply this, the following patch shows the somewhat
cleaned up version I was testing with.


diff --git a/wpa_supplicant/bgscan_learn.c b/wpa_supplicant/bgscan_learn.c
index 07d31e4..c9e6f57 100644
--- a/wpa_supplicant/bgscan_learn.c
+++ b/wpa_supplicant/bgscan_learn.c
@@ -151,6 +151,29 @@ static int bgscan_learn_load(struct bgscan_learn_data *data)
 
 			bgscan_learn_add_neighbor(bss, addr);
 		}
+
+		if (os_strncmp(buf, "SSID ", 5) == 0) {
+			/*
+			 * Check if current SSID is the same as the one stored
+			 * in the data file.
+			 */
+			u8 ssid[MAX_SSID_LEN];
+			char *start = buf + 5;
+			char *end = os_strstr(start, "\n");
+
+			if (data->ssid->ssid &&
+			    (!end ||
+			     end - start != (int) data->ssid->ssid_len * 2 ||
+			     hexstr2bin(start, ssid, data->ssid->ssid_len) ||
+			     os_memcmp(ssid, data->ssid->ssid,
+				       data->ssid->ssid_len) != 0)) {
+				wpa_printf(MSG_INFO, "bgscan learn: "
+					   "Different SSID in data file, "
+					   "omitting BSS entries");
+				fclose(f);
+				return 0;
+			}
+		}
 	}
 
 	fclose(f);
@@ -162,6 +185,8 @@ static void bgscan_learn_save(struct bgscan_learn_data *data)
 {
 	FILE *f;
 	struct bgscan_learn_bss *bss;
+	char buf[2 * MAX_SSID_LEN + 5 + 2];
+	char *pos;
 
 	if (data->fname == NULL)
 		return;
@@ -174,6 +199,17 @@ static void bgscan_learn_save(struct bgscan_learn_data *data)
 		return;
 	fprintf(f, "wpa_supplicant-bgscan-learn\n");
 
+	if (data->ssid->ssid) {
+		/* Store SSID as a hexdump */
+		pos = buf;
+		os_memcpy(pos, "SSID ", 5);
+		pos += 5;
+		pos += wpa_snprintf_hex(pos, 2 * MAX_SSID_LEN + 1,
+					data->ssid->ssid, data->ssid->ssid_len);
+		os_memcpy(pos, "\n", 2);
+		fprintf(f, "%s", buf);
+	}
+
 	dl_list_for_each(bss, &data->bss, struct bgscan_learn_bss, list) {
 		fprintf(f, "BSS " MACSTR " %d\n",
 			MAC2STR(bss->bssid), bss->freq);

-- 
Jouni Malinen                                            PGP id EFC895FA



More information about the Hostap mailing list