]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P GO: Select driver-preferred channel for GO when band is specified
authorKavita Kavita <kkavita@qti.qualcomm.com>
Wed, 7 May 2025 10:26:01 +0000 (15:56 +0530)
committerJouni Malinen <j@w1.fi>
Fri, 23 May 2025 13:00:44 +0000 (16:00 +0300)
Add support to select driver-preferred channel for GO when band is
specified in the "freq" parameter.

Signed-off-by: Kavita Kavita <kkavita@qti.qualcomm.com>
src/common/ieee802_11_common.c
src/common/ieee802_11_common.h
wpa_supplicant/p2p_supplicant.c

index 838869a0363bb0bf6409ddcb3806f41c2edc68eb..ae7a7647a5bbfb63ef042b9dbb9db869f59d3022 100644 (file)
@@ -2927,6 +2927,18 @@ int oper_class_bw_to_int(const struct oper_class_map *map)
 }
 
 
+bool is_24ghz_freq(int freq)
+{
+       return freq >= 2400 && freq <= 2484;
+}
+
+
+bool is_5ghz_freq(int freq)
+{
+       return freq >= 5150 && freq <= 5885;
+}
+
+
 int center_idx_to_bw_6ghz(u8 idx)
 {
        /* Channel: 2 */
index abd17f0628c43ca80ce7274d28fba53a886bfe30..5f52b573cf5434f88ec61a3713b7ff711d8c142b 100644 (file)
@@ -300,6 +300,8 @@ u8 country_to_global_op_class(const char *country, u8 op_class);
 
 const struct oper_class_map * get_oper_class(const char *country, u8 op_class);
 int oper_class_bw_to_int(const struct oper_class_map *map);
+bool is_24ghz_freq(int freq);
+bool is_5ghz_freq(int freq);
 int center_idx_to_bw_6ghz(u8 idx);
 bool is_6ghz_freq(int freq);
 bool is_6ghz_op_class(u8 op_class);
index 73dbd5f22dae451575fe557c0b9fbf5e3f2338bb..cb2f0d19b829e34e434d7ec0aa5962362267b582 100644 (file)
@@ -7318,13 +7318,11 @@ int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname)
 
 static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq)
 {
-       unsigned int r;
+       unsigned int r, i, size = P2P_MAX_PREF_CHANNELS;
+       struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS];
+       int res = -1;
 
        if (!wpa_s->conf->num_p2p_pref_chan && !freq) {
-               unsigned int i, size = P2P_MAX_PREF_CHANNELS;
-               struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS];
-               int res;
-
                res = wpa_drv_get_pref_freq_list(wpa_s, WPA_IF_P2P_GO,
                                                 &size, pref_freq_list);
                if (!res && size > 0 && !is_p2p_allow_6ghz(wpa_s->global->p2p))
@@ -7360,6 +7358,13 @@ static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq)
                }
        }
 
+       if (freq == 2 || freq == 5) {
+               res = wpa_drv_get_pref_freq_list(wpa_s, WPA_IF_P2P_GO,
+                                                &size, pref_freq_list);
+               if (!res && size > 0 && !is_p2p_allow_6ghz(wpa_s->global->p2p))
+                       size = p2p_remove_6ghz_channels(pref_freq_list, size);
+       }
+
        if (freq == 2) {
                wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz "
                           "band");
@@ -7369,6 +7374,28 @@ static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq)
                        freq = wpa_s->best_24_freq;
                        wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band "
                                   "channel: %d MHz", freq);
+               } else if (!res && size > 0) {
+                       for (i = 0; i < size; i++) {
+                               freq = pref_freq_list[i].freq;
+                               if (is_24ghz_freq(freq) &&
+                                   p2p_supported_freq(wpa_s->global->p2p,
+                                                      freq) &&
+                                   !wpas_p2p_disallowed_freq(wpa_s->global,
+                                                             freq) &&
+                                   p2p_pref_freq_allowed(&pref_freq_list[i],
+                                                         true))
+                                       break;
+                       }
+
+                       if (i >= size) {
+                               wpa_printf(MSG_DEBUG,
+                                          "P2P: Could not select 2.4 GHz channel for P2P group");
+                               return -1;
+                       }
+
+                       wpa_printf(MSG_DEBUG,
+                                  "P2P: Use preferred 2.4 GHz band channel: %d MHz",
+                                  freq);
                } else {
                        if (os_get_random((u8 *) &r, sizeof(r)) < 0)
                                return -1;
@@ -7387,6 +7414,27 @@ static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq)
                        freq = wpa_s->best_5_freq;
                        wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band "
                                   "channel: %d MHz", freq);
+               } else if (!res && size > 0) {
+                       for (i = 0; i < size; i++) {
+                               freq = pref_freq_list[i].freq;
+                               if (is_5ghz_freq(freq) &&
+                                   p2p_supported_freq(wpa_s->global->p2p,
+                                                      freq) &&
+                                   !wpas_p2p_disallowed_freq(wpa_s->global,
+                                                             freq) &&
+                                   p2p_pref_freq_allowed(&pref_freq_list[i],
+                                                         true))
+                                       break;
+                       }
+
+                       if (i >= size) {
+                               wpa_printf(MSG_DEBUG,
+                                          "P2P: Could not select 5 GHz channel for P2P group");
+                               return -1;
+                       }
+                       wpa_printf(MSG_DEBUG,
+                                  "P2P: Use preferred 5 GHz band channel: %d MHz",
+                                  freq);
                } else {
                        const int freqs[] = {
                                /* operating class 115 */
@@ -7394,7 +7442,7 @@ static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq)
                                /* operating class 124 */
                                5745, 5765, 5785, 5805,
                        };
-                       unsigned int i, num_freqs = ARRAY_SIZE(freqs);
+                       unsigned int num_freqs = ARRAY_SIZE(freqs);
 
                        if (os_get_random((u8 *) &r, sizeof(r)) < 0)
                                return -1;