2015-04-08 3:09 GMT+02:00 Mario St-Gelais <[email protected]>: > On Mon, Apr 06, 2015 at 07:39:35PM -0700, Philip Guenther wrote: >>On Mon, Apr 6, 2015 at 3:59 PM, Mario St-Gelais <[email protected]> >>wrote: >>> I have been playing around trying to come up with something that kind of >>> have >>> the verbosity of lsusb but use OpenBSD's #include <dev/usb/usb.h> and avoid >>> all of libusb stuff. >>> >>> I hit a wall when I try to use USB_DEVICE_GET_FDESC : >>... >>> So basically I have the following function that fails. >>> I set udf_size=25 as this is the value I get from wTotalLength shown above >>> as >>> explained in the man. >>> >>> int >>> get_usb_device_fdesc(int f, int a, struct usb_device_fdesc *u) >>> { >>> u->udf_addr = a; >>> u->udf_config_index = USB_CURRENT_CONFIG_INDEX; >>> u->udf_size=25; >>> int e = ioctl(f, USB_DEVICE_GET_FDESC, u); >>> return e; >>> } >> >>First, when a system call fails you should be looking at errno to see >>why the call failed, or at least get a hint. I strongly advise using >>the err(3) family of functions, even in test or 'toy' programs, >>because one wrong assumption can waste *hours* of time. So: >> >>#include <err.h> >> >>and then use it like >> >> if (ioctl(f, USB_DEVICE_GET_FDESC, u) == -1) >> err(1, "ioctl(GET_FDESC)"); >> >>Now, my guess in this case is that it would report "Bad Address" >>indicating the errno was EFAULT. Why? Well, let's look at usb(4): >> >> USB_DEVICE_GET_FDESC (struct usb_device_fdesc *) >> This command can be used to retrieve all descriptors for the >> given configuration of a device on the bus. The udf_addr field >> needs to be filled with the bus device address. The >> udf_config_index field needs to be filled with the configuration >> index for the relevant configuration descriptor. For convenience >> the current configuration can be specified by >> USB_CURRENT_CONFIG_INDEX. The udf_data field needs to point to a >> memory area of the size given in the udf_size field. The proper >> size can be determined by first issuing a USB_DEVICE_GET_CDESC >> command and inspecting the wTotalLength field: >>... >> >>So, where's the allocation of wTotalLength bytes of memory and the >>initialization of u->udf_data to point to it? >> >> >>Philip Guenther > > Thanks Philip. > > I made some progress. I had #include <err.h> but wasn't using it. > I read and re-read the USB_DEVICE_GET_CDESC so many times... > Indeed after implementing err function, I got "Bad Address". You were right. > So I introduced a malloc in my function. No more bad address, not I get > "Device not configured". > > int > get_usb_device_fdesc(int f, int a, struct usb_device_fdesc *u) > { > u->udf_addr = a; > u->udf_config_index = USB_CURRENT_CONFIG_INDEX; > u->udf_size=25; //25 not to be hardcoded > if ((u->udf_data=malloc(25)) == NULL) > err(1, "malloc"); > if (ioctl(f, USB_DEVICE_GET_FDESC, u) == -1) > err(1, "ioctl(GET_FDESC)"); > return 0; //fwiw > } > > Not quite sur what that udf_data is supposed to contain, I have some more > homework to do. > > (gdb) p *u > $1 = {udf_bus = 0 '\0', udf_addr = 1 '\001', udf_config_index = -1, > udf_size = 25, udf_data = 0x12dea87fd280 "\t\002\031"} > (gdb) >
udf_data will contain the data you requested :) First a config descriptor, then your first interface descriptor followed by an HID descriptor for HID device then endpoint descriptors. I have a similar project on the stoves and I have the feeling the USB thing is a rabbit hole. -- Cordialement, Coues Ludovic +336 148 743 42

