Question

I am trying to get the firmware version of my usb device. As per the specification:

When using the USB interface, the commands are sent as CONTROL READ requests, where the request byte is the command, and the Index and Value are additional parameters sent to the Device. If the PC is requesting data, it will be returned in the endpoint 0 IN buffer.

Command               Description              Device Response / Notes 
  a             Request firmware version     The device returns 4 bytes containing the version number in ASCII.

Now to request firmware version, I do the following:

char buffer[4];
unsigned char a = 'a';
r = libusb_control_transfer(dev_handle,0,a,0,0,buffer,4,0);

But the program stops responding, and I can't get any result.

Was it helpful?

Solution

There are two things I see that could be wrong here:

The character value 'a' is equal to 0x61, I think what you want is 0x0A for your bRequest parameter.

Also, since you are getting data from the device you probably want to setup bmRequestType properly. 0x80 is the mask that represents data going from the device to the host, right now you are specifying that you are giving data to the device.

In these cases a USB analyzer is highly useful, so you can look at the bus to get an idea of exactly what the setup packet contains that is sent to your device as well as what it's response to the host is.

Here is the modified code:

char buffer[4];
r = libusb_control_transfer(dev_handle,0x80,0x0a,0,0,buffer,4,0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top