Skip to content
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

wifi: TWT improvements #82312

Merged
merged 4 commits into from
Dec 16, 2024
Merged
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
23 changes: 22 additions & 1 deletion drivers/wifi/nxp/nxp_wifi_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1396,11 +1396,13 @@ static int nxp_wifi_set_twt(const struct device *dev, struct wifi_twt_params *pa
twt_setup_conf.implicit = params->setup.implicit;
twt_setup_conf.announced = params->setup.announce;
twt_setup_conf.trigger_enabled = params->setup.trigger;
twt_setup_conf.twt_info_disabled = params->setup.twt_info_disable;
krish2718 marked this conversation as resolved.
Show resolved Hide resolved
twt_setup_conf.negotiation_type = params->negotiation_type;
twt_setup_conf.twt_wakeup_duration = params->setup.twt_wake_interval;
twt_setup_conf.flow_identifier = params->flow_id;
twt_setup_conf.hard_constraint = 1;
twt_setup_conf.twt_mantissa = params->setup.twt_interval;
twt_setup_conf.twt_exponent = params->setup.twt_exponent;
twt_setup_conf.twt_mantissa = params->setup.twt_mantissa;
twt_setup_conf.twt_request = params->setup.responder;
ret = wlan_set_twt_setup_cfg(&twt_setup_conf);
} else if (params->operation == WIFI_TWT_TEARDOWN) {
Expand All @@ -1412,6 +1414,22 @@ static int nxp_wifi_set_twt(const struct device *dev, struct wifi_twt_params *pa

return ret;
}

static int nxp_wifi_set_btwt(const struct device *dev, struct wifi_twt_params *params)
{
wlan_btwt_config_t btwt_config;

btwt_config.action = 1;
btwt_config.sub_id = params->btwt.sub_id;
btwt_config.nominal_wake = params->btwt.nominal_wake;
btwt_config.max_sta_support = params->btwt.max_sta_support;
btwt_config.twt_mantissa = params->btwt.twt_mantissa;
btwt_config.twt_offset = params->btwt.twt_offset;
btwt_config.twt_exponent = params->btwt.twt_exponent;
btwt_config.sp_gap = params->btwt.sp_gap;

return wlan_set_btwt_cfg(&btwt_config);
}
#endif

static void nxp_wifi_sta_init(struct net_if *iface)
Expand Down Expand Up @@ -1774,6 +1792,9 @@ static const struct wifi_mgmt_ops nxp_wifi_uap_mgmt = {
.set_power_save = nxp_wifi_power_save,
.get_power_save_config = nxp_wifi_get_power_save,
.ap_config_params = nxp_wifi_ap_config_params,
#ifdef CONFIG_NXP_WIFI_11AX_TWT
.set_btwt = nxp_wifi_set_btwt,
#endif
};

static const struct net_wifi_mgmt_offload nxp_wifi_uap_apis = {
Expand Down
39 changes: 39 additions & 0 deletions include/zephyr/net/wifi_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ enum net_request_wifi_cmd {
NET_REQUEST_WIFI_CMD_PS,
/** Setup or teardown TWT flow */
NET_REQUEST_WIFI_CMD_TWT,
/** Setup BTWT flow */
NET_REQUEST_WIFI_CMD_BTWT,
/** Get power save config */
NET_REQUEST_WIFI_CMD_PS_CONFIG,
/** Set or get regulatory domain */
Expand Down Expand Up @@ -194,6 +196,11 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PS);

NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_TWT);

#define NET_REQUEST_WIFI_BTWT \
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_BTWT)

NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_BTWT);

