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