summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-02-11 11:25:55 +0700
committerGitHub <[email protected]>2021-02-11 11:25:55 +0700
commitdc64d6ad55951496a77ae4db4fdae686e5778ab2 (patch)
tree39b2df046f1154413ddfaa7cd4ce01f8860e306b /examples
parentba11bb2b80e11f130f5383d733a5529ca4dabdb4 (diff)
parent5178e2af55bd8c6e4342f38cdc48a730b768282a (diff)
Merge pull request #645 from ipopov/webserial-fix
Fix unintended control transfers in webserial example.
Diffstat (limited to 'examples')
-rw-r--r--examples/device/webusb_serial/src/main.c78
1 files changed, 40 insertions, 38 deletions
diff --git a/examples/device/webusb_serial/src/main.c b/examples/device/webusb_serial/src/main.c
index 9309bbf6e..143a73374 100644
--- a/examples/device/webusb_serial/src/main.c
+++ b/examples/device/webusb_serial/src/main.c
@@ -151,52 +151,54 @@ 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);
+ 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);
- return tud_control_xfer(rhport, request, (void*) desc_ms_os_20, total_len);
- }else
- {
- return false;
- }
+ 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);
- case 0x22:
- // Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to
- // connect and disconnect.
- web_serial_connected = (request->wValue != 0);
+ return tud_control_xfer(rhport, request, (void*) desc_ms_os_20, total_len);
+ }else
+ {
+ return false;
+ }
- // Always lit LED if connected
- if ( web_serial_connected )
- {
- board_led_write(true);
- blink_interval_ms = BLINK_ALWAYS_ON;
+ default:
+ 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)