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

login
register
mail settings
Submitter Piotr.Nakraszewicz@tieto.com
Date July 9, 2012, 12:04 p.m.
Message ID <E50901D4F2CF69428D43141B7C85867929E167DB39@EXMB03.eu.tieto.com>
Download mbox | patch
Permalink /patch/169799/
State Rejected
Headers show

Comments

Piotr.Nakraszewicz@tieto.com - July 9, 2012, 12:04 p.m.
Sending v2 based on Jouni's comment.

Pozdrawiam / Best regards,
Piotr


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.

Signed-hostap: Piotr Nakraszewicz <piotr.nakraszewicz@tieto.com>
---
 wpa_supplicant/bgscan_learn.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

Patch

diff --git a/wpa_supplicant/bgscan_learn.c b/wpa_supplicant/bgscan_learn.c
index ed4d879..9400480 100644
--- a/wpa_supplicant/bgscan_learn.c
+++ b/wpa_supplicant/bgscan_learn.c
@@ -151,6 +151,30 @@  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 (!end ||
+			    /* Compare ssid len (hexdump is twice as long) */
+			    (end - start) != (data->ssid->ssid_len * 2) ||
+			    /* Convert hexdump ssid to binary form */
+			    hexstr2bin(start, ssid, data->ssid->ssid_len) ||
+			    /* Compare ssid */
+			    os_memcmp(ssid, data->ssid->ssid,
+				      data->ssid->ssid_len)) {
+				wpa_printf(MSG_INFO, "bgscan learn: "
+					   "Different ssid in data file, "
+					   "ommiting BSS entries");
+				fclose(f);
+				return 0;
+			}
+		}
 	}
 
 	fclose(f);
@@ -162,6 +186,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 +200,15 @@  static void bgscan_learn_save(struct bgscan_learn_data *data)
 		return;
 	fprintf(f, "wpa_supplicant-bgscan-learn\n");
 
+	/* 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);