From 84286a227b780dab38019fefb3e5cc723a78b19e Mon Sep 17 00:00:00 2001 From: Sunil Dutt Undekari Date: Wed, 6 Jun 2012 15:46:05 +0300 Subject: [PATCH] P2P: Improve p2p_prov_disc-auto robustness Perform addition additional scan runs on the operating channel of the GO (if known from previous scan results) and fall back to initiate the PD for GO Negotiation if these additional scans do not detect the peer as GO. Signed-hostap: Sunil Dutt Undekari --- wpa_supplicant/p2p_supplicant.c | 42 +++++++++++++++++++++++++++++-- wpa_supplicant/wpa_supplicant_i.h | 1 + 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index d41a8dc92..8fcdf4117 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -39,6 +39,8 @@ */ #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10 +#define P2P_AUTO_PD_SCAN_ATTEMPTS 5 + #ifndef P2P_MAX_CLIENT_IDLE /* * How many seconds to try to reconnect to the GO when connection in P2P client @@ -61,6 +63,7 @@ static struct wpa_supplicant * wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, int go); static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s); +static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq); static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx); static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr, const u8 *dev_addr, enum p2p_wps_method wps_method, @@ -2763,8 +2766,27 @@ static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s, if (wpa_s->p2p_auto_pd) { int join = wpas_p2p_peer_go(wpa_s, wpa_s->pending_join_dev_addr); + if (join == 0 && + wpa_s->auto_pd_scan_retry < P2P_AUTO_PD_SCAN_ATTEMPTS) { + wpa_s->auto_pd_scan_retry++; + bss = wpa_bss_get_bssid(wpa_s, + wpa_s->pending_join_dev_addr); + if (bss) { + freq = bss->freq; + wpa_printf(MSG_DEBUG, "P2P: Scan retry %d for " + "the peer " MACSTR " at %d MHz", + wpa_s->auto_pd_scan_retry, + MAC2STR(wpa_s-> + pending_join_dev_addr), + freq); + wpas_p2p_join_scan_req(wpa_s, freq); + return; + } + } + if (join < 0) join = 0; + wpa_s->p2p_auto_pd = 0; wpa_s->pending_pd_use = join ? AUTO_PD_JOIN : AUTO_PD_GO_NEG; wpa_printf(MSG_DEBUG, "P2P: Auto PD with " MACSTR " join=%d", @@ -2915,13 +2937,13 @@ start: } -static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx) +static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq) { - struct wpa_supplicant *wpa_s = eloop_ctx; int ret; struct wpa_driver_scan_params params; struct wpabuf *wps_ie, *ies; size_t ielen; + int freqs[2] = { 0, 0 }; os_memset(¶ms, 0, sizeof(params)); @@ -2954,6 +2976,10 @@ static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx) params.p2p_probe = 1; params.extra_ies = wpabuf_head(ies); params.extra_ies_len = wpabuf_len(ies); + if (freq > 0) { + freqs[0] = freq; + params.freqs = freqs; + } /* * Run a scan to update BSS table and start Provision Discovery once @@ -2975,6 +3001,13 @@ static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx) } +static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx) +{ + struct wpa_supplicant *wpa_s = eloop_ctx; + wpas_p2p_join_scan_req(wpa_s, 0); +} + + static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr, const u8 *dev_addr, enum p2p_wps_method wps_method, int auto_join) @@ -3798,8 +3831,13 @@ int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr, wpa_s->p2p_auto_pd = 1; wpa_s->p2p_auto_join = 0; wpa_s->pending_pd_before_join = 0; + wpa_s->auto_pd_scan_retry = 0; wpas_p2p_stop_find(wpa_s); wpa_s->p2p_join_scan_count = 0; + os_get_time(&wpa_s->p2p_auto_started); + wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld", + wpa_s->p2p_auto_started.sec, + wpa_s->p2p_auto_started.usec); wpas_p2p_join_scan(wpa_s, NULL); return 0; } diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index dadeafb0a..84e8fa454 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -481,6 +481,7 @@ struct wpa_supplicant { u8 pending_join_dev_addr[ETH_ALEN]; int pending_join_wps_method; int p2p_join_scan_count; + int auto_pd_scan_retry; int force_long_sd; u16 pending_pd_config_methods; enum {