[PATCH] util-linux/lsusb.c: print manufacturer/product strings if available
Aleksander Mazur
deweloper at wp.pl
Wed Dec 13 16:12:30 UTC 2023
Hi,
AFAIR similar problem applies to util-linux/lspci.c.
Do you build busybox with shell enabled?
Instead of busybox's lspci/lsusb I use 2 quite simple shell scripts (working in hush).
--
Aleksander Mazur
Dnia 2023-12-13, o godz. 16:04:02
Peter Korsgaard <peter at korsgaard.com> napisał(a):
> Just listing the vendor/product IDs is not always very helpful, so add logic
> to print the manufacturer and product strings similar to the "big" usbutils
> versions.
>
> Not all devices provide sensible strings though. The usbutils version works
> around this by falling back to looking up the vendor/product IDs in the hwdb
> and using those strings instead, which is not an option here - Instead
> simply trim() the strings for readability.
>
> lsusb | sort
> Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 001 Device 002: ID 0bda:5539 Realtek Semiconductor Corp.
> Integrated_Webcam_HD Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp. 58200
> Bus 001 Device 030: ID 8087:0aaa Intel Corp. Bluetooth 9460/9560 Jefferson
> Peak (JfP) Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 006 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 006 Device 002: ID 0bda:5487 Realtek Semiconductor Corp. Dell dock
> Bus 006 Device 003: ID 0bda:5413 Realtek Semiconductor Corp. Dell dock
> Bus 006 Device 004: ID 413c:b06e Dell Computer Corp. Dell dock
> Bus 006 Device 005: ID 0451:8142 Texas Instruments, Inc. TUSB8041 4-Port Hub
> Bus 006 Device 006: ID 0bda:402e Realtek Semiconductor Corp. USB Audio
> Bus 006 Device 007: ID 413c:1010 Dell Computer Corp. USB 2.0 Hub [MTT]
> Bus 006 Device 008: ID 413c:b06f Dell Computer Corp. Dell dock
> Bus 006 Device 009: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
> Bus 006 Device 010: ID 413c:2110 Dell Computer Corp. Dell Wired Multimedia
> Keyboard Bus 006 Device 011: ID 0451:8142 Texas Instruments, Inc. TUSB8041
> 4-Port Hub Bus 006 Device 012: ID 0451:3410 Texas Instruments, Inc. TUSB3410
> Microcontroller Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> Bus 007 Device 002: ID 0bda:0487 Realtek Semiconductor Corp. Dell dock
> Bus 007 Device 003: ID 0bda:0413 Realtek Semiconductor Corp. Dell dock
> Bus 007 Device 004: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit
> Ethernet Adapter
>
> ./busybox lsusb | sort
> Bus 001 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host
> Controller Bus 001 Device 002: ID 0bda:5539 CNFHH53Q0324300ACA10
> Integrated_Webcam_HD Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp 58200
> Bus 001 Device 030: ID 8087:0aaa
> Bus 002 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host
> Controller Bus 003 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd
> xHCI Host Controller Bus 004 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64
> xhci-hcd xHCI Host Controller Bus 005 Device 001: ID 1d6b:0002 Linux
> 6.1.0-13-amd64 dummy_hcd Dummy host controller Bus 006 Device 001: ID
> 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller Bus 006 Device
> 002: ID 0bda:5487 Dell Inc. Dell dock Bus 006 Device 003: ID 0bda:5413 Dell
> Inc. Dell dock Bus 006 Device 004: ID 413c:b06e Dell dock
> Bus 006 Device 005: ID 0451:8142
> Bus 006 Device 006: ID 0bda:402e Generic USB Audio
> Bus 006 Device 007: ID 413c:1010 USB 2.0 Hub [MTT]
> Bus 006 Device 008: ID 413c:b06f Dell dock
> Bus 006 Device 009: ID 046d:c016 Logitech Optical USB Mouse
> Bus 006 Device 010: ID 413c:2110 Dell Dell Wired Multimedia Keyboard
> Bus 006 Device 011: ID 0451:8142
> Bus 006 Device 012: ID 0451:3410 Texas Instruments TUSB3410 Boot Device
> Bus 007 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host
> Controller Bus 007 Device 002: ID 0bda:0487 Dell Inc. Dell dock
> Bus 007 Device 003: ID 0bda:0413 Dell Inc. Dell dock
> Bus 007 Device 004: ID 0bda:8153 Realtek USB 10/100/1000 LAN
>
> ./scripts/bloat-o-meter busybox_unstripped{_orig,}
> function old new delta
> trim - 101 +101
> fileAction 338 431 +93
> add_sysfs_prop - 70 +70
> open_read_close - 54 +54
> read_close - 35 +35
> .rodata 3268 3294 +26
> ------------------------------------------------------------------------------
> (add/remove: 5/0 grow/shrink: 2/0 up/down: 379/0) Total: 379 bytes
>
> Signed-off-by: Peter Korsgaard <peter at korsgaard.com>
> ---
> util-linux/lsusb.c | 28 +++++++++++++++++++++++++++-
> 1 file changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/util-linux/lsusb.c b/util-linux/lsusb.c
> index 262c70a1b..0a9e505f4 100644
> --- a/util-linux/lsusb.c
> +++ b/util-linux/lsusb.c
> @@ -24,6 +24,24 @@
>
> #include "libbb.h"
>
> +static char * FAST_FUNC add_sysfs_prop(const char *dir, const char *suffix,
> + char *buf, size_t size)
> +{
> + char *filename;
> + ssize_t len;
> +
> + filename = concat_path_file(dir, suffix);
> + len = open_read_close(filename, buf, size - 1);
> + free(filename);
> +
> + if (len < 0)
> + len = 0;
> +
> + buf[len] = '\0';
> +
> + return trim(buf);
> +}
> +
> static int FAST_FUNC fileAction(struct recursive_state *state UNUSED_PARAM,
> const char *fileName,
> struct stat *statbuf UNUSED_PARAM)
> @@ -61,7 +79,15 @@ static int FAST_FUNC fileAction(struct recursive_state
> *state UNUSED_PARAM, config_close(parser);
>
> if (busnum) {
> - printf("Bus %s Device %s: ID %04x:%04x\n", busnum, devnum,
> product_vid, product_did);
> + char name[256], *p;
> +
> + p = add_sysfs_prop(fileName, "/manufacturer", name,
> sizeof(name) - 1);
> + if (p != name)
> + p = stpcpy(p, " ");
> + add_sysfs_prop(fileName, "/product", p, name + sizeof(name)
> - p); +
> + printf("Bus %s Device %s: ID %04x:%04x %s\n", busnum, devnum,
> + product_vid, product_did, name);
> free(busnum);
> free(devnum);
> }
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: lspci
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20231213/36e1a4e9/attachment-0002.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: lsusb
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20231213/36e1a4e9/attachment-0003.ksh>
More information about the busybox
mailing list