Skip to content

Commit

Permalink
hostap: Support getting Wi-Fi connection paramters recently used
Browse files Browse the repository at this point in the history
Support saving and getting Wi-Fi connection paramters recently used.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
  • Loading branch information
MaochenWang1 committed Jul 24, 2024
1 parent af57038 commit ebb96a5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/zephyr/net/wifi_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ enum net_request_wifi_cmd {
NET_REQUEST_WIFI_CMD_AP_STA_DISCONNECT,
/** Get Wi-Fi driver and Firmware versions */
NET_REQUEST_WIFI_CMD_VERSION,
/** Get Wi-Fi latest connection parameters */
NET_REQUEST_WIFI_CMD_CONN_PARAMS,
/** Set RTS threshold */
NET_REQUEST_WIFI_CMD_RTS_THRESHOLD,
/** Configure AP parameter */
Expand Down Expand Up @@ -186,6 +188,12 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_STA_DISCONNECT);

NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_VERSION);

/** Request a Wi-Fi connection parameters */
#define NET_REQUEST_WIFI_CONN_PARAMS \
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_CONN_PARAMS)

NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CONN_PARAMS);

/** Request a Wi-Fi RTS threshold */
#define NET_REQUEST_WIFI_RTS_THRESHOLD \
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_RTS_THRESHOLD)
Expand Down Expand Up @@ -933,6 +941,14 @@ struct wifi_mgmt_ops {
* @return 0 if ok, < 0 if error
*/
int (*get_version)(const struct device *dev, struct wifi_version *params);
/** Get Wi-Fi connection parameters recently used
*
* @param dev Pointer to the device structure for the driver instance
* @param params the Wi-Fi connection parameters recently used
*
* @return 0 if ok, < 0 if error
*/
int (*get_conn_params)(const struct device *dev, struct wifi_connect_req_params *params);
/** Set RTS threshold value
*
* @param dev Pointer to the device structure for the driver instance.
Expand Down
26 changes: 26 additions & 0 deletions modules/hostap/src/supp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
extern struct k_sem wpa_supplicant_ready_sem;
extern struct wpa_global *global;

/* save the last wifi connection parameters */
static struct wifi_connect_req_params last_wifi_conn_params;

enum requested_ops {
CONNECT = 0,
DISCONNECT
Expand Down Expand Up @@ -519,6 +522,8 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s,
goto out;
}

memset(&last_wifi_conn_params, 0, sizeof(struct wifi_connect_req_params));
memcpy((void *)&last_wifi_conn_params, params, sizeof(struct wifi_connect_req_params));
return 0;

rem_net:
Expand Down Expand Up @@ -905,6 +910,27 @@ int supplicant_channel(const struct device *dev, struct wifi_channel_info *chann
return wifi_mgmt_api->channel(dev, channel);
}

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

params = &last_wifi_conn_params;
out:
k_mutex_unlock(&wpa_supplicant_mutex);
return ret;
}

#ifdef CONFIG_AP
int supplicant_ap_enable(const struct device *dev,
struct wifi_connect_req_params *params)
Expand Down
10 changes: 10 additions & 0 deletions modules/hostap/src/supp_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ int supplicant_filter(const struct device *dev, struct wifi_filter_info *filter)
*/
int supplicant_channel(const struct device *dev, struct wifi_channel_info *channel);

/** Get Wi-Fi connection parameters recently used
*
* @param dev Pointer to the device structure for the driver instance
* @param params the Wi-Fi connection parameters recently used
*
* @return 0 if ok, < 0 if error
*/
int supplicant_get_wifi_conn_params(const struct device *dev,
struct wifi_connect_req_params *params);

#ifdef CONFIG_AP
/**
* @brief Set Wi-Fi AP 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 @@ -59,6 +59,7 @@ static const struct wifi_mgmt_ops mgmt_ops = {
.mode = supplicant_mode,
.filter = supplicant_filter,
.channel = supplicant_channel,
.get_conn_params = supplicant_get_wifi_conn_params,
#ifdef CONFIG_AP
.ap_enable = supplicant_ap_enable,
.ap_disable = supplicant_ap_disable,
Expand Down
16 changes: 16 additions & 0 deletions subsys/net/l2/wifi/wifi_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,22 @@ static int wifi_get_version(uint32_t mgmt_request, struct net_if *iface,

NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_VERSION, wifi_get_version);

static int wifi_get_connection_params(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);
struct wifi_connect_req_params *conn_params = data;

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

return wifi_mgmt_api->get_conn_params(dev, conn_params);
}

NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CONN_PARAMS, wifi_get_connection_params);

static int wifi_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
Expand Down

0 comments on commit ebb96a5

Please sign in to comment.