Skip to content

Modify btwt_setup usage #89294

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
25 changes: 17 additions & 8 deletions drivers/wifi/nxp/nxp_wifi_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1772,14 +1772,23 @@ static int nxp_wifi_set_btwt(const struct device *dev, struct wifi_twt_params *p
{
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;
memset(&btwt_config, 0, sizeof(wlan_btwt_config_t));

btwt_config.bcast_bet_sta_wait = params->btwt.btwt_sta_wait;
btwt_config.bcast_offset = params->btwt.btwt_offset;
btwt_config.bcast_twtli = params->btwt.btwt_li;
btwt_config.count = params->btwt.btwt_count;

for (int i = 0; i < btwt_config.count; i++) {
btwt_config.btwt_sets[i].btwt_id
= params->btwt.btwt_set_cfg[i].btwt_id;
btwt_config.btwt_sets[i].bcast_mantissa
= params->btwt.btwt_set_cfg[i].btwt_mantissa;
btwt_config.btwt_sets[i].bcast_exponent
= params->btwt.btwt_set_cfg[i].btwt_exponent;
btwt_config.btwt_sets[i].nominal_wake
= params->btwt.btwt_set_cfg[i].btwt_nominal_wake;
}

return wlan_set_btwt_cfg(&btwt_config);
}
Expand Down
38 changes: 24 additions & 14 deletions include/zephyr/net/wifi_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,20 @@ struct wifi_ps_params {
enum wifi_ps_exit_strategy exit_strategy;
Copy link
Member

Choose a reason for hiding this comment

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

The commit message is missing why this change is needed.
Also information about this change could be placed to migration guide

Copy link
Contributor Author

@NXP-Liam-Li NXP-Liam-Li Apr 30, 2025

Choose a reason for hiding this comment

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

Soft ap supports WIFI_BTWT_AGREEMENT_MAX BTWT sessions. The BTWT parameters for each session can be different.

The current usage can only set one set of parameters. All sessions follow this set of parameters.

Add enhance code to support setting different BTWT parameters for every sessions.

Also add this information in commit message.

};

#define WIFI_BTWT_AGREEMENT_MAX 5

/** @brief Wi-Fi broadcast TWT parameters */
struct wifi_btwt_params {
/** Broadcast TWT ID */
uint8_t btwt_id;
/** Broadcast TWT mantissa */
uint16_t btwt_mantissa;
/** Broadcast TWT exponent */
uint8_t btwt_exponent;
/** Broadcast TWT range */
uint8_t btwt_nominal_wake;
};

/** @brief Wi-Fi TWT parameters */
struct wifi_twt_params {
/** TWT operation, see enum wifi_twt_operation */
Expand Down Expand Up @@ -748,20 +762,16 @@ struct wifi_twt_params {
} 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;
/** Broadcast TWT station wait time */
uint8_t btwt_sta_wait;
/** Broadcast TWT offset */
uint16_t btwt_offset;
/** In multiple of 4 beacon interval */
uint8_t btwt_li;
/** Broadcast TWT agreement count */
uint8_t btwt_count;
/** Broadcast TWT agreement sets */
struct wifi_btwt_params btwt_set_cfg[WIFI_BTWT_AGREEMENT_MAX];
} btwt;
/** Teardown specific parameters */
struct {
Expand Down
76 changes: 60 additions & 16 deletions subsys/net/l2/wifi/wifi_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1918,34 +1918,75 @@ static int cmd_wifi_btwt_setup(const struct shell *sh, size_t argc, char *argv[]
struct net_if *iface = get_iface(IFACE_TYPE_SAP, argc, argv);
struct wifi_twt_params params = {0};
int idx = 1;
long value;
int ret = 0;
int err = 0;

context.sh = sh;

params.btwt.sub_id = (uint16_t)shell_strtol(argv[idx++], 10, &ret);
params.btwt.nominal_wake = (uint8_t)shell_strtol(argv[idx++], 10, &ret);
params.btwt.max_sta_support = (uint8_t)shell_strtol(argv[idx++], 10, &ret);
params.btwt.btwt_sta_wait = (uint8_t)shell_strtol(argv[idx++], 10, &err);
if (err) {
PR_ERROR("Parse btwt sta_wait (err %d)\n", err);
return -EINVAL;
}

if (!parse_number(sh, &value, argv[idx++], NULL, 1, 0xFFFF)) {
params.btwt.btwt_offset = (uint16_t)shell_strtol(argv[idx++], 10, &err);
if (err) {
PR_ERROR("Parse btwt offset (err %d)\n", err);
return -EINVAL;
}
params.btwt.twt_mantissa = (uint16_t)value;

params.btwt.twt_offset = (uint16_t)shell_strtol(argv[idx++], 10, &ret);
params.btwt.btwt_li = (uint8_t)shell_strtol(argv[idx++], 10, &err);
if (err) {
PR_ERROR("Parse btwt_li (err %d)\n", err);
return -EINVAL;
}

if (!parse_number(sh, &value, argv[idx++], NULL, 0, WIFI_MAX_TWT_EXPONENT)) {
params.btwt.btwt_count = (uint8_t)shell_strtol(argv[idx++], 10, &err);
if (err) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here, the error status needs to be checked after every conversion call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

PR_ERROR("Parse btwt count (err %d)\n", err);
return -EINVAL;
}
params.btwt.twt_exponent = (uint8_t)value;

params.btwt.sp_gap = (uint8_t)shell_strtol(argv[idx++], 10, &ret);
if (params.btwt.btwt_count < 2 || params.btwt.btwt_count > 5) {
PR_ERROR("Invalid broadcast twt count. Count rang: 2-5.\n");
return -EINVAL;
}

if (ret) {
PR_ERROR("Invalid argument (ret %d)\n", ret);
if (argc != 5 + params.btwt.btwt_count * 4) {
PR_ERROR("Invalid number of broadcast parameters.\n");
return -EINVAL;
}

for (int i = 0; i < params.btwt.btwt_count; i++) {
params.btwt.btwt_set_cfg[i].btwt_id
= (uint8_t)shell_strtol(argv[idx++], 10, &err);
if (err) {
PR_ERROR("Parse btwt [%d] id (err %d)\n", i, err);
return -EINVAL;
}

params.btwt.btwt_set_cfg[i].btwt_mantissa
= (uint16_t)shell_strtol(argv[idx++], 10, &err);
if (err) {
PR_ERROR("Parse btwt [%d] mantissa (err %d)\n", i, err);
return -EINVAL;
}

params.btwt.btwt_set_cfg[i].btwt_exponent
= (uint8_t)shell_strtol(argv[idx++], 10, &err);
if (err) {
PR_ERROR("Parse btwt [%d] exponent (err %d)\n", i, err);
return -EINVAL;
}

params.btwt.btwt_set_cfg[i].btwt_nominal_wake
= (uint8_t)shell_strtol(argv[idx++], 10, &err);
if (err) {
PR_ERROR("Parse btwt [%d] nominal_wake (err %d)\n", i, err);
return -EINVAL;
}
}


if (net_mgmt(NET_REQUEST_WIFI_BTWT, iface, &params, sizeof(params))) {
PR_WARNING("Failed reason : %s\n",
wifi_twt_get_err_code_str(params.fail_reason));
Expand Down Expand Up @@ -3855,11 +3896,14 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops,
SHELL_CMD_ARG(
btwt_setup, NULL,
" Start a BTWT flow:\n"
"<sub_id: Broadcast TWT AP config> <nominal_wake: 64-255> <max_sta_support>"
"<twt_mantissa:0-sizeof(UINT16)> <twt_offset> <twt_exponent: 0-31> <sp_gap>.\n"
"<sta_wait> <offset> <twtli> <session_num>: 2-5\n"
"<id0> <mantissa0> <exponent0> <nominal_wake0>: 64-255\n"
"<id1> <mantissa1> <exponent1> <nominal_wake1>: 64-255\n"
"<idx> <mantissax> <exponentx> <nominal_wakex>: 64-255\n"
" The total number of '0, 1, ..., x' is session_num\n"
"[-i, --iface=<interface index>] : Interface index.\n",
cmd_wifi_btwt_setup,
8, 2),
13, 2),
SHELL_CMD_ARG(teardown, NULL, " Teardown a TWT flow:\n"
"<negotiation_type, 0: Individual, 1: Broadcast, 2: Wake TBTT>\n"
"<setup_cmd: 0: Request, 1: Suggest, 2: Demand>\n"
Expand Down