Flipper Zero Firmware
Loading...
Searching...
No Matches
gatt.h
1#pragma once
2
3#include <stdint.h>
4#include <stdbool.h>
5#include <stdio.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11#include <ble/core/auto/ble_types.h>
12
13/* Callback signature for getting characteristic data
14 * Is called when characteristic is created to get max data length. Data ptr is NULL in this case
15 * The result is passed to aci_gatt_add_char as "Char_Value_Length"
16 * For updates, called with a context - see flipper_gatt_characteristic_update
17 * Returns true if *data ownership is transferred to the caller and will be freed */
18typedef bool (
19 *cbBleGattCharacteristicData)(const void* context, const uint8_t** data, uint16_t* data_len);
20
21/* Used to specify the type of data for a characteristic - constant or callback-based */
22typedef enum {
23 FlipperGattCharacteristicDataFixed,
24 FlipperGattCharacteristicDataCallback,
25} BleGattCharacteristicDataType;
26
27typedef struct {
28 Char_Desc_Uuid_t uuid;
29 struct {
30 cbBleGattCharacteristicData fn;
31 const void* context;
32 } data_callback;
33 uint8_t uuid_type;
34 uint8_t max_length;
35 uint8_t security_permissions;
36 uint8_t access_permissions;
37 uint8_t gatt_evt_mask;
38 uint8_t is_variable;
40
41/* Describes a single characteristic, providing data or callbacks to get data */
42typedef struct {
43 const char* name;
45 union {
46 struct {
47 const uint8_t* ptr;
48 uint16_t length;
49 } fixed;
50 struct {
51 cbBleGattCharacteristicData fn;
52 const void* context;
53 } callback;
54 } data;
55 Char_UUID_t uuid;
56 // Some packed bitfields to save space
57 BleGattCharacteristicDataType data_prop_type : 2;
58 uint8_t is_variable : 2;
59 uint8_t uuid_type : 2;
60 uint8_t char_properties;
61 uint8_t security_permissions;
62 uint8_t gatt_evt_mask;
64
65_Static_assert(
66 sizeof(BleGattCharacteristicParams) == 36,
67 "BleGattCharacteristicParams size must be 36 bytes");
68
69typedef struct {
70 const BleGattCharacteristicParams* characteristic;
71 uint16_t handle;
72 uint16_t descriptor_handle;
74
75/* Initialize a characteristic instance; copies the characteristic descriptor
76 * into the instance */
77void ble_gatt_characteristic_init(
78 uint16_t svc_handle,
79 const BleGattCharacteristicParams* char_descriptor,
80 BleGattCharacteristicInstance* char_instance);
81
82/* Delete a characteristic instance; frees the copied characteristic
83 * descriptor from the instance */
84void ble_gatt_characteristic_delete(
85 uint16_t svc_handle,
86 BleGattCharacteristicInstance* char_instance);
87
88/* Update a characteristic instance; if source==NULL, uses the data from
89 * the characteristic:
90 * - For fixed data, fixed.ptr is used as the source if source==NULL
91 * - For callback-based data, collback.context is passed as the context
92 * if source==NULL
93 */
94bool ble_gatt_characteristic_update(
95 uint16_t svc_handle,
96 BleGattCharacteristicInstance* char_instance,
97 const void* source);
98
99bool ble_gatt_service_add(
100 uint8_t Service_UUID_Type,
101 const Service_UUID_t* Service_UUID,
102 uint8_t Service_Type,
103 uint8_t Max_Attribute_Records,
104 uint16_t* Service_Handle);
105
106bool ble_gatt_service_delete(uint16_t svc_handle);
107
108#ifdef __cplusplus
109}
110#endif
Definition gatt.h:69
Definition gatt.h:42