diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 7ffac965e..27a7ffcda 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -2590,6 +2590,14 @@ static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) #endif /* CONFIG_P2P */ +static int wpa_supplicant_ctrl_iface_sta_autoconnect( + struct wpa_supplicant *wpa_s, char *cmd) +{ + wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0; + return 0; +} + + char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, char *buf, size_t *resp_len) { @@ -2903,6 +2911,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, } else if (os_strncmp(buf, "ROAM ", 5) == 0) { if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) reply_len = -1; + } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { + if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16)) + reply_len = -1; } else { os_memcpy(reply, "UNKNOWN COMMAND\n", 16); reply_len = 16; diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 8bc05bd60..0b26a9bce 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -1225,8 +1225,19 @@ static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " "pre-shared key may be incorrect"); } - if (wpa_s->wpa_state >= WPA_ASSOCIATED) - wpa_supplicant_req_scan(wpa_s, 0, 100000); + if (!wpa_s->auto_reconnect_disabled || + wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { + wpa_printf(MSG_DEBUG, "WPA: Auto connect enabled: try to " + "reconnect (wps=%d)", + wpa_s->key_mgmt == WPA_KEY_MGMT_WPS); + if (wpa_s->wpa_state >= WPA_ASSOCIATED) + wpa_supplicant_req_scan(wpa_s, 0, 100000); + } else { + wpa_printf(MSG_DEBUG, "WPA: Auto connect disabled: do not try " + "to re-connect"); + wpa_s->reassociate = 0; + wpa_s->disconnected = 1; + } bssid = wpa_s->bssid; if (is_zero_ether_addr(bssid)) bssid = wpa_s->pending_bssid; diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index cf2ab80fb..855f720ad 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -2088,6 +2088,26 @@ static int wpa_cli_cmd_p2p_ext_listen(struct wpa_ctrl *ctrl, int argc, #endif /* CONFIG_P2P */ +static int wpa_cli_cmd_sta_autoconnect(struct wpa_ctrl *ctrl, int argc, + char *argv[]) +{ + char cmd[256]; + int res; + + if (argc != 1) { + printf("Invalid STA_AUTOCONNECT command: needs one argument " + "(0/1 = disable/enable automatic reconnection)\n"); + return -1; + } + res = os_snprintf(cmd, sizeof(cmd), "STA_AUTOCONNECT %s", argv[0]); + if (res < 0 || (size_t) res >= sizeof(cmd) - 1) { + printf("Too long STA_AUTOCONNECT command.\n"); + return -1; + } + return wpa_ctrl_command(ctrl, cmd); +} + + enum wpa_cli_cmd_flags { cli_cmd_flag_none = 0x00, cli_cmd_flag_sensitive = 0x01 @@ -2364,6 +2384,8 @@ static struct wpa_cli_cmd wpa_cli_commands[] = { { "p2p_ext_listen", wpa_cli_cmd_p2p_ext_listen, cli_cmd_flag_none, "[ ] = set extended listen timing" }, #endif /* CONFIG_P2P */ + { "sta_autoconnect", wpa_cli_cmd_sta_autoconnect, cli_cmd_flag_none, + "<0/1> = disable/enable automatic reconnection" }, { NULL, NULL, cli_cmd_flag_none, NULL } }; diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index df4a24ded..66f544e3a 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -525,6 +525,7 @@ struct wpa_supplicant { int after_wps; unsigned int wps_freq; int wps_fragment_size; + int auto_reconnect_disabled; };