Add option for disabling automatic reconnection on disconnection
authorArdong Chen <ardongchen@atheros.com>
Mon, 6 Sep 2010 14:28:45 +0000 (17:28 +0300)
committerJouni Malinen <j@w1.fi>
Fri, 10 Sep 2010 17:30:26 +0000 (10:30 -0700)
ctrl_interface STA_AUTOCONNECT command can now be used to disable
automatic reconnection on receiving disconnection event. The default
behavior is for wpa_supplicant to try to reconnect automatically, i.e.,
to maintain previous behavior.

wpa_supplicant/ctrl_iface.c
wpa_supplicant/events.c
wpa_supplicant/wpa_cli.c
wpa_supplicant/wpa_supplicant_i.h

index 7ffac96..27a7ffc 100644 (file)
@@ -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;
index 8bc05bd..0b26a9b 100644 (file)
@@ -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;
index cf2ab80..855f720 100644 (file)
@@ -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,
          "[<period> <interval>] = 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 }
 };
 
index df4a24d..66f544e 100644 (file)
@@ -525,6 +525,7 @@ struct wpa_supplicant {
        int after_wps;
        unsigned int wps_freq;
        int wps_fragment_size;
+       int auto_reconnect_disabled;
 };