Skip to content

Commit 16aca91

Browse files
GaofengZhangNXPkrish2718
authored andcommitted
[nrf fromtree] hostapd: add ap status in l2 wifi
add ap status in l2 wifi Signed-off-by: Gaofeng Zhang <[email protected]> (cherry picked from commit 0c54a3f)
1 parent e78a076 commit 16aca91

File tree

6 files changed

+188
-36
lines changed

6 files changed

+188
-36
lines changed

include/zephyr/net/wifi_mgmt.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,18 @@ struct wifi_wps_config_params {
10741074
char pin[WIFI_WPS_PIN_MAX_LEN + 1];
10751075
};
10761076

1077+
/** Wi-Fi AP status
1078+
*/
1079+
enum wifi_hostapd_iface_state {
1080+
WIFI_HAPD_IFACE_UNINITIALIZED,
1081+
WIFI_HAPD_IFACE_DISABLED,
1082+
WIFI_HAPD_IFACE_COUNTRY_UPDATE,
1083+
WIFI_HAPD_IFACE_ACS,
1084+
WIFI_HAPD_IFACE_HT_SCAN,
1085+
WIFI_HAPD_IFACE_DFS,
1086+
WIFI_HAPD_IFACE_ENABLED
1087+
};
1088+
10771089
#include <zephyr/net/net_if.h>
10781090

10791091
/** Scan result callback

modules/hostap/src/supp_api.c

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ static inline enum wifi_security_type wpas_key_mgmt_to_zephyr(int key_mgmt, int
378378
return WIFI_SECURITY_TYPE_PSK_SHA256;
379379
case WPA_KEY_MGMT_SAE:
380380
return WIFI_SECURITY_TYPE_SAE;
381+
case WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_PSK:
382+
return WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL;
381383
default:
382384
return WIFI_SECURITY_TYPE_UNKNOWN;
383385
}
@@ -1574,7 +1576,7 @@ int hapd_config_network(struct hostapd_iface *iface,
15741576
if (!hostapd_cli_cmd_v("set wpa 0")) {
15751577
goto out;
15761578
}
1577-
iface->bss[0]->conf->wpa_key_mgmt = 0;
1579+
iface->bss[0]->conf->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
15781580
}
15791581

15801582
if (!hostapd_cli_cmd_v("set ieee80211w %d", params->mfp)) {
@@ -1636,6 +1638,80 @@ int supplicant_ap_config_params(const struct device *dev, struct wifi_ap_config_
16361638
}
16371639
#endif
16381640

1641+
int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *status)
1642+
{
1643+
int ret = 0;
1644+
struct hostapd_iface *iface;
1645+
struct hostapd_config *conf;
1646+
struct hostapd_data *hapd;
1647+
struct hostapd_bss_config *bss;
1648+
struct hostapd_ssid *ssid;
1649+
struct hostapd_hw_modes *hw_mode;
1650+
int proto; /* Wi-Fi secure protocol */
1651+
int key_mgmt; /* Wi-Fi key management */
1652+
1653+
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
1654+
1655+
iface = get_hostapd_handle(dev);
1656+
if (!iface) {
1657+
ret = -1;
1658+
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
1659+
goto out;
1660+
}
1661+
1662+
conf = iface->conf;
1663+
if (!conf) {
1664+
ret = -1;
1665+
wpa_printf(MSG_ERROR, "Conf %s not found", dev->name);
1666+
goto out;
1667+
}
1668+
1669+
bss = conf->bss[0];
1670+
if (!bss) {
1671+
ret = -1;
1672+
wpa_printf(MSG_ERROR, "Bss_conf %s not found", dev->name);
1673+
goto out;
1674+
}
1675+
1676+
hapd = iface->bss[0];
1677+
if (!hapd) {
1678+
ret = -1;
1679+
wpa_printf(MSG_ERROR, "Bss %s not found", dev->name);
1680+
goto out;
1681+
}
1682+
1683+
status->state = iface->state;
1684+
ssid = &bss->ssid;
1685+
1686+
os_memcpy(status->bssid, hapd->own_addr, WIFI_MAC_ADDR_LEN);
1687+
status->iface_mode = WPAS_MODE_AP;
1688+
status->band = wpas_band_to_zephyr(wpas_freq_to_band(iface->freq));
1689+
key_mgmt = bss->wpa_key_mgmt;
1690+
proto = bss->wpa;
1691+
status->security = wpas_key_mgmt_to_zephyr(key_mgmt, proto);
1692+
status->mfp = bss->ieee80211w;
1693+
status->channel = conf->channel;
1694+
os_memcpy(status->ssid, ssid->ssid, ssid->ssid_len);
1695+
1696+
status->dtim_period = bss->dtim_period;
1697+
status->beacon_interval = conf->beacon_int;
1698+
1699+
hw_mode = iface->current_mode;
1700+
1701+
status->link_mode = conf->ieee80211ax ? WIFI_6
1702+
: conf->ieee80211ac ? WIFI_5
1703+
: conf->ieee80211n ? WIFI_4
1704+
: hw_mode->mode == HOSTAPD_MODE_IEEE80211G ? WIFI_3
1705+
: hw_mode->mode == HOSTAPD_MODE_IEEE80211A ? WIFI_2
1706+
: hw_mode->mode == HOSTAPD_MODE_IEEE80211B ? WIFI_1
1707+
: WIFI_0;
1708+
status->twt_capable = (hw_mode->he_capab[IEEE80211_MODE_AP].mac_cap[0] & 0x04);
1709+
1710+
out:
1711+
k_mutex_unlock(&wpa_supplicant_mutex);
1712+
return ret;
1713+
}
1714+
16391715
int supplicant_ap_enable(const struct device *dev,
16401716
struct wifi_connect_req_params *params)
16411717
{
@@ -1717,7 +1793,7 @@ int supplicant_ap_enable(const struct device *dev,
17171793
goto out;
17181794
}
17191795

1720-
/* No need to check for existing network to join for SoftAP*/
1796+
/* No need to check for existing network to join for SoftAP */
17211797
wpa_s->conf->ap_scan = 2;
17221798
/* Set BSS parameter max_num_sta to default configured value */
17231799
wpa_s->conf->max_num_sta = CONFIG_WIFI_MGMT_AP_MAX_NUM_STA;

modules/hostap/src/supp_api.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ static inline int hapd_state(const struct device *dev, int *state)
250250
}
251251
#endif
252252

