summaryrefslogtreecommitdiff
path: root/util-linux/lsusb.c
diff options
context:
space:
mode:
authorSouf Oued2009-12-07 01:37:34 +0100
committerDenys Vlasenko2009-12-07 01:37:34 +0100
commit11a802a0fa04627110809d908c588aa2c471d5aa (patch)
tree5e39c0017b7935e424106153e1031f0ac5f91f4d /util-linux/lsusb.c
parent982bc7176d04d9d3e2b40c4ddba24eab9f02dc4d (diff)
downloadbusybox-11a802a0fa04627110809d908c588aa2c471d5aa.zip
busybox-11a802a0fa04627110809d908c588aa2c471d5aa.tar.gz
lsusb: new applet. +400 bytes
Signed-off-by: Souf Oued <souf_oued@yahoo.fr> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/lsusb.c')
-rw-r--r--util-linux/lsusb.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/util-linux/lsusb.c b/util-linux/lsusb.c
new file mode 100644
index 0000000..7c5b6b9
--- /dev/null
+++ b/util-linux/lsusb.c
@@ -0,0 +1,67 @@
+/* vi: set sw=4 ts=4: */
+/*
+* lspci implementation for busybox
+*
+* Copyright (C) 2009 Malek Degachi <malek-degachi@laposte.net>
+*
+* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+*/
+#include <libbb.h>
+
+static int FAST_FUNC fileAction(
+ const char *fileName,
+ struct stat *statbuf UNUSED_PARAM,
+ void *userData UNUSED_PARAM,
+ int depth UNUSED_PARAM)
+{
+ parser_t *parser;
+ char *tokens[6];
+ char *bus = NULL, *device = NULL;
+ int product_vid = 0, product_did = 0;
+
+ char *uevent_filename = concat_path_file(fileName, "/uevent");
+ parser = config_open2(uevent_filename, fopen_for_read);
+ free(uevent_filename);
+
+ while (config_read(parser, tokens, 6, 1, "\\/=", PARSE_NORMAL)) {
+ if ((parser->lineno == 1) && strcmp(tokens[0], "DEVTYPE") == 0) {
+ break;
+ }
+
+ if (strcmp(tokens[0], "DEVICE") == 0) {
+ bus = xstrdup(tokens[4]);
+ device = xstrdup(tokens[5]);
+ continue;
+ }
+
+ if (strcmp(tokens[0], "PRODUCT") == 0) {
+ product_vid = xstrtou(tokens[1], 16);
+ product_did = xstrtou(tokens[2], 16);
+ continue;
+ }
+ }
+ config_close(parser);
+
+ if (bus) {
+ printf("Bus %s Device %s: ID %04x:%04x\n", bus, device, product_vid, product_did);
+ free(bus);
+ free(device);
+ }
+
+ return TRUE;
+}
+
+int lsusb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int lsusb_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+{
+ /* no options, no getopt */
+
+ recursive_action("/sys/bus/usb/devices",
+ ACTION_RECURSE,
+ fileAction,
+ NULL, /* dirAction */
+ NULL, /* userData */
+ 0 /* depth */);
+
+ return EXIT_SUCCESS;
+}