Skip to content

Commit fcdf6ab

Browse files
committed
Check protocol in setProtocol before sending it to the device
1 parent 2283753 commit fcdf6ab

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

BTHID.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void BTHID::Reset() {
4848
l2cap_state = L2CAP_WAIT;
4949
}
5050

51-
void BTHID::disconnect() { // Use this void to disconnect any of the controllers
51+
void BTHID::disconnect() { // Use this void to disconnect the device
5252
// First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
5353
pBtd->l2cap_disconnection_request(hci_handle, ++identifier, interrupt_scid, interrupt_dcid);
5454
Reset();
@@ -383,7 +383,13 @@ void BTHID::setProtocol() {
383383
Notify(PSTR("\r\nSet protocol mode: "), 0x80);
384384
D_PrintHex<uint8_t > (protocolMode, 0x80);
385385
#endif
386-
uint8_t command = 0x70 | protocolMode; // Set Protocol, see HID specs page 33
386+
if (protocolMode != HID_BOOT_PROTOCOL && protocolMode != HID_RPT_PROTOCOL) {
387+
#ifdef DEBUG_USB_HOST
388+
Notify(PSTR("\r\nNot a valid protocol mode. Using Boot protocol instead."), 0x80);
389+
#endif
390+
protocolMode = HID_BOOT_PROTOCOL; // Use Boot Protocol by default
391+
}
392+
uint8_t command = 0x70 | protocolMode; // Set Protocol, see Bluetooth HID specs page 33
387393
pBtd->L2CAP_Command(hci_handle, &command, 1, control_scid[0], control_scid[1]);
388394
}
389395

0 commit comments

Comments
 (0)