2009-12-07 06:07:34 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
2010-04-03 19:09:47 +05:30
|
|
|
* lsusb implementation for busybox
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Malek Degachi <malek-degachi@laposte.net>
|
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2010-04-03 19:09:47 +05:30
|
|
|
*/
|
2016-11-23 16:16:32 +05:30
|
|
|
//config:config LSUSB
|
2017-07-19 01:31:24 +05:30
|
|
|
//config: bool "lsusb (3.5 kb)"
|
2016-11-23 16:16:32 +05:30
|
|
|
//config: default y
|
|
|
|
//config: #select PLATFORM_LINUX
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: lsusb is a utility for displaying information about USB buses in the
|
|
|
|
//config: system and devices connected to them.
|
2016-11-23 16:16:32 +05:30
|
|
|
//config:
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: This version uses sysfs (/sys/bus/usb/devices) only.
|
2016-11-23 16:16:32 +05:30
|
|
|
|
2017-08-06 02:58:19 +05:30
|
|
|
//applet:IF_LSUSB(APPLET_NOEXEC(lsusb, lsusb, BB_DIR_USR_BIN, BB_SUID_DROP, lsusb))
|
2016-11-23 16:16:32 +05:30
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_LSUSB) += lsusb.o
|
2011-04-11 06:59:49 +05:30
|
|
|
|
|
|
|
//usage:#define lsusb_trivial_usage NOUSAGE_STR
|
|
|
|
//usage:#define lsusb_full_usage ""
|
|
|
|
|
2010-04-03 19:09:47 +05:30
|
|
|
#include "libbb.h"
|
2009-12-07 06:07:34 +05:30
|
|
|
|
|
|
|
static int FAST_FUNC fileAction(
|
|
|
|
const char *fileName,
|
|
|
|
struct stat *statbuf UNUSED_PARAM,
|
|
|
|
void *userData UNUSED_PARAM,
|
|
|
|
int depth UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
parser_t *parser;
|
2010-03-23 09:36:37 +05:30
|
|
|
char *tokens[4];
|
|
|
|
char *busnum = NULL, *devnum = NULL;
|
2009-12-07 06:07:34 +05:30
|
|
|
int product_vid = 0, product_did = 0;
|
|
|
|
char *uevent_filename = concat_path_file(fileName, "/uevent");
|
2010-03-23 09:36:37 +05:30
|
|
|
|
2009-12-07 06:07:34 +05:30
|
|
|
parser = config_open2(uevent_filename, fopen_for_read);
|
|
|
|
free(uevent_filename);
|
|
|
|
|
2010-03-23 09:36:37 +05:30
|
|
|
while (config_read(parser, tokens, 4, 2, "\\/=", PARSE_NORMAL)) {
|
2009-12-07 06:07:34 +05:30
|
|
|
if ((parser->lineno == 1) && strcmp(tokens[0], "DEVTYPE") == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(tokens[0], "PRODUCT") == 0) {
|
|
|
|
product_vid = xstrtou(tokens[1], 16);
|
|
|
|
product_did = xstrtou(tokens[2], 16);
|
|
|
|
continue;
|
|
|
|
}
|
2010-03-23 09:36:37 +05:30
|
|
|
|
|
|
|
if (strcmp(tokens[0], "BUSNUM") == 0) {
|
|
|
|
busnum = xstrdup(tokens[1]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(tokens[0], "DEVNUM") == 0) {
|
|
|
|
devnum = xstrdup(tokens[1]);
|
|
|
|
continue;
|
|
|
|
}
|
2009-12-07 06:07:34 +05:30
|
|
|
}
|
|
|
|
config_close(parser);
|
|
|
|
|
2010-03-23 09:36:37 +05:30
|
|
|
if (busnum) {
|
|
|
|
printf("Bus %s Device %s: ID %04x:%04x\n", busnum, devnum, product_vid, product_did);
|
|
|
|
free(busnum);
|
|
|
|
free(devnum);
|
2009-12-07 06:07:34 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|