net: l2: wifi: Modify btwt_setup usage.

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.

Usage:
wifi twt btwt_setup <sta_wait> <offset>
<twtli> <session_num>
<id0> <mantissa0> <exponent0> <nominal_wake0>
<id1> <mantissa1> <exponent1> <nominal_wake1>
<idx> <mantissax> <exponentx> <nominal_wakex>
The total number of '0, 1, ..., x' is session_num

For example:
wifi twt btwt_setup 0 0 0 2 0 112 10 128 1 32 10 64

Signed-off-by: Qiankun Li <qiankun.li@nxp.com>
This commit is contained in:
Qiankun Li 2025-04-24 09:13:14 +05:30 committed by Benjamin Cabé
commit 448b787c82
2 changed files with 88 additions and 34 deletions

View file

@ -702,6 +702,20 @@ struct wifi_ps_params {
enum wifi_ps_exit_strategy exit_strategy;
};
#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 */
@ -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 {

View file

@ -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);
if (!parse_number(sh, &value, argv[idx++], NULL, 1, 0xFFFF)) {
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;
}
params.btwt.twt_mantissa = (uint16_t)value;
params.btwt.twt_offset = (uint16_t)shell_strtol(argv[idx++], 10, &ret);
if (!parse_number(sh, &value, argv[idx++], NULL, 0, WIFI_MAX_TWT_EXPONENT)) {
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_exponent = (uint8_t)value;
params.btwt.sp_gap = (uint8_t)shell_strtol(argv[idx++], 10, &ret);
if (ret) {
PR_ERROR("Invalid argument (ret %d)\n", 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;
}
params.btwt.btwt_count = (uint8_t)shell_strtol(argv[idx++], 10, &err);
if (err) {
PR_ERROR("Parse btwt count (err %d)\n", err);
return -EINVAL;
}
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 (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));
@ -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"
"[-i, --iface=<interface index>] : Interface index.\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"