Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157660012
D57202.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D57202.diff
View Options
diff --git a/sys/dev/usb/usb.h b/sys/dev/usb/usb.h
--- a/sys/dev/usb/usb.h
+++ b/sys/dev/usb/usb.h
@@ -309,6 +309,9 @@
} __packed;
typedef struct usb_device_descriptor usb_device_descriptor_t;
+/* Maximum sane wTotalLength for a BOS descriptor */
+#define USB_BOS_DESC_MAX_LEN 4096
+
/* Binary Device Object Store (BOS) */
struct usb_bos_descriptor {
uByte bLength;
diff --git a/sys/dev/usb/usb_request.h b/sys/dev/usb/usb_request.h
--- a/sys/dev/usb/usb_request.h
+++ b/sys/dev/usb/usb_request.h
@@ -60,6 +60,10 @@
usb_error_t usbd_req_get_ss_hub_descriptor(struct usb_device *udev,
struct mtx *mtx, struct usb_hub_ss_descriptor *hd,
uint8_t nports);
+usb_error_t usbd_req_get_bos_descriptor(struct usb_device *udev,
+ struct mtx *mtx, struct usb_bos_descriptor *desc, int len);
+usb_error_t usbd_req_get_bos_descriptor_full(struct usb_device *udev,
+ struct mtx *mtx, struct usb_bos_descriptor **pdesc, int *len);
usb_error_t usbd_req_get_hub_status(struct usb_device *udev, struct mtx *mtx,
struct usb_hub_status *st);
usb_error_t usbd_req_get_port_status(struct usb_device *udev, struct mtx *mtx,
diff --git a/sys/dev/usb/usb_request.c b/sys/dev/usb/usb_request.c
--- a/sys/dev/usb/usb_request.c
+++ b/sys/dev/usb/usb_request.c
@@ -1535,6 +1535,74 @@
return (usbd_do_request(udev, mtx, &req, hd));
}
+/*------------------------------------------------------------------------*
+ * usbd_req_get_bos_descriptor
+ *
+ * Returns:
+ * 0: Success
+ * Else: Failure
+ *------------------------------------------------------------------------*/
+usb_error_t
+usbd_req_get_bos_descriptor(struct usb_device *udev, struct mtx *mtx,
+ struct usb_bos_descriptor *bd, int len)
+{
+ struct usb_device_request req;
+
+ req.bmRequestType = UT_READ_DEVICE;
+ req.bRequest = UR_GET_DESCRIPTOR;
+ USETW2(req.wValue, UDESC_BOS, 0);
+ USETW(req.wIndex, 0);
+ USETW(req.wLength, len);
+
+ return (usbd_do_request_flags(udev, mtx, &req, bd, USB_SHORT_XFER_OK,
+ NULL, USB_DEFAULT_TIMEOUT));
+}
+
+/*------------------------------------------------------------------------*
+ * usbd_req_get_bos_descriptor_full
+ *
+ * Returns:
+ * 0: Success
+ * Else: Failure
+ *------------------------------------------------------------------------*/
+usb_error_t
+usbd_req_get_bos_descriptor_full(struct usb_device *udev, struct mtx *mtx,
+ struct usb_bos_descriptor **bdp, int *len)
+{
+ struct usb_bos_descriptor *bdesc;
+ uint32_t desc_len;
+ int err;
+
+ *bdp = NULL;
+ *len = 0;
+
+ bdesc = malloc(sizeof(struct usb_bos_descriptor), M_USBDEV, M_WAITOK);
+ err = usbd_req_get_bos_descriptor(udev, mtx, bdesc, sizeof(*bdesc));
+ if (err) {
+ free(bdesc, M_USBDEV);
+ return (err);
+ }
+ desc_len = UGETW(bdesc->wTotalLength);
+ free(bdesc, M_USBDEV);
+
+ if (desc_len < sizeof(struct usb_bos_descriptor) ||
+ desc_len > USB_BOS_DESC_MAX_LEN) {
+ DPRINTFN(0, "BOS descriptor wTotalLength %u is invalid\n",
+ desc_len);
+ return (USB_ERR_INVAL);
+ }
+
+ bdesc = malloc(desc_len, M_USBDEV, M_WAITOK);
+ err = usbd_req_get_bos_descriptor(udev, mtx, bdesc, desc_len);
+ if (err) {
+ free(bdesc, M_USBDEV);
+ return (err);
+ }
+ *bdp = bdesc;
+ *len = desc_len;
+ return (0);
+}
+
/*------------------------------------------------------------------------*
* usbd_req_get_hub_status
*
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, May 24, 7:48 PM (13 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33484664
Default Alt Text
D57202.diff (3 KB)
Attached To
Mode
D57202: usb: Implement usbd_req_get_bos_descriptor helper
Attached
Detach File
Event Timeline
Log In to Comment