Skip to content

Commit 255c947

Browse files
committed
net: l2: wifi: add wifi config command
- Added "wifi config" command. - Add OKC parameter to "wifi config" command. Set okc to 1 to enable opportunistic key caching. Signed-off-by: Gang Li <gang.li_1@nxp.com>
1 parent 66acb36 commit 255c947

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed

include/zephyr/net/wifi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,12 @@ enum wifi_ap_config_param {
735735
WIFI_AP_CONFIG_PARAM_VHT_CAPAB = BIT(4),
736736
};
737737

738+
/** @brief Wi-Fi STA mode configuration parameter */
739+
enum wifi_config_param {
740+
/** Used for STA mode configuration parameter OKC */
741+
WIFI_CONFIG_PARAM_OKC = BIT(0),
742+
};
743+
738744
/** Helper function to get user-friendly status name for the status code. */
739745
const char *wifi_conn_status_txt(enum wifi_conn_status status);
740746

include/zephyr/net/wifi_mgmt.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ enum net_request_wifi_cmd {
109109
NET_REQUEST_WIFI_CMD_RTS_THRESHOLD,
110110
/** Configure AP parameter */
111111
NET_REQUEST_WIFI_CMD_AP_CONFIG_PARAM,
112+
/** Configure STA parameter */
113+
NET_REQUEST_WIFI_CMD_CONFIG_PARAM,
112114
/** DPP actions */
113115
NET_REQUEST_WIFI_CMD_DPP,
114116
/** BSS transition management query */
@@ -267,6 +269,12 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD);
267269

268270
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_CONFIG_PARAM);
269271

272+
/** Request a Wi-Fi STA parameters configuration */
273+
#define NET_REQUEST_WIFI_CONFIG_PARAM \
274+
(NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_CONFIG_PARAM)
275+
276+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CONFIG_PARAM);
277+
270278
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
271279
/** Request a Wi-Fi DPP operation */
272280
#define NET_REQUEST_WIFI_DPP \
@@ -1054,6 +1062,14 @@ struct wifi_ap_config_params {
10541062
#endif
10551063
};
10561064

