summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo Popov <[email protected]>2021-02-10 01:05:37 -0500
committerIvo Popov <[email protected]>2021-02-10 01:05:37 -0500
commitce7fb36337b409bfaf7ebea27d184d47cacd423e (patch)
tree03b6de09f507d9dbea07362f87d4e730c491350b
parenta96ee8f1d850bbd645040e0f5d133e6c1c93a3a4 (diff)
Fix unintended control transfers in webserial example.
-rw-r--r--examples/device/webusb_serial/src/main.c73
1 files changed, 34 insertions, 39 deletions
diff --git a/examples/device/webusb_serial/src/main.c b/examples/device/webusb_serial/src/main.c
index 9309bbf6e..72d25840e 100644
--- a/examples/device/webusb_serial/src/main.c
+++ b/examples/device/webusb_serial/src/main.c
@@ -151,52 +151,47 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
// nothing to with DATA & ACK stage
if (stage != CONTROL_STAGE_SETUP ) return true;
- switch (request->bRequest)
- {
- case VENDOR_REQUEST_WEBUSB:
- // match vendor request in BOS descriptor
- // Get landing page url
- return tud_control_xfer(rhport, request, (void*) &desc_url, desc_url.bLength);
-
- case VENDOR_REQUEST_MICROSOFT:
- if ( request->wIndex == 7 )
- {
- // Get Microsoft OS 2.0 compatible descriptor
- uint16_t total_len;
- memcpy(&total_len, desc_ms_os_20+8, 2);
-
- return tud_control_xfer(rhport, request, (void*) desc_ms_os_20, total_len);
- }else
- {
- return false;
- }
+ if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_VENDOR) {
+ switch (request->bRequest) {
+ case VENDOR_REQUEST_WEBUSB:
+ // match vendor request in BOS descriptor
+ // Get landing page url
+ return tud_control_xfer(rhport, request, (void*) &desc_url, desc_url.bLength);
- case 0x22:
- // Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to
- // connect and disconnect.
- web_serial_connected = (request->wValue != 0);
+ case VENDOR_REQUEST_MICROSOFT:
+ if ( request->wIndex == 7 ) {
+ // Get Microsoft OS 2.0 compatible descriptor
+ uint16_t total_len;
+ memcpy(&total_len, desc_ms_os_20+8, 2);
- // Always lit LED if connected
- if ( web_serial_connected )
- {
- board_led_write(true);
- blink_interval_ms = BLINK_ALWAYS_ON;
+ return tud_control_xfer(rhport, request, (void*) desc_ms_os_20, total_len);
+ } else {
+ return false;
+ }
+ }
+ } else if (
+ request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
+ request->bRequest == 0x22) {
+ // Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to
+ // connect and disconnect.
+ web_serial_connected = (request->wValue != 0);
- tud_vendor_write_str("\r\nTinyUSB WebUSB device example\r\n");
- }else
- {
- blink_interval_ms = BLINK_MOUNTED;
- }
+ // Always lit LED if connected
+ if ( web_serial_connected ) {
+ board_led_write(true);
+ blink_interval_ms = BLINK_ALWAYS_ON;
- // response with status OK
- return tud_control_status(rhport, request);
+ tud_vendor_write_str("\r\nTinyUSB WebUSB device example\r\n");
+ } else {
+ blink_interval_ms = BLINK_MOUNTED;
+ }
- default:
- // stall unknown request
- return false;
+ // response with status OK
+ return tud_control_status(rhport, request);
}
- return true;
+ // stall unknown request
+ return false;
}
void webserial_task(void)