Add ctrl_iface command FLUSH for clearing wpa_supplicant state

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>
This commit is contained in:
Jouni Malinen 2013-03-31 20:31:07 +03:00
parent 97236cee6a
commit acb546436a
2 changed files with 68 additions and 4 deletions

View 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) static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
{ {
char *pos, *pos2; 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 * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
char *buf, size_t *resp_len) 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) if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
reply_len = -1; reply_len = -1;
} else if (os_strcmp(buf, "P2P_FLUSH") == 0) { } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); p2p_ctrl_flush(wpa_s);
wpa_s->force_long_sd = 0;
if (wpa_s->global->p2p)
p2p_flush(wpa_s->global->p2p);
} else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
reply_len = -1; 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)) if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
reply_len = -1; reply_len = -1;
#endif /* CONFIG_WNM */ #endif /* CONFIG_WNM */
} else if (os_strcmp(buf, "FLUSH") == 0) {
wpa_supplicant_ctrl_iface_flush(wpa_s);
} else { } else {
os_memcpy(reply, "UNKNOWN COMMAND\n", 16); os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
reply_len = 16; reply_len = 16;

View 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 { enum wpa_cli_cmd_flags {
cli_cmd_flag_none = 0x00, cli_cmd_flag_none = 0x00,
cli_cmd_flag_sensitive = 0x01 cli_cmd_flag_sensitive = 0x01
@ -2726,6 +2732,8 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
#endif /* CONFIG_WNM */ #endif /* CONFIG_WNM */
{ "raw", wpa_cli_cmd_raw, NULL, cli_cmd_flag_sensitive, { "raw", wpa_cli_cmd_raw, NULL, cli_cmd_flag_sensitive,
"<params..> = Sent unprocessed command" }, "<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 } { NULL, NULL, NULL, cli_cmd_flag_none, NULL }
}; };