/** Request a Wi-Fi power save configuration */
#define NET_REQUEST_WIFI_PS_CONFIG \
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PS_CONFIG)
Expand Down Expand Up @@ -747,7 +754,30 @@ struct wifi_twt_params {
* prepare the data before TWT SP starts.
*/
uint32_t twt_wake_ahead_duration;
/** TWT info enabled or disable */
krish2718 marked this conversation as resolved.
Show resolved Hide resolved
bool twt_info_disable;
/** TWT exponent */
uint8_t twt_exponent;
/** TWT Mantissa Range: [0-sizeof(UINT16)] */
uint16_t twt_mantissa;
} setup;
/** Setup specific parameters */
struct {
/** Broadcast TWT AP config */
uint16_t sub_id;
/** Range 64-255 */
uint8_t nominal_wake;
/** Max STA support */
uint8_t max_sta_support;
/** TWT mantissa */
uint16_t twt_mantissa;
/** TWT offset */
uint16_t twt_offset;
/** TWT exponent */
uint8_t twt_exponent;
/** SP gap */
uint8_t sp_gap;
} btwt;
/** Teardown specific parameters */
struct {
/** Teardown all flows */
Expand All @@ -766,6 +796,7 @@ struct wifi_twt_params {
/* 256 (u8) * 1TU */
#define WIFI_MAX_TWT_WAKE_INTERVAL_US 262144
#define WIFI_MAX_TWT_WAKE_AHEAD_DURATION_US (LONG_MAX - 1)
#define WIFI_MAX_TWT_EXPONENT 31

/** @endcond */

Expand Down Expand Up @@ -1362,6 +1393,14 @@ struct wifi_mgmt_ops {
* @return 0 if ok, < 0 if error
*/
int (*set_twt)(const struct device *dev, struct wifi_twt_params *params);
/** Setup BTWT flow
*
* @param dev Pointer to the device structure for the driver instance.
* @param params BTWT parameters
*
* @return 0 if ok, < 0 if error
*/
int (*set_btwt)(const struct device *dev, struct wifi_twt_params *params);
/** Get power save config
*
* @param dev Pointer to the device structure for the driver instance.
Expand Down
12 changes: 12 additions & 0 deletions modules/hostap/src/supp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,18 @@ int supplicant_set_twt(const struct device *dev, struct wifi_twt_params *params)
return wifi_mgmt_api->set_twt(dev, params);
}

int supplicant_set_btwt(const struct device *dev, struct wifi_twt_params *params)
{
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);

if (!wifi_mgmt_api || !wifi_mgmt_api->set_btwt) {
wpa_printf(MSG_ERROR, "Set Broadcast TWT not supported");
return -ENOTSUP;
}

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

int supplicant_get_power_save_config(const struct device *dev,
struct wifi_ps_config *config)
{
Expand Down
9 changes: 9 additions & 0 deletions modules/hostap/src/supp_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ int supplicant_set_power_save(const struct device *dev, struct wifi_ps_params *p
*/
int supplicant_set_twt(const struct device *dev, struct wifi_twt_params *params);

/**
* @brief Set Wi-Fi BTWT parameters
*
* @param dev Wi-Fi interface name to use
* @param params BTWT parameters to set
* @return 0 for OK; -1 for ERROR
*/
int supplicant_set_btwt(const struct device *dev, struct wifi_twt_params *params);

/**
* @brief Get 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 @@ -114,6 +114,7 @@ static const struct wifi_mgmt_ops mgmt_ap_ops = {
#ifdef CONFIG_WIFI_NM_HOSTAPD_CRYPTO_ENTERPRISE
.enterprise_creds = supplicant_add_enterprise_creds,
#endif
.set_btwt = supplicant_set_btwt,
};

DEFINE_WIFI_NM_INSTANCE(hostapd, &mgmt_ap_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 @@ -916,6 +916,35 @@ static int wifi_set_twt(uint32_t mgmt_request, struct net_if *iface,

NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_TWT, wifi_set_twt);

static int wifi_set_btwt(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_twt_params *twt_params = data;
struct wifi_iface_status info = { 0 };

if (wifi_mgmt_api == NULL || wifi_mgmt_api->set_btwt == NULL) {
twt_params->fail_reason =
WIFI_TWT_FAIL_OPERATION_NOT_SUPPORTED;
return -ENOTSUP;
}

if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &info,
sizeof(struct wifi_iface_status))) {
twt_params->fail_reason =
WIFI_TWT_FAIL_UNABLE_TO_GET_IFACE_STATUS;
goto fail;
}

return wifi_mgmt_api->set_btwt(dev, twt_params);
fail:
return -ENOEXEC;

}

NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_BTWT, wifi_set_btwt);

void wifi_mgmt_raise_twt_event(struct net_if *iface, struct wifi_twt_params *twt_params)
{
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_TWT,
Expand Down
Loading
Loading