Skip to content

Commit 87b4940

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 87b4940

File tree

4 files changed

+139
-1
lines changed

4 files changed

+139
-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: 26 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,16 @@ 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+
#if defined(CONFIG_WIFI_NM_WPA_SUPPLICANT)
1070+
/** Parameter used for opportunistic key caching */
1071+
int okc;
1072+
#endif
1073+
};
1074+
10571075
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
10581076
/** @brief Wi-Fi DPP configuration parameter */
10591077
/** Wi-Fi DPP QR-CODE in string max len for SHA512 */
@@ -1538,7 +1556,14 @@ struct wifi_mgmt_ops {
15381556
* @return 0 if ok, < 0 if error
15391557
*/
15401558
int (*ap_config_params)(const struct device *dev, struct wifi_ap_config_params *params);
1541-
1559+
/** Configure STA parameter
1560+
*
1561+
* @param dev Pointer to the device structure for the driver instance.
1562+
* @param params STA mode parameter configuration parameter info
1563+
*
1564+
* @return 0 if ok, < 0 if error
1565+
*/
1566+
int (*config_params)(const struct device *dev, struct wifi_config_params *params);
15421567
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
15431568
/** Dispatch DPP operations by action enum, with or without arguments in string format
15441569
*

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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,6 +3809,72 @@ 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+
#if defined(CONFIG_WIFI_NM_WPA_SUPPLICANT)
3821+
{"okc", required_argument, 0, 'o'},
3822+
#endif
3823+
{"iface", required_argument, 0, 'i'},
3824+
{0, 0, 0, 0}};
3825+
#if defined(CONFIG_WIFI_NM_WPA_SUPPLICANT)
3826+
long val;
3827+
#endif
3828+
3829+
while ((opt = getopt_long(argc, argv, "o:i:",
3830+
long_options, &opt_index)) != -1) {
3831+
state = getopt_state_get();
3832+
switch (opt) {
3833+
#if defined(CONFIG_WIFI_NM_WPA_SUPPLICANT)
3834+
case 'o':
3835+
if (!parse_number(sh, &val, state->optarg, "okc", 0, 1)) {
3836+
return -EINVAL;
3837+
}
3838+
params->okc = val;
3839+
params->type |= WIFI_CONFIG_PARAM_OKC;
3840+
break;
3841+
#endif
3842+
case 'i':
3843+
/* Unused, but parsing to avoid unknown option error */
3844+
break;
3845+
default:
3846+
PR_ERROR("Invalid option %c\n", state->optopt);
3847+
shell_help(sh);
3848+
return SHELL_CMD_HELP_PRINTED;
3849+
}
3850+
}
3851+
3852+
return 0;
3853+
}
3854+
3855+
static int cmd_wifi_config_params(const struct shell *sh, size_t argc, char *argv[])
3856+
{
3857+
struct net_if *iface = get_iface(IFACE_TYPE_STA, argc, argv);
3858+
struct wifi_config_params config_params = { 0 };
3859+
int ret = -1;
3860+
3861+
context.sh = sh;
3862+
3863+
if (wifi_config_args_to_params(sh, argc, argv, &config_params)) {
3864+
return -ENOEXEC;
3865+
}
3866+
3867+
ret = net_mgmt(NET_REQUEST_WIFI_CONFIG_PARAM, iface,
3868+
&config_params, sizeof(struct wifi_config_params));
3869+
if (ret) {
3870+
PR_WARNING("Setting STA parameter failed: %s\n",
3871+
strerror(-ret));
3872+
return -ENOEXEC;
3873+
}
3874+
3875+
return 0;
3876+
}
3877+
38123878
SHELL_STATIC_SUBCMD_SET_CREATE(
38133879
wifi_cmd_ap,
38143880
SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n"
@@ -4287,6 +4353,18 @@ SHELL_SUBCMD_ADD((wifi), ps_exit_strategy, NULL,
42874353
cmd_wifi_ps_exit_strategy,
42884354
2, 2);
42894355

4356+
SHELL_SUBCMD_ADD((wifi), config, NULL,
4357+
"Configure STA parameters.\n"
4358+
#if defined(CONFIG_WIFI_NM_WPA_SUPPLICANT)
4359+
"Please refer to wpa_supplicant.conf to set the following options,\n"
4360+
"============ IEEE 802.11 related configuration ============\n"
4361+
"-o, --okc=<0/1>: Opportunistic Key Caching. 0: disable, 1: enable\n"
4362+
"===========================================================\n"
4363+
#endif
4364+
"[-i, --iface=<interface index>] : Interface index.\n",
4365+
cmd_wifi_config_params,
4366+
3, 12);
4367+
42904368
SHELL_CMD_REGISTER(wifi, &wifi_commands, "Wi-Fi commands", NULL);
42914369

42924370
static int wifi_shell_init(void)

0 commit comments

Comments
 (0)