From 67b9bd089b0a556d3a1aa417412ecfa46f05b960 Mon Sep 17 00:00:00 2001 From: Dmitry Shmidt Date: Mon, 11 Apr 2011 23:14:38 +0300 Subject: [PATCH] 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 --- wpa_supplicant/ctrl_iface.c | 14 ++++++++++++++ wpa_supplicant/events.c | 2 +- wpa_supplicant/wpa_cli.c | 23 +++++++++++++++++++++++ wpa_supplicant/wpa_supplicant.c | 1 + wpa_supplicant/wpa_supplicant_i.h | 1 + 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 5488ea447..dd39f8b0d 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/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); diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 7198e1ded..4d7fa82b6 100644 --- a/wpa_supplicant/events.c +++ b/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) { diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index e4224029d..f414af702 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/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, " = set ap_scan parameter" }, + { "scan_interval", wpa_cli_cmd_scan_interval, + cli_cmd_flag_none, + " = set scan_interval parameter (in seconds)" }, { "bss_expire_age", wpa_cli_cmd_bss_expire_age, cli_cmd_flag_none, " = set BSS expiration age parameter" }, diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index d8c2a2cce..2c5a20c62 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/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; diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 859a65b89..8498666fc 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/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;