18#ifndef NIMBLE_CPP_SERVER_H_
19#define NIMBLE_CPP_SERVER_H_
22#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
24# if defined(CONFIG_NIMBLE_CPP_IDF)
25# include "host/ble_gap.h"
27# include "nimble/nimble/host/include/host/ble_gap.h"
38# define NIMBLE_ATT_REMOVE_HIDE 1
39# define NIMBLE_ATT_REMOVE_DELETE 2
48# if CONFIG_BT_NIMBLE_EXT_ADV
53# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
64 bool disconnect(uint16_t connHandle, uint8_t reason = BLE_ERR_REM_USER_CONN_TERM)
const;
67 void updateConnParams(uint16_t connHandle, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout)
const;
75 uint16_t
getPeerMTU(uint16_t connHandle)
const;
81 void setDataLen(uint16_t connHandle, uint16_t tx_octets)
const;
83# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
89# if CONFIG_BT_NIMBLE_EXT_ADV
91 bool startAdvertising(uint8_t instanceId,
int duration = 0,
int maxEvents = 0)
const;
93 bool updatePhy(uint16_t connHandle, uint8_t txPhysMask, uint8_t rxPhysMask, uint16_t phyOptions);
94 bool getPhy(uint16_t connHandle, uint8_t* txPhy, uint8_t* rxPhy);
97# if !CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_)
107# if CONFIG_BT_NIMBLE_EXT_ADV
116 bool m_gattsStarted : 1;
117 bool m_svcChanged : 1;
118 bool m_deleteCallbacks : 1;
119# if !CONFIG_BT_NIMBLE_EXT_ADV
120 bool m_advertiseOnDisconnect : 1;
123 std::vector<NimBLEService*> m_svcVec;
124 std::array<uint16_t, CONFIG_BT_NIMBLE_MAX_CONNECTIONS> m_connectedPeers;
126# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
130 static int handleGapEvent(
struct ble_gap_event* event,
void* arg);
131 static int handleGattEvent(uint16_t connHandle, uint16_t attrHandle, ble_gatt_access_ctxt* ctxt,
void* arg);
132 void serviceChanged();
206# if CONFIG_BT_NIMBLE_EXT_ADV
A BLE device address.
Definition NimBLEAddress.h:41
Perform and manage BLE advertising.
Definition NimBLEAdvertising.h:52
The model of a BLE Characteristic.
Definition NimBLECharacteristic.h:40
A model of a BLE client.
Definition NimBLEClient.h:49
Connection information.
Definition NimBLEConnInfo.h:32
A model of a BLE Device from which all the BLE roles are created.
Definition NimBLEDevice.h:109
Extended advertising class.
Definition NimBLEExtAdvertising.h:111
Callbacks associated with the operation of a BLE server.
Definition NimBLEServer.h:140
virtual void onConnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo)
Handle a client connection. This is called when a client connects.
Definition NimBLEServer.cpp:987
virtual uint32_t onPassKeyDisplay()
Called when a client requests a passkey for pairing (display).
Definition NimBLEServer.cpp:999
virtual void onDisconnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo, int reason)
Handle a client disconnection. This is called when a client disconnects.
Definition NimBLEServer.cpp:991
virtual void onConfirmPassKey(NimBLEConnInfo &connInfo, uint32_t pin)
Called when using numeric comparision for pairing.
Definition NimBLEServer.cpp:1004
virtual void onPhyUpdate(NimBLEConnInfo &connInfo, uint8_t txPhy, uint8_t rxPhy)
Called when the PHY update procedure is complete.
Definition NimBLEServer.cpp:1022
virtual void onAuthenticationComplete(NimBLEConnInfo &connInfo)
Called when the pairing procedure is complete.
Definition NimBLEServer.cpp:1013
virtual void onConnParamsUpdate(NimBLEConnInfo &connInfo)
Called when connection parameters are updated following a request to update via NimBLEServer::updateC...
Definition NimBLEServer.cpp:1017
virtual void onMTUChange(uint16_t MTU, NimBLEConnInfo &connInfo)
Called when the connection MTU changes.
Definition NimBLEServer.cpp:995
virtual void onIdentity(NimBLEConnInfo &connInfo)
Called when the peer identity address is resolved.
Definition NimBLEServer.cpp:1009
The model of a BLE server.
Definition NimBLEServer.h:60
void removeService(NimBLEService *service, bool deleteSvc=false)
Remove a service from the server.
Definition NimBLEServer.cpp:708
NimBLEConnInfo getPeerInfoByHandle(uint16_t connHandle) const
Get the connection information of a connected peer by connection handle.
Definition NimBLEServer.cpp:337
NimBLEService * getServiceByHandle(uint16_t handle) const
Get a BLE Service by its handle.
Definition NimBLEServer.cpp:137
NimBLEConnInfo getPeerInfo(uint8_t index) const
Get the connection information of a connected peer by vector index.
Definition NimBLEServer.cpp:299
std::vector< uint16_t > getPeerDevices() const
Get a vector of the connected client handles.
Definition NimBLEServer.cpp:283
bool stopAdvertising() const
Stop advertising.
Definition NimBLEServer.cpp:877
NimBLEService * getServiceByUUID(const char *uuid, uint16_t instanceId=0) const
Get a BLE Service by its UUID.
Definition NimBLEServer.cpp:108
NimBLEClient * getClient(uint16_t connHandle)
Create a client instance from the connection handle.
Definition NimBLEServer.cpp:946
uint16_t getPeerMTU(uint16_t connHandle) const
Get the MTU value of a client connection.
Definition NimBLEServer.cpp:887
uint8_t getConnectedCount() const
Return the number of connected clients.
Definition NimBLEServer.cpp:268
void setCallbacks(NimBLEServerCallbacks *pCallbacks, bool deleteCallbacks=true)
Set the server callbacks.
Definition NimBLEServer.cpp:680
void updateConnParams(uint16_t connHandle, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout) const
Request an Update the connection parameters:
Definition NimBLEServer.cpp:900
void addService(NimBLEService *service)
Adds a service which was either already created but removed from availability, or created and later a...
Definition NimBLEServer.cpp:745
bool getPhy(uint16_t connHandle, uint8_t *txPhy, uint8_t *rxPhy)
Get the PHY used for a peer connection.
Definition NimBLEServer.cpp:851
NimBLEExtAdvertising * getAdvertising() const
Retrieve the advertising object that can be used to advertise the existence of the server.
Definition NimBLEServer.cpp:152
void deleteClient()
Delete the NimBLEClient instance that was created with getClient()
Definition NimBLEServer.cpp:978
NimBLEService * createService(const char *uuid)
Create a BLE Service.
Definition NimBLEServer.cpp:85
bool startAdvertising(uint8_t instanceId, int duration=0, int maxEvents=0) const
Start advertising.
Definition NimBLEServer.cpp:803
bool updatePhy(uint16_t connHandle, uint8_t txPhysMask, uint8_t rxPhysMask, uint16_t phyOptions)
Request an update to the PHY used for a peer connection.
Definition NimBLEServer.cpp:835
bool disconnect(uint16_t connHandle, uint8_t reason=BLE_ERR_REM_USER_CONN_TERM) const
Disconnect the specified client with optional reason.
Definition NimBLEServer.cpp:234
void start()
Start the GATT server.
Definition NimBLEServer.cpp:182
void advertiseOnDisconnect(bool enable)
Set the server to automatically start advertising when a client disconnects.
Definition NimBLEServer.cpp:259
void setDataLen(uint16_t connHandle, uint16_t tx_octets) const
Request an update of the data packet length.
Definition NimBLEServer.cpp:924
The model of a BLE service.
Definition NimBLEService.h:34
A model of a BLE UUID.
Definition NimBLEUUID.h:41