summaryrefslogtreecommitdiff
path: root/Userland/Utilities/lsusb.cpp
diff options
context:
space:
mode:
authorJesse Buhagiar <jooster669@gmail.com>2021-06-10 00:24:04 +1000
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-18 17:04:57 +0430
commit01cd474930d8f8fc262647fe069bed63ddc60744 (patch)
treeb2537f00bac3da0ffe1f0cc66c59f4860fdbdeb6 /Userland/Utilities/lsusb.cpp
parent119b8a2692300e9479b28feb053c6f6af6088801 (diff)
downloadserenity-01cd474930d8f8fc262647fe069bed63ddc60744.zip
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.
Diffstat (limited to 'Userland/Utilities/lsusb.cpp')
-rw-r--r--Userland/Utilities/lsusb.cpp20
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);
});
}