Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/dev/usb/usb_subr.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/dev/usb/usb_subr.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.224 retrieving revision 1.224.2.2 diff -u -p -r1.224 -r1.224.2.2 --- src/sys/dev/usb/usb_subr.c 2018/04/30 05:04:34 1.224 +++ src/sys/dev/usb/usb_subr.c 2020/04/13 08:04:50 1.224.2.2 @@ -1,4 +1,4 @@ -/* $NetBSD: usb_subr.c,v 1.224 2018/04/30 05:04:34 mlelstv Exp $ */ +/* $NetBSD: usb_subr.c,v 1.224.2.2 2020/04/13 08:04:50 martin Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */ /* @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.224 2018/04/30 05:04:34 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.224.2.2 2020/04/13 08:04:50 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -66,10 +66,7 @@ __KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v #define DPRINTF(FMT,A,B,C,D) USBHIST_LOG(usbdebug,FMT,A,B,C,D) #define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(usbdebug,N,FMT,A,B,C,D) -Static usbd_status usbd_set_config(struct usbd_device *, int); Static void usbd_devinfo(struct usbd_device *, int, char *, size_t); -Static void usbd_devinfo_vp(struct usbd_device *, char *, size_t, char *, size_t, - int, int); Static int usbd_getnewaddr(struct usbd_bus *); Static int usbd_print(void *, const char *); Static int usbd_ifprint(void *, const char *); @@ -115,42 +112,6 @@ usbd_errstr(usbd_status err) } } -usbd_status -usbd_get_string_desc(struct usbd_device *dev, int sindex, int langid, - usb_string_descriptor_t *sdesc, int *sizep) -{ - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); - usb_device_request_t req; - usbd_status err; - int actlen; - - req.bmRequestType = UT_READ_DEVICE; - req.bRequest = UR_GET_DESCRIPTOR; - USETW2(req.wValue, UDESC_STRING, sindex); - USETW(req.wIndex, langid); - USETW(req.wLength, 2); /* only size byte first */ - err = usbd_do_request_flags(dev, &req, sdesc, USBD_SHORT_XFER_OK, - &actlen, USBD_DEFAULT_TIMEOUT); - if (err) - return err; - - if (actlen < 2) - return USBD_SHORT_XFER; - - USETW(req.wLength, sdesc->bLength); /* the whole string */ - err = usbd_do_request_flags(dev, &req, sdesc, USBD_SHORT_XFER_OK, - &actlen, USBD_DEFAULT_TIMEOUT); - if (err) - return err; - - if (actlen != sdesc->bLength) { - DPRINTF("expected %jd, got %jd", sdesc->bLength, actlen, 0, 0); - } - - *sizep = actlen; - return USBD_NORMAL_COMPLETION; -} - static void usbd_trim_spaces(char *p) { @@ -194,7 +155,7 @@ usbd_get_device_strings(struct usbd_devi } -Static void +void usbd_devinfo_vp(struct usbd_device *dev, char *v, size_t vl, char *p, size_t pl, int usedev, int useencoded) { @@ -247,7 +208,7 @@ usbd_devinfo(struct usbd_device *dev, in usbd_devinfo_vp(dev, vendor, USB_MAX_ENCODED_STRING_LEN, product, USB_MAX_ENCODED_STRING_LEN, 0, 1); - cp += snprintf(cp, ep - cp, "%s (%#04x) %s (%#04x)", vendor, + cp += snprintf(cp, ep - cp, "%s (0x%04x) %s (0x%04x)", vendor, UGETW(udd->idVendor), product, UGETW(udd->idProduct)); if (showclass) cp += snprintf(cp, ep - cp, ", class %d/%d", @@ -313,7 +274,7 @@ usbd_delay_ms(struct usbd_device *dev, u usbd_status usbd_reset_port(struct usbd_device *dev, int port, usb_port_status_t *ps) { - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); + USBHIST_FUNC(); USBHIST_CALLARGS(usbdebug, "port %jd", port, 0, 0, 0); usb_device_request_t req; usbd_status err; int n; @@ -356,32 +317,46 @@ usbd_reset_port(struct usbd_device *dev, usb_interface_descriptor_t * usbd_find_idesc(usb_config_descriptor_t *cd, int ifaceidx, int altidx) { - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); + USBHIST_FUNC(); + USBHIST_CALLARGS(usbdebug, "iface/alt idx %jd/%jd", + ifaceidx, altidx, 0, 0); char *p = (char *)cd; char *end = p + UGETW(cd->wTotalLength); - usb_interface_descriptor_t *d; + usb_descriptor_t *desc; + usb_interface_descriptor_t *idesc; int curidx, lastidx, curaidx = 0; for (curidx = lastidx = -1; p < end; ) { - d = (usb_interface_descriptor_t *)p; + desc = (usb_descriptor_t *)p; + DPRINTFN(4, "idx=%jd(%jd) altidx=%jd(%jd)", ifaceidx, curidx, altidx, curaidx); - DPRINTFN(4, "len=%jd type=%jd", d->bLength, d->bDescriptorType, - 0, 0); - if (d->bLength == 0) /* bad descriptor */ + DPRINTFN(4, "len=%jd type=%jd", desc->bLength, + desc->bDescriptorType, 0, 0); + + if (desc->bLength < USB_DESCRIPTOR_SIZE) + break; + p += desc->bLength; + if (p > end) break; - p += d->bLength; - if (p <= end && d->bDescriptorType == UDESC_INTERFACE) { - if (d->bInterfaceNumber != lastidx) { - lastidx = d->bInterfaceNumber; - curidx++; - curaidx = 0; - } else - curaidx++; - if (ifaceidx == curidx && altidx == curaidx) - return d; + + if (desc->bDescriptorType != UDESC_INTERFACE) + continue; + idesc = (usb_interface_descriptor_t *)desc; + if (idesc->bLength < USB_INTERFACE_DESCRIPTOR_SIZE) + break; + + if (idesc->bInterfaceNumber != lastidx) { + lastidx = idesc->bInterfaceNumber; + curidx++; + curaidx = 0; + } else { + curaidx++; } + if (ifaceidx == curidx && altidx == curaidx) + return idesc; } + return NULL; } @@ -391,29 +366,39 @@ usbd_find_edesc(usb_config_descriptor_t { char *p = (char *)cd; char *end = p + UGETW(cd->wTotalLength); - usb_interface_descriptor_t *d; - usb_endpoint_descriptor_t *e; + usb_interface_descriptor_t *idesc; + usb_endpoint_descriptor_t *edesc; + usb_descriptor_t *desc; int curidx; - d = usbd_find_idesc(cd, ifaceidx, altidx); - if (d == NULL) + idesc = usbd_find_idesc(cd, ifaceidx, altidx); + if (idesc == NULL) return NULL; - if (endptidx >= d->bNumEndpoints) /* quick exit */ + if (endptidx >= idesc->bNumEndpoints) /* quick exit */ return NULL; curidx = -1; - for (p = (char *)d + d->bLength; p < end; ) { - e = (usb_endpoint_descriptor_t *)p; - if (e->bLength == 0) /* bad descriptor */ + for (p = (char *)idesc + idesc->bLength; p < end; ) { + desc = (usb_descriptor_t *)p; + + if (desc->bLength < USB_DESCRIPTOR_SIZE) break; - p += e->bLength; - if (p <= end && e->bDescriptorType == UDESC_INTERFACE) - return NULL; - if (p <= end && e->bDescriptorType == UDESC_ENDPOINT) { - curidx++; - if (curidx == endptidx) - return e; - } + p += desc->bLength; + if (p > end) + break; + + if (desc->bDescriptorType == UDESC_INTERFACE) + break; + if (desc->bDescriptorType != UDESC_ENDPOINT) + continue; + + edesc = (usb_endpoint_descriptor_t *)desc; + if (edesc->bLength < USB_ENDPOINT_DESCRIPTOR_SIZE) + break; + + curidx++; + if (curidx == endptidx) + return edesc; } return NULL; } @@ -421,13 +406,14 @@ usbd_find_edesc(usb_config_descriptor_t usbd_status usbd_fill_iface_data(struct usbd_device *dev, int ifaceidx, int altidx) { - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); + USBHIST_FUNC(); + USBHIST_CALLARGS(usbdebug, "ifaceidx=%jd altidx=%jd", + ifaceidx, altidx, 0, 0); struct usbd_interface *ifc = &dev->ud_ifaces[ifaceidx]; usb_interface_descriptor_t *idesc; char *p, *end; int endpt, nendpt; - DPRINTFN(4, "ifaceidx=%jd altidx=%jd", ifaceidx, altidx, 0, 0); idesc = usbd_find_idesc(dev->ud_cdesc, ifaceidx, altidx); if (idesc == NULL) return USBD_INVAL; @@ -452,7 +438,8 @@ usbd_fill_iface_data(struct usbd_device DPRINTFN(10, "p=%#jx end=%#jx len=%jd type=%jd", (uintptr_t)p, (uintptr_t)end, ed->bLength, ed->bDescriptorType); - if (p + ed->bLength <= end && ed->bLength != 0 && + if (p + ed->bLength <= end && + ed->bLength >= USB_ENDPOINT_DESCRIPTOR_SIZE && ed->bDescriptorType == UDESC_ENDPOINT) goto found; if (ed->bLength == 0 || @@ -516,26 +503,10 @@ usbd_free_iface_data(struct usbd_device } } -Static usbd_status -usbd_set_config(struct usbd_device *dev, int conf) -{ - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); - usb_device_request_t req; - - DPRINTFN(5, "dev %#jx conf %jd", (uintptr_t)dev, conf, 0, 0); - - req.bmRequestType = UT_WRITE_DEVICE; - req.bRequest = UR_SET_CONFIG; - USETW(req.wValue, conf); - USETW(req.wIndex, 0); - USETW(req.wLength, 0); - return usbd_do_request(dev, &req, 0); -} - usbd_status usbd_set_config_no(struct usbd_device *dev, int no, int msg) { - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); + USBHIST_FUNC(); USBHIST_CALLARGS(usbdebug, "%jd", no, 0, 0, 0); usb_config_descriptor_t cd; usbd_status err; int index; @@ -543,7 +514,6 @@ usbd_set_config_no(struct usbd_device *d if (no == USB_UNCONFIG_NO) return usbd_set_config_index(dev, USB_UNCONFIG_INDEX, msg); - DPRINTFN(5, "%jd", no, 0, 0, 0); /* Figure out what config index to use. */ for (index = 0; index < dev->ud_ddesc.bNumConfigurations; index++) { err = usbd_get_config_desc(dev, index, &cd); @@ -558,13 +528,14 @@ usbd_set_config_no(struct usbd_device *d usbd_status usbd_set_config_index(struct usbd_device *dev, int index, int msg) { - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); + USBHIST_FUNC(); + USBHIST_CALLARGS(usbdebug, "dev=%#jx index=%jd", + (uintptr_t)dev, index, 0, 0); usb_config_descriptor_t cd, *cdp; usb_bos_descriptor_t *bdp = NULL; usbd_status err; int i, ifcidx, nifc, len, selfpowered, power; - DPRINTFN(5, "dev=%#jx index=%jd", (uintptr_t)dev, index, 0, 0); if (index >= dev->ud_ddesc.bNumConfigurations && index != USB_UNCONFIG_INDEX) { @@ -609,7 +580,7 @@ usbd_set_config_index(struct usbd_device return err; } len = UGETW(cd.wTotalLength); - if (len == 0) { + if (len < USB_CONFIG_DESCRIPTOR_SIZE) { DPRINTF("empty short descriptor", 0, 0, 0, 0); return USBD_INVAL; } @@ -631,6 +602,11 @@ usbd_set_config_index(struct usbd_device err = USBD_INVAL; goto bad; } + if (UGETW(cdp->wTotalLength) != UGETW(cd.wTotalLength)) { + DPRINTF("bad len %jd", UGETW(cdp->wTotalLength), 0, 0, 0); + err = USBD_INVAL; + goto bad; + } if (USB_IS_SS(dev->ud_speed)) { usb_bos_descriptor_t bd; @@ -639,7 +615,7 @@ usbd_set_config_index(struct usbd_device err = usbd_get_bos_desc(dev, index, &bd); if (!err) { int blen = UGETW(bd.wTotalLength); - if (blen == 0) { + if (blen < USB_BOS_DESCRIPTOR_SIZE) { DPRINTF("empty bos descriptor", 0, 0, 0, 0); err = USBD_INVAL; goto bad; @@ -654,7 +630,8 @@ usbd_set_config_index(struct usbd_device break; usbd_delay_ms(dev, 200); } - if (err || bdp->bDescriptorType != UDESC_BOS) { + if (err || bdp->bDescriptorType != UDESC_BOS || + UGETW(bdp->wTotalLength) != UGETW(bd.wTotalLength)) { DPRINTF("error %jd or bad desc %jd", err, bdp->bDescriptorType, 0, 0); kmem_free(bdp, blen); @@ -681,7 +658,7 @@ usbd_set_config_index(struct usbd_device */ selfpowered = !!(cdp->bmAttributes & UC_SELF_POWERED); - DPRINTF("addr %jd cno=%jd attr=%#02jx, selfpowered=%jd", + DPRINTF("addr %jd cno=%jd attr=0x%02jx, selfpowered=%jd", dev->ud_addr, cdp->bConfigurationValue, cdp->bmAttributes, selfpowered); DPRINTF("max power=%jd", cdp->bMaxPower * 2, 0, 0, 0); @@ -777,13 +754,13 @@ usbd_status usbd_setup_pipe_flags(struct usbd_device *dev, struct usbd_interface *iface, struct usbd_endpoint *ep, int ival, struct usbd_pipe **pipe, uint8_t flags) { - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); + USBHIST_FUNC(); + USBHIST_CALLARGS(usbdebug, "dev=%#jx addr=%jd iface=%#jx ep=%#jx", + (uintptr_t)dev, dev->ud_addr, (uintptr_t)iface, (uintptr_t)ep); struct usbd_pipe *p; usbd_status err; p = kmem_alloc(dev->ud_bus->ub_pipesize, KM_SLEEP); - DPRINTFN(1, "dev=%#jx addr=%jd iface=%#jx ep=%#jx", - (uintptr_t)dev, dev->ud_addr, (uintptr_t)iface, (uintptr_t)ep); DPRINTFN(1, "pipe=%#jx", (uintptr_t)p, 0, 0, 0); p->up_dev = dev; p->up_iface = iface; @@ -796,7 +773,6 @@ usbd_setup_pipe_flags(struct usbd_device p->up_repeat = 0; p->up_interval = ival; p->up_flags = flags; - p->up_serialise = true; SIMPLEQ_INIT(&p->up_queue); err = dev->ud_bus->ub_methods->ubm_open(p); if (err) { @@ -823,7 +799,8 @@ usbd_kill_pipe(struct usbd_pipe *pipe) usbd_lock_pipe(pipe); pipe->up_methods->upm_close(pipe); usbd_unlock_pipe(pipe); - usb_rem_task(pipe->up_dev, &pipe->up_async_task); + usb_rem_task_wait(pipe->up_dev, &pipe->up_async_task, USB_TASKQ_DRIVER, + NULL); pipe->up_endpoint->ue_refcnt--; kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize); } @@ -906,6 +883,7 @@ usbd_attachwholedevice(device_t parent, dlocs[USBDEVIFCF_INTERFACE] = -1; KERNEL_LOCK(1, curlwp); + config_pending_incr(parent); dv = config_found_sm_loc(parent, "usbdevif", dlocs, &uaa, usbd_print, config_stdsubmatch); KERNEL_UNLOCK_ONE(curlwp); @@ -916,6 +894,7 @@ usbd_attachwholedevice(device_t parent, dev->ud_nifaces_claimed = 1; /* XXX */ usbd_serialnumber(dv, dev); } + config_pending_decr(parent); return USBD_NORMAL_COMPLETION; } @@ -1013,13 +992,13 @@ usbd_status usbd_probe_and_attach(device_t parent, struct usbd_device *dev, int port, int addr) { - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); + USBHIST_FUNC(); + USBHIST_CALLARGS(usbdebug, "trying device specific drivers", 0, 0, 0, 0); usb_device_descriptor_t *dd = &dev->ud_ddesc; int confi, nifaces; usbd_status err; /* First try with device specific drivers. */ - DPRINTF("trying device specific drivers", 0, 0, 0, 0); err = usbd_attachwholedevice(parent, dev, port, 0); if (dev->ud_nifaces_claimed || err) return err; @@ -1032,7 +1011,7 @@ usbd_probe_and_attach(device_t parent, s err = usbd_set_config_index(dev, confi, 1); if (err) { DPRINTF("port %jd, set config at addr %jd failed, " - "error=%d", port, addr, err, 0); + "error=%jd", port, addr, err, 0); printf("%s: port %d, set config at addr %d failed\n", device_xname(parent), port, addr); return err; @@ -1122,37 +1101,6 @@ usbd_reattach_device(device_t parent, st } /* - * Get the first 8 bytes of the device descriptor. - * Do as Windows does: try to read 64 bytes -- there are devices which - * recognize the initial descriptor fetch (before the control endpoint's - * MaxPacketSize is known by the host) by exactly this length. - */ -usbd_status -usbd_get_initial_ddesc(struct usbd_device *dev, usb_device_descriptor_t *desc) -{ - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); - usb_device_request_t req; - char buf[64]; - int res, actlen; - - DPRINTFN(5, "dev %#jx", (uintptr_t)dev, 0, 0, 0); - - req.bmRequestType = UT_READ_DEVICE; - req.bRequest = UR_GET_DESCRIPTOR; - USETW2(req.wValue, UDESC_DEVICE, 0); - USETW(req.wIndex, 0); - USETW(req.wLength, 64); - res = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK, - &actlen, USBD_DEFAULT_TIMEOUT); - if (res) - return res; - if (actlen < 8) - return USBD_SHORT_XFER; - memcpy(desc, buf, 8); - return USBD_NORMAL_COMPLETION; -} - -/* * Called when a new device has been put in the powered state, * but not yet in the addressed state. * Get initial descriptor, set the address, get full descriptor, @@ -1162,7 +1110,9 @@ usbd_status usbd_new_device(device_t parent, struct usbd_bus *bus, int depth, int speed, int port, struct usbd_port *up) { - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); + USBHIST_FUNC(); + USBHIST_CALLARGS(usbdebug, "bus=%#jx port=%jd depth=%jd speed=%jd", + (uintptr_t)bus, port, depth, speed); struct usbd_device *dev, *adev; struct usbd_device *hub; usb_device_descriptor_t *dd; @@ -1172,9 +1122,6 @@ usbd_new_device(device_t parent, struct int i; int p; - DPRINTF("bus=%#jx port=%jd depth=%jd speed=%jd", - (uintptr_t)bus, port, depth, speed); - if (bus->ub_methods->ubm_newdev != NULL) return (bus->ub_methods->ubm_newdev)(parent, bus, depth, speed, port, up); @@ -1227,9 +1174,10 @@ usbd_new_device(device_t parent, struct adev = hub, hub = hub->ud_myhub) ; if (hub) { - for (p = 0; p < hub->ud_hub->uh_hubdesc.bNbrPorts; p++) { - if (hub->ud_hub->uh_ports[p].up_dev == adev) { - dev->ud_myhsport = &hub->ud_hub->uh_ports[p]; + for (p = 1; p <= hub->ud_hub->uh_hubdesc.bNbrPorts; p++) { + if (hub->ud_hub->uh_ports[p - 1].up_dev == adev) { + dev->ud_myhsport = + &hub->ud_hub->uh_ports[p - 1]; goto found; } } @@ -1312,6 +1260,7 @@ usbd_new_device(device_t parent, struct /* Re-establish the default pipe with the new MPS. */ usbd_kill_pipe(dev->ud_pipe0); + dev->ud_pipe0 = NULL; err = usbd_setup_pipe_flags(dev, 0, &dev->ud_ep0, USBD_DEFAULT_INTERVAL, &dev->ud_pipe0, USBD_MPSAFE); if (err) { @@ -1337,6 +1286,7 @@ usbd_new_device(device_t parent, struct /* Re-establish the default pipe with the new address. */ usbd_kill_pipe(dev->ud_pipe0); + dev->ud_pipe0 = NULL; err = usbd_setup_pipe_flags(dev, 0, &dev->ud_ep0, USBD_DEFAULT_INTERVAL, &dev->ud_pipe0, USBD_MPSAFE); if (err) { @@ -1390,6 +1340,10 @@ usbd_reload_device_desc(struct usbd_devi err = usbd_get_device_desc(dev, udd); if (err) return err; + if (udd->bDescriptorType != UDESC_DEVICE) + return USBD_INVAL; + if (udd->bLength < USB_DEVICE_DESCRIPTOR_SIZE) + return USBD_INVAL; DPRINTFN(15, "bLength %5ju", udd->bLength, 0, 0, 0); DPRINTFN(15, "bDescriptorType %5ju", udd->bDescriptorType, 0, 0, 0); @@ -1399,10 +1353,10 @@ usbd_reload_device_desc(struct usbd_devi DPRINTFN(15, "bDeviceSubClass %5ju", udd->bDeviceSubClass, 0, 0, 0); DPRINTFN(15, "bDeviceProtocol %5ju", udd->bDeviceProtocol, 0, 0, 0); DPRINTFN(15, "bMaxPacketSize0 %5ju", udd->bMaxPacketSize, 0, 0, 0); - DPRINTFN(15, "idVendor %#02jx %#02jx", + DPRINTFN(15, "idVendor 0x%02jx 0x%02jx", udd->idVendor[0], udd->idVendor[1], 0, 0); - DPRINTFN(15, "idProduct %#02jx %#02jx", + DPRINTFN(15, "idProduct 0x%02jx 0x%02jx", udd->idProduct[0], udd->idProduct[1], 0, 0); DPRINTFN(15, "bcdDevice %2jx.%02jx", udd->bcdDevice[1], @@ -1423,15 +1377,24 @@ void usbd_remove_device(struct usbd_device *dev, struct usbd_port *up) { - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); - - DPRINTF("dev %#jx up %#jx", (uintptr_t)dev, (uintptr_t)up, 0, 0); + USBHIST_FUNC(); + USBHIST_CALLARGS(usbdebug, "dev %#jx up %#jx", + (uintptr_t)dev, (uintptr_t)up, 0, 0); if (dev->ud_pipe0 != NULL) usbd_kill_pipe(dev->ud_pipe0); up->up_dev = NULL; dev->ud_bus->ub_devices[usb_addr2dindex(dev->ud_addr)] = NULL; + if (dev->ud_vendor != NULL) { + kmem_free(dev->ud_vendor, USB_MAX_ENCODED_STRING_LEN); + } + if (dev->ud_product != NULL) { + kmem_free(dev->ud_product, USB_MAX_ENCODED_STRING_LEN); + } + if (dev->ud_serial != NULL) { + kmem_free(dev->ud_serial, USB_MAX_ENCODED_STRING_LEN); + } kmem_free(dev, sizeof(*dev)); } @@ -1458,11 +1421,11 @@ usbd_print(void *aux, const char *pnp) * by each driver. */ if (uaa->uaa_vendor != UHUB_UNK_VENDOR) - aprint_normal(" vendor %#04x", uaa->uaa_vendor); + aprint_normal(" vendor 0x%04x", uaa->uaa_vendor); if (uaa->uaa_product != UHUB_UNK_PRODUCT) - aprint_normal(" product %#04x", uaa->uaa_product); + aprint_normal(" product 0x%04x", uaa->uaa_product); if (uaa->uaa_release != UHUB_UNK_RELEASE) - aprint_normal(" release %#04x", uaa->uaa_release); + aprint_normal(" release 0x%04x", uaa->uaa_release); #endif return UNCONF; } @@ -1484,11 +1447,11 @@ usbd_ifprint(void *aux, const char *pnp) * by each driver. */ if (uaa->uaa_vendor != UHUB_UNK_VENDOR) - aprint_normal(" vendor %#04x", uaa->uaa_vendor); + aprint_normal(" vendor 0x%04x", uaa->uaa_vendor); if (uaa->uaa_product != UHUB_UNK_PRODUCT) - aprint_normal(" product %#04x", uaa->uaa_product); + aprint_normal(" product 0x%04x", uaa->uaa_product); if (uaa->uaa_release != UHUB_UNK_RELEASE) - aprint_normal(" release %#04x", uaa->uaa_release); + aprint_normal(" release 0x%04x", uaa->uaa_release); #endif return UNCONF; } @@ -1555,8 +1518,8 @@ usbd_fill_deviceinfo(struct usbd_device } const int nports = dev->ud_hub->uh_hubdesc.bNbrPorts; - for (i = 0; i < __arraycount(di->udi_ports) && i < nports; i++) { - p = &dev->ud_hub->uh_ports[i]; + for (i = 1; i <= __arraycount(di->udi_ports) && i <= nports; i++) { + p = &dev->ud_hub->uh_ports[i - 1]; if (p->up_dev) err = p->up_dev->ud_addr; else { @@ -1578,81 +1541,11 @@ usbd_fill_deviceinfo(struct usbd_device else err = USB_PORT_DISABLED; } - di->udi_ports[i] = err; + di->udi_ports[i - 1] = err; } di->udi_nports = nports; } -#ifdef COMPAT_30 -void -usbd_fill_deviceinfo_old(struct usbd_device *dev, struct usb_device_info_old *di, - int usedev) -{ - struct usbd_port *p; - int i, j, err; - - di->udi_bus = device_unit(dev->ud_bus->ub_usbctl); - di->udi_addr = dev->ud_addr; - di->udi_cookie = dev->ud_cookie; - usbd_devinfo_vp(dev, di->udi_vendor, sizeof(di->udi_vendor), - di->udi_product, sizeof(di->udi_product), usedev, 0); - usbd_printBCD(di->udi_release, sizeof(di->udi_release), - UGETW(dev->ud_ddesc.bcdDevice)); - di->udi_vendorNo = UGETW(dev->ud_ddesc.idVendor); - di->udi_productNo = UGETW(dev->ud_ddesc.idProduct); - di->udi_releaseNo = UGETW(dev->ud_ddesc.bcdDevice); - di->udi_class = dev->ud_ddesc.bDeviceClass; - di->udi_subclass = dev->ud_ddesc.bDeviceSubClass; - di->udi_protocol = dev->ud_ddesc.bDeviceProtocol; - di->udi_config = dev->ud_config; - di->udi_power = dev->ud_selfpowered ? 0 : dev->ud_power; - di->udi_speed = dev->ud_speed; - - if (dev->ud_subdevlen > 0) { - for (i = 0, j = 0; i < dev->ud_subdevlen && - j < USB_MAX_DEVNAMES; i++) { - if (!dev->ud_subdevs[i]) - continue; - strncpy(di->udi_devnames[j], - device_xname(dev->ud_subdevs[i]), USB_MAX_DEVNAMELEN); - di->udi_devnames[j][USB_MAX_DEVNAMELEN-1] = '\0'; - j++; - } - } else { - j = 0; - } - for (/* j is set */; j < USB_MAX_DEVNAMES; j++) - di->udi_devnames[j][0] = 0; /* empty */ - - if (!dev->ud_hub) { - di->udi_nports = 0; - return; - } - - const int nports = dev->ud_hub->uh_hubdesc.bNbrPorts; - for (i = 0; i < __arraycount(di->udi_ports) && i < nports; - i++) { - p = &dev->ud_hub->uh_ports[i]; - if (p->up_dev) - err = p->up_dev->ud_addr; - else { - const int s = UGETW(p->up_status.wPortStatus); - if (s & UPS_PORT_ENABLED) - err = USB_PORT_ENABLED; - else if (s & UPS_SUSPEND) - err = USB_PORT_SUSPENDED; - else if (s & UPS_PORT_POWER) - err = USB_PORT_POWERED; - else - err = USB_PORT_DISABLED; - } - di->udi_ports[i] = err; - } - di->udi_nports = nports; -} -#endif - - void usb_free_device(struct usbd_device *dev) { @@ -1708,15 +1601,15 @@ usb_free_device(struct usbd_device *dev) int usb_disconnect_port(struct usbd_port *up, device_t parent, int flags) { - USBHIST_FUNC(); USBHIST_CALLED(usbdebug); struct usbd_device *dev = up->up_dev; device_t subdev; char subdevname[16]; const char *hubname = device_xname(parent); int i, rc; - DPRINTFN(3, "up=%#jx dev=%#jx port=%jd", (uintptr_t)up, (uintptr_t)dev, - up->up_portno, 0); + USBHIST_FUNC(); + USBHIST_CALLARGS(usbdebug, "up=%#jx dev=%#jx port=%jd", + (uintptr_t)up, (uintptr_t)dev, up->up_portno, 0); if (dev == NULL) { return 0;