From 5ab9a6a53e8fcd667aa96dfe1022ae1ca6def892 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 15 Feb 2013 12:34:55 +0200 Subject: [PATCH] WPS: Add support for NFC handover select generation with wpa_supplicant When wpa_supplicant is controlling an AP mode interface, it can generate the alternative carrier record for NFC connection handover select message similarly to the way this is done in hostapd. Signed-hostap: Jouni Malinen --- wpa_supplicant/ap.c | 12 ++++++++++++ wpa_supplicant/ap.h | 2 ++ wpa_supplicant/ctrl_iface.c | 19 +++++++++++++------ wpa_supplicant/wps_supplicant.c | 7 +++++-- wpa_supplicant/wps_supplicant.h | 3 ++- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/wpa_supplicant/ap.c b/wpa_supplicant/ap.c index df0bba07b..23c7025e3 100644 --- a/wpa_supplicant/ap.c +++ b/wpa_supplicant/ap.c @@ -860,6 +860,18 @@ struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s, return hostapd_wps_nfc_config_token(hapd, ndef); } + +struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s, + int ndef) +{ + struct hostapd_data *hapd; + + if (wpa_s->ap_iface == NULL) + return NULL; + hapd = wpa_s->ap_iface->bss[0]; + return hostapd_wps_nfc_hs_cr(hapd, ndef); +} + #endif /* CONFIG_WPS */ diff --git a/wpa_supplicant/ap.h b/wpa_supplicant/ap.h index a997937ee..fd4c25abb 100644 --- a/wpa_supplicant/ap.h +++ b/wpa_supplicant/ap.h @@ -54,5 +54,7 @@ void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht, int offset); struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s, int ndef); +struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s, + int ndef); #endif /* AP_H */ diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 1163c2453..f36fef759 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -909,12 +909,13 @@ static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s, static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s, - char *reply, size_t max_len) + char *reply, size_t max_len, + int ndef, int cr) { struct wpabuf *buf; int res; - buf = wpas_wps_nfc_handover_sel(wpa_s); + buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr); if (buf == NULL) return -1; @@ -934,18 +935,24 @@ static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s, size_t max_len) { char *pos; + int ndef; pos = os_strchr(cmd, ' '); if (pos == NULL) return -1; *pos++ = '\0'; - if (os_strcmp(cmd, "NDEF") != 0) + if (os_strcmp(cmd, "WPS") == 0) + ndef = 0; + else if (os_strcmp(cmd, "NDEF") == 0) + ndef = 1; + else return -1; - if (os_strcmp(pos, "WPS") == 0) { - return wpas_ctrl_nfc_get_handover_sel_wps(wpa_s, reply, - max_len); + if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { + return wpas_ctrl_nfc_get_handover_sel_wps( + wpa_s, reply, max_len, ndef, + os_strcmp(pos, "WPS-CR") == 0); } return -1; diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c index a38972b5c..c89479f7d 100644 --- a/wpa_supplicant/wps_supplicant.c +++ b/wpa_supplicant/wps_supplicant.c @@ -2003,9 +2003,12 @@ struct wpabuf * wpas_wps_nfc_handover_req(struct wpa_supplicant *wpa_s, int cr) } -struct wpabuf * wpas_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s) +struct wpabuf * wpas_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s, + int ndef, int cr) { - return NULL; + if (!cr) + return NULL; + return wpas_ap_wps_nfc_handover_sel(wpa_s, ndef); } diff --git a/wpa_supplicant/wps_supplicant.h b/wpa_supplicant/wps_supplicant.h index c3816f457..5bc5ffa5d 100644 --- a/wpa_supplicant/wps_supplicant.h +++ b/wpa_supplicant/wps_supplicant.h @@ -69,7 +69,8 @@ int wpas_wps_start_nfc(struct wpa_supplicant *wpa_s, const u8 *bssid); int wpas_wps_nfc_tag_read(struct wpa_supplicant *wpa_s, const struct wpabuf *data); struct wpabuf * wpas_wps_nfc_handover_req(struct wpa_supplicant *wpa_s, int cr); -struct wpabuf * wpas_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s); +struct wpabuf * wpas_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s, + int ndef, int cr); int wpas_wps_nfc_rx_handover_req(struct wpa_supplicant *wpa_s, const struct wpabuf *data); int wpas_wps_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,