From: Kavita Kavita Date: Wed, 7 May 2025 10:26:01 +0000 (+0530) Subject: P2P GO: Select driver-preferred channel for GO when band is specified X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39232d58aeb6add921554f2d8c810a4d40b53ad0;p=thirdparty%2Fhostap.git P2P GO: Select driver-preferred channel for GO when band is specified Add support to select driver-preferred channel for GO when band is specified in the "freq" parameter. Signed-off-by: Kavita Kavita --- diff --git a/src/common/ieee802_11_common.c b/src/common/ieee802_11_common.c index 838869a03..ae7a7647a 100644 --- a/src/common/ieee802_11_common.c +++ b/src/common/ieee802_11_common.c @@ -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 */ diff --git a/src/common/ieee802_11_common.h b/src/common/ieee802_11_common.h index abd17f062..5f52b573c 100644 --- a/src/common/ieee802_11_common.h +++ b/src/common/ieee802_11_common.h @@ -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); diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 73dbd5f22..cb2f0d19b 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -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;