Skip to content

Commit 7c167c6

Browse files
nxf58150aescolar
authored andcommitted
modules: hostap: add 11k cmd support
Add 11k cmds support. User can issue 11k cmds to enable/disable 11k and send Neighbor Report Request packet. Signed-off-by: Hui Bai <[email protected]>
1 parent 3ca71c9 commit 7c167c6

File tree

7 files changed

+237
-0
lines changed

7 files changed

+237
-0
lines changed

drivers/wifi/nxp/nxp_wifi_drv.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,17 @@ static void nxp_wifi_auto_connect(void)
10551055
}
10561056
#endif
10571057

1058+
static int nxp_wifi_11k_cfg(const struct device *dev, struct wifi_11k_params *params)
1059+
{
1060+
if (params->oper == WIFI_MGMT_GET) {
1061+
params->enable_11k = wlan_get_host_11k_status();
1062+
} else {
1063+
wlan_host_11k_cfg(params->enable_11k);
1064+
}
1065+
1066+
return 0;
1067+
}
1068+
10581069
static int nxp_wifi_power_save(const struct device *dev, struct wifi_ps_params *params)
10591070
{
10601071
int status = NXP_WIFI_RET_SUCCESS;
@@ -1640,6 +1651,7 @@ static const struct wifi_mgmt_ops nxp_wifi_sta_mgmt = {
16401651
#if defined(CONFIG_NET_STATISTICS_WIFI)
16411652
.get_stats = nxp_wifi_stats,
16421653
#endif
1654+
.cfg_11k = nxp_wifi_11k_cfg,
16431655
.set_power_save = nxp_wifi_power_save,
16441656
.get_power_save_config = nxp_wifi_get_power_save,
16451657
.set_twt = nxp_wifi_set_twt,

include/zephyr/net/wifi_mgmt.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ enum net_request_wifi_cmd {
7171
NET_REQUEST_WIFI_CMD_AP_DISABLE,
7272
/** Get interface status */
7373
NET_REQUEST_WIFI_CMD_IFACE_STATUS,
74+
/** Set or get 11k status */
75+
NET_REQUEST_WIFI_CMD_11K_CONFIG,
76+
/** Send 11k neighbor request */
77+
NET_REQUEST_WIFI_CMD_11K_NEIGHBOR_REQUEST,
7478
/** Set power save status */
7579
NET_REQUEST_WIFI_CMD_PS,
7680
/** Setup or teardown TWT flow */
@@ -154,6 +158,16 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_DISABLE);
154158

155159
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_IFACE_STATUS);
156160

161+
#define NET_REQUEST_WIFI_11K_CONFIG \
162+
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_11K_CONFIG)
163+
164+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_11K_CONFIG);
165+
166+
#define NET_REQUEST_WIFI_11K_NEIGHBOR_REQUEST \
167+
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_11K_NEIGHBOR_REQUEST)
168+
169+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_11K_NEIGHBOR_REQUEST);
170+
157171
/** Request a Wi-Fi power save */
158172
#define NET_REQUEST_WIFI_PS \
159173
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PS)
@@ -769,6 +783,16 @@ enum wifi_mgmt_op {
769783
WIFI_MGMT_SET = 1,
770784
};
771785

786+
/** Wi-Fi 11k parameters */
787+
struct wifi_11k_params {
788+
/** 11k command operation */
789+
enum wifi_mgmt_op oper;
790+
/** 11k enable/disable */
791+
bool enable_11k;
792+
/** SSID */
793+
uint8_t ssid[WIFI_SSID_MAX_LEN + 1];
794+
};
795+
772796
/** Max regulatory channel number */
773797
#define MAX_REG_CHAN_NUM 42
774798

