HelenOS sources
This source file includes following definitions.
- print_usage
- main
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <str_error.h>
#include <stdbool.h>
#include <getopt.h>
#include <devman.h>
#include <loc.h>
#include <usb/dev.h>
#include <usb/dev/pipes.h>
#include "usbinfo.h"
static void print_usage(char *app_name)
{
#define _INDENT " "
#define _OPTION(opt, description) \
printf(_INDENT opt "\n" _INDENT _INDENT description "\n")
printf(NAME ": query USB devices for descriptors\n\n");
printf("Usage: %s [options] device [device [device [ ... ]]]\n",
app_name);
printf(_INDENT "The device can be specified in two ways.\n");
printf(_INDENT " o Using its devman path, e.g. /hw/pci0/.../usb00_a1.\n");
printf(_INDENT " o Or using BUS.ADDR numbers as printed by lsusb.\n");
_OPTION("-h --help", "Print this help and exit.");
_OPTION("-l --list", "Print a list of host controllers and devices.");
_OPTION("-i --identification", "Brief device identification.");
_OPTION("-m --match-ids", "Print match ids generated for the device.");
_OPTION("-t --descriptor-tree", "Print descriptor tree.");
_OPTION("-T --descriptor-tree-full", "Print detailed descriptor tree");
_OPTION("-s --strings", "Try to print all string descriptors.");
_OPTION("-S --status", "Get status of the device.");
_OPTION("-r --hid-report", "Dump HID report descriptor.");
_OPTION("-R --hid-report-usages", "Dump usages of HID report.");
printf("\n");
printf("If no option is specified, `-i' is considered default.\n");
printf("\n");
#undef _OPTION
#undef _INDENT
}
static struct option long_options[] = {
{ "help", no_argument, NULL, 'h' },
{ "identification", no_argument, NULL, 'i' },
{ "list", no_argument, NULL, 'l' },
{ "match-ids", no_argument, NULL, 'm' },
{ "descriptor-tree", no_argument, NULL, 't' },
{ "descriptor-tree-full", no_argument, NULL, 'T' },
{ "strings", no_argument, NULL, 's' },
{ "status", no_argument, NULL, 'S' },
{ "hid-report", no_argument, NULL, 'r' },
{ "hid-report-usages", no_argument, NULL, 'R' },
{ 0, 0, NULL, 0 }
};
static const char *short_options = "hilmtTsSrR";
static usbinfo_action_t actions[] = {
{
.opt = 'i',
.action = dump_short_device_identification,
.active = false
},
{
.opt = 'm',
.action = dump_device_match_ids,
.active = false
},
{
.opt = 't',
.action = dump_descriptor_tree_brief,
.active = false
},
{
.opt = 'T',
.action = dump_descriptor_tree_full,
.active = false
},
{
.opt = 's',
.action = dump_strings,
.active = false
},
{
.opt = 'S',
.action = dump_status,
.active = false
},
{
.opt = 'r',
.action = dump_hidreport_raw,
.active = false
},
{
.opt = 'R',
.action = dump_hidreport_usages,
.active = false
},
{
.opt = 0
}
};
int main(int argc, char *argv[])
{
if (argc <= 1) {
print_usage(argv[0]);
return -1;
}
bool something_active = false;
int opt;
int idx;
do {
opt = getopt_long(argc, argv,
short_options, long_options, NULL);
switch (opt) {
case -1:
break;
case 'l':
list();
break;
case '?':
print_usage(argv[0]);
return 1;
case 'h':
print_usage(argv[0]);
return 0;
default:
idx = 0;
while (actions[idx].opt != 0) {
if (actions[idx].opt == opt) {
actions[idx].active = true;
something_active = true;
break;
}
idx++;
}
break;
}
} while (opt > 0);
if (!something_active) {
actions[0].active = true;
}
int i;
for (i = optind; i < argc; i++) {
char *devpath = argv[i];
devman_handle_t handle = 0;
errno_t rc = usb_resolve_device_handle(devpath, &handle);
if (rc != EOK) {
fprintf(stderr, NAME ": device `%s' not found "
"or not of USB kind, skipping.\n",
devpath);
continue;
}
usb_device_t *usb_dev = usb_device_create(handle);
if (usb_dev == NULL) {
fprintf(stderr, NAME ": device `%s' not found "
"or not of USB kind, skipping.\n",
devpath);
continue;
}
printf("%s\n", devpath);
int action = 0;
while (actions[action].opt != 0) {
if (actions[action].active) {
actions[action].action(usb_dev);
}
action++;
}
usb_device_destroy(usb_dev);
}
return 0;
}
HelenOS homepage, sources at GitHub