Generating a unique device ID

David Zeuthen david at fubar.dk
Sun Jul 11 04:34:28 PDT 2004


On Sun, 2004-07-11 at 01:17 +0100, Jono Bacon wrote:
> Hi all,
> 
> It seems fairly common knowledge that a device ID is non-unique, but I 
> have been wondering how to determine a unique ID for a device. We will 
> need this ID to be able to send FDI files back and forth over the net.
> 
> My first assumption that a combination of the device ID and the 
> class/name could be an option. Is anyone aware of a way of generating a 
> unique ID the information that HAL can give us?
> 

HAL does generate Unique ID's for devices [1], we call it the UDI, which
is short for Unique Device Identifier and every device got a info.udi
property. The universe within this being unique is constrained to the
system though.

For a hardware database you probably don't want to use the UDI of a
device as the primary key. You probably want some kind of storage format
(RDBMS?) and a table for each bus class, e.g. something like

 Table PCIDevice
 ---------
 PRIMARY VARCHAR(80) device_id   # e.g. pci_<vendor_id>_<product_id>_...
 INT pci_vendor_id
 INT pci_product_id
 INT pci_subsystem_vendor_id
 INT pci_subsystem_product_id
 (other Vital Product Data entries...)

 Table USBDevice
 ---------
 PRIMARY VARCHAR(80) device_id
 INT usb_vendor_id
 INT usb_product_id
 (other Vital Product Data entries...)

and you might have 

 Table FDIFiles
 ------------
 PRIMARY VARCHAR(80) fdi_id
 FOREIGN VARCHAR(80) device_id
 VARCHAR(1000) fdi_file

or something; I'm just making this up (and my SQL and RDBMS knowledge is
a bit rusty) :-). 

In reality you probably want a much more sophisticated design where you
actually can generate the .fdi file from you database tables. You also
want some web user interface to the database, user concept, privileges,
signatures, moderation etc. etc.

Looking at the properties exported by HAL in hal-device-manager is a
good start I think; I'm not positive we got all of them yet :-)

Cheers,
David

[1] : As far as it's possible as some hardware is just broken. E.g. if
you plug in two USB mice and the serial number is broken for the make of
each mouse there is no way to tell them apart. 

The two mice still got a separate unique ID's (by appending a number to
one of them) but if you make them persistent (e.g. keep the HalDevice
around by setting info.persistent to TRUE[2]) and remove both and then
plug them back in they might have switched HalDevice and thus any user
data.

In general though, for everyday use, we can assume that it's possible to
generate UDI's. And we got a wealth of data to use; for instance Kay
wrote code to extract the UUID of a disk so this can (and should) be
used in the UDI computation.

[2] : This is useful if you want to have user data associated with each
device in a persistent manner, e.g. the data is there the second time
you plug in the device

_______________________________________________
hal mailing list
hal at freedesktop.org
http://freedesktop.org/mailman/listinfo/hal



More information about the Hal mailing list