]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add ctrl_iface command FLUSH for clearing wpa_supplicant state
authorJouni Malinen <j@w1.fi>
Sun, 31 Mar 2013 17:31:07 +0000 (20:31 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 31 Mar 2013 17:31:07 +0000 (20:31 +0300)
This is mainly for testing purposes where it is convenient to have an
easy way of getting wpa_supplicant state cleared between test cases.

Signed-hostap: Jouni Malinen <j@w1.fi>

wpa_supplicant/ctrl_iface.c
wpa_supplicant/wpa_cli.c

index 3f1111b45fac82f1ebb1887f5cd8d697daa24c54..49497718a6d9d1d56edbb2c909b37e53d173cb9a 100644 (file)
@@ -4490,6 +4490,15 @@ static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
 }
 
 
+static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
+{
+       os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
+       wpa_s->force_long_sd = 0;
+       if (wpa_s->global->p2p)
+               p2p_flush(wpa_s->global->p2p);
+}
+
+
 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
 {
        char *pos, *pos2;
@@ -4946,6 +4955,54 @@ static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
 }
 
 
+static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
+{
+       wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
+
+#ifdef CONFIG_P2P
+       wpas_p2p_stop_find(wpa_s);
+       p2p_ctrl_flush(wpa_s);
+       wpas_p2p_group_remove(wpa_s, "*");
+#endif /* CONFIG_P2P */
+
+#ifdef CONFIG_WPS_TESTING
+       wps_version_number = 0x20;
+       wps_testing_dummy_cred = 0;
+#endif /* CONFIG_WPS_TESTING */
+#ifdef CONFIG_WPS
+       wpas_wps_cancel(wpa_s);
+#endif /* CONFIG_WPS */
+
+#ifdef CONFIG_TDLS_TESTING
+       extern unsigned int tdls_testing;
+       tdls_testing = 0;
+#endif /* CONFIG_TDLS_TESTING */
+#ifdef CONFIG_TDLS
+       wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
+       wpa_tdls_enable(wpa_s->wpa, 1);
+#endif /* CONFIG_TDLS */
+
+       wpa_s->no_keep_alive = 0;
+
+       os_free(wpa_s->disallow_aps_bssid);
+       wpa_s->disallow_aps_bssid = NULL;
+       wpa_s->disallow_aps_bssid_count = 0;
+       os_free(wpa_s->disallow_aps_ssid);
+       wpa_s->disallow_aps_ssid = NULL;
+       wpa_s->disallow_aps_ssid_count = 0;
+
+       wpa_s->set_sta_uapsd = 0;
+       wpa_s->sta_uapsd = 0;
+
+       wpa_drv_radio_disable(wpa_s, 0);
+
+       wpa_bss_flush(wpa_s);
+       wpa_blacklist_clear(wpa_s);
+       wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
+       wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
+}
+
+
 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                                         char *buf, size_t *resp_len)
 {
@@ -5223,10 +5280,7 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
                        reply_len = -1;
        } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
-               os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
-               wpa_s->force_long_sd = 0;
-               if (wpa_s->global->p2p)
-                       p2p_flush(wpa_s->global->p2p);
+               p2p_ctrl_flush(wpa_s);
        } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
                if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
                        reply_len = -1;
@@ -5474,6 +5528,8 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
                        reply_len = -1;
 #endif /* CONFIG_WNM */
+       } else if (os_strcmp(buf, "FLUSH") == 0) {
+               wpa_supplicant_ctrl_iface_flush(wpa_s);
        } else {
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
                reply_len = 16;
index 9fb9d0bbb181c33bf08ec792d84eb5b37c648a74..3765c4e682c08a5341cbf5527a2df5f13ae54c83 100644 (file)
@@ -2279,6 +2279,12 @@ static int wpa_cli_cmd_raw(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static int wpa_cli_cmd_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+       return wpa_ctrl_command(ctrl, "FLUSH");
+}
+
+
 enum wpa_cli_cmd_flags {
        cli_cmd_flag_none               = 0x00,
        cli_cmd_flag_sensitive          = 0x01
@@ -2726,6 +2732,8 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
 #endif /* CONFIG_WNM */
        { "raw", wpa_cli_cmd_raw, NULL, cli_cmd_flag_sensitive,
          "<params..> = Sent unprocessed command" },
+       { "flush", wpa_cli_cmd_flush, NULL, cli_cmd_flag_none,
+         "= flush wpa_supplicant state" },
        { NULL, NULL, NULL, cli_cmd_flag_none, NULL }
 };