From 448b787c82765d510d7a0a4c7f1c93dd7db41656 Mon Sep 17 00:00:00 2001 From: Qiankun Li Date: Thu, 24 Apr 2025 09:13:14 +0530 Subject: [PATCH] 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 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 --- include/zephyr/net/wifi_mgmt.h | 38 +++++++++------ subsys/net/l2/wifi/wifi_shell.c | 84 +++++++++++++++++++++++++-------- 2 files changed, 88 insertions(+), 34 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 8c6654f3ef5..64088070dc0 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -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 { diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 0b8257695dd..537e406979e 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -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, ¶ms, 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" - " " - " .\n" - "[-i, --iface=] : Interface index.\n", + " : 2-5\n" + " : 64-255\n" + " : 64-255\n" + " : 64-255\n" + " The total number of '0, 1, ..., x' is session_num\n", + "[-i, --iface=] : Interface index.\n" cmd_wifi_btwt_setup, - 8, 2), + 13, 2), SHELL_CMD_ARG(teardown, NULL, " Teardown a TWT flow:\n" "\n" "\n"