From 7b121af26af51079fa56f8a1cde0d1ea65fd9e39 Mon Sep 17 00:00:00 2001 From: Purushottam Kushwaha Date: Tue, 8 Dec 2020 16:23:56 +0530 Subject: [PATCH] P2P: Delay P2P scan when an external scan is in progress When an external scan is in progress on the same radio, delay the P2P search operation based on configuration parameter p2p_search_delay. The "search_delay" configuration done through p2p_find always takes precedence over this delay value set due to an external scan trigger. Signed-off-by: Jouni Malinen --- src/p2p/p2p.c | 7 ++++++- src/p2p/p2p.h | 3 ++- wpa_supplicant/p2p_supplicant.c | 22 +++++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index 6b92a6d23..74b7b52ae 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -3510,12 +3510,17 @@ int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq, } -void p2p_scan_res_handled(struct p2p_data *p2p) +void p2p_scan_res_handled(struct p2p_data *p2p, unsigned int delay) { if (!p2p->p2p_scan_running) { p2p_dbg(p2p, "p2p_scan was not running, but scan results received"); } p2p->p2p_scan_running = 0; + + /* Use this delay only when p2p_find doesn't set it */ + if (!p2p->search_delay) + p2p->search_delay = delay; + eloop_cancel_timeout(p2p_scan_timeout, p2p, NULL); if (p2p_run_after_scan(p2p)) diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index ed8beab19..762bd40be 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -1625,6 +1625,7 @@ int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq, /** * p2p_scan_res_handled - Indicate end of scan results * @p2p: P2P module context from p2p_init() + * @delay: Search delay for next scan in ms * * This function is called to indicate that all P2P scan results from a scan * have been reported with zero or more calls to p2p_scan_res_handler(). This @@ -1632,7 +1633,7 @@ int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq, * struct p2p_config::p2p_scan() call if none of the p2p_scan_res_handler() * calls stopped iteration. */ -void p2p_scan_res_handled(struct p2p_data *p2p); +void p2p_scan_res_handled(struct p2p_data *p2p, unsigned int delay); enum p2p_send_action_result { P2P_SEND_ACTION_SUCCESS /* Frame was send and acknowledged */, diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 8c8a834da..7d6e2dac8 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -242,6 +242,22 @@ static void wpas_p2p_set_own_freq_preference(struct wpa_supplicant *wpa_s, } +static void wpas_p2p_scan_res_handled(struct wpa_supplicant *wpa_s) +{ + unsigned int delay = wpas_p2p_search_delay(wpa_s); + + /* In case of concurrent P2P and external scans, delay P2P search. */ + if (wpa_s->radio->external_scan_running) { + delay = wpa_s->conf->p2p_search_delay; + wpa_printf(MSG_DEBUG, + "P2P: Delay next P2P search by %d ms to let externally triggered scan complete", + delay); + } + + p2p_scan_res_handled(wpa_s->global->p2p, delay); +} + + static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res) { @@ -287,7 +303,7 @@ static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s, break; } - p2p_scan_res_handled(wpa_s->global->p2p); + wpas_p2p_scan_res_handled(wpa_s); } @@ -305,7 +321,7 @@ static void wpas_p2p_scan_res_fail_handler(struct wpa_supplicant *wpa_s) wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Failed to get scan results - try to continue"); - p2p_scan_res_handled(wpa_s->global->p2p); + wpas_p2p_scan_res_handled(wpa_s); } @@ -7089,7 +7105,7 @@ static void wpas_p2p_scan_res_ignore_search(struct wpa_supplicant *wpa_s, * Indicate that results have been processed so that the P2P module can * continue pending tasks. */ - p2p_scan_res_handled(wpa_s->global->p2p); + wpas_p2p_scan_res_handled(wpa_s); }