Skip to content

Commit fbe812b

Browse files
committed
Add an option to search/limit hub by description
Adding new option to limit hub by description. Existing -s option limits by attached device description, and new feature -H limits by hub instead. Thanks to @pendragonsound for submitting patch! Closes #611.
1 parent d963085 commit fbe812b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

uhubctl.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ static int hub_phys_count = 0;
217217
/* default options */
218218
static char opt_vendor[16] = "";
219219
static char opt_search[64] = ""; /* Search by attached device description */
220+
static char opt_searchhub[64] = ""; /* Search by hub description */
220221
static char opt_location[32] = ""; /* Hub location a-b.c.d */
221222
static int opt_level = 0; /* Hub location level (e.g., a-b is level 2, a-b.c is level 3)*/
222223
static int opt_ports = ALL_HUB_PORTS; /* Bitmask of ports to operate on */
@@ -240,7 +241,7 @@ static int is_rpi_4b = 0;
240241
static int is_rpi_5 = 0;
241242

242243
static const char short_options[] =
243-
"l:L:n:a:p:d:r:w:s:hvefRN"
244+
"l:L:n:a:p:d:r:w:s:H:hvefRN"
244245
#if defined(__linux__)
245246
"S"
246247
#if (LIBUSB_API_VERSION >= 0x01000107) /* 1.0.23 */
@@ -253,6 +254,7 @@ static const struct option long_options[] = {
253254
{ "location", required_argument, NULL, 'l' },
254255
{ "vendor", required_argument, NULL, 'n' },
255256
{ "search", required_argument, NULL, 's' },
257+
{ "searchhub",required_argument, NULL, 'H' },
256258
{ "level", required_argument, NULL, 'L' },
257259
{ "ports", required_argument, NULL, 'p' },
258260
{ "action", required_argument, NULL, 'a' },
@@ -288,6 +290,7 @@ static int print_usage(void)
288290
"--location, -l - limit hub by location [all smart hubs].\n"
289291
"--level -L - limit hub by location level (e.g. a-b.c is level 3).\n"
290292
"--vendor, -n - limit hub by vendor id [%s] (partial ok).\n"
293+
"--searchhub,-H - limit hub by description.\n"
291294
"--search, -s - limit hub by attached device description.\n"
292295
"--delay, -d - delay for cycle/flash action [%g sec].\n"
293296
"--repeat, -r - repeat power off count [%d] (some devices need it to turn off).\n"
@@ -963,6 +966,12 @@ static int usb_find_hubs(void)
963966
}
964967
}
965968
}
969+
if (strlen(opt_searchhub) > 0) {
970+
/* Search by hub description */
971+
if (strstr(info.ds.description, opt_searchhub) == NULL) {
972+
info.actionable = 0;
973+
}
974+
}
966975
if (strlen(opt_location) > 0) {
967976
if (strcasecmp(opt_location, info.location)) {
968977
info.actionable = 0;
@@ -1149,6 +1158,9 @@ int main(int argc, char *argv[])
11491158
case 's':
11501159
snprintf(opt_search, sizeof(opt_search), "%s", optarg);
11511160
break;
1161+
case 'H':
1162+
snprintf(opt_searchhub, sizeof(opt_searchhub), "%s", optarg);
1163+
break;
11521164
case 'p':
11531165
if (!strcasecmp(optarg, "all")) { /* all ports is the default */
11541166
break;

0 commit comments

Comments
 (0)