summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2017-09-12 15:47:31 +0200
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-10-24 01:52:58 +0000
commit7193771d61e816b7c6b33ef79d19d8ed32570efb (patch)
tree1d9caf2c23863a0acc28d97cc9d555faafdb3a19 /include
parent0ddc5fa840c142a955087a5b5e36217139b3fb3f (diff)
downloadchrome-ec-7193771d61e816b7c6b33ef79d19d8ed32570efb.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> (cherry picked from commit 77f011206c87a7a3e8cd93d3635c6c4f0ea3e32d) Reviewed-on: https://chromium-review.googlesource.com/734626 Commit-Queue: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/config.h12
-rw-r--r--include/usb_descriptor.h48
2 files changed, 60 insertions, 0 deletions
diff --git a/include/config.h b/include/config.h
index 69cd4d95fb..aa221c48b1 100644
--- a/include/config.h
+++ b/include/config.h
@@ -2776,6 +2776,18 @@
#define CONFIG_AUX_TIMER_PERIOD_MS (CONFIG_WATCHDOG_PERIOD_MS - 500)
/*****************************************************************************/
+/* WebUSB config */
+
+/*
+ * Enable the WebUSB support and define its URL.
+ * Export a WebUSB Platform Descriptor in the Binary Object Store descriptor.
+ * The WebUSB landing page URL is equal to 'CONFIG_WEBUSB_URL' plus the
+ * https:// prefix.
+ * This requires CONFIG_USB_BOS.
+ */
+#undef CONFIG_WEBUSB_URL
+
+/*****************************************************************************/
/*
* Support controlling power to WiFi, WWAN (3G/LTE), and/or bluetooth modules.
diff --git a/include/usb_descriptor.h b/include/usb_descriptor.h
index 33fde009d2..62f8b0d8e0 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;
@@ -295,5 +342,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 */