From 303f60d39b29ae6d73e74051dd7db9b460615fad Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Thu, 29 Sep 2011 16:53:55 +0300 Subject: [PATCH] P2P: Do not request station mode scans during P2P operations The P2P search mechanism depends on the same scan functionality that is used for station mode scans. If these operations are being used at the same time, scan result processing is not handled properly. Avoid unexpected behavior by delaying station mode scan requests if a P2P operation is in progress. Among other things, this allows the station mode connection attempt to be continued after a P2P find or group formation has been completed if the interface is available (i.e., when the P2P group uses a separate virtual interface). --- src/p2p/p2p.c | 8 ++++++++ src/p2p/p2p.h | 7 +++++++ wpa_supplicant/p2p_supplicant.c | 9 +++++++++ wpa_supplicant/p2p_supplicant.h | 1 + wpa_supplicant/scan.c | 14 ++++++++++++++ 5 files changed, 39 insertions(+) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index c0c59a6f9..62926b544 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -3681,3 +3681,11 @@ p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next) return &dev->info; } + + +int p2p_in_progress(struct p2p_data *p2p) +{ + if (p2p == NULL) + return 0; + return p2p->state != P2P_IDLE; +} diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index d01f57454..4cab3da9a 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -1509,4 +1509,11 @@ int p2p_add_wps_vendor_extension(struct p2p_data *p2p, int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel, int cfg_op_channel); +/** + * p2p_in_progress - Check whether a P2P operation is progress + * @p2p: P2P module context from p2p_init() + * Returns: 0 if P2P module is idle or 1 if an operation is in progress + */ +int p2p_in_progress(struct p2p_data *p2p); + #endif /* P2P_H */ diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 9894bfeb3..f1912f3e9 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -4365,3 +4365,12 @@ int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s) return 0; } + + +int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s) +{ + if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) + return 0; + + return p2p_in_progress(wpa_s->global->p2p); +} diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h index ad74217ba..9a13f9f6c 100644 --- a/wpa_supplicant/p2p_supplicant.h +++ b/wpa_supplicant/p2p_supplicant.h @@ -127,5 +127,6 @@ int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr); int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s); void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s, struct wps_event_fail *fail); +int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s); #endif /* P2P_SUPPLICANT_H */ diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index 7689ff6a3..5be661a2e 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -284,6 +284,20 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) return; } +#ifdef CONFIG_P2P + if (wpas_p2p_in_progress(wpa_s)) { + if (wpa_s->wpa_state == WPA_SCANNING) { + wpa_dbg(wpa_s, MSG_DEBUG, "Delay station mode scan " + "while P2P operation is in progress"); + wpa_supplicant_req_scan(wpa_s, 5, 0); + } else { + wpa_dbg(wpa_s, MSG_DEBUG, "Do not request scan while " + "P2P operation is in progress"); + } + return; + } +#endif /* CONFIG_P2P */ + if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) || wpa_s->conf->ap_scan == 2) max_ssids = 1;