scan: Add a helper function to append supported freqs from a given band

This functionality was repeated for couple of times. Use a shared helper
function to avoid code duplication.

Signed-off-by: Veerendranath Jakkam <vjakkam@codeaurora.org>
This commit is contained in:
Veerendranath Jakkam 2020-11-20 19:58:50 +05:30 committed by Jouni Malinen
parent bba926350a
commit 2a37cda747
3 changed files with 38 additions and 61 deletions

View File

@ -291,41 +291,6 @@ static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s,
} }
static int wpas_p2p_add_scan_freq_list(struct wpa_supplicant *wpa_s,
enum hostapd_hw_mode band,
struct wpa_driver_scan_params *params)
{
struct hostapd_hw_modes *mode;
int num_chans = 0;
int *freqs, i;
mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, band, 0);
if (!mode)
return -1;
if (params->freqs) {
while (params->freqs[num_chans])
num_chans++;
}
freqs = os_realloc(params->freqs,
(num_chans + mode->num_channels + 1) * sizeof(int));
if (!freqs)
return -1;
params->freqs = freqs;
for (i = 0; i < mode->num_channels; i++) {
if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED)
continue;
params->freqs[num_chans++] = mode->channels[i].freq;
}
params->freqs[num_chans] = 0;
return 0;
}
static void wpas_p2p_trigger_scan_cb(struct wpa_radio_work *work, int deinit) static void wpas_p2p_trigger_scan_cb(struct wpa_radio_work *work, int deinit)
{ {
struct wpa_supplicant *wpa_s = work->wpa_s; struct wpa_supplicant *wpa_s = work->wpa_s;
@ -351,10 +316,10 @@ static void wpas_p2p_trigger_scan_cb(struct wpa_radio_work *work, int deinit)
if (wpa_s->conf->p2p_6ghz_disable && !params->freqs) { if (wpa_s->conf->p2p_6ghz_disable && !params->freqs) {
wpa_printf(MSG_DEBUG, wpa_printf(MSG_DEBUG,
"P2P: 6 GHz disabled - update the scan frequency list"); "P2P: 6 GHz disabled - update the scan frequency list");
wpas_p2p_add_scan_freq_list(wpa_s, HOSTAPD_MODE_IEEE80211G, wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, params,
params); 0);
wpas_p2p_add_scan_freq_list(wpa_s, HOSTAPD_MODE_IEEE80211A, wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, params,
params); 0);
} }
ret = wpa_drv_scan(wpa_s, params); ret = wpa_drv_scan(wpa_s, params);
if (ret == 0) if (ret == 0)
@ -5342,10 +5307,10 @@ static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq,
} else if (wpa_s->conf->p2p_6ghz_disable) { } else if (wpa_s->conf->p2p_6ghz_disable) {
wpa_printf(MSG_DEBUG, wpa_printf(MSG_DEBUG,
"P2P: 6 GHz disabled - update the scan frequency list"); "P2P: 6 GHz disabled - update the scan frequency list");
wpas_p2p_add_scan_freq_list(wpa_s, HOSTAPD_MODE_IEEE80211G, wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, &params,
&params); 0);
wpas_p2p_add_scan_freq_list(wpa_s, HOSTAPD_MODE_IEEE80211A, wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, &params,
&params); 0);
} }
ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);

View File

@ -670,30 +670,38 @@ static int non_p2p_network_enabled(struct wpa_supplicant *wpa_s)
#endif /* CONFIG_P2P */ #endif /* CONFIG_P2P */
static void wpa_setband_scan_freqs_list(struct wpa_supplicant *wpa_s, int wpa_add_scan_freqs_list(struct wpa_supplicant *wpa_s,
enum hostapd_hw_mode band, enum hostapd_hw_mode band,
struct wpa_driver_scan_params *params, struct wpa_driver_scan_params *params, int is_6ghz)
int is_6ghz)
{ {
/* Include only supported channels for the specified band */ /* Include only supported channels for the specified band */
struct hostapd_hw_modes *mode; struct hostapd_hw_modes *mode;
int count, i; int num_chans = 0;
int *freqs, i;
mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, band, is_6ghz); mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, band, is_6ghz);
if (mode == NULL) { if (!mode)
/* No channels supported in this band - use empty list */ return -1;
params->freqs = os_zalloc(sizeof(int));
return; if (params->freqs) {
while (params->freqs[num_chans])
num_chans++;
} }
params->freqs = os_calloc(mode->num_channels + 1, sizeof(int)); freqs = os_realloc(params->freqs,
if (params->freqs == NULL) (num_chans + mode->num_channels + 1) * sizeof(int));
return; if (!freqs)
for (count = 0, i = 0; i < mode->num_channels; i++) { return -1;
params->freqs = freqs;
for (i = 0; i < mode->num_channels; i++) {
if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED) if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED)
continue; continue;
params->freqs[count++] = mode->channels[i].freq; params->freqs[num_chans++] = mode->channels[i].freq;
} }
params->freqs[num_chans] = 0;
return 0;
} }
@ -704,12 +712,13 @@ static void wpa_setband_scan_freqs(struct wpa_supplicant *wpa_s,
return; /* unknown what channels the driver supports */ return; /* unknown what channels the driver supports */
if (params->freqs) if (params->freqs)
return; /* already using a limited channel set */ return; /* already using a limited channel set */
if (wpa_s->setband == WPA_SETBAND_5G) if (wpa_s->setband == WPA_SETBAND_5G)
wpa_setband_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, params,
params, 0); 0);
else if (wpa_s->setband == WPA_SETBAND_2G) else if (wpa_s->setband == WPA_SETBAND_2G)
wpa_setband_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, params,
params, 0); 0);
} }

View File

@ -86,5 +86,8 @@ unsigned int wpas_get_est_tpt(const struct wpa_supplicant *wpa_s,
const u8 *ies, size_t ies_len, int rate, const u8 *ies, size_t ies_len, int rate,
int snr); int snr);
void wpa_supplicant_set_default_scan_ies(struct wpa_supplicant *wpa_s); void wpa_supplicant_set_default_scan_ies(struct wpa_supplicant *wpa_s);
int wpa_add_scan_freqs_list(struct wpa_supplicant *wpa_s,
enum hostapd_hw_mode band,
struct wpa_driver_scan_params *params, int is_6ghz);
#endif /* SCAN_H */ #endif /* SCAN_H */