From 01f5dd91d50ad6893a5bc8ad0e65449fe690e552 Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Fri, 17 Sep 2021 17:25:19 +0200 Subject: [PATCH] Fix for #115 --- BleKeyboard.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/BleKeyboard.cpp b/BleKeyboard.cpp index 8b77b98..605dc37 100644 --- a/BleKeyboard.cpp +++ b/BleKeyboard.cpp @@ -118,9 +118,17 @@ void BleKeyboard::begin(void) hid->pnp(0x02, 0xe502, 0xa111, 0x0210); hid->hidInfo(0x00, 0x01); - BLESecurity* pSecurity = new BLESecurity(); - pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND); +#if defined(USE_NIMBLE) + + BLEDevice::setSecurityAuth(true, true, true); + +#else + + BLESecurity* pSecurity = new BLESecurity(); + pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND); + +#endif // USE_NIMBLE hid->reportMap((uint8_t*)_hidReportDescriptor, sizeof(_hidReportDescriptor)); hid->startServices(); @@ -480,13 +488,31 @@ size_t BleKeyboard::write(const uint8_t *buffer, size_t size) { void BleKeyboard::onConnect(BLEServer* pServer) { this->connected = true; + +#if !defined(USE_NIMBLE) + + BLE2902* desc = (BLE2902*)this->inputKeyboard->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); + desc->setNotifications(true); + desc = (BLE2902*)this->inputMediaKeys->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); + desc->setNotifications(true); + +#endif // !USE_NIMBLE + } void BleKeyboard::onDisconnect(BLEServer* pServer) { this->connected = false; + #if !defined(USE_NIMBLE) + + BLE2902* desc = (BLE2902*)this->inputKeyboard->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); + desc->setNotifications(false); + desc = (BLE2902*)this->inputMediaKeys->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); + desc->setNotifications(false); + advertising->start(); -#endif // !USE_NIMBLE + +#endif // !USE_NIMBLE } void BleKeyboard::onWrite(BLECharacteristic* me) {