@@ -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
3334static 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