Skip to content

Commit 0406f9b

Browse files
Rex-Chen-NXPkartben
authored andcommitted
net: wifi: shell: add parameters for twt setup
Add two parameters for twt setup. Signed-off-by: Rex Chen <[email protected]>
1 parent a1f579a commit 0406f9b

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

drivers/wifi/nxp/nxp_wifi_drv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,11 +1498,13 @@ static int nxp_wifi_set_twt(const struct device *dev, struct wifi_twt_params *pa
14981498
twt_setup_conf.implicit = params->setup.implicit;
14991499
twt_setup_conf.announced = params->setup.announce;
15001500
twt_setup_conf.trigger_enabled = params->setup.trigger;
1501+
twt_setup_conf.twt_info_disabled = params->setup.twt_info_disable;
15011502
twt_setup_conf.negotiation_type = params->negotiation_type;
15021503
twt_setup_conf.twt_wakeup_duration = params->setup.twt_wake_interval;
15031504
twt_setup_conf.flow_identifier = params->flow_id;
15041505
twt_setup_conf.hard_constraint = 1;
1505-
twt_setup_conf.twt_mantissa = params->setup.twt_interval;
1506+
twt_setup_conf.twt_exponent = params->setup.twt_exponent;
1507+
twt_setup_conf.twt_mantissa = params->setup.twt_mantissa;
15061508
twt_setup_conf.twt_request = params->setup.responder;
15071509
ret = wlan_set_twt_setup_cfg(&twt_setup_conf);
15081510
} else if (params->operation == WIFI_TWT_TEARDOWN) {

include/zephyr/net/wifi_mgmt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,12 @@ struct wifi_twt_params {
756756
* prepare the data before TWT SP starts.
757757
*/
758758
uint32_t twt_wake_ahead_duration;
759+
/** TWT info enabled or disable */
760+
bool twt_info_disable;
761+
/** TWT exponent */
762+
uint8_t twt_exponent;
763+
/** TWT Mantissa Range: [0-sizeof(UINT16)] */
764+
uint16_t twt_mantissa;
759765
} setup;
760766
/** Setup specific parameters */
761767
struct {
@@ -792,6 +798,7 @@ struct wifi_twt_params {
792798
/* 256 (u8) * 1TU */
793799
#define WIFI_MAX_TWT_WAKE_INTERVAL_US 262144
794800
#define WIFI_MAX_TWT_WAKE_AHEAD_DURATION_US (LONG_MAX - 1)
801+
#define WIFI_MAX_TWT_EXPONENT 31
795802

796803
/** @endcond */
797804

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF);
2929
#include <zephyr/sys/slist.h>
3030

3131
#include "net_shell_private.h"
32+
#include <math.h>
3233
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
3334
static const char ca_cert_test[] = {
3435
#include <wifi_enterprise_test_certs/ca.pem.inc>
@@ -1624,6 +1625,10 @@ static int twt_args_to_params(const struct shell *sh, size_t argc, char *argv[],
16241625
int opt_index = 0;
16251626
struct getopt_state *state;
16261627
long value;
1628+
double twt_mantissa_scale = 0.0;
1629+
double twt_interval_scale = 0.0;
1630+
uint16_t scale = 1000;
1631+
int exponent = 0;
16271632
static const struct option long_options[] = {
16281633
{"negotiation-type", required_argument, 0, 'n'},
16291634
{"setup-cmd", required_argument, 0, 'c'},
@@ -1636,12 +1641,15 @@ static int twt_args_to_params(const struct shell *sh, size_t argc, char *argv[],
16361641
{"wake-interval", required_argument, 0, 'w'},
16371642
{"interval", required_argument, 0, 'i'},
16381643
{"wake-ahead-duration", required_argument, 0, 'D'},
1644+
{"info-disable", required_argument, 0, 'd'},
1645+
{"exponent", required_argument, 0, 'e'},
1646+
{"mantissa", required_argument, 0, 'm'},
16391647
{"help", no_argument, 0, 'h'},
16401648
{0, 0, 0, 0}};
16411649

16421650
params->operation = WIFI_TWT_SETUP;
16431651

1644-
while ((opt = getopt_long(argc, argv, "n:c:t:f:r:T:I:a:t:w:i:D:d:e:h",
1652+
while ((opt = getopt_long(argc, argv, "n:c:t:f:r:T:I:a:t:w:i:D:d:e:m:h",
16451653
long_options, &opt_index)) != -1) {
16461654
state = getopt_state_get();
16471655
switch (opt) {
@@ -1730,11 +1738,56 @@ static int twt_args_to_params(const struct shell *sh, size_t argc, char *argv[],
17301738
params->setup.twt_wake_ahead_duration = (uint32_t)value;
17311739
break;
17321740

1741+
case 'd':
1742+
if (!parse_number(sh, &value, state->optarg, NULL, 0, 1)) {
1743+
return -EINVAL;
1744+
}
1745+
params->setup.twt_info_disable = (bool)value;
1746+
break;
1747+
1748+
case 'e':
1749+
if (!parse_number(sh, &value, state->optarg, NULL, 0,
1750+
WIFI_MAX_TWT_EXPONENT)) {
1751+
return -EINVAL;
1752+
}
1753+
params->setup.twt_exponent = (uint8_t)value;
1754+
break;
1755+
1756+
case 'm':
1757+
if (!parse_number(sh, &value, state->optarg, NULL, 0, 0xFFFF)) {
1758+
return -EINVAL;
1759+
}
1760+
params->setup.twt_mantissa = (uint16_t)value;
1761+
break;
1762+
17331763
case 'h':
17341764
return -ENOEXEC;
17351765
}
17361766
}
17371767

1768+
if ((params->setup.twt_interval != 0) &&
1769+
((params->setup.twt_exponent != 0) ||
1770+
(params->setup.twt_mantissa != 0))) {
1771+
PR_ERROR("Only one of TWT internal or (mantissa, exponent) should be used\n");
1772+
return -EINVAL;
1773+
}
1774+
1775+
if (params->setup.twt_interval) {
1776+
/* control the region of mantissa filed */
1777+
twt_interval_scale = (double)(params->setup.twt_interval / scale);
1778+
/* derive mantissa and exponent from interval */
1779+
twt_mantissa_scale = frexp(twt_interval_scale, &exponent);
1780+
params->setup.twt_mantissa = ceil(twt_mantissa_scale * scale);
1781+
params->setup.twt_exponent = exponent;
1782+
} else if ((params->setup.twt_exponent != 0) ||
1783+
(params->setup.twt_mantissa != 0)) {
1784+
params->setup.twt_interval = floor(ldexp(params->setup.twt_mantissa,
1785+
params->setup.twt_exponent));
1786+
} else {
1787+
PR_ERROR("Either TWT interval or (mantissa, exponent) is needed\n");
1788+
return -EINVAL;
1789+
}
1790+
17381791
return 0;
17391792
}
17401793

@@ -3386,9 +3439,12 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops,
33863439
"<-w --wake-interval>: 1-262144us\n"
33873440
"<-i --interval>: 1us-2^31us\n"
33883441
"<-D --wake-ahead-duration>: 0us-2^31us\n"
3442+
"<-d --info-disable>: 0/1\n"
3443+
"<-e --exponent>: 0-31\n"
3444+
"<-m --mantissa>: 1-2^16\n"
33893445
"[-h, --help]: Print out command usage.\n",
33903446
cmd_wifi_twt_setup,
3391-
23, 1),
3447+
25, 5),
33923448
SHELL_CMD_ARG(
33933449
btwt_setup, NULL,
33943450
" Start a BTWT flow:\n"

0 commit comments

Comments
 (0)