Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to read device descriptor for attached USB device when attached event occurs #1446

Open
ercjethava opened this issue Jan 24, 2024 · 6 comments
Labels
linux question Technical support, will be closed if deemed not a libusb issue. Please use mailing list.

Comments

@ercjethava
Copy link

-> I am trying to read USB device descriptor information such as Manufacturer and Product string when USB device attached event occurs .

Sample code used along with minor changes:
https://github.com/libusb/libusb/blob/master/examples/hotplugtest.c

/* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:8 -*- */
/*
 * libusb example program for hotplug API
 * Copyright © 2012-2013 Nathan Hjelm <hjelmn@mac.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <stdlib.h>
#include <stdio.h>

#include "libusb.h"

int done = 0;
libusb_device_handle *handle = NULL;

static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data)
{
	struct libusb_device_descriptor desc;
	int rc;

	(void)ctx;
	(void)dev;
	(void)event;
	(void)user_data;

	rc = libusb_get_device_descriptor(dev, &desc);
	if (LIBUSB_SUCCESS == rc) {
		printf ("Device attached: %04x:%04x\n", desc.idVendor, desc.idProduct);
	} else {
		printf ("Device attached\n");
		fprintf (stderr, "Error getting device descriptor: %s\n",
			 libusb_strerror((enum libusb_error)rc));
	}

	if (handle) {
		libusb_close (handle);
		handle = NULL;
	}

	rc = libusb_open (dev, &handle);
	if (LIBUSB_SUCCESS != rc) {
		fprintf (stderr, "Error opening device: %s\n",
			 libusb_strerror((enum libusb_error)rc));
	}

	// read manufacturer, product number
	char manu[256], prod[256];
	rc = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, (unsigned char *)manu, sizeof(manu));
	if (rc < 0) {
		printf("Error getting manufacturer string: %s \n", libusb_error_name(rc));
	} else {
		printf("Manufacturer: %s\n", manu);
	}

	rc = libusb_get_string_descriptor_ascii(handle, desc.iProduct, (unsigned char *)prod, sizeof(prod));
	if (rc < 0) {
		printf("Error getting product string: %s \n", libusb_error_name(rc));
	} else {
		printf("Product: %s\n", prod);
	}

	return 0;
}

static int LIBUSB_CALL hotplug_callback_detach(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data)
{
	struct libusb_device_descriptor desc;
	int rc;

	(void)ctx;
	(void)dev;
	(void)event;
	(void)user_data;

	rc = libusb_get_device_descriptor(dev, &desc);
	if (LIBUSB_SUCCESS == rc) {
		printf ("Device detached: %04x:%04x\n", desc.idVendor, desc.idProduct);
	} else {
		printf ("Device detached\n");
		fprintf (stderr, "Error getting device descriptor: %s\n",
			 libusb_strerror((enum libusb_error)rc));
	}

	if (handle) {
		libusb_close (handle);
		handle = NULL;
	}

	return 0;
}

int main(int argc, char *argv[])
{
	libusb_hotplug_callback_handle hp[2];
	int product_id, vendor_id, class_id;
	int rc;
	libusb_context *ctx = NULL;
	// vendor_id  = (argc > 1) ? (int)strtol (argv[1], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
	// product_id = (argc > 2) ? (int)strtol (argv[2], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
	/* register callbcak only for USB hub device */
	vendor_id  = 0x2109;
	product_id = 0x2817;
	class_id   = (argc > 3) ? (int)strtol (argv[3], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;

	rc = libusb_init_context(&ctx, /*options=*/NULL, /*num_options=*/0);
	if (LIBUSB_SUCCESS != rc)
	{
		printf ("failed to initialise libusb: %s\n",
			libusb_strerror((enum libusb_error)rc));
		return EXIT_FAILURE;
	}

	rc = libusb_set_option (ctx, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG);
	if (LIBUSB_SUCCESS != rc)
	{
		printf ("failed to set option: %s\n",
			libusb_strerror((enum libusb_error)rc));
		return EXIT_FAILURE;
	}

	if (!libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) {
		printf ("Hotplug capabilities are not supported on this platform\n");
		libusb_exit (NULL);
		return EXIT_FAILURE;
	}

	rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, 0, vendor_id,
		product_id, class_id, hotplug_callback, NULL, &hp[0]);
	if (LIBUSB_SUCCESS != rc) {
		fprintf (stderr, "Error registering callback 0\n");
		libusb_exit (NULL);
		return EXIT_FAILURE;
	}

	rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 0, vendor_id,
		product_id,class_id, hotplug_callback_detach, NULL, &hp[1]);
	if (LIBUSB_SUCCESS != rc) {
		fprintf (stderr, "Error registering callback 1\n");
		libusb_exit (NULL);
		return EXIT_FAILURE;
	}

	while (1) {
		rc = libusb_handle_events (NULL);
		if (LIBUSB_SUCCESS != rc)
			printf ("libusb_handle_events() failed: %s\n",
				libusb_strerror((enum libusb_error)rc));
	}

	if (handle) {
		libusb_close (handle);
	}

	libusb_exit (NULL);

	return EXIT_SUCCESS;
}
user@user:~/libusb$ sudo ./examples/hotplugtest 
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.004573] [000090b7] libusb: error [usbi_get_context] API misuse! Using non-default context as implicit default.
[ 0.004582] [000090b7] libusb: debug [libusb_hotplug_register_callback] new hotplug cb 0x563af38b69d0 with handle 1
[ 0.004591] [000090b7] libusb: debug [libusb_hotplug_register_callback] new hotplug cb 0x563af38b6970 with handle 2
[ 0.004597] [000090b7] libusb: error [usbi_get_context] API misuse! Using non-default context as implicit default.
[ 0.004604] [000090b7] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.004613] [000090b7] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.004619] [000090b7] libusb: debug [usbi_wait_for_events] poll() 2 fds with timeout in 60000ms


