[PATCH] Use BSS expiration age as fast association threshold

Masashi Honma masashi.honma
Thu Feb 28 21:21:37 PST 2013


2013/2/28 Jouni Malinen <j at w1.fi> wrote:

> On Tue, Feb 26, 2013 at 10:36:00PM +0900, Masashi Honma wrote:
> > diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
> > @@ -1344,7 +1344,7 @@ int wpa_supplicant_fast_associate(struct
>
> > -    if (now.sec - wpa_s->last_scan.sec > 5) {
> > +    if (now.sec - wpa_s->last_scan.sec > wpa_s->conf->bss_expiration_age) {
> >          wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
>
> This would change the default behavior to use up to 180 seconds old scan
> results to avoid the new scan. I don't think I want to go that far as
> the default behavior.. Scan results may have changed considerably and
> BSS or even network selection is not really going to be ideal if the
> device has moved.


I see.

My purpose is only making it configurable.
So I modified the patch.


[PATCH] Make scan results expiration age configurable

Signed-hostap: Masashi Honma <masashi.honma at gmail.com>

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 06efd2c..a2c6bf7 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -3386,6 +3386,15 @@ static int wpa_supplicant_ctrl_iface_scan_interval(
 }


+static int wpa_supplicant_ctrl_iface_last_scan_expiration_age(
+	struct wpa_supplicant *wpa_s, char *cmd)
+{
+	int expiration_age = atoi(cmd);
+	return wpa_supplicant_set_last_scan_expiration_age(wpa_s,
+							   expiration_age);
+}
+
+
 static int wpa_supplicant_ctrl_iface_bss_expire_age(
 	struct wpa_supplicant *wpa_s, char *cmd)
 {
@@ -5332,6 +5341,10 @@ char * wpa_supplicant_ctrl_iface_process(struct
wpa_supplicant *wpa_s,
 	} else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
 		if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
 			reply_len = -1;
+	} else if (os_strncmp(buf, "LAST_SCAN_EXPIRATION_AGE ", 25) == 0) {
+		if (wpa_supplicant_ctrl_iface_last_scan_expiration_age(
+		    wpa_s, buf + 25))
+			reply_len = -1;
 	} else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
 		reply_len = wpa_supplicant_global_iface_list(
 			wpa_s->global, reply, reply_size);
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 6c8ab6c..6813ff6 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -1343,10 +1343,14 @@ int wpa_supplicant_fast_associate(struct
wpa_supplicant *wpa_s)
 	if (wpa_s->last_scan_res_used <= 0)
 		return -1;

-	os_get_time(&now);
-	if (now.sec - wpa_s->last_scan.sec > 5) {
-		wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
-		return -1;
+	if (wpa_s->last_scan_expiration_age > 0) {
+		os_get_time(&now);
+		if (now.sec - wpa_s->last_scan.sec >
+		    wpa_s->last_scan_expiration_age) {
+			wpa_printf(MSG_DEBUG, "Fast associate: Old scan "
+				   "results");
+			return -1;
+		}
 	}

 	return wpas_select_network_from_last_scan(wpa_s);
diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index 133a077..f6f283c 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -658,6 +658,13 @@ static int wpa_cli_cmd_scan_interval(struct
wpa_ctrl *ctrl, int argc,
 }


+static int wpa_cli_cmd_last_scan_expiration_age(struct wpa_ctrl
*ctrl, int argc,
+						char *argv[])
+{
+	return wpa_cli_cmd(ctrl, "LAST_SCAN_EXPIRATION_AGE", 1, argc, argv);
+}
+
+
 static int wpa_cli_cmd_bss_expire_age(struct wpa_ctrl *ctrl, int argc,
 				      char *argv[])
 {
@@ -2464,6 +2471,9 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
 	{ "scan_interval", wpa_cli_cmd_scan_interval, NULL,
 	  cli_cmd_flag_none,
 	  "<value> = set scan_interval parameter (in seconds)" },
+	{ "last_scan_expiration_age", wpa_cli_cmd_last_scan_expiration_age,
+	  NULL, cli_cmd_flag_none,
+	  "<value> = set last_scan_expiration_age parameter (in seconds)" },
 	{ "bss_expire_age", wpa_cli_cmd_bss_expire_age, NULL,
 	  cli_cmd_flag_none,
 	  "<value> = set BSS expiration age parameter" },
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index fc3a84b..9fe7c60 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -1993,6 +1993,29 @@ int wpa_supplicant_set_scan_interval(struct
wpa_supplicant *wpa_s,


 /**
+ * wpa_supplicant_set_last_scan_expiration_age - Set last scan expiration age
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * @expiration_age: expiration age in seconds
+ * Returns: 0 if succeed or -1 if expiration_age has an invalid value
+ *
+ */
+int wpa_supplicant_set_last_scan_expiration_age(struct wpa_supplicant *wpa_s,
+						int expiration_age)
+{
+	if (expiration_age < 0) {
+		wpa_msg(wpa_s, MSG_ERROR, "Invalid expiration age %d",
+			expiration_age);
+		return -1;
+	}
+	wpa_msg(wpa_s, MSG_DEBUG, "Setting expiration age: %d sec",
+		expiration_age);
+	wpa_s->last_scan_expiration_age = expiration_age;
+
+	return 0;
+}
+
+
+/**
  * wpa_supplicant_set_debug_params - Set global debug params
  * @global: wpa_global structure
  * @debug_level: debug level
@@ -2417,6 +2440,7 @@ static struct wpa_supplicant * wpa_supplicant_alloc(void)
 		return NULL;
 	wpa_s->scan_req = INITIAL_SCAN_REQ;
 	wpa_s->scan_interval = 5;
+	wpa_s->last_scan_expiration_age = 5;
 	wpa_s->new_connection = 1;
 	wpa_s->parent = wpa_s;
 	wpa_s->sched_scanning = 0;
diff --git a/wpa_supplicant/wpa_supplicant_i.h
b/wpa_supplicant/wpa_supplicant_i.h
index 0f51f8e..c637f68 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -371,6 +371,7 @@ struct wpa_supplicant {
 	unsigned int last_scan_res_used;
 	unsigned int last_scan_res_size;
 	int last_scan_full;
+	int last_scan_expiration_age;
 	struct os_time last_scan;

 	struct wpa_driver_ops *driver;
@@ -724,6 +725,8 @@ int wpa_supplicant_set_bss_expiration_count(struct
wpa_supplicant *wpa_s,
 					    unsigned int expire_count);
 int wpa_supplicant_set_scan_interval(struct wpa_supplicant *wpa_s,
 				     int scan_interval);
+int wpa_supplicant_set_last_scan_expiration_age(struct wpa_supplicant *wpa_s,
+						int expiration_age);
 int wpa_supplicant_set_debug_params(struct wpa_global *global,
 				    int debug_level, int debug_timestamp,
 				    int debug_show_keys);


Regards,
Masashi Honma.



More information about the Hostap mailing list