summaryrefslogtreecommitdiff
path: root/tmk_core/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol')
-rw-r--r--tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c7
-rw-r--r--tmk_core/protocol/chibios/chibios.c8
-rw-r--r--tmk_core/protocol/chibios/usb_main.c76
-rw-r--r--tmk_core/protocol/lufa/lufa.c119
-rw-r--r--tmk_core/protocol/usb_descriptor.c52
-rw-r--r--tmk_core/protocol/usb_descriptor.h22
-rw-r--r--tmk_core/protocol/webusb_descriptor.h266
7 files changed, 548 insertions, 2 deletions
diff --git a/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c b/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c
index 69b3ad574c..1dfbaaab96 100644
--- a/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c
+++ b/tmk_core/protocol/arm_atsam/md_rgb_matrix_programs.c
@@ -97,5 +97,10 @@ void *led_setups[] = {leds_rainbow_s, leds_rainbow_ns, leds_teal_salmon, leds_ye
const uint8_t led_setups_count = sizeof(led_setups) / sizeof(led_setups[0]);
+<<<<<<< HEAD
+# endif // USE_MASSDROP_CONFIGURATOR
+#endif // RGB_MATRIX_ENABLE
+=======
# endif // USE_MASSDROP_CONFIGURATOR
-#endif // RGB_MATRIX_ENABLE \ No newline at end of file
+#endif // RGB_MATRIX_ENABLE
+>>>>>>> qmk/master
diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c
index c9a480c325..bd6adbe17e 100644
--- a/tmk_core/protocol/chibios/chibios.c
+++ b/tmk_core/protocol/chibios/chibios.c
@@ -81,6 +81,10 @@ void console_task(void);
void midi_ep_task(void);
#endif
+#ifdef WEBUSB_ENABLE
+void webusb_task(void);
+#endif
+
/* TESTING
* Amber LED blinker thread, times are in milliseconds.
*/
@@ -218,4 +222,8 @@ void protocol_post_task(void) {
#ifdef RAW_ENABLE
raw_hid_task();
#endif
+#ifdef WEBUSB_ENABLE
+ webusb_task();
+#endif
+
}
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index eb9ef82554..b61228511d 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -50,6 +50,18 @@
extern keymap_config_t keymap_config;
#endif
+#ifdef RAW_ENABLE
+# include "raw_hid.h"
+#endif
+
+#ifdef ORYX_ENABLE
+# include "oryx.h"
+#endif
+
+#ifdef WEBUSB_ENABLE
+# include "webusb.h"
+#endif
+
#ifdef JOYSTICK_ENABLE
# include "joystick.h"
#endif
@@ -319,6 +331,9 @@ typedef struct {
#ifdef VIRTSER_ENABLE
usb_driver_config_t serial_driver;
#endif
+#ifdef WEBUSB_ENABLE
+ usb_driver_config_t webusb_driver;
+#endif
#ifdef JOYSTICK_ENABLE
usb_driver_config_t joystick_driver;
#endif
@@ -366,6 +381,13 @@ static usb_driver_configs_t drivers = {
.serial_driver = QMK_USB_DRIVER_CONFIG(CDC, CDC_NOTIFICATION_EPNUM, false),
#endif
+#ifdef WEBUSB_ENABLE
+# define WEBUSB_IN_CAPACITY 4
+# define WEBUSB_OUT_CAPACITY 4
+# define WEBUSB_IN_MODE USB_EP_MODE_TYPE_INTR
+# define WEBUSB_OUT_MODE USB_EP_MODE_TYPE_INTR
+ .webusb_driver = QMK_USB_DRIVER_CONFIG(WEBUSB, 0, false),
+#endif
#ifdef JOYSTICK_ENABLE
# define JOYSTICK_IN_CAPACITY 4
# define JOYSTICK_OUT_CAPACITY 4
@@ -674,6 +696,27 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
}
}
+#ifdef WEBUSB_ENABLE
+ switch (usbp->setup[1]) {
+ case WEBUSB_VENDOR_CODE:
+ if (usbp->setup[4] == WebUSB_RTYPE_GetURL) {
+ if (usbp->setup[2] == WEBUSB_LANDING_PAGE_INDEX) {
+ usbSetupTransfer(usbp, (uint8_t *)&WebUSB_LandingPage, WebUSB_LandingPage.Header.Size, NULL);
+ return TRUE;
+ break;
+ }
+ }
+ break;
+
+ case MS_OS_20_VENDOR_CODE:
+ if (usbp->setup[4] == MS_OS_20_DESCRIPTOR_INDEX) {
+ usbSetupTransfer(usbp, (uint8_t *)&MS_OS_20_Descriptor, MS_OS_20_Descriptor.Header.TotalLength, NULL);
+ return TRUE;
+ break;
+ }
+ break;
+ }
+#endif
/* Handle the Get_Descriptor Request for HID class (not handled by the default hook) */
if ((usbp->setup[0] == 0x81) && (usbp->setup[1] == USB_REQ_GET_DESCRIPTOR)) {
dp = usbp->config->get_descriptor_cb(usbp, usbp->setup[3], usbp->setup[2], get_hword(&usbp->setup[4]));
@@ -1093,7 +1136,15 @@ void raw_hid_send(uint8_t *data, uint8_t length) {
if (length != RAW_EPSIZE) {
return;
}
+
+# ifdef ORYX_ENABLE
+ if (chnWriteTimeout(&drivers.raw_driver.driver, data, length, TIME_IMMEDIATE) != length) {
+ rawhid_state.pairing = false;
+ rawhid_state.paired = false;
+ }
+# else
chnWrite(&drivers.raw_driver.driver, data, length);
+# endif
}
__attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) {
@@ -1115,6 +1166,31 @@ void raw_hid_task(void) {
#endif
+#ifdef WEBUSB_ENABLE
+void webusb_send(uint8_t *data, uint8_t length) {
+ if (chnWriteTimeout(&drivers.webusb_driver.driver, data, length, TIME_IMMEDIATE) != length) {
+ webusb_state.paired = false;
+ webusb_state.pairing = false;
+ }
+}
+
+// Users should #include "raw_hid.h" in their own code
+// and implement this function there. Leave this as weak linkage
+// so users can opt to not handle data coming in.
+
+void webusb_task(void) {
+ uint8_t buffer[WEBUSB_EPSIZE];
+ size_t size = 0;
+ do {
+ size_t size = chnReadTimeout(&drivers.webusb_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
+ if (size > 0) {
+ webusb_receive(buffer, size);
+ }
+ } while (size > 0);
+}
+
+#endif
+
#ifdef MIDI_ENABLE
void send_midi_packet(MIDI_EventPacket_t *event) {
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index b4b03357a3..1084f67659 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -86,6 +86,9 @@ extern keymap_config_t keymap_config;
# include "raw_hid.h"
#endif
+#ifdef WEBUSB_ENABLE
+# include "webusb.h"
+#endif
#ifdef JOYSTICK_ENABLE
# include "joystick.h"
#endif
@@ -158,7 +161,10 @@ void raw_hid_send(uint8_t *data, uint8_t length) {
// Check to see if the host is ready to accept another packet
if (Endpoint_IsINReady()) {
// Write data
- Endpoint_Write_Stream_LE(data, RAW_EPSIZE, NULL);
+ if (Endpoint_Write_Stream_LE(data, RAW_EPSIZE, NULL)) {
+ rawhid_state.pairing = false;
+ rawhid_state.paired = false;
+ }
// Finalize the stream transfer to send the last packet
Endpoint_ClearIN();
}
@@ -268,6 +274,65 @@ static void Console_Task(void) {
}
#endif
+#ifdef WEBUSB_ENABLE
+void webusb_send(uint8_t *data, uint8_t length) {
+ if (USB_DeviceState != DEVICE_STATE_Configured) {
+ return;
+ }
+
+ Endpoint_SelectEndpoint(WEBUSB_IN_EPNUM);
+
+ if (Endpoint_Write_Stream_LE(data, length, NULL)) {
+ // Stream failed to complete, resetting WEBUSB's state
+ webusb_state.paired = false;
+ webusb_state.pairing = false;
+ }
+ Endpoint_ClearIN();
+}
+
+static void webusb_task(void) {
+ // Create a temporary buffer to hold the read in data from the host
+ uint8_t data[WEBUSB_EPSIZE];
+ bool data_read = false;
+
+ // Device must be connected and configured for the task to run
+ if (USB_DeviceState != DEVICE_STATE_Configured) return;
+
+ Endpoint_SelectEndpoint(WEBUSB_OUT_EPNUM);
+
+ // Check to see if a packet has been sent from the host
+ if (Endpoint_IsOUTReceived()) {
+ // Check to see if the packet contains data
+ if (Endpoint_IsReadWriteAllowed()) {
+ /* Read data */
+ Endpoint_Read_Stream_LE(data, sizeof(data), NULL);
+ data_read = true;
+ }
+
+ // Finalize the stream transfer to receive the last packet
+ Endpoint_ClearOUT();
+
+ if (data_read) {
+ webusb_receive(data, sizeof(data));
+ }
+ }
+}
+
+/** Microsoft OS 2.0 Descriptor. This is used by Windows to select the USB driver for the device.
+ *
+ * For WebUSB in Chrome, the correct driver is WinUSB, which is selected via CompatibleID.
+ *
+ * Additionally, while Chrome is built using libusb, a magic registry key needs to be set containing a GUID for
+ * the device.
+ */
+const MS_OS_20_Descriptor_t PROGMEM MS_OS_20_Descriptor = MS_OS_20_DESCRIPTOR;
+
+/** URL descriptor string. This is a UTF-8 string containing a URL excluding the prefix. At least one of these must be
+ * defined and returned when the Landing Page descriptor index is requested.
+ */
+const WebUSB_URL_Descriptor_t PROGMEM WebUSB_LandingPage = WEBUSB_URL_DESCRIPTOR(WEBUSB_LANDING_PAGE_URL);
+#endif
+
/*******************************************************************************
* Joystick
******************************************************************************/
@@ -479,6 +544,12 @@ void EVENT_USB_Device_ConfigurationChanged(void) {
# endif
#endif
+#ifdef WEBUSB_ENABLE
+ /* Setup Webusb Endpoints */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint(WEBUSB_IN_EPADDR, EP_TYPE_INTERRUPT, WEBUSB_EPSIZE, 1);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint(WEBUSB_OUT_EPADDR, EP_TYPE_INTERRUPT, WEBUSB_EPSIZE, 1);
+#endif
+
#ifdef MIDI_ENABLE
/* Setup MIDI stream endpoints */
ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1);
@@ -624,6 +695,48 @@ void EVENT_USB_Device_ControlRequest(void) {
}
break;
+#ifdef WEBUSB_ENABLE
+ case WEBUSB_VENDOR_CODE:
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE)) {
+ switch (USB_ControlRequest.wIndex) {
+ case WebUSB_RTYPE_GetURL:
+ switch (USB_ControlRequest.wValue) {
+ case WEBUSB_LANDING_PAGE_INDEX:
+ Endpoint_ClearSETUP();
+ /* Write the descriptor data to the control endpoint */
+ Endpoint_Write_Control_PStream_LE(&WebUSB_LandingPage, WebUSB_LandingPage.Header.Size);
+ /* Release the endpoint after transaction. */
+ Endpoint_ClearStatusStage();
+ break;
+ default: /* Stall transfer on invalid index. */
+ Endpoint_StallTransaction();
+ break;
+ }
+ break;
+ default: /* Stall on unknown WebUSB request */
+ Endpoint_StallTransaction();
+ break;
+ }
+ }
+
+ break;
+ case MS_OS_20_VENDOR_CODE:
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE)) {
+ switch (USB_ControlRequest.wIndex) {
+ case MS_OS_20_DESCRIPTOR_INDEX:
+ Endpoint_ClearSETUP();
+ /* Write the descriptor data to the control endpoint */
+ Endpoint_Write_Control_PStream_LE(&MS_OS_20_Descriptor, MS_OS_20_Descriptor.Header.TotalLength);
+ /* Release the endpoint after transaction. */
+ Endpoint_ClearStatusStage();
+ break;
+ default: /* Stall on unknown MS OS 2.0 request */
+ Endpoint_StallTransaction();
+ break;
+ }
+ }
+ break;
+#endif
}
#ifdef VIRTSER_ENABLE
@@ -1096,6 +1209,10 @@ void protocol_post_task(void) {
raw_hid_task();
#endif
+#ifdef WEBUSB_ENABLE
+ webusb_task();
+#endif
+
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
USB_USBTask();
#endif
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index 21795cef60..4905096354 100644
--- a/tmk_core/protocol/usb_descriptor.c
+++ b/tmk_core/protocol/usb_descriptor.c
@@ -39,6 +39,9 @@
#include "util.h"
#include "report.h"
#include "usb_descriptor.h"
+#ifdef WEBUSB_ENABLE
+# include "webusb_descriptor.h"
+#endif
#include "usb_descriptor_common.h"
#ifdef JOYSTICK_ENABLE
@@ -362,6 +365,12 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
};
#endif
+#ifdef WEBUSB_ENABLE
+const USB_Descriptor_BOS_t PROGMEM BOSDescriptor = BOS_DESCRIPTOR(
+ (MS_OS_20_PLATFORM_DESCRIPTOR(MS_OS_20_VENDOR_CODE, MS_OS_20_DESCRIPTOR_SET_TOTAL_LENGTH))
+ (WEBUSB_PLATFORM_DESCRIPTOR(WEBUSB_VENDOR_CODE, WEBUSB_LANDING_PAGE_INDEX))
+);
+#endif
#ifdef JOYSTICK_ENABLE
const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = {
HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
@@ -429,7 +438,11 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
.Size = sizeof(USB_Descriptor_Device_t),
.Type = DTYPE_Device
},
+#if defined(WEBUSB_ENABLE) && !defined(STENO_ENABLE)
+ .USBSpecification = VERSION_BCD(2, 1, 0),
+#else
.USBSpecification = VERSION_BCD(2, 0, 0),
+#endif
#if VIRTSER_ENABLE
.Class = USB_CSCP_IADDeviceClass,
@@ -705,6 +718,38 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
},
#endif
+#ifdef WEBUSB_ENABLE
+ /*
+ * Webusb
+ */
+ .WebUSB_Interface = {.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+
+ .InterfaceNumber = INTERFACE_ID_WebUSB,
+ .AlternateSetting = 0x00,
+
+ .TotalEndpoints = 2,
+
+ .Class = USB_CSCP_VendorSpecificClass,
+ .SubClass = 0x00,
+ .Protocol = 0x00,
+
+ .InterfaceStrIndex = NO_DESCRIPTOR},
+
+ .WebUSB_DataInEndpoint = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+
+ .EndpointAddress = WEBUSB_IN_EPADDR,
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = WEBUSB_EPSIZE,
+ .PollingIntervalMS = 0x05},
+
+ .WebUSB_DataOutEndpoint = {.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+
+ .EndpointAddress = WEBUSB_OUT_EPADDR,
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = WEBUSB_EPSIZE,
+ .PollingIntervalMS = 0x05},
+#endif
+
#ifdef MIDI_ENABLE
/*
* MIDI
@@ -1099,6 +1144,13 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
Size = sizeof(USB_Descriptor_Device_t);
break;
+#ifdef WEBUSB_ENABLE
+ case DTYPE_BOS:
+ Address = &BOSDescriptor;
+ Size = pgm_read_byte(&BOSDescriptor.TotalLength);
+
+ break;
+#endif
case DTYPE_Configuration:
Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
diff --git a/tmk_core/protocol/usb_descriptor.h b/tmk_core/protocol/usb_descriptor.h
index f8b7a863aa..fd25376f90 100644
--- a/tmk_core/protocol/usb_descriptor.h
+++ b/tmk_core/protocol/usb_descriptor.h
@@ -51,6 +51,9 @@
# define USB_ENDPOINTS_ARE_REORDERABLE
# endif
#endif
+#ifdef WEBUSB_ENABLE
+# include "webusb_descriptor.h"
+#endif
/*
* USB descriptor structure
@@ -100,6 +103,12 @@ typedef struct {
USB_Descriptor_Endpoint_t Console_OUTEndpoint;
#endif
+#ifdef WEBUSB_ENABLE
+ USB_Descriptor_Interface_t WebUSB_Interface;
+ USB_Descriptor_Endpoint_t WebUSB_DataInEndpoint;
+ USB_Descriptor_Endpoint_t WebUSB_DataOutEndpoint;
+#endif
+
#ifdef MIDI_ENABLE
USB_Descriptor_Interface_Association_t Audio_Interface_Association;
// MIDI Audio Control Interface
@@ -187,6 +196,10 @@ enum usb_interfaces {
CDI_INTERFACE,
#endif
+#ifdef WEBUSB_ENABLE
+ INTERFACE_ID_WebUSB,
+#endif
+
#if defined(JOYSTICK_ENABLE)
JOYSTICK_INTERFACE,
#endif
@@ -265,6 +278,14 @@ enum usb_endpoints {
CDC_OUT_EPNUM = NEXT_EPNUM,
# endif
#endif
+
+#ifdef WEBUSB_ENABLE
+ WEBUSB_IN_EPNUM = NEXT_EPNUM,
+ WEBUSB_OUT_EPNUM = NEXT_EPNUM,
+# define WEBUSB_IN_EPADDR (ENDPOINT_DIR_IN | WEBUSB_IN_EPNUM)
+# define WEBUSB_OUT_EPADDR (ENDPOINT_DIR_OUT | WEBUSB_OUT_EPNUM)
+#endif
+
#ifdef JOYSTICK_ENABLE
JOYSTICK_IN_EPNUM = NEXT_EPNUM,
# ifdef USB_ENDPOINTS_ARE_REORDERABLE
@@ -310,6 +331,7 @@ enum usb_endpoints {
#define MIDI_STREAM_EPSIZE 64
#define CDC_NOTIFICATION_EPSIZE 8
#define CDC_EPSIZE 16
+#define WEBUSB_EPSIZE 64
#define JOYSTICK_EPSIZE 8
#define DIGITIZER_EPSIZE 8
diff --git a/tmk_core/protocol/webusb_descriptor.h b/tmk_core/protocol/webusb_descriptor.h
new file mode 100644
index 0000000000..a293e5ebb6
--- /dev/null
+++ b/tmk_core/protocol/webusb_descriptor.h
@@ -0,0 +1,266 @@
+#pragma once
+
+#ifndef WORD_TO_BYTES_LE
+# define WORD_TO_BYTES_LE(n) n % 256, (n / 256) % 256
+#endif
+#ifndef LONG_TO_BYTES_LE
+# define LONG_TO_BYTES_LE(n) n % 256, (n / 256) % 256, (n / 65536) % 256, (n / 16777216) % 256
+#endif
+
+#define WEBUSB_VENDOR_CODE 0x42
+
+#ifndef WEBUSB_LANDING_PAGE_URL
+# define WEBUSB_LANDING_PAGE_URL u8"docs.qmk.fm"
+#endif
+
+#define WEBUSB_LANDING_PAGE_PROTOCOL 1 /* 0: http 1: https forced to 1 since https is a requirement to connect over webusb */
+
+#ifndef WEBUSB_LANDING_PAGE_INDEX
+# define WEBUSB_LANDING_PAGE_INDEX 0
+#endif
+
+#define WEBUSB_VERSION VERSION_BCD(1, 0, 0)
+
+/* $ python -c "import uuid;print(', '.join(map(hex, uuid.UUID('3408b638-09a9-47a0-8bfd-a0768815b665').bytes_le)))" */
+#define WEBUSB_PLATFORM_UUID 0x38, 0xb6, 0x8, 0x34, 0xa9, 0x9, 0xa0, 0x47, 0x8b, 0xfd, 0xa0, 0x76, 0x88, 0x15, 0xb6, 0x65
+
+/** \brief Convenience macro to easily create device capability platform descriptors for the WebUSB platform.
+ *
+ * \note This macro is designed to be wrapped in parentheses and included in a sequence to the \ref BOS_DESCRIPTOR macro.
+ *
+ * \param[in] VendorCode Vendor Code that all control requests coming from the browser must use.
+ *
+ * \param[in] LandingPageIndex Index of the URL Descriptor to use as the Landing Page for the device.
+ *
+ */
+#define WEBUSB_PLATFORM_DESCRIPTOR(VendorCode, LandingPageIndex) /* WebUSB Platform Descriptor size */ 24, DTYPE_DeviceCapability, DCTYPE_Platform, /* Reserved */ 0, WEBUSB_PLATFORM_UUID, WORD_TO_BYTES_LE(WEBUSB_VERSION), VendorCode, LandingPageIndex
+
+/** \brief Convenience macro to easily create \ref WebUSB_URL_Descriptor_t instances from a wide character string.
+ *
+ * \note This macro is for little-endian systems only.
+ *
+ * \param[in] URL URL string to initialize a URL Descriptor structure with.
+ *
+ * \note Prefix String literal with u8 to ensure proper conversion: e.g. WEBUSB_URL_DESCRIPTOR(u8"www.google.com")
+ */
+#define WEBUSB_URL_DESCRIPTOR(URL) \
+ { .Header = {.Size = sizeof(WebUSB_URL_Descriptor_t) + (sizeof(URL) - 1), .Type = WebUSB_DTYPE_URL}, .Scheme = (WEBUSB_LANDING_PAGE_PROTOCOL), .UTF8_URL = (URL) }
+
+/* WebUSB Protocol Data Structures */
+enum WebUSB_Request_t {
+ WebUSB_RTYPE_GetURL = 2, /**< Indicates the device should return the indicated WebUSB_URL descriptor. */
+};
+
+enum WebUSB_Descriptor_t {
+ WebUSB_DTYPE_URL = 3, /**< Indicates that the descriptor is a URL descriptor. */
+};
+
+/** \brief WebUSB URL Descriptor (LUFA naming convention).
+ *
+ * Type define for a WebUSB URL Descriptor. This structure uses LUFA-specific element names
+ * to make each element's purpose clearer.
+ *
+ * \note Regardless of CPU architecture, these values should be stored as little endian.
+ */
+typedef struct {
+ USB_Descriptor_Header_t Header; /**< Descriptor header, including type (WebUSB_DTYPE_URL) and size. */
+
+ uint8_t Scheme; /**< URL scheme prefix: 0 means http://, 1 means https://, 255 means included in URL */
+ uint8_t UTF8_URL[]; /**< UTF-8 encoded URL (excluding scheme prefix). */
+} ATTR_PACKED WebUSB_URL_Descriptor_t;
+
+#define MS_OS_20_VENDOR_CODE 0x45 // Must be different than WEBUSB_VENDOR_CODE
+
+#define MS_OS_20_DESCRIPTOR_CONFIGURATION_HEADER_LENGTH 168
+#define MS_OS_20_DESCRIPTOR_FUNCTION_HEADER_LENGTH 160
+#define MS_OS_20_DESCRIPTOR_SET_TOTAL_LENGTH 178 // Sum of `.Length`s in MS_OS_20_Descriptor in WebUSB.c
+
+#define MS_OS_20_DESCRIPTOR_COMPATIBILITY_ID { 'W', 'I', 'N', 'U', 'S', 'B', 0, 0 }
+#define MS_OS_20_DESCRIPTOR_SUB_COMPATIBILITY_ID {0, 0, 0, 0, 0, 0, 0, 0}
+
+#define MS_OS_20_PROPERTY_NAME_LENGTH 42
+#define MS_OS_20_PROPERTY_NAME { \
+ 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, \
+ 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00, \
+ 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, \
+ 'D', 0x00, 's', 0x00, 0x00, 0x00 \
+ }
+#define MS_OS_20_PROPERTY_DATA_LENGTH 80
+#define MS_OS_20_PROPERTY_DATA { \
+ '{', 0x00, '9', 0x00, 'D', 0x00, 'B', 0x00, '7', 0x00, 'F', 0x00, \
+ '1', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00, '7', 0x00, 'E', 0x00, \
+ '7', 0x00, 'A', 0x00, '-', 0x00, '4', 0x00, '0', 0x00, '0', 0x00, \
+ '8', 0x00, '-', 0x00, '9', 0x00, '3', 0x00, '6', 0x00, 'B', 0x00, \
+ '-', 0x00, '6', 0x00, 'B', 0x00, 'A', 0x00, '6', 0x00, 'C', 0x00, \
+ '1', 0x00, '9', 0x00, 'A', 0x00, '3', 0x00, '0', 0x00, '8', 0x00, \
+ 'c', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00 \
+ }
+
+#define MS_OS_20_PLATFORM_UUID 0xdf, 0x60, 0xdd, 0xd8, 0x89, 0x45, 0xc7, 0x4c, 0x9c, 0xd2, 0x65, 0x9d, 0x9e, 0x64, 0x8a, 0x9f
+
+#define MS_OS_20_WINDOWS_VERSION_8_1 0x06030000 // Windows version (8.1)
+
+#ifndef MS_OS_20_ALTERNATE_ENUMERATION_CODE
+# define MS_OS_20_ALTERNATE_ENUMERATION_CODE 0 /**< Set to non-zero to enable Windows to allow device to return alternate USB descriptors. */
+#endif
+
+/** \brief Convenience macro to easily create device capability platform descriptors for the MS OS 2.0 platform.
+ *
+ * \note This macro is designed to be wrapped in parentheses and included in a sequence to the \ref BOS_DESCRIPTOR macro.
+ *
+ * \param[in] VendorCode Vendor Code that all control requests coming from Windows must use.
+ *
+ * \param[in] TotalLength The length, in bytes, of the MS OS 2.0 descriptor set to be retrieved by Windows.
+ */
+#define MS_OS_20_PLATFORM_DESCRIPTOR(VendorCode, TotalLength) /* Total size of this descriptor */ 28, DTYPE_DeviceCapability, DCTYPE_Platform, /* Reserved */ 0, MS_OS_20_PLATFORM_UUID, LONG_TO_BYTES_LE(MS_OS_20_WINDOWS_VERSION_8_1), WORD_TO_BYTES_LE(TotalLength), VendorCode, MS_OS_20_ALTERNATE_ENUMERATION_CODE
+
+ /* MS OS 2.0 Descriptors Data Structures */
+ enum MS_OS_20_wIndex_t {
+ MS_OS_20_DESCRIPTOR_INDEX = 0x07, /**< Indicates the device should return MS OS 2.0 Descriptor Set. */
+ MS_OS_20_SET_ALT_ENUMERATION = 0x08, /**< Indicates the device may "subsequently return alternate USB descriptors when Windows requests the information." */
+ };
+
+enum MS_OS_20_Descriptor_Types {
+ MS_OS_20_SET_HEADER_DESCRIPTOR = 0x00,
+ MS_OS_20_SUBSET_HEADER_CONFIGURATION = 0x01,
+ MS_OS_20_SUBSET_HEADER_FUNCTION = 0x02,
+ MS_OS_20_FEATURE_COMPATBLE_ID = 0x03,
+ MS_OS_20_FEATURE_REG_PROPERTY = 0x04,
+ // MS_OS_20_FEATURE_MIN_RESUME_TIME = 0x05,
+ // MS_OS_20_FEATURE_MODEL_ID = 0x06,
+ MS_OS_20_FEATURE_CCGP_DEVICE = 0x07,
+};
+
+/** \brief Microsoft OS 2.0 Descriptor Set Header (LUFA naming convention).
+ *
+ * \note Regardless of CPU architecture, these values should be stored as little endian.
+ */
+typedef struct {
+ uint16_t Length; /**< The length, in bytes, of this header. Shall be set to 10. */
+ uint16_t DescriptorType; /**< Shall be set to MS_OS_20_SET_HEADER_DESCRIPTOR */
+ uint32_t WindowsVersion;
+ uint16_t TotalLength; /**< The size of entire MS OS 2.0 descriptor set. The value shall match the value in the descriptor set information structure. */
+} ATTR_PACKED MS_OS_20_Descriptor_Set_Header_t;
+
+/** \brief Microsoft OS 2.0 configuration subset header.
+ *
+ */
+typedef struct {
+ uint16_t Length; /**< The length, in bytes, of this subset header. Shall be set to 8. */
+ uint16_t DescriptorType; /**< MS_OS_20_SUBSET_HEADER_CONFIGURATION */
+ uint8_t ConfigurationValue; /**< The configuration value for the USB configuration to which this subset applies. */
+ uint8_t Reserved; /**< Shall be set to 0. */
+ uint16_t TotalLength; /**< The size of entire configuration subset including this header. */
+} ATTR_PACKED MS_OS_20_Configuration_Subset_Header;
+
+/** \brief Microsoft OS 2.0 Function subset header.
+ *
+ */
+typedef struct {
+ uint16_t Length; /**< The length, in bytes, of this subset header. Shall be set to 8. */
+ uint16_t DescriptorType; /**< MS_OS_20_SUBSET_HEADER_FUNCTION */
+ uint8_t FirstInterface; /**< The interface number for the first interface of the function to which this subset applies. */
+ uint8_t Reserved; /**< Shall be set to 0. */
+ uint16_t SubsetLength; /**< The size of entire function subset including this header. */
+} ATTR_PACKED MS_OS_20_Function_Subset_Header;
+
+/** \brief Microsoft OS 2.0 Feature Descriptor for CompatibleID.
+ *
+ * These values are used by Windows to locate the appropriate driver for the device.
+ *
+ * For WebUSB in Chrome, the CompatibleID needs to be WINUSB, and the SubCompatibleID is null.
+ *
+ * \note ID values must be 8 bytes long and contain only the ASCII values for uppercase letters, numbers, underscores, and the NULL character. No other characters are allowed, and the last byte in the ID must be the NULL 0x00.
+ */
+typedef struct {
+ uint16_t Length; /**< The length, bytes, of the compatible ID descriptor including value descriptors. Shall be set to 20. */
+ uint16_t DescriptorType; /**< MS_OS_20_FEATURE_COMPATIBLE_ID */
+ uint8_t CompatibleID[8]; /**< Compatible ID ASCII String */
+ uint8_t SubCompatibleID[8]; /**< Sub-compatible ID ASCII String */
+} ATTR_PACKED MS_OS_20_CompatibleID_Descriptor;
+
+/** \brief Property Data Type values for the Microsoft OS 2.0 Registry Property Descriptor.
+ *
+ */
+enum MS_OS_20_Property_Data_Types {
+ MS_OS_20_REG_SZ = 1, /**< A NULL-terminated Unicode String */
+ MS_OS_20_REG_EXPAND_SZ = 2, /**< A NULL-terminated Unicode String that includes environment variables */
+ MS_OS_20_REG_BINARY = 3, /**< Free-form binary */
+ MS_OS_20_REG_DWORD_LITTLE_ENDIAN = 4, /**< A little-endian 32-bit integer */
+ MS_OS_20_REG_DWORD_BIG_ENDIAN = 5, /**< A big-endian 32-bit integer */
+ MS_OS_20_REG_LINK = 6, /**< A NULL-terminated Unicode string that contains a symbolic link */
+ MS_OS_20_REG_MULTI_SZ = 7 /**< Multiple NULL-terminated Unicode strings */
+};
+
+/** \brief Microsoft OS 2.0 Registry Property Descriptor.
+ *
+ * This descriptor is used to add per-device or per-function registry values that is read by the Windows USB driver stack or the device’s function driver.
+ */
+typedef struct {
+ uint16_t Length; /**< The length in bytes of is descriptor. */
+ uint16_t DescriptorType; /**< MS_OS_20_FEATURE_REG_PROPERTY */
+ uint16_t PropertyDataType; /**< MS_OS_20_Property_Data_types, MS_OS_20_REG_MULTI_SZ even for single interface because libusb. */
+ uint16_t PropertyNameLength; /**< The length of the property name. */
+ uint8_t PropertyName[MS_OS_20_PROPERTY_NAME_LENGTH]; /**< The name of registry property as NULL-terminated UTF-16 LE string. */
+ uint16_t PropertyDataLength; /**< The length of property data. */
+ uint8_t PropertyData[MS_OS_20_PROPERTY_DATA_LENGTH]; /**< Property Data. */
+} ATTR_PACKED MS_OS_20_Registry_Property_Descriptor;
+
+/** \brief Microsoft OS 2.0 Feature Descriptor for CCGP Devices.
+ *
+ * This descriptor indicates that the device should be treated as a composite device by Windows regardless of
+ * the number of interfaces, configuration, or class, subclass, and protocol codes, the device reports.
+ *
+ * \note The CCGP device descriptor must be applied to the entire device.
+ */
+typedef struct {
+ uint16_t Length; /**< The length, bytes, of the compatible ID descriptor including value descriptors. Shall be set to 4. */
+ uint16_t DescriptorType; /**< MS_OS_20_FEATURE_CCGP_DEVICE */
+} ATTR_PACKED MS_OS_20_CCGP_Device_Descriptor;
+
+typedef struct {
+ MS_OS_20_Descriptor_Set_Header_t Header;
+ MS_OS_20_Configuration_Subset_Header ConfigurationSubsetHeader;
+ MS_OS_20_Function_Subset_Header FunctionSubsetHeader;
+ MS_OS_20_CompatibleID_Descriptor CompatibleID;
+ MS_OS_20_Registry_Property_Descriptor RegistryProperty;
+} MS_OS_20_Descriptor_t;
+
+#define MS_OS_20_DESCRIPTOR { \
+ .Header = { \
+ .Length = CPU_TO_LE16(10), \
+ .DescriptorType = CPU_TO_LE16(MS_OS_20_SET_HEADER_DESCRIPTOR), \
+ .WindowsVersion = MS_OS_20_WINDOWS_VERSION_8_1, \
+ .TotalLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_SET_TOTAL_LENGTH) \
+ }, \
+ .ConfigurationSubsetHeader = { \
+ .Length = CPU_TO_LE16(8), \
+ .DescriptorType = CPU_TO_LE16(MS_OS_20_SUBSET_HEADER_CONFIGURATION), \
+ .ConfigurationValue = 0, \
+ .Reserved = 0, \
+ .TotalLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_CONFIGURATION_HEADER_LENGTH) \
+ }, \
+ .FunctionSubsetHeader = { \
+ .Length = CPU_TO_LE16(8), \
+ .DescriptorType = CPU_TO_LE16(MS_OS_20_SUBSET_HEADER_FUNCTION), \
+ .FirstInterface = INTERFACE_ID_WebUSB, \
+ .Reserved = 0, \
+ .SubsetLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_FUNCTION_HEADER_LENGTH) \
+ }, \
+ .CompatibleID = { \
+ .Length = CPU_TO_LE16(20), \
+ .DescriptorType = CPU_TO_LE16(MS_OS_20_FEATURE_COMPATBLE_ID), \
+ .CompatibleID = MS_OS_20_DESCRIPTOR_COMPATIBILITY_ID, \
+ .SubCompatibleID = MS_OS_20_DESCRIPTOR_SUB_COMPATIBILITY_ID \
+ }, \
+ .RegistryProperty = { \
+ .Length = CPU_TO_LE16(132), \
+ .DescriptorType = CPU_TO_LE16(MS_OS_20_FEATURE_REG_PROPERTY), \
+ .PropertyDataType = CPU_TO_LE16(MS_OS_20_REG_MULTI_SZ), \
+ .PropertyNameLength = CPU_TO_LE16(MS_OS_20_PROPERTY_NAME_LENGTH), \
+ .PropertyName = MS_OS_20_PROPERTY_NAME, \
+ .PropertyDataLength = CPU_TO_LE16(MS_OS_20_PROPERTY_DATA_LENGTH), \
+ .PropertyData = MS_OS_20_PROPERTY_DATA \
+ } \
+}
+