-> Device connected
[13.837303] [000090c5] libusb: debug [linux_enumerate_device] busnum 4 devaddr 26 session_id 1050
[13.837327] [000090c5] libusb: debug [linux_enumerate_device] allocating new device for 4/26 (session 1050)
[13.837373] [000090c5] libusb: debug [linux_get_parent_info] dev 0x7fe6a0001fa0 (4-1) has parent 0x563af38b8490 (usb4) port 1
[13.837409] [000090b7] libusb: debug [usbi_wait_for_events] poll() returned 1
[13.837429] [000090b7] libusb: debug [handle_event_trigger] event triggered
[13.837434] [000090b7] libusb: debug [handle_event_trigger] hotplug message received
[13.837452] [000090b7] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[13.837458] [000090b7] libusb: debug [usbi_wait_for_events] poll() 2 fds with timeout in 60000ms
[13.852983] [000090c5] libusb: debug [linux_enumerate_device] busnum 3 devaddr 44 session_id 812
[13.853003] [000090c5] libusb: debug [linux_enumerate_device] allocating new device for 3/44 (session 812)
[13.853044] [000090c5] libusb: debug [linux_get_parent_info] dev 0x7fe6a0002630 (3-3) has parent 0x563af38b74d0 (usb3) port 3
[13.853072] [000090b7] libusb: debug [usbi_wait_for_events] poll() returned 1
[13.853089] [000090b7] libusb: debug [handle_event_trigger] event triggered
[13.853099] [000090b7] libusb: debug [handle_event_trigger] hotplug message received
[13.853110] [000090b7] libusb: debug [libusb_get_device_descriptor]  
Device attached: 2109:2817
[13.853138] [000090b7] libusb: debug [libusb_open] open 3.44
[13.968254] [000090b7] libusb: debug [usbi_add_event_source] add fd 7 events 4
Error getting manufacturer string: LIBUSB_ERROR_BUSY 
Error getting product string: LIBUSB_ERROR_BUSY 
[13.968292] [000090b7] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[13.968296] [000090b7] libusb: debug [handle_events] event sources modified, reallocating event data
[13.968303] [000090b7] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms
[15.821050] [000090c5] libusb: debug [linux_enumerate_device] busnum 4 devaddr 27 session_id 1051
[15.821079] [000090c5] libusb: debug [linux_enumerate_device] allocating new device for 4/27 (session 1051)
[15.821144] [000090c5] libusb: debug [linux_get_parent_info] dev 0x7fe6a0004120 (4-1.1) has parent 0x7fe6a0001fa0 (4-1) port 1
[15.821190] [000090b7] libusb: debug [usbi_wait_for_events] poll() returned 1
[15.821213] [000090b7] libusb: debug [handle_event_trigger] event triggered
[15.821222] [000090b7] libusb: debug [handle_event_trigger] hotplug message received
[15.821235] [000090b7] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[15.821240] [000090b7] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms
[18.332071] [000090c5] libusb: debug [linux_enumerate_device] busnum 3 devaddr 45 session_id 813
[18.332092] [000090c5] libusb: debug [linux_enumerate_device] allocating new device for 3/45 (session 813)
[18.332136] [000090c5] libusb: debug [linux_get_parent_info] dev 0x7fe6a0004810 (3-3.5) has parent 0x7fe6a0002630 (3-3) port 5
[18.332189] [000090b7] libusb: debug [usbi_wait_for_events] poll() returned 1
[18.332194] [000090b7] libusb: debug [handle_event_trigger] event triggered
[18.332197] [000090b7] libusb: debug [handle_event_trigger] hotplug message received
[18.332208] [000090b7] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[18.332212] [000090b7] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms
[78.392372] [000090b7] libusb: debug [usbi_wait_for_events] poll() returned 0

user@user:~/libusb$ sudo dmesg

[18553.472883] usb 3-3: new high-speed USB device number 44 using xhci_hcd
[18553.623458] usb 3-3: New USB device found, idVendor=2109, idProduct=2817, bcdDevice= 5.33
[18553.623468] usb 3-3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[18553.623472] usb 3-3: Product: USB2.0 Hub             
[18553.623475] usb 3-3: Manufacturer: VIA Labs, Inc.         
[18553.625553] hub 3-3:1.0: USB hub found
[18553.625800] hub 3-3:1.0: 5 ports detected
[18553.749516] usb 4-1: new SuperSpeed USB device number 26 using xhci_hcd
[18553.771713] usb 4-1: New USB device found, idVendor=2109, idProduct=0817, bcdDevice= 5.33
[18553.771723] usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[18553.771727] usb 4-1: Product: USB3.0 Hub             
[18553.771730] usb 4-1: Manufacturer: VIA Labs, Inc.         
[18553.773532] hub 4-1:1.0: USB hub found
[18553.773834] hub 4-1:1.0: 4 ports detected
[18554.341163] usb 4-1.1: new SuperSpeed USB device number 27 using xhci_hcd
[18554.362559] usb 4-1.1: New USB device found, idVendor=0bda, idProduct=8153, bcdDevice=30.00
[18554.362563] usb 4-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=6
[18554.362564] usb 4-1.1: Product: USB 10/100/1000 LAN
[18554.362565] usb 4-1.1: Manufacturer: CMI
[18554.362566] usb 4-1.1: SerialNumber: 000001
[18554.445643] r8152-cfgselector 4-1.1: reset SuperSpeed USB device number 27 using xhci_hcd
[18554.495617] r8152 4-1.1:1.0: load rtl8153a-4 v2 02/07/20 successfully
[18554.529865] r8152 4-1.1:1.0 eth0: v1.12.13
[18558.380873] usb 3-3.5: new high-speed USB device number 45 using xhci_hcd
[18558.482483] usb 3-3.5: New USB device found, idVendor=2109, idProduct=8817, bcdDevice= 0.01
[18558.482494] usb 3-3.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[18558.482498] usb 3-3.5: Product: USB-C Multiport Adapter
[18558.482501] usb 3-3.5: Manufacturer: VIA Labs, Inc.         
[18558.482503] usb 3-3.5: SerialNumber: 0000000000000001
[18558.659558] r8152 4-1.1:1.0 enx5c857e3d381a: renamed from eth0

