From ae7613b2c9e8097ad11d8daafc7e247e900272e5 Mon Sep 17 00:00:00 2001 From: Hui Bai Date: Fri, 29 Nov 2024 14:41:46 +0800 Subject: [PATCH] wifi: add hidden SSID configuration support for SoftAP Added hidden ssid support configuration for AP mode. Signed-off-by: Hui Bai --- drivers/wifi/nxp/nxp_wifi_drv.c | 4 ++++ include/zephyr/net/wifi_mgmt.h | 6 ++++++ modules/hostap/src/supp_api.c | 4 ++++ subsys/net/l2/wifi/wifi_shell.c | 24 +++++++++++++++++++++++- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/wifi/nxp/nxp_wifi_drv.c b/drivers/wifi/nxp/nxp_wifi_drv.c index 44342639538..171aa74dcc8 100644 --- a/drivers/wifi/nxp/nxp_wifi_drv.c +++ b/drivers/wifi/nxp/nxp_wifi_drv.c @@ -501,6 +501,10 @@ static int nxp_wifi_start_ap(const struct device *dev, struct wifi_connect_req_p return -EAGAIN; } + if (params->ignore_broadcast_ssid != 0) { + wlan_uap_set_hidden_ssid(params->ignore_broadcast_ssid); + } + ret = wlan_add_network(&nxp_wlan_network); if (ret != WM_SUCCESS) { status = NXP_WIFI_RET_FAIL; diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index a5082a05f6e..398afea8d8c 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -560,6 +560,12 @@ struct wifi_connect_req_params { const uint8_t *identities[WIFI_ENT_IDENTITY_MAX_USERS]; /** User Passwords */ const uint8_t *passwords[WIFI_ENT_IDENTITY_MAX_USERS]; + /** Hidden SSID configure + * 0: disabled (default) + * 1: send empty (length=0) SSID in beacon and ignore probe request for broadcast SSID + * 2: clear SSID, but keep the original length and ignore probe request for broadcast SSID + */ + uint8_t ignore_broadcast_ssid; }; /** @brief Wi-Fi connect result codes. To be overlaid on top of \ref wifi_status diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 6ca77e7cf3c..2fecad1c3c9 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -2232,6 +2232,10 @@ int hapd_config_network(struct hostapd_iface *iface, goto out; } + if (!hostapd_cli_cmd_v("set ignore_broadcast_ssid %d", params->ignore_broadcast_ssid)) { + goto out; + } + return ret; out: return -1; diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index cb05f8df83f..3b4b21da937 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -596,6 +596,7 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv {"eap-pwd6", required_argument, 0, 'P'}, {"eap-pwd7", required_argument, 0, 'P'}, {"eap-pwd8", required_argument, 0, 'P'}, + {"ignore-broadcast-ssid", required_argument, 0, 'i'}, {"ieee-80211r", no_argument, 0, 'R'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; @@ -613,6 +614,7 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv size_t offset = 0; long channel; int key_passwd_cnt = 0; + int ret = 0; /* Defaults */ params->band = WIFI_FREQ_BAND_UNKNOWN; @@ -620,8 +622,9 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv params->security = WIFI_SECURITY_TYPE_NONE; params->mfp = WIFI_MFP_OPTIONAL; params->eap_ver = 1; + params->ignore_broadcast_ssid = 0; - while ((opt = getopt_long(argc, argv, "s:p:k:e:w:b:c:m:t:a:K:S:V:I:P:Rh", + while ((opt = getopt_long(argc, argv, "s:p:k:e:w:b:c:m:t:a:K:S:V:I:P:i:Rh", long_options, &opt_index)) != -1) { state = getopt_state_get(); switch (opt) { @@ -808,13 +811,22 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv case 'R': params->ft_used = true; break; + case 'i': + params->ignore_broadcast_ssid = shell_strtol(state->optarg, 10, &ret); + break; case 'h': return -ENOEXEC; default: PR_ERROR("Invalid option %c\n", state->optopt); return -EINVAL; } + + if (ret) { + PR_ERROR("Invalid argument %d ret %d\n", opt_index, ret); + return -EINVAL; + } } + if (params->psk && !secure_connection) { PR_WARNING("Passphrase provided without security configuration\n"); } @@ -851,6 +863,10 @@ static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv } } #endif + if (params->ignore_broadcast_ssid > 2) { + PR_ERROR("Invalid ignore_broadcast_ssid value\n"); + return -EINVAL; + } return 0; } @@ -3140,6 +3156,12 @@ SHELL_STATIC_SUBCMD_SET_CREATE( "0:Disable, 1:Optional, 2:Required\n" "-b --band= (2 -2.6GHz, 5 - 5Ghz, 6 - 6GHz)\n" "-m --bssid=\n" + "-i --ignore-broadcast-ssid=. Hide SSID in AP mode.\n" + "0: disabled (default)\n" + "1: send empty (length=0) SSID in beacon and ignore probe request for " + "broadcast SSID.\n" + "2: clear SSID (ASCII 0), but keep the original length and ignore " + "probe requests for broadcast SSID.\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"