diff --git a/src/NimBLEDevice.cpp b/src/NimBLEDevice.cpp index b26c1e92..abf63cfe 100644 --- a/src/NimBLEDevice.cpp +++ b/src/NimBLEDevice.cpp @@ -611,6 +611,7 @@ uint16_t NimBLEDevice::getMTU() { * @brief Gets the number of bonded peers stored */ int NimBLEDevice::getNumBonds() { +# if MYNEWT_VAL(BLE_STORE_MAX_BONDS) ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)]; int num_peers, rc; rc = ble_store_util_bonded_peers(&peer_id_addrs[0], &num_peers, MYNEWT_VAL(BLE_STORE_MAX_BONDS)); @@ -619,6 +620,9 @@ int NimBLEDevice::getNumBonds() { } return num_peers; +# else + return 0; +# endif } /** @@ -652,6 +656,7 @@ bool NimBLEDevice::deleteBond(const NimBLEAddress& address) { * @returns True if bonded. */ bool NimBLEDevice::isBonded(const NimBLEAddress& address) { +# if MYNEWT_VAL(BLE_STORE_MAX_BONDS) ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)]; int num_peers, rc; @@ -666,7 +671,8 @@ bool NimBLEDevice::isBonded(const NimBLEAddress& address) { return true; } } - +# endif + (void)address; // unused return false; } @@ -676,14 +682,19 @@ bool NimBLEDevice::isBonded(const NimBLEAddress& address) { * @returns NimBLEAddress of the found bonded peer or null address if not found. */ NimBLEAddress NimBLEDevice::getBondedAddress(int index) { +# if MYNEWT_VAL(BLE_STORE_MAX_BONDS) ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)]; int num_peers, rc; rc = ble_store_util_bonded_peers(&peer_id_addrs[0], &num_peers, MYNEWT_VAL(BLE_STORE_MAX_BONDS)); - if (rc != 0 || index > num_peers || index < 0) { + if (rc != 0 || index >= num_peers || index < 0) { return NimBLEAddress{}; } return NimBLEAddress(peer_id_addrs[index]); +# else + (void)index; // unused + return NimBLEAddress{}; +# endif } # endif @@ -1264,10 +1275,17 @@ bool NimBLEDevice::startSecurity(uint16_t connHandle, int* rcPtr) { * @return true if the passkey was injected successfully. */ bool NimBLEDevice::injectPassKey(const NimBLEConnInfo& peerInfo, uint32_t passkey) { +#if MYNEWT_VAL(BLE_SM_LEGACY) ble_sm_io pkey{.action = BLE_SM_IOACT_INPUT, .passkey = passkey}; int rc = ble_sm_inject_io(peerInfo.getConnHandle(), &pkey); NIMBLE_LOGD(LOG_TAG, "BLE_SM_IOACT_INPUT; ble_sm_inject_io result: %d", rc); return rc == 0; +#else + (void)peerInfo; + (void)passkey; + NIMBLE_LOGE(LOG_TAG, "Passkey entry not supported with current security settings"); + return false; +#endif } /** @@ -1276,10 +1294,17 @@ bool NimBLEDevice::injectPassKey(const NimBLEConnInfo& peerInfo, uint32_t passke * @param [in] accept Whether the user confirmed or declined the comparison. */ bool NimBLEDevice::injectConfirmPasskey(const NimBLEConnInfo& peerInfo, bool accept) { +#if MYNEWT_VAL(BLE_SM_SC) ble_sm_io pkey{.action = BLE_SM_IOACT_NUMCMP, .numcmp_accept = accept}; int rc = ble_sm_inject_io(peerInfo.getConnHandle(), &pkey); NIMBLE_LOGD(LOG_TAG, "BLE_SM_IOACT_NUMCMP; ble_sm_inject_io result: %d", rc); return rc == 0; +#else + (void)peerInfo; + (void)accept; + NIMBLE_LOGE(LOG_TAG, "Numeric comparison not supported with current security settings"); + return false; +#endif } # endif // MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_PERIPHERAL) diff --git a/src/NimBLEHIDDevice.cpp b/src/NimBLEHIDDevice.cpp index 105ef11b..af0d38ed 100644 --- a/src/NimBLEHIDDevice.cpp +++ b/src/NimBLEHIDDevice.cpp @@ -84,9 +84,7 @@ void NimBLEHIDDevice::setReportMap(uint8_t* map, uint16_t size) { * This function called when all the services have been created. */ void NimBLEHIDDevice::startServices() { - m_deviceInfoSvc->start(); - m_hidSvc->start(); - m_batterySvc->start(); + // no-op now, services started by server start. } // startServices /** diff --git a/src/NimBLEHIDDevice.h b/src/NimBLEHIDDevice.h index 1d82fd12..b479c461 100644 --- a/src/NimBLEHIDDevice.h +++ b/src/NimBLEHIDDevice.h @@ -49,7 +49,8 @@ class NimBLEHIDDevice { NimBLEHIDDevice(NimBLEServer* server); void setReportMap(uint8_t* map, uint16_t); - void startServices(); + void startServices() __attribute__((deprecated("Services are now started by the server when start() is called, " + "this function is no longer needed and will be removed in a future release."))); bool setManufacturer(const std::string& name); void setPnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version); void setHidInfo(uint8_t country, uint8_t flags);