@mcuee mcuee added the question Technical support, will be closed if deemed not a libusb issue. Please use mailing list. label Jan 24, 2024
@mcuee
Copy link
Member

mcuee commented Jan 24, 2024

Maybe you have to wait a bit for the device to get settled with proper driver.

@ercjethava
Copy link
Author

@mcuee

I have tried adding 10sec delay before accessing attached device handle still same issue seeing.

static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data)
{
	struct libusb_device_descriptor desc;
	int rc;

	(void)ctx;
	(void)dev;
	(void)event;
	(void)user_data;

	rc = libusb_get_device_descriptor(dev, &desc);
	if (LIBUSB_SUCCESS == rc) {
		printf ("Device attached: %04x:%04x\n", desc.idVendor, desc.idProduct);
	} else {
		printf ("Device attached\n");
		fprintf (stderr, "Error getting device descriptor: %s\n",
			 libusb_strerror((enum libusb_error)rc));
	}

	if (handle) {
		libusb_close (handle);
		handle = NULL;
	}

        printf("wait for 10 seconds\n");
        sleep(10);
        printf("wait for 10 seconds done\n");
	rc = libusb_open (dev, &handle);
	if (LIBUSB_SUCCESS != rc) {
		fprintf (stderr, "Error opening device: %s\n",
			 libusb_strerror((enum libusb_error)rc));
	}

	// read manufacturer, product number
	char manu[256], prod[256];
	rc = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, (unsigned char *)manu, sizeof(manu));
	if (rc < 0) {
		printf("Error getting manufacturer string: %s \n", libusb_error_name(rc));
	} else {
		printf("Manufacturer: %s\n", manu);
	}

	rc = libusb_get_string_descriptor_ascii(handle, desc.iProduct, (unsigned char *)prod, sizeof(prod));
	if (rc < 0) {
		printf("Error getting product string: %s \n", libusb_error_name(rc));
	} else {
		printf("Product: %s\n", prod);
	}

	return 0;
}
timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.001345] [000228af] libusb: error [usbi_get_context] API misuse! Using non-default context as implicit default.
[ 0.001351] [000228af] libusb: debug [libusb_hotplug_register_callback] new hotplug cb 0x5573ccf8e9c0 with handle 1
[ 0.001353] [000228af] libusb: debug [libusb_hotplug_register_callback] new hotplug cb 0x5573ccf8e960 with handle 2
[ 0.001355] [000228af] libusb: error [usbi_get_context] API misuse! Using non-default context as implicit default.
[ 0.001358] [000228af] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.001361] [000228af] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.001364] [000228af] libusb: debug [usbi_wait_for_events] poll() 2 fds with timeout in 60000ms

-> device plugged-in

