Cleanup and add support for non-esp devices.

This commit is contained in:
h2zero 2021-12-29 08:08:25 -07:00
parent 96459073a4
commit 8620092c90
9 changed files with 175 additions and 87 deletions

View file

@ -11,11 +11,9 @@
* Created on: Jul 3, 2017 * Created on: Jul 3, 2017
* Author: kolban * Author: kolban
*/ */
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include "nimconfig.h" #include "nimconfig.h"
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER) #if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
#include "NimBLEDevice.h" #include "NimBLEDevice.h"
#include "NimBLEAdvertisedDevice.h" #include "NimBLEAdvertisedDevice.h"
@ -783,7 +781,5 @@ size_t NimBLEAdvertisedDevice::getPayloadLength() {
return m_payload.size(); return m_payload.size();
} // getPayloadLength } // getPayloadLength
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
#endif /* CONFIG_BT_ENABLED */

View file

@ -29,6 +29,7 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include <time.h>
class NimBLEScan; class NimBLEScan;

View file

@ -439,7 +439,7 @@ void NimBLECharacteristic::notify(std::string value, bool is_notification) {
int rc = 0; int rc = 0;
for (auto &it : m_subscribedVec) { for (auto &it : m_subscribedVec) {
uint16_t _mtu = getService()->getServer()->getPeerMTU(it.first); uint16_t _mtu = getService()->getServer()->getPeerMTU(it.first) - 3;
// check if connected and subscribed // check if connected and subscribed
if(_mtu == 0 || it.second == 0) { if(_mtu == 0 || it.second == 0) {
@ -455,8 +455,8 @@ void NimBLECharacteristic::notify(std::string value, bool is_notification) {
} }
} }
if (length > _mtu - 3) { if (length > _mtu) {
NIMBLE_LOGW(LOG_TAG, "- Truncating to %d bytes (maximum notify size)", _mtu - 3); NIMBLE_LOGW(LOG_TAG, "- Truncating to %d bytes (maximum notify size)", _mtu);
} }
if(is_notification && (!(it.second & NIMBLE_SUB_NOTIFY))) { if(is_notification && (!(it.second & NIMBLE_SUB_NOTIFY))) {

View file

@ -143,6 +143,9 @@ NimBLECharacteristic* NimBLEDescriptor::getCharacteristic() {
int NimBLEDescriptor::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle, int NimBLEDescriptor::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg) { struct ble_gatt_access_ctxt *ctxt, void *arg) {
(void)conn_handle;
(void)attr_handle;
const ble_uuid_t *uuid; const ble_uuid_t *uuid;
int rc; int rc;
NimBLEDescriptor* pDescriptor = (NimBLEDescriptor*)arg; NimBLEDescriptor* pDescriptor = (NimBLEDescriptor*)arg;
@ -236,6 +239,7 @@ void NimBLEDescriptor::setValue(const uint8_t* data, size_t length) {
m_value.attr_len = length; m_value.attr_len = length;
memcpy(m_value.attr_value, data, length); memcpy(m_value.attr_value, data, length);
portEXIT_CRITICAL(&m_valMux); portEXIT_CRITICAL(&m_valMux);
} // setValue } // setValue
@ -275,6 +279,7 @@ NimBLEDescriptorCallbacks::~NimBLEDescriptorCallbacks() {}
* @param [in] pDescriptor The descriptor that is the source of the event. * @param [in] pDescriptor The descriptor that is the source of the event.
*/ */
void NimBLEDescriptorCallbacks::onRead(NimBLEDescriptor* pDescriptor) { void NimBLEDescriptorCallbacks::onRead(NimBLEDescriptor* pDescriptor) {
(void)pDescriptor;
NIMBLE_LOGD("NimBLEDescriptorCallbacks", "onRead: default"); NIMBLE_LOGD("NimBLEDescriptorCallbacks", "onRead: default");
} // onRead } // onRead
@ -284,6 +289,7 @@ void NimBLEDescriptorCallbacks::onRead(NimBLEDescriptor* pDescriptor) {
* @param [in] pDescriptor The descriptor that is the source of the event. * @param [in] pDescriptor The descriptor that is the source of the event.
*/ */
void NimBLEDescriptorCallbacks::onWrite(NimBLEDescriptor* pDescriptor) { void NimBLEDescriptorCallbacks::onWrite(NimBLEDescriptor* pDescriptor) {
(void)pDescriptor;
NIMBLE_LOGD("NimBLEDescriptorCallbacks", "onWrite: default"); NIMBLE_LOGD("NimBLEDescriptorCallbacks", "onWrite: default");
} // onWrite } // onWrite

View file

@ -18,32 +18,38 @@
#include "NimBLEDevice.h" #include "NimBLEDevice.h"
#include "NimBLEUtils.h" #include "NimBLEUtils.h"
#include "esp_err.h" #ifdef ESP_PLATFORM
#include "esp_bt.h" # include "esp_err.h"
#include "nvs_flash.h" # include "esp_bt.h"
# include "nvs_flash.h"
#if defined(CONFIG_NIMBLE_CPP_IDF) # if defined(CONFIG_NIMBLE_CPP_IDF)
#include "esp_nimble_hci.h" # include "esp_nimble_hci.h"
#include "nimble/nimble_port.h" # include "nimble/nimble_port.h"
#include "nimble/nimble_port_freertos.h" # include "nimble/nimble_port_freertos.h"
#include "host/ble_hs.h" # include "host/ble_hs.h"
#include "host/ble_hs_pvcy.h" # include "host/ble_hs_pvcy.h"
#include "host/util/util.h" # include "host/util/util.h"
#include "services/gap/ble_svc_gap.h" # include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h" # include "services/gatt/ble_svc_gatt.h"
# else
# include "nimble/esp_port/esp-hci/include/esp_nimble_hci.h"
# endif
#else #else
#include "nimble/esp_port/esp-hci/include/esp_nimble_hci.h" # include "nimble/nimble/controller/include/controller/ble_phy.h"
#include "nimble/porting/nimble/include/nimble/nimble_port.h"
#include "nimble/porting/npl/freertos/include/nimble/nimble_port_freertos.h"
#include "nimble/nimble/host/include/host/ble_hs.h"
#include "nimble/nimble/host/include/host/ble_hs_pvcy.h"
#include "nimble/nimble/host/util/include/host/util/util.h"
#include "nimble/nimble/host/services/gap/include/services/gap/ble_svc_gap.h"
#include "nimble/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h"
#endif #endif
#ifdef CONFIG_ENABLE_ARDUINO_DEPENDS #ifndef CONFIG_NIMBLE_CPP_IDF
#include "esp32-hal-bt.h" # include "nimble/porting/nimble/include/nimble/nimble_port.h"
# include "nimble/porting/npl/freertos/include/nimble/nimble_port_freertos.h"
# include "nimble/nimble/host/include/host/ble_hs.h"
# include "nimble/nimble/host/include/host/ble_hs_pvcy.h"
# include "nimble/nimble/host/util/include/host/util/util.h"
# include "nimble/nimble/host/services/gap/include/services/gap/ble_svc_gap.h"
# include "nimble/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h"
#endif
#if defined(ESP_PLATFORM) && defined(CONFIG_ENABLE_ARDUINO_DEPENDS)
# include "esp32-hal-bt.h"
#endif #endif
#include "NimBLELog.h" #include "NimBLELog.h"
@ -75,9 +81,10 @@ std::list <NimBLEAddress> NimBLEDevice::m_ignoreList;
std::vector<NimBLEAddress> NimBLEDevice::m_whiteList; std::vector<NimBLEAddress> NimBLEDevice::m_whiteList;
NimBLESecurityCallbacks* NimBLEDevice::m_securityCallbacks = nullptr; NimBLESecurityCallbacks* NimBLEDevice::m_securityCallbacks = nullptr;
uint8_t NimBLEDevice::m_own_addr_type = BLE_OWN_ADDR_PUBLIC; uint8_t NimBLEDevice::m_own_addr_type = BLE_OWN_ADDR_PUBLIC;
#ifdef ESP_PLATFORM
uint16_t NimBLEDevice::m_scanDuplicateSize = CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE; uint16_t NimBLEDevice::m_scanDuplicateSize = CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE;
uint8_t NimBLEDevice::m_scanFilterMode = CONFIG_BTDM_SCAN_DUPL_TYPE; uint8_t NimBLEDevice::m_scanFilterMode = CONFIG_BTDM_SCAN_DUPL_TYPE;
#endif
/** /**
* @brief Create a new instance of a server. * @brief Create a new instance of a server.
@ -142,7 +149,8 @@ void NimBLEDevice::stopAdvertising() {
* try and release/delete it. * try and release/delete it.
*/ */
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER) #if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
/* STATIC */ NimBLEScan* NimBLEDevice::getScan() { /* STATIC */
NimBLEScan* NimBLEDevice::getScan() {
if (m_pScan == nullptr) { if (m_pScan == nullptr) {
m_pScan = new NimBLEScan(); m_pScan = new NimBLEScan();
} }
@ -159,7 +167,8 @@ void NimBLEDevice::stopAdvertising() {
* @return A reference to the new client object. * @return A reference to the new client object.
*/ */
#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) #if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
/* STATIC */ NimBLEClient* NimBLEDevice::createClient(NimBLEAddress peerAddress) { /* STATIC */
NimBLEClient* NimBLEDevice::createClient(NimBLEAddress peerAddress) {
if(m_cList.size() >= NIMBLE_MAX_CONNECTIONS) { if(m_cList.size() >= NIMBLE_MAX_CONNECTIONS) {
NIMBLE_LOGW(LOG_TAG,"Number of clients exceeds Max connections. Cur=%d Max=%d", NIMBLE_LOGW(LOG_TAG,"Number of clients exceeds Max connections. Cur=%d Max=%d",
m_cList.size(), NIMBLE_MAX_CONNECTIONS); m_cList.size(), NIMBLE_MAX_CONNECTIONS);
@ -177,7 +186,8 @@ void NimBLEDevice::stopAdvertising() {
* Checks if it is connected or trying to connect and disconnects/stops it first. * Checks if it is connected or trying to connect and disconnects/stops it first.
* @param [in] pClient A pointer to the client object. * @param [in] pClient A pointer to the client object.
*/ */
/* STATIC */ bool NimBLEDevice::deleteClient(NimBLEClient* pClient) { /* STATIC */
bool NimBLEDevice::deleteClient(NimBLEClient* pClient) {
if(pClient == nullptr) { if(pClient == nullptr) {
return false; return false;
} }
@ -221,7 +231,8 @@ void NimBLEDevice::stopAdvertising() {
* @brief Get the list of created client objects. * @brief Get the list of created client objects.
* @return A pointer to the list of clients. * @return A pointer to the list of clients.
*/ */
/* STATIC */std::list<NimBLEClient*>* NimBLEDevice::getClientList() { /* STATIC */
std::list<NimBLEClient*>* NimBLEDevice::getClientList() {
return &m_cList; return &m_cList;
} // getClientList } // getClientList
@ -230,7 +241,8 @@ void NimBLEDevice::stopAdvertising() {
* @brief Get the number of created client objects. * @brief Get the number of created client objects.
* @return Number of client objects created. * @return Number of client objects created.
*/ */
/* STATIC */size_t NimBLEDevice::getClientListSize() { /* STATIC */
size_t NimBLEDevice::getClientListSize() {
return m_cList.size(); return m_cList.size();
} // getClientList } // getClientList
@ -240,7 +252,8 @@ void NimBLEDevice::stopAdvertising() {
* @param [in] conn_id The client connection ID to search for. * @param [in] conn_id The client connection ID to search for.
* @return A pointer to the client object with the spcified connection ID. * @return A pointer to the client object with the spcified connection ID.
*/ */
/* STATIC */NimBLEClient* NimBLEDevice::getClientByID(uint16_t conn_id) { /* STATIC */
NimBLEClient* NimBLEDevice::getClientByID(uint16_t conn_id) {
for(auto it = m_cList.cbegin(); it != m_cList.cend(); ++it) { for(auto it = m_cList.cbegin(); it != m_cList.cend(); ++it) {
if((*it)->getConnId() == conn_id) { if((*it)->getConnId() == conn_id) {
return (*it); return (*it);
@ -256,7 +269,8 @@ void NimBLEDevice::stopAdvertising() {
* @param [in] peer_addr The address of the peer to search for. * @param [in] peer_addr The address of the peer to search for.
* @return A pointer to the client object with the peer address. * @return A pointer to the client object with the peer address.
*/ */
/* STATIC */NimBLEClient* NimBLEDevice::getClientByPeerAddress(const NimBLEAddress &peer_addr) { /* STATIC */
NimBLEClient* NimBLEDevice::getClientByPeerAddress(const NimBLEAddress &peer_addr) {
for(auto it = m_cList.cbegin(); it != m_cList.cend(); ++it) { for(auto it = m_cList.cbegin(); it != m_cList.cend(); ++it) {
if((*it)->getPeerAddress().equals(peer_addr)) { if((*it)->getPeerAddress().equals(peer_addr)) {
return (*it); return (*it);
@ -270,7 +284,8 @@ void NimBLEDevice::stopAdvertising() {
* @brief Finds the first disconnected client in the list. * @brief Finds the first disconnected client in the list.
* @return A pointer to the first client object that is not connected to a peer. * @return A pointer to the first client object that is not connected to a peer.
*/ */
/* STATIC */NimBLEClient* NimBLEDevice::getDisconnectedClient() { /* STATIC */
NimBLEClient* NimBLEDevice::getDisconnectedClient() {
for(auto it = m_cList.cbegin(); it != m_cList.cend(); ++it) { for(auto it = m_cList.cbegin(); it != m_cList.cend(); ++it) {
if(!(*it)->isConnected()) { if(!(*it)->isConnected()) {
return (*it); return (*it);
@ -281,7 +296,7 @@ void NimBLEDevice::stopAdvertising() {
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) #endif // #if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
#ifdef ESP_PLATFORM
/** /**
* @brief Set the transmission power. * @brief Set the transmission power.
* @param [in] powerLevel The power level to set, can be one of: * @param [in] powerLevel The power level to set, can be one of:
@ -307,12 +322,15 @@ void NimBLEDevice::stopAdvertising() {
* * ESP_BLE_PWR_TYPE_SCAN = 10, For scan * * ESP_BLE_PWR_TYPE_SCAN = 10, For scan
* * ESP_BLE_PWR_TYPE_DEFAULT = 11, For default, if not set other, it will use default value * * ESP_BLE_PWR_TYPE_DEFAULT = 11, For default, if not set other, it will use default value
*/ */
/* STATIC */ void NimBLEDevice::setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType) { /* STATIC */
void NimBLEDevice::setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType) {
NIMBLE_LOGD(LOG_TAG, ">> setPower: %d (type: %d)", powerLevel, powerType); NIMBLE_LOGD(LOG_TAG, ">> setPower: %d (type: %d)", powerLevel, powerType);
esp_err_t errRc = esp_ble_tx_power_set(powerType, powerLevel); esp_err_t errRc = esp_ble_tx_power_set(powerType, powerLevel);
if (errRc != ESP_OK) { if (errRc != ESP_OK) {
NIMBLE_LOGE(LOG_TAG, "esp_ble_tx_power_set: rc=%d", errRc); NIMBLE_LOGE(LOG_TAG, "esp_ble_tx_power_set: rc=%d", errRc);
} }
NIMBLE_LOGD(LOG_TAG, "<< setPower"); NIMBLE_LOGD(LOG_TAG, "<< setPower");
} // setPower } // setPower
@ -334,9 +352,8 @@ void NimBLEDevice::stopAdvertising() {
* * ESP_BLE_PWR_TYPE_DEFAULT = 11, For default, if not set other, it will use default value * * ESP_BLE_PWR_TYPE_DEFAULT = 11, For default, if not set other, it will use default value
* @return the power level currently used by the type specified. * @return the power level currently used by the type specified.
*/ */
/* STATIC */
/* STATIC */ int NimBLEDevice::getPower(esp_ble_power_type_t powerType) { int NimBLEDevice::getPower(esp_ble_power_type_t powerType) {
switch(esp_ble_tx_power_get(powerType)) { switch(esp_ble_tx_power_get(powerType)) {
case ESP_PWR_LVL_N12: case ESP_PWR_LVL_N12:
return -12; return -12;
@ -359,13 +376,25 @@ void NimBLEDevice::stopAdvertising() {
} }
} // getPower } // getPower
#else
void NimBLEDevice::setPower(int dbm) {
ble_phy_txpwr_set(dbm);
}
int NimBLEDevice::getPower() {
return ble_phy_txpwr_get();
}
#endif
/** /**
* @brief Get our device address. * @brief Get our device address.
* @return A NimBLEAddress object of our public address if we have one, * @return A NimBLEAddress object of our public address if we have one,
* if not then our current random address. * if not then our current random address.
*/ */
/* STATIC*/ NimBLEAddress NimBLEDevice::getAddress() { /* STATIC*/
NimBLEAddress NimBLEDevice::getAddress() {
ble_addr_t addr = {BLE_ADDR_PUBLIC, 0}; ble_addr_t addr = {BLE_ADDR_PUBLIC, 0};
if(BLE_HS_ENOADDR == ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, addr.val, NULL)) { if(BLE_HS_ENOADDR == ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, addr.val, NULL)) {
@ -382,7 +411,8 @@ void NimBLEDevice::stopAdvertising() {
* @brief Return a string representation of the address of this device. * @brief Return a string representation of the address of this device.
* @return A string representation of this device address. * @return A string representation of this device address.
*/ */
/* STATIC */ std::string NimBLEDevice::toString() { /* STATIC */
std::string NimBLEDevice::toString() {
return getAddress().toString(); return getAddress().toString();
} // toString } // toString
@ -392,7 +422,8 @@ void NimBLEDevice::stopAdvertising() {
* @param [in] mtu Value to set local mtu: * @param [in] mtu Value to set local mtu:
* * This should be larger than 23 and lower or equal to BLE_ATT_MTU_MAX = 527. * * This should be larger than 23 and lower or equal to BLE_ATT_MTU_MAX = 527.
*/ */
/* STATIC */int NimBLEDevice::setMTU(uint16_t mtu) { /* STATIC */
int NimBLEDevice::setMTU(uint16_t mtu) {
NIMBLE_LOGD(LOG_TAG, ">> setLocalMTU: %d", mtu); NIMBLE_LOGD(LOG_TAG, ">> setLocalMTU: %d", mtu);
int rc = ble_att_set_preferred_mtu(mtu); int rc = ble_att_set_preferred_mtu(mtu);
@ -410,11 +441,13 @@ void NimBLEDevice::stopAdvertising() {
* @brief Get local MTU value set. * @brief Get local MTU value set.
* @return The current preferred MTU setting. * @return The current preferred MTU setting.
*/ */
/* STATIC */uint16_t NimBLEDevice::getMTU() { /* STATIC */
uint16_t NimBLEDevice::getMTU() {
return ble_att_preferred_mtu(); return ble_att_preferred_mtu();
} }
#ifdef ESP_PLATFORM
/** /**
* @brief Set the duplicate filter cache size for filtering scanned devices. * @brief Set the duplicate filter cache size for filtering scanned devices.
* @param [in] cacheSize The number of advertisements filtered before the cache is reset.\n * @param [in] cacheSize The number of advertisements filtered before the cache is reset.\n
@ -460,6 +493,7 @@ void NimBLEDevice::setScanFilterMode(uint8_t mode) {
m_scanFilterMode = mode; m_scanFilterMode = mode;
} }
#endif
#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) || defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL) #if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) || defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
/** /**
@ -482,7 +516,7 @@ int NimBLEDevice::getNumBonds() {
/** /**
* @brief Deletes all bonding information. * @brief Deletes all bonding information.
*/ */
/*STATIC*/ /*STATIC*/
void NimBLEDevice::deleteAllBonds() { void NimBLEDevice::deleteAllBonds() {
ble_store_clear(); ble_store_clear();
} }
@ -562,6 +596,7 @@ NimBLEAddress NimBLEDevice::getBondedAddress(int index) {
* @param [in] address The address to check for in the whitelist. * @param [in] address The address to check for in the whitelist.
* @returns true if the address is in the whitelist. * @returns true if the address is in the whitelist.
*/ */
/*STATIC*/
bool NimBLEDevice::onWhiteList(const NimBLEAddress & address) { bool NimBLEDevice::onWhiteList(const NimBLEAddress & address) {
for (auto &it : m_whiteList) { for (auto &it : m_whiteList) {
if (it == address) { if (it == address) {
@ -578,6 +613,7 @@ bool NimBLEDevice::onWhiteList(const NimBLEAddress & address) {
* @param [in] address The address to add to the whitelist. * @param [in] address The address to add to the whitelist.
* @returns true if successful. * @returns true if successful.
*/ */
/*STATIC*/
bool NimBLEDevice::whiteListAdd(const NimBLEAddress & address) { bool NimBLEDevice::whiteListAdd(const NimBLEAddress & address) {
if (NimBLEDevice::onWhiteList(address)) { if (NimBLEDevice::onWhiteList(address)) {
return true; return true;
@ -609,6 +645,7 @@ bool NimBLEDevice::whiteListAdd(const NimBLEAddress & address) {
* @param [in] address The address to remove from the whitelist. * @param [in] address The address to remove from the whitelist.
* @returns true if successful. * @returns true if successful.
*/ */
/*STATIC*/
bool NimBLEDevice::whiteListRemove(const NimBLEAddress & address) { bool NimBLEDevice::whiteListRemove(const NimBLEAddress & address) {
if (!NimBLEDevice::onWhiteList(address)) { if (!NimBLEDevice::onWhiteList(address)) {
return true; return true;
@ -648,6 +685,7 @@ bool NimBLEDevice::whiteListRemove(const NimBLEAddress & address) {
* @brief Gets the count of addresses in the whitelist. * @brief Gets the count of addresses in the whitelist.
* @returns The number of addresses in the whitelist. * @returns The number of addresses in the whitelist.
*/ */
/*STATIC*/
size_t NimBLEDevice::getWhiteListCount() { size_t NimBLEDevice::getWhiteListCount() {
return m_whiteList.size(); return m_whiteList.size();
} }
@ -658,6 +696,7 @@ size_t NimBLEDevice::getWhiteListCount() {
* @param [in] index The vector index to retrieve the address from. * @param [in] index The vector index to retrieve the address from.
* @returns the NimBLEAddress at the whitelist index or nullptr if not found. * @returns the NimBLEAddress at the whitelist index or nullptr if not found.
*/ */
/*STATIC*/
NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) { NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
if (index > m_whiteList.size()) { if (index > m_whiteList.size()) {
NIMBLE_LOGE(LOG_TAG, "Invalid index; %u", index); NIMBLE_LOGE(LOG_TAG, "Invalid index; %u", index);
@ -671,7 +710,8 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
* @brief Host reset, we pass the message so we don't make calls until resynced. * @brief Host reset, we pass the message so we don't make calls until resynced.
* @param [in] reason The reason code for the reset. * @param [in] reason The reason code for the reset.
*/ */
/* STATIC */ void NimBLEDevice::onReset(int reason) /* STATIC */
void NimBLEDevice::onReset(int reason)
{ {
if(!m_synced) { if(!m_synced) {
return; return;
@ -695,7 +735,8 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
/** /**
* @brief Host resynced with controller, all clear to make calls to the stack. * @brief Host resynced with controller, all clear to make calls to the stack.
*/ */
/* STATIC */ void NimBLEDevice::onSync(void) /* STATIC */
void NimBLEDevice::onSync(void)
{ {
NIMBLE_LOGI(LOG_TAG, "NimBle host synced."); NIMBLE_LOGI(LOG_TAG, "NimBle host synced.");
// This check is needed due to potentially being called multiple times in succession // This check is needed due to potentially being called multiple times in succession
@ -708,6 +749,14 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
int rc = ble_hs_util_ensure_addr(0); int rc = ble_hs_util_ensure_addr(0);
assert(rc == 0); assert(rc == 0);
#ifndef ESP_PLATFORM
rc = ble_hs_id_infer_auto(m_own_addr_type, &m_own_addr_type);
if (rc != 0) {
NIMBLE_LOGE(LOG_TAG, "error determining address type; rc=%d", rc);
return;
}
#endif
// Yield for houskeeping before returning to operations. // Yield for houskeeping before returning to operations.
// Occasionally triggers exception without. // Occasionally triggers exception without.
taskYIELD(); taskYIELD();
@ -733,9 +782,11 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
/** /**
* @brief The main host task. * @brief The main host task.
*/ */
/* STATIC */ void NimBLEDevice::host_task(void *param) /* STATIC */
void NimBLEDevice::host_task(void *param)
{ {
NIMBLE_LOGI(LOG_TAG, "BLE Host Task Started"); NIMBLE_LOGI(LOG_TAG, "BLE Host Task Started");
/* This function will return only when nimble_port_stop() is executed */ /* This function will return only when nimble_port_stop() is executed */
nimble_port_run(); nimble_port_run();
@ -747,9 +798,11 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
* @brief Initialize the %BLE environment. * @brief Initialize the %BLE environment.
* @param [in] deviceName The device name of the device. * @param [in] deviceName The device name of the device.
*/ */
/* STATIC */ void NimBLEDevice::init(const std::string &deviceName) { /* STATIC */
void NimBLEDevice::init(const std::string &deviceName) {
if(!initialized){ if(!initialized){
int rc=0; int rc=0;
#ifdef ESP_PLATFORM
esp_err_t errRc = ESP_OK; esp_err_t errRc = ESP_OK;
#ifdef CONFIG_ENABLE_ARDUINO_DEPENDS #ifdef CONFIG_ENABLE_ARDUINO_DEPENDS
@ -781,6 +834,7 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg)); ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg));
ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE)); ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));
ESP_ERROR_CHECK(esp_nimble_hci_init()); ESP_ERROR_CHECK(esp_nimble_hci_init());
#endif
nimble_port_init(); nimble_port_init();
// Setup callbacks for host events // Setup callbacks for host events
@ -805,9 +859,10 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
nimble_port_freertos_init(NimBLEDevice::host_task); nimble_port_freertos_init(NimBLEDevice::host_task);
} }
// Wait for host and controller to sync before returning and accepting new tasks // Wait for host and controller to sync before returning and accepting new tasks
while(!m_synced){ while(!m_synced){
vTaskDelay(1 / portTICK_PERIOD_MS); taskYIELD();
} }
initialized = true; // Set the initialization flag to ensure we are only initialized once. initialized = true; // Set the initialization flag to ensure we are only initialized once.
@ -819,16 +874,17 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
* @param [in] clearAll If true, deletes all server/advertising/scan/client objects after deinitializing. * @param [in] clearAll If true, deletes all server/advertising/scan/client objects after deinitializing.
* @note If clearAll is true when called, any references to the created objects become invalid. * @note If clearAll is true when called, any references to the created objects become invalid.
*/ */
/* STATIC */ void NimBLEDevice::deinit(bool clearAll) { /* STATIC */
void NimBLEDevice::deinit(bool clearAll) {
int ret = nimble_port_stop(); int ret = nimble_port_stop();
if (ret == 0) { if (ret == 0) {
nimble_port_deinit(); nimble_port_deinit();
#ifdef ESP_PLATFORM
ret = esp_nimble_hci_and_controller_deinit(); ret = esp_nimble_hci_and_controller_deinit();
if (ret != ESP_OK) { if (ret != ESP_OK) {
NIMBLE_LOGE(LOG_TAG, "esp_nimble_hci_and_controller_deinit() failed with error: %d", ret); NIMBLE_LOGE(LOG_TAG, "esp_nimble_hci_and_controller_deinit() failed with error: %d", ret);
} }
#endif
initialized = false; initialized = false;
m_synced = false; m_synced = false;
@ -875,6 +931,7 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
* @brief Check if the initialization is complete. * @brief Check if the initialization is complete.
* @return true if initialized. * @return true if initialized.
*/ */
/*STATIC*/
bool NimBLEDevice::getInitialized() { bool NimBLEDevice::getInitialized() {
return initialized; return initialized;
} // getInitialized } // getInitialized
@ -886,7 +943,8 @@ bool NimBLEDevice::getInitialized() {
* @param mitm If true we are capable of man in the middle protection, false if not. * @param mitm If true we are capable of man in the middle protection, false if not.
* @param sc If true we will perform secure connection pairing, false we will use legacy pairing. * @param sc If true we will perform secure connection pairing, false we will use legacy pairing.
*/ */
/*STATIC*/ void NimBLEDevice::setSecurityAuth(bool bonding, bool mitm, bool sc) { /*STATIC*/
void NimBLEDevice::setSecurityAuth(bool bonding, bool mitm, bool sc) {
NIMBLE_LOGD(LOG_TAG, "Setting bonding: %d, mitm: %d, sc: %d",bonding,mitm,sc); NIMBLE_LOGD(LOG_TAG, "Setting bonding: %d, mitm: %d, sc: %d",bonding,mitm,sc);
ble_hs_cfg.sm_bonding = bonding; ble_hs_cfg.sm_bonding = bonding;
ble_hs_cfg.sm_mitm = mitm; ble_hs_cfg.sm_mitm = mitm;
@ -903,7 +961,8 @@ bool NimBLEDevice::getInitialized() {
* * 0x08 BLE_SM_PAIR_AUTHREQ_SC * * 0x08 BLE_SM_PAIR_AUTHREQ_SC
* * 0x10 BLE_SM_PAIR_AUTHREQ_KEYPRESS - not yet supported. * * 0x10 BLE_SM_PAIR_AUTHREQ_KEYPRESS - not yet supported.
*/ */
/*STATIC*/void NimBLEDevice::setSecurityAuth(uint8_t auth_req) { /*STATIC*/
void NimBLEDevice::setSecurityAuth(uint8_t auth_req) {
NimBLEDevice::setSecurityAuth((auth_req & BLE_SM_PAIR_AUTHREQ_BOND)>0, NimBLEDevice::setSecurityAuth((auth_req & BLE_SM_PAIR_AUTHREQ_BOND)>0,
(auth_req & BLE_SM_PAIR_AUTHREQ_MITM)>0, (auth_req & BLE_SM_PAIR_AUTHREQ_MITM)>0,
(auth_req & BLE_SM_PAIR_AUTHREQ_SC)>0); (auth_req & BLE_SM_PAIR_AUTHREQ_SC)>0);
@ -919,7 +978,8 @@ bool NimBLEDevice::getInitialized() {
* * 0x03 BLE_HS_IO_NO_INPUT_OUTPUT NoInputNoOutput IO capability * * 0x03 BLE_HS_IO_NO_INPUT_OUTPUT NoInputNoOutput IO capability
* * 0x04 BLE_HS_IO_KEYBOARD_DISPLAY KeyboardDisplay Only IO capability * * 0x04 BLE_HS_IO_KEYBOARD_DISPLAY KeyboardDisplay Only IO capability
*/ */
/*STATIC*/ void NimBLEDevice::setSecurityIOCap(uint8_t iocap) { /*STATIC*/
void NimBLEDevice::setSecurityIOCap(uint8_t iocap) {
ble_hs_cfg.sm_io_cap = iocap; ble_hs_cfg.sm_io_cap = iocap;
} // setSecurityIOCap } // setSecurityIOCap
@ -933,7 +993,8 @@ bool NimBLEDevice::getInitialized() {
* * 0x04: BLE_SM_PAIR_KEY_DIST_SIGN * * 0x04: BLE_SM_PAIR_KEY_DIST_SIGN
* * 0x08: BLE_SM_PAIR_KEY_DIST_LINK * * 0x08: BLE_SM_PAIR_KEY_DIST_LINK
*/ */
/*STATIC*/void NimBLEDevice::setSecurityInitKey(uint8_t init_key) { /*STATIC*/
void NimBLEDevice::setSecurityInitKey(uint8_t init_key) {
ble_hs_cfg.sm_our_key_dist = init_key; ble_hs_cfg.sm_our_key_dist = init_key;
} // setsSecurityInitKey } // setsSecurityInitKey
@ -947,7 +1008,8 @@ bool NimBLEDevice::getInitialized() {
* * 0x04: BLE_SM_PAIR_KEY_DIST_SIGN * * 0x04: BLE_SM_PAIR_KEY_DIST_SIGN
* * 0x08: BLE_SM_PAIR_KEY_DIST_LINK * * 0x08: BLE_SM_PAIR_KEY_DIST_LINK
*/ */
/*STATIC*/void NimBLEDevice::setSecurityRespKey(uint8_t resp_key) { /*STATIC*/
void NimBLEDevice::setSecurityRespKey(uint8_t resp_key) {
ble_hs_cfg.sm_their_key_dist = resp_key; ble_hs_cfg.sm_their_key_dist = resp_key;
} // setsSecurityRespKey } // setsSecurityRespKey
@ -956,7 +1018,8 @@ bool NimBLEDevice::getInitialized() {
* @brief Set the passkey the server will ask for when pairing. * @brief Set the passkey the server will ask for when pairing.
* @param [in] pin The passkey to use. * @param [in] pin The passkey to use.
*/ */
/*STATIC*/void NimBLEDevice::setSecurityPasskey(uint32_t pin) { /*STATIC*/
void NimBLEDevice::setSecurityPasskey(uint32_t pin) {
m_passkey = pin; m_passkey = pin;
} // setSecurityPasskey } // setSecurityPasskey
@ -965,7 +1028,8 @@ bool NimBLEDevice::getInitialized() {
* @brief Get the current passkey used for pairing. * @brief Get the current passkey used for pairing.
* @return The current passkey. * @return The current passkey.
*/ */
/*STATIC*/uint32_t NimBLEDevice::getSecurityPasskey() { /*STATIC*/
uint32_t NimBLEDevice::getSecurityPasskey() {
return m_passkey; return m_passkey;
} // getSecurityPasskey } // getSecurityPasskey
@ -975,11 +1039,13 @@ bool NimBLEDevice::getInitialized() {
* @param [in] callbacks Pointer to NimBLESecurityCallbacks class * @param [in] callbacks Pointer to NimBLESecurityCallbacks class
* @deprecated For backward compatibility, New code should use client/server callback methods. * @deprecated For backward compatibility, New code should use client/server callback methods.
*/ */
/*STATIC*/
void NimBLEDevice::setSecurityCallbacks(NimBLESecurityCallbacks* callbacks) { void NimBLEDevice::setSecurityCallbacks(NimBLESecurityCallbacks* callbacks) {
NimBLEDevice::m_securityCallbacks = callbacks; NimBLEDevice::m_securityCallbacks = callbacks;
} // setSecurityCallbacks } // setSecurityCallbacks
#ifdef ESP_PLATFORM
/** /**
* @brief Set the own address type. * @brief Set the own address type.
* @param [in] own_addr_type Own Bluetooth Device address type.\n * @param [in] own_addr_type Own Bluetooth Device address type.\n
@ -990,6 +1056,7 @@ void NimBLEDevice::setSecurityCallbacks(NimBLESecurityCallbacks* callbacks) {
* * 0x03: BLE_OWN_ADDR_RPA_RANDOM_DEFAULT * * 0x03: BLE_OWN_ADDR_RPA_RANDOM_DEFAULT
* @param [in] useNRPA If true, and address type is random, uses a non-resolvable random address. * @param [in] useNRPA If true, and address type is random, uses a non-resolvable random address.
*/ */
/*STATIC*/
void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) { void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
m_own_addr_type = own_addr_type; m_own_addr_type = own_addr_type;
switch (own_addr_type) { switch (own_addr_type) {
@ -1013,18 +1080,15 @@ void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
break; break;
} }
} // setOwnAddrType } // setOwnAddrType
#endif
/** /**
* @brief Start the connection securing and authorization for this connection. * @brief Start the connection securing and authorization for this connection.
* @param conn_id The connection id of the peer device. * @param conn_id The connection id of the peer device.
* @returns NimBLE stack return code, 0 = success. * @returns NimBLE stack return code, 0 = success.
*/ */
/* STATIC */int NimBLEDevice::startSecurity(uint16_t conn_id) { /* STATIC */
/* if(m_securityCallbacks != nullptr) { int NimBLEDevice::startSecurity(uint16_t conn_id) {
m_securityCallbacks->onSecurityRequest();
}
*/
int rc = ble_gap_security_initiate(conn_id); int rc = ble_gap_security_initiate(conn_id);
if(rc != 0){ if(rc != 0){
NIMBLE_LOGE(LOG_TAG, "ble_gap_security_initiate: rc=%d %s", rc, NimBLEUtils::returnCodeToString(rc)); NIMBLE_LOGE(LOG_TAG, "ble_gap_security_initiate: rc=%d %s", rc, NimBLEUtils::returnCodeToString(rc));
@ -1039,7 +1103,8 @@ void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
* @param [in] address The address to look for. * @param [in] address The address to look for.
* @return True if ignoring. * @return True if ignoring.
*/ */
/*STATIC*/ bool NimBLEDevice::isIgnored(const NimBLEAddress &address) { /*STATIC*/
bool NimBLEDevice::isIgnored(const NimBLEAddress &address) {
for(auto &it : m_ignoreList) { for(auto &it : m_ignoreList) {
if(it.equals(address)){ if(it.equals(address)){
return true; return true;
@ -1054,7 +1119,8 @@ void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
* @brief Add a device to the ignore list. * @brief Add a device to the ignore list.
* @param [in] address The address of the device we want to ignore. * @param [in] address The address of the device we want to ignore.
*/ */
/*STATIC*/ void NimBLEDevice::addIgnored(const NimBLEAddress &address) { /*STATIC*/
void NimBLEDevice::addIgnored(const NimBLEAddress &address) {
m_ignoreList.push_back(address); m_ignoreList.push_back(address);
} }
@ -1063,7 +1129,8 @@ void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
* @brief Remove a device from the ignore list. * @brief Remove a device from the ignore list.
* @param [in] address The address of the device we want to remove from the list. * @param [in] address The address of the device we want to remove from the list.
*/ */
/*STATIC*/void NimBLEDevice::removeIgnored(const NimBLEAddress &address) { /*STATIC*/
void NimBLEDevice::removeIgnored(const NimBLEAddress &address) {
for(auto it = m_ignoreList.begin(); it != m_ignoreList.end(); ++it) { for(auto it = m_ignoreList.begin(); it != m_ignoreList.end(); ++it) {
if((*it).equals(address)){ if((*it).equals(address)){
m_ignoreList.erase(it); m_ignoreList.erase(it);
@ -1077,6 +1144,7 @@ void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) {
* @brief Set a custom callback for gap events. * @brief Set a custom callback for gap events.
* @param [in] handler The function to call when gap events occur. * @param [in] handler The function to call when gap events occur.
*/ */
/*STATIC*/
void NimBLEDevice::setCustomGapHandler(gap_event_handler handler) { void NimBLEDevice::setCustomGapHandler(gap_event_handler handler) {
m_customGapHandler = handler; m_customGapHandler = handler;
int rc = ble_gap_event_listener_register(&m_listener, m_customGapHandler, NULL); int rc = ble_gap_event_listener_register(&m_listener, m_customGapHandler, NULL);
@ -1088,5 +1156,4 @@ void NimBLEDevice::setCustomGapHandler(gap_event_handler handler) {
} }
} // setCustomGapHandler } // setCustomGapHandler
#endif // CONFIG_BT_ENABLED #endif // CONFIG_BT_ENABLED

View file

@ -38,7 +38,9 @@
#include "NimBLESecurity.h" #include "NimBLESecurity.h"
#include "NimBLEAddress.h" #include "NimBLEAddress.h"
#include "esp_bt.h" #ifdef ESP_PLATFORM
# include "esp_bt.h"
#endif
#include <map> #include <map>
#include <string> #include <string>
@ -109,8 +111,17 @@ public:
static NimBLEServer* getServer(); static NimBLEServer* getServer();
#endif #endif
#ifdef ESP_PLATFORM
static void setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT); static void setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT);
static int getPower(esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT); static int getPower(esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT);
static void setOwnAddrType(uint8_t own_addr_type, bool useNRPA=false);
static void setScanDuplicateCacheSize(uint16_t cacheSize);
static void setScanFilterMode(uint8_t type);
#else
static void setPower(int dbm);
static int getPower();
#endif
static void setCustomGapHandler(gap_event_handler handler); static void setCustomGapHandler(gap_event_handler handler);
static void setSecurityAuth(bool bonding, bool mitm, bool sc); static void setSecurityAuth(bool bonding, bool mitm, bool sc);
static void setSecurityAuth(uint8_t auth_req); static void setSecurityAuth(uint8_t auth_req);
@ -120,15 +131,12 @@ public:
static void setSecurityPasskey(uint32_t pin); static void setSecurityPasskey(uint32_t pin);
static uint32_t getSecurityPasskey(); static uint32_t getSecurityPasskey();
static void setSecurityCallbacks(NimBLESecurityCallbacks* pCallbacks); static void setSecurityCallbacks(NimBLESecurityCallbacks* pCallbacks);
static void setOwnAddrType(uint8_t own_addr_type, bool useNRPA=false);
static int startSecurity(uint16_t conn_id); static int startSecurity(uint16_t conn_id);
static int setMTU(uint16_t mtu); static int setMTU(uint16_t mtu);
static uint16_t getMTU(); static uint16_t getMTU();
static bool isIgnored(const NimBLEAddress &address); static bool isIgnored(const NimBLEAddress &address);
static void addIgnored(const NimBLEAddress &address); static void addIgnored(const NimBLEAddress &address);
static void removeIgnored(const NimBLEAddress &address); static void removeIgnored(const NimBLEAddress &address);
static void setScanDuplicateCacheSize(uint16_t cacheSize);
static void setScanFilterMode(uint8_t type);
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER) #if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
static NimBLEAdvertising* getAdvertising(); static NimBLEAdvertising* getAdvertising();
@ -198,8 +206,10 @@ private:
static ble_gap_event_listener m_listener; static ble_gap_event_listener m_listener;
static gap_event_handler m_customGapHandler; static gap_event_handler m_customGapHandler;
static uint8_t m_own_addr_type; static uint8_t m_own_addr_type;
#ifdef ESP_PLATFORM
static uint16_t m_scanDuplicateSize; static uint16_t m_scanDuplicateSize;
static uint8_t m_scanFilterMode; static uint8_t m_scanFilterMode;
#endif
static std::vector<NimBLEAddress> m_whiteList; static std::vector<NimBLEAddress> m_whiteList;
}; };

View file

@ -126,30 +126,30 @@ std::string NimBLEEddystoneTLM::toString() {
out += " C\n"; out += " C\n";
out += "Adv. Count "; out += "Adv. Count ";
snprintf(val, sizeof(val), "%d", ENDIAN_CHANGE_U32(m_eddystoneData.advCount)); snprintf(val, sizeof(val), "%" PRIu32, ENDIAN_CHANGE_U32(m_eddystoneData.advCount));
out += val; out += val;
out += "\n"; out += "\n";
out += "Time in seconds "; out += "Time in seconds ";
snprintf(val, sizeof(val), "%d", rawsec/10); snprintf(val, sizeof(val), "%" PRIu32, rawsec/10);
out += val; out += val;
out += "\n"; out += "\n";
out += "Time "; out += "Time ";
snprintf(val, sizeof(val), "%04d", rawsec / 864000); snprintf(val, sizeof(val), "%04" PRIu32, rawsec / 864000);
out += val; out += val;
out += "."; out += ".";
snprintf(val, sizeof(val), "%02d", (rawsec / 36000) % 24); snprintf(val, sizeof(val), "%02" PRIu32, (rawsec / 36000) % 24);
out += val; out += val;
out += ":"; out += ":";
snprintf(val, sizeof(val), "%02d", (rawsec / 600) % 60); snprintf(val, sizeof(val), "%02" PRIu32, (rawsec / 600) % 60);
out += val; out += val;
out += ":"; out += ":";
snprintf(val, sizeof(val), "%02d", (rawsec / 10) % 60); snprintf(val, sizeof(val), "%02" PRIu32, (rawsec / 10) % 60);
out += val; out += val;
out += "\n"; out += "\n";

View file

@ -186,6 +186,7 @@ int NimBLERemoteDescriptor::onReadCB(uint16_t conn_handle,
const struct ble_gatt_error *error, const struct ble_gatt_error *error,
struct ble_gatt_attr *attr, void *arg) struct ble_gatt_attr *attr, void *arg)
{ {
(void)attr;
ble_task_data_t *pTaskData = (ble_task_data_t*)arg; ble_task_data_t *pTaskData = (ble_task_data_t*)arg;
NimBLERemoteDescriptor* desc = (NimBLERemoteDescriptor*)pTaskData->pATT; NimBLERemoteDescriptor* desc = (NimBLERemoteDescriptor*)pTaskData->pATT;
uint16_t conn_id = desc->getRemoteCharacteristic()->getRemoteService()->getClient()->getConnId(); uint16_t conn_id = desc->getRemoteCharacteristic()->getRemoteService()->getClient()->getConnId();

View file

@ -11,7 +11,8 @@
#include "NimBLEUtils.h" #include "NimBLEUtils.h"
#include "NimBLELog.h" #include "NimBLELog.h"
#include "nimconfig.h"
#include <stdlib.h>
static const char* LOG_TAG = "NimBLEUtils"; static const char* LOG_TAG = "NimBLEUtils";
@ -342,6 +343,7 @@ const char* NimBLEUtils::returnCodeToString(int rc) {
return "Unknown"; return "Unknown";
} }
#else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT) #else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT)
(void)rc;
return ""; return "";
#endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT) #endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT)
} }
@ -369,6 +371,7 @@ const char* NimBLEUtils::advTypeToString(uint8_t advType) {
return "Unknown flag"; return "Unknown flag";
} }
#else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT) #else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT)
(void)advType;
return ""; return "";
#endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT) #endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT)
} // adFlagsToString } // adFlagsToString
@ -416,8 +419,11 @@ char* NimBLEUtils::buildHexData(uint8_t* target, const uint8_t* source, uint8_t
* @param [in] arg Unused. * @param [in] arg Unused.
*/ */
void NimBLEUtils::dumpGapEvent(ble_gap_event *event, void *arg){ void NimBLEUtils::dumpGapEvent(ble_gap_event *event, void *arg){
(void)arg;
#if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT) #if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT)
NIMBLE_LOGD(LOG_TAG, "Received a GAP event: %s", gapEventToString(event->type)); NIMBLE_LOGD(LOG_TAG, "Received a GAP event: %s", gapEventToString(event->type));
#else
(void)event;
#endif #endif
} }
@ -504,6 +510,7 @@ const char* NimBLEUtils::gapEventToString(uint8_t eventType) {
return "Unknown event type"; return "Unknown event type";
} }
#else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT) #else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT)
(void)eventType;
return ""; return "";
#endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT) #endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT)
} // gapEventToString } // gapEventToString