253+
/**
254+
* @brief Get Wi-Fi SAP status
255+
*
256+
* @param dev Wi-Fi device
257+
* @param status SAP status
258+
* @return 0 for OK; -1 for ERROR
259+
*/
260+
int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *status);
261+
253262
/**
254263
* @brief Set Wi-Fi AP configuration
255264
*

modules/hostap/src/supp_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static const struct wifi_mgmt_ops mgmt_ap_ops = {
9999
.ap_disable = supplicant_ap_disable,
100100
.ap_sta_disconnect = supplicant_ap_sta_disconnect,
101101
.ap_bandwidth = supplicant_ap_bandwidth,
102+
.iface_status = supplicant_ap_status,
102103
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
103104
.dpp_dispatch = hapd_dpp_dispatch,
104105
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const char *wifi_security_txt(enum wifi_security_type security)
4141
return "WAPI";
4242
case WIFI_SECURITY_TYPE_EAP_TLS:
4343
return "EAP";
44+
case WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL:
45+
return "WPA/WPA2/WPA3 PSK";
4446
case WIFI_SECURITY_TYPE_UNKNOWN:
4547
default:
4648
return "UNKNOWN";

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 86 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,65 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[])
954954
return 0;
955955
}
956956

957+
static int cmd_wifi_ap_status(const struct shell *sh, size_t argc, char *argv[])
958+
{
959+
struct net_if *iface = net_if_get_wifi_sap();
960+
struct wifi_iface_status status = {0};
961+
uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")];
962+
963+
context.sh = sh;
964+
965+
if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &status,
966+
sizeof(struct wifi_iface_status))) {
967+
PR_WARNING("Status request failed\n");
968+
969+
return -ENOEXEC;
970+
}
971+
972+
switch (status.state) {
973+
case WIFI_HAPD_IFACE_UNINITIALIZED:
974+
PR("State: %s\n", "HAPD_IFACE_UNINITIALIZED");
975+
return 0;
976+
case WIFI_HAPD_IFACE_DISABLED:
977+
PR("State: %s\n", "HAPD_IFACE_DISABLED");
978+
return 0;
979+
case WIFI_HAPD_IFACE_COUNTRY_UPDATE:
980+
PR("State: %s\n", "HAPD_IFACE_DISABLED");
981+
return 0;
982+
case WIFI_HAPD_IFACE_ACS:
983+
PR("State: %s\n", "HAPD_IFACE_DISABLED");
984+
return 0;
985+
case WIFI_HAPD_IFACE_HT_SCAN:
986+
PR("State: %s\n", "HAPD_IFACE_DISABLED");
987+
return 0;
988+
case WIFI_HAPD_IFACE_DFS:
989+
PR("State: %s\n", "HAPD_IFACE_DISABLED");
990+
break;
991+
case WIFI_HAPD_IFACE_ENABLED:
992+
break;
993+
default:
994+
return 0;
995+
}
996+
997+
PR("Interface Mode: %s\n", wifi_mode_txt(status.iface_mode));
998+
PR("Link Mode: %s\n", wifi_link_mode_txt(status.link_mode));
999+
PR("SSID: %.32s\n", status.ssid);
1000+
PR("BSSID: %s\n", net_sprint_ll_addr_buf(status.bssid, WIFI_MAC_ADDR_LEN, mac_string_buf,
1001+
sizeof(mac_string_buf)));
1002+
PR("Band: %s\n", wifi_band_txt(status.band));
1003+
PR("Channel: %d\n", status.channel);
1004+
PR("Security: %s\n", wifi_security_txt(status.security));
1005+
PR("MFP: %s\n", wifi_mfp_txt(status.mfp));
1006+
if (status.iface_mode == WIFI_MODE_INFRA) {
1007+
PR("RSSI: %d\n", status.rssi);
1008+
}
1009+
PR("Beacon Interval: %d\n", status.beacon_interval);
1010+
PR("DTIM: %d\n", status.dtim_period);
1011+
PR("TWT: %s\n", status.twt_capable ? "Supported" : "Not supported");
1012+
1013+
return 0;
1014+
}
1015+
9571016
#if defined(CONFIG_NET_STATISTICS_WIFI) && \
9581017
defined(CONFIG_NET_STATISTICS_USER_API)
9591018
static void print_wifi_stats(struct net_if *iface, struct net_stats_wifi *data,
@@ -2754,43 +2813,36 @@ static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[
27542813
return 0;
27552814
}
27562815

2757-
SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap,
2758-
SHELL_CMD_ARG(disable, NULL,
2759-
"Disable Access Point mode.\n",
2760-
cmd_wifi_ap_disable,
2761-
1, 0),
2816+
SHELL_STATIC_SUBCMD_SET_CREATE(
2817+
wifi_cmd_ap,
2818+
SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n", cmd_wifi_ap_disable, 1, 0),
27622819
SHELL_CMD_ARG(enable, NULL,
2763-
"-s --ssid=<SSID>\n"
2764-
"-c --channel=<channel number>\n"
2765-
"-p --passphrase=<PSK> (valid only for secure SSIDs)\n"
2766-
"-k --key-mgmt=<Security type> (valid only for secure SSIDs)\n"
2767-
"0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP-TLS, 6:WEP\n"
2768-
"7: WPA-PSK, 11: DPP\n"
2769-
"-w --ieee-80211w=<MFP> (optional: needs security type to be specified)\n"
2770-
"0:Disable, 1:Optional, 2:Required\n"
2771-
"-b --band=<band> (2 -2.6GHz, 5 - 5Ghz, 6 - 6GHz)\n"
2772-
"-m --bssid=<BSSID>\n"
2773-
"-h --help (prints help)",
2774-
cmd_wifi_ap_enable,
2775-
2, 13),
2776-
SHELL_CMD_ARG(stations, NULL,
2777-
"List stations connected to the AP",
2778-
cmd_wifi_ap_stations,
2779-
1, 0),
2820+
"-s --ssid=<SSID>\n"
2821+
"-c --channel=<channel number>\n"
2822+
"-p --passphrase=<PSK> (valid only for secure SSIDs)\n"
2823+
"-k --key-mgmt=<Security type> (valid only for secure SSIDs)\n"
2824+
"0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP-TLS, 6:WEP\n"
2825+
"7: WPA-PSK, 11: DPP\n"
2826+
"-w --ieee-80211w=<MFP> (optional: needs security type to be specified)\n"
2827+
"0:Disable, 1:Optional, 2:Required\n"
2828+
"-b --band=<band> (2 -2.6GHz, 5 - 5Ghz, 6 - 6GHz)\n"
2829+
"-m --bssid=<BSSID>\n"
2830+
"-h --help (prints help)",
2831+
cmd_wifi_ap_enable, 2, 13),
2832+
SHELL_CMD_ARG(stations, NULL, "List stations connected to the AP", cmd_wifi_ap_stations, 1,
2833+
0),
27802834
SHELL_CMD_ARG(disconnect, NULL,
2781-
"Disconnect a station from the AP\n"
2782-
"<MAC address of the station>\n",
2783-
cmd_wifi_ap_sta_disconnect,
2784-
2, 0),
2835+
"Disconnect a station from the AP\n"
2836+
"<MAC address of the station>\n",
2837+
cmd_wifi_ap_sta_disconnect, 2, 0),
27852838
SHELL_CMD_ARG(config, NULL,
2786-
"Configure AP parameters.\n"
2787-
"-i --max_inactivity=<time duration (in seconds)>\n"
2788-
"-s --max_num_sta=<maximum number of stations>\n"
2789-
"-h --help (prints help)",
2790-
cmd_wifi_ap_config_params,
2791-
2, 5),
2792-
SHELL_SUBCMD_SET_END
2793-
);
2839+
"Configure AP parameters.\n"
2840+
"-i --max_inactivity=<time duration (in seconds)>\n"
2841+
"-s --max_num_sta=<maximum number of stations>\n"
2842+
"-h --help (prints help)",
2843+
cmd_wifi_ap_config_params, 2, 5),
2844+
SHELL_CMD_ARG(status, NULL, "Status of Wi-Fi SAP\n", cmd_wifi_ap_status, 1, 0),
2845+
SHELL_SUBCMD_SET_END);
27942846

27952847
SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops,
27962848
SHELL_CMD_ARG(quick_setup, NULL, " Start a TWT flow with defaults:\n"

0 commit comments

Comments
 (0)