[ 5.618754] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3 detached: 0
[ 5.618784] [000228b0] libusb: debug [linux_get_device_address] scan 3-3
[ 5.618859] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=33
[ 5.618867] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: add.
[ 5.618870] [000228b0] libusb: debug [linux_enumerate_device] busnum 3 devaddr 33 session_id 801
[ 5.618876] [000228b0] libusb: debug [linux_enumerate_device] allocating new device for 3/33 (session 801)
[ 5.618934] [000228b0] libusb: debug [linux_get_parent_info] dev 0x7fb310001fa0 (3-3) has parent 0x5573ccf8f4c0 (usb3) port 3
[ 5.618969] [000228af] libusb: debug [usbi_wait_for_events] poll() returned 1
[ 5.618993] [000228af] libusb: debug [handle_event_trigger] event triggered
[ 5.619002] [000228af] libusb: debug [handle_event_trigger] hotplug message received
[ 5.619010] [000228af] libusb: debug [libusb_get_device_descriptor]  
Device attached: 2109:2817
wait for 10 seconds
[ 5.637301] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 4-1 detached: 0
[ 5.637311] [000228b0] libusb: debug [linux_get_device_address] scan 4-1
[ 5.637332] [000228b0] libusb: debug [linux_get_device_address] bus=4 dev=18
[ 5.637335] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: add.
[ 5.637337] [000228b0] libusb: debug [linux_enumerate_device] busnum 4 devaddr 18 session_id 1042
[ 5.637339] [000228b0] libusb: debug [linux_enumerate_device] allocating new device for 4/18 (session 1042)
[ 5.637354] [000228b0] libusb: debug [linux_get_parent_info] dev 0x7fb310002630 (4-1) has parent 0x5573ccf90480 (usb4) port 1
[ 6.714823] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 4-1 detached: 0
[ 6.714852] [000228b0] libusb: debug [linux_get_device_address] scan 4-1
[ 6.714952] [000228b0] libusb: debug [linux_get_device_address] bus=4 dev=18
[ 6.714965] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: change.
[ 6.714972] [000228b0] libusb: error [udev_hotplug_event] ignoring udev action change
[ 6.866641] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3 detached: 0
[ 6.866663] [000228b0] libusb: debug [linux_get_device_address] scan 3-3
[ 6.866728] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=33
[ 6.866733] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: change.
[ 6.866737] [000228b0] libusb: error [udev_hotplug_event] ignoring udev action change
[ 7.262530] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 4-1 detached: 0
[ 7.262557] [000228b0] libusb: debug [linux_get_device_address] scan 4-1
[ 7.262628] [000228b0] libusb: debug [linux_get_device_address] bus=4 dev=18
[ 7.262634] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: bind.
[ 7.414606] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3 detached: 0
[ 7.414634] [000228b0] libusb: debug [linux_get_device_address] scan 3-3
[ 7.414730] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=33
[ 7.414795] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: bind.
[ 7.442212] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 4-1.1 detached: 0
[ 7.442238] [000228b0] libusb: debug [linux_get_device_address] scan 4-1.1
[ 7.442313] [000228b0] libusb: debug [linux_get_device_address] bus=4 dev=19
[ 7.442323] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: add.
[ 7.442328] [000228b0] libusb: debug [linux_enumerate_device] busnum 4 devaddr 19 session_id 1043
[ 7.442335] [000228b0] libusb: debug [linux_enumerate_device] allocating new device for 4/19 (session 1043)
[ 7.442387] [000228b0] libusb: debug [linux_get_parent_info] dev 0x7fb310004180 (4-1.1) has parent 0x7fb310002630 (4-1) port 1
[ 7.592952] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3.3 detached: 0
[ 7.592966] [000228b0] libusb: debug [linux_get_device_address] scan 3-3.3
[ 7.593005] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=35
[ 7.593008] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: add.
[ 7.593009] [000228b0] libusb: debug [linux_enumerate_device] busnum 3 devaddr 35 session_id 803
[ 7.593012] [000228b0] libusb: debug [linux_enumerate_device] allocating new device for 3/35 (session 803)
[ 7.593038] [000228b0] libusb: debug [linux_get_parent_info] dev 0x7fb3100047f0 (3-3.3) has parent 0x7fb310001fa0 (3-3) port 3
[ 7.775176] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3.2 detached: 0
[ 7.775214] [000228b0] libusb: debug [linux_get_device_address] scan 3-3.2
[ 7.775323] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=34
[ 7.775334] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: add.
[ 7.775343] [000228b0] libusb: debug [linux_enumerate_device] busnum 3 devaddr 34 session_id 802
[ 7.775354] [000228b0] libusb: debug [linux_enumerate_device] allocating new device for 3/34 (session 802)
[ 7.775436] [000228b0] libusb: debug [linux_get_parent_info] dev 0x7fb310004e30 (3-3.2) has parent 0x7fb310001fa0 (3-3) port 2
[ 7.800892] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 4-1.1 detached: 0
[ 7.800906] [000228b0] libusb: debug [linux_get_device_address] scan 4-1.1
[ 7.800938] [000228b0] libusb: debug [linux_get_device_address] bus=4 dev=19
[ 7.800941] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: change.
[ 7.800942] [000228b0] libusb: error [udev_hotplug_event] ignoring udev action change
[ 7.956913] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3.3 detached: 0
[ 7.956926] [000228b0] libusb: debug [linux_get_device_address] scan 3-3.3
[ 7.956963] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=35
[ 7.956965] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: change.
[ 7.956966] [000228b0] libusb: error [udev_hotplug_event] ignoring udev action change
[ 7.985053] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3.2 detached: 0
[ 7.985069] [000228b0] libusb: debug [linux_get_device_address] scan 3-3.2
[ 7.985103] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=34
[ 7.985106] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: change.
[ 7.985108] [000228b0] libusb: error [udev_hotplug_event] ignoring udev action change
[ 9.076799] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 4-1.1 detached: 0
[ 9.076836] [000228b0] libusb: debug [linux_get_device_address] scan 4-1.1
[ 9.076876] [000228b0] libusb: debug [linux_get_device_address] bus=4 dev=19
[ 9.076879] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: change.
[ 9.076884] [000228b0] libusb: error [udev_hotplug_event] ignoring udev action change
[ 9.092779] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3.2 detached: 0
[ 9.092790] [000228b0] libusb: debug [linux_get_device_address] scan 3-3.2
[ 9.092816] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=34
[ 9.092818] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: bind.
[ 9.092946] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3.3 detached: 0
[ 9.092953] [000228b0] libusb: debug [linux_get_device_address] scan 3-3.3
[ 9.092985] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=35
[ 9.092987] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: bind.
[ 9.284775] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 4-1.1 detached: 0
[ 9.284803] [000228b0] libusb: debug [linux_get_device_address] scan 4-1.1
[ 9.284854] [000228b0] libusb: debug [linux_get_device_address] bus=4 dev=19
[ 9.284857] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: change.
[ 9.284858] [000228b0] libusb: error [udev_hotplug_event] ignoring udev action change
[10.160760] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 4-1.1 detached: 0
[10.160771] [000228b0] libusb: debug [linux_get_device_address] scan 4-1.1
[10.160801] [000228b0] libusb: debug [linux_get_device_address] bus=4 dev=19
[10.160805] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: change.
[10.160807] [000228b0] libusb: error [udev_hotplug_event] ignoring udev action change
[10.188866] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 4-1.1 detached: 0
[10.188880] [000228b0] libusb: debug [linux_get_device_address] scan 4-1.1
[10.188911] [000228b0] libusb: debug [linux_get_device_address] bus=4 dev=19
[10.188913] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: change.
[10.188914] [000228b0] libusb: error [udev_hotplug_event] ignoring udev action change
[10.189142] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3.5 detached: 0
[10.189149] [000228b0] libusb: debug [linux_get_device_address] scan 3-3.5
[10.189173] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=36
[10.189174] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: add.
[10.189175] [000228b0] libusb: debug [linux_enumerate_device] busnum 3 devaddr 36 session_id 804
[10.189178] [000228b0] libusb: debug [linux_enumerate_device] allocating new device for 3/36 (session 804)
[10.189191] [000228b0] libusb: debug [linux_get_parent_info] dev 0x7fb310005f00 (3-3.5) has parent 0x7fb310001fa0 (3-3) port 5
[10.524743] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3.5 detached: 0
[10.524757] [000228b0] libusb: debug [linux_get_device_address] scan 3-3.5
[10.524798] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=36
[10.524802] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: change.
[10.524804] [000228b0] libusb: error [udev_hotplug_event] ignoring udev action change
[10.552746] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 4-1.1 detached: 0
[10.552776] [000228b0] libusb: debug [linux_get_device_address] scan 4-1.1
[10.552802] [000228b0] libusb: debug [linux_get_device_address] bus=4 dev=19
[10.552805] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: bind.
[11.037278] [000228b0] libusb: debug [linux_get_device_address] getting address for device: 3-3.5 detached: 0
[11.037289] [000228b0] libusb: debug [linux_get_device_address] scan 3-3.5
[11.037323] [000228b0] libusb: debug [linux_get_device_address] bus=3 dev=36
[11.037328] [000228b0] libusb: debug [udev_hotplug_event] udev hotplug event. action: bind.
wait for 10 seconds done
[15.619205] [000228af] libusb: debug [libusb_open] open 3.33
[15.619282] [000228af] libusb: debug [usbi_add_event_source] add fd 7 events 4
Error getting manufacturer string: LIBUSB_ERROR_BUSY 
Error getting product string: LIBUSB_ERROR_BUSY 
[15.619307] [000228af] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[15.619313] [000228af] libusb: debug [handle_events] event sources modified, reallocating event data
[15.619320] [000228af] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms
[15.619330] [000228af] libusb: debug [usbi_wait_for_events] poll() returned 1
[15.619334] [000228af] libusb: debug [handle_event_trigger] event triggered
[15.619339] [000228af] libusb: debug [handle_event_trigger] hotplug message received
[15.619347] [000228af] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[15.619352] [000228af] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms

