{"id":18582770,"url":"https://github.com/gikoskos/usbids","last_synced_at":"2026-04-25T23:36:46.275Z","repository":{"id":98957734,"uuid":"43296185","full_name":"Gikoskos/usbids","owner":"Gikoskos","description":"The USB list from the www.linux-usb.org/usb.ids website as a C array","archived":false,"fork":false,"pushed_at":"2018-09-24T14:30:10.000Z","size":615,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-16T04:13:16.857Z","etag":null,"topics":["c","python3"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gikoskos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-09-28T11:04:53.000Z","updated_at":"2021-03-10T20:01:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"f9b42d4d-0559-4995-adab-0efc27e30ef1","html_url":"https://github.com/Gikoskos/usbids","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Gikoskos/usbids","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gikoskos%2Fusbids","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gikoskos%2Fusbids/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gikoskos%2Fusbids/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gikoskos%2Fusbids/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gikoskos","download_url":"https://codeload.github.com/Gikoskos/usbids/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gikoskos%2Fusbids/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32280979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T18:29:39.964Z","status":"ssl_error","status_checked_at":"2026-04-25T18:29:32.149Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","python3"],"created_at":"2024-11-07T00:14:19.735Z","updated_at":"2026-04-25T23:36:46.259Z","avatar_url":"https://github.com/Gikoskos.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The USB.IDS list as a C array\n\nThe usb.ids list from [this link](http://www.linux-usb.org/usb.ids) as an array that can be used and indexed on the run-time in C programs. Binary search included.\n\n```c\n#include \"usbids.h\"\n#include \u003cstdio.h\u003e\n\n...\n\nUsbDevStruct *usbdev;\n\nusbdev = UsbListFind(0x041e, 0x4095);\nif (usbdev) {\n  printf('Vendor: %s, Device: %s\\n', usbdev-\u003eVendor, usbdev-\u003eDevice);\n}\n```\n\nNote that this is just an array of structs that contain the USB vendor and device IDs in numeric format (the default is `unsigned short`), and the USB vendor and device names as a null-terminated `char*` array.\n\nAnything related to device classes, subclasses, HIDs etc, on the ubs.ids list, is ignored.\n\n## How to use\n\nIn the repo you'll find a python script that downloads the current usb.ids list and generates the source files on-the-fly.\n\nTo run it you'll need Python 3:\n\n`python3 make_usbids.py`\n\nThe files `usbids.h` and `usbids.c` will be created which you can include in your build system.\n\nOnly dependency is a C99 (at least) compatible standard library.\n\n## Documentation\n\n```c\n//represents a USB device\ntypedef struct {\n  \t//the device's vendor ID\n\tunsigned short VendorID;\n\n  \t//the device's numerical ID\n\tunsigned short DeviceID;\n\n  \t//the name of the vendor as a null-terminated character array\n\tchar* Vendor;\n\n  \t//the name of the device as a null-terminated character array\n\tchar* Device;\n} UsbDevStruct;\n```\n\nSo, for example, for this entry in the usb.ids list:\n\n```\n03e8  EndPoints, Inc.\n\t0004  SE401 Webcam\n```\n\nthe struct would look like this:\n\n```c\nVendorID = 0x03e8;\nDeviceID = 0x0004;\nVendor = \"EndPoints, Inc.\";\nDevice = \"SE401 Webcam\";\n```\n\n------\n\n```c\n//each item of this array is an entry in the usb.ids list\nUsbDevStruct UsbList[];\n\n//the length of the UsbList array\nunsigned int UsbListLength;\n```\n\nNote that in the usb.ids list there are a lot of Vendors which have no corresponding device entries, eg\n\n```\n03e9  Thesys Microelectronics\n03ea  Data Broadcasting Corp.\n```\n\nThe entries for these vendors simply have their `DeviceID` and `Device` fields set to 0:\n\n```c\nVendorID = 0x03e9;\nDeviceID = 0;\nVendor = \"Thesys Microelectronics\";\nDevice = NULL;\n\nVendorID = 0x03ea;\nDeviceID = 0;\nVendor = \"Data Broadcasting Corp.\";\nDevice = NULL;\n```\n\nTo check if an entry is a standalone vendor entry **_don't_** compare the entry's `DeviceID` with 0:\n\n```c\nUsbDevStruct *dev = UsbListFind(0x03ee, 0x0000);\n\nif (dev-\u003eDeviceID == 0) { //Bad\n  printf('This is a standalone vendor entry\\n');\n}\n```\n\nbecause there are devices that actually have 0 as their `DeviceID`, eg\n\n```\n03ee  Mitsumi\n\t0000  CD-R/RW Drive\n```\n\nInstead, check if that entry has a `Device` name:\n\n```c\nif (dev-\u003eDevice == NULL) { //Good\n  printf('This is a standalone vendor entry\\n');\n}\n```\n\n------\n\n```c\n//searches the UsbList array for a USB device that has `vendor` and `device` IDs\n//returns a pointer to the UsbList array item if the search was successful, NULL otherwise\nUsbDevStruct *UsbListFind(unsigned short vendor, unsigned short device);\n```\n\n`UsbListFind` uses the standard library's `bsearch` under the hood.\n\n------\n\n```c\n//returns 1 if the UsbList array is sorted, 0 otherwise\nint UsbListIsSorted(void);\n\n//runs various tests that check the integrity of the array\n//these tests should finish without any failed assertions\nvoid UsbListRunTests(void);\n```\n\nThese are utility functions that I used to test the integrity of the array. Feel free to delete them if you don't want to use them.\n\n## Custom symbol names/types\n\nSince the source files are generated on-the-fly, it's possible to set your own symbol names/types by changing the values of the dictionary `usbid_struct` on the `make_usbids.py` script:\n\n```python\nusbid_struct = {\n    'name': 'UsbDevStruct',\n    'vendorid': 'VendorID',\n    'deviceid': 'DeviceID',\n    'vendorname': 'Vendor',\n    'devicename': 'Device',\n    'nametype': 'char*',\n    'idtype': 'unsigned short',\n    'arrayname': 'UsbList'\n}\n```\n\nFor example, you can set the values of the dictionary to resemble names that are more C-like:\n\n```python\nusbid_struct = {\n    'name': 'usbdev_s',\n    'vendorid': 'vid',\n    'deviceid': 'did',\n    'vendorname': 'vname',\n    'devicename': 'dname',\n    'nametype': 'char*',\n    'idtype': 'unsigned short',\n    'arrayname': 'usblist'\n}\n```\n\nThe generated symbols will be\n\n```c\ntypedef struct {\n\tunsigned short vid;\n\tunsigned short did;\n\tchar* vname;\n\tchar* dname;\n} usbdev_s;\n\nextern usbdev_s usblist[];\nextern unsigned int usblistLength;\n\nusbdev_s *usblistFind(unsigned short vendor, unsigned short device);\nint usblistIsSorted(void);\nvoid usblistRunTests(void);\n```\n\nNote that, even though it's possible to change the type of both the vendor/device ID and name members, of the `UsbDevStruct`, through the `nametype` and `idtype` keys of the dictionary above, it's not recommended to do so, unless you know what you're doing.\n\n## License\n\nThis code is in the public domain.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgikoskos%2Fusbids","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgikoskos%2Fusbids","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgikoskos%2Fusbids/lists"}