ble_gatts.h
Go to the documentation of this file.
1
56 #ifndef __BLE_GATTS_H__
57 #define __BLE_GATTS_H__
58
59 #include "ble_error.h"
60 #include "ble_att.h"
61 #include "ble_gatt.h"
62
63 #include <stdint.h>
64
70 #define MAX_INC_SRVC_NUM (5)
75 #define BROADCAST (0x01)
76 #define READ (0x02)
77 #define WRITE_CMD (0x04)
78 #define WRITE_REQ (0x08)
79 #define NOTIFY (0x10)
80 #define INDICATE (0x20)
81 #define WRITE_SIGNED (0x40)
82 #define EXT_PROP (0x80)
87 #define READ_POS (0x00)
88 #define WRITE_POS (0x02)
89 #define INDICATE_POS (0x04)
90 #define NOTIFY_POS (0x06)
96 #define NOAUTH (0x00)
98 #define UNAUTH (0x01)
100 #define AUTH (0x02)
102 #define SEC_CON (0x03)
108 #define SEC_LEVEL_MASK (0x03)
114 #define UUID_TYPE_16 (0x00)
115 #define UUID_TYPE_128 (0x02)
135 #define SRVC_SECONDARY_SET (0x80)
136 #define SRVC_UUID_TYPE_SET(uuid_len) ((uuid_len) << 5)
137 #define SRVC_DISABLE (0x10)
138 #define SRVC_PERM(sec_level) (((sec_level) & SEC_LEVEL_MASK) << 2)
139 #define SRVC_ENCRP_KEY_SIZE_16 (0x02)
140 #define SRVC_MULTI_ENABLE (0x01)
167 #define READ_PERM_UNSEC (READ << 8)
168 #define READ_PERM(sec_level) (READ << 8 | (((sec_level) & SEC_LEVEL_MASK) << READ_POS))
170 #define WRITE_REQ_PERM_UNSEC (WRITE_REQ << 8)
171 #define WRITE_REQ_PERM(sec_level) (WRITE_REQ << 8 | (((sec_level) & SEC_LEVEL_MASK) << WRITE_POS))
173 #define WRITE_CMD_PERM_UNSEC (WRITE_CMD << 8)
174 #define WRITE_CMD_PERM(sec_level) (WRITE_CMD << 8 | (((sec_level) & SEC_LEVEL_MASK) << WRITE_POS))
176 #define WRITE_SIGNED_PERM_UNSEC (WRITE_SIGNED << 8)
177 #define WRITE_SIGNED_PERM(sec_level) (WRITE_SIGNED << 8 | (((sec_level) & SEC_LEVEL_MASK) << WRITE_POS))
179 #define INDICATE_PERM_UNSEC (INDICATE << 8)
180 #define INDICATE_PERM(sec_level) (INDICATE << 8 | (((sec_level) & SEC_LEVEL_MASK) << INDICATE_POS))
182 #define NOTIFY_PERM_UNSEC (NOTIFY << 8)
183 #define NOTIFY_PERM(sec_level) (NOTIFY << 8 | (((sec_level) & SEC_LEVEL_MASK) << NOTIFY_POS))
185 #define BROADCAST_ENABLE (BROADCAST << 8)
186 #define EXT_PROP_ENABLE (EXT_PROP << 8)
204 #define ATT_VAL_LOC_USER (1 << 15)
205 #define ATT_VAL_LOC_STACK (0 << 15)
206 #define ATT_UUID_TYPE_SET(uuid_len) ((uuid_len) << 13)
207 #define ATT_ENC_KEY_SIZE_16 (0x1000)
219 typedef enum
220 {
221 SERVICE_TABLE_TYPE_16 = 0x00,
222 SERVICE_TABLE_TYPE_128,
223 } gatts_service_type_t;
224
225
235 typedef struct
236 {
237 uint16_t uuid;
238 uint16_t perm;
245 uint16_t ext_perm;
252 uint16_t max_size;
258 } attm_desc_t;
259
263 typedef struct
264 {
265 uint8_t uuid[16];
266 uint16_t perm;
273 uint16_t ext_perm;
280 uint16_t max_size;
286 } attm_desc_128_t;
287
291 typedef struct
292 {
293
294 uint16_t *shdl;
297 const uint8_t *uuid;
298 uint8_t *attr_tab_cfg;
302 uint8_t max_nb_attr;
303 union attribute_table
304 {
305 const attm_desc_t *attr_tab_16;
306 const attm_desc_128_t *attr_tab_128;
307 } attr_tab;
308 uint16_t *inc_srvc_handle[MAX_INC_SRVC_NUM];
309 uint16_t inc_srvc_num;
310 uint8_t srvc_perm;
311 gatts_service_type_t attr_tab_type;
312 } gatts_create_db_t;
313
317 typedef struct
318 {
319 uint16_t handle;
320 uint16_t length;
321 uint8_t status;
322 uint8_t *value;
323 } gatts_read_cfm_t;
324
328 typedef struct
329 {
330 uint16_t handle;
331 uint8_t status;
332 } gatts_write_cfm_t;
333
337 typedef struct
338 {
339 uint16_t handle;
340 uint16_t length;
341 uint8_t status;
342 } gatts_prep_write_cfm_t;
343
344
348 typedef struct
349 {
350 gatt_evt_type_t type;
351 uint16_t handle;
352 uint16_t length;
353 uint8_t *value;
354 } gatts_noti_ind_t;
355
375 uint16_t ble_gatts_srvc_db_create(gatts_create_db_t *p_param);
376
394 uint16_t ble_gatts_value_set(uint16_t handle, uint16_t length, uint16_t offset, const uint8_t* p_value);
395
412 uint16_t ble_gatts_value_get(uint16_t handle, uint16_t* p_length, uint8_t* p_value);
413
429 uint16_t ble_gatts_attr_permission_set(uint16_t handle, uint16_t perm, uint16_t ext_perm);
430
444 uint16_t ble_gatts_attr_permission_get(uint16_t handle, uint16_t *p_perm, uint16_t *p_ext_perm);
445
463 uint16_t ble_gatts_read_cfm(uint8_t conn_idx, const gatts_read_cfm_t *p_param);
464
482 uint16_t ble_gatts_write_cfm(uint8_t conn_idx, const gatts_write_cfm_t *p_param);
483
501 uint16_t ble_gatts_prepare_write_cfm(uint8_t conn_idx, const gatts_prep_write_cfm_t *p_param);
502
521 uint16_t ble_gatts_noti_ind(uint8_t conn_idx, const gatts_noti_ind_t *p_param);
522
530 void ble_gatts_service_changed(void);
533 #endif // BLE_SDK_GATTS_H_
534
gatts_service_type_t
gatts_service_type_t
Service table type.
Definition: ble_gatts.h:220
gatts_read_cfm_t::length
uint16_t length
Definition: ble_gatts.h:320
attm_desc_t
Service(16-bit UUID) description.
Definition: ble_gatts.h:236
SERVICE_TABLE_TYPE_16
@ SERVICE_TABLE_TYPE_16
Definition: ble_gatts.h:221
SERVICE_TABLE_TYPE_128
@ SERVICE_TABLE_TYPE_128
Definition: ble_gatts.h:222
gatts_noti_ind_t::length
uint16_t length
Definition: ble_gatts.h:352
ble_gatts_read_cfm
uint16_t ble_gatts_read_cfm(uint8_t conn_idx, const gatts_read_cfm_t *p_param)
Respond to an attribute read request. It is used in profile read callback function gatts_prf_cbs_t::a...
ble_gatts_prepare_write_cfm
uint16_t ble_gatts_prepare_write_cfm(uint8_t conn_idx, const gatts_prep_write_cfm_t *p_param)
Respond to an attribute prepare write request. It is used in profile prepare write callback function ...
gatts_create_db_t::srvc_perm
uint8_t srvc_perm
Definition: ble_gatts.h:310
gatts_noti_ind_t::value
uint8_t * value
Definition: ble_gatts.h:353
attm_desc_128_t
Service(128 bits UUID) description.
Definition: ble_gatts.h:264
ble_gatt.h
BLE GATT.
ble_gatts_write_cfm
uint16_t ble_gatts_write_cfm(uint8_t conn_idx, const gatts_write_cfm_t *p_param)
Respond to an attribute write request. It is used in profile write callback function gatts_prf_cbs_t:...
gatts_noti_ind_t
GATT sending Notification or Indication event param description.
Definition: ble_gatts.h:349
gatt_evt_type_t
gatt_evt_type_t
GATT common events.
Definition: ble_gatt.h:67
gatts_read_cfm_t::value
uint8_t * value
Definition: ble_gatts.h:322
gatts_create_db_t::attr_tab_type
gatts_service_type_t attr_tab_type
Definition: ble_gatts.h:311
ble_gatts_srvc_db_create
uint16_t ble_gatts_srvc_db_create(gatts_create_db_t *p_param)
Register a service's attribute list.
gatts_create_db_t::attribute_table::attr_tab_16
const attm_desc_t * attr_tab_16
Definition: ble_gatts.h:305
ble_gatts_attr_permission_set
uint16_t ble_gatts_attr_permission_set(uint16_t handle, uint16_t perm, uint16_t ext_perm)
Update attribute permission.
gatts_write_cfm_t
GATT write attribute result description.
Definition: ble_gatts.h:329
gatts_create_db_t::attr_tab_cfg
uint8_t * attr_tab_cfg
Definition: ble_gatts.h:298
ble_gatts_value_set
uint16_t ble_gatts_value_set(uint16_t handle, uint16_t length, uint16_t offset, const uint8_t *p_value)
Update attribute value only if the attribute value is saved in the BLE Stack space.
attm_desc_128_t::max_size
uint16_t max_size
Definition: ble_gatts.h:280
gatts_create_db_t::inc_srvc_num
uint16_t inc_srvc_num
Definition: ble_gatts.h:309
gatts_prep_write_cfm_t::length
uint16_t length
Definition: ble_gatts.h:340
ble_error.h
File that contains error codes.
gatts_create_db_t::attribute_table
Definition: ble_gatts.h:304
gatts_prep_write_cfm_t::status
uint8_t status
Definition: ble_gatts.h:341
attm_desc_128_t::perm
uint16_t perm
Definition: ble_gatts.h:266
gatts_read_cfm_t::handle
uint16_t handle
Definition: ble_gatts.h:319
attm_desc_t::ext_perm
uint16_t ext_perm
Definition: ble_gatts.h:245
attm_desc_t::uuid
uint16_t uuid
Definition: ble_gatts.h:237
gatts_read_cfm_t::status
uint8_t status
Definition: ble_gatts.h:321
MAX_INC_SRVC_NUM
#define MAX_INC_SRVC_NUM
Definition: ble_gatts.h:70
gatts_prep_write_cfm_t
GATT prepare write result description.
Definition: ble_gatts.h:338
gatts_create_db_t::shdl
uint16_t * shdl
Definition: ble_gatts.h:294
gatts_write_cfm_t::status
uint8_t status
Definition: ble_gatts.h:331
gatts_create_db_t::uuid
const uint8_t * uuid
Definition: ble_gatts.h:297
gatts_noti_ind_t::type
gatt_evt_type_t type
Definition: ble_gatts.h:350
gatts_prep_write_cfm_t::handle
uint16_t handle
Definition: ble_gatts.h:339
ble_gatts_attr_permission_get
uint16_t ble_gatts_attr_permission_get(uint16_t handle, uint16_t *p_perm, uint16_t *p_ext_perm)
Retrieve attribute permission.
gatts_create_db_t::max_nb_attr
uint8_t max_nb_attr
Definition: ble_gatts.h:302
gatts_write_cfm_t::handle
uint16_t handle
Definition: ble_gatts.h:330
ble_gatts_noti_ind
uint16_t ble_gatts_noti_ind(uint8_t conn_idx, const gatts_noti_ind_t *p_param)
Send out a notification or an indication. The execution status of sending notification or indication ...
gatts_create_db_t
Parameter of Added service description.
Definition: ble_gatts.h:292
ble_att.h
Attribute Protocol.
ble_gatts_value_get
uint16_t ble_gatts_value_get(uint16_t handle, uint16_t *p_length, uint8_t *p_value)
Retrieve attribute value only if the attribute value is saved in the BLE Stack space.
ble_gatts_service_changed
void ble_gatts_service_changed(void)
When service on local device finishes upgrade, call this API to send service upgrade to stack....
gatts_noti_ind_t::handle
uint16_t handle
Definition: ble_gatts.h:351
gatts_create_db_t::attribute_table::attr_tab_128
const attm_desc_128_t * attr_tab_128
Definition: ble_gatts.h:306
attm_desc_t::max_size
uint16_t max_size
Definition: ble_gatts.h:252
attm_desc_t::perm
uint16_t perm
Definition: ble_gatts.h:238
gatts_read_cfm_t
GATT read attribute result description.
Definition: ble_gatts.h:318
attm_desc_128_t::ext_perm
uint16_t ext_perm
Definition: ble_gatts.h:273