mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-24 06:00:55 +01:00
[BREAKING] Refactor NimBLEDevice
* General code cleanup
* `NimBLEDevice::getInitialized` renamed to `NimBLEDevice::isInitialized`.
* `NimBLEDevice::setPower` no longer takes the `esp_power_level_t` and `esp_ble_power_type_t`, instead only an integer value in dbm units is accepted.
* `NimBLEDevice::setPower` now returns a bool value, true = success.
* `NimBLEDevice::setMTU` now returns a bool value, true = success.
* `NimBLEDevice::injectConfirmPIN` renamed to `NimBLEDevice::injectConfirmPasskey` to use Bluetooth naming.
* Fixes crash if `NimBLEDevice::deinit` is called when the stack has not been initialized.
* Reverts 73f0277
as it would cause a crash when the NimBLEServer instance has a connection.
* `NimBLEDevice::getAddress` will now return the address currently in use.
* `NimBLEDevice::init` now returns a bool with `true` indicating success.
* `NimBLEDevice::deinit` now returns a bool with `true` inidicating success.
* `NimBLEDevice::setDeviceName` now returns a bool with `true` indicating success.
* `NimBLEDevice::setCustomGapHandler` now returns a bool with `true` indicating success.
* `NimBLEDevice::setOwnAddrType` now returns a bool with `true` indicating success.
* `NimBLEDevice::setOwnAddrType` will now correctly apply the provided address type for all devices.
* `NimBLEDevice::setOwnAddrType` no longer takes a `bool nrpa` parameter.
This commit is contained in:
parent
877a29a8b1
commit
a2fe5b4780
13 changed files with 800 additions and 796 deletions
|
@ -50,7 +50,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
|
||||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||||
/** Inject false if passkeys don't match. */
|
/** Inject false if passkeys don't match. */
|
||||||
NimBLEDevice::injectConfirmPIN(connInfo, true);
|
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Pairing process complete, we can check the results in connInfo */
|
/** Pairing process complete, we can check the results in connInfo */
|
||||||
|
@ -58,7 +58,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
|
||||||
if(!connInfo.isEncrypted()) {
|
if(!connInfo.isEncrypted()) {
|
||||||
printf("Encrypt connection failed - disconnecting\n");
|
printf("Encrypt connection failed - disconnecting\n");
|
||||||
/** Find the client with the connection handle provided in desc */
|
/** Find the client with the connection handle provided in desc */
|
||||||
NimBLEDevice::getClientByID(connInfo.getConnHandle())->disconnect();
|
NimBLEDevice::getClientByHandle(connInfo.getConnHandle())->disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ class ServerCallbacks: public NimBLEServerCallbacks {
|
||||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||||
/** Inject false if passkeys don't match. */
|
/** Inject false if passkeys don't match. */
|
||||||
NimBLEDevice::injectConfirmPIN(connInfo, true);
|
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
void onAuthenticationComplete(NimBLEConnInfo& connInfo){
|
void onAuthenticationComplete(NimBLEConnInfo& connInfo){
|
||||||
|
|
|
@ -62,7 +62,7 @@ class MyClientCallback : public BLEClientCallbacks {
|
||||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||||
/** Inject false if passkeys don't match. */
|
/** Inject false if passkeys don't match. */
|
||||||
NimBLEDevice::injectConfirmPIN(connInfo, true);
|
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Pairing process complete, we can check the results in connInfo */
|
/** Pairing process complete, we can check the results in connInfo */
|
||||||
|
@ -70,7 +70,7 @@ class MyClientCallback : public BLEClientCallbacks {
|
||||||
if(!connInfo.isEncrypted()) {
|
if(!connInfo.isEncrypted()) {
|
||||||
printf("Encrypt connection failed - disconnecting\n");
|
printf("Encrypt connection failed - disconnecting\n");
|
||||||
/** Find the client with the connection handle provided in desc */
|
/** Find the client with the connection handle provided in desc */
|
||||||
NimBLEDevice::getClientByID(connInfo.getConnHandle())->disconnect();
|
NimBLEDevice::getClientByHandle(connInfo.getConnHandle())->disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ class MyServerCallbacks: public BLEServerCallbacks {
|
||||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||||
/** Inject false if passkeys don't match. */
|
/** Inject false if passkeys don't match. */
|
||||||
NimBLEDevice::injectConfirmPIN(connInfo, true);
|
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
void onAuthenticationComplete(NimBLEConnInfo& connInfo){
|
void onAuthenticationComplete(NimBLEConnInfo& connInfo){
|
||||||
|
|
|
@ -70,7 +70,7 @@ class MyServerCallbacks: public BLEServerCallbacks {
|
||||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||||
/** Inject false if passkeys don't match. */
|
/** Inject false if passkeys don't match. */
|
||||||
NimBLEDevice::injectConfirmPIN(connInfo, true);
|
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
void onAuthenticationComplete(NimBLEConnInfo& connInfo){
|
void onAuthenticationComplete(NimBLEConnInfo& connInfo){
|
||||||
|
|
|
@ -44,7 +44,7 @@ NimBLEAdvertising::NimBLEAdvertising() {
|
||||||
* @brief Stops the current advertising and resets the advertising data to the default values.
|
* @brief Stops the current advertising and resets the advertising data to the default values.
|
||||||
*/
|
*/
|
||||||
void NimBLEAdvertising::reset() {
|
void NimBLEAdvertising::reset() {
|
||||||
if(NimBLEDevice::getInitialized() && isAdvertising()) {
|
if(NimBLEDevice::isInitialized() && isAdvertising()) {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
memset(&m_advData, 0, sizeof m_advData);
|
memset(&m_advData, 0, sizeof m_advData);
|
||||||
|
@ -58,6 +58,8 @@ void NimBLEAdvertising::reset() {
|
||||||
m_advData.name_is_complete = 1;
|
m_advData.name_is_complete = 1;
|
||||||
#ifndef CONFIG_IDF_TARGET_ESP32P4
|
#ifndef CONFIG_IDF_TARGET_ESP32P4
|
||||||
m_advData.tx_pwr_lvl = NimBLEDevice::getPower();
|
m_advData.tx_pwr_lvl = NimBLEDevice::getPower();
|
||||||
|
#else
|
||||||
|
m_advData.tx_pwr_lvl = 0;
|
||||||
#endif
|
#endif
|
||||||
m_advData.flags = (BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP);
|
m_advData.flags = (BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP);
|
||||||
|
|
||||||
|
@ -641,7 +643,7 @@ bool NimBLEAdvertising::start(uint32_t duration, advCompleteCB_t advCompleteCB,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||||
rc = ble_gap_adv_start(NimBLEDevice::m_own_addr_type,
|
rc = ble_gap_adv_start(NimBLEDevice::m_ownAddrType,
|
||||||
(dirAddr != nullptr) ? dirAddr->getBase() : NULL,
|
(dirAddr != nullptr) ? dirAddr->getBase() : NULL,
|
||||||
duration,
|
duration,
|
||||||
&m_advParams,
|
&m_advParams,
|
||||||
|
@ -649,7 +651,7 @@ bool NimBLEAdvertising::start(uint32_t duration, advCompleteCB_t advCompleteCB,
|
||||||
NimBLEAdvertising::handleGapEvent,
|
NimBLEAdvertising::handleGapEvent,
|
||||||
(void*)this);
|
(void*)this);
|
||||||
#else
|
#else
|
||||||
rc = ble_gap_adv_start(NimBLEDevice::m_own_addr_type,
|
rc = ble_gap_adv_start(NimBLEDevice::m_ownAddrType,
|
||||||
(dirAddr != nullptr) ? &peerAddr : NULL,
|
(dirAddr != nullptr) ? &peerAddr : NULL,
|
||||||
duration,
|
duration,
|
||||||
&m_advParams,
|
&m_advParams,
|
||||||
|
@ -1022,6 +1024,8 @@ void NimBLEAdvertisementData::addTxPower() {
|
||||||
cdata[1] = BLE_HS_ADV_TYPE_TX_PWR_LVL;
|
cdata[1] = BLE_HS_ADV_TYPE_TX_PWR_LVL;
|
||||||
#ifndef CONFIG_IDF_TARGET_ESP32P4
|
#ifndef CONFIG_IDF_TARGET_ESP32P4
|
||||||
cdata[2] = NimBLEDevice::getPower();
|
cdata[2] = NimBLEDevice::getPower();
|
||||||
|
#else
|
||||||
|
cdata[2] = 0;
|
||||||
#endif
|
#endif
|
||||||
addData(cdata, 3);
|
addData(cdata, 3);
|
||||||
} // addTxPower
|
} // addTxPower
|
||||||
|
|
|
@ -226,7 +226,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttributes)
|
||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
#if CONFIG_BT_NIMBLE_EXT_ADV
|
#if CONFIG_BT_NIMBLE_EXT_ADV
|
||||||
rc = ble_gap_ext_connect(NimBLEDevice::m_own_addr_type,
|
rc = ble_gap_ext_connect(NimBLEDevice::m_ownAddrType,
|
||||||
peerAddr,
|
peerAddr,
|
||||||
m_connectTimeout,
|
m_connectTimeout,
|
||||||
m_phyMask,
|
m_phyMask,
|
||||||
|
@ -237,7 +237,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttributes)
|
||||||
this);
|
this);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
rc = ble_gap_connect(NimBLEDevice::m_own_addr_type, peerAddr,
|
rc = ble_gap_connect(NimBLEDevice::m_ownAddrType, peerAddr,
|
||||||
m_connectTimeout, &m_pConnParams,
|
m_connectTimeout, &m_pConnParams,
|
||||||
NimBLEClient::handleGapEvent, this);
|
NimBLEClient::handleGapEvent, this);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1342,7 +1342,7 @@ void NimBLEClientCallbacks::onIdentity(NimBLEConnInfo& connInfo){
|
||||||
|
|
||||||
void NimBLEClientCallbacks::onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pin){
|
void NimBLEClientCallbacks::onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pin){
|
||||||
NIMBLE_LOGD("NimBLEClientCallbacks", "onConfirmPIN: default: true");
|
NIMBLE_LOGD("NimBLEClientCallbacks", "onConfirmPIN: default: true");
|
||||||
NimBLEDevice::injectConfirmPIN(connInfo, true);
|
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -12,43 +12,55 @@
|
||||||
* Author: kolban
|
* Author: kolban
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MAIN_NIMBLEDEVICE_H_
|
#ifndef NIMBLE_CPP_DEVICE_H_
|
||||||
#define MAIN_NIMBLEDEVICE_H_
|
#define NIMBLE_CPP_DEVICE_H_
|
||||||
|
|
||||||
#include "nimconfig.h"
|
#include "nimconfig.h"
|
||||||
#if defined(CONFIG_BT_ENABLED)
|
#if defined(CONFIG_BT_ENABLED)
|
||||||
|
# ifdef ESP_PLATFORM
|
||||||
|
# include <esp_bt.h>
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||||
|
# include <host/ble_gap.h>
|
||||||
|
# else
|
||||||
|
# include <nimble/nimble/host/include/host/ble_gap.h>
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/**** FIX COMPILATION ****/
|
||||||
|
# undef min
|
||||||
|
# undef max
|
||||||
|
/**************************/
|
||||||
|
|
||||||
|
# include <string>
|
||||||
|
# include <vector>
|
||||||
|
|
||||||
|
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||||
|
# include <array>
|
||||||
|
class NimBLEClient;
|
||||||
|
# endif
|
||||||
|
|
||||||
# if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
# if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||||
#include "NimBLEScan.h"
|
class NimBLEScan;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
# if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||||
# if CONFIG_BT_NIMBLE_EXT_ADV
|
# if CONFIG_BT_NIMBLE_EXT_ADV
|
||||||
# include "NimBLEExtAdvertising.h"
|
class NimBLEExtAdvertising;
|
||||||
# else
|
# else
|
||||||
# include "NimBLEAdvertising.h"
|
class NimBLEAdvertising;
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
|
||||||
class NimBLEClient;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
# if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
# if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||||
#include "NimBLEServer.h"
|
class NimBLEServer;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#include "NimBLEUtils.h"
|
# if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL) || defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||||
#include "NimBLEAddress.h"
|
class NimBLEConnInfo;
|
||||||
|
|
||||||
#ifdef ESP_PLATFORM
|
|
||||||
#ifndef CONFIG_IDF_TARGET_ESP32P4
|
|
||||||
# include "esp_bt.h"
|
|
||||||
#endif
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#include <string>
|
class NimBLEAddress;
|
||||||
#include <array>
|
|
||||||
|
|
||||||
# define BLEDevice NimBLEDevice
|
# define BLEDevice NimBLEDevice
|
||||||
# define BLEClient NimBLEClient
|
# define BLEClient NimBLEClient
|
||||||
|
@ -58,8 +70,6 @@ class NimBLEClient;
|
||||||
# define BLEAdvertisedDevice NimBLEAdvertisedDevice
|
# define BLEAdvertisedDevice NimBLEAdvertisedDevice
|
||||||
# define BLEScan NimBLEScan
|
# define BLEScan NimBLEScan
|
||||||
# define BLEUUID NimBLEUUID
|
# define BLEUUID NimBLEUUID
|
||||||
#define BLESecurity NimBLESecurity
|
|
||||||
#define BLESecurityCallbacks NimBLESecurityCallbacks
|
|
||||||
# define BLEAddress NimBLEAddress
|
# define BLEAddress NimBLEAddress
|
||||||
# define BLEUtils NimBLEUtils
|
# define BLEUtils NimBLEUtils
|
||||||
# define BLEClientCallbacks NimBLEClientCallbacks
|
# define BLEClientCallbacks NimBLEClientCallbacks
|
||||||
|
@ -73,7 +83,6 @@ class NimBLEClient;
|
||||||
# define BLECharacteristicCallbacks NimBLECharacteristicCallbacks
|
# define BLECharacteristicCallbacks NimBLECharacteristicCallbacks
|
||||||
# define BLEAdvertisementData NimBLEAdvertisementData
|
# define BLEAdvertisementData NimBLEAdvertisementData
|
||||||
# define BLEDescriptor NimBLEDescriptor
|
# define BLEDescriptor NimBLEDescriptor
|
||||||
#define BLE2902 NimBLE2902
|
|
||||||
# define BLE2904 NimBLE2904
|
# define BLE2904 NimBLE2904
|
||||||
# define BLEDescriptorCallbacks NimBLEDescriptorCallbacks
|
# define BLEDescriptorCallbacks NimBLEDescriptorCallbacks
|
||||||
# define BLEBeacon NimBLEBeacon
|
# define BLEBeacon NimBLEBeacon
|
||||||
|
@ -89,17 +98,15 @@ class NimBLEClient;
|
||||||
|
|
||||||
typedef int (*gap_event_handler)(ble_gap_event* event, void* arg);
|
typedef int (*gap_event_handler)(ble_gap_event* event, void* arg);
|
||||||
|
|
||||||
extern "C" void ble_store_config_init(void);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A model of a %BLE Device from which all the BLE roles are created.
|
* @brief A model of a BLE Device from which all the BLE roles are created.
|
||||||
*/
|
*/
|
||||||
class NimBLEDevice {
|
class NimBLEDevice {
|
||||||
public:
|
public:
|
||||||
static void init(const std::string &deviceName);
|
static bool init(const std::string& deviceName);
|
||||||
static void deinit(bool clearAll = false);
|
static bool deinit(bool clearAll = false);
|
||||||
static void setDeviceName(const std::string &deviceName);
|
static bool setDeviceName(const std::string& deviceName);
|
||||||
static bool getInitialized();
|
static bool isInitialized();
|
||||||
static NimBLEAddress getAddress();
|
static NimBLEAddress getAddress();
|
||||||
static std::string toString();
|
static std::string toString();
|
||||||
static bool whiteListAdd(const NimBLEAddress& address);
|
static bool whiteListAdd(const NimBLEAddress& address);
|
||||||
|
@ -107,6 +114,28 @@ public:
|
||||||
static bool onWhiteList(const NimBLEAddress& address);
|
static bool onWhiteList(const NimBLEAddress& address);
|
||||||
static size_t getWhiteListCount();
|
static size_t getWhiteListCount();
|
||||||
static NimBLEAddress getWhiteListAddress(size_t index);
|
static NimBLEAddress getWhiteListAddress(size_t index);
|
||||||
|
static bool setPower(int8_t dbm);
|
||||||
|
static int getPower();
|
||||||
|
static bool setOwnAddrType(uint8_t type);
|
||||||
|
static void setScanDuplicateCacheSize(uint16_t cacheSize);
|
||||||
|
static void setScanFilterMode(uint8_t type);
|
||||||
|
static bool setCustomGapHandler(gap_event_handler handler);
|
||||||
|
static void setSecurityAuth(bool bonding, bool mitm, bool sc);
|
||||||
|
static void setSecurityAuth(uint8_t auth);
|
||||||
|
static void setSecurityIOCap(uint8_t iocap);
|
||||||
|
static void setSecurityInitKey(uint8_t initKey);
|
||||||
|
static void setSecurityRespKey(uint8_t respKey);
|
||||||
|
static void setSecurityPasskey(uint32_t passKey);
|
||||||
|
static uint32_t getSecurityPasskey();
|
||||||
|
static bool startSecurity(uint16_t connHandle);
|
||||||
|
static bool setMTU(uint16_t mtu);
|
||||||
|
static uint16_t getMTU();
|
||||||
|
static bool isIgnored(const NimBLEAddress& address);
|
||||||
|
static void addIgnored(const NimBLEAddress& address);
|
||||||
|
static void removeIgnored(const NimBLEAddress& address);
|
||||||
|
static void onReset(int reason);
|
||||||
|
static void onSync(void);
|
||||||
|
static void host_task(void* param);
|
||||||
|
|
||||||
# if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
# if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||||
static NimBLEScan* getScan();
|
static NimBLEScan* getScan();
|
||||||
|
@ -117,43 +146,16 @@ public:
|
||||||
static NimBLEServer* getServer();
|
static NimBLEServer* getServer();
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#ifdef ESP_PLATFORM
|
# if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL) || defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||||
#ifndef CONFIG_IDF_TARGET_ESP32P4
|
static bool injectConfirmPasskey(const NimBLEConnInfo& peerInfo, bool accept);
|
||||||
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);
|
|
||||||
#endif
|
|
||||||
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 setSecurityAuth(bool bonding, bool mitm, bool sc);
|
|
||||||
static void setSecurityAuth(uint8_t auth_req);
|
|
||||||
static void setSecurityIOCap(uint8_t iocap);
|
|
||||||
static void setSecurityInitKey(uint8_t init_key);
|
|
||||||
static void setSecurityRespKey(uint8_t init_key);
|
|
||||||
static void setSecurityPasskey(uint32_t pin);
|
|
||||||
static uint32_t getSecurityPasskey();
|
|
||||||
static int startSecurity(uint16_t conn_id);
|
|
||||||
static bool injectConfirmPIN(const NimBLEConnInfo& peerInfo, bool accept);
|
|
||||||
static bool injectPassKey(const NimBLEConnInfo& peerInfo, uint32_t pin);
|
static bool injectPassKey(const NimBLEConnInfo& peerInfo, uint32_t pin);
|
||||||
static int setMTU(uint16_t mtu);
|
# endif
|
||||||
static uint16_t getMTU();
|
|
||||||
static bool isIgnored(const NimBLEAddress &address);
|
|
||||||
static void addIgnored(const NimBLEAddress &address);
|
|
||||||
static void removeIgnored(const NimBLEAddress &address);
|
|
||||||
|
|
||||||
# if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
# if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||||
# if CONFIG_BT_NIMBLE_EXT_ADV
|
# if CONFIG_BT_NIMBLE_EXT_ADV
|
||||||
static NimBLEExtAdvertising* getAdvertising();
|
static NimBLEExtAdvertising* getAdvertising();
|
||||||
static bool startAdvertising(uint8_t inst_id,
|
static bool startAdvertising(uint8_t instId, int duration = 0, int maxEvents = 0);
|
||||||
int duration = 0,
|
static bool stopAdvertising(uint8_t instId);
|
||||||
int max_events = 0);
|
|
||||||
static bool stopAdvertising(uint8_t inst_id);
|
|
||||||
static bool stopAdvertising();
|
static bool stopAdvertising();
|
||||||
# endif
|
# endif
|
||||||
# if !CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_)
|
# if !CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_)
|
||||||
|
@ -164,10 +166,11 @@ public:
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||||
static NimBLEClient* createClient(NimBLEAddress peerAddress = NimBLEAddress{});
|
static NimBLEClient* createClient();
|
||||||
|
static NimBLEClient* createClient(const NimBLEAddress& peerAddress);
|
||||||
static bool deleteClient(NimBLEClient* pClient);
|
static bool deleteClient(NimBLEClient* pClient);
|
||||||
static NimBLEClient* getClientByID(uint16_t conn_id);
|
static NimBLEClient* getClientByHandle(uint16_t connHandle);
|
||||||
static NimBLEClient* getClientByPeerAddress(const NimBLEAddress &peer_addr);
|
static NimBLEClient* getClientByPeerAddress(const NimBLEAddress& peerAddress);
|
||||||
static NimBLEClient* getDisconnectedClient();
|
static NimBLEClient* getDisconnectedClient();
|
||||||
static size_t getCreatedClientCount();
|
static size_t getCreatedClientCount();
|
||||||
# endif
|
# endif
|
||||||
|
@ -181,6 +184,41 @@ public:
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static bool m_synced;
|
||||||
|
static bool m_initialized;
|
||||||
|
static std::vector<NimBLEAddress> m_ignoreList;
|
||||||
|
static uint32_t m_passkey;
|
||||||
|
static ble_gap_event_listener m_listener;
|
||||||
|
static uint8_t m_ownAddrType;
|
||||||
|
static std::vector<NimBLEAddress> m_whiteList;
|
||||||
|
|
||||||
|
# if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||||
|
static NimBLEScan* m_pScan;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||||
|
static NimBLEServer* m_pServer;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||||
|
# if CONFIG_BT_NIMBLE_EXT_ADV
|
||||||
|
static NimBLEExtAdvertising* m_bleAdvertising;
|
||||||
|
# else
|
||||||
|
static NimBLEAdvertising* m_bleAdvertising;
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||||
|
static std::array<NimBLEClient*, NIMBLE_MAX_CONNECTIONS> m_pClients;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifdef ESP_PLATFORM
|
||||||
|
# ifdef CONFIG_BTDM_BLE_SCAN_DUPL
|
||||||
|
static uint16_t m_scanDuplicateSize;
|
||||||
|
static uint8_t m_scanFilterMode;
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
|
||||||
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||||
friend class NimBLEClient;
|
friend class NimBLEClient;
|
||||||
# endif
|
# endif
|
||||||
|
@ -200,44 +238,6 @@ private:
|
||||||
friend class NimBLEExtAdvertising;
|
friend class NimBLEExtAdvertising;
|
||||||
friend class NimBLEExtAdvertisement;
|
friend class NimBLEExtAdvertisement;
|
||||||
# endif
|
# endif
|
||||||
#endif
|
|
||||||
|
|
||||||
static void onReset(int reason);
|
|
||||||
static void onSync(void);
|
|
||||||
static void host_task(void *param);
|
|
||||||
static bool m_synced;
|
|
||||||
|
|
||||||
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
|
||||||
static NimBLEScan* m_pScan;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
|
||||||
static NimBLEServer* m_pServer;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
|
||||||
# if CONFIG_BT_NIMBLE_EXT_ADV
|
|
||||||
static NimBLEExtAdvertising* m_bleAdvertising;
|
|
||||||
# else
|
|
||||||
static NimBLEAdvertising* m_bleAdvertising;
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static std::vector<NimBLEAddress> m_ignoreList;
|
|
||||||
static uint32_t m_passkey;
|
|
||||||
static ble_gap_event_listener m_listener;
|
|
||||||
static gap_event_handler m_customGapHandler;
|
|
||||||
static uint8_t m_own_addr_type;
|
|
||||||
static std::vector<NimBLEAddress> m_whiteList;
|
|
||||||
#ifdef ESP_PLATFORM
|
|
||||||
# ifdef CONFIG_BTDM_BLE_SCAN_DUPL
|
|
||||||
static uint16_t m_scanDuplicateSize;
|
|
||||||
static uint8_t m_scanFilterMode;
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
|
||||||
static std::array<NimBLEClient*, NIMBLE_MAX_CONNECTIONS> m_pClients;
|
|
||||||
# endif
|
# endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -248,5 +248,24 @@ private:
|
||||||
# include "NimBLERemoteDescriptor.h"
|
# include "NimBLERemoteDescriptor.h"
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||||
|
# include "NimBLEScan.h"
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||||
|
# include "NimBLEServer.h"
|
||||||
|
# include "NimBLEService.h"
|
||||||
|
# include "NimBLECharacteristic.h"
|
||||||
|
# include "NimBLEDescriptor.h"
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||||
|
# if CONFIG_BT_NIMBLE_EXT_ADV
|
||||||
|
# include "NimBLEExtAdvertising.h"
|
||||||
|
# else
|
||||||
|
# include "NimBLEAdvertising.h"
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
|
||||||
#endif // CONFIG_BT_ENABLED
|
#endif // CONFIG_BT_ENABLED
|
||||||
#endif // MAIN_NIMBLEDEVICE_H_
|
#endif // NIMBLE_CPP_DEVICE_H_
|
||||||
|
|
|
@ -387,7 +387,7 @@ NimBLEExtAdvertisement::NimBLEExtAdvertisement(uint8_t priPhy, uint8_t secPhy)
|
||||||
: m_advAddress{}
|
: m_advAddress{}
|
||||||
{
|
{
|
||||||
memset (&m_params, 0, sizeof(m_params));
|
memset (&m_params, 0, sizeof(m_params));
|
||||||
m_params.own_addr_type = NimBLEDevice::m_own_addr_type;
|
m_params.own_addr_type = NimBLEDevice::m_ownAddrType;
|
||||||
m_params.primary_phy = priPhy;
|
m_params.primary_phy = priPhy;
|
||||||
m_params.secondary_phy = secPhy;
|
m_params.secondary_phy = secPhy;
|
||||||
m_params.tx_power = 127;
|
m_params.tx_power = 127;
|
||||||
|
|
|
@ -310,7 +310,7 @@ bool NimBLEScan::start(uint32_t duration, bool is_continue) {
|
||||||
scan_params.passive = m_scan_params.passive;
|
scan_params.passive = m_scan_params.passive;
|
||||||
scan_params.itvl = m_scan_params.itvl;
|
scan_params.itvl = m_scan_params.itvl;
|
||||||
scan_params.window = m_scan_params.window;
|
scan_params.window = m_scan_params.window;
|
||||||
int rc = ble_gap_ext_disc(NimBLEDevice::m_own_addr_type,
|
int rc = ble_gap_ext_disc(NimBLEDevice::m_ownAddrType,
|
||||||
duration/10,
|
duration/10,
|
||||||
0,
|
0,
|
||||||
m_scan_params.filter_duplicates,
|
m_scan_params.filter_duplicates,
|
||||||
|
@ -321,7 +321,7 @@ bool NimBLEScan::start(uint32_t duration, bool is_continue) {
|
||||||
NimBLEScan::handleGapEvent,
|
NimBLEScan::handleGapEvent,
|
||||||
NULL);
|
NULL);
|
||||||
#else
|
#else
|
||||||
int rc = ble_gap_disc(NimBLEDevice::m_own_addr_type,
|
int rc = ble_gap_disc(NimBLEDevice::m_ownAddrType,
|
||||||
duration,
|
duration,
|
||||||
&m_scan_params,
|
&m_scan_params,
|
||||||
NimBLEScan::handleGapEvent,
|
NimBLEScan::handleGapEvent,
|
||||||
|
|
|
@ -702,7 +702,7 @@ int NimBLEServer::handleGapEvent(struct ble_gap_event *event, void *arg) {
|
||||||
return BLE_ATT_ERR_INVALID_HANDLE;
|
return BLE_ATT_ERR_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pServer->m_pServerCallbacks->onConfirmPIN(peerInfo, event->passkey.params.numcmp);
|
pServer->m_pServerCallbacks->onConfirmPassKey(peerInfo, event->passkey.params.numcmp);
|
||||||
//TODO: Handle out of band pairing
|
//TODO: Handle out of band pairing
|
||||||
} else if (event->passkey.params.action == BLE_SM_IOACT_OOB) {
|
} else if (event->passkey.params.action == BLE_SM_IOACT_OOB) {
|
||||||
static uint8_t tem_oob[16] = {0};
|
static uint8_t tem_oob[16] = {0};
|
||||||
|
@ -1076,9 +1076,9 @@ uint32_t NimBLEServerCallbacks::onPassKeyDisplay(){
|
||||||
return 123456;
|
return 123456;
|
||||||
} //onPassKeyDisplay
|
} //onPassKeyDisplay
|
||||||
|
|
||||||
void NimBLEServerCallbacks::onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pin){
|
void NimBLEServerCallbacks::onConfirmPassKey(NimBLEConnInfo& connInfo, uint32_t pin){
|
||||||
NIMBLE_LOGD("NimBLEServerCallbacks", "onConfirmPIN: default: true");
|
NIMBLE_LOGD("NimBLEServerCallbacks", "onConfirmPIN: default: true");
|
||||||
NimBLEDevice::injectConfirmPIN(connInfo, true);
|
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||||
} // onConfirmPIN
|
} // onConfirmPIN
|
||||||
|
|
||||||
void NimBLEServerCallbacks::onIdentity(NimBLEConnInfo& connInfo){
|
void NimBLEServerCallbacks::onIdentity(NimBLEConnInfo& connInfo){
|
||||||
|
|
|
@ -180,10 +180,10 @@ public:
|
||||||
/**
|
/**
|
||||||
* @brief Called when using numeric comparision for pairing.
|
* @brief Called when using numeric comparision for pairing.
|
||||||
* @param [in] connInfo A reference to a NimBLEConnInfo instance with information
|
* @param [in] connInfo A reference to a NimBLEConnInfo instance with information
|
||||||
* Should be passed back to NimBLEDevice::injectConfirmPIN
|
* Should be passed back to NimBLEDevice::injectConfirmPasskey
|
||||||
* @param [in] pin The pin to compare with the client.
|
* @param [in] pin The pin to compare with the client.
|
||||||
*/
|
*/
|
||||||
virtual void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pin);
|
virtual void onConfirmPassKey(NimBLEConnInfo& connInfo, uint32_t pin);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called when the pairing procedure is complete.
|
* @brief Called when the pairing procedure is complete.
|
||||||
|
|
Loading…
Reference in a new issue