From owner-freebsd-bugs@FreeBSD.ORG Tue Jan 20 05:20:23 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5142816A4CF for ; Tue, 20 Jan 2004 05:20:23 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id CBCF843D48 for ; Tue, 20 Jan 2004 05:20:08 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i0KDK8FR027473 for ; Tue, 20 Jan 2004 05:20:08 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i0KDK8BA027472; Tue, 20 Jan 2004 05:20:08 -0800 (PST) (envelope-from gnats) Resent-Date: Tue, 20 Jan 2004 05:20:08 -0800 (PST) Resent-Message-Id: <200401201320.i0KDK8BA027472@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, James Bond Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6DFCD16A4CE for ; Tue, 20 Jan 2004 05:15:34 -0800 (PST) Received: from mx0.rambler.ru (mx0.rambler.ru [81.19.66.47]) by mx1.FreeBSD.org (Postfix) with ESMTP id A297943D1D for ; Tue, 20 Jan 2004 05:15:25 -0800 (PST) (envelope-from JamesBond@rambler.ru) Received: from mailc.rambler.ru (mailc.rambler.ru [81.19.66.27]) by mx0.rambler.ru (Postfix) with ESMTP id DC864433384 for ; Tue, 20 Jan 2004 16:15:23 +0300 (MSK) (envelope-from JamesBond@rambler.ru) Received: from 127.0.0.1 (b2-gw.tsu.tula.ru [62.76.48.135]) (authenticated bits=0) by mailc.rambler.ru (8.12.10/8.12.10) with ESMTP id i0KDFGLO012110 for ; Tue, 20 Jan 2004 16:15:17 +0300 (MSK) Message-Id: <868215093.20040120162215@rambler.ru> Date: Tue, 20 Jan 2004 16:22:15 +0300 From: James Bond To: FreeBSD-gnats-submit@FreeBSD.org Subject: kern/61627: New USB printer not supported correctly X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: James Bond List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Jan 2004 13:20:23 -0000 >Number: 61627 >Category: kern >Synopsis: New USB printer not supported correctly >Confidential: no >Severity: critical >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Jan 20 05:20:08 PST 2004 >Closed-Date: >Last-Modified: >Originator: Zaikov S.G. >Release: FreeBSD 4.9-RELEASE-p1 i386 >Organization: TSU >Environment: System: FreeBSD acc.acc.tula.ru 4.9-RELEASE-p1 FreeBSD 4.9-RELEASE-p1 #14: Fri Jan 16 11:53:53 MSK 2004 acc107_3@acc.acc.tula.ru:/usr/obj/usr/src/sys/Z i386 >Description: FreeBSD usb-subsystem don't recognize modern USB printer. >How-To-Repeat: I test with HP laserjet 1300 and KERNCONF with lines: # USB support device uhci # UHCI PCI->USB interface device ohci # OHCI PCI->USB interface device usb # USB Bus (required) device ugen # Generic device ulpt # Printer Plug USB-printer into USB port. We will see lines like this: ugen0: Hewlett-Packard hp LaserJet 1300, rev 1.10/1.00, addr 2 instead of ulpt. >Fix: I get this answer from ticso@cicely12.cicely.de with this patch: --Sr1nOIr3CvdE5hEN - --- ulpt.c.orig Fri May 2 15:50:58 2003 +++ ulpt.c Fri May 2 15:56:40 2003 @@ -174,7 +174,8 @@ id->bInterfaceClass == UICLASS_PRINTER && id->bInterfaceSubClass == UISUBCLASS_PRINTER && (id->bInterfaceProtocol == UIPROTO_PRINTER_UNI || - id->bInterfaceProtocol == UIPROTO_PRINTER_BI)) + id->bInterfaceProtocol == UIPROTO_PRINTER_BI || + id->bInterfaceProtocol == UIPROTO_PRINTER_1284)) return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO); return (UMATCH_NONE); } @@ -183,79 +184,63 @@ { USB_ATTACH_START(ulpt, sc, uaa); usbd_device_handle dev = uaa->device; + + usb_config_descriptor_t *cdesc; + usbd_interface_handle iface = uaa->iface; - usb_interface_descriptor_t *id = usbd_get_interface_descriptor(iface); + usb_interface_descriptor_t *ifcd = usbd_get_interface_descriptor(iface); + usb_interface_descriptor_t *id, *iend; char devinfo[1024]; usb_endpoint_descriptor_t *ed; usbd_status err; + u_int8_t epcount; + int i, altno; DPRINTFN(10,("ulpt_attach: sc=%p\n", sc)); usbd_devinfo(dev, 0, devinfo); USB_ATTACH_SETUP; - printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev), - devinfo, id->bInterfaceClass, id->bInterfaceSubClass); - /* Figure out which endpoint is the bulk out endpoint. */ - ed = usbd_interface2endpoint_descriptor(iface, 0); - if (ed == NULL) - goto nobulk; - if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_OUT || - (ed->bmAttributes & UE_XFERTYPE) != UE_BULK) { - /* In case we are using a bidir protocol... */ - ed = usbd_interface2endpoint_descriptor(iface, 1); - if (ed == NULL) - goto nobulk; - if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_OUT || - (ed->bmAttributes & UE_XFERTYPE) != UE_BULK) - goto nobulk; - } - sc->sc_bulk = ed->bEndpointAddress; - DPRINTFN(10, ("ulpt_attach: bulk=%d\n", sc->sc_bulk)); - - sc->sc_iface = iface; - err = usbd_interface2device_handle(iface, &sc->sc_udev); - if (err) { - sc->sc_dying = 1; - USB_ATTACH_ERROR_RETURN; - } - sc->sc_ifaceno = id->bInterfaceNumber; - -#if 0 -/* - * This code is disabled because for some mysterious reason it causes - * printing not to work. But only sometimes, and mostly with - * UHCI and less often with OHCI. *sigh* - */ - { - usb_config_descriptor_t *cd = usbd_get_config_descriptor(dev); - usb_device_request_t req; - int len, alen; - - req.bmRequestType = UT_READ_CLASS_INTERFACE; - req.bRequest = UR_GET_DEVICE_ID; - USETW(req.wValue, cd->bConfigurationValue); - USETW2(req.wIndex, id->bInterfaceNumber, id->bAlternateSetting); - USETW(req.wLength, sizeof devinfo - 1); - err = usbd_do_request_flags(dev, &req, devinfo, USBD_SHORT_XFER_OK, - &alen); - if (err) { - printf("%s: cannot get device id\n", USBDEVNAME(sc->sc_dev)); - } else if (alen <= 2) { - printf("%s: empty device id, no printer connected?\n", - USBDEVNAME(sc->sc_dev)); - } else { - /* devinfo now contains an IEEE-1284 device ID */ - len = ((devinfo[0] & 0xff) << 8) | (devinfo[1] & 0xff); - if (len > sizeof devinfo - 3) - len = sizeof devinfo - 3; - devinfo[len] = 0; - printf("%s: device id <", USBDEVNAME(sc->sc_dev)); - ieee1284_print_id(devinfo+2); - printf(">\n"); - } - } + cdesc = usbd_get_config_descriptor(dev); + if (cdesc == NULL) { + printf("%s: failed to get configuration descriptor\n", + USBDEVNAME(sc->sc_dev)); + USB_ATTACH_ERROR_RETURN; + } + iend = (usb_interface_descriptor_t *) + ((char *)cdesc + UGETW(cdesc->wTotalLength)); +#ifdef DIAGNOSTIC + if (ifcd < (usb_interface_descriptor_t *)cdesc || + ifcd >= iend) + panic("ulpt: iface desc out of range\n"); #endif - + /* Step through all the descriptors looking for bidir mode */ + for (id = ifcd, altno = 0; + id < iend; + id = (void *)((char *)id + id->bLength)) { + if (id->bDescriptorType == UDESC_INTERFACE && + id->bInterfaceNumber == ifcd->bInterfaceNumber) { + if (id->bInterfaceClass == UICLASS_PRINTER && + id->bInterfaceSubClass == UISUBCLASS_PRINTER && + id->bInterfaceProtocol == UIPROTO_PRINTER_BI) { + DPRINTF(("ulpt_attach: set altno = %d\n", altno)); + err = usbd_set_interface(iface, altno); + if (err == 0) { + printf("%s: %s, iclass %d/%d-%d(%d)\n",USBDEVNAME(sc->sc_dev), + devinfo, id->bInterfaceClass, id->bInterfaceSubClass, + id->bInterfaceNumber+id->bAlternateSetting,id->bInterfaceProtocol); + epcount = 0; + (void)usbd_endpoint_count(iface, &epcount); + for (i = 0; i < epcount; i++) { + ed = usbd_interface2endpoint_descriptor(iface, i); + if (ed != NULL) { + if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && + (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) { + sc->sc_bulk = ed->bEndpointAddress; + DPRINTFN(10, ("ulpt_attach: bulk=%d\n",sc->sc_bulk)); + sc->sc_iface = iface; + err = usbd_interface2device_handle(iface,&sc->sc_udev); + if (err == 0) { + sc->sc_ifaceno = id->bInterfaceNumber; #if defined(__FreeBSD__) sc->dev = make_dev(&ulpt_cdevsw, device_get_unit(self), UID_ROOT, GID_OPERATOR, 0644, "ulpt%d", device_get_unit(self)); @@ -263,10 +248,17 @@ device_get_unit(self)|ULPT_NOPRIME, UID_ROOT, GID_OPERATOR, 0644, "unlpt%d", device_get_unit(self)); #endif - USB_ATTACH_SUCCESS_RETURN; - - nobulk: + } + } + } + } + } + } + altno++; + } + } + id = ifcd; /* not found, use original */ printf("%s: could not find bulk endpoint\n", USBDEVNAME(sc->sc_dev)); sc->sc_dying = 1; USB_ATTACH_ERROR_RETURN; --Sr1nOIr3CvdE5hEN-- >Release-Note: >Audit-Trail: >Unformatted: To: FreeBSD-gnats-submit@freebsd.org From: JamesBond@rambler.ru Reply-To: JamesBond@rambler.ru Cc: X-send-pr-version: 3.113 X-GNATS-Notify: