From owner-freebsd-usb@freebsd.org Wed Jan 4 13:39:37 2017 Return-Path: Delivered-To: freebsd-usb@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0071EC9EEBB for ; Wed, 4 Jan 2017 13:39:36 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D952D13AF for ; Wed, 4 Jan 2017 13:39:36 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id v04Ddavd077634 for ; Wed, 4 Jan 2017 13:39:36 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-usb@FreeBSD.org Subject: [Bug 215765] libusb_handle_events_completed() hangs after device removal Date: Wed, 04 Jan 2017 13:39:36 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: usb X-Bugzilla-Version: 11.0-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: kjopek@gmail.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-usb@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jan 2017 13:39:37 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D215765 Bug ID: 215765 Summary: libusb_handle_events_completed() hangs after device removal Product: Base System Version: 11.0-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: usb Assignee: freebsd-usb@FreeBSD.org Reporter: kjopek@gmail.com Created attachment 178508 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D178508&action= =3Dedit Logs from pcscd pcscd installed on FreeBSD 11.0-CURRENT has serious problems when YubiKey w= as detached and reattached to machine. It looks like one of pcscd's threads ha= ngs after device removal on function libusb_handle_events_completed() from libu= sb. Steps to reproduce: Install pcsc-lite either from ports or packages. Start pcscd demon in foreground mode with logging enabled: pcscd -f -a -I Try to attach YubiKey, list YubiKey status in GPG (gpg2 --card-status), det= ach it, reattach, list card status in GPG. In my case the second attempt shows something like: $ gpg2 --card-status gpg: selecting openpgp failed: Operation not supported by device while pcscd logs the following error: 02006441 ccid_usb.c:1323:InterruptStop() libusb_cancel_transfer failed: -5 14759547 winscard.c:261:SCardConnect() Reader Yubico Yubikey 4 OTP+U2F+CCID= 00 00 Not Found Expected result is that pcscd correctly reinitializes YubiKey and gpg shows correctly status of a YubiKey. Also, there are questions from maintainer of pcscd and ccid related to libu= sb implementation in FreeBSD: - Why libusb_handle_events_completed() does not return on device removal? - How to cancel a transfer after device removal if libusb_cancel_transfer() fails with LIBUSB_ERROR_NOT_FOUND since the device is removed? Please notice that on MacOS libusb_handle_events_completed() returns when t= he USB device is removed. Here are the details about platform and installed software: FreeBSD AMDC2690 11.0-RELEASE-p2 FreeBSD 11.0-RELEASE-p2 #0: Mon Oct 24 06:55:27 UTC 2016=20=20=20=20 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64 pcscd --version pcsc-lite version 1.8.18. Copyright (C) 1999-2002 by David Corcoran . Copyright (C) 2001-2015 by Ludovic Rousseau . Copyright (C) 2003-2004 by Damien Sauveron . Report bugs to . Enabled features: FreeBSD amd64-portbld-freebsd11.0 serial usb libusb usbdropdir=3D/usr/local/lib/pcsc/drivers/ ipcdir=3D/var/run/pcscd configdir=3D/usr/local/etc/reader.conf.d ccid version is 1.4.25 patched to add more verbose logging. Logs from verbose version of ccid are also attached to this mail. Respects for Ludovico Rousseau for his help on debugging ccid and pcscd. --=20 You are receiving this mail because: You are the assignee for the bug.=