summaryrefslogtreecommitdiff
path: root/sys/dev/usb
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2005-09-20 08:04:00 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2005-09-20 08:04:00 +0000
commitd7217b0449288745240ac55e088b86cf94ab2b15 (patch)
tree8ff4248ad7b06a49023e8e2eeb03709004c8fd73 /sys/dev/usb
parentdf6ed6211ca48b1ecf5020e36974c35375a6a160 (diff)
add iterators for usb descriptors. from Tony Lambris and Staffan Ulfberg.
Diffstat (limited to 'sys/dev/usb')
-rw-r--r--sys/dev/usb/usbdi.c34
-rw-r--r--sys/dev/usb/usbdi.h10
2 files changed, 42 insertions, 2 deletions
diff --git a/sys/dev/usb/usbdi.c b/sys/dev/usb/usbdi.c
index c18409b12a1..fe218f2ccce 100644
--- a/sys/dev/usb/usbdi.c
+++ b/sys/dev/usb/usbdi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: usbdi.c,v 1.25 2004/07/08 22:18:45 deraadt Exp $ */
+/* $OpenBSD: usbdi.c,v 1.26 2005/09/20 08:03:59 dlg Exp $ */
/* $NetBSD: usbdi.c,v 1.103 2002/09/27 15:37:38 provos Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.28 1999/11/17 22:33:49 n_hibma Exp $ */
@@ -1137,6 +1137,38 @@ usb_match_device(const struct usb_devno *tbl, u_int nentries, u_int sz,
return (NULL);
}
+void
+usb_desc_iter_init(usbd_device_handle dev, usbd_desc_iter_t *iter)
+{
+ const usb_config_descriptor_t *cd = usbd_get_config_descriptor(dev);
+
+ iter->cur = (const uByte *)cd;
+ iter->end = (const uByte *)cd + UGETW(cd->wTotalLength);
+}
+
+const usb_descriptor_t *
+usb_desc_iter_next(usbd_desc_iter_t *iter)
+{
+ const usb_descriptor_t *desc;
+
+ if (iter->cur + sizeof(usb_descriptor_t) >= iter->end) {
+ if (iter->cur != iter->end)
+ printf("usb_desc_iter_next: bad descriptor\n");
+ return NULL;
+ }
+ desc = (const usb_descriptor_t *)iter->cur;
+ if (desc->bLength == 0) {
+ printf("usb_desc_iter_next: descriptor length = 0\n");
+ return NULL;
+ }
+ iter->cur += desc->bLength;
+ if (iter->cur > iter->end) {
+ printf("usb_desc_iter_next: descriptor length too large\n");
+ return NULL;
+ }
+ return desc;
+}
+
#if defined(__FreeBSD__)
int
usbd_driver_load(module_t mod, int what, void *arg)
diff --git a/sys/dev/usb/usbdi.h b/sys/dev/usb/usbdi.h
index 11bc0d8e150..1f7bd12ff2d 100644
--- a/sys/dev/usb/usbdi.h
+++ b/sys/dev/usb/usbdi.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: usbdi.h,v 1.24 2005/08/01 05:36:49 brad Exp $ */
+/* $OpenBSD: usbdi.h,v 1.25 2005/09/20 08:03:59 dlg Exp $ */
/* $NetBSD: usbdi.h,v 1.62 2002/07/11 21:14:35 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $ */
@@ -182,6 +182,14 @@ usbd_status usbd_reload_device_desc(usbd_device_handle);
int usbd_ratecheck(struct timeval *last);
+/* An iterator for descriptors. */
+typedef struct {
+ const uByte *cur;
+ const uByte *end;
+} usbd_desc_iter_t;
+void usb_desc_iter_init(usbd_device_handle, usbd_desc_iter_t *);
+const usb_descriptor_t *usb_desc_iter_next(usbd_desc_iter_t *);
+
/*
* The usb_task structs form a queue of things to run in the USB event
* thread. Normally this is just device discovery when a connect/disconnect