Developer World
Spresense SDK Library v3.2.0-ebc0364
ble_gatt.h
Go to the documentation of this file.
1/****************************************************************************
2 * modules/include/bluetooth/ble_gatt.h
3 *
4 * Copyright 2018 Sony Semiconductor Solutions Corporation
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17 * the names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
35
43#ifndef __MODULES_INCLUDE_BLUETOOTH_BLE_GATT_H
44#define __MODULES_INCLUDE_BLUETOOTH_BLE_GATT_H
45
46/****************************************************************************
47 * Included Files
48 ****************************************************************************/
49
50#include <stdint.h>
51#include <bluetooth/bluetooth.h>
52#include <bluetooth/bt_common.h>
53
54/****************************************************************************
55 * Pre-processor Definitions
56 ****************************************************************************/
57
62#define BLE_MAX_SERVICES 1
69#define BLE_MAX_CHARACTERISTICS 1
76#define BLE_MAX_CHAR_SIZE 20
83#define BLE_GATT_INVALID_SERVICE_HANDLE UINT16_MAX
90#define BLE_GATT_INVALID_ATTRIBUTE_HANDLE (0x0000)
91
98#define BLE_DB_DISCOVERY_MAX_SRV 3
105#define BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV 4
108/****************************************************************************
109 * Public Types prototype
110 ****************************************************************************/
111
112struct ble_gatt_char_s;
113
114/****************************************************************************
115 * Public Types
116 ****************************************************************************/
117
122typedef enum
123{
128
133typedef enum
134{
138
144typedef enum{
152
157typedef struct
158{
159 uint8_t uuid128[BT_UUID128_LEN];
161
166typedef struct
167{
169 uint16_t uuidAlias;
171
176typedef struct
177{
179 union
180 {
184} BLE_UUID;
185
190typedef struct
191{
195
200typedef struct
201{
203 uint8_t *data;
204 uint16_t length;
206
212typedef struct
213{
214 uint8_t broadcast :1;
215 uint8_t read :1;
216 uint8_t writeWoResp :1;
217 uint8_t write :1;
218 uint8_t notify :1;
219 uint8_t indicate :1;
220 uint8_t authSignedWr :1;
221 uint8_t reserve :1;
223
231{
232 void (*write)(struct ble_gatt_char_s *ble_gatt_char);
233 void (*read)(struct ble_gatt_char_s *ble_gatt_char);
234 void (*notify)(struct ble_gatt_char_s *ble_gatt_char, bool enable);
235};
236
242{
243 uint16_t handle;
247 uint8_t status;
248 union
249 {
252 };
253};
254
260{
261 uint16_t handle;
264 uint8_t num;
265 struct ble_gatt_char_s *chars[BLE_MAX_CHARACTERISTICS];
266};
267
273{
276 uint8_t num;
277 struct ble_gatt_service_s services[BLE_MAX_SERVICES];
278 /* TODO: temporary, needs to consider the design */
280};
281
287{
288 uint16_t start_handle;
289 uint16_t end_handle;
290};
291
297{
299 uint16_t char_valhandle;
302};
303
309{
312 uint16_t cepd_handle;
313
316 uint16_t cudd_handle;
317
320 uint16_t cccd_handle;
321
324 uint16_t sccd_handle;
325
328 uint16_t cpfd_handle;
329
332 uint16_t cafd_handle;
333
337};
338
344{
345 uint8_t char_count;
347 struct ble_gattc_db_disc_char_s characteristics[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV];
349};
350
356{
357 uint8_t srv_count;
358 uint16_t conn_handle;
359 struct ble_gattc_db_disc_srv_s services[BLE_DB_DISCOVERY_MAX_SRV];
360};
361
367{
368 uint8_t srv_count;
369 uint16_t end_handle;
370};
371
378{
379 uint8_t group_id;
380 uint8_t event_id;
381 uint8_t result;
382 uint16_t conn_handle;
384 union{
385 uint32_t reason;
388};
389
397{
400 void (*write)(uint16_t conn_handle, struct ble_gatt_char_s *ble_gatt_char);
401
404 void (*read)(uint16_t conn_handle, struct ble_gatt_char_s *ble_gatt_char);
405
408 void (*notify)(uint16_t conn_handle, struct ble_gatt_char_s *ble_gatt_char);
409
413
416 void (*descriptor_write)(uint16_t conn_handle, uint16_t handle, int status);
417
420 void (*descriptor_read)(uint16_t conn_handle,
421 uint16_t handle,
422 uint8_t *data,
423 uint16_t len);
424};
425
426#ifdef __cplusplus
427#define EXTERN extern "C"
428extern "C"
429{
430#else
431#define EXTERN extern
432#endif
433
434/****************************************************************************
435 * Public Function Prototypes
436 ****************************************************************************/
437
445
456
467
479
493 struct ble_gatt_char_s *charc,
494 uint8_t *data,
495 int len);
496
508
522 struct ble_gatt_char_s *charc,
523 uint8_t *data,
524 int len);
525
536int ble_read_characteristic(uint16_t conn_handle, uint16_t char_handle);
537
552 uint16_t char_handle,
553 uint8_t *data,
554 int len,
555 bool rsp);
556
567int ble_descriptor_read(uint16_t conn_handle, uint16_t handle);
568
582 uint16_t handle,
583 uint8_t *data,
584 int len);
585
598
611int ble_continue_db_discovery(uint16_t start_handle, uint16_t conn_handle);
612
622int ble_discover_uuid(uint16_t conn_handle, BLE_UUID *srv_uuid, BLE_UUID *char_uuid);
623
624#undef EXTERN
625#ifdef __cplusplus
626}
627#endif
628
629#endif /* __MODULES_INCLUDE_BLUETOOTH_BLE_GATT_H */
int ble_write_characteristic(uint16_t conn_handle, uint16_t char_handle, uint8_t *data, int len, bool rsp)
BLE Write Characteristic value Send write characteristic request to peripheral (For Central role)
int ble_characteristic_read(uint16_t conn_handle, struct ble_gatt_char_s *charc)
BLE Read Characteristic value (Deprecated) Send read characteristic request to peripheral (For Centra...
int ble_add_characteristic(struct ble_gatt_service_s *service, struct ble_gatt_char_s *charc)
BLE add Characteristic to service Add characteristic to service.
BLE_GATT_TYPE
GATTS service type.
Definition: ble_gatt.h:134
@ BLE_GATTS_SRVTYP_SECONDARY
Definition: ble_gatt.h:136
@ BLE_GATTS_SRVTYP_PRIMARY
Definition: ble_gatt.h:135
BLE_GATT_UUID_TYPE
GATTS UUID type.
Definition: ble_gatt.h:123
@ BLE_UUID_TYPE_BASEALIAS_BTSIG
Definition: ble_gatt.h:125
@ BLE_UUID_TYPE_BASEALIAS_VENDOR
Definition: ble_gatt.h:126
@ BLE_UUID_TYPE_UUID128
Definition: ble_gatt.h:124
int ble_register_servce(struct ble_gatt_service_s *service)
BLE Register GATT Service Register GATT Service to HAL.
int ble_descriptor_read(uint16_t conn_handle, uint16_t handle)
BLE Read Descriptor value Send read descriptor request to peripheral (For Central role)
BLE_SEC_MODE
Definition: ble_gatt.h:144
@ BLE_SEC_MODE2LV2__MITM_DATA_SGN
Definition: ble_gatt.h:150
@ BLE_SEC_MODE_NO_ACCESS
Definition: ble_gatt.h:145
@ BLE_SEC_MODE1LV3_MITM_ENC
Definition: ble_gatt.h:148
@ BLE_SEC_MODE1LV2_NO_MITM_ENC
Definition: ble_gatt.h:147
@ BLE_SEC_MODE1LV1_NO_SEC
Definition: ble_gatt.h:146
@ BLE_SEC_MODE2LV1_NO_MITM_DATA_SGN
Definition: ble_gatt.h:149
int ble_characteristic_write(uint16_t conn_handle, struct ble_gatt_char_s *charc, uint8_t *data, int len)
BLE Write Characteristic value (Deprecated) Send write characteristic request to peripheral (For Cent...
int ble_create_service(struct ble_gatt_service_s **service)
BLE Create GATT Service Create GATT Service instance and return instance pointer via *service.
int ble_continue_db_discovery(uint16_t start_handle, uint16_t conn_handle)
BLE continue database discovery Send continue database discovery request to peripheral (For Central r...
bool ble_gatt_is_supported(void)
Get Bluetooth Low Ennergy GATT support or not support.
int ble_descriptor_write(uint16_t conn_handle, uint16_t handle, uint8_t *data, int len)
BLE Write Descriptor value Send write descriptor request to peripheral (For Central role)
int ble_read_characteristic(uint16_t conn_handle, uint16_t char_handle)
BLE Read Characteristic value Send read characteristic request to peripheral (For Central role)
int ble_start_db_discovery(uint16_t conn_handle)
BLE start database discovery Send database discovery request to peripheral (For Central role) In case...
int ble_discover_uuid(uint16_t conn_handle, BLE_UUID *srv_uuid, BLE_UUID *char_uuid)
Discover GATT database with specific UUID.
int ble_characteristic_notify(uint16_t conn_handle, struct ble_gatt_char_s *charc, uint8_t *data, int len)
BLE Notify Characteristic value Notify characteristic value to Central (For Peripheral role)
Bluetooth common header for SDK on Spresense.
Bluetooth generic API.
Attribute permission structure.
Definition: ble_gatt.h:191
BLE_SEC_MODE readPerm
Definition: ble_gatt.h:192
BLE_SEC_MODE writePerm
Definition: ble_gatt.h:193
Characteristic standard properties.
Definition: ble_gatt.h:213
uint8_t indicate
Definition: ble_gatt.h:219
uint8_t write
Definition: ble_gatt.h:217
uint8_t broadcast
Definition: ble_gatt.h:214
uint8_t authSignedWr
Definition: ble_gatt.h:220
uint8_t notify
Definition: ble_gatt.h:218
uint8_t reserve
Definition: ble_gatt.h:221
uint8_t read
Definition: ble_gatt.h:215
uint8_t writeWoResp
Definition: ble_gatt.h:216
characteristic value attribute structure
Definition: ble_gatt.h:201
uint16_t length
Definition: ble_gatt.h:204
uint8_t * data
Definition: ble_gatt.h:203
BLE_ATTR_PERM attrPerm
Definition: ble_gatt.h:202
BLE security mode security level.
128-bit UUID structure for BLE
Definition: ble_gatt.h:158
UUID base + alias structure.
Definition: ble_gatt.h:167
uint16_t uuidAlias
Definition: ble_gatt.h:169
BLE_UUID128 uuidBase
Definition: ble_gatt.h:168
BLE UUID structure.
Definition: ble_gatt.h:177
BLE_GATT_UUID_TYPE type
Definition: ble_gatt.h:178
BLE_UUID128 uuid128
Definition: ble_gatt.h:181
BLE_UUID_ALIAS alias
Definition: ble_gatt.h:182
Bluetooth LE characteristic callbacks(for Central)
Definition: ble_gatt.h:397
void(* read)(uint16_t conn_handle, struct ble_gatt_char_s *ble_gatt_char)
Definition: ble_gatt.h:404
void(* write)(uint16_t conn_handle, struct ble_gatt_char_s *ble_gatt_char)
Definition: ble_gatt.h:400
void(* database_discovery)(struct ble_gatt_event_db_discovery_t *db_disc)
Definition: ble_gatt.h:412
void(* notify)(uint16_t conn_handle, struct ble_gatt_char_s *ble_gatt_char)
Definition: ble_gatt.h:408
void(* descriptor_write)(uint16_t conn_handle, uint16_t handle, int status)
Definition: ble_gatt.h:416
void(* descriptor_read)(uint16_t conn_handle, uint16_t handle, uint8_t *data, uint16_t len)
Definition: ble_gatt.h:420
Bluetooth LE GATT characteristic context.
Definition: ble_gatt.h:242
struct ble_gatt_central_ops_s * ble_gatt_central_ops
Definition: ble_gatt.h:250
BLE_CHAR_PROP property
Definition: ble_gatt.h:246
BLE_UUID uuid
Definition: ble_gatt.h:244
struct ble_gatt_peripheral_ops_s * ble_gatt_peripheral_ops
Definition: ble_gatt.h:251
BLE_CHAR_VALUE value
Definition: ble_gatt.h:245
uint8_t status
Definition: ble_gatt.h:247
uint16_t handle
Definition: ble_gatt.h:243
Definition: ble_gatt.h:367
uint16_t end_handle
Definition: ble_gatt.h:369
uint8_t srv_count
Definition: ble_gatt.h:368
GATTC attribute database discovery event structure.
Definition: ble_gatt.h:378
uint16_t conn_handle
Definition: ble_gatt.h:382
uint8_t result
Definition: ble_gatt.h:381
uint32_t reason
Definition: ble_gatt.h:385
union ble_gatt_event_db_discovery_t::@52 params
uint8_t group_id
Definition: ble_gatt.h:379
struct ble_gattc_db_discovery_s db_discovery
Definition: ble_gatt.h:386
struct ble_gatt_coverrun_state_s state
Definition: ble_gatt.h:383
uint8_t event_id
Definition: ble_gatt.h:380
Bluetooth LE characteristic callbacks(for Peripheral)
Definition: ble_gatt.h:231
void(* notify)(struct ble_gatt_char_s *ble_gatt_char, bool enable)
Definition: ble_gatt.h:234
void(* read)(struct ble_gatt_char_s *ble_gatt_char)
Definition: ble_gatt.h:233
void(* write)(struct ble_gatt_char_s *ble_gatt_char)
Definition: ble_gatt.h:232
Bluetooth LE GATT service context.
Definition: ble_gatt.h:260
BLE_UUID uuid
Definition: ble_gatt.h:262
BLE_GATT_TYPE type
Definition: ble_gatt.h:263
uint8_t num
Definition: ble_gatt.h:264
struct ble_gatt_char_s * chars[BLE_MAX_CHARACTERISTICS]
Definition: ble_gatt.h:265
uint16_t handle
Definition: ble_gatt.h:261
Bluetooth LE GATT context.
Definition: ble_gatt.h:273
struct ble_gatt_central_ops_s * ble_gatt_central_ops
Definition: ble_gatt.h:279
struct ble_state_s * ble_state
Definition: ble_gatt.h:274
struct ble_gatt_service_s services[BLE_MAX_SERVICES]
Definition: ble_gatt.h:277
struct ble_hal_gatt_ops_s * ble_hal_gatt_ops
Definition: ble_gatt.h:275
uint8_t num
Definition: ble_gatt.h:276
GATTC characteristic structure.
Definition: ble_gatt.h:297
BLE_CHAR_PROP char_prope
Definition: ble_gatt.h:298
BLE_UUID char_valuuid
Definition: ble_gatt.h:301
uint16_t char_declhandle
Definition: ble_gatt.h:300
uint16_t char_valhandle
Definition: ble_gatt.h:299
GATTC discovered characteristic data structure.
Definition: ble_gatt.h:309
uint16_t cpfd_handle
Definition: ble_gatt.h:328
uint16_t cccd_handle
Definition: ble_gatt.h:320
uint16_t cudd_handle
Definition: ble_gatt.h:316
uint16_t cepd_handle
Definition: ble_gatt.h:312
struct ble_gattc_char_s characteristic
Definition: ble_gatt.h:336
uint16_t cafd_handle
Definition: ble_gatt.h:332
uint16_t sccd_handle
Definition: ble_gatt.h:324
GATTC discovered service data structure.
Definition: ble_gatt.h:344
BLE_UUID srv_uuid
Definition: ble_gatt.h:348
struct ble_gattc_db_disc_char_s characteristics[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV]
Definition: ble_gatt.h:347
struct ble_gattc_handle_range_s srv_handle_range
Definition: ble_gatt.h:346
uint8_t char_count
Definition: ble_gatt.h:345
GATTC discovered attribute database data structure.
Definition: ble_gatt.h:356
uint16_t conn_handle
Definition: ble_gatt.h:358
struct ble_gattc_db_disc_srv_s services[BLE_DB_DISCOVERY_MAX_SRV]
Definition: ble_gatt.h:359
uint8_t srv_count
Definition: ble_gatt.h:357
GATTC handle range structure.
Definition: ble_gatt.h:287
uint16_t start_handle
Definition: ble_gatt.h:288
uint16_t end_handle
Definition: ble_gatt.h:289
Bluetooth LE GATT HAL.
Definition: bt_if.h:222
Bluetooth LE context.
Definition: bt_common.h:164