hostapd: add ap status in l2 wifi

add ap status in l2 wifi

Signed-off-by: Gaofeng Zhang <gaofeng.zhang@nxp.com>
This commit is contained in:
Gaofeng Zhang 2024-09-29 14:24:22 +08:00 committed by Anas Nashif
parent 193bfabd3f
commit 0c54a3f8c7
6 changed files with 188 additions and 36 deletions

View file

@ -1072,6 +1072,18 @@ struct wifi_wps_config_params {
char pin[WIFI_WPS_PIN_MAX_LEN + 1];
};
/** Wi-Fi AP status
*/
enum wifi_hostapd_iface_state {
WIFI_HAPD_IFACE_UNINITIALIZED,
WIFI_HAPD_IFACE_DISABLED,
WIFI_HAPD_IFACE_COUNTRY_UPDATE,
WIFI_HAPD_IFACE_ACS,
WIFI_HAPD_IFACE_HT_SCAN,
WIFI_HAPD_IFACE_DFS,
WIFI_HAPD_IFACE_ENABLED
};
#include <zephyr/net/net_if.h>
/** Scan result callback

View file

@ -378,6 +378,8 @@ static inline enum wifi_security_type wpas_key_mgmt_to_zephyr(int key_mgmt, int
return WIFI_SECURITY_TYPE_PSK_SHA256;
case WPA_KEY_MGMT_SAE:
return WIFI_SECURITY_TYPE_SAE;
case WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_PSK:
return WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL;
default:
return WIFI_SECURITY_TYPE_UNKNOWN;
}
@ -1570,7 +1572,7 @@ int hapd_config_network(struct hostapd_iface *iface,
if (!hostapd_cli_cmd_v("set wpa 0")) {
goto out;
}
iface->bss[0]->conf->wpa_key_mgmt = 0;
iface->bss[0]->conf->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
}
if (!hostapd_cli_cmd_v("set ieee80211w %d", params->mfp)) {
@ -1632,6 +1634,80 @@ out:
}
#endif
int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *status)
{
int ret = 0;
struct hostapd_iface *iface;
struct hostapd_config *conf;
struct hostapd_data *hapd;
struct hostapd_bss_config *bss;
struct hostapd_ssid *ssid;
struct hostapd_hw_modes *hw_mode;
int proto; /* Wi-Fi secure protocol */
int key_mgmt; /* Wi-Fi key management */
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
iface = get_hostapd_handle(dev);
if (!iface) {
ret = -1;
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
goto out;
}
conf = iface->conf;
if (!conf) {
ret = -1;
wpa_printf(MSG_ERROR, "Conf %s not found", dev->name);
goto out;
}
bss = conf->bss[0];
if (!bss) {
ret = -1;
wpa_printf(MSG_ERROR, "Bss_conf %s not found", dev->name);
goto out;
}
hapd = iface->bss[0];
if (!hapd) {
ret = -1;
wpa_printf(MSG_ERROR, "Bss %s not found", dev->name);
goto out;
}
status->state = iface->state;
ssid = &bss->ssid;
os_memcpy(status->bssid, hapd->own_addr, WIFI_MAC_ADDR_LEN);
status->iface_mode = WPAS_MODE_AP;
status->band = wpas_band_to_zephyr(wpas_freq_to_band(iface->freq));
key_mgmt = bss->wpa_key_mgmt;
proto = bss->wpa;
status->security = wpas_key_mgmt_to_zephyr(key_mgmt, proto);
status->mfp = bss->ieee80211w;
status->channel = conf->channel;
os_memcpy(status->ssid, ssid->ssid, ssid->ssid_len);
status->dtim_period = bss->dtim_period;
status->beacon_interval = conf->beacon_int;
hw_mode = iface->current_mode;
status->link_mode = conf->ieee80211ax ? WIFI_6
: conf->ieee80211ac ? WIFI_5
: conf->ieee80211n ? WIFI_4
: hw_mode->mode == HOSTAPD_MODE_IEEE80211G ? WIFI_3
: hw_mode->mode == HOSTAPD_MODE_IEEE80211A ? WIFI_2
: hw_mode->mode == HOSTAPD_MODE_IEEE80211B ? WIFI_1
: WIFI_0;
status->twt_capable = (hw_mode->he_capab[IEEE80211_MODE_AP].mac_cap[0] & 0x04);
out:
k_mutex_unlock(&wpa_supplicant_mutex);
return ret;
}
int supplicant_ap_enable(const struct device *dev,
struct wifi_connect_req_params *params)
{
@ -1711,7 +1787,7 @@ int supplicant_ap_enable(const struct device *dev,
goto out;
}
/* No need to check for existing network to join for SoftAP*/
/* No need to check for existing network to join for SoftAP */
wpa_s->conf->ap_scan = 2;
/* Set BSS parameter max_num_sta to default configured value */
wpa_s->conf->max_num_sta = CONFIG_WIFI_MGMT_AP_MAX_NUM_STA;

View file

@ -250,6 +250,15 @@ static inline int hapd_state(const struct device *dev, int *state)
}
#endif
/**
* @brief Get Wi-Fi SAP status
*
* @param dev Wi-Fi device
* @param status SAP status
* @return 0 for OK; -1 for ERROR
*/
int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *status);
/**
* @brief Set Wi-Fi AP configuration
*

View file

@ -99,6 +99,7 @@ static const struct wifi_mgmt_ops mgmt_ap_ops = {
.ap_disable = supplicant_ap_disable,
.ap_sta_disconnect = supplicant_ap_sta_disconnect,
.ap_bandwidth = supplicant_ap_bandwidth,
.iface_status = supplicant_ap_status,
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
.dpp_dispatch = hapd_dpp_dispatch,
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */

