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>
This commit is contained in:
Dmitry Shmidt 2011-04-11 23:14:38 +03:00 committed by Jouni Malinen
parent df13a1cdff
commit 67b9bd089b
5 changed files with 40 additions and 1 deletions

View file

@ -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( static int wpa_supplicant_ctrl_iface_bss_expire_age(
struct wpa_supplicant *wpa_s, char *cmd) 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) { } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
reply_len = -1; 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) { } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
reply_len = wpa_supplicant_global_iface_list( reply_len = wpa_supplicant_global_iface_list(
wpa_s->global, reply, reply_size); wpa_s->global, reply, reply_size);

View file

@ -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_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
wpa_supplicant_associate(wpa_s, NULL, ssid); wpa_supplicant_associate(wpa_s, NULL, ssid);
} else { } else {
int timeout_sec = 5; int timeout_sec = wpa_s->scan_interval;
int timeout_usec = 0; int timeout_usec = 0;
#ifdef CONFIG_P2P #ifdef CONFIG_P2P
if (wpa_s->p2p_in_provisioning) { if (wpa_s->p2p_in_provisioning) {

View file

@ -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, static int wpa_cli_cmd_bss_expire_age(struct wpa_ctrl *ctrl, int argc,
char *argv[]) char *argv[])
{ {
@ -2429,6 +2449,9 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
{ "ap_scan", wpa_cli_cmd_ap_scan, { "ap_scan", wpa_cli_cmd_ap_scan,
cli_cmd_flag_none, cli_cmd_flag_none,
"<value> = set ap_scan parameter" }, "<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, { "bss_expire_age", wpa_cli_cmd_bss_expire_age,
cli_cmd_flag_none, cli_cmd_flag_none,
"<value> = set BSS expiration age parameter" }, "<value> = set BSS expiration age parameter" },

View file

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

View file

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