diff --git a/usr.sbin/usbconfig/usbconfig.8 b/usr.sbin/usbconfig/usbconfig.8 --- a/usr.sbin/usbconfig/usbconfig.8 +++ b/usr.sbin/usbconfig/usbconfig.8 @@ -33,9 +33,11 @@ .Nm .Op Fl u Ar unit .Op Fl a Ar addr +.Op Fl i Ar interface_index .Op cmds... .Nm -.Op Oo Fl d Oc Ar [ugen]. +.Fl d Ar [[/dev/]ugen]. +.Op Fl i Ar interface_index .Op cmds... .Sh DESCRIPTION The @@ -49,9 +51,11 @@ .It Fl a Ar addr Limit device range to the given USB device index. Should only be used in conjunction with the unit argument. -.It Fl d Ar [ugen]. +.It Fl d Ar [[/dev/]ugen]. Limit device range to USB devices connected to the given unit and address. -The unit and address coordinates may be prefixed by the lowercased word "ugen". +The unit and address coordinates may be prefixed by the lowercased word "ugen", +or the full path name +.Pa /dev/ugen . .It Fl i Ar interface_index Specify interface index as indicated by the command description. If this argument is not specified a value of zero will be used for the interface index. @@ -81,6 +85,9 @@ .Cm dump_curr_config_desc output. Usually there is no need to adjust this setting. +This command uses the +.Fl i Ar interface_index +option. .It Cm set_template Ar template Set the global USB device side template. See @@ -126,6 +133,9 @@ currently attached to the device. .It Cm detach_kernel_driver Detach kernel driver for the selected interface and USB device. +This command uses the +.Fl i Ar interface_index +option. .It Cm suspend Force the device to suspend. .It Cm resume diff --git a/usr.sbin/usbconfig/usbconfig.c b/usr.sbin/usbconfig/usbconfig.c --- a/usr.sbin/usbconfig/usbconfig.c +++ b/usr.sbin/usbconfig/usbconfig.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -64,7 +65,6 @@ uint8_t got_list:1; uint8_t got_bus:1; uint8_t got_addr:1; - uint8_t got_iface:1; uint8_t got_set_config:1; uint8_t got_set_alt:1; uint8_t got_set_template:1; @@ -100,10 +100,6 @@ }; enum { - T_UNIT, - T_ADDR, - T_UGEN, - T_IFACE, T_SET_CONFIG, T_SET_ALT, T_SET_TEMPLATE, @@ -136,10 +132,6 @@ static struct options options; static const struct token token[] = { - {"-u", T_UNIT, 1}, - {"-a", T_ADDR, 1}, - {"-d", T_UGEN, 1}, - {"-i", T_IFACE, 1}, {"set_config", T_SET_CONFIG, 1}, {"set_alt", T_SET_ALT, 1}, {"set_template", T_SET_TEMPLATE, 1}, @@ -279,8 +271,8 @@ { fprintf(stderr, "" "usbconfig - configure the USB subsystem" "\n" - "usage: usbconfig -u -a -i [cmds...]" "\n" - "usage: usbconfig -d [ugen]. -i [cmds...]" "\n" + "usage: usbconfig [-u ] [-a ] [-i ] [cmds...]" "\n" + "usage: usbconfig -d [ugen]. [-i ] [cmds...]" "\n" "commands:" "\n" " set_config " "\n" " set_alt " "\n" @@ -563,6 +555,7 @@ int addr; int n; int t; + int ch; if (argc < 1) { usage(); @@ -571,7 +564,52 @@ if (pbe == NULL) err(1, "could not access USB backend\n"); - for (n = 1; n != argc; n++) { + while ((ch = getopt(argc, argv, "a:d:i:u:")) != -1) { + switch (ch) { + case 'a': + opt->addr = num_id(optarg, "addr"); + opt->got_addr = 1; + break; + + case 'd': + if (strncmp(optarg, "ugen", strlen("ugen")) == 0) { + ptr = optarg + strlen("ugen"); + } else if (strncmp(optarg, "/dev/ugen", + strlen("/dev/ugen")) == 0) { + ptr = optarg + strlen("/dev/ugen"); + } else { + ptr = optarg; + } + if ((sscanf(ptr, "%d.%d", + &unit, &addr) != 2) || + (unit < 0) || (unit > 65535) || + (addr < 0) || (addr > 65535)) { + errx(1, "cannot " + "parse '%s'", optarg); + } + opt->bus = unit; + opt->addr = addr; + opt->got_bus = 1; + opt->got_addr = 1; + break; + + case 'i': + opt->iface = num_id(optarg, "iface"); + break; + + case 'u': + opt->bus = num_id(optarg, "busnum"); + opt->got_bus = 1; + break; + + default: + usage(); + } + } + argc -= optind; + argv += optind; + + for (n = 0; n != argc; n++) { /* get number of additional options */ t = (argc - n - 1); @@ -654,52 +692,6 @@ opt->got_show_iface_driver = 1; break; - case T_UGEN: - if (opt->got_any) { - /* allow multiple commands on the same line */ - flush_command(pbe, opt); - } - ptr = argv[n + 1]; - - if ((ptr[0] == 'u') && - (ptr[1] == 'g') && - (ptr[2] == 'e') && - (ptr[3] == 'n')) - ptr += 4; - - if ((sscanf(ptr, "%d.%d", - &unit, &addr) != 2) || - (unit < 0) || (unit > 65535) || - (addr < 0) || (addr > 65535)) { - errx(1, "cannot " - "parse '%s'", argv[n + 1]); - } - opt->bus = unit; - opt->addr = addr; - opt->got_bus = 1; - opt->got_addr = 1; - n++; - break; - - case T_UNIT: - if (opt->got_any) { - /* allow multiple commands on the same line */ - flush_command(pbe, opt); - } - opt->bus = num_id(argv[n + 1], "busnum"); - opt->got_bus = 1; - n++; - break; - case T_ADDR: - opt->addr = num_id(argv[n + 1], "addr"); - opt->got_addr = 1; - n++; - break; - case T_IFACE: - opt->iface = num_id(argv[n + 1], "iface"); - opt->got_iface = 1; - n++; - break; case T_SET_CONFIG: if (opt->got_set_config) duplicate_option(argv[n]);