Parcourir la source

Make scan interval configurable

It is now possible to configure the the time in seconds that
wpa_supplicant waits before requesting a new scan after failing to find
a suitable network in scan results.

Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
Dmitry Shmidt il y a 14 ans
Parent
commit
67b9bd089b

+ 14 - 0
wpa_supplicant/ctrl_iface.c

@@ -2005,6 +2005,17 @@ static int wpa_supplicant_ctrl_iface_ap_scan(
 }
 
 
+static int wpa_supplicant_ctrl_iface_scan_interval(
+	struct wpa_supplicant *wpa_s, char *cmd)
+{
+	int scan_int = atoi(cmd);
+	if (scan_int < 0)
+		return -1;
+	wpa_s->scan_interval = scan_int;
+	return 0;
+}
+
+
 static int wpa_supplicant_ctrl_iface_bss_expire_age(
 	struct wpa_supplicant *wpa_s, char *cmd)
 {
@@ -3190,6 +3201,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
 	} else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
 		if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
 			reply_len = -1;
+	} 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_strcmp(buf, "INTERFACE_LIST") == 0) {
 		reply_len = wpa_supplicant_global_iface_list(
 			wpa_s->global, reply, reply_size);

+ 1 - 1
wpa_supplicant/events.c

@@ -965,7 +965,7 @@ static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
 			wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
 			wpa_supplicant_associate(wpa_s, NULL, ssid);
 		} else {
-			int timeout_sec = 5;
+			int timeout_sec = wpa_s->scan_interval;
 			int timeout_usec = 0;
 #ifdef CONFIG_P2P
 			if (wpa_s->p2p_in_provisioning) {

+ 23 - 0
wpa_supplicant/wpa_cli.c

@@ -475,6 +475,26 @@ static int wpa_cli_cmd_ap_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static int wpa_cli_cmd_scan_interval(struct wpa_ctrl *ctrl, int argc,
+				     char *argv[])
+{
+	char cmd[256];
+	int res;
+
+	if (argc != 1) {
+		printf("Invalid SCAN_INTERVAL command: needs one argument "
+		       "scan_interval value)\n");
+		return -1;
+	}
+	res = os_snprintf(cmd, sizeof(cmd), "SCAN_INTERVAL %s", argv[0]);
+	if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+		printf("Too long SCAN_INTERVAL command.\n");
+		return -1;
+	}
+	return wpa_ctrl_command(ctrl, cmd);
+}
+
+
 static int wpa_cli_cmd_bss_expire_age(struct wpa_ctrl *ctrl, int argc,
 				      char *argv[])
 {
@@ -2429,6 +2449,9 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
 	{ "ap_scan", wpa_cli_cmd_ap_scan,
 	  cli_cmd_flag_none,
 	  "<value> = set ap_scan parameter" },
+	{ "scan_interval", wpa_cli_cmd_scan_interval,
+	  cli_cmd_flag_none,
+	  "<value> = set scan_interval parameter (in seconds)" },
 	{ "bss_expire_age", wpa_cli_cmd_bss_expire_age,
 	  cli_cmd_flag_none,
 	  "<value> = set BSS expiration age parameter" },

+ 1 - 0
wpa_supplicant/wpa_supplicant.c

@@ -2068,6 +2068,7 @@ static struct wpa_supplicant * wpa_supplicant_alloc(void)
 	if (wpa_s == NULL)
 		return NULL;
 	wpa_s->scan_req = 1;
+	wpa_s->scan_interval = 5;
 	wpa_s->new_connection = 1;
 	wpa_s->parent = wpa_s;
 

+ 1 - 0
wpa_supplicant/wpa_supplicant_i.h

@@ -405,6 +405,7 @@ struct wpa_supplicant {
 		       * are no enabled networks in the configuration */
 	int scan_runs; /* number of scan runs since WPS was started */
 	int *next_scan_freqs;
+	int scan_interval; /* time in sec between scans to find suitable AP */
 
 	struct wpa_client_mlme mlme;
 	unsigned int drv_flags;