Where is the Serial Number of USB device stored?

Hi guys,
I may be asking something off-topic here but I cannot find the information elsewhere (at least using my google searches).

I just want to ask where the serial number of a USB device (same one seen in USBDeview) is stored? I assume it’s on the hardware but another question I have is if the driver of the device responsible in retrieving the serial number or is it purely Windows Kernel that retrieve it?

And one last question on the hardware side is it provided by the firmware (example: Windows CE variant) or the underlying itself?

Hi Michael,

The serial number of a USB device is referenced by the device descriptor. So you should first read the device descriptor and then retrieve the string descriptor referenced by the iSerialNumber field of the USB_DEVICE_DESCRIPTOR structure. If iSerialNumber is zero the device has not a valid serial number.

If you need to retrieve the serial number from user mode, take a look at the usbview application that is included with the DDK.

Hope this helps.

Eugenio Barahona

Not all devices have serial numbers like Eugenio mentioned. And there is
no industry standard serial number nomenclature for USB devices like there
is for MAC addresses. So just beware that you can’t rely on the serial
number if you are trying to reliably track devices across across ports or
systems.

On Thu, Feb 4, 2016 at 9:19 AM, wrote:

> Hi Michael,
>
> The serial number of a USB device is referenced by the device descriptor.
> So you should first read the device descriptor and then retrieve the string
> descriptor referenced by the iSerialNumber field of the
> USB_DEVICE_DESCRIPTOR structure. If iSerialNumber is zero the device has
> not a valid serial number.
>
> If you need to retrieve the serial number from user mode, take a look at
> the usbview application that is included with the DDK.
>
> Hope this helps.
>
> Eugenio Barahona
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: <
> http://www.osronline.com/showlists.cfm?list=ntdev&gt;
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
></http:>

xxxxx@gmail.com wrote:

I just want to ask where the serial number of a USB device (same one seen in USBDeview) is stored? I assume it’s on the hardware but another question I have is if the driver of the device responsible in retrieving the serial number or is it purely Windows Kernel that retrieve it?

USB is a protocol bus. There are a set of standard requests that all
devices must respond to. That includes GetDescriptor requests. The
first action with the device (after assigning a device ID) is to request
the device descriptor. That includes the VID and PID, and string IDs
for the manufacturer, product, and serial number. That’s done by the
stock USB drivers, so they know what kind of driver to load. When
someone needs the serial number, they’ll send a separate GetDescriptor
request for that string ID. Because the serial number is part of the
hardware ID, the stock USB drivers will also fetch that.

UsbView gets the serial numbers by talking directly to the USB hub
driver, below the level of the function driver for the device. The hub
drivers have a small set of ioctls to fetch useful information, to
support applications like UsbView.

As Eugenio said, the string descriptors are all optional.

And one last question on the hardware side is it provided by the firmware (example: Windows CE variant) or the underlying itself?

That’s an implementation detail in the device hardware. With some
chips, the firmware just sets up a pointer to the strings and the
underlying hardware handles the request. With some chips, all standard
requests are handled by code in the firmware. It doesn’t really matter
– when you’re designing a device, you do what your hardware requires.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

>stored? I assume it’s on the hardware

Yes. A field of the standard USB descriptor, hardcoded to the hardware and queried via USB standard-defined ways (IIRC control pipe 0).

It is just near the vendor/model codes.

but another question I have is if the driver of the device responsible in retrieving the serial number or
is it purely Windows Kernel that retrieve it?

The underlying USB stack (usbhub.sys or so) will do it, convert it to PnP InstanceId and report the latter to kernel PnP.

And one last question on the hardware side is it provided by the firmware

Depends on how hardware is implemented.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

>Not all devices have serial numbers like Eugenio mentioned.

Yes, it is allowed by the USB spec, and in this case PnP InstanceId will be the related to USB port number.

So, you plug the device to another USB port, and another devnode is created with lengthly install process.

So just beware that you can’t rely on the serial number if you are trying to reliably track devices
across across ports or systems.

If Windows kernel PnP subsystem relies on them (if they are present) - then why he can’t rely?


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

On Thu, Feb 4, 2016 at 9:19 AM, wrote:

Hi Michael,

The serial number of a USB device is referenced by the device descriptor. So you should first read the device descriptor and then retrieve the string descriptor referenced by the iSerialNumber field of the USB_DEVICE_DESCRIPTOR structure. If iSerialNumber is zero the device has not a valid serial number.

If you need to retrieve the serial number from user mode, take a look at the usbview application that is included with the DDK.

Hope this helps.

Eugenio Barahona


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

>If Windows kernel PnP subsystem relies on them (if they are present) -
then why he can’t rely?

Because if something might not be present how can it be reliable?

Second there’s no guarantee the value will be unique. I have a batch of
USB sticks that all report the same serial number and manufacturers are
free to assign any number they want so you could have different
manufacturers assigning the same number. And if the serial number is all
you are going on, then again it’s not reliable.

