diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index b1bafc10c..63fe557e4 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -755,6 +755,9 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx, } else if (os_strcmp(buf, "WPS_PBC") == 0) { if (hostapd_wps_button_pushed(hapd, NULL)) reply_len = -1; + } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { + if (hostapd_wps_cancel(hapd)) + reply_len = -1; #ifdef CONFIG_WPS_OOB } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) { if (hostapd_ctrl_iface_wps_oob(hapd, buf + 8)) diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index 89125fdf7..e2d9f9f87 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -392,6 +392,13 @@ static int hostapd_cli_cmd_wps_pbc(struct wpa_ctrl *ctrl, int argc, } +static int hostapd_cli_cmd_wps_cancel(struct wpa_ctrl *ctrl, int argc, + char *argv[]) +{ + return wpa_ctrl_command(ctrl, "WPS_CANCEL"); +} + + #ifdef CONFIG_WPS_OOB static int hostapd_cli_cmd_wps_oob(struct wpa_ctrl *ctrl, int argc, char *argv[]) @@ -719,6 +726,7 @@ static struct hostapd_cli_cmd hostapd_cli_commands[] = { { "wps_pin", hostapd_cli_cmd_wps_pin }, { "wps_check_pin", hostapd_cli_cmd_wps_check_pin }, { "wps_pbc", hostapd_cli_cmd_wps_pbc }, + { "wps_cancel", hostapd_cli_cmd_wps_cancel }, #ifdef CONFIG_WPS_OOB { "wps_oob", hostapd_cli_cmd_wps_oob }, #endif /* CONFIG_WPS_OOB */ diff --git a/src/ap/sta_info.c b/src/ap/sta_info.c index c1c212bbf..d8b5621bc 100644 --- a/src/ap/sta_info.c +++ b/src/ap/sta_info.c @@ -592,6 +592,23 @@ void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta, } +#ifdef CONFIG_WPS +int ap_sta_wps_cancel(struct hostapd_data *hapd, + struct sta_info *sta, void *ctx) +{ + if (sta && (sta->flags & WLAN_STA_WPS)) { + ap_sta_deauthenticate(hapd, sta, + WLAN_REASON_PREV_AUTH_NOT_VALID); + wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR, + __func__, MAC2STR(sta->addr)); + return 1; + } + + return 0; +} +#endif /* CONFIG_WPS */ + + int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta, int old_vlanid) { diff --git a/src/ap/sta_info.h b/src/ap/sta_info.h index d3a0fe1a9..2f3af1b52 100644 --- a/src/ap/sta_info.h +++ b/src/ap/sta_info.h @@ -156,6 +156,10 @@ void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta, u16 reason); void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta, u16 reason); +#ifdef CONFIG_WPS +int ap_sta_wps_cancel(struct hostapd_data *hapd, + struct sta_info *sta, void *ctx); +#endif /* CONFIG_WPS */ int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta, int old_vlanid); void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta); diff --git a/src/ap/wps_hostapd.c b/src/ap/wps_hostapd.c index 94eea255e..01038e9e2 100644 --- a/src/ap/wps_hostapd.c +++ b/src/ap/wps_hostapd.c @@ -1104,6 +1104,24 @@ int hostapd_wps_button_pushed(struct hostapd_data *hapd, } +static int wps_cancel(struct hostapd_data *hapd, void *ctx) +{ + if (hapd->wps == NULL) + return 0; + + wps_registrar_wps_cancel(hapd->wps->registrar); + ap_for_each_sta(hapd, ap_sta_wps_cancel, NULL); + + return 0; +} + + +int hostapd_wps_cancel(struct hostapd_data *hapd) +{ + return hostapd_wps_for_each(hapd, wps_cancel, NULL); +} + + #ifdef CONFIG_WPS_OOB int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type, char *path, char *method, char *name) diff --git a/src/ap/wps_hostapd.h b/src/ap/wps_hostapd.h index 91942250a..5f5d2f6d4 100644 --- a/src/ap/wps_hostapd.h +++ b/src/ap/wps_hostapd.h @@ -20,6 +20,7 @@ int hostapd_wps_add_pin(struct hostapd_data *hapd, const u8 *addr, const char *uuid, const char *pin, int timeout); int hostapd_wps_button_pushed(struct hostapd_data *hapd, const u8 *p2p_dev_addr); +int hostapd_wps_cancel(struct hostapd_data *hapd); int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type, char *path, char *method, char *name); int hostapd_wps_get_mib_sta(struct hostapd_data *hapd, const u8 *addr, @@ -67,6 +68,11 @@ static inline int hostapd_wps_button_pushed(struct hostapd_data *hapd, return 0; } +static inline int hostapd_wps_cancel(struct hostapd_data *hapd) +{ + return 0; +} + #endif /* CONFIG_WPS */ #endif /* WPS_HOSTAPD_H */ diff --git a/wpa_supplicant/ap.c b/wpa_supplicant/ap.c index d18e3f1c2..66b0e1f8f 100644 --- a/wpa_supplicant/ap.c +++ b/wpa_supplicant/ap.c @@ -659,21 +659,6 @@ int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid, } -static int wpa_supplicant_ap_wps_sta_cancel(struct hostapd_data *hapd, - struct sta_info *sta, void *ctx) -{ - if (sta && (sta->flags & WLAN_STA_WPS)) { - ap_sta_deauthenticate(hapd, sta, - WLAN_REASON_PREV_AUTH_NOT_VALID); - wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR, - __func__, MAC2STR(sta->addr)); - return 1; - } - - return 0; -} - - int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s) { struct wps_registrar *reg; @@ -685,7 +670,7 @@ int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s) reg = wpa_s->ap_iface->bss[0]->wps->registrar; reg_sel = wps_registrar_wps_cancel(reg); wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0], - wpa_supplicant_ap_wps_sta_cancel, NULL); + ap_sta_wps_cancel, NULL); if (!reg_sel && !wps_sta) { wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "