diff options
Diffstat (limited to 'sys/dev/usb/usb_subr.c')
-rw-r--r-- | sys/dev/usb/usb_subr.c | 114 |
1 files changed, 50 insertions, 64 deletions
diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c index a26022ee9ad..981663dd903 100644 --- a/sys/dev/usb/usb_subr.c +++ b/sys/dev/usb/usb_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_subr.c,v 1.3 1999/08/19 08:18:39 fgsch Exp $ */ +/* $OpenBSD: usb_subr.c,v 1.4 1999/08/27 09:00:30 fgsch Exp $ */ /* $NetBSD: usb_subr.c,v 1.38 1999/08/17 20:59:04 augustss Exp $ */ /* @@ -131,6 +131,33 @@ char *usbd_error_strs[] = { }; #endif +char * +usbd_errstr(err) + usbd_status err; +{ + static char buffer[5]; + +#ifdef USB_DEBUG + if ( err < USBD_ERROR_MAX ) { + return usbd_error_strs[err]; + } else { +#if !defined(__OpenBSD__) + snprintf(buffer, sizeof buffer, "%d", err); +#else + sprintf(buffer, "%d", err); +#endif /* !defined(__OpenBSD__) */ + return buffer; + } +#else +#if !defined(__OpenBSD__) + snprintf(buffer, sizeof buffer, "%d", err); +#else + sprintf(buffer, "%d", err); +#endif /* !defined(__OpenBSD__) */ + return buffer; +#endif +} + usbd_status usbd_get_string_desc(dev, sindex, langid, sdesc) usbd_device_handle dev; @@ -313,8 +340,8 @@ usbd_reset_port(dev, port, ps) USETW(req.wIndex, port); USETW(req.wLength, 0); r = usbd_do_request(dev, &req, 0); - DPRINTFN(1,("usbd_reset_port: port %d reset done, error=%d(%s)\n", - port, r, usbd_error_strs[r])); + DPRINTFN(1,("usbd_reset_port: port %d reset done, error=%s\n", + port, usbd_errstr(r))); if (r != USBD_NORMAL_COMPLETION) return (r); n = 10; @@ -574,8 +601,8 @@ usbd_set_config_index(dev, index, msg) (UGETW(ds.wStatus) & UDS_SELF_POWERED)) selfpowered = 1; DPRINTF(("usbd_set_config_index: status=0x%04x, " - "error=%d(%s)\n", - UGETW(ds.wStatus), r, usbd_error_strs[r])); + "error=%s\n", + UGETW(ds.wStatus), usbd_errstr(r))); } else selfpowered = 1; } @@ -609,8 +636,8 @@ usbd_set_config_index(dev, index, msg) r = usbd_set_config(dev, cdp->bConfigurationValue); if (r != USBD_NORMAL_COMPLETION) { DPRINTF(("usbd_set_config_index: setting config=%d failed, " - "error=%d(%s)\n", - cdp->bConfigurationValue, r, usbd_error_strs[r])); + "error=%s\n", + cdp->bConfigurationValue, usbd_errstr(r))); goto bad; } DPRINTF(("usbd_set_config_index: setting new config %d\n", @@ -669,9 +696,9 @@ usbd_setup_pipe(dev, iface, ep, pipe) SIMPLEQ_INIT(&p->queue); r = dev->bus->open_pipe(p); if (r != USBD_NORMAL_COMPLETION) { - DPRINTFN(-1,("usbd_setup_pipe: endpoint=0x%x failed, error=%d" - "(%s)\n", - ep->edesc->bEndpointAddress, r, usbd_error_strs[r])); + DPRINTFN(-1,("usbd_setup_pipe: endpoint=0x%x failed, error=" + "%s\n", + ep->edesc->bEndpointAddress, usbd_errstr(r))); free(p, M_USB); return (r); } @@ -764,8 +791,8 @@ usbd_probe_and_attach(parent, dev, port, addr) if (r != USBD_NORMAL_COMPLETION) { #ifdef USB_DEBUG DPRINTF(("%s: port %d, set config at addr %d failed, " - "error=%d(%s)\n", USBDEVNAME(*parent), port, - addr, r, usbd_error_strs[r])); + "error=%s\n", USBDEVNAME(*parent), port, + addr, usbd_errstr(r))); #else printf("%s: port %d, set config at addr %d failed\n", USBDEVNAME(*parent), port, addr); @@ -926,6 +953,12 @@ usbd_new_device(parent, bus, depth, lowspeed, port, up) return (r); } + DPRINTF(("usbd_new_device: adding unit addr=%d, rev=%02x, class=%d, " + "subclass=%d, protocol=%d, maxpacket=%d, len=%d, ls=%d\n", + addr,UGETW(dd->bcdUSB), dd->bDeviceClass, dd->bDeviceSubClass, + dd->bDeviceProtocol, dd->bMaxPacketSize, dd->bLength, + dev->lowspeed)); + if (dd->bDescriptorType != UDESC_DEVICE) { /* Illegal device descriptor */ DPRINTFN(-1,("usbd_new_device: illegal descriptor %d\n", @@ -934,10 +967,11 @@ usbd_new_device(parent, bus, depth, lowspeed, port, up) return (USBD_INVAL); } - DPRINTF(("usbd_new_device: adding unit addr=%d, rev=%02x, class=%d, " - "subclass=%d, protocol=%d, maxpacket=%d, ls=%d\n", - addr,UGETW(dd->bcdUSB), dd->bDeviceClass, dd->bDeviceSubClass, - dd->bDeviceProtocol, dd->bMaxPacketSize, dev->lowspeed)); + if (dd->bLength < USB_DEVICE_DESCRIPTOR_SIZE) { + DPRINTFN(-1,("usbd_new_device: bad length %d\n", dd->bLength)); + usbd_remove_device(dev, up); + return (USBD_INVAL); + } USETW(dev->def_ep_desc.wMaxPacketSize, dd->bMaxPacketSize); @@ -1086,54 +1120,6 @@ usbd_bus_print_child(device_t bus, device_t dev) } #endif -usbd_status -usb_insert_transfer(reqh) - usbd_request_handle reqh; -{ - usbd_pipe_handle pipe = reqh->pipe; - - SIMPLEQ_INSERT_TAIL(&pipe->queue, reqh, next); - if (pipe->running) - return (USBD_IN_PROGRESS); - pipe->running = 1; - return (USBD_NORMAL_COMPLETION); -} - -void -usb_start_next(pipe) - usbd_pipe_handle pipe; -{ - usbd_request_handle reqh; - usbd_status r; - - DPRINTFN(10, ("usb_start_next: pipe=%p\n", pipe)); - -#ifdef DIAGNOSTIC - if (!pipe) { - printf("usb_start_next: pipe == 0\n"); - return; - } - if (!pipe->methods || !pipe->methods->start) { - printf("usb_start_next: no start method\n"); - return; - } -#endif - - /* Get next request in queue. */ - reqh = SIMPLEQ_FIRST(&pipe->queue); - DPRINTFN(5, ("usb_start_next: start reqh=%p\n", reqh)); - if (!reqh) - pipe->running = 0; - else { - r = pipe->methods->start(reqh); - if (r != USBD_IN_PROGRESS) { - printf("usb_start_next: error=%d\n", r); - pipe->running = 0; - /* XXX do what? */ - } - } -} - void usbd_fill_deviceinfo(dev, di) usbd_device_handle dev; |