From d314213f6cd668f41f309679b6bbbeaaa5d5ebf9 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Mon, 12 Oct 2020 10:23:40 +0800 Subject: [PATCH] P2P: Pick a 5 GHz channel from more possible channels For an autonomous P2P group on the 5 GHz band, a channel was picked only from the operating class 115 which is not available in the EU region anymore. As a result, an autonomous group creation would always fail in this generic 5 GHz channel case. There are more possible available channels for the 5 GHz currently. Especially in the EU region, the operating class 115 channels are no longer available, but SRD channels (the operating class 124) are available. Allow them to be used here if they are marked as allowed for P2P GO use. In addition, iterate through all the potential options instead of just checking the first randomly picked channel. Start this iteration from random position to maintain some randomness in this process. Signed-off-by: Jimmy Chen --- wpa_supplicant/p2p_supplicant.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index c04e8ec71..e3d3c1d71 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -6067,10 +6067,32 @@ static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq) wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band " "channel: %d MHz", freq); } else { + const int freqs[] = { + /* operating class 115 */ + 5180, 5200, 5220, 5240, + /* operating class 124 */ + 5745, 5765, 5785, 5805, + }; + unsigned int i, num_freqs = ARRAY_SIZE(freqs); + if (os_get_random((u8 *) &r, sizeof(r)) < 0) return -1; - freq = 5180 + (r % 4) * 20; - if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) { + + /* + * Most of the 5 GHz channels require DFS. Only + * operating classes 115 and 124 are available possibly + * without that requirement. Check these for + * availability starting from a randomly picked + * position. + */ + for (i = 0; i < num_freqs; i++, r++) { + freq = freqs[r % num_freqs]; + if (p2p_supported_freq_go(wpa_s->global->p2p, + freq)) + break; + } + + if (i >= num_freqs) { wpa_printf(MSG_DEBUG, "P2P: Could not select " "5 GHz channel for P2P group"); return -1;