nRF Connect SDK Bare Metal API 2.0.99
Loading...
Searching...
No Matches
ble_common.h
1
14#ifndef BLE_COMMON_H__
15#define BLE_COMMON_H__
16
17#include <stdbool.h>
18#include <stdint.h>
19#include <ble_gap.h>
20#include <ble_gatt.h>
21#include <zephyr/sys/byteorder.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
30#define ATT_OPCODE_LEN sizeof(uint8_t)
31
35#define ATT_HANDLE_LEN sizeof(uint16_t)
36
44#define BYTES_TO_WORDS(n_bytes) (((n_bytes) + 3) >> 2)
45
53static inline bool is_notification_enabled(const uint8_t *gatts_value)
54{
55 const uint16_t cccd_val = sys_get_le16(gatts_value);
56
57 return (cccd_val & BLE_GATT_HVX_NOTIFICATION);
58}
59
67static inline bool is_indication_enabled(const uint8_t *gatts_value)
68{
69 const uint16_t cccd_val = sys_get_le16(gatts_value);
70
71 return (cccd_val & BLE_GATT_HVX_INDICATION);
72}
73
82static inline bool ble_gap_conn_sec_mode_equal(const ble_gap_conn_sec_mode_t *a,
83 const ble_gap_conn_sec_mode_t *b)
84{
85 return (a->sm == b->sm) && (a->lv == b->lv);
86}
87
91#define BLE_GAP_CONN_SEC_MODE_NO_ACCESS \
92 (ble_gap_conn_sec_mode_t) \
93 { \
94 .sm = 0, .lv = 0 \
95 }
96
100#define BLE_GAP_CONN_SEC_MODE_OPEN \
101 (ble_gap_conn_sec_mode_t) \
102 { \
103 .sm = 1, .lv = 1 \
104 }
105
109#define BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM \
110 (ble_gap_conn_sec_mode_t) \
111 { \
112 .sm = 1, .lv = 2 \
113 }
114
118#define BLE_GAP_CONN_SEC_MODE_ENC_WITH_MITM \
119 (ble_gap_conn_sec_mode_t) \
120 { \
121 .sm = 1, .lv = 3 \
122 }
123
127#define BLE_GAP_CONN_SEC_MODE_LESC_ENC_WITH_MITM \
128 (ble_gap_conn_sec_mode_t) \
129 { \
130 .sm = 1, .lv = 4 \
131 }
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* BLE_COMMON_H__ */
138
static bool is_notification_enabled(const uint8_t *gatts_value)
Read CCCD value from data and check if notifications are enabled.
Definition ble_common.h:53
static bool is_indication_enabled(const uint8_t *gatts_value)
Read CCCD value from data and check if indications are enabled.
Definition ble_common.h:67
static bool ble_gap_conn_sec_mode_equal(const ble_gap_conn_sec_mode_t *a, const ble_gap_conn_sec_mode_t *b)
Compare GAP connection security mode.
Definition ble_common.h:82