@@ -1572,74 +1572,139 @@ static int cmd_wifi_twt_setup_quick(const struct shell *sh, size_t argc,
1572
1572
return 0 ;
1573
1573
}
1574
1574
1575
- static int cmd_wifi_twt_setup (const struct shell * sh , size_t argc ,
1576
- char * argv [] )
1575
+ static int twt_args_to_params (const struct shell * sh , size_t argc , char * argv [] ,
1576
+ struct wifi_twt_params * params )
1577
1577
{
1578
- struct net_if * iface = net_if_get_wifi_sta () ;
1579
- struct wifi_twt_params params = { 0 } ;
1580
- int idx = 1 ;
1578
+ int opt ;
1579
+ int opt_index = 0 ;
1580
+ struct getopt_state * state ;
1581
1581
long value ;
1582
+ static const struct option long_options [] = {
1583
+ {"negotiation-type" , required_argument , 0 , 'n' },
1584
+ {"setup-cmd" , required_argument , 0 , 'c' },
1585
+ {"dialog-token" , required_argument , 0 , 't' },
1586
+ {"flow-id" , required_argument , 0 , 'f' },
1587
+ {"responder" , required_argument , 0 , 'r' },
1588
+ {"trigger" , required_argument , 0 , 'T' },
1589
+ {"implicit" , required_argument , 0 , 'I' },
1590
+ {"announce" , required_argument , 0 , 'a' },
1591
+ {"wake-interval" , required_argument , 0 , 'w' },
1592
+ {"interval" , required_argument , 0 , 'i' },
1593
+ {"wake-ahead-duration" , required_argument , 0 , 'D' },
1594
+ {"help" , no_argument , 0 , 'h' },
1595
+ {0 , 0 , 0 , 0 }};
1582
1596
1583
- context . sh = sh ;
1597
+ params -> operation = WIFI_TWT_SETUP ;
1584
1598
1585
- params .operation = WIFI_TWT_SETUP ;
1599
+ while ((opt = getopt_long (argc , argv , "n:c:t:f:r:T:I:a:t:w:i:D:d:e:h" ,
1600
+ long_options , & opt_index )) != -1 ) {
1601
+ state = getopt_state_get ();
1602
+ switch (opt ) {
1603
+ case 'n' :
1604
+ if (!parse_number (sh , & value , state -> optarg , NULL ,
1605
+ WIFI_TWT_INDIVIDUAL ,
1606
+ WIFI_TWT_WAKE_TBTT )) {
1607
+ return - EINVAL ;
1608
+ }
1609
+ params -> negotiation_type = (enum wifi_twt_negotiation_type )value ;
1610
+ break ;
1586
1611
1587
- if (!parse_number (sh , & value , argv [idx ++ ], NULL , WIFI_TWT_INDIVIDUAL ,
1588
- WIFI_TWT_WAKE_TBTT )) {
1589
- return - EINVAL ;
1590
- }
1591
- params .negotiation_type = (enum wifi_twt_negotiation_type )value ;
1612
+ case 'c' :
1613
+ if (!parse_number (sh , & value , state -> optarg , NULL ,
1614
+ WIFI_TWT_SETUP_CMD_REQUEST ,
1615
+ WIFI_TWT_SETUP_CMD_DEMAND )) {
1616
+ return - EINVAL ;
1617
+ }
1618
+ params -> setup_cmd = (enum wifi_twt_setup_cmd )value ;
1619
+ break ;
1592
1620
1593
- if (!parse_number (sh , & value , argv [idx ++ ], NULL , WIFI_TWT_SETUP_CMD_REQUEST ,
1594
- WIFI_TWT_SETUP_CMD_DEMAND )) {
1595
- return - EINVAL ;
1596
- }
1597
- params .setup_cmd = (enum wifi_twt_setup_cmd )value ;
1621
+ case 't' :
1622
+ if (!parse_number (sh , & value , state -> optarg , NULL , 1 , 255 )) {
1623
+ return - EINVAL ;
1624
+ }
1625
+ params -> dialog_token = (uint8_t )value ;
1626
+ break ;
1598
1627
1599
- if (!parse_number (sh , & value , argv [idx ++ ], NULL , 1 , 255 )) {
1600
- return - EINVAL ;
1601
- }
1602
- params .dialog_token = (uint8_t )value ;
1628
+ case 'f' :
1629
+ if (!parse_number (sh , & value , state -> optarg , NULL , 0 ,
1630
+ (WIFI_MAX_TWT_FLOWS - 1 ))) {
1631
+ return - EINVAL ;
1632
+ }
1633
+ params -> flow_id = (uint8_t )value ;
1634
+ break ;
1603
1635
1604
- if (!parse_number (sh , & value , argv [idx ++ ], NULL , 0 , (WIFI_MAX_TWT_FLOWS - 1 ))) {
1605
- return - EINVAL ;
1606
- }
1607
- params .flow_id = (uint8_t )value ;
1636
+ case 'r' :
1637
+ if (!parse_number (sh , & value , state -> optarg , NULL , 0 , 1 )) {
1638
+ return - EINVAL ;
1639
+ }
1640
+ params -> setup .responder = (bool )value ;
1641
+ break ;
1608
1642
1609
- if (!parse_number (sh , & value , argv [idx ++ ], NULL , 0 , 1 )) {
1610
- return - EINVAL ;
1611
- }
1612
- params .setup .responder = (bool )value ;
1643
+ case 'T' :
1644
+ if (!parse_number (sh , & value , state -> optarg , NULL , 0 , 1 )) {
1645
+ return - EINVAL ;
1646
+ }
1647
+ params -> setup .trigger = (bool )value ;
1648
+ break ;
1613
1649
1614
- if (!parse_number (sh , & value , argv [idx ++ ], NULL , 0 , 1 )) {
1615
- return - EINVAL ;
1616
- }
1617
- params .setup .trigger = (bool )value ;
1650
+ case 'I' :
1651
+ if (!parse_number (sh , & value , state -> optarg , NULL , 0 , 1 )) {
1652
+ return - EINVAL ;
1653
+ }
1654
+ params -> setup .implicit = (bool )value ;
1655
+ break ;
1618
1656
1619
- if (!parse_number (sh , & value , argv [idx ++ ], NULL , 0 , 1 )) {
1620
- return - EINVAL ;
1621
- }
1622
- params .setup .implicit = (bool )value ;
1657
+ case 'a' :
1658
+ if (!parse_number (sh , & value , state -> optarg , NULL , 0 , 1 )) {
1659
+ return - EINVAL ;
1660
+ }
1661
+ params -> setup .announce = (bool )value ;
1662
+ break ;
1623
1663
1624
- if (!parse_number (sh , & value , argv [idx ++ ], NULL , 0 , 1 )) {
1625
- return - EINVAL ;
1626
- }
1627
- params .setup .announce = (bool )value ;
1664
+ case 'w' :
1665
+ if (!parse_number (sh , & value , state -> optarg , NULL , 1 ,
1666
+ WIFI_MAX_TWT_WAKE_INTERVAL_US )) {
1667
+ return - EINVAL ;
1668
+ }
1669
+ params -> setup .twt_wake_interval = (uint32_t )value ;
1670
+ break ;
1628
1671
1629
- if (!parse_number (sh , & value , argv [idx ++ ], NULL , 1 , WIFI_MAX_TWT_WAKE_INTERVAL_US )) {
1630
- return - EINVAL ;
1631
- }
1632
- params .setup .twt_wake_interval = (uint32_t )value ;
1672
+ case 'i' :
1673
+ if (!parse_number (sh , & value , state -> optarg , NULL , 1 ,
1674
+ WIFI_MAX_TWT_INTERVAL_US )) {
1675
+ return - EINVAL ;
1676
+ }
1677
+ params -> setup .twt_interval = (uint64_t )value ;
1678
+ break ;
1633
1679
1634
- if (!parse_number (sh , & value , argv [idx ++ ], NULL , 1 , WIFI_MAX_TWT_INTERVAL_US )) {
1635
- return - EINVAL ;
1680
+ case 'D' :
1681
+ if (!parse_number (sh , & value , state -> optarg , NULL , 0 ,
1682
+ WIFI_MAX_TWT_WAKE_AHEAD_DURATION_US )) {
1683
+ return - EINVAL ;
1684
+ }
1685
+ params -> setup .twt_wake_ahead_duration = (uint32_t )value ;
1686
+ break ;
1687
+
1688
+ case 'h' :
1689
+ return - ENOEXEC ;
1690
+ }
1636
1691
}
1637
- params .setup .twt_interval = (uint64_t )value ;
1638
1692
1639
- if (!parse_number (sh , & value , argv [idx ++ ], NULL , 0 , WIFI_MAX_TWT_WAKE_AHEAD_DURATION_US )) {
1640
- return - EINVAL ;
1693
+ return 0 ;
1694
+ }
1695
+
1696
+ static int cmd_wifi_twt_setup (const struct shell * sh , size_t argc ,
1697
+ char * argv [])
1698
+ {
1699
+ struct net_if * iface = net_if_get_wifi_sta ();
1700
+ struct wifi_twt_params params = { 0 };
1701
+
1702
+ context .sh = sh ;
1703
+
1704
+ if (twt_args_to_params (sh , argc , argv , & params )) {
1705
+ shell_help (sh );
1706
+ return - ENOEXEC ;
1641
1707
}
1642
- params .setup .twt_wake_ahead_duration = (uint32_t )value ;
1643
1708
1644
1709
if (net_mgmt (NET_REQUEST_WIFI_TWT , iface , & params , sizeof (params ))) {
1645
1710
PR_WARNING ("%s with %s failed. reason : %s\n" ,
@@ -3265,13 +3330,20 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops,
3265
3330
cmd_wifi_twt_setup_quick ,
3266
3331
3 , 0 ),
3267
3332
SHELL_CMD_ARG (setup , NULL , " Start a TWT flow:\n"
3268
- "<negotiation_type, 0: Individual, 1: Broadcast, 2: Wake TBTT>\n"
3269
- "<setup_cmd: 0: Request, 1: Suggest, 2: Demand>\n"
3270
- "<dialog_token: 1-255> <flow_id: 0-7> <responder: 0/1> <trigger: 0/1> <implicit:0/1> "
3271
- "<announce: 0/1> <twt_wake_interval: 1-262144us> <twt_interval: 1us-2^31us>.\n"
3272
- "<twt_wake_ahead_duration>: 0us-2^31us>\n" ,
3333
+ "<-n --negotiation-type>: 0: Individual, 1: Broadcast, 2: Wake TBTT\n"
3334
+ "<-c --setup-cmd>: 0: Request, 1: Suggest, 2: Demand\n"
3335
+ "<-t --dialog-token>: 1-255\n"
3336
+ "<-f --flow-id>: 0-7\n"
3337
+ "<-r --responder>: 0/1\n"
3338
+ "<-T --trigger>: 0/1\n"
3339
+ "<-I --implicit>:0/1\n"
3340
+ "<-a --announce>: 0/1\n"
3341
+ "<-w --wake-interval>: 1-262144us\n"
3342
+ "<-i --interval>: 1us-2^31us\n"
3343
+ "<-D --wake-ahead-duration>: 0us-2^31us\n"
3344
+ "[-h, --help]: Print out command usage.\n" ,
3273
3345
cmd_wifi_twt_setup ,
3274
- 12 , 0 ),
3346
+ 23 , 1 ),
3275
3347
SHELL_CMD_ARG (teardown , NULL , " Teardown a TWT flow:\n"
3276
3348
"<negotiation_type, 0: Individual, 1: Broadcast, 2: Wake TBTT>\n"
3277
3349
"<setup_cmd: 0: Request, 1: Suggest, 2: Demand>\n"
0 commit comments