Skip to content

Commit 76a10fa

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 c3326dd commit 76a10fa

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
@@ -1032,6 +1032,18 @@ struct wifi_dpp_params {
10321032

10331033
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */
10341034

1035+
/** Wi-Fi AP status
1036+
*/
1037+
enum wifi_hostapd_iface_state {
1038+
WIFI_HAPD_IFACE_UNINITIALIZED,
1039+
WIFI_HAPD_IFACE_DISABLED,
1040+
WIFI_HAPD_IFACE_COUNTRY_UPDATE,
1041+
WIFI_HAPD_IFACE_ACS,
1042+
WIFI_HAPD_IFACE_HT_SCAN,
1043+
WIFI_HAPD_IFACE_DFS,
1044+
WIFI_HAPD_IFACE_ENABLED
1045+
};
1046+
10351047
#include <zephyr/net/net_if.h>
10361048

10371049
/** Scan result callback

modules/hostap/src/supp_api.c

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ static inline enum wifi_security_type wpas_key_mgmt_to_zephyr(int key_mgmt, int
376376
return WIFI_SECURITY_TYPE_PSK_SHA256;
377377
case WPA_KEY_MGMT_SAE:
378378
return WIFI_SECURITY_TYPE_SAE;
379+
case WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_PSK:
380+
return WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL;
379381
default:
380382
return WIFI_SECURITY_TYPE_UNKNOWN;
381383
}
@@ -1483,7 +1485,7 @@ int hapd_config_network(struct hostapd_iface *iface,
14831485
if (!hostapd_cli_cmd_v("set wpa 0")) {
14841486
goto out;
14851487
}
1486-
iface->bss[0]->conf->wpa_key_mgmt = 0;
1488+
iface->bss[0]->conf->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
14871489
}
14881490

14891491
if (!hostapd_cli_cmd_v("set ieee80211w %d", params->mfp)) {
@@ -1545,6 +1547,80 @@ int supplicant_ap_config_params(const struct device *dev, struct wifi_ap_config_
15451547
}
15461548
#endif
15471549

1550+
int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *status)
1551+
{
1552+
int ret = 0;
1553+
struct hostapd_iface *iface;
1554+
struct hostapd_config *conf;
1555+
struct hostapd_data *hapd;
1556+
struct hostapd_bss_config *bss;
1557+
struct hostapd_ssid *ssid;
1558+
struct hostapd_hw_modes *hw_mode;
1559+
int proto; /* Wi-Fi secure protocol */
1560+
int key_mgmt; /* Wi-Fi key management */
1561+
1562+
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
1563+
1564+
iface = get_hostapd_handle(dev);
1565+
if (!iface) {
1566+
ret = -1;
1567+
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
1568+
goto out;
1569+
}
1570+
1571+
conf = iface->conf;
1572+
if (!conf) {
1573+
ret = -1;
1574+
wpa_printf(MSG_ERROR, "Conf %s not found", dev->name);
1575+
goto out;
1576+
}
1577+
1578+
bss = conf->bss[0];
1579+
if (!bss) {
1580+
ret = -1;
1581+
wpa_printf(MSG_ERROR, "Bss_conf %s not found", dev->name);
1582+
goto out;
1583+
}
1584+
1585+
hapd = iface->bss[0];
1586+
if (!hapd) {
1587+
ret = -1;
1588+
wpa_printf(MSG_ERROR, "Bss %s not found", dev->name);
1589+
goto out;
1590+
}
1591+
1592+
status->state = iface->state;
1593+
ssid = &bss->ssid;
1594+
1595+
os_memcpy(status->bssid, hapd->own_addr, WIFI_MAC_ADDR_LEN);
1596+
status->iface_mode = WPAS_MODE_AP;
1597+
status->band = wpas_band_to_zephyr(wpas_freq_to_band(iface->freq));
1598+
key_mgmt = bss->wpa_key_mgmt;
1599+
proto = bss->wpa;
1600+
status->security = wpas_key_mgmt_to_zephyr(key_mgmt, proto);
1601+
status->mfp = bss->ieee80211w;
1602+
status->channel = conf->channel;
1603+
os_memcpy(status->ssid, ssid->ssid, ssid->ssid_len);
1604+
1605+
status->dtim_period = bss->dtim_period;
1606+
status->beacon_interval = conf->beacon_int;
1607+
1608+
hw_mode = iface->current_mode;
1609+
1610+
status->link_mode = conf->ieee80211ax ? WIFI_6
1611+
: conf->ieee80211ac ? WIFI_5
1612+
: conf->ieee80211n ? WIFI_4
1613+
: hw_mode->mode == HOSTAPD_MODE_IEEE80211G ? WIFI_3
1614+
: hw_mode->mode == HOSTAPD_MODE_IEEE80211A ? WIFI_2
1615+
: hw_mode->mode == HOSTAPD_MODE_IEEE80211B ? WIFI_1
1616+
: WIFI_0;
1617+
status->twt_capable = (hw_mode->he_capab[IEEE80211_MODE_AP].mac_cap[0] & 0x04);
1618+
1619+
out:
1620+
k_mutex_unlock(&wpa_supplicant_mutex);
1621+
return ret;
1622+
}
1623+
15481624
int supplicant_ap_enable(const struct device *dev,
15491625
struct wifi_connect_req_params *params)
15501626
{
@@ -1626,7 +1702,7 @@ int supplicant_ap_enable(const struct device *dev,
16261702
goto out;
16271703
}
16281704

1629-
/* No need to check for existing network to join for SoftAP*/
1705+
/* No need to check for existing network to join for SoftAP */
16301706
wpa_s->conf->ap_scan = 2;
16311707
/* Set BSS parameter max_num_sta to default configured value */
16321708
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
@@ -241,6 +241,15 @@ static inline int hapd_state(const struct device *dev, int *state)
241241
}
242242
#endif
243243

