1#ifdef NOT_FOR_SHOW_ONLY
16#ifndef MAIN_NIMBLEDEVICE_H_
17#define MAIN_NIMBLEDEVICE_H_
20#if defined(CONFIG_BT_ENABLED)
22#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
23#include "NimBLEScan.h"
26#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
27# if CONFIG_BT_NIMBLE_EXT_ADV
28# include "NimBLEExtAdvertising.h"
30# include "NimBLEAdvertising.h"
34#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
35#include "NimBLEClient.h"
38#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
39#include "NimBLEServer.h"
42#include "NimBLEUtils.h"
43#include "NimBLESecurity.h"
44#include "NimBLEAddress.h"
54#define BLEDevice NimBLEDevice
55#define BLEClient NimBLEClient
56#define BLERemoteService NimBLERemoteService
57#define BLERemoteCharacteristic NimBLERemoteCharacteristic
58#define BLERemoteDescriptor NimBLERemoteDescriptor
59#define BLEAdvertisedDevice NimBLEAdvertisedDevice
60#define BLEScan NimBLEScan
61#define BLEUUID NimBLEUUID
62#define BLESecurity NimBLESecurity
63#define BLESecurityCallbacks NimBLESecurityCallbacks
64#define BLEAddress NimBLEAddress
65#define BLEUtils NimBLEUtils
66#define BLEClientCallbacks NimBLEClientCallbacks
67#define BLEAdvertisedDeviceCallbacks NimBLEAdvertisedDeviceCallbacks
68#define BLEScanResults NimBLEScanResults
69#define BLEServer NimBLEServer
70#define BLEService NimBLEService
71#define BLECharacteristic NimBLECharacteristic
72#define BLEAdvertising NimBLEAdvertising
73#define BLEServerCallbacks NimBLEServerCallbacks
74#define BLECharacteristicCallbacks NimBLECharacteristicCallbacks
75#define BLEAdvertisementData NimBLEAdvertisementData
76#define BLEDescriptor NimBLEDescriptor
77#define BLE2902 NimBLE2902
78#define BLE2904 NimBLE2904
79#define BLEDescriptorCallbacks NimBLEDescriptorCallbacks
80#define BLEBeacon NimBLEBeacon
81#define BLEEddystoneTLM NimBLEEddystoneTLM
82#define BLEEddystoneURL NimBLEEddystoneURL
84#ifdef CONFIG_BT_NIMBLE_MAX_CONNECTIONS
85#define NIMBLE_MAX_CONNECTIONS CONFIG_BT_NIMBLE_MAX_CONNECTIONS
87#define NIMBLE_MAX_CONNECTIONS CONFIG_NIMBLE_MAX_CONNECTIONS
90typedef int (*gap_event_handler)(ble_gap_event *event,
void *arg);
92extern "C" void ble_store_config_init(
void);
99 static void init(
const std::string &deviceName);
100 static void deinit(
bool clearAll =
false);
101 static bool getInitialized();
102 static NimBLEAddress getAddress();
103 static std::string toString();
104 static bool whiteListAdd(
const NimBLEAddress & address);
105 static bool whiteListRemove(
const NimBLEAddress & address);
106 static bool onWhiteList(
const NimBLEAddress & address);
107 static size_t getWhiteListCount();
108 static NimBLEAddress getWhiteListAddress(
size_t index);
110#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
111 static NimBLEScan* getScan();
114#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
115 static NimBLEServer* createServer();
116 static NimBLEServer* getServer();
120 static void setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT);
121 static int getPower(esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT);
122 static void setOwnAddrType(uint8_t own_addr_type,
bool useNRPA=
false);
123 static void setScanDuplicateCacheSize(uint16_t cacheSize);
124 static void setScanFilterMode(uint8_t type);
126 static void setPower(
int dbm);
127 static int getPower();
130 static void setCustomGapHandler(gap_event_handler handler);
131 static void setSecurityAuth(
bool bonding,
bool mitm,
bool sc);
132 static void setSecurityAuth(uint8_t auth_req);
133 static void setSecurityIOCap(uint8_t iocap);
134 static void setSecurityInitKey(uint8_t init_key);
135 static void setSecurityRespKey(uint8_t init_key);
136 static void setSecurityPasskey(uint32_t pin);
137 static uint32_t getSecurityPasskey();
138 static void setSecurityCallbacks(NimBLESecurityCallbacks* pCallbacks);
139 static int startSecurity(uint16_t conn_id);
140 static int setMTU(uint16_t mtu);
141 static uint16_t getMTU();
142 static bool isIgnored(
const NimBLEAddress &address);
143 static void addIgnored(
const NimBLEAddress &address);
144 static void removeIgnored(
const NimBLEAddress &address);
146#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
147# if CONFIG_BT_NIMBLE_EXT_ADV
148 static NimBLEExtAdvertising* getAdvertising();
149 static bool startAdvertising(uint8_t inst_id,
152 static bool stopAdvertising(uint8_t inst_id);
153 static bool stopAdvertising();
155 static NimBLEAdvertising* getAdvertising();
156 static bool startAdvertising();
157 static bool stopAdvertising();
161#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
162 static NimBLEClient* createClient(NimBLEAddress peerAddress = NimBLEAddress(
""));
163 static bool deleteClient(NimBLEClient* pClient);
164 static NimBLEClient* getClientByID(uint16_t conn_id);
165 static NimBLEClient* getClientByPeerAddress(
const NimBLEAddress &peer_addr);
166 static NimBLEClient* getDisconnectedClient();
167 static size_t getClientListSize();
168 static std::list<NimBLEClient*>* getClientList();
171#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) || defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
172 static bool deleteBond(
const NimBLEAddress &address);
173 static int getNumBonds();
174 static bool isBonded(
const NimBLEAddress &address);
175 static void deleteAllBonds();
176 static NimBLEAddress getBondedAddress(
int index);
180#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
181 friend class NimBLEClient;
184#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
185 friend class NimBLEScan;
188#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
189 friend class NimBLEServer;
190 friend class NimBLECharacteristic;
193#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
194 friend class NimBLEAdvertising;
195# if CONFIG_BT_NIMBLE_EXT_ADV
196 friend class NimBLEExtAdvertising;
197 friend class NimBLEExtAdvertisement;
201 static void onReset(
int reason);
202 static void onSync(
void);
203 static void host_task(
void *param);
204 static bool m_synced;
206#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
207 static NimBLEScan* m_pScan;
210#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
211 static NimBLEServer* m_pServer;
214#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
215# if CONFIG_BT_NIMBLE_EXT_ADV
216 static NimBLEExtAdvertising* m_bleAdvertising;
218 static NimBLEAdvertising* m_bleAdvertising;
222#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
223 static std::list <NimBLEClient*> m_cList;
225 static std::list <NimBLEAddress> m_ignoreList;
226 static NimBLESecurityCallbacks* m_securityCallbacks;
227 static uint32_t m_passkey;
228 static ble_gap_event_listener m_listener;
229 static gap_event_handler m_customGapHandler;
230 static uint8_t m_own_addr_type;
232 static uint16_t m_scanDuplicateSize;
233 static uint8_t m_scanFilterMode;
235 static std::vector<NimBLEAddress> m_whiteList;