mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +00:00
Userland/Libraries: Add LibUSBDB library
Simple clone of LibPCIDB to support USB IDs instead of PCI ones. The format is basically identical, besides a few changes of the double tab fields.
This commit is contained in:
parent
119b8a2692
commit
01cd474930
7 changed files with 338 additions and 2 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibUSBDB/Database.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -27,6 +28,11 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (unveil("/res/usb.ids", "r") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unveil(nullptr, nullptr) < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
|
@ -38,6 +44,11 @@ int main(int argc, char** argv)
|
|||
|
||||
Core::DirIterator usb_devices("/proc/bus/usb", Core::DirIterator::SkipDots);
|
||||
|
||||
RefPtr<USBDB::Database> usb_db = USBDB::Database::open();
|
||||
if (!usb_db) {
|
||||
warnln("Failed to open usb.ids");
|
||||
}
|
||||
|
||||
while (usb_devices.has_next()) {
|
||||
auto full_path = LexicalPath(usb_devices.next_full_path());
|
||||
|
||||
|
@ -52,13 +63,18 @@ int main(int argc, char** argv)
|
|||
auto json = JsonValue::from_string(contents);
|
||||
VERIFY(json.has_value());
|
||||
|
||||
json.value().as_array().for_each([bus_id](auto& value) {
|
||||
json.value().as_array().for_each([bus_id, usb_db](auto& value) {
|
||||
auto& device_descriptor = value.as_object();
|
||||
|
||||
auto vendor_id = device_descriptor.get("vendor_id").to_u32();
|
||||
auto product_id = device_descriptor.get("product_id").to_u32();
|
||||
|
||||
outln("Device {}: ID {:04x}:{:04x}", bus_id, vendor_id, product_id);
|
||||
StringView vendor_string = usb_db->get_vendor(vendor_id);
|
||||
StringView device_string = usb_db->get_device(vendor_id, product_id);
|
||||
if (device_string.is_empty())
|
||||
device_string = "Unknown Device";
|
||||
|
||||
outln("Device {}: ID {:04x}:{:04x} {} {}", bus_id, vendor_id, product_id, vendor_string, device_string);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue