From 0cdde7afe95651e642ac50909824215a370c9eca Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 9 Feb 2016 12:10:12 +0100 Subject: [PATCH] Check status byte in HCI Authentication Complete Event If paring fails simply disconnect --- BTD.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index b3b41a7f..05ef4901 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -589,16 +589,25 @@ void BTD::HCI_event_task() { break; case EV_AUTHENTICATION_COMPLETE: - if(pairWithWii && !connectToWii) { + if(!hcibuf[2]) { // Check if paring was successful + if(pairWithWii && !connectToWii) { #ifdef DEBUG_USB_HOST - Notify(PSTR("\r\nPairing successful with Wiimote"), 0x80); + Notify(PSTR("\r\nPairing successful with Wiimote"), 0x80); #endif - connectToWii = true; // Used to indicate to the Wii service, that it should connect to this device - } else if(pairWithHIDDevice && !connectToHIDDevice) { + connectToWii = true; // Used to indicate to the Wii service, that it should connect to this device + } else if(pairWithHIDDevice && !connectToHIDDevice) { #ifdef DEBUG_USB_HOST - Notify(PSTR("\r\nPairing successful with HID device"), 0x80); + Notify(PSTR("\r\nPairing successful with HID device"), 0x80); #endif - connectToHIDDevice = true; // Used to indicate to the BTHID service, that it should connect to this device + connectToHIDDevice = true; // Used to indicate to the BTHID service, that it should connect to this device + } + } else { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nParing Failed: "), 0x80); + D_PrintHex (hcibuf[2], 0x80); +#endif + hci_disconnect(hci_handle); + hci_state = HCI_DISCONNECT_STATE; } break; /* We will just ignore the following events */