From ac54a8d0a5a7c074e32278b90abfd9d533ad57dc Mon Sep 17 00:00:00 2001 From: Shivani Tambatkar Date: Fri, 1 Dec 2023 15:19:46 -0800 Subject: [PATCH 2/7] hostapd: add device bandwidth to chan_switch command Add new parameters bandwidth_device and center_freq_device to the channel switch cli command. Parse, validate and configure the parameters during channel switch. Signed-off-by: Shivani Tambatkar Signed-off-by: Aloka Dixit --- hostapd/ctrl_iface.c | 72 ++++++++++++++++++++++++++++++++++++++++++ hostapd/hostapd_cli.c | 6 ++-- src/ap/beacon.c | 1 - src/ap/ctrl_iface_ap.c | 2 ++ src/ap/hostapd.c | 1 - 5 files changed, 77 insertions(+), 5 deletions(-) --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -2529,6 +2529,77 @@ static bool hostapd_ctrl_is_freq_in_cmod return false; } + +static int hostapd_check_validity_device_params(struct hostapd_freq_params *params) +{ + int freq_section = 0; + + if (params->bandwidth_device == 0 && params->center_freq_device == 0) + return 0; + else if (params->bandwidth_device == 0 || params->center_freq_device == 0) + return -EINVAL; + + if ((params->center_freq1 == params->center_freq_device) && + (params->bandwidth == params->bandwidth_device)) { + params->bandwidth_device = 0; + params->center_freq_device = 0; + return 0; + } + + if (params->bandwidth_device != 2*params->bandwidth) { + wpa_printf(MSG_ERROR, + "Device bandwidth is not set to twice the operating bandwidth\n"); + return -EINVAL; + } + + if (params->center_freq1 > params->center_freq_device) + freq_section = 1; + + switch (params->bandwidth_device) { + case 320: + if (freq_section) { + if (params->center_freq_device != params->center_freq1 - 80) + return -EINVAL; + } else { + if (params->center_freq_device != params->center_freq1 + 80) + return -EINVAL; + } + break; + case 160: + if (freq_section) { + if (params->center_freq_device != params->center_freq1 - 40) + return -EINVAL; + } else { + if (params->center_freq_device != params->center_freq1 + 40) + return -EINVAL; + } + break; + case 80: + if (freq_section) { + if (params->center_freq_device != params->center_freq1 - 20) + return -EINVAL; + } else { + if (params->center_freq_device != params->center_freq1 + 20) + return -EINVAL; + } + break; + case 40: + if (freq_section) { + if (params->center_freq_device != params->center_freq1 - 10) + return -EINVAL; + } else { + if (params->center_freq_device != params->center_freq1 + 10) + return -EINVAL; + } + break; + default: + return -EINVAL; + } + + return 0; +} + + static int hostapd_ctrl_check_freq_params(struct hostapd_freq_params *params, u16 punct_bitmap) { @@ -2861,6 +2932,14 @@ static int hostapd_ctrl_iface_chan_switc return ret; } + ret = hostapd_check_validity_device_params(&settings.freq_params); + if (ret) { + wpa_printf(MSG_ERROR, "chanswitch: invalid device parameters provided %d %d", + settings.freq_params.bandwidth_device, + settings.freq_params.center_freq_device); + return ret; + } + switch (settings.freq_params.bandwidth) { case 40: bandwidth = CHAN_WIDTH_40; --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -1209,6 +1209,7 @@ static int hostapd_cli_cmd_chan_switch(s "arguments (count and freq)\n" "usage: [sec_channel_offset=] " "[center_freq1=] [center_freq2=] [bandwidth=] " + "[bandwidth_device =] [center_freq_device=] " "[blocktx] [ht|vht|he|eht]\n"); return -1; } @@ -1731,7 +1732,8 @@ static const struct hostapd_cli_cmd host " = 0 - 20 MHz, 1 - 40 MHz, 2 - 80 MHz, 3 - 160 MHz" }, { "chan_switch", hostapd_cli_cmd_chan_switch, NULL, " [sec_channel_offset=] [center_freq1=]\n" - " [center_freq2=] [bandwidth=] [blocktx] [ht|vht]\n" + " [center_freq2=] [bandwidth=] [bandwidth_device=] \n" + " [center_freq_device=] [blocktx] [ht|vht|he|eht] \n" " = initiate channel switch announcement" }, { "color_change", hostapd_cli_cmd_color_change, NULL, " = initiate bss color change to set user color if value between 1-63\n" --- a/src/ap/ctrl_iface_ap.c +++ b/src/ap/ctrl_iface_ap.c @@ -1354,6 +1354,8 @@ int hostapd_parse_csa_settings(const cha SET_CSA_SETTING(sec_channel_offset); SET_CSA_SETTING(ru_punct_bitmap); SET_CSA_SETTING_EXT(punct_bitmap); + SET_CSA_SETTING(bandwidth_device); + SET_CSA_SETTING(center_freq_device); settings->freq_params.ht_enabled = !!os_strstr(pos, " ht"); settings->freq_params.vht_enabled = !!os_strstr(pos, " vht"); settings->freq_params.he_enabled = !!os_strstr(pos, " he");