]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P: Pick a 5 GHz channel from more possible channels
authorJimmy Chen <jimmycmchen@google.com>
Mon, 12 Oct 2020 02:23:40 +0000 (10:23 +0800)
committerJouni Malinen <j@w1.fi>
Sat, 27 Feb 2021 17:19:35 +0000 (19:19 +0200)
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 <jimmycmchen@google.com>
wpa_supplicant/p2p_supplicant.c

index c04e8ec71a15094591ce14f1ef7207103237c7f4..e3d3c1d710290239fa2a22f42f51acb40fa6eee7 100644 (file)
@@ -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;