From 96a5570d090908dd6746321981e520fab805ff89 Mon Sep 17 00:00:00 2001 From: Gang Li Date: Fri, 6 Dec 2024 07:13:17 +0100 Subject: [PATCH 1/3] net: wifi: add "bandwidth" parameter to "wifi ap enable" command Add "bandwidth" parameter to "wifi ap enable" command. Add "ht_capab" and "vht_capab" parameters to "wifi ap config" command. Signed-off-by: Gang Li --- include/zephyr/net/wifi.h | 27 +++++++++++++++++ include/zephyr/net/wifi_mgmt.h | 11 +++++++ subsys/net/l2/wifi/wifi_mgmt.c | 15 ++++++++++ subsys/net/l2/wifi/wifi_shell.c | 51 +++++++++++++++++++++++++++++++-- 4 files changed, 101 insertions(+), 3 deletions(-) diff --git a/include/zephyr/net/wifi.h b/include/zephyr/net/wifi.h index c64ee6acac9e..485d04ae571b 100644 --- a/include/zephyr/net/wifi.h +++ b/include/zephyr/net/wifi.h @@ -223,6 +223,27 @@ enum wifi_frequency_bands { /** Helper function to get user-friendly frequency band name. */ const char *wifi_band_txt(enum wifi_frequency_bands band); +/** + * @brief IEEE 802.11 operational frequency bandwidths (not exhaustive). + */ +enum wifi_frequency_bandwidths { + /** 20 MHz. */ + WIFI_FREQ_BANDWIDTH_20MHZ = 1, + /** 40 MHz. */ + WIFI_FREQ_BANDWIDTH_40MHZ, + /** 80 MHz. */ + WIFI_FREQ_BANDWIDTH_80MHZ, + + /** Number of frequency bandwidths available. */ + __WIFI_FREQ_BANDWIDTH_AFTER_LAST, + /** Highest frequency bandwidth available. */ + WIFI_FREQ_BANDWIDTH_MAX = __WIFI_FREQ_BANDWIDTH_AFTER_LAST - 1, + /** Invalid frequency bandwidth */ + WIFI_FREQ_BANDWIDTH_UNKNOWN +}; + +const char *const wifi_bandwidth_txt(enum wifi_frequency_bandwidths bandwidth); + /** Max SSID length */ #define WIFI_SSID_MAX_LEN 32 /** Minimum PSK length */ @@ -655,6 +676,12 @@ enum wifi_ap_config_param { WIFI_AP_CONFIG_PARAM_MAX_INACTIVITY = BIT(0), /** Used for AP mode configuration parameter max_num_sta */ WIFI_AP_CONFIG_PARAM_MAX_NUM_STA = BIT(1), + /** Used for AP mode configuration parameter bandwidth */ + WIFI_AP_CONFIG_PARAM_BANDWIDTH = BIT(2), + /** Used for AP mode configuration parameter ht_capab */ + WIFI_AP_CONFIG_PARAM_HT_CAPAB = BIT(3), + /** Used for AP mode configuration parameter vht_capab */ + WIFI_AP_CONFIG_PARAM_VHT_CAPAB = BIT(4), }; #ifdef __cplusplus diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 398afea8d8c9..5ea11ef0ffa3 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -566,6 +566,8 @@ struct wifi_connect_req_params { * 2: clear SSID, but keep the original length and ignore probe request for broadcast SSID */ uint8_t ignore_broadcast_ssid; + /** Parameter used for frequency band */ + enum wifi_frequency_bandwidths bandwidth; }; /** @brief Wi-Fi connect result codes. To be overlaid on top of \ref wifi_status @@ -976,6 +978,7 @@ struct wifi_channel_info { /** @cond INTERNAL_HIDDEN */ #define WIFI_AP_STA_MAX_INACTIVITY (LONG_MAX - 1) +#define WIFI_AP_IEEE_80211_CAPAB_MAX_LEN 64 /** @endcond */ /** @brief Wi-Fi AP configuration parameter */ @@ -986,6 +989,14 @@ struct wifi_ap_config_params { uint32_t max_inactivity; /** Parameter used for setting maximum number of stations */ uint32_t max_num_sta; + /** Parameter used for frequency band */ + enum wifi_frequency_bandwidths bandwidth; +#if defined(CONFIG_WIFI_NM_HOSTAPD_AP) + /** Parameter used for setting HT capabilities */ + char ht_capab[WIFI_AP_IEEE_80211_CAPAB_MAX_LEN + 1]; + /** Parameter used for setting VHT capabilities */ + char vht_capab[WIFI_AP_IEEE_80211_CAPAB_MAX_LEN + 1]; +#endif }; #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 659b13fb81c1..1f1e63305f4d 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -129,6 +129,21 @@ const char *wifi_band_txt(enum wifi_frequency_bands band) } } +const char *const wifi_bandwidth_txt(enum wifi_frequency_bandwidths bandwidth) +{ + switch (bandwidth) { + case WIFI_FREQ_BANDWIDTH_20MHZ: + return "20 MHz"; + case WIFI_FREQ_BANDWIDTH_40MHZ: + return "40 MHz"; + case WIFI_FREQ_BANDWIDTH_80MHZ: + return "80 MHz"; + case WIFI_FREQ_BANDWIDTH_UNKNOWN: + default: + return "UNKNOWN"; + } +} + const char *wifi_state_txt(enum wifi_iface_state state) { switch (state) { diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 6bd009f96e93..9c9862bf51f7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -576,6 +576,7 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv {"channel", required_argument, 0, 'c'}, {"timeout", required_argument, 0, 't'}, {"anon-id", required_argument, 0, 'a'}, + {"bandwidth", required_argument, 0, 'B'}, {"key1-pwd", required_argument, 0, 'K'}, {"key2-pwd", required_argument, 0, 'K'}, {"suiteb-type", required_argument, 0, 'S'}, @@ -623,8 +624,9 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv params->mfp = WIFI_MFP_OPTIONAL; params->eap_ver = 1; params->ignore_broadcast_ssid = 0; + params->bandwidth = WIFI_FREQ_BANDWIDTH_20MHZ; - while ((opt = getopt_long(argc, argv, "s:p:k:e:w:b:c:m:t:a:K:S:V:I:P:i:Rh", + while ((opt = getopt_long(argc, argv, "s:p:k:e:w:b:c:m:t:a:B:K:S:V:I:P:i:Rh", long_options, &opt_index)) != -1) { state = getopt_state_get(); switch (opt) { @@ -737,6 +739,24 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv return -EINVAL; } break; + case 'B': + if (iface_mode == WIFI_MODE_AP) { + switch (atoi(state->optarg)) { + case 1: + params->bandwidth = WIFI_FREQ_BANDWIDTH_20MHZ; + break; + case 2: + params->bandwidth = WIFI_FREQ_BANDWIDTH_40MHZ; + break; + case 3: + params->bandwidth = WIFI_FREQ_BANDWIDTH_80MHZ; + break; + default: + PR_ERROR("Invalid bandwidth: %d\n", atoi(state->optarg)); + return -EINVAL; + } + } + break; case 'K': if (key_passwd_cnt >= 2) { PR_WARNING("too many key_passwd (max 2 key_passwd)\n"); @@ -1835,11 +1855,15 @@ static int wifi_ap_config_args_to_params(const struct shell *sh, size_t argc, ch static const struct option long_options[] = { {"max_inactivity", required_argument, 0, 'i'}, {"max_num_sta", required_argument, 0, 's'}, +#if defined(CONFIG_WIFI_NM_HOSTAPD_AP) + {"ht_capab", required_argument, 0, 'n'}, + {"vht_capab", required_argument, 0, 'c'}, +#endif {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; long val; - while ((opt = getopt_long(argc, argv, "i:s:h", + while ((opt = getopt_long(argc, argv, "i:s:n:c:h", long_options, &opt_index)) != -1) { state = getopt_state_get(); switch (opt) { @@ -1859,6 +1883,16 @@ static int wifi_ap_config_args_to_params(const struct shell *sh, size_t argc, ch params->max_num_sta = (uint32_t)val; params->type |= WIFI_AP_CONFIG_PARAM_MAX_NUM_STA; break; +#if defined(CONFIG_WIFI_NM_HOSTAPD_AP) + case 'n': + strncpy(params->ht_capab, state->optarg, WIFI_AP_IEEE_80211_CAPAB_MAX_LEN); + params->type |= WIFI_AP_CONFIG_PARAM_HT_CAPAB; + break; + case 'c': + strncpy(params->vht_capab, state->optarg, WIFI_AP_IEEE_80211_CAPAB_MAX_LEN); + params->type |= WIFI_AP_CONFIG_PARAM_VHT_CAPAB; + break; +#endif case 'h': shell_help(sh); return SHELL_CMD_HELP_PRINTED; @@ -3154,6 +3188,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( "broadcast SSID.\n" "2: clear SSID (ASCII 0), but keep the original length and ignore " "probe requests for broadcast SSID.\n" + "[-B, --bandwidth=]: 1:20MHz, 2:40MHz, 3:80MHz\n" "[-K, --key1-pwd for eap phase1 or --key2-pwd for eap phase2]:\n" "Private key passwd for enterprise mode. Default no password for private key.\n" "[-S, --suiteb-type]: 1:suiteb, 2:suiteb-192. Default 0: not suiteb mode.\n" @@ -3173,8 +3208,18 @@ SHELL_STATIC_SUBCMD_SET_CREATE( "Configure AP parameters.\n" "-i --max_inactivity=