summaryrefslogtreecommitdiffstats
path: root/udev-acl
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2008-12-29 00:18:08 +0100
committerKay Sievers <kay.sievers@vrfy.org>2008-12-29 00:18:08 +0100
commitceee5de11c68b233a77e4721601cf98daecef6c8 (patch)
tree405b88b985dff74bb8c8cb4548608214583ff288 /udev-acl
parent07d80fe422905e8943c20118f875b2b1f49b47e5 (diff)
add udev-acl
Diffstat (limited to 'udev-acl')
-rw-r--r--udev-acl/usbdev_id.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/udev-acl/usbdev_id.c b/udev-acl/usbdev_id.c
new file mode 100644
index 0000000..5caeb97
--- /dev/null
+++ b/udev-acl/usbdev_id.c
@@ -0,0 +1,84 @@
+/*
+ * find all usb-device interfaces, and make them available in a single string
+ *
+ * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#define USB_DT_DEVICE 0x01
+#define USB_DT_INTERFACE 0x04
+
+static int devinfo(const char *syspath)
+{
+ char filename[1024];
+ int fd;
+ ssize_t size;
+ unsigned char buf[18 + 65535];
+ unsigned int pos;
+ struct usb_interface_descriptor {
+ u_int8_t bLength;
+ u_int8_t bDescriptorType;
+ u_int8_t bInterfaceNumber;
+ u_int8_t bAlternateSetting;
+ u_int8_t bNumEndpoints;
+ u_int8_t bInterfaceClass;
+ u_int8_t bInterfaceSubClass;
+ u_int8_t bInterfaceProtocol;
+ u_int8_t iInterface;
+ };
+
+ strcpy(filename, "/sys");
+ strcat(filename, syspath);
+ strcat(filename, "/descriptors");
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return -1;
+ size = read(fd, buf, sizeof(buf));
+ close(fd);
+ if (size < 18 || size == sizeof(buf))
+ return -1;
+
+ printf("ID_USB_INTERFACES=:");
+ pos = 0;
+ while (pos < sizeof(buf)) {
+ struct usb_interface_descriptor *desc;
+
+ desc = (struct usb_interface_descriptor *) &buf[pos];
+ if (desc->bLength < 3)
+ break;
+
+ if (desc->bDescriptorType == USB_DT_INTERFACE)
+ printf("%02x%02x%02x:", desc->bInterfaceClass, desc->bInterfaceSubClass, desc->bInterfaceProtocol);
+ pos += desc->bLength;
+ }
+ printf("\n");
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ const char *devpath = argv[1];
+
+ if (devpath == NULL)
+ return 1;
+ devinfo(devpath);
+ return 0;
+}