Skip to content

Commit de2b325

Browse files
committed
Add WebUSB platform descriptor
Adds a WebUSB platform descriptor to the BOS descriptor and a landing page pointing to https://code.pybricks.com. Signed-off-by: Nate Karstens <[email protected]>
1 parent dbbf6a0 commit de2b325

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

lib/pbio/drv/usb/stm32_usbd/usbd_desc.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static const char software_version[] = PBIO_PROTOCOL_VERSION_STR;
7474
#define USB_DEV_CAP_TYPE_PLATFORM (5)
7575

7676
#define USB_SIZ_STRING_SERIAL 0x1A
77-
#define USB_SIZ_BOS_DESC_CONST (5 + 28)
77+
#define USB_SIZ_BOS_DESC_CONST (5 + 28 + 24)
7878
#define USB_SIZ_UUID (128 / 8)
7979
#define USB_SIZ_PLATFORM_HDR (4 + USB_SIZ_UUID)
8080
#define USB_SIZ_HUB_NAME_MAX (16)
@@ -118,7 +118,7 @@ __ALIGN_BEGIN static uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
118118
USB_DESC_TYPE_BOS, /* bDescriptorType = BOS */
119119
LOBYTE(USB_SIZ_BOS_DESC), /* wTotalLength */
120120
HIBYTE(USB_SIZ_BOS_DESC), /* wTotalLength */
121-
1, /* bNumDeviceCaps */
121+
2, /* bNumDeviceCaps */
122122

123123
28, /* bLength */
124124
USB_DEVICE_CAPABITY_TYPE, /* bDescriptorType = Device Capability */
@@ -141,7 +141,29 @@ __ALIGN_BEGIN static uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
141141
LOBYTE(USBD_SIZ_MS_OS_DSCRPTR_SET), /* wMSOSDescriptorSetTotalLength */
142142
HIBYTE(USBD_SIZ_MS_OS_DSCRPTR_SET), /* wMSOSDescriptorSetTotalLength */
143143
USBD_MS_VENDOR_CODE, /* bMS_VendorCode */
144-
0x00 /* bAltEnumCode = Does not support alternate enumeration */
144+
0x00, /* bAltEnumCode = Does not support alternate enumeration */
145+
146+
24, /* bLength */
147+
USB_DEVICE_CAPABITY_TYPE, /* bDescriptorType = Device Capability */
148+
USB_DEV_CAP_TYPE_PLATFORM, /* bDevCapabilityType */
149+
0x00, /* bReserved */
150+
151+
/*
152+
* PlatformCapabilityUUID
153+
* WebUSB Platform Capability descriptor
154+
* 3408B638-09A9-47A0-8BFD-A0768815B665
155+
* RFC 4122 explains the correct byte ordering
156+
*/
157+
0x38, 0xB6, 0x08, 0x34, /* 32-bit value */
158+
0xA9, 0x09, /* 16-bit value */
159+
0xA0, 0x47, /* 16-bit value */
160+
0x8B, 0xFD,
161+
0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65,
162+
163+
LOBYTE(0x0100), /* bcdVersion */
164+
HIBYTE(0x0100), /* bcdVersion */
165+
USBD_WEBUSB_VENDOR_CODE, /* bVendorCode */
166+
USBD_WEBUSB_LANDING_PAGE_IDX /* iLandingPage */
145167
};
146168

147169
static uint16_t USBD_BOSDesc_Len;

lib/pbio/drv/usb/stm32_usbd/usbd_pybricks.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ __ALIGN_BEGIN static uint8_t USBD_Pybricks_CfgDesc[USBD_PYBRICKS_CONFIG_DESC_SIZ
155155
0x00 /* bInterval */
156156
};
157157

158+
__ALIGN_BEGIN static const uint8_t WebUSB_DescSet[20] __ALIGN_END =
159+
{
160+
20, /* bLength */
161+
0x03, /* bDescriptorType = URL */
162+
0x01, /* bScheme = https:// */
163+
164+
/* URL */
165+
'c', 'o', 'd', 'e', '.',
166+
'p', 'y', 'b', 'r', 'i', 'c', 'k', 's', '.',
167+
'c', 'o', 'm'
168+
};
169+
158170
/**
159171
* @}
160172
*/
@@ -248,6 +260,14 @@ static USBD_StatusTypeDef USBD_Pybricks_Setup(USBD_HandleTypeDef *pdev,
248260
MIN(sizeof(USBD_OSDescSet), req->wLength));
249261
break;
250262

263+
case USBD_WEBUSB_VENDOR_CODE:
264+
if ((req->wValue == USBD_WEBUSB_LANDING_PAGE_IDX) && (req->wIndex == 0x02)) {
265+
(void)USBD_CtlSendData(pdev,
266+
(uint8_t *)WebUSB_DescSet,
267+
MIN(sizeof(WebUSB_DescSet), req->wLength));
268+
}
269+
break;
270+
251271
default:
252272
USBD_CtlError(pdev, req);
253273
ret = USBD_FAIL;

lib/pbio/drv/usb/stm32_usbd/usbd_pybricks.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ extern "C" {
4141
* @{
4242
*/
4343
#define USBD_MS_VENDOR_CODE 0x01
44+
#define USBD_WEBUSB_VENDOR_CODE 0x02
45+
4446
#define USBD_SIZ_MS_OS_DSCRPTR_SET (10 + 20 + 132)
4547

48+
#define USBD_WEBUSB_LANDING_PAGE_IDX 1
49+
4650
#define USBD_PYBRICKS_CONFIG_DESC_SIZ (9 + 9 + 7 + 7)
4751

4852
#define USBD_PYBRICKS_IN_EP 0x81U /* EP1 for data IN */

0 commit comments

Comments
 (0)