Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 117 lines (97 sloc) 2.95 kb
f8e1553 @gregkh initial test
authored
1 /*
71a4554 @gregkh fix up license and copyright
authored
2 * lsusb
f8e1553 @gregkh initial test
authored
3 *
4 * Copyright (C) 2009 Kay Sievers <kay.sievers@vrfy.org>
71a4554 @gregkh fix up license and copyright
authored
5 * Copyright (C) 2009 Greg Kroah-Hartman <greg@kroah.com>
f8e1553 @gregkh initial test
authored
6 *
7 * This program is free software; you can redistribute it and/or
71a4554 @gregkh fix up license and copyright
authored
8 * modify it under the terms of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
f8e1553 @gregkh initial test
authored
10 */
11
12 #include <stdio.h>
13 #include <stdarg.h>
14 #include <stdlib.h>
81cf82a @gregkh start messing around with adding the devices to a list
authored
15 #include <stddef.h>
f8e1553 @gregkh initial test
authored
16 #include <unistd.h>
17 #include <errno.h>
18 #include <string.h>
19 #include <getopt.h>
20 #include <syslog.h>
21 #include <fcntl.h>
22 #include <poll.h>
5a187b4 @gregkh start parsing the raw usb config header
authored
23 #include <limits.h>
16c0ab0 @gregkh first hack to get the interfaces for the device
authored
24 #include <dirent.h>
25 #include <ctype.h>
f8e1553 @gregkh initial test
authored
26 #include <sys/select.h>
81cf82a @gregkh start messing around with adding the devices to a list
authored
27 #include <sys/stat.h>
f8e1553 @gregkh initial test
authored
28
129e7b3 @gregkh fix build issues on older versions of libudev
authored
29 #define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
30
46cae44 @gregkh start printing out stuff.
authored
31 #include <libudev.h>
81cf82a @gregkh start messing around with adding the devices to a list
authored
32 #include "list.h"
46cae44 @gregkh start printing out stuff.
authored
33 #include "usb.h"
1ca9c1a @gregkh create device.c for all usb device stuff
authored
34 #include "lsusb.h"
0990f74 @gregkh add way to create any endpoint
authored
35
36
37
81cf82a @gregkh start messing around with adding the devices to a list
authored
38 static LIST_HEAD(usb_devices);
2d8ba8a @gregkh move interface logic out to interface.c
authored
39 struct udev *udev;
81cf82a @gregkh start messing around with adding the devices to a list
authored
40
1ca9c1a @gregkh create device.c for all usb device stuff
authored
41 void *robust_malloc(size_t size)
46cae44 @gregkh start printing out stuff.
authored
42 {
108fd93 @gregkh add interface support
authored
43 void *data;
46cae44 @gregkh start printing out stuff.
authored
44
108fd93 @gregkh add interface support
authored
45 data = malloc(size);
46 if (data == NULL)
46cae44 @gregkh start printing out stuff.
authored
47 exit(1);
108fd93 @gregkh add interface support
authored
48 memset(data, 0, size);
49 return data;
50 }
51
1ca9c1a @gregkh create device.c for all usb device stuff
authored
52 char *get_dev_string(struct udev_device *device, const char *name)
46cae44 @gregkh start printing out stuff.
authored
53 {
54 const char *value;
55
56 value = udev_device_get_sysattr_value(device, name);
57 if (value != NULL)
58 return strdup(value);
59 return NULL;
60 }
f8e1553 @gregkh initial test
authored
61
5a187b4 @gregkh start parsing the raw usb config header
authored
62
7aa0ab7 @gregkh start reading some attributes.
authored
63 //int main(int argc, char *argv[])
64 int main(void)
f8e1553 @gregkh initial test
authored
65 {
66 struct udev_enumerate *enumerate;
67 struct udev_list_entry *list_entry;
68
69 /* libudev context */
70 udev = udev_new();
71
72 /* prepare a device scan */
73 enumerate = udev_enumerate_new(udev);
44b6689 @gregkh more usb attributes added.
authored
74 /* filter for usb devices */
7aa0ab7 @gregkh start reading some attributes.
authored
75 udev_enumerate_add_match_subsystem(enumerate, "usb");
f8e1553 @gregkh initial test
authored
76 /* retrieve the list */
77 udev_enumerate_scan_devices(enumerate);
78 /* print devices */
79 udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
80 struct udev_device *device;
81
82 device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
83 udev_list_entry_get_name(list_entry));
84 if (device == NULL)
85 continue;
5a187b4 @gregkh start parsing the raw usb config header
authored
86 if (strcmp("usb_device", udev_device_get_devtype(device)) == 0)
87 // if (strstr(udev_device_get_sysname(device), "usb") != NULL)
1bbd827 @gregkh create raw.c and endpoint.c
authored
88 create_usb_device(device);
7aa0ab7 @gregkh start reading some attributes.
authored
89 #if 0
5a187b4 @gregkh start parsing the raw usb config header
authored
90 printf("%s: ", udev_list_entry_get_name(list_entry));
7aa0ab7 @gregkh start reading some attributes.
authored
91 printf("\tdevtype: %s\n", udev_device_get_devtype(device));
5a187b4 @gregkh start parsing the raw usb config header
authored
92 printf("\tsubsystem: %s\n", udev_device_get_subsystem(device));
7aa0ab7 @gregkh start reading some attributes.
authored
93 printf("\tsyspath: %s\n", udev_device_get_syspath(device));
94 printf("\tsysnum: %s\n", udev_device_get_sysnum(device));
5a187b4 @gregkh start parsing the raw usb config header
authored
95 printf("\tsysname: %s\n", udev_device_get_sysname(device));
7aa0ab7 @gregkh start reading some attributes.
authored
96 printf("\tdevpath: %s\n", udev_device_get_devpath(device));
97 printf("\tdevnode: %s\n", udev_device_get_devnode(device));
98 printf("\tdriver: %s\n", udev_device_get_driver(device));
46cae44 @gregkh start printing out stuff.
authored
99
108fd93 @gregkh add interface support
authored
100 if (strcmp("usb_device", udev_device_get_devtype(device)) == 0)
101 create_usb_device(device);
102
103 if (strcmp("usb_interface", udev_device_get_devtype(device)) == 0)
104 create_usb_interface(device);
5a187b4 @gregkh start parsing the raw usb config header
authored
105 #endif
7aa0ab7 @gregkh start reading some attributes.
authored
106
f8e1553 @gregkh initial test
authored
107 udev_device_unref(device);
108 }
109 udev_enumerate_unref(enumerate);
110
111 udev_unref(udev);
515cb0c @gregkh start adding sort to device list
authored
112 sort_usb_devices();
81cf82a @gregkh start messing around with adding the devices to a list
authored
113 print_usb_devices();
114 free_usb_devices();
f8e1553 @gregkh initial test
authored
115 return 0;
116 }
Something went wrong with that request. Please try again.