Skip to content

Add support for OKC settings #93204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/zephyr/net/wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,12 @@ enum wifi_ap_config_param {
WIFI_AP_CONFIG_PARAM_VHT_CAPAB = BIT(4),
};

/** @brief Wi-Fi STA mode configuration parameter */
enum wifi_config_param {
/** Used for STA mode configuration parameter OKC */
WIFI_CONFIG_PARAM_OKC = BIT(0),
};

/** Helper function to get user-friendly status name for the status code. */
const char *wifi_conn_status_txt(enum wifi_conn_status status);

Expand Down
25 changes: 24 additions & 1 deletion include/zephyr/net/wifi_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ enum net_request_wifi_cmd {
NET_REQUEST_WIFI_CMD_RTS_THRESHOLD,
/** Configure AP parameter */
NET_REQUEST_WIFI_CMD_AP_CONFIG_PARAM,
/** Configure STA parameter */
NET_REQUEST_WIFI_CMD_CONFIG_PARAM,
/** DPP actions */
NET_REQUEST_WIFI_CMD_DPP,
/** BSS transition management query */
Expand Down Expand Up @@ -267,6 +269,12 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD);

NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_CONFIG_PARAM);

/** Request a Wi-Fi STA parameters configuration */
#define NET_REQUEST_WIFI_CONFIG_PARAM \
(NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_CONFIG_PARAM)

NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CONFIG_PARAM);

#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
/** Request a Wi-Fi DPP operation */
#define NET_REQUEST_WIFI_DPP \
Expand Down Expand Up @@ -1054,6 +1062,14 @@ struct wifi_ap_config_params {
#endif
};

/** @brief Wi-Fi STA configuration parameter */
struct wifi_config_params {
/** Parameter used to identify the different STA parameters */
enum wifi_config_param type;
/** Parameter used for opportunistic key caching */
int okc;
};

#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
/** @brief Wi-Fi DPP configuration parameter */
/** Wi-Fi DPP QR-CODE in string max len for SHA512 */
Expand Down Expand Up @@ -1538,7 +1554,14 @@ struct wifi_mgmt_ops {
* @return 0 if ok, < 0 if error
*/
int (*ap_config_params)(const struct device *dev, struct wifi_ap_config_params *params);

/** Configure STA parameter
*
* @param dev Pointer to the device structure for the driver instance.
* @param params STA mode parameter configuration parameter info
*
* @return 0 if ok, < 0 if error
*/
int (*config_params)(const struct device *dev, struct wifi_config_params *params);
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
/** Dispatch DPP operations by action enum, with or without arguments in string format
*
Expand Down
28 changes: 28 additions & 0 deletions modules/hostap/src/supp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2336,3 +2336,31 @@ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *pa
return 0;
}
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */

int supplicant_config_params(const struct device *dev, struct wifi_config_params *params)
{
struct wpa_supplicant *wpa_s;
int ret = 0;

k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);

wpa_s = get_wpa_s_handle(dev);
if (!wpa_s) {
ret = -ENOENT;
wpa_printf(MSG_ERROR, "Device %s not found", dev->name);
goto out;
}

if (params->type & WIFI_CONFIG_PARAM_OKC) {
if (!wpa_cli_cmd_v("set okc %d", params->okc)) {
ret = -EINVAL;
wpa_printf(MSG_ERROR, "Failed to set OKC");
goto out;
}
wpa_printf(MSG_INFO, "Set OKC: %d", params->okc);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wpa_printf(MSG_INFO, "Set OKC: %d", params->okc);
wpa_printf(MSG_DEBUG, "Set OKC: %d", params->okc);

}

out:
k_mutex_unlock(&wpa_supplicant_mutex);
return ret;
}
9 changes: 9 additions & 0 deletions modules/hostap/src/supp_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,13 @@ int dpp_params_to_cmd(struct wifi_dpp_params *params, char *cmd, size_t max_len)
*/
int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *params);
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */

