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 //usage:#define lsusb_trivial_usage NOUSAGE_STR
11 //usage:#define lsusb_full_usage ""
15 static int FAST_FUNC
fileAction(
17 struct stat
*statbuf UNUSED_PARAM
,
18 void *userData UNUSED_PARAM
,
19 int depth UNUSED_PARAM
)
23 char *busnum
= NULL
, *devnum
= NULL
;
24 int product_vid
= 0, product_did
= 0;
25 char *uevent_filename
= concat_path_file(fileName
, "/uevent");
27 parser
= config_open2(uevent_filename
, fopen_for_read
);
28 free(uevent_filename
);
30 while (config_read(parser
, tokens
, 4, 2, "\\/=", PARSE_NORMAL
)) {
31 if ((parser
->lineno
== 1) && strcmp(tokens
[0], "DEVTYPE") == 0) {
35 if (strcmp(tokens
[0], "PRODUCT") == 0) {
36 product_vid
= xstrtou(tokens
[1], 16);
37 product_did
= xstrtou(tokens
[2], 16);
41 if (strcmp(tokens
[0], "BUSNUM") == 0) {
42 busnum
= xstrdup(tokens
[1]);
46 if (strcmp(tokens
[0], "DEVNUM") == 0) {
47 devnum
= xstrdup(tokens
[1]);
54 printf("Bus %s Device %s: ID %04x:%04x\n", busnum
, devnum
, product_vid
, product_did
);
62 int lsusb_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
63 int lsusb_main(int argc UNUSED_PARAM
, char **argv UNUSED_PARAM
)
65 /* no options, no getopt */
67 recursive_action("/sys/bus/usb/devices",