View file

@ -41,6 +41,8 @@ const char *wifi_security_txt(enum wifi_security_type security)
return "WAPI";
case WIFI_SECURITY_TYPE_EAP_TLS:
return "EAP";
case WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL:
return "WPA/WPA2/WPA3 PSK";
case WIFI_SECURITY_TYPE_UNKNOWN:
default:
return "UNKNOWN";

View file

@ -953,6 +953,65 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[])
return 0;
}
static int cmd_wifi_ap_status(const struct shell *sh, size_t argc, char *argv[])
{
struct net_if *iface = net_if_get_wifi_sap();
struct wifi_iface_status status = {0};
uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")];
context.sh = sh;
if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &status,
sizeof(struct wifi_iface_status))) {
PR_WARNING("Status request failed\n");
return -ENOEXEC;
}
switch (status.state) {
case WIFI_HAPD_IFACE_UNINITIALIZED:
PR("State: %s\n", "HAPD_IFACE_UNINITIALIZED");
return 0;
case WIFI_HAPD_IFACE_DISABLED:
PR("State: %s\n", "HAPD_IFACE_DISABLED");
return 0;
case WIFI_HAPD_IFACE_COUNTRY_UPDATE:
PR("State: %s\n", "HAPD_IFACE_DISABLED");
return 0;
case WIFI_HAPD_IFACE_ACS:
PR("State: %s\n", "HAPD_IFACE_DISABLED");
return 0;
case WIFI_HAPD_IFACE_HT_SCAN:
PR("State: %s\n", "HAPD_IFACE_DISABLED");
return 0;
case WIFI_HAPD_IFACE_DFS:
PR("State: %s\n", "HAPD_IFACE_DISABLED");
break;
case WIFI_HAPD_IFACE_ENABLED:
break;
default:
return 0;
}
PR("Interface Mode: %s\n", wifi_mode_txt(status.iface_mode));
PR("Link Mode: %s\n", wifi_link_mode_txt(status.link_mode));
PR("SSID: %.32s\n", status.ssid);
PR("BSSID: %s\n", net_sprint_ll_addr_buf(status.bssid, WIFI_MAC_ADDR_LEN, mac_string_buf,
sizeof(mac_string_buf)));
PR("Band: %s\n", wifi_band_txt(status.band));
PR("Channel: %d\n", status.channel);
PR("Security: %s\n", wifi_security_txt(status.security));
PR("MFP: %s\n", wifi_mfp_txt(status.mfp));
if (status.iface_mode == WIFI_MODE_INFRA) {
PR("RSSI: %d\n", status.rssi);
}
PR("Beacon Interval: %d\n", status.beacon_interval);
PR("DTIM: %d\n", status.dtim_period);
PR("TWT: %s\n", status.twt_capable ? "Supported" : "Not supported");
return 0;
}
#if defined(CONFIG_NET_STATISTICS_WIFI) && \
defined(CONFIG_NET_STATISTICS_USER_API)
static void print_wifi_stats(struct net_if *iface, struct net_stats_wifi *data,
@ -2716,43 +2775,36 @@ static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[
return 0;
}
SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap,
SHELL_CMD_ARG(disable, NULL,
"Disable Access Point mode.\n",
cmd_wifi_ap_disable,
1, 0),
SHELL_STATIC_SUBCMD_SET_CREATE(
wifi_cmd_ap,
SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n", cmd_wifi_ap_disable, 1, 0),
SHELL_CMD_ARG(enable, NULL,
"-s --ssid=<SSID>\n"
"-c --channel=<channel number>\n"
"-p --passphrase=<PSK> (valid only for secure SSIDs)\n"
"-k --key-mgmt=<Security type> (valid only for secure SSIDs)\n"
"0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP-TLS, 6:WEP\n"
"7: WPA-PSK, 11: DPP\n"
"-w --ieee-80211w=<MFP> (optional: needs security type to be specified)\n"
"0:Disable, 1:Optional, 2:Required\n"
"-b --band=<band> (2 -2.6GHz, 5 - 5Ghz, 6 - 6GHz)\n"
"-m --bssid=<BSSID>\n"
"-h --help (prints help)",
cmd_wifi_ap_enable,
2, 13),
SHELL_CMD_ARG(stations, NULL,
"List stations connected to the AP",
cmd_wifi_ap_stations,
1, 0),
"-s --ssid=<SSID>\n"
"-c --channel=<channel number>\n"
"-p --passphrase=<PSK> (valid only for secure SSIDs)\n"
"-k --key-mgmt=<Security type> (valid only for secure SSIDs)\n"
"0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP-TLS, 6:WEP\n"
"7: WPA-PSK, 11: DPP\n"
"-w --ieee-80211w=<MFP> (optional: needs security type to be specified)\n"
"0:Disable, 1:Optional, 2:Required\n"
"-b --band=<band> (2 -2.6GHz, 5 - 5Ghz, 6 - 6GHz)\n"
"-m --bssid=<BSSID>\n"
"-h --help (prints help)",
cmd_wifi_ap_enable, 2, 13),
SHELL_CMD_ARG(stations, NULL, "List stations connected to the AP", cmd_wifi_ap_stations, 1,
0),
SHELL_CMD_ARG(disconnect, NULL,
"Disconnect a station from the AP\n"
"<MAC address of the station>\n",
cmd_wifi_ap_sta_disconnect,
2, 0),
"Disconnect a station from the AP\n"
"<MAC address of the station>\n",
cmd_wifi_ap_sta_disconnect, 2, 0),
SHELL_CMD_ARG(config, NULL,
"Configure AP parameters.\n"
"-i --max_inactivity=<time duration (in seconds)>\n"
"-s --max_num_sta=<maximum number of stations>\n"
"-h --help (prints help)",
cmd_wifi_ap_config_params,
2, 5),
SHELL_SUBCMD_SET_END
);
"Configure AP parameters.\n"
"-i --max_inactivity=<time duration (in seconds)>\n"
"-s --max_num_sta=<maximum number of stations>\n"
"-h --help (prints help)",
cmd_wifi_ap_config_params, 2, 5),
SHELL_CMD_ARG(status, NULL, "Status of Wi-Fi SAP\n", cmd_wifi_ap_status, 1, 0),
SHELL_SUBCMD_SET_END);
SHELL_SUBCMD_ADD((wifi), ap, &wifi_cmd_ap,
"Access Point mode commands.",