Axel Rohde
2010-06-13 11:03:12 UTC
Hi everybody!
I've observed the following weird behaviour when obtaining the string
descriptors via libusb_get_string_descriptor_ascii( ):
I'm using usblib-1.0 on windows to communicate with a ATmega32U2 HID
device based on LUFA.
That device's firmware implements three string descriptors with the
following indices:
0x01: Manufacturer descriptor string
0x02: Product descriptor string
0xDC: SerialNumber descriptor string
All three are successfully retrieved by the standard Windows HID driver.
The unusual value for the SN descriptor string index is because of the
way LUFA implements the automatic generation of that string based on the
internal unique ID of the microcontroller.
http://www.fourwalledcubicle.com/files/MyUSB/Doc/100513/html/group___group___descriptors.html#gae91cf5b90df788954090bcbd8bf1bece
The problem arises when my software on the host tries to obtain the
serial number string by calling:
r=libusb_get_string_descriptor_ascii(pHandle,
oDeviceDescriptor.iSerialNumber, (unsigned char*) szSN, 255 );
... it returns with error code -2 (LIBUSB_ERROR_INVALID_PARAM).
I ran the xusb example on my device and it successfully manages to
obtain the SN-string, so I had a look at the xusb source to see what I
am doing wrong.
Here is an excerpt from line 688 of:
http://git.libusb.org/?p=libusb-pbatard.git;a=blob;f=examples/xusb.c;h=4ebd37a15977ef48a728658db02c7751c1a094b6;hb=HEAD
for (i=1; i<nb_strings; i++) {
if (libusb_get_string_descriptor_ascii(handle, (uint8_t)i,
string, 128) >= 0) {
printf(" String (%d/%d): \"%s\"\n", i, nb_strings-1,
string);
}
}
As you can see, it doesn't use the string index reported by the
device-descriptor (0xDC) , but a sequentially incremented counter i, so
it successfully manages to obtain the SN-string with index=3;
The funny thing, is that the device descriptor obtained by xusb states
that the SN-string-decriptor-index indeed is 220 (=0xDC).
I modified my host software accordingly and it now succeeds retrieving
the SN-string by requesting index=3 instead of index=0xDC.
Since the Windows HID driver manages to obtain the SN string, I first
thought it might be a bug in libusb-1.0, so I dived into the source of
libusb, but everything looks as it should and I can't come up with a
plausible explanation for that LIBUSB_ERROR_INVALID_PARAM error code.
Did I misunderstand the documentation of
libusb_get_string_descriptor_ascii()?
http://libusb.sourceforge.net/api-1.0/group__desc.html#gaf3f92d0a7465d49a5e61eb3f8689fae4
I assumed the descriptor index is the one reported by the device-descriptor.
Regards,
Axel.
I've observed the following weird behaviour when obtaining the string
descriptors via libusb_get_string_descriptor_ascii( ):
I'm using usblib-1.0 on windows to communicate with a ATmega32U2 HID
device based on LUFA.
That device's firmware implements three string descriptors with the
following indices:
0x01: Manufacturer descriptor string
0x02: Product descriptor string
0xDC: SerialNumber descriptor string
All three are successfully retrieved by the standard Windows HID driver.
The unusual value for the SN descriptor string index is because of the
way LUFA implements the automatic generation of that string based on the
internal unique ID of the microcontroller.
http://www.fourwalledcubicle.com/files/MyUSB/Doc/100513/html/group___group___descriptors.html#gae91cf5b90df788954090bcbd8bf1bece
The problem arises when my software on the host tries to obtain the
serial number string by calling:
r=libusb_get_string_descriptor_ascii(pHandle,
oDeviceDescriptor.iSerialNumber, (unsigned char*) szSN, 255 );
... it returns with error code -2 (LIBUSB_ERROR_INVALID_PARAM).
I ran the xusb example on my device and it successfully manages to
obtain the SN-string, so I had a look at the xusb source to see what I
am doing wrong.
Here is an excerpt from line 688 of:
http://git.libusb.org/?p=libusb-pbatard.git;a=blob;f=examples/xusb.c;h=4ebd37a15977ef48a728658db02c7751c1a094b6;hb=HEAD
for (i=1; i<nb_strings; i++) {
if (libusb_get_string_descriptor_ascii(handle, (uint8_t)i,
string, 128) >= 0) {
printf(" String (%d/%d): \"%s\"\n", i, nb_strings-1,
string);
}
}
As you can see, it doesn't use the string index reported by the
device-descriptor (0xDC) , but a sequentially incremented counter i, so
it successfully manages to obtain the SN-string with index=3;
The funny thing, is that the device descriptor obtained by xusb states
that the SN-string-decriptor-index indeed is 220 (=0xDC).
I modified my host software accordingly and it now succeeds retrieving
the SN-string by requesting index=3 instead of index=0xDC.
Since the Windows HID driver manages to obtain the SN string, I first
thought it might be a bug in libusb-1.0, so I dived into the source of
libusb, but everything looks as it should and I can't come up with a
plausible explanation for that LIBUSB_ERROR_INVALID_PARAM error code.
Did I misunderstand the documentation of
libusb_get_string_descriptor_ascii()?
http://libusb.sourceforge.net/api-1.0/group__desc.html#gaf3f92d0a7465d49a5e61eb3f8689fae4
I assumed the descriptor index is the one reported by the device-descriptor.
Regards,
Axel.