@@ -75,6 +75,7 @@ void sleep_ms(int milliseconds)
75
75
#define POWER_OFF 0
76
76
#define POWER_ON 1
77
77
#define POWER_CYCLE 2
78
+ #define POWER_TOGGLE 3
78
79
79
80
#define MAX_HUB_CHAIN 8 /* Per USB 3.0 spec max hub chain is 7 */
80
81
@@ -248,7 +249,7 @@ static int print_usage()
248
249
"Without options, show status for all smart hubs.\n"
249
250
"\n"
250
251
"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"
252
253
"--ports, -p - ports to operate on [all hub ports].\n"
253
254
"--location, -l - limit hub by location [all smart hubs].\n"
254
255
"--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[])
942
943
if (!strcasecmp (optarg , "cycle" ) || !strcasecmp (optarg , "2" )) {
943
944
opt_action = POWER_CYCLE ;
944
945
}
946
+ if (!strcasecmp (optarg , "toggle" ) || !strcasecmp (optarg , "3" )) {
947
+ opt_action = POWER_TOGGLE ;
948
+ }
945
949
break ;
946
950
case 'd' :
947
951
opt_delay = atof (optarg );
@@ -1029,6 +1033,9 @@ int main(int argc, char *argv[])
1029
1033
continue ;
1030
1034
if (k == 1 && opt_action == POWER_KEEP )
1031
1035
continue ;
1036
+ // if toggle requested, do it only once when `k == 0`
1037
+ if (k == 1 && opt_action == POWER_TOGGLE )
1038
+ continue ;
1032
1039
int i ;
1033
1040
for (i = 0 ; i < hub_count ; i ++ ) {
1034
1041
if (hubs [i ].actionable == 0 )
@@ -1053,7 +1060,10 @@ int main(int argc, char *argv[])
1053
1060
int port_status = get_port_status (devh , port );
1054
1061
int power_mask = hubs [i ].super_speed ? USB_SS_PORT_STAT_POWER
1055
1062
: 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 ))
1057
1067
continue ;
1058
1068
if (k == 1 && (port_status & power_mask ))
1059
1069
continue ;
0 commit comments