From 3e7533b3990a130408bc37f55983d09709b1e355 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 25 Oct 2010 21:29:22 +0300 Subject: [PATCH] WPS ER: Show SetSelectedRegistrar events as ctrl_iface events This makes it easier to figure out if something goes wrong in preparing the AP for enrolling a station. --- src/ap/wps_hostapd.c | 2 ++ src/common/wpa_ctrl.h | 1 + src/wps/wps.h | 19 ++++++++++++++++++- src/wps/wps_er.c | 24 +++++++++++++++++++++++- wpa_supplicant/wps_supplicant.c | 31 +++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/ap/wps_hostapd.c b/src/ap/wps_hostapd.c index 75a058657..ba02757df 100644 --- a/src/ap/wps_hostapd.c +++ b/src/ap/wps_hostapd.c @@ -571,6 +571,8 @@ static void hostapd_wps_event_cb(void *ctx, enum wps_event event, break; case WPS_EV_ER_AP_SETTINGS: break; + case WPS_EV_ER_SET_SELECTED_REGISTRAR: + break; } if (hapd->wps_event_cb) hapd->wps_event_cb(hapd->wps_event_cb_ctx, event, data); diff --git a/src/common/wpa_ctrl.h b/src/common/wpa_ctrl.h index b70cf7a37..8a29fb659 100644 --- a/src/common/wpa_ctrl.h +++ b/src/common/wpa_ctrl.h @@ -89,6 +89,7 @@ extern "C" { #define WPS_EVENT_ER_ENROLLEE_ADD "WPS-ER-ENROLLEE-ADD " #define WPS_EVENT_ER_ENROLLEE_REMOVE "WPS-ER-ENROLLEE-REMOVE " #define WPS_EVENT_ER_AP_SETTINGS "WPS-ER-AP-SETTINGS " +#define WPS_EVENT_ER_SET_SEL_REG "WPS-ER-AP-SET-SEL-REG " /** P2P device found */ #define P2P_EVENT_DEVICE_FOUND "P2P-DEVICE-FOUND " diff --git a/src/wps/wps.h b/src/wps/wps.h index bf8bddc44..ce0a22634 100644 --- a/src/wps/wps.h +++ b/src/wps/wps.h @@ -417,7 +417,12 @@ enum wps_event { /** * WPS_EV_ER_AP_SETTINGS - ER: AP Settings learned */ - WPS_EV_ER_AP_SETTINGS + WPS_EV_ER_AP_SETTINGS, + + /** + * WPS_EV_ER_SET_SELECTED_REGISTRAR - ER: SetSelectedRegistrar event + */ + WPS_EV_ER_SET_SELECTED_REGISTRAR }; /** @@ -492,6 +497,18 @@ union wps_event_data { const u8 *uuid; const struct wps_credential *cred; } ap_settings; + + struct wps_event_er_set_selected_registrar { + const u8 *uuid; + int sel_reg; + u16 dev_passwd_id; + u16 sel_reg_config_methods; + enum { + WPS_ER_SET_SEL_REG_START, + WPS_ER_SET_SEL_REG_DONE, + WPS_ER_SET_SEL_REG_FAILED + } state; + } set_sel_reg; }; /** diff --git a/src/wps/wps_er.c b/src/wps/wps_er.c index 473cfc315..ed5659f61 100644 --- a/src/wps/wps_er.c +++ b/src/wps/wps_er.c @@ -1269,19 +1269,30 @@ static void wps_er_http_set_sel_reg_cb(void *ctx, struct http_client *c, enum http_client_event event) { struct wps_er_ap *ap = ctx; + union wps_event_data data; + + os_memset(&data, 0, sizeof(data)); switch (event) { case HTTP_CLIENT_OK: wpa_printf(MSG_DEBUG, "WPS ER: SetSelectedRegistrar OK"); + data.set_sel_reg.state = WPS_ER_SET_SEL_REG_DONE; + data.set_sel_reg.uuid = ap->uuid; break; case HTTP_CLIENT_FAILED: case HTTP_CLIENT_INVALID_REPLY: case HTTP_CLIENT_TIMEOUT: wpa_printf(MSG_DEBUG, "WPS ER: SetSelectedRegistrar failed"); + data.set_sel_reg.state = WPS_ER_SET_SEL_REG_FAILED; + data.set_sel_reg.uuid = ap->uuid; break; } http_client_free(ap->http); ap->http = NULL; + + if (data.set_sel_reg.uuid) + ap->er->wps->event_cb(ap->er->wps->cb_ctx, + WPS_EV_ER_SET_SELECTED_REGISTRAR, &data); } @@ -1377,6 +1388,7 @@ void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id, struct wps_registrar *reg = er->wps->registrar; const u8 *auth_macs; size_t count; + union wps_event_data data; if (er->skip_set_sel_reg) { wpa_printf(MSG_DEBUG, "WPS ER: Skip SetSelectedRegistrar"); @@ -1399,8 +1411,18 @@ void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id, return; } - dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) + os_memset(&data, 0, sizeof(data)); + data.set_sel_reg.sel_reg = sel_reg; + data.set_sel_reg.dev_passwd_id = dev_passwd_id; + data.set_sel_reg.sel_reg_config_methods = sel_reg_config_methods; + data.set_sel_reg.state = WPS_ER_SET_SEL_REG_START; + + dl_list_for_each(ap, &er->ap, struct wps_er_ap, list) { + data.set_sel_reg.uuid = ap->uuid; + er->wps->event_cb(er->wps->cb_ctx, + WPS_EV_ER_SET_SELECTED_REGISTRAR, &data); wps_er_send_set_sel_reg(ap, msg); + } wpabuf_free(msg); } diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c index bc8dc420f..e2adb608c 100644 --- a/wpa_supplicant/wps_supplicant.c +++ b/wpa_supplicant/wps_supplicant.c @@ -509,6 +509,33 @@ static void wpa_supplicant_wps_event_er_ap_settings( } +static void wpa_supplicant_wps_event_er_set_sel_reg( + struct wpa_supplicant *wpa_s, + struct wps_event_er_set_selected_registrar *ev) +{ + char uuid_str[100]; + + uuid_bin2str(ev->uuid, uuid_str, sizeof(uuid_str)); + switch (ev->state) { + case WPS_ER_SET_SEL_REG_START: + wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG + "uuid=%s state=START sel_reg=%d dev_passwd_id=%u " + "sel_reg_config_methods=0x%x", + uuid_str, ev->sel_reg, ev->dev_passwd_id, + ev->sel_reg_config_methods); + break; + case WPS_ER_SET_SEL_REG_DONE: + wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG + "uuid=%s state=DONE", uuid_str); + break; + case WPS_ER_SET_SEL_REG_FAILED: + wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_SET_SEL_REG + "uuid=%s state=FAILED", uuid_str); + break; + } +} + + static void wpa_supplicant_wps_event(void *ctx, enum wps_event event, union wps_event_data *data) { @@ -547,6 +574,10 @@ static void wpa_supplicant_wps_event(void *ctx, enum wps_event event, wpa_supplicant_wps_event_er_ap_settings(wpa_s, &data->ap_settings); break; + case WPS_EV_ER_SET_SELECTED_REGISTRAR: + wpa_supplicant_wps_event_er_set_sel_reg(wpa_s, + &data->set_sel_reg); + break; } }