Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/NimBLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -619,6 +620,9 @@ int NimBLEDevice::getNumBonds() {
}

return num_peers;
# else
return 0;
# endif
}

/**
Expand Down Expand Up @@ -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;

Expand All @@ -666,7 +671,8 @@ bool NimBLEDevice::isBonded(const NimBLEAddress& address) {
return true;
}
}

# endif
(void)address; // unused
return false;
}

Expand All @@ -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

Expand Down Expand Up @@ -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
}

/**
Expand All @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions src/NimBLEHIDDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
3 changes: 2 additions & 1 deletion src/NimBLEHIDDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down