1 /* vi: set sw=4 ts=4: */
3 * lsusb implementation for busybox
5 * Copyright (C) 2009 Malek Degachi <malek-degachi@laposte.net>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 //config: bool "lsusb (3.5 kb)"
12 //config: #select PLATFORM_LINUX
14 //config: lsusb is a utility for displaying information about USB buses in the
15 //config: system and devices connected to them.
17 //config: This version uses sysfs (/sys/bus/usb/devices) only.
19 //applet:IF_LSUSB(APPLET_NOEXEC(lsusb, lsusb, BB_DIR_USR_BIN, BB_SUID_DROP, lsusb))
21 //kbuild:lib-$(CONFIG_LSUSB) += lsusb.o
23 //usage:#define lsusb_trivial_usage NOUSAGE_STR
24 //usage:#define lsusb_full_usage ""
28 static int FAST_FUNC fileAction(
30 struct stat *statbuf UNUSED_PARAM,
31 void *userData UNUSED_PARAM,
32 int depth UNUSED_PARAM)
36 char *busnum = NULL, *devnum = NULL;
37 int product_vid = 0, product_did = 0;
38 char *uevent_filename = concat_path_file(fileName, "/uevent");
40 parser = config_open2(uevent_filename, fopen_for_read);
41 free(uevent_filename);
43 while (config_read(parser, tokens, 4, 2, "\\/=", PARSE_NORMAL)) {
44 if ((parser->lineno == 1) && strcmp(tokens[0], "DEVTYPE") == 0) {
48 if (strcmp(tokens[0], "PRODUCT") == 0) {
49 product_vid = xstrtou(tokens[1], 16);
50 product_did = xstrtou(tokens[2], 16);
54 if (strcmp(tokens[0], "BUSNUM") == 0) {
55 busnum = xstrdup(tokens[1]);
59 if (strcmp(tokens[0], "DEVNUM") == 0) {
60 devnum = xstrdup(tokens[1]);
67 printf("Bus %s Device %s: ID %04x:%04x\n", busnum, devnum, product_vid, product_did);
75 int lsusb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
76 int lsusb_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
78 /* no options, no getopt */
80 recursive_action("/sys/bus/usb/devices",