Skip to content

Commit 2db8fed

Browse files
committed
Cleanup compiler warnings when using HID device or bonds disabled.
1 parent 56580cb commit 2db8fed

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/NimBLEDevice.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ uint16_t NimBLEDevice::getMTU() {
611611
* @brief Gets the number of bonded peers stored
612612
*/
613613
int NimBLEDevice::getNumBonds() {
614+
# if MYNEWT_VAL(BLE_STORE_MAX_BONDS)
614615
ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
615616
int num_peers, rc;
616617
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() {
619620
}
620621

621622
return num_peers;
623+
# else
624+
return 0;
625+
# endif
622626
}
623627

624628
/**
@@ -652,6 +656,7 @@ bool NimBLEDevice::deleteBond(const NimBLEAddress& address) {
652656
* @returns True if bonded.
653657
*/
654658
bool NimBLEDevice::isBonded(const NimBLEAddress& address) {
659+
# if MYNEWT_VAL(BLE_STORE_MAX_BONDS)
655660
ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
656661
int num_peers, rc;
657662

@@ -666,7 +671,8 @@ bool NimBLEDevice::isBonded(const NimBLEAddress& address) {
666671
return true;
667672
}
668673
}
669-
674+
# endif
675+
(void)address; // unused
670676
return false;
671677
}
672678

@@ -676,6 +682,7 @@ bool NimBLEDevice::isBonded(const NimBLEAddress& address) {
676682
* @returns NimBLEAddress of the found bonded peer or null address if not found.
677683
*/
678684
NimBLEAddress NimBLEDevice::getBondedAddress(int index) {
685+
# if MYNEWT_VAL(BLE_STORE_MAX_BONDS)
679686
ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
680687
int num_peers, rc;
681688
rc = ble_store_util_bonded_peers(&peer_id_addrs[0], &num_peers, MYNEWT_VAL(BLE_STORE_MAX_BONDS));
@@ -684,6 +691,10 @@ NimBLEAddress NimBLEDevice::getBondedAddress(int index) {
684691
}
685692

686693
return NimBLEAddress(peer_id_addrs[index]);
694+
# else
695+
(void)index; // unused
696+
return NimBLEAddress{};
697+
# endif
687698
}
688699
# endif
689700

@@ -1264,10 +1275,17 @@ bool NimBLEDevice::startSecurity(uint16_t connHandle, int* rcPtr) {
12641275
* @return true if the passkey was injected successfully.
12651276
*/
12661277
bool NimBLEDevice::injectPassKey(const NimBLEConnInfo& peerInfo, uint32_t passkey) {
1278+
#if MYNEWT_VAL(BLE_SM_LEGACY)
12671279
ble_sm_io pkey{.action = BLE_SM_IOACT_INPUT, .passkey = passkey};
12681280
int rc = ble_sm_inject_io(peerInfo.getConnHandle(), &pkey);
12691281
NIMBLE_LOGD(LOG_TAG, "BLE_SM_IOACT_INPUT; ble_sm_inject_io result: %d", rc);
12701282
return rc == 0;
1283+
#else
1284+
(void)peerInfo;
1285+
(void)passkey;
1286+
NIMBLE_LOGE(LOG_TAG, "Passkey entry not supported with current security settings");
1287+
return false;
1288+
#endif
12711289
}
12721290

12731291
/**
@@ -1276,10 +1294,17 @@ bool NimBLEDevice::injectPassKey(const NimBLEConnInfo& peerInfo, uint32_t passke
12761294
* @param [in] accept Whether the user confirmed or declined the comparison.
12771295
*/
12781296
bool NimBLEDevice::injectConfirmPasskey(const NimBLEConnInfo& peerInfo, bool accept) {
1297+
#if MYNEWT_VAL(BLE_SM_SC)
12791298
ble_sm_io pkey{.action = BLE_SM_IOACT_NUMCMP, .numcmp_accept = accept};
12801299
int rc = ble_sm_inject_io(peerInfo.getConnHandle(), &pkey);
12811300
NIMBLE_LOGD(LOG_TAG, "BLE_SM_IOACT_NUMCMP; ble_sm_inject_io result: %d", rc);
12821301
return rc == 0;
1302+
#else
1303+
(void)peerInfo;
1304+
(void)accept;
1305+
NIMBLE_LOGE(LOG_TAG, "Numeric comparison not supported with current security settings");
1306+
return false;
1307+
#endif
12831308
}
12841309
# endif // MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
12851310

src/NimBLEHIDDevice.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ void NimBLEHIDDevice::setReportMap(uint8_t* map, uint16_t size) {
8484
* This function called when all the services have been created.
8585
*/
8686
void NimBLEHIDDevice::startServices() {
87-
m_deviceInfoSvc->start();
88-
m_hidSvc->start();
89-
m_batterySvc->start();
87+
// no-op now, services started by server start.
9088
} // startServices
9189

9290
/**

src/NimBLEHIDDevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class NimBLEHIDDevice {
4949
NimBLEHIDDevice(NimBLEServer* server);
5050

5151
void setReportMap(uint8_t* map, uint16_t);
52-
void startServices();
52+
void startServices() __attribute__((deprecated("Services are now started by the server when start() is called, "
53+
"this function is no longer needed and will be removed in a future release.")));
5354
bool setManufacturer(const std::string& name);
5455
void setPnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version);
5556
void setHidInfo(uint8_t country, uint8_t flags);

0 commit comments

Comments
 (0)