summaryrefslogtreecommitdiff
path: root/include/usb_descriptor.h
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2017-09-12 15:47:31 +0200
committerchrome-bot <chrome-bot@chromium.org>2017-09-22 10:18:50 -0700
commit77f011206c87a7a3e8cd93d3635c6c4f0ea3e32d (patch)
tree75d281c3355aa9c1918e29c31a63037d81768add /include/usb_descriptor.h
parente3333972d5bcf110fd2c51de92097a546694d0a1 (diff)
downloadchrome-ec-77f011206c87a7a3e8cd93d3635c6c4f0ea3e32d.tar.gz
Add WebUSB descriptor support
The WebUSB specification defines a specific Platform Descriptor in the Binary Object Store: https://wicg.github.io/webusb/#webusb-platform-capability-descriptor This descriptor provides a special 'Landing page' URL to the host browser and associated privileges for it. Bump the USB version for BOS descriptors to 2.1 to be compatible with Chrome implementation. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BUG=none BRANCH=twinkie TEST=manual: on Twinkie (chip/stm32) and HG proto2 (chip/g), enumerate WebUSB descriptors with lsusb and connect to a WebUSB page in Chrome R61+. Change-Id: I7211ab554f4a6c156c1e8e79a3d9f0d6644217c6 Reviewed-on: https://chromium-review.googlesource.com/664813 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'include/usb_descriptor.h')
-rw-r--r--include/usb_descriptor.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/include/usb_descriptor.h b/include/usb_descriptor.h
index 7f03b1883a..a0e9d843cc 100644
--- a/include/usb_descriptor.h
+++ b/include/usb_descriptor.h
@@ -86,6 +86,24 @@ struct usb_contid_caps_descriptor {
#define USB_DC_DTYPE_BILLBOARD 0x0d
/* RESERVED 0x00, 0xOe - 0xff */
+/* Platform descriptor */
+struct usb_platform_descriptor {
+ uint8_t bLength;
+ uint8_t bDescriptorType; /* USB_DT_DEVICE_CAPABILITY */
+ uint8_t bDevCapabilityType; /* USB_DC_DTYPE_PLATFORM */
+ uint8_t bReserved; /* SBZ */
+ uint8_t PlatformCapUUID[16]; /* USB_PLAT_CAP_xxx */
+ uint16_t bcdVersion; /* 0x0100 */
+ uint8_t bVendorCode;
+ uint8_t iLandingPage;
+} __packed;
+#define USB_DT_PLATFORM_SIZE 24
+
+/* Platform Capability UUIDs */
+#define USB_PLAT_CAP_WEBUSB /*{3408b638-09a9-47a0-8bfd-a0768815b665}*/ \
+ {0x38, 0xB6, 0x08, 0x34, 0xA9, 0x09, 0xA0, 0x47, \
+ 0x8B, 0xFD, 0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65}
+
/* Qualifier Descriptor */
struct usb_qualifier_descriptor {
uint8_t bLength;
@@ -227,6 +245,35 @@ struct usb_endpoint_descriptor {
#define USB_REQ_SET_INTERFACE 0x0B
#define USB_REQ_SYNCH_FRAME 0x0C
+/* WebUSB URL descriptors */
+#define WEBUSB_REQ_GET_URL 0x02
+#define USB_DT_WEBUSB_URL 0x03
+
+#define USB_URL_SCHEME_HTTP 0x00
+#define USB_URL_SCHEME_HTTPS 0x01
+#define USB_URL_SCHEME_NONE 0xff
+
+/*
+ * URL descriptor helper.
+ * (similar to string descriptor but UTF-8 instead of UTF-16)
+ */
+#define USB_URL_DESC(scheme, str) \
+ (const void *)&(const struct { \
+ uint8_t _len; \
+ uint8_t _type; \
+ uint8_t _scheme; \
+ char _data[sizeof(str)]; \
+ }) { \
+ /* Total size of the descriptor is : \
+ * size of the UTF-8 text plus the len/type fields \
+ * minus the string 0-termination \
+ */ \
+ sizeof(str) + 3 - 1, \
+ USB_DT_WEBUSB_URL, \
+ USB_URL_SCHEME_##scheme, \
+ str \
+ }
+
/* Setup Packet */
struct usb_setup_packet {
uint8_t bmRequestType;
@@ -294,5 +341,6 @@ extern const uint8_t usb_string_desc[];
/* USB string descriptor with the firmware version */
extern const void * const usb_fw_version;
extern const struct bos_context bos_ctx;
+extern const void *webusb_url;
#endif /* __CROS_EC_USB_DESCRIPTOR_H */