windowsusb

Cannot have a zero-length USB "serial" string descriptor?


I am working on a USB hardware project, and would like the user to be able to change the device serial number. This is reported to the system via "USB string descriptor" 3.

I find that if the serial is zero-length (and therefore 32 bytes of nulls), the device doesn't even show up in (Windows) Device Manager. Whereas when it has a non-zero number of (unicode) characters followed by nulls, it works fine.

Is there any particular reason why this should be the case?


Solution

  • The serial number is transmitted as the response to a control transfer request from the host and has the format of a string descriptor, which looks like so:

    Offset  Field            Size   Description
    0       bLength          1      Size of descriptor (in bytes)
    1       bDescriptorType  1      String descriptor type (0x03)
    2       bString          n      Unicode encoded string (in UTF-16)
    

    The string descriptor has a variable length. The bString field starting at offset 2 is as long as required. The string is not null-terminated.

    The string descriptor and thus the control transfer response for an empty string would look like so:

    0x02 0x03
    

    In any case, an empty or missing serial number isn't a good idea. Most operating systems use the combination of VID, PID and serial number to uniquely identify USB devices. On Windows, it's even the basis for driver installation though Windows has a few tricks to deal with a missing serial number.

    To hear that the fixed length strings have worked on Windows, is a bit of a surprise. You cannot assume that it will work on other operation systems or even with a future Windows version.