From owner-freebsd-usb@FreeBSD.ORG Fri Dec 21 07:15:59 2012 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 26803ADB; Fri, 21 Dec 2012 07:15:59 +0000 (UTC) (envelope-from xiaofanc@gmail.com) Received: from mail-ea0-f169.google.com (mail-ea0-f169.google.com [209.85.215.169]) by mx1.freebsd.org (Postfix) with ESMTP id 839D08FC13; Fri, 21 Dec 2012 07:15:58 +0000 (UTC) Received: by mail-ea0-f169.google.com with SMTP id a12so1688719eaa.14 for ; Thu, 20 Dec 2012 23:15:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=p1rVESgO+2LKf1nD6EtIe7GaRgkQk8FBJN2HqlUalNY=; b=yGkpH+2rhjfKUAZkkukcOzTjVggreyUi9u9Chfa9BQMAUa6J2DIqjt9ZXbrnHrJL9m 9zIPcdxFbPuvp8PO1TCV4V7OiBPIfqyXg9fPxFXwNAxBPCVnmA36nXvSsOYb2+f7rJqM HA2HHU9/xXR243aPzKUATiOBDtzhzHoa5CJ2vspdAGyAcLyqBLpYgpGBucgag/ujq/Wg JV0mXngmh0DgSAbZj6viBvfIPyw7c/HPFiIu/KplXXG69jswe4UI/qaeS/Ktk+a5fs3K i6DmSKhJAmnNsIoPLkOvi+6jmDqD52cv2KVpHH7V274rpfYo3mYnyCMtNv1xbrkJrZHW CjMw== MIME-Version: 1.0 Received: by 10.14.174.198 with SMTP id x46mr29744759eel.23.1356074123415; Thu, 20 Dec 2012 23:15:23 -0800 (PST) Received: by 10.14.136.142 with HTTP; Thu, 20 Dec 2012 23:15:23 -0800 (PST) In-Reply-To: <201211171319.34781.hselasky@c2i.net> References: <201211162247.qAGMlTm2057387@red.freebsd.org> <201211171319.34781.hselasky@c2i.net> Date: Fri, 21 Dec 2012 15:15:23 +0800 Message-ID: Subject: Re: usb/173666: [USB, LIBUSB] usb_reset() behavior different between GNU/Linux and FreeBSD From: Xiaofan Chen To: Hans Petter Selasky Content-Type: text/plain; charset=ISO-8859-1 Cc: "Wojciech A. Koszek" , freebsd-usb@freebsd.org X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Dec 2012 07:15:59 -0000 On Sat, Nov 17, 2012 at 8:19 PM, Hans Petter Selasky wrote: > On Friday 16 November 2012 23:47:29 Wojciech A. Koszek wrote: >> >Number: 173666 >> >Category: usb >> >Synopsis: [USB, LIBUSB] usb_reset() behavior different between >> >GNU/Linux and FreeBSD Confidential: no >> >Severity: non-critical >> >Priority: low >> >Responsible: freebsd-usb >> >State: open >> >Quarter: >> >Keywords: >> >Date-Required: >> >Class: sw-bug >> >Submitter-Id: current-users >> >Arrival-Date: Fri Nov 16 22:50:00 UTC 2012 >> >Closed-Date: >> >Last-Modified: >> >Originator: Wojciech A. Koszek >> >Release: 9.0-RELEASE >> >> >Organization: >> FreeBSD >> >> >Environment: >> FreeBSD seu 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:15:25 UTC >> 2012 root@obrian.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 >> >> >Description: >> I have a driver written for libusb, which works fine under GNU/Linux and >> libusb. Device: >> >> gen0.2: at usbus0, cfg=0 md=HOST spd=LOW >> (1.5Mbps) pwr=ON >> >> (I used USB sniffer to uncover traffic based on what Windows was doing) >> >> Under Linux usb_reset()+usb_set_configuration() calls works fine. Under >> FreeBSD I have to disable calling usb_reset(), otherwise >> usb_set_configuration() fails with I/O error. >> > > According to: > > http://libusb.sourceforge.net/doc/function.usbreset.html > > What you describe is the expected behaviour. The above document is really meant for libusb-0.1 but the behavior of libusb-compat's usb_reset() is different since it is based on libusb-1.0's libusb_reset_device. http://git.libusb.org/?p=libusb-compat-0.1.git;a=blob;f=libusb/core.c 743 API_EXPORTED int usb_reset(usb_dev_handle *dev) 744 { 745 usbi_dbg(""); 746 return compat_err(libusb_reset_device(dev->handle)); 747 } For libusb-1.0 under Linux and Mac OS X, usually libusb_reset_device will not cause enumeration. Reference: http://libusb.6.n5.nabble.com/PATCH-make-libusb-reset-force-re-enumeration-on-Mac-td4499375.html http://libusb.sourceforge.net/api-1.0/group__dev.html#ga7321bd8dc28e9a20b411bf18e6d0e9aa int libusb_reset_device ( libusb_device_handle * dev ) Perform a USB port reset to reinitialize a device. The system will attempt to restore the previous configuration and alternate settings after the reset has completed. If the reset fails, the descriptors change, or the previous state cannot be restored, the device will appear to be disconnected and reconnected. This means that the device handle is no longer valid (you should close it) and rediscover the device. A return code of LIBUSB_ERROR_NOT_FOUND indicates when this is the case. This is a blocking function which usually incurs a noticeable delay. Parameters: dev a handle of the device to reset Returns: 0 on success LIBUSB_ERROR_NOT_FOUND if re-enumeration is required, or if the device has been disconnected another LIBUSB_ERROR code on other failure -- Xiaofan