Changes for kernel and Busybox
[tomato.git] / release / src / router / busybox / util-linux / lsusb.c
blob540f21ec6d61cf1f8827fceb65f046d8bf649986
1 /* vi: set sw=4 ts=4: */
2 /*
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.
8 */
10 //usage:#define lsusb_trivial_usage NOUSAGE_STR
11 //usage:#define lsusb_full_usage ""
13 #include "libbb.h"
15 static int FAST_FUNC fileAction(
16 const char *fileName,
17 struct stat *statbuf UNUSED_PARAM,
18 void *userData UNUSED_PARAM,
19 int depth UNUSED_PARAM)
21 parser_t *parser;
22 char *tokens[4];
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) {
32 break;
35 if (strcmp(tokens[0], "PRODUCT") == 0) {
36 product_vid = xstrtou(tokens[1], 16);
37 product_did = xstrtou(tokens[2], 16);
38 continue;
41 if (strcmp(tokens[0], "BUSNUM") == 0) {
42 busnum = xstrdup(tokens[1]);
43 continue;
46 if (strcmp(tokens[0], "DEVNUM") == 0) {
47 devnum = xstrdup(tokens[1]);
48 continue;
51 config_close(parser);
53 if (busnum) {
54 printf("Bus %s Device %s: ID %04x:%04x\n", busnum, devnum, product_vid, product_did);
55 free(busnum);
56 free(devnum);
59 return TRUE;
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",
68 ACTION_RECURSE,
69 fileAction,
70 NULL, /* dirAction */
71 NULL, /* userData */
72 0 /* depth */);
74 return EXIT_SUCCESS;