esp-nimble-cpp 2.0.2
Loading...
Searching...
No Matches
NimBLEConnInfo.h
1/*
2 * Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
3 * esp-nimble-cpp, NimBLE-Arduino contributors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NIMBLECONNINFO_H_
19#define NIMBLECONNINFO_H_
20
21#if defined(CONFIG_NIMBLE_CPP_IDF)
22# include "host/ble_gap.h"
23#else
24# include "nimble/nimble/host/include/host/ble_gap.h"
25#endif
26
27#include "NimBLEAddress.h"
28
33 public:
35 NimBLEAddress getAddress() const { return NimBLEAddress(m_desc.peer_ota_addr); }
36
38 NimBLEAddress getIdAddress() const { return NimBLEAddress(m_desc.peer_id_addr); }
39
41 uint16_t getConnHandle() const { return m_desc.conn_handle; }
42
44 uint16_t getConnInterval() const { return m_desc.conn_itvl; }
45
47 uint16_t getConnTimeout() const { return m_desc.supervision_timeout; }
48
50 uint16_t getConnLatency() const { return m_desc.conn_latency; }
51
53 uint16_t getMTU() const { return ble_att_mtu(m_desc.conn_handle); }
54
56 bool isMaster() const { return (m_desc.role == BLE_GAP_ROLE_MASTER); }
57
59 bool isSlave() const { return (m_desc.role == BLE_GAP_ROLE_SLAVE); }
60
62 bool isBonded() const { return (m_desc.sec_state.bonded == 1); }
63
65 bool isEncrypted() const { return (m_desc.sec_state.encrypted == 1); }
66
68 bool isAuthenticated() const { return (m_desc.sec_state.authenticated == 1); }
69
71 uint8_t getSecKeySize() const { return m_desc.sec_state.key_size; }
72
73 private:
74 friend class NimBLEServer;
75 friend class NimBLEClient;
76 friend class NimBLECharacteristic;
77 friend class NimBLEDescriptor;
78
79 ble_gap_conn_desc m_desc{};
80 NimBLEConnInfo() {};
81 NimBLEConnInfo(ble_gap_conn_desc desc) { m_desc = desc; }
82};
83#endif
A BLE device address.
Definition NimBLEAddress.h:41
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
uint16_t getConnLatency() const
Gets the allowable latency for this connection (unit = number of intervals)
Definition NimBLEConnInfo.h:50
NimBLEAddress getAddress() const
Gets the over-the-air address of the connected peer.
Definition NimBLEConnInfo.h:35
uint16_t getMTU() const
Gets the maximum transmission unit size for this connection (in bytes)
Definition NimBLEConnInfo.h:53
NimBLEAddress getIdAddress() const
Gets the ID address of the connected peer.
Definition NimBLEConnInfo.h:38
bool isEncrypted() const
Check if the connection in encrypted.
Definition NimBLEConnInfo.h:65
uint8_t getSecKeySize() const
Gets the key size used to encrypt the connection.
Definition NimBLEConnInfo.h:71
bool isMaster() const
Check if we are in the master role in this connection.
Definition NimBLEConnInfo.h:56
bool isAuthenticated() const
Check if the the connection has been authenticated.
Definition NimBLEConnInfo.h:68
uint16_t getConnHandle() const
Gets the connection handle (also known as the connection id) of the connected peer.
Definition NimBLEConnInfo.h:41
uint16_t getConnTimeout() const
Gets the supervision timeout for this connection (in 10ms units)
Definition NimBLEConnInfo.h:47
uint16_t getConnInterval() const
Gets the connection interval for this connection (in 1.25ms units)
Definition NimBLEConnInfo.h:44
bool isSlave() const
Check if we are in the slave role in this connection.
Definition NimBLEConnInfo.h:59
bool isBonded() const
Check if we are connected to a bonded peer.
Definition NimBLEConnInfo.h:62
A model of a BLE descriptor.
Definition NimBLEDescriptor.h:33
The model of a BLE server.
Definition NimBLEServer.h:60