Merge pull request #645 from ipopov/webserial-fix

Fix unintended control transfers in webserial example.
This commit is contained in:
Ha Thach 2021-02-11 11:25:55 +07:00 committed by GitHub
commit dc64d6ad55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 38 deletions

View File

@ -151,6 +151,7 @@ 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;
if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_VENDOR) {
switch (request->bRequest)
{
case VENDOR_REQUEST_WEBUSB:
@ -171,14 +172,18 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
return false;
}
case 0x22:
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);
// Always lit LED if connected
if ( web_serial_connected )
{
if ( web_serial_connected ) {
board_led_write(true);
blink_interval_ms = BLINK_ALWAYS_ON;
@ -190,13 +195,10 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
// response with status OK
return tud_control_status(rhport, request);
default:
// stall unknown request
return false;
}
return true;
// stall unknown request
return false;
}
void webserial_task(void)