> Date: Tue, 3 Jul 2018 09:35:09 +0200
> From: Martin Pieuchot <[email protected]>
> 
> Here's the next iteration on my work on usbdevs(8).  It is now printing
> the USB IDs by default with the expected Vendor:Device order.
> 
> Additional information is printed on a second line.  Port status are
> still missing but are coming in the next diff.
> 
> 
> Examples:
> 
>   $ ./obj/usbdevs
>   Controller /dev/usb0:
>   addr 01: 8086:0000 Intel, xHCI root hub
>   addr 02: 04f2:b45d Chicony Electronics Co.,Ltd., Integrated Camera
> 
> 
>   $ ./obj/usbdevs -v
>   Controller /dev/usb0:
>   addr 01: 8086:0000 Intel, xHCI root hub
>            super speed, self powered, config 1, rev 1.00
>   addr 02: 04f2:b45d Chicony Electronics Co.,Ltd., Integrated Camera
>            high speed, power 500 mA, config 1, rev 0.29, iSerialNumber 0x0001
> 
>   $ ./obj/usbdevs -vv
>   Controller /dev/usb0:
>   addr 01: 8086:0000 Intel, xHCI root hub
>            super speed, self powered, config 1, rev 1.00
>            port 01: disabled
>            port 02: disabled
>            port 03: disabled
>            port 04: disabled
>            port 05: disabled
>            port 06: disabled
>            port 07: disabled
>            port 08: addr 02
>            port 09: disabled
>            port 10: disabled
>            port 11: disabled
>            port 12: disabled
>            port 13: disabled
>            port 14: disabled
>            port 15: disabled
>   addr 02: 04f2:b45d Chicony Electronics Co.,Ltd., Integrated Camera
>            high speed, power 500 mA, config 1, rev 0.29, iSerialNumber 0x0001
> 
> 
> Ok?

ok kettenis@

> Index: usbdevs.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/usbdevs/usbdevs.c,v
> retrieving revision 1.26
> diff -u -p -r1.26 usbdevs.c
> --- usbdevs.c 1 Jul 2018 08:51:50 -0000       1.26
> +++ usbdevs.c 3 Jul 2018 07:33:31 -0000
> @@ -46,13 +46,15 @@
>  #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
>  #endif
>  
> +#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
> +
>  #define USBDEV "/dev/usb"
>  
>  int verbose = 0;
>  int showdevs = 0;
>  
>  void usage(void);
> -void usbdev(int f, int a, int rec);
> +void usbdev(int f, uint8_t, int rec);
>  void usbdump(int f);
>  void dumpone(char *name, int f, int addr);
>  int main(int, char **);
> @@ -70,22 +72,25 @@ char done[USB_MAX_DEVICES];
>  int indent;
>  
>  void
> -usbdev(int f, int a, int rec)
> +usbdev(int f, uint8_t addr, int rec)
>  {
>       struct usb_device_info di;
> -     int e, p, i;
> +     int e, p, i, s, nports;
>  
> -     di.udi_addr = a;
> +     di.udi_addr = addr;
>       e = ioctl(f, USB_DEVICEINFO, &di);
>       if (e) {
>               if (errno != ENXIO)
> -                     printf("addr %d: I/O error\n", a);
> +                     printf("addr %d: I/O error\n", addr);
>               return;
>       }
>  
> -     printf("addr %d: ", a);
> -     done[a] = 1;
> +     printf("addr %02u: ", addr);
> +     done[addr] = 1;
> +     printf("%04x:%04x %s, %s", di.udi_vendorNo, di.udi_productNo,
> +         di.udi_vendor, di.udi_product);
>       if (verbose) {
> +             printf("\n\t ");
>               switch (di.udi_speed) {
>               case USB_SPEED_LOW:
>                       printf("low speed, ");
> @@ -111,15 +116,11 @@ usbdev(int f, int a, int rec)
>                       printf("config %d, ", di.udi_config);
>               else
>                       printf("unconfigured, ");
> -     }
> -     if (verbose) {
> -             printf("%s(0x%04x), %s(0x%04x), rev %s",
> -                 di.udi_product, di.udi_productNo,
> -                 di.udi_vendor, di.udi_vendorNo, di.udi_release);
> +
> +             printf("rev %s", di.udi_release);
>               if (strlen(di.udi_serial))
>                       printf(", iSerialNumber %s", di.udi_serial);
> -     } else
> -             printf("%s, %s", di.udi_product, di.udi_vendor);
> +     }
>       printf("\n");
>       if (showdevs) {
>               for (i = 0; i < USB_MAX_DEVNAMES; i++)
> @@ -129,29 +130,29 @@ usbdev(int f, int a, int rec)
>       }
>       if (!rec)
>               return;
> -     for (p = 0; p < di.udi_nports && p < nitems(di.udi_ports); p++) {
> -             int s = di.udi_ports[p];
>  
> -             if (s >= USB_MAX_DEVICES) {
> -                     if (verbose > 1) {
> -                             printf("%*sport %d %s\n", indent+1, "", p+1,
> +     nports = MINIMUM(di.udi_nports, nitems(di.udi_ports));
> +     if (verbose > 1) {
> +             for (p = 0; p < nports; p++) {
> +                     s = di.udi_ports[p];
> +                     printf("\t port %02u:", p+1);
> +                     if (s < USB_MAX_DEVICES)
> +                             printf(" addr %02u\n", s);
> +                     else {
> +                             printf(" %s\n",
>                                   s == USB_PORT_ENABLED ? "enabled" :
>                                   s == USB_PORT_SUSPENDED ? "suspended" :
>                                   s == USB_PORT_POWERED ? "powered" :
>                                   s == USB_PORT_DISABLED ? "disabled" :
>                                   "???");
>                       }
> -                     continue;
>               }
> -             indent++;
> -             printf("%*s", indent, "");
> -             if (verbose > 1)
> -                     printf("port %d ", p+1);
> -             if (s == 0)
> -                     printf("addr 0 should never happen!\n");
> -             else
> +     }
> +
> +     for (p = 0; p < nports ; p++) {
> +             s = di.udi_ports[p];
> +             if (s < USB_MAX_DEVICES)
>                       usbdev(f, s, 1);
> -             indent--;
>       }
>  }
>  
> 
> 

Reply via email to