@@ -1227,6 +1251,22 @@ struct wifi_mgmt_ops {
12271251
*/
12281252
int (*reset_stats)(const struct device *dev);
12291253
#endif /* CONFIG_NET_STATISTICS_WIFI */
1254+
/** Set or get 11K status
1255+
*
1256+
* @param dev Pointer to the device structure for the driver instance.
1257+
* @param params 11k parameters
1258+
*
1259+
* @return 0 if ok, < 0 if error
1260+
*/
1261+
int (*cfg_11k)(const struct device *dev, struct wifi_11k_params *params);
1262+
/** Send 11k neighbor request
1263+
*
1264+
* @param dev Pointer to the device structure for the driver instance.
1265+
* @param params 11k parameters
1266+
*
1267+
* @return 0 if ok, < 0 if error
1268+
*/
1269+
int (*send_11k_neighbor_request)(const struct device *dev, struct wifi_11k_params *params);
12301270
/** Set power save status
12311271
*
12321272
* @param dev Pointer to the device structure for the driver instance.

modules/hostap/src/supp_api.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,48 @@ int supplicant_pmksa_flush(const struct device *dev)
13841384
return ret;
13851385
}
13861386

1387+
int supplicant_11k_cfg(const struct device *dev, struct wifi_11k_params *params)
1388+
{
1389+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
1390+
1391+
if (!wifi_mgmt_api || !wifi_mgmt_api->cfg_11k) {
1392+
wpa_printf(MSG_ERROR, "cfg 11k not supported");
1393+
return -ENOTSUP;
1394+
}
1395+
1396+
return wifi_mgmt_api->cfg_11k(dev, params);
1397+
}
1398+
1399+
int supplicant_11k_neighbor_request(const struct device *dev, struct wifi_11k_params *params)
1400+
{
1401+
int ssid_len = strlen(params->ssid);
1402+
1403+
if (params != NULL && ssid_len > 0) {
1404+
if (ssid_len > WIFI_SSID_MAX_LEN) {
1405+
wpa_printf(MSG_ERROR, "%s: ssid too long %u",
1406+
__func__, ssid_len);
1407+
return -1;
1408+
}
1409+
1410+
if (!wpa_cli_cmd_v("neighbor_rep_request ssid %s",
1411+
params->ssid)) {
1412+
wpa_printf(MSG_ERROR,
1413+
"%s: cli cmd <neighbor_rep_request ssid %s> fail",
1414+
__func__, params->ssid);
1415+
return -1;
1416+
}
1417+
} else {
1418+
if (!wpa_cli_cmd_v("neighbor_rep_request")) {
1419+
wpa_printf(MSG_ERROR,
1420+
"%s: cli cmd <neighbor_rep_request> fail",
1421+
__func__);
1422+
return -1;
1423+
}
1424+
}
1425+
1426+
return 0;
1427+
}
1428+
13871429
int supplicant_set_power_save(const struct device *dev, struct wifi_ps_params *params)
13881430
{
13891431
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);

modules/hostap/src/supp_api.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ int supplicant_reset_stats(const struct device *dev);
100100
*/
101101
int supplicant_pmksa_flush(const struct device *dev);
102102

103+
/** Set or get 11K status
104+
*
105+
* @param dev Pointer to the device structure for the driver instance.
106+
* @param params 11k parameters
107+
*
108+
* @return 0 if ok, < 0 if error
109+
*/
110+
int supplicant_11k_cfg(const struct device *dev, struct wifi_11k_params *params);
111+
112+
/** Send 11k neighbor request
113+
*
114+
* @param dev Pointer to the device structure for the driver instance.
115+
* @param params 11k parameters
116+
*
117+
* @return 0 if ok, < 0 if error
118+
*/
119+
int supplicant_11k_neighbor_request(const struct device *dev, struct wifi_11k_params *params);
120+
103121
/**
104122
* @brief Set Wi-Fi power save configuration
105123
*

modules/hostap/src/supp_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ static const struct wifi_mgmt_ops mgmt_ops = {
6262
.get_stats = supplicant_get_stats,
6363
.reset_stats = supplicant_reset_stats,
6464
#endif
65+
.cfg_11k = supplicant_11k_cfg,
66+
.send_11k_neighbor_request = supplicant_11k_neighbor_request,
6567
.set_power_save = supplicant_set_power_save,
6668
.set_twt = supplicant_set_twt,
6769
.get_power_save_config = supplicant_get_power_save_config,

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,39 @@ static int wifi_iface_stats_reset(uint32_t mgmt_request, struct net_if *iface,
555555
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_RESET_WIFI, wifi_iface_stats_reset);
556556
#endif /* CONFIG_NET_STATISTICS_WIFI */
557557

558+
static int wifi_11k_cfg(uint32_t mgmt_request, struct net_if *iface,
559+
void *data, size_t len)
560+
{
561+
const struct device *dev = net_if_get_device(iface);
562+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
563+
struct wifi_11k_params *params = data;
564+
565+
if (wifi_mgmt_api == NULL || wifi_mgmt_api->cfg_11k == NULL) {
566+
return -ENOTSUP;
567+
}
568+
569+
return wifi_mgmt_api->cfg_11k(dev, params);
570+
}
571+
572+
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_11K_CONFIG, wifi_11k_cfg);
573+
574+
static int wifi_11k_neighbor_request(uint32_t mgmt_request, struct net_if *iface,
575+
void *data, size_t len)
576+
{
577+
const struct device *dev = net_if_get_device(iface);
578+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
579+
struct wifi_11k_params *params = data;
580+
581+
if (wifi_mgmt_api == NULL || wifi_mgmt_api->send_11k_neighbor_request == NULL) {
582+
return -ENOTSUP;
583+
}
584+
585+
return wifi_mgmt_api->send_11k_neighbor_request(dev, params);
586+
}
587+
588+
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_11K_NEIGHBOR_REQUEST,
589+
wifi_11k_neighbor_request);
590+
558591
static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,
559592
void *data, size_t len)
560593
{

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,84 @@ static int cmd_wifi_stats(const struct shell *sh, size_t argc, char *argv[])
11721172
return 0;
11731173
}
11741174