@mcuee
Copy link
Member

mcuee commented Jan 27, 2024

@mcuee

I have tried adding 10sec delay before accessing attached device handle still same issue seeing.

Please provide more details about your host, Linux distro used and your test device.
For example, you can post the output of xusb -d xxxx:xxxx and lsusb -vvv about your device. Thanks.

Reference:
https://github.com/libusb/libusb/wiki/Troubleshooting

Please also make sure you use the latest version of libusb release version like libusb-1.0.26, or better use libusb-1.0.27-rc1.
https://github.com/libusb/libusb/releases

@mcuee mcuee added the linux label Jan 27, 2024
@ercjethava
Copy link
Author

ercjethava commented Jan 27, 2024

@mcuee I have tried with multiple device seeing same issue.

I have used latest master branch to test this using provided sample code hotplugtest.c. by reading string_descriptor when attached event occurs.

user@user:/libusb$  lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.3 LTS
Release:	22.04
Codename:	jammy

user@user:/libusb$  uname -a
Linux user 6.5.0-14-generic #14~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Nov 20 18:15:30 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

user@user:~/libusb$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   examples/hotplugtest.c

no changes added to commit (use "git add" and/or "git commit -a")
user@user:~/libusb$

user@user:~/libusb$ git diff
diff --git a/examples/hotplugtest.c b/examples/hotplugtest.c
index 270fe5ac..6bcf4df5 100644
--- a/examples/hotplugtest.c
+++ b/examples/hotplugtest.c
@@ -20,6 +20,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <unistd.h>
 
 #include "libusb.h"
 
@@ -50,13 +51,30 @@ static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev,
                handle = NULL;
        }
 
+       printf("waiting for 10 seconds : start \n");
+       sleep(10);
+       printf("waiting for 10 seconds : finished \n");
        rc = libusb_open (dev, &handle);
        if (LIBUSB_SUCCESS != rc) {
                fprintf (stderr, "Error opening device: %s\n",
                         libusb_strerror((enum libusb_error)rc));
        }
 
-       done++;
+       // read manufacturer, product number
+       char manu[256], prod[256];
+       rc = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, (unsigned char *)manu, sizeof(manu));
+       if (rc < 0) {
+               printf("Error getting manufacturer string: %s \n", libusb_error_name(rc));
+       } else {
+               printf("Manufacturer: %s\n", manu);
+       }
+
+       rc = libusb_get_string_descriptor_ascii(handle, desc.iProduct, (unsigned char *)prod, sizeof(prod));
+       if (rc < 0) {
+               printf("Error getting product string: %s \n", libusb_error_name(rc));
+       } else {
+               printf("Product: %s\n", prod);
+       }
 
        return 0;
 }
@@ -85,8 +103,6 @@ static int LIBUSB_CALL hotplug_callback_detach(libusb_context *ctx, libusb_devic
                handle = NULL;
        }
 
-       done++;
-
        return 0;
 }
 
@@ -95,12 +111,16 @@ int main(int argc, char *argv[])
        libusb_hotplug_callback_handle hp[2];
        int product_id, vendor_id, class_id;
        int rc;
+       libusb_context *ctx = NULL;
+       // vendor_id  = (argc > 1) ? (int)strtol (argv[1], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
+       // product_id = (argc > 2) ? (int)strtol (argv[2], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
+       /* register callbcak only for USB hub device */
+       vendor_id  = 0x2109;
+       product_id = 0x2817;
 
