@@ -29,6 +29,7 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF);
29
29
#include <zephyr/sys/slist.h>
30
30
31
31
#include "net_shell_private.h"
32
+ #include <math.h>
32
33
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
33
34
static const char ca_cert_test [] = {
34
35
#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[],
1624
1625
int opt_index = 0 ;
1625
1626
struct getopt_state * state ;
1626
1627
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 ;
1627
1632
static const struct option long_options [] = {
1628
1633
{"negotiation-type" , required_argument , 0 , 'n' },
1629
1634
{"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[],
1636
1641
{"wake-interval" , required_argument , 0 , 'w' },
1637
1642
{"interval" , required_argument , 0 , 'i' },
1638
1643
{"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' },
1639
1647
{"help" , no_argument , 0 , 'h' },
1640
1648
{0 , 0 , 0 , 0 }};
1641
1649
1642
1650
params -> operation = WIFI_TWT_SETUP ;
1643
1651
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" ,
1645
1653
long_options , & opt_index )) != -1 ) {
1646
1654
state = getopt_state_get ();
1647
1655
switch (opt ) {
@@ -1730,11 +1738,56 @@ static int twt_args_to_params(const struct shell *sh, size_t argc, char *argv[],
1730
1738
params -> setup .twt_wake_ahead_duration = (uint32_t )value ;
1731
1739
break ;
1732
1740
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
+
1733
1763
case 'h' :
1734
1764
return - ENOEXEC ;
1735
1765
}
1736
1766
}
1737
1767
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
+
1738
1791
return 0 ;
1739
1792
}
1740
1793
@@ -3386,9 +3439,12 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops,
3386
3439
"<-w --wake-interval>: 1-262144us\n"
3387
3440
"<-i --interval>: 1us-2^31us\n"
3388
3441
"<-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"
3389
3445
"[-h, --help]: Print out command usage.\n" ,
3390
3446
cmd_wifi_twt_setup ,
3391
- 23 , 1 ),
3447
+ 25 , 5 ),
3392
3448
SHELL_CMD_ARG (
3393
3449
btwt_setup , NULL ,
3394
3450
" Start a BTWT flow:\n"
0 commit comments