3

I am working on a project that involves the auto-detection of USB and firewire devices being plugged and unplugged from an OS X system. For a given device, the system needs to recognise a device when it is plugged in (no matter which port) and load a device-specific bundle to deal with it.

The key to making this work is obviously the unique identification of each device. I know that USB devices are identified by a combination of the vendor ID and product ID fields, but this does not provide a unique ID, only the "kind" of device. If I have two devices the same and I plug both of them in to the computer, I would like some way to distinguish them. Is there a general and reliable way to do this, perhaps using other fields in the USB descriptor?

A related question, how does this work for USB serial ports? Suppose I plug in two USB serial ports of the same make/model. OS X should give them unique inodes in the /dev tree. However, suppose it calls them /dev/usbserial1 and /dev/usbserial2. If I then unplug the ports and plug in only one one of them, will that port be given the same name as it previously had, or will it just get /dev/usbserial1 (since it is the only) port plugged in?

Same question for firewire devices, although I think firewire devices are supposed to have a 64-bit GUID. In this case I am looking for someone to verify that using the GUID for firewire device identification would be reliable. In other words, if I plugged in two separate cameras of the same make and model, would I expect them to have different GUIDs?

I know I could test some of these with the appropriate hardware, but I don't have multiple bits of hardware at this time, so I am hoping someone may know at least some of the answers to the above questions.

Ilya
  • 5,533
  • 2
  • 29
  • 57
OzBandit
  • 1,044
  • 7
  • 14

2 Answers2

1

With luck, your USB devices should have unique serial numbers, in addition to the VID/PID combination. If you're enumerating IOUSBDevice objects, look at the USB Serial Number property.

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
  • Ok, thanks. By "with luck" does this mean some devices may not provide serial numbers? – OzBandit Jun 09 '11 at 13:11
  • 1
    @David: It means that there's no real requirement for this to be present (nor for it to be unique, as there aren't any requirements for the contents other than being Unicode). but it seems reasonable to assume that if it does exist, it will be unique. – Hasturkun Jun 09 '11 at 13:20
  • The [USB Spec](http://www.usb.org/developers/docs/) says that *if* there is a serial number, it **must** be unique. Beware: there are a few cheap chips out there that do not obey this rule. The serial number itself is optional. – Turbo J Jun 09 '11 at 18:54
  • @Turbo J: I can't find that wording anywhere in the USB 2.0 or the USB 3.0 spec, can you give me the chapter/section number? – Hasturkun Jun 09 '11 at 19:15
  • 1
    Okay, I found one exception, the USB Mass Storage Bulk Only spec requires the device to have a unique serial number of at least 12 digits, other specs may have similar requirements. this is far from universal, though. – Hasturkun Jun 09 '11 at 19:29
0

On Windows, Microsoft remembers device-specific settings by:

  • the device's serial number (the iSerialNumber field in the USB device descriptor), if available
  • or otherwise, by the "path" to the device: its bus (i.e. what hub it's plugged into etc.) + USB VID and PID

Without serial numbers, USB devices are virtually indistinguishable. You could tell apart different USB disk drives, but for devices which have no non-volatile memory of any kind (and many USB devices fall into this category), they are just indistinguishable, so you just have to make the best effort to do what the user expects.

Ilya
  • 5,533
  • 2
  • 29
  • 57