-       vendor_id  = (argc > 1) ? (int)strtol (argv[1], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
-       product_id = (argc > 2) ? (int)strtol (argv[2], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
        class_id   = (argc > 3) ? (int)strtol (argv[3], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
 
-       rc = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0);
+       rc = libusb_init_context(&ctx, /*options=*/NULL, /*num_options=*/0);
        if (LIBUSB_SUCCESS != rc)
        {
                printf ("failed to initialise libusb: %s\n",
@@ -108,6 +128,14 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
        }
 
+       rc = libusb_set_option (ctx, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG);
+       if (LIBUSB_SUCCESS != rc)
+       {
+               printf ("failed to set option: %s\n",
+                       libusb_strerror((enum libusb_error)rc));
+               return EXIT_FAILURE;
+       }
+
        if (!libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) {
                printf ("Hotplug capabilities are not supported on this platform\n");
                libusb_exit (NULL);
@@ -130,7 +158,7 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
        }
 
-       while (done < 2) {
+       while (1) {
                rc = libusb_handle_events (NULL);
                if (LIBUSB_SUCCESS != rc)
                        printf ("libusb_handle_events() failed: %s\n",

Test1: attached USB hub to PC

user@user:~/libusb$ sudo ./examples/hotplugtest
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.004630] [000027b6] libusb: error [usbi_get_context] API misuse! Using non-default context as implicit default.
[ 0.004633] [000027b6] libusb: debug [libusb_hotplug_register_callback] new hotplug cb 0x55bec7e419d0 with handle 1
[ 0.004635] [000027b6] libusb: debug [libusb_hotplug_register_callback] new hotplug cb 0x55bec7e41970 with handle 2
[ 0.004636] [000027b6] libusb: error [usbi_get_context] API misuse! Using non-default context as implicit default.
[ 0.004639] [000027b6] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.004640] [000027b6] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.004642] [000027b6] libusb: debug [usbi_wait_for_events] poll() 2 fds with timeout in 60000ms


[ 8.383303] [000027c4] libusb: debug [linux_enumerate_device] busnum 3 devaddr 17 session_id 785
[ 8.383331] [000027c4] libusb: debug [linux_enumerate_device] allocating new device for 3/17 (session 785)
[ 8.383376] [000027c4] libusb: debug [linux_get_parent_info] dev 0x7fb108001fa0 (3-3) has parent 0x55bec7e424d0 (usb3) port 3
[ 8.383411] [000027b6] libusb: debug [usbi_wait_for_events] poll() returned 1
[ 8.383435] [000027b6] libusb: debug [handle_event_trigger] event triggered
[ 8.383442] [000027b6] libusb: debug [handle_event_trigger] hotplug message received
[ 8.383454] [000027b6] libusb: debug [libusb_get_device_descriptor]  
Device attached: 2109:2817
waiting for 10 seconds : start 
[ 8.538102] [000027c4] libusb: debug [linux_enumerate_device] busnum 4 devaddr 8 session_id 1032
[ 8.538132] [000027c4] libusb: debug [linux_enumerate_device] allocating new device for 4/8 (session 1032)
[ 8.538196] [000027c4] libusb: debug [linux_get_parent_info] dev 0x7fb108002630 (4-1) has parent 0x55bec7e43490 (usb4) port 1
[10.234882] [000027c4] libusb: debug [linux_enumerate_device] busnum 3 devaddr 18 session_id 786
[10.234916] [000027c4] libusb: debug [linux_enumerate_device] allocating new device for 3/18 (session 786)
[10.234976] [000027c4] libusb: debug [linux_get_parent_info] dev 0x7fb1080040d0 (3-3.2) has parent 0x7fb108001fa0 (3-3) port 2
[10.235146] [000027c4] libusb: debug [linux_enumerate_device] busnum 4 devaddr 9 session_id 1033
[10.235157] [000027c4] libusb: debug [linux_enumerate_device] allocating new device for 4/9 (session 1033)
[10.235208] [000027c4] libusb: debug [linux_get_parent_info] dev 0x7fb1080048a0 (4-1.1) has parent 0x7fb108002630 (4-1) port 1
[10.394055] [000027c4] libusb: debug [linux_enumerate_device] busnum 3 devaddr 19 session_id 787
[10.394083] [000027c4] libusb: debug [linux_enumerate_device] allocating new device for 3/19 (session 787)
[10.394161] [000027c4] libusb: debug [linux_get_parent_info] dev 0x7fb108004f10 (3-3.3) has parent 0x7fb108001fa0 (3-3) port 3
[12.814608] [000027c4] libusb: debug [linux_enumerate_device] busnum 3 devaddr 20 session_id 788
[12.814631] [000027c4] libusb: debug [linux_enumerate_device] allocating new device for 3/20 (session 788)
[12.814674] [000027c4] libusb: debug [linux_get_parent_info] dev 0x7fb108006310 (3-3.5) has parent 0x7fb108001fa0 (3-3) port 5
waiting for 10 seconds : finished 
[18.383746] [000027b6] libusb: debug [libusb_open] open 3.17
[18.383859] [000027b6] libusb: debug [usbi_add_event_source] add fd 7 events 4
Error getting manufacturer string: LIBUSB_ERROR_BUSY 
Error getting product string: LIBUSB_ERROR_BUSY 
[18.383890] [000027b6] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[18.383896] [000027b6] libusb: debug [handle_events] event sources modified, reallocating event data
[18.383902] [000027b6] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms
[18.383915] [000027b6] libusb: debug [usbi_wait_for_events] poll() returned 1
[18.383920] [000027b6] libusb: debug [handle_event_trigger] event triggered
[18.383924] [000027b6] libusb: debug [handle_event_trigger] hotplug message received
[18.383933] [000027b6] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[18.383939] [000027b6] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms

user@user:~/libusb$ lsusb -d 2109:2817 -v

Bus 003 Device 017: ID 2109:2817 VIA Labs, Inc. USB2.0 Hub             
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.10
  bDeviceClass            9 Hub
  bDeviceSubClass         0 
  bDeviceProtocol         2 TT per port
  bMaxPacketSize0        64
  idVendor           0x2109 VIA Labs, Inc.
  idProduct          0x2817 
  bcdDevice            5.33
  iManufacturer           1 VIA Labs, Inc.         
  iProduct                2 USB2.0 Hub             
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0029
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 Hub
      bInterfaceSubClass      0 
      bInterfaceProtocol      1 Single TT
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0001  1x 1 bytes
        bInterval              12
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass         9 Hub
      bInterfaceSubClass      0 
      bInterfaceProtocol      2 TT per port
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0001  1x 1 bytes
        bInterval              12

Test2: attached wireless Logitech mouse to USB hub

user@user:~/libusb$ sudo ./examples/hotplugtest
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.004398] [0000244f] libusb: error [usbi_get_context] API misuse! Using non-default context as implicit default.
[ 0.004409] [0000244f] libusb: debug [libusb_hotplug_register_callback] new hotplug cb 0x55cf73bf09d0 with handle 1
[ 0.004414] [0000244f] libusb: debug [libusb_hotplug_register_callback] new hotplug cb 0x55cf73bf0970 with handle 2
[ 0.004419] [0000244f] libusb: error [usbi_get_context] API misuse! Using non-default context as implicit default.
[ 0.004427] [0000244f] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.004441] [0000244f] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.004447] [0000244f] libusb: debug [usbi_wait_for_events] poll() 2 fds with timeout in 60000ms