1175+
static int cmd_wifi_11k(const struct shell *sh, size_t argc, char *argv[])
1176+
{
1177+
struct net_if *iface = net_if_get_first_wifi();
1178+
struct wifi_11k_params params = { 0 };
1179+
1180+
context.sh = sh;
1181+
1182+
if (argc > 2) {
1183+
PR_WARNING("Invalid number of arguments\n");
1184+
return -ENOEXEC;
1185+
}
1186+
1187+
if (argc == 1) {
1188+
params.oper = WIFI_MGMT_GET;
1189+
} else {
1190+
params.oper = WIFI_MGMT_SET;
1191+
if (!strncasecmp(argv[1], "enable", 2)) {
1192+
params.enable_11k = true;
1193+
} else if (!strncasecmp(argv[1], "disable", 3)) {
1194+
params.enable_11k = false;
1195+
} else {
1196+
PR_WARNING("Invalid argument\n");
1197+
return -ENOEXEC;
1198+
}
1199+
}
1200+
1201+
if (net_mgmt(NET_REQUEST_WIFI_11K_CONFIG, iface, &params, sizeof(params))) {
1202+
PR_WARNING("11k enable/disable failed\n");
1203+
return -ENOEXEC;
1204+
}
1205+
1206+
if (params.oper == WIFI_MGMT_GET) {
1207+
PR("11k is %s\n", params.enable_11k ? "disabled" : "enabled");
1208+
} else {
1209+
PR("%s %s requested\n", argv[0], argv[1]);
1210+
}
1211+
1212+
return 0;
1213+
}
1214+
1215+
1216+
static int cmd_wifi_11k_neighbor_request(const struct shell *sh, size_t argc, char *argv[])
1217+
{
1218+
struct net_if *iface = net_if_get_first_wifi();
1219+
struct wifi_11k_params params = { 0 };
1220+
1221+
context.sh = sh;
1222+
1223+
if ((argc != 1 && argc != 3) || (argc == 3 && !strncasecmp("ssid", argv[1], 4))) {
1224+
PR_WARNING("Invalid input arguments\n");
1225+
PR_WARNING("Usage: %s\n", argv[0]);
1226+
PR_WARNING("or %s ssid <ssid>\n", argv[0]);
1227+
return -ENOEXEC;
1228+
}
1229+
1230+
if (argc == 3) {
1231+
if (strlen(argv[2]) > (sizeof(params.ssid) - 1)) {
1232+
PR_WARNING("Error: ssid too long\n");
1233+
return -ENOEXEC;
1234+
}
1235+
(void)memcpy((void *)params.ssid, (const void *)argv[2],
1236+
(size_t)strlen(argv[2]));
1237+
}
1238+
1239+
if (net_mgmt(NET_REQUEST_WIFI_11K_NEIGHBOR_REQUEST, iface, &params, sizeof(params))) {
1240+
PR_WARNING("11k neighbor request failed\n");
1241+
return -ENOEXEC;
1242+
}
1243+
1244+
if (argc == 3) {
1245+
PR("%s %s %s requested\n", argv[0], argv[1], argv[2]);
1246+
} else {
1247+
PR("%s requested\n", argv[0]);
1248+
}
1249+
1250+
return 0;
1251+
}
1252+
11751253
static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[])
11761254
{
11771255
struct net_if *iface = net_if_get_first_wifi();
@@ -3057,6 +3135,18 @@ SHELL_SUBCMD_ADD((wifi), dpp, &wifi_cmd_dpp,
30573135

30583136
SHELL_SUBCMD_SET_CREATE(wifi_commands, (wifi));
30593137

3138+
SHELL_SUBCMD_ADD((wifi), 11k, &wifi_commands,
3139+
"Configure 11k or get 11k status.\n"
3140+
"[enable/disable]\n",
3141+
cmd_wifi_11k,
3142+
1, 1);
3143+
3144+
SHELL_SUBCMD_ADD((wifi), 11k_neighbor_request, &wifi_commands,
3145+
"Send Neighbor Report Request frame.\n"
3146+
"[ssid <ssid>]\n",
3147+
cmd_wifi_11k_neighbor_request,
3148+
1, 2);
3149+
30603150
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM
30613151
SHELL_SUBCMD_ADD((wifi), 11v_btm_query, &wifi_commands,
30623152
"<query_reason: The reason code for a BSS transition management query>.\n",

0 commit comments

Comments
 (0)