From owner-freebsd-usb@FreeBSD.ORG Sat Dec 22 10:17:17 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 E1F87DD2; Sat, 22 Dec 2012 10:17:17 +0000 (UTC) (envelope-from xiaofanc@gmail.com) Received: from mail-ee0-f45.google.com (mail-ee0-f45.google.com [74.125.83.45]) by mx1.freebsd.org (Postfix) with ESMTP id 4A7C58FC0A; Sat, 22 Dec 2012 10:17:16 +0000 (UTC) Received: by mail-ee0-f45.google.com with SMTP id d49so2782980eek.18 for ; Sat, 22 Dec 2012 02:17:16 -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=gXJAEIJuFZ3LzKQQGm31Du4QbeQObjwE6dIfGL+AxNs=; b=lB1m8Cji0num6Bfyblq7yPfH4htFOvDkn8bBtym+Fkap0ImxHMpalXvX2JvXXfR9xm 1j0L8SYpsvN8GR+c75dZkO681FKfZVPoeelfHdtHrNhiEyRzHx+CAPk4hx4HTXMDWiZc k8AEur9SNemvhqsSDbdAfULx8v/HsCbckaOtUiRwEnpX7TP0Iwrrk958yfOBZbZzZY9n iro6AjJUL2dnTyzOMmK403gnlGzZ2XVxP/4J18QUy4tGbvix/jX5YWEP9HnGolSxVmh2 M/Jp3EYw7axCOVi39FKocninl2DjCNqbOI+ZwUoA0rJ4DBVJYVq9uI8P/C6aSGVG69ql 4waA== MIME-Version: 1.0 Received: by 10.14.207.6 with SMTP id m6mr39527227eeo.10.1356171435924; Sat, 22 Dec 2012 02:17:15 -0800 (PST) Received: by 10.223.90.204 with HTTP; Sat, 22 Dec 2012 02:17:15 -0800 (PST) In-Reply-To: <201212210838.32260.hselasky@c2i.net> References: <201211162247.qAGMlTm2057387@red.freebsd.org> <201211171319.34781.hselasky@c2i.net> <201212210838.32260.hselasky@c2i.net> Date: Sat, 22 Dec 2012 18:17:15 +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: Sat, 22 Dec 2012 10:17:18 -0000 On Fri, Dec 21, 2012 at 3:38 PM, Hans Petter Selasky wrote: > If you look in the old libusb-0.1 code you'll see something different I think. > Could you check that? Not much differences in reality. I believe it is a document bug for the libusb-0.1. Both old libusb-0.1 code and libusb-1.0 use the same IOCTL under Linux and the behavior should be similar. Please refer to the following code listing and take note even though the name of the IOCTL is different but they are the same if you look at the defines. On the other hand, libusb-win32's usb_reset will cause re-enumeration. >From libusb-0.1.12 source (linux.c) int usb_reset(usb_dev_handle *dev) { int ret; ret = ioctl(dev->fd, IOCTL_USB_RESET, NULL); if (ret) USB_ERROR_STR(-errno, "could not reset: %s", strerror(errno)); return 0; } >From libusb.org libusb.git (libusb-1.0) souce: static int op_reset_device(struct libusb_device_handle *handle) { int fd = _device_handle_priv(handle)->fd; int i, r, ret = 0; /* Doing a device reset will cause the usbfs driver to get unbound from any interfaces it is bound to. By voluntarily unbinding the usbfs driver ourself, we stop the kernel from rebinding the interface after reset (which would end up with the interface getting bound to the in kernel driver if any). */ for (i = 0; i < USB_MAXINTERFACES; i++) { if (handle->claimed_interfaces & (1L << i)) { op_release_interface(handle, i); } } usbi_mutex_lock(&handle->lock); r = ioctl(fd, IOCTL_USBFS_RESET, NULL); if (r) { if (errno == ENODEV) { ret = LIBUSB_ERROR_NOT_FOUND; goto out; } usbi_err(HANDLE_CTX(handle), "reset failed error %d errno %d", r, errno); ret = LIBUSB_ERROR_OTHER; goto out; } /* And re-claim any interfaces which were claimed before the reset */ for (i = 0; i < USB_MAXINTERFACES; i++) { if (handle->claimed_interfaces & (1L << i)) { r = op_claim_interface(handle, i); if (r) { usbi_warn(HANDLE_CTX(handle), "failed to re-claim interface %d after reset", i); handle->claimed_interfaces &= ~(1L << i); } } } out: usbi_mutex_unlock(&handle->lock); return ret; } -- Xiaofan