annotate toys/other/lsusb.c @ 900:edd8e6fd418d

Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
author Andre Renaud <andre@bluewatersys.com>
date Tue, 14 May 2013 17:42:11 -0500
parents
children 36993c59a3d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
900
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
1 /* lsusb.c - list available USB devices
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
2 *
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
3 * Copyright 2013 Andre Renaud <andre@bluewatersys.com>
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
4
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
5 USE_LSUSB(NEWTOY(lsusb, NULL, TOYFLAG_USR|TOYFLAG_BIN))
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
6
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
7 config LSUSB
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
8 bool "lsusb"
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
9 default n
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
10 help
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
11 usage: lsusb
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
12 */
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
13
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
14 #include "toys.h"
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
15
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
16 static int list_device(struct dirtree *new)
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
17 {
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
18 FILE *file;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
19 char *name;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
20 int busnum = 0;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
21 int devnum = 0;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
22 int pid = 0;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
23 int vid = 0;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
24 if (!new->parent)
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
25 return DIRTREE_RECURSE;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
26 if (new->name[0] == '.')
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
27 return 0;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
28 name = dirtree_path(new, 0);
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
29 snprintf(toybuf, sizeof(toybuf), "%s/%s", name, "/uevent");
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
30 file = fopen(toybuf, "r");
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
31 if (!file)
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
32 return 0;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
33 if (!fgets(toybuf, sizeof(toybuf), file) || !strncmp(toybuf, "DEVTYPE=", 8)) {
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
34 fclose(file);
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
35 return 0;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
36 }
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
37 while (fgets(toybuf, sizeof(toybuf), file)) {
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
38 if (!strncmp(toybuf, "BUSNUM=", 7))
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
39 busnum = atoi(&toybuf[7]);
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
40 if (!strncmp(toybuf, "DEVNUM=", 7))
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
41 devnum = atoi(&toybuf[7]);
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
42 if (!strncmp(toybuf, "PRODUCT=", 8)) {
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
43 char *pos = strchr(toybuf, '/');
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
44 pid = xstrtoul(&toybuf[8], NULL, 16);
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
45 if (pos)
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
46 vid = xstrtoul(pos + 1, NULL, 16);
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
47 }
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
48 }
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
49 fclose(file);
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
50
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
51 printf("Bus %03d Device %03d: ID %04x:%04x\n", busnum, devnum, pid, vid);
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
52
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
53 return 0;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
54 }
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
55
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
56 void lsusb_main(void)
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
57 {
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
58 dirtree_read("/sys/bus/usb/devices/", list_device);
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
59 return;
edd8e6fd418d Attached is a pretty simple implementation of lsub. It doesn't implement any of the flags/options, but does the raw output.
Andre Renaud <andre@bluewatersys.com>
parents:
diff changeset
60 }