From 9e97cc80a2d3a866d26027d9b62cc37ab4e218d2 Mon Sep 17 00:00:00 2001 From: Harshitha Prem Date: Tue, 10 Oct 2023 16:23:58 +0530 Subject: [PATCH] hostapd: [single wiphy] avoid channel switch across radio In single wiphy scenario, the phy supports more than one band and when we try to change channel without specifying the wifi interface in hostapd_cli, it would lead to an exception. To handle this, if the given freq is not in the list of channels for that interface's current operating mode, then the cli would fail. Hence, in case of single wiphy, the below hostapd_cli should be used to change the channel hostapd_cli -i wlanX chan_switch \ center_freq1= bandwidth= Signed-off-by: Harshitha Prem --- hostapd/ctrl_iface.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index 9e32d126535a..2ce62ba5486e 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -2506,6 +2506,29 @@ static int hostapd_ctrl_register_frame(struct hostapd_data *hapd, #ifdef NEED_AP_MLME +static bool hostapd_ctrl_is_freq_in_cmode(struct hostapd_hw_modes *mode, + struct hostapd_multi_hw_info *current_hw_info, + int freq) +{ + struct hostapd_channel_data *chan; + int i; + + for (i = 0; i < mode->num_channels; i++) { + chan = &mode->channels[i]; + + if (chan->flag & HOSTAPD_CHAN_DISABLED) + continue; + + if (!chan_in_current_hw_info(current_hw_info, chan)) + continue; + + if (chan->freq == freq) + return true; + } + + return false; +} + static int hostapd_ctrl_check_freq_params(struct hostapd_freq_params *params, u16 punct_bitmap) { @@ -2822,6 +2845,14 @@ static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface *iface, if (ret) return ret; + if (iface->num_hw_features > 1 && + !hostapd_ctrl_is_freq_in_cmode(iface->current_mode, iface->current_hw_info, + settings.freq_params.freq)) { + wpa_printf(MSG_INFO, "chanswitch: invalid frequency settings provided" + " for multi band phy"); + return -1; + } + ret = hostapd_ctrl_check_freq_params(&settings.freq_params, settings.punct_bitmap); if (ret) { -- 2.17.1