From e9a7ae41fa4dcb5df2e1244182ae279b6a16ce17 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Thu, 5 Aug 2010 09:15:11 -0700 Subject: [PATCH] P2P: Use SSID from GO Negotiation to limit WPS provisioning step In order to avoid picking incorrect SSID from old scan results, use SSID from GO Negotiation to select the AP. --- src/p2p/p2p.c | 7 ++++++- src/p2p/p2p_go_neg.c | 10 ++++++++-- wpa_supplicant/p2p_supplicant.c | 2 ++ wpa_supplicant/wps_supplicant.c | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index 608f834fc..7a1a315f6 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -1092,8 +1092,13 @@ void p2p_go_complete(struct p2p_data *p2p, struct p2p_device *peer) os_memcpy(res.ssid, p2p->ssid, p2p->ssid_len); res.ssid_len = p2p->ssid_len; p2p_random(res.passphrase, 8); - } else + } else { res.freq = peer->oper_freq; + if (p2p->ssid_len) { + os_memcpy(res.ssid, p2p->ssid, p2p->ssid_len); + res.ssid_len = p2p->ssid_len; + } + } p2p_channels_intersect(&p2p->channels, &peer->channels, &intersection); diff --git a/src/p2p/p2p_go_neg.c b/src/p2p/p2p_go_neg.c index f55bba7a9..bf36c7a09 100644 --- a/src/p2p/p2p_go_neg.c +++ b/src/p2p/p2p_go_neg.c @@ -786,11 +786,14 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa, } if (!go && msg.group_id) { - /* TODO: Store SSID for Provisioning step */ + /* Store SSID for Provisioning step */ + p2p->ssid_len = msg.group_id_len - ETH_ALEN; + os_memcpy(p2p->ssid, msg.group_id + ETH_ALEN, p2p->ssid_len); } else if (!go) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Mandatory P2P Group ID attribute missing from " "GO Negotiation Response"); + p2p->ssid_len = 0; #ifdef CONFIG_P2P_STRICT status = P2P_SC_FAIL_INVALID_PARAMS; goto fail; @@ -1034,11 +1037,14 @@ void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa, } if (dev->go_state == REMOTE_GO && msg.group_id) { - /* TODO: Store SSID for Provisioning step */ + /* Store SSID for Provisioning step */ + p2p->ssid_len = msg.group_id_len - ETH_ALEN; + os_memcpy(p2p->ssid, msg.group_id + ETH_ALEN, p2p->ssid_len); } else if (dev->go_state == REMOTE_GO) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Mandatory P2P Group ID attribute missing from " "GO Negotiation Confirmation"); + p2p->ssid_len = 0; #ifdef CONFIG_P2P_STRICT p2p_parse_free(&msg); return; diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index b9b18bb0b..88e529594 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -698,6 +698,8 @@ static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s, static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s, struct p2p_go_neg_results *res) { + wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID", + res->ssid, res->ssid_len); wpa_supplicant_ap_deinit(wpa_s); wpas_copy_go_neg_results(wpa_s, res); if (res->wps_method == WPS_PBC) diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c index c955e9ffb..55a03e2a9 100644 --- a/wpa_supplicant/wps_supplicant.c +++ b/wpa_supplicant/wps_supplicant.c @@ -32,6 +32,7 @@ #include "blacklist.h" #include "bss.h" #include "scan.h" +#include "p2p/p2p.h" #include "p2p_supplicant.h" #include "wps_supplicant.h" @@ -691,6 +692,16 @@ int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid, return -1; ssid->temporary = 1; ssid->p2p_group = p2p_group; + if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) { + ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1); + if (ssid->ssid) { + ssid->ssid_len = wpa_s->go_params->ssid_len; + os_memcpy(ssid->ssid, wpa_s->go_params->ssid, + ssid->ssid_len); + wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP " + "SSID", ssid->ssid, ssid->ssid_len); + } + } wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0); if (wpa_s->wps_fragment_size) ssid->eap.fragment_size = wpa_s->wps_fragment_size; @@ -714,6 +725,16 @@ int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, return -1; ssid->temporary = 1; ssid->p2p_group = p2p_group; + if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) { + ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1); + if (ssid->ssid) { + ssid->ssid_len = wpa_s->go_params->ssid_len; + os_memcpy(ssid->ssid, wpa_s->go_params->ssid, + ssid->ssid_len); + wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP " + "SSID", ssid->ssid, ssid->ssid_len); + } + } if (pin) os_snprintf(val, sizeof(val), "\"pin=%s dev_pw_id=%u\"", pin, dev_pw_id);