[ 6.515511] [0000245d] libusb: debug [linux_enumerate_device] busnum 3 devaddr 13 session_id 781
[ 6.515536] [0000245d] libusb: debug [linux_enumerate_device] allocating new device for 3/13 (session 781)
[ 6.515586] [0000245d] libusb: debug [linux_get_parent_info] dev 0x7f66d8001fa0 (3-3) has parent 0x55cf73bf14d0 (usb3) port 3
[ 6.515632] [0000244f] libusb: debug [usbi_wait_for_events] poll() returned 1
[ 6.515655] [0000244f] libusb: debug [handle_event_trigger] event triggered
[ 6.515663] [0000244f] libusb: debug [handle_event_trigger] hotplug message received
[ 6.515683] [0000244f] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 6.515691] [0000244f] libusb: debug [usbi_wait_for_events] poll() 2 fds with timeout in 60000ms
[ 6.669104] [0000245d] libusb: debug [linux_enumerate_device] busnum 4 devaddr 6 session_id 1030
[ 6.669133] [0000245d] libusb: debug [linux_enumerate_device] allocating new device for 4/6 (session 1030)
[ 6.669164] [0000245d] libusb: debug [linux_get_parent_info] dev 0x7f66d8002630 (4-1) has parent 0x55cf73bf2490 (usb4) port 1
[ 6.669188] [0000244f] libusb: debug [usbi_wait_for_events] poll() returned 1
[ 6.669198] [0000244f] libusb: debug [handle_event_trigger] event triggered
[ 6.669204] [0000244f] libusb: debug [handle_event_trigger] hotplug message received
[ 6.669211] [0000244f] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 6.669215] [0000244f] libusb: debug [usbi_wait_for_events] poll() 2 fds with timeout in 60000ms
[ 8.405659] [0000245d] libusb: debug [linux_enumerate_device] busnum 4 devaddr 7 session_id 1031
[ 8.405689] [0000245d] libusb: debug [linux_enumerate_device] allocating new device for 4/7 (session 1031)
[ 8.405754] [0000245d] libusb: debug [linux_get_parent_info] dev 0x7f66d8004120 (4-1.1) has parent 0x7f66d8002630 (4-1) port 1
[ 8.405794] [0000244f] libusb: debug [usbi_wait_for_events] poll() returned 1
[ 8.405822] [0000244f] libusb: debug [handle_event_trigger] event triggered
[ 8.405831] [0000244f] libusb: debug [handle_event_trigger] hotplug message received
[ 8.405846] [0000244f] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 8.405854] [0000244f] libusb: debug [usbi_wait_for_events] poll() 2 fds with timeout in 60000ms
[ 8.436481] [0000245d] libusb: debug [linux_enumerate_device] busnum 3 devaddr 14 session_id 782
[ 8.436497] [0000245d] libusb: debug [linux_enumerate_device] allocating new device for 3/14 (session 782)
[ 8.436535] [0000245d] libusb: debug [linux_get_parent_info] dev 0x7f66d8004770 (3-3.2) has parent 0x7f66d8001fa0 (3-3) port 2
[ 8.436557] [0000244f] libusb: debug [usbi_wait_for_events] poll() returned 1
[ 8.436569] [0000244f] libusb: debug [handle_event_trigger] event triggered
[ 8.436574] [0000244f] libusb: debug [handle_event_trigger] hotplug message received
[ 8.436581] [0000244f] libusb: debug [libusb_get_device_descriptor]  
Device attached: 046d:0a7a
waiting for 10 seconds : start 
[ 8.588664] [0000245d] libusb: debug [linux_enumerate_device] busnum 3 devaddr 15 session_id 783
[ 8.588689] [0000245d] libusb: debug [linux_enumerate_device] allocating new device for 3/15 (session 783)
[ 8.588767] [0000245d] libusb: debug [linux_get_parent_info] dev 0x7f66d8004e40 (3-3.3) has parent 0x7f66d8001fa0 (3-3) port 3
[11.033165] [0000245d] libusb: debug [linux_enumerate_device] busnum 3 devaddr 16 session_id 784
[11.033190] [0000245d] libusb: debug [linux_enumerate_device] allocating new device for 3/16 (session 784)
[11.033241] [0000245d] libusb: debug [linux_get_parent_info] dev 0x7f66d8005480 (3-3.5) has parent 0x7f66d8001fa0 (3-3) port 5
waiting for 10 seconds : finished 
[18.436845] [0000244f] libusb: debug [libusb_open] open 3.14
[18.436940] [0000244f] libusb: debug [usbi_add_event_source] add fd 7 events 4
Error getting manufacturer string: LIBUSB_ERROR_BUSY 
Error getting product string: LIBUSB_ERROR_BUSY 
[18.436965] [0000244f] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[18.436970] [0000244f] libusb: debug [handle_events] event sources modified, reallocating event data
[18.436975] [0000244f] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms
[18.436986] [0000244f] libusb: debug [usbi_wait_for_events] poll() returned 1
[18.436989] [0000244f] libusb: debug [handle_event_trigger] event triggered
[18.436994] [0000244f] libusb: debug [handle_event_trigger] hotplug message received
[18.437003] [0000244f] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[18.437006] [0000244f] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms


user@user:~/libusb$ lsusb -d 046d:0a7a -v

Bus 003 Device 014: ID 046d:0a7a Logitech, Inc. Logi USB Headset
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x046d Logitech, Inc.
  idProduct          0x0a7a 
  bcdDevice            0.15
  iManufacturer           1 Logitech
  iProduct                2 Logi USB Headset
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0114
    bNumInterfaces          4
    bConfigurationValue     1
    iConfiguration          4 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      1 Control Device
      bInterfaceProtocol      0 
      iInterface              0 
      AudioControl Interface Descriptor:
        bLength                10
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdADC               1.00
        wTotalLength       0x0069
        bInCollection           2
        baInterfaceNr(0)        1
        baInterfaceNr(1)        2
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID             1
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bNrChannels             2
        wChannelConfig     0x0003
          Left Front (L)
          Right Front (R)
        iChannelNames           0 
        iTerminal               0 
      AudioControl Interface Descriptor:
        bLength                10
        bDescriptorType        36
        bDescriptorSubtype      6 (FEATURE_UNIT)
        bUnitID                 2
        bSourceID               8
        bControlSize            1
        bmaControls(0)       0x01
          Mute Control
        bmaControls(1)       0x02
          Volume Control
        bmaControls(2)       0x02
          Volume Control
        iFeature                4 
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID             3
        wTerminalType      0x0301 Speaker
        bAssocTerminal          4
        bSourceID               2
        iTerminal               0 
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID             6
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bSourceID               5
        iTerminal               0 
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      6 (FEATURE_UNIT)
        bUnitID                 5
        bSourceID               4
        bControlSize            1
        bmaControls(0)       0x03
          Mute Control
          Volume Control
        bmaControls(1)       0x00
        iFeature                6 
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID             4
        wTerminalType      0x0201 Microphone
        bAssocTerminal          3
        bNrChannels             1
        wChannelConfig     0x0001
          Left Front (L)
        iChannelNames           0 
        iTerminal               0 
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID            13
        wTerminalType      0x0201 Microphone
        bAssocTerminal          3
        bNrChannels             1
        wChannelConfig     0x0001
          Left Front (L)
        iChannelNames           0 
        iTerminal               5 
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      6 (FEATURE_UNIT)
        bUnitID                 7
        bSourceID              13
        bControlSize            1
        bmaControls(0)       0x03
          Mute Control
          Volume Control
        bmaControls(1)       0x00
        iFeature                5 
      AudioControl Interface Descriptor:
        bLength                13
        bDescriptorType        36
        bDescriptorSubtype      4 (MIXER_UNIT)
        bUnitID                 8
        bNrInPins               2
        baSourceID(0)           1
        baSourceID(1)           7
        bNrChannels             2
        wChannelConfig     0x0003
          Left Front (L)
          Right Front (R)
        iChannelNames           0 
        bmControls(0)        0x00
        iMixer                  0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0 
      iInterface              0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0 
      iInterface              0 
      AudioStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink           1
        bDelay                  3 frames
        wFormatTag         0x0001 PCM
      AudioStreaming Interface Descriptor:
        bLength                23
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bNrChannels             2
        bSubframeSize           2
        bBitResolution         16
        bSamFreqType            5 Discrete
        tSamFreq[ 0]         8000
        tSamFreq[ 1]        16000
        tSamFreq[ 2]        32000
        tSamFreq[ 3]        44100
        tSamFreq[ 4]        48000
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes           13
          Transfer Type            Isochronous
          Synch Type               Synchronous
          Usage Type               Data
        wMaxPacketSize     0x00c0  1x 192 bytes
        bInterval               1
        bRefresh                0
        bSynchAddress           0
        AudioStreaming Endpoint Descriptor:
          bLength                 7
          bDescriptorType        37
          bDescriptorSubtype      1 (EP_GENERAL)
          bmAttributes         0x01
            Sampling Frequency
          bLockDelayUnits         1 Milliseconds
          wLockDelay         0x0004
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0 
      iInterface              0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0 
      iInterface              0 
      AudioStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink           6
        bDelay                  3 frames
        wFormatTag         0x0001 PCM
      AudioStreaming Interface Descriptor:
        bLength                23
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bNrChannels             1
        bSubframeSize           2
        bBitResolution         16
        bSamFreqType            5 Discrete
        tSamFreq[ 0]         8000
        tSamFreq[ 1]        16000
        tSamFreq[ 2]        32000
        tSamFreq[ 3]        44100
        tSamFreq[ 4]        48000
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes           13
          Transfer Type            Isochronous
          Synch Type               Synchronous
          Usage Type               Data
        wMaxPacketSize     0x0060  1x 96 bytes
        bInterval               1
        bRefresh                0
        bSynchAddress           0
        AudioStreaming Endpoint Descriptor:
          bLength                 7
          bDescriptorType        37
          bDescriptorSubtype      1 (EP_GENERAL)
          bmAttributes         0x01
            Sampling Frequency
          bLockDelayUnits         1 Milliseconds
          wLockDelay         0x0004
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        3
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength     138
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               8

@tormodvolden
Copy link
Contributor

The title says "unable to read device descriptor". Does libusb_get_device_descriptor() fail?

@mcuee
Copy link
Member

mcuee commented Apr 27, 2024

@ercjethava

Any update on this issue? I will close this issue if we do not get the reply for a long time (say two months).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linux question Technical support, will be closed if deemed not a libusb issue. Please use mailing list.
Projects
None yet
Development

No branches or pull requests

3 participants