On Thu, Feb 4, 2016 at 3:19 PM, Maxim S. Shatskih
wrote:

> >Not all devices have serial numbers like Eugenio mentioned.
>
> Yes, it is allowed by the USB spec, and in this case PnP InstanceId will
> be the related to USB port number.
>
> So, you plug the device to another USB port, and another devnode is
> created with lengthly install process.
>
> >So just beware that you can’t rely on the serial number if you are trying
> to reliably track devices
> >across across ports or systems.
>
> If Windows kernel PnP subsystem relies on them (if they are present) -
> then why he can’t rely?
>
> –
> Maxim S. Shatskih
> Microsoft MVP on File System And Storage
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
> On Thu, Feb 4, 2016 at 9:19 AM,
> wrote:
>
>> Hi Michael,
>>
>> The serial number of a USB device is referenced by the device
>> descriptor. So you should first read the device descriptor and then
>> retrieve the string descriptor referenced by the iSerialNumber field of the
>> USB_DEVICE_DESCRIPTOR structure. If iSerialNumber is zero the device has
>> not a valid serial number.
>>
>> If you need to retrieve the serial number from user mode, take a look at
>> the usbview application that is included with the DDK.
>>
>> Hope this helps.
>>
>> Eugenio Barahona
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list online at: <
>> http://www.osronline.com/showlists.cfm?list=ntdev&gt;
>>
>> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
>> software drivers!
>> Details at http:
>>
>> To unsubscribe, visit the List Server section of OSR Online at <
>> http://www.osronline.com/page.cfm?name=ListServer&gt;
>>
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: <
> http://www.osronline.com/showlists.cfm?list=ntdev&gt;
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
></http:></http:>

Paul McDonough wrote:

I have a batch of USB sticks that all report the same serial number

This used to generate a nice DUPLICATE_PDO blue screen back in the day :slight_smile:

> This used to generate a nice DUPLICATE_PDO blue screen back in the day :slight_smile:

There were the times… Eventually it dawned upon MS that malfunction of a USB peripheral device is not a reason to crash the whole machine. Thanks to cheap manufacturers and never-resting “security researchers”.
A duplicate USB serial number is violation of contract, so it can be treated as device malfunction. Or security-related vulnerability, if you prefer.

So there is a well known registry trick to ignore “serial numbers”:

http://blogs.msdn.com/b/microsoft_apgc_hardware_developer_support_team/archive/2013/11/10/to-ignore-a-device-s-serial-number.aspx

Regards,
– pa

Pavel A wrote:

So there is a well known registry trick to ignore “serial numbers”:

I actually used it for a different reason: we were in a manufacturing environment, and thousands upon thousands of devices would have been connected to the same machine for USB firmware download/initial programming, each with their own unique serial number…

Well, turns out Windows (or at least XP) used to get a little “unstable” with 10,000+ devnodes hanging around, like registry out-of-space errors and the like. Putting in the registry key to disable serial numbers got us right back down to one devnode per USB port.

Paul wrote:

Second there’s no guarantee the value will be unique. I have a batch
of USB sticks that all report the same serial number and manufacturers
are free to assign any number they want so you could have different
manufacturers assigning the same number. And if the serial number is
all you are going on, then again it’s not reliable.

That’s a foolish thing to do, because Windows can’t handle it. If you
plug in two devices with the same serial number simultaneously, Windows
ignores one.

Max is right. Windows relies on it, so there’s no reason for apps not
to do so.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Different manufacturers can have the same number, the uniqueness is vid+pid+serialnumber.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Friday, February 5, 2016 10:05 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Where is the Serial Number of USB device stored?

Paul wrote:
>
> Second there’s no guarantee the value will be unique. I have a batch
> of USB sticks that all report the same serial number and manufacturers
> are free to assign any number they want so you could have different
> manufacturers assigning the same number. And if the serial number is
> all you are going on, then again it’s not reliable.

That’s a foolish thing to do, because Windows can’t handle it. If you plug in two devices with the same serial number simultaneously, Windows ignores one.

Max is right. Windows relies on it, so there’s no reason for apps not to do so.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

Thanks to everyone that have replied. I apologize I wasn’t able to get back immediately. So, it seems like the serial number can be retrieved from the device descriptor coming from the device.

xxxxx@gmail.com wrote:

Thanks to everyone that have replied. I apologize I wasn’t able to get back immediately. So, it seems like the serial number can be retrieved from the device descriptor coming from the device.

Not exactly. The device descriptor contains the index of the serial
number string. It’s just a one-byte number. You then make a separate
request to fetch the string descriptor with that index. Commonly, the
manufacturer is string #1, the product name is string #2, and the serial
number is string #3.

There are three basic types of descriptors: device, configuration, and
string. They are all stored in the device, usually in an EEPROM.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.