1065+
/** @brief Wi-Fi STA configuration parameter */
1066+
struct wifi_config_params {
1067+
/** Parameter used to identify the different STA parameters */
1068+
enum wifi_config_param type;
1069+
/** Parameter used for opportunistic key caching */
1070+
int okc;
1071+
};
1072+
10571073
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
10581074
/** @brief Wi-Fi DPP configuration parameter */
10591075
/** Wi-Fi DPP QR-CODE in string max len for SHA512 */
@@ -1538,7 +1554,14 @@ struct wifi_mgmt_ops {
15381554
* @return 0 if ok, < 0 if error
15391555
*/
15401556
int (*ap_config_params)(const struct device *dev, struct wifi_ap_config_params *params);
1541-
1557+
/** Configure STA parameter
1558+
*
1559+
* @param dev Pointer to the device structure for the driver instance.
1560+
* @param params STA mode parameter configuration parameter info
1561+
*
1562+
* @return 0 if ok, < 0 if error
1563+
*/
1564+
int (*config_params)(const struct device *dev, struct wifi_config_params *params);
15421565
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
15431566
/** Dispatch DPP operations by action enum, with or without arguments in string format
15441567
*

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,35 @@ static int wifi_pmksa_flush(uint64_t mgmt_request, struct net_if *iface,
13571357

13581358
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PMKSA_FLUSH, wifi_pmksa_flush);
13591359

1360+
static int wifi_config_params(uint64_t mgmt_request, struct net_if *iface,
1361+
void *data, size_t len)
1362+
{
1363+
const struct device *dev = net_if_get_device(iface);
1364+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
1365+
struct wifi_config_params *params = data;
1366+
1367+
if (dev == NULL) {
1368+
return -ENODEV;
1369+
}
1370+
1371+
if (wifi_mgmt_api == NULL ||
1372+
wifi_mgmt_api->config_params == NULL) {
1373+
return -ENOTSUP;
1374+
}
1375+
1376+
if (!net_if_is_admin_up(iface)) {
1377+
return -ENETDOWN;
1378+
}
1379+
1380+
if (!data || len != sizeof(*params)) {
1381+
return -EINVAL;
1382+
}
1383+
1384+
return wifi_mgmt_api->config_params(dev, params);
1385+
}
1386+
1387+
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CONFIG_PARAM, wifi_config_params);
1388+
13601389
static int wifi_get_rts_threshold(uint64_t mgmt_request, struct net_if *iface,
13611390
void *data, size_t len)
13621391
{

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,6 +3809,66 @@ static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[
38093809

38103810
return 0;
38113811
}
3812+
3813+
static int wifi_config_args_to_params(const struct shell *sh, size_t argc, char *argv[],
3814+
struct wifi_config_params *params)
3815+
{
3816+
int opt;
3817+
int opt_index = 0;
3818+
struct getopt_state *state;
3819+
static const struct option long_options[] = {
3820+
{"okc", required_argument, 0, 'o'},
3821+
{"iface", required_argument, 0, 'i'},
3822+
{0, 0, 0, 0}};
3823+
long val;
3824+
3825+
while ((opt = getopt_long(argc, argv, "o:i:",
3826+
long_options, &opt_index)) != -1) {
3827+
state = getopt_state_get();
3828+
switch (opt) {
3829+
case 'o':
3830+
if (!parse_number(sh, &val, state->optarg, "okc", 0, 1)) {
3831+
return -EINVAL;
3832+
}
3833+
params->okc = val;
3834+
params->type |= WIFI_CONFIG_PARAM_OKC;
3835+
break;
3836+
case 'i':
3837+
/* Unused, but parsing to avoid unknown option error */
3838+
break;
3839+
default:
3840+
PR_ERROR("Invalid option %c\n", state->optopt);
3841+
shell_help(sh);
3842+
return SHELL_CMD_HELP_PRINTED;
3843+
}
3844+
}
3845+
3846+
return 0;
3847+
}
3848+
3849+
static int cmd_wifi_config_params(const struct shell *sh, size_t argc, char *argv[])
3850+
{
3851+
struct net_if *iface = get_iface(IFACE_TYPE_STA, argc, argv);
3852+
struct wifi_config_params config_params = { 0 };
3853+
int ret = -1;
3854+
3855+
context.sh = sh;
3856+
3857+
if (wifi_config_args_to_params(sh, argc, argv, &config_params)) {
3858+
return -ENOEXEC;
3859+
}
3860+
3861+
ret = net_mgmt(NET_REQUEST_WIFI_CONFIG_PARAM, iface,
3862+
&config_params, sizeof(struct wifi_config_params));
3863+
if (ret) {
3864+
PR_WARNING("Setting STA parameter failed: %s\n",
3865+
strerror(-ret));
3866+
return -ENOEXEC;
3867+
}
3868+
3869+
return 0;
3870+
}
3871+
38123872
SHELL_STATIC_SUBCMD_SET_CREATE(
38133873
wifi_cmd_ap,
38143874
SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n"
@@ -4287,6 +4347,13 @@ SHELL_SUBCMD_ADD((wifi), ps_exit_strategy, NULL,
42874347
cmd_wifi_ps_exit_strategy,
42884348
2, 2);
42894349

4350+
SHELL_SUBCMD_ADD((wifi), config, NULL,
4351+
"Configure STA parameters.\n"
4352+
"-o, --okc=<0/1>: Opportunistic Key Caching. 0: disable, 1: enable\n"
4353+
"[-i, --iface=<interface index>] : Interface index.\n",
4354+
cmd_wifi_config_params,
4355+
3, 12);
4356+
42904357
SHELL_CMD_REGISTER(wifi, &wifi_commands, "Wi-Fi commands", NULL);
42914358

42924359
static int wifi_shell_init(void)

0 commit comments

Comments
 (0)