Developer World
Spresense SDK Library v1.4.2-3df2e9d
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
63 
69 #define BLE_MAX_CHARACTERISTICS 1
70 
76 #define BLE_MAX_CHAR_SIZE 20
77 
83 #define BLE_GATT_INVALID_SERVICE_HANDLE UINT16_MAX
84 
90 #define BLE_DB_DISCOVERY_MAX_SRV 3
91 
97 #define BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV 4
98 
100 /****************************************************************************
101  * Public Types prototype
102  ****************************************************************************/
103 
104 struct ble_gatt_char_s;
105 
106 /****************************************************************************
107  * Public Types
108  ****************************************************************************/
109 
114 typedef enum
115 {
120 
125 typedef enum
126 {
129 } BLE_GATT_TYPE;
130 
136 typedef enum{
143 } BLE_SEC_MODE;
144 
149 typedef struct
150 {
151  uint8_t uuid128[BT_UUID128_LEN];
152 } BLE_UUID128;
153 
158 typedef struct
159 {
161  uint16_t uuidAlias;
163 
168 typedef struct
169 {
171  union
172  {
175  } value;
176 } BLE_UUID;
177 
182 typedef struct
183 {
186 } BLE_ATTR_PERM;
187 
192 typedef struct
193 {
195  uint8_t *data;
196  uint16_t length;
198 
204 typedef struct
205 {
206  uint8_t broadcast :1;
207  uint8_t read :1;
208  uint8_t writeWoResp :1;
209  uint8_t write :1;
210  uint8_t notify :1;
211  uint8_t indicate :1;
212  uint8_t authSignedWr :1;
213  uint8_t reserve :1;
214 } BLE_CHAR_PROP;
215 
223 {
224  void (*write)(struct ble_gatt_char_s *ble_gatt_char);
225  void (*read)(struct ble_gatt_char_s *ble_gatt_char);
226  void (*notify)(struct ble_gatt_char_s *ble_gatt_char, bool enable);
227 };
228 
234 {
235  uint16_t handle;
239  uint8_t status;
240  union
241  {
244  };
245 };
246 
252 {
253  uint16_t handle;
256  uint8_t num;
257  struct ble_gatt_char_s *chars[BLE_MAX_CHARACTERISTICS];
258 };
259 
265 {
268  uint8_t num;
269  struct ble_gatt_service_s services[BLE_MAX_SERVICES];
270  /* TODO: temporary, needs to consider the design */
272 };
273 
279 {
280  uint16_t start_handle;
281  uint16_t end_handle;
282 };
283 
289 {
291  uint16_t char_valhandle;
292  uint16_t char_declhandle;
294 };
295 
301 {
302  uint16_t cccd_handle;
303  struct ble_gattc_char_s characteristic;
304 };
305 
311 {
312  uint8_t char_count;
313  struct ble_gattc_handle_range_s srv_handle_range;
314  struct ble_gattc_db_disc_char_s characteristics[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV];
316 };
317 
323 {
324  uint8_t srv_count;
325  uint16_t conn_handle;
326  struct ble_gattc_db_disc_srv_s services[BLE_DB_DISCOVERY_MAX_SRV];
327 };
328 
334 {
335  uint8_t srv_count;
336  uint16_t end_handle;
337 };
338 
345 {
346  uint8_t group_id;
347  uint8_t event_id;
348  uint8_t result;
349  uint16_t conn_handle;
351  union{
352  uint32_t reason;
353  struct ble_gattc_db_discovery_s db_discovery;
354  } params;
355 };
356 
364 {
365  void (*write)(struct ble_gatt_char_s *ble_gatt_char);
366  void (*read)(struct ble_gatt_char_s *ble_gatt_char);
367  void (*notify)(struct ble_gatt_char_s *ble_gatt_char);
368  void (*database_discovery)(struct ble_gatt_event_db_discovery_t *db_disc);
369 };
370 
371 
372 
373 /****************************************************************************
374  * Private Data
375  ****************************************************************************/
376 
377 /****************************************************************************
378  * Public Function Prototypes
379  ****************************************************************************/
380 
387 bool ble_gatt_is_supported(void);
388 
398 int ble_create_service(struct ble_gatt_service_s **service);
399 
409 int ble_register_servce(struct ble_gatt_service_s *service);
410 
421 int ble_add_characteristic(struct ble_gatt_service_s *service, struct ble_gatt_char_s *charc);
422 
434 int ble_characteristic_notify(struct ble_gatt_char_s *charc, uint8_t *data, int len);
435 
445 int ble_characteristic_read(struct ble_gatt_char_s *charc);
446 
458 int ble_characteristic_write(struct ble_gatt_char_s *charc, uint8_t *data, int len);
459 
469 int ble_start_db_discovery(uint16_t conn_handle);
470 
481 int ble_continue_db_discovery(uint16_t start_handle, uint16_t conn_handle);
482 
483 #endif /* __MODULES_INCLUDE_BLUETOOTH_BLE_GATT_H */
uint16_t handle
Definition: ble_gatt.h:253
Definition: ble_gatt.h:128
BLE UUID structure.
Definition: ble_gatt.h:168
uint16_t handle
Definition: ble_gatt.h:235
void(* write)(struct ble_gatt_char_s *ble_gatt_char)
Definition: ble_gatt.h:224
void(* read)(struct ble_gatt_char_s *ble_gatt_char)
Definition: ble_gatt.h:225
uint8_t indicate
Definition: ble_gatt.h:211
uint16_t end_handle
Definition: ble_gatt.h:281
uint16_t char_declhandle
Definition: ble_gatt.h:292
BLE_UUID uuid
Definition: ble_gatt.h:254
struct ble_gatt_peripheral_ops_s * ble_gatt_peripheral_ops
Definition: ble_gatt.h:243
void(* notify)(struct ble_gatt_char_s *ble_gatt_char, bool enable)
Definition: ble_gatt.h:226
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.
Definition: ble_gatt.h:333
int ble_characteristic_notify(struct ble_gatt_char_s *charc, uint8_t *data, int len)
BLE Notify Characteristic value Notify characteristic value to Central (For Peripheral role) ...
uint16_t cccd_handle
Definition: ble_gatt.h:302
BLE_UUID srv_uuid
Definition: ble_gatt.h:315
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...
characteristic value attribute structure
Definition: ble_gatt.h:192
BLE_CHAR_PROP property
Definition: ble_gatt.h:238
Bluetooth LE characteristic callbacks(for Peripheral)
Definition: ble_gatt.h:222
Bluetooth LE GATT characteristic context.
Definition: ble_gatt.h:233
struct ble_gatt_central_ops_s * ble_gatt_central_ops
Definition: ble_gatt.h:271
BLE_SEC_MODE readPerm
Definition: ble_gatt.h:184
uint8_t char_count
Definition: ble_gatt.h:312
uint16_t length
Definition: ble_gatt.h:196
Bluetooth generic API.
uint8_t srv_count
Definition: ble_gatt.h:335
Attribute permission structure.
Definition: ble_gatt.h:182
bool ble_gatt_is_supported(void)
Get Bluetooth Low Ennergy GATT support or not support.
Definition: ble_gatt.h:117
Bluetooth LE context.
Definition: bt_common.h:101
Definition: ble_gatt.h:138
int ble_create_service(struct ble_gatt_service_s **service)
BLE Create GATT Service Create GATT Service instance and return instance pointer via *service...
BLE_SEC_MODE
Definition: ble_gatt.h:136
uint16_t char_valhandle
Definition: ble_gatt.h:291
BLE_GATT_TYPE type
Definition: ble_gatt.h:255
BLE_SEC_MODE writePerm
Definition: ble_gatt.h:185
uint8_t * data
Definition: ble_gatt.h:195
uint8_t num
Definition: ble_gatt.h:256
struct ble_hal_gatt_ops_s * ble_hal_gatt_ops
Definition: ble_gatt.h:267
Characteristic standard properties.
Definition: ble_gatt.h:204
BLE_GATT_UUID_TYPE type
Definition: ble_gatt.h:170
BLE_UUID uuid
Definition: ble_gatt.h:236
uint32_t reason
Definition: ble_gatt.h:352
UUID base + alias structure.
Definition: ble_gatt.h:158
Bluetooth LE GATT HAL.
Definition: bt_if.h:179
int ble_characteristic_write(struct ble_gatt_char_s *charc, uint8_t *data, int len)
BLE Write Characteristic value Send write characteristic request to peripheral (For Central role) ...
GATTC handle range structure.
Definition: ble_gatt.h:278
GATTC attribute database discovery event structure.
Definition: ble_gatt.h:344
128-bit UUID structure for BLE
Definition: ble_gatt.h:149
uint8_t event_id
Definition: ble_gatt.h:347
BLE security mode security level.
Definition: ble_gatt.h:137
Bluetooth LE characteristic callbacks(for Central)
Definition: ble_gatt.h:363
int ble_register_servce(struct ble_gatt_service_s *service)
BLE Register GATT Service Register GATT Service to HAL.
BLE_UUID_ALIAS alias
Definition: ble_gatt.h:174
GATTC discovered service data structure.
Definition: ble_gatt.h:310
struct ble_gatt_central_ops_s * ble_gatt_central_ops
Definition: ble_gatt.h:242
Definition: ble_gatt.h:140
uint8_t notify
Definition: ble_gatt.h:210
GATTC discovered attribute database data structure.
Definition: ble_gatt.h:322
uint8_t num
Definition: ble_gatt.h:268
BLE_UUID char_valuuid
Definition: ble_gatt.h:293
GATTC characteristic structure.
Definition: ble_gatt.h:288
GATTC discovered characteristic data structure.
Definition: ble_gatt.h:300
uint16_t uuidAlias
Definition: ble_gatt.h:161
int64_t value
Definition: video.h:81
BLE_ATTR_PERM attrPerm
Definition: ble_gatt.h:194
uint8_t authSignedWr
Definition: ble_gatt.h:212
uint8_t group_id
Definition: ble_gatt.h:346
Definition: ble_gatt.h:141
int ble_characteristic_read(struct ble_gatt_char_s *charc)
BLE Read Characteristic value Send read characteristic request to peripheral (For Central role) ...
uint8_t status
Definition: ble_gatt.h:239
uint8_t read
Definition: ble_gatt.h:207
Bluetooth LE GATT service context.
Definition: ble_gatt.h:251
Definition: ble_gatt.h:118
uint16_t conn_handle
Definition: ble_gatt.h:349
uint16_t conn_handle
Definition: ble_gatt.h:325
Definition: ble_gatt.h:142
BLE_UUID128 uuidBase
Definition: ble_gatt.h:160
BLE_CHAR_VALUE value
Definition: ble_gatt.h:237
uint8_t broadcast
Definition: ble_gatt.h:206
uint8_t srv_count
Definition: ble_gatt.h:324
Bluetooth LE GATT context.
Definition: ble_gatt.h:264
BLE_UUID128 uuid128
Definition: ble_gatt.h:173
Definition: ble_gatt.h:116
BLE_GATT_TYPE
GATTS service type.
Definition: ble_gatt.h:125
uint8_t write
Definition: ble_gatt.h:209
struct ble_state_s * ble_state
Definition: ble_gatt.h:266
uint16_t end_handle
Definition: ble_gatt.h:336
BLE_GATT_UUID_TYPE
GATTS UUID type.
Definition: ble_gatt.h:114
Bluetooth common header for SDK on Spresense.
Definition: ble_gatt.h:139
Definition: ble_gatt.h:127
uint8_t writeWoResp
Definition: ble_gatt.h:208
uint8_t result
Definition: ble_gatt.h:348
uint16_t start_handle
Definition: ble_gatt.h:280
uint8_t reserve
Definition: ble_gatt.h:213
int ble_start_db_discovery(uint16_t conn_handle)
BLE start database discovery Send database discovery request to peripheral (For Central role) ...
BLE_CHAR_PROP char_prope
Definition: ble_gatt.h:290