diff options
Diffstat (limited to 'Userland/Utilities/lsusb.cpp')
-rw-r--r-- | Userland/Utilities/lsusb.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Userland/Utilities/lsusb.cpp b/Userland/Utilities/lsusb.cpp index 3859e064c7..da7d7f3ad1 100644 --- a/Userland/Utilities/lsusb.cpp +++ b/Userland/Utilities/lsusb.cpp @@ -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); }); } |