@@ -75,6 +75,7 @@ void sleep_ms(int milliseconds)
7575#define POWER_OFF 0
7676#define POWER_ON 1
7777#define POWER_CYCLE 2
78+ #define POWER_TOGGLE 3
7879
7980#define MAX_HUB_CHAIN 8 /* Per USB 3.0 spec max hub chain is 7 */
8081
@@ -248,7 +249,7 @@ static int print_usage()
248249 "Without options, show status for all smart hubs.\n"
249250 "\n"
250251 "Options [defaults in brackets]:\n"
251- "--action, -a - action to off/on/cycle (0/1/2) for affected ports.\n"
252+ "--action, -a - action to off/on/cycle/toggle (0/1/2/3 ) for affected ports.\n"
252253 "--ports, -p - ports to operate on [all hub ports].\n"
253254 "--location, -l - limit hub by location [all smart hubs].\n"
254255 "--level -L - limit hub by location level (e.g. a-b.c is level 3).\n"
@@ -942,6 +943,9 @@ int main(int argc, char *argv[])
942943 if (!strcasecmp (optarg , "cycle" ) || !strcasecmp (optarg , "2" )) {
943944 opt_action = POWER_CYCLE ;
944945 }
946+ if (!strcasecmp (optarg , "toggle" ) || !strcasecmp (optarg , "3" )) {
947+ opt_action = POWER_TOGGLE ;
948+ }
945949 break ;
946950 case 'd' :
947951 opt_delay = atof (optarg );
@@ -1029,6 +1033,9 @@ int main(int argc, char *argv[])
10291033 continue ;
10301034 if (k == 1 && opt_action == POWER_KEEP )
10311035 continue ;
1036+ // if toggle requested, do it only once when `k == 0`
1037+ if (k == 1 && opt_action == POWER_TOGGLE )
1038+ continue ;
10321039 int i ;
10331040 for (i = 0 ; i < hub_count ; i ++ ) {
10341041 if (hubs [i ].actionable == 0 )
@@ -1053,7 +1060,10 @@ int main(int argc, char *argv[])
10531060 int port_status = get_port_status (devh , port );
10541061 int power_mask = hubs [i ].super_speed ? USB_SS_PORT_STAT_POWER
10551062 : USB_PORT_STAT_POWER ;
1056- if (k == 0 && !(port_status & power_mask ))
1063+ if (opt_action == POWER_TOGGLE ) {
1064+ request = (port_status & power_mask ) ? LIBUSB_REQUEST_CLEAR_FEATURE : LIBUSB_REQUEST_SET_FEATURE ;
1065+ }
1066+ if (k == 0 && !(port_status & power_mask ) && (opt_action != POWER_TOGGLE ))
10571067 continue ;
10581068 if (k == 1 && (port_status & power_mask ))
10591069 continue ;
0 commit comments