Skip to content

Commit

Permalink
hostap: Support flushing PMKSA cache entries
Browse files Browse the repository at this point in the history
Support flushing PMKSA cache entries in the reconnection
failed case of WPA3 SAE.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
  • Loading branch information
MaochenWang1 committed Jul 24, 2024
1 parent ebb96a5 commit c0b464c
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/zephyr/net/wifi_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ enum net_request_wifi_cmd {
NET_REQUEST_WIFI_CMD_RTS_THRESHOLD,
/** Configure AP parameter */
NET_REQUEST_WIFI_CMD_AP_CONFIG_PARAM,
/** Flush PMKSA cache entries */
NET_REQUEST_WIFI_CMD_PMKSA_FLUSH,
/** @cond INTERNAL_HIDDEN */
NET_REQUEST_WIFI_CMD_MAX
/** @endcond */
Expand Down Expand Up @@ -206,6 +208,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 PMKSA cache entries flush */
#define NET_REQUEST_WIFI_PMKSA_FLUSH \
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PMKSA_FLUSH)

NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PMKSA_FLUSH);

/** @brief Wi-Fi management events */
enum net_event_wifi_cmd {
/** Scan results available */
Expand Down Expand Up @@ -965,6 +973,13 @@ 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);
/** Flush PMKSA cache entries
*
* @param dev Pointer to the device structure for the driver instance.
*
* @return 0 if ok, < 0 if error
*/
int (*pmksa_flush)(const struct device *dev);
};

/** Wi-Fi management offload API */
Expand Down
25 changes: 25 additions & 0 deletions modules/hostap/src/supp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,31 @@ int supplicant_get_stats(const struct device *dev, struct net_stats_wifi *stats)
}
#endif /* CONFIG_NET_STATISTICS_WIFI */

int supplicant_pmksa_flush(const struct device *dev)
{
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 = -1;
wpa_printf(MSG_ERROR, "Device %s not found", dev->name);
goto out;
}

if (!wpa_cli_cmd_v("pmksa_flush")) {
ret = -1;
wpa_printf(MSG_ERROR, "pmksa_flush failed");
goto out;
}

out:
k_mutex_unlock(&wpa_supplicant_mutex);
return ret;
}

int supplicant_set_power_save(const struct device *dev, struct wifi_ps_params *params)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
Expand Down
8 changes: 8 additions & 0 deletions modules/hostap/src/supp_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ int supplicant_scan(const struct device *dev, struct wifi_scan_params *params,
int supplicant_get_stats(const struct device *dev, struct net_stats_wifi *stats);
#endif /* CONFIG_NET_STATISTICS_WIFI || __DOXYGEN__ */

/** Flush PMKSA cache entries
*
* @param dev Pointer to the device structure for the driver instance.
*
* @return 0 if ok, < 0 if error
*/
int supplicant_pmksa_flush(const struct device *dev);

/**
* @brief Set Wi-Fi power save configuration
*
Expand Down
1 change: 1 addition & 0 deletions modules/hostap/src/supp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static const struct wifi_mgmt_ops mgmt_ops = {
.ap_disable = supplicant_ap_disable,
.ap_sta_disconnect = supplicant_ap_sta_disconnect,
#endif /* CONFIG_AP */
.pmksa_flush = supplicant_pmksa_flush,
};

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

NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD, wifi_set_rts_threshold);

static int wifi_pmksa_flush(uint32_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);

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

return wifi_mgmt_api->pmksa_flush(dev);
}

NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PMKSA_FLUSH, wifi_pmksa_flush);

#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS
void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface,
struct wifi_raw_scan_result *raw_scan_result)
Expand Down
17 changes: 17 additions & 0 deletions subsys/net/l2/wifi/wifi_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,20 @@ static int cmd_wifi_version(const struct shell *sh, size_t argc, char *argv[])
return 0;
}

static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[])
{
struct net_if *iface = net_if_get_wifi_sta();

context.sh = sh;

if (net_mgmt(NET_REQUEST_WIFI_PMKSA_FLUSH, iface, NULL, 0)) {
PR_WARNING("Flush PMKSA cache entries failed\n");
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 @@ -2122,6 +2136,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands,
cmd_wifi_set_rts_threshold,
2,
0),
SHELL_CMD_ARG(pmksa_flush, NULL,
"Flush PMKSA cache entries.\n",
cmd_wifi_pmksa_flush, 1, 0),
SHELL_SUBCMD_SET_END
);

Expand Down

0 comments on commit c0b464c

Please sign in to comment.