/**
* @brief Wi-Fi STA configuration parameter.
*
* @param dev Wi-Fi interface handle to use
* @param params STA parameters
* @return 0 for OK; -1 for ERROR
*/
int supplicant_config_params(const struct device *dev, struct wifi_config_params *params);
#endif /* ZEPHYR_SUPP_MGMT_H */
1 change: 1 addition & 0 deletions modules/hostap/src/supp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ static const struct wifi_mgmt_ops mgmt_ops = {
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
.enterprise_creds = supplicant_add_enterprise_creds,
#endif
.config_params = supplicant_config_params,
};

DEFINE_WIFI_NM_INSTANCE(wifi_supplicant, &mgmt_ops);
Expand Down
29 changes: 29 additions & 0 deletions subsys/net/l2/wifi/wifi_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,35 @@ static int wifi_pmksa_flush(uint64_t mgmt_request, struct net_if *iface,

NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PMKSA_FLUSH, wifi_pmksa_flush);

static int wifi_config_params(uint64_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
struct wifi_config_params *params = data;

if (dev == NULL) {
return -ENODEV;
}

if (wifi_mgmt_api == NULL ||
wifi_mgmt_api->config_params == NULL) {
return -ENOTSUP;
}

if (!net_if_is_admin_up(iface)) {
return -ENETDOWN;
}

if (!data || len != sizeof(*params)) {
return -EINVAL;
}

return wifi_mgmt_api->config_params(dev, params);
}

NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CONFIG_PARAM, wifi_config_params);

static int wifi_get_rts_threshold(uint64_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
Expand Down
67 changes: 67 additions & 0 deletions subsys/net/l2/wifi/wifi_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -3809,6 +3809,66 @@ static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[

return 0;
}

static int wifi_config_args_to_params(const struct shell *sh, size_t argc, char *argv[],
struct wifi_config_params *params)
{
int opt;
int opt_index = 0;
struct getopt_state *state;
static const struct option long_options[] = {
{"okc", required_argument, 0, 'o'},
{"iface", required_argument, 0, 'i'},
{0, 0, 0, 0}};
long val;

while ((opt = getopt_long(argc, argv, "o:i:",
long_options, &opt_index)) != -1) {
state = getopt_state_get();
switch (opt) {
case 'o':
if (!parse_number(sh, &val, state->optarg, "okc", 0, 1)) {
return -EINVAL;
}
params->okc = val;
params->type |= WIFI_CONFIG_PARAM_OKC;
break;
case 'i':
/* Unused, but parsing to avoid unknown option error */
break;
default:
PR_ERROR("Invalid option %c\n", state->optopt);
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
}

return 0;
}

static int cmd_wifi_config_params(const struct shell *sh, size_t argc, char *argv[])
{
struct net_if *iface = get_iface(IFACE_TYPE_STA, argc, argv);
struct wifi_config_params config_params = { 0 };
int ret = -1;

context.sh = sh;

if (wifi_config_args_to_params(sh, argc, argv, &config_params)) {
return -ENOEXEC;
}

ret = net_mgmt(NET_REQUEST_WIFI_CONFIG_PARAM, iface,
&config_params, sizeof(struct wifi_config_params));
if (ret) {
PR_WARNING("Setting STA parameter failed: %s\n",
strerror(-ret));
return -ENOEXEC;
}

return 0;
}

SHELL_STATIC_SUBCMD_SET_CREATE(
wifi_cmd_ap,
SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n"
Expand Down Expand Up @@ -4287,6 +4347,13 @@ SHELL_SUBCMD_ADD((wifi), ps_exit_strategy, NULL,
cmd_wifi_ps_exit_strategy,
2, 2);

SHELL_SUBCMD_ADD((wifi), config, NULL,
"Configure STA parameters.\n"
"-o, --okc=<0/1>: Opportunistic Key Caching. 0: disable, 1: enable\n"
"[-i, --iface=<interface index>] : Interface index.\n",
cmd_wifi_config_params,
3, 12);

SHELL_CMD_REGISTER(wifi, &wifi_commands, "Wi-Fi commands", NULL);

static int wifi_shell_init(void)
Expand Down