244+
/**
245+
* @brief Get Wi-Fi SAP status
246+
*
247+
* @param dev Wi-Fi device
248+
* @param status SAP status
249+
* @return 0 for OK; -1 for ERROR
250+
*/
251+
int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *status);
252+
244253
/**
245254
* @brief Set Wi-Fi AP configuration
246255
*

modules/hostap/src/supp_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static const struct wifi_mgmt_ops mgmt_ap_ops = {
9898
.ap_disable = supplicant_ap_disable,
9999
.ap_sta_disconnect = supplicant_ap_sta_disconnect,
100100
.ap_bandwidth = supplicant_ap_bandwidth,
101+
.iface_status = supplicant_ap_status,
101102
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
102103
.dpp_dispatch = hapd_dpp_dispatch,
103104
#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
@@ -953,6 +953,65 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[])
953953
return 0;
954954
}
955955

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

2705-
SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap,
2706-
SHELL_CMD_ARG(disable, NULL,
2707-
"Disable Access Point mode.\n",
2708-
cmd_wifi_ap_disable,
2709-
1, 0),
2764+
SHELL_STATIC_SUBCMD_SET_CREATE(
2765+
wifi_cmd_ap,
2766+
SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n", cmd_wifi_ap_disable, 1, 0),
27102767
SHELL_CMD_ARG(enable, NULL,
2711-
"-s --ssid=<SSID>\n"
2712-
"-c --channel=<channel number>\n"
2713-
"-p --passphrase=<PSK> (valid only for secure SSIDs)\n"
2714-
"-k --key-mgmt=<Security type> (valid only for secure SSIDs)\n"
2715-
"0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP-TLS, 6:WEP\n"
2716-
"7: WPA-PSK, 11: DPP\n"
2717-
"-w --ieee-80211w=<MFP> (optional: needs security type to be specified)\n"
2718-
"0:Disable, 1:Optional, 2:Required\n"
2719-
"-b --band=<band> (2 -2.6GHz, 5 - 5Ghz, 6 - 6GHz)\n"
2720-
"-m --bssid=<BSSID>\n"
2721-
"-h --help (prints help)",
2722-
cmd_wifi_ap_enable,
2723-
2, 13),
2724-
SHELL_CMD_ARG(stations, NULL,
2725-
"List stations connected to the AP",
2726-
cmd_wifi_ap_stations,
2727-
1, 0),
2768+
"-s --ssid=<SSID>\n"
2769+
"-c --channel=<channel number>\n"
2770+
"-p --passphrase=<PSK> (valid only for secure SSIDs)\n"
2771+
"-k --key-mgmt=<Security type> (valid only for secure SSIDs)\n"
2772+
"0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP-TLS, 6:WEP\n"
2773+
"7: WPA-PSK, 11: DPP\n"
2774+
"-w --ieee-80211w=<MFP> (optional: needs security type to be specified)\n"
2775+
"0:Disable, 1:Optional, 2:Required\n"
2776+
"-b --band=<band> (2 -2.6GHz, 5 - 5Ghz, 6 - 6GHz)\n"
2777+
"-m --bssid=<BSSID>\n"
2778+
"-h --help (prints help)",
2779+
cmd_wifi_ap_enable, 2, 13),
2780+
SHELL_CMD_ARG(stations, NULL, "List stations connected to the AP", cmd_wifi_ap_stations, 1,
2781+
0),
27282782
SHELL_CMD_ARG(disconnect, NULL,
2729-
"Disconnect a station from the AP\n"
2730-
"<MAC address of the station>\n",
2731-
cmd_wifi_ap_sta_disconnect,
2732-
2, 0),
2783+
"Disconnect a station from the AP\n"
2784+
"<MAC address of the station>\n",
2785+
cmd_wifi_ap_sta_disconnect, 2, 0),
27332786
SHELL_CMD_ARG(config, NULL,
2734-
"Configure AP parameters.\n"
2735-
"-i --max_inactivity=<time duration (in seconds)>\n"
2736-
"-s --max_num_sta=<maximum number of stations>\n"
2737-
"-h --help (prints help)",
2738-
cmd_wifi_ap_config_params,
2739-
2, 5),
2740-
SHELL_SUBCMD_SET_END
2741-
);
2787+
"Configure AP parameters.\n"
2788+
"-i --max_inactivity=<time duration (in seconds)>\n"
2789+
"-s --max_num_sta=<maximum number of stations>\n"
2790+
"-h --help (prints help)",
2791+
cmd_wifi_ap_config_params, 2, 5),
2792+
SHELL_CMD_ARG(status, NULL, "Status of Wi-Fi SAP\n", cmd_wifi_ap_status, 1, 0),
2793+
SHELL_SUBCMD_SET_END);
27422794

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

0 commit comments

Comments
 (0)