dragoon  4383
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ble_gatts.h
1 /*
2  * Copyright (c) 2011 - 2017, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form, except as embedded into a Nordic
12  * Semiconductor ASA integrated circuit in a product or a software update for
13  * such product, must reproduce the above copyright notice, this list of
14  * conditions and the following disclaimer in the documentation and/or other
15  * materials provided with the distribution.
16  *
17  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * 4. This software, with or without modification, must only be used with a
22  * Nordic Semiconductor ASA integrated circuit.
23  *
24  * 5. Any software provided in binary form under this license must not be reverse
25  * engineered, decompiled, modified and/or disassembled.
26  *
27  * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
28  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29  * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
30  * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
31  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */
38 
45 #ifndef BLE_GATTS_H__
46 #define BLE_GATTS_H__
47 
48 #include "ble_types.h"
49 #include "ble_ranges.h"
50 #include "ble_l2cap.h"
51 #include "ble_gap.h"
52 #include "ble_gatt.h"
53 #include "nrf_svc.h"
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
66 {
81 };
82 
87 {
96 };
97 
103 {
106 };
107 
115 #define BLE_ERROR_GATTS_INVALID_ATTR_TYPE (NRF_GATTS_ERR_BASE + 0x000)
116 #define BLE_ERROR_GATTS_SYS_ATTR_MISSING (NRF_GATTS_ERR_BASE + 0x001)
121 #define BLE_GATTS_FIX_ATTR_LEN_MAX (510)
122 #define BLE_GATTS_VAR_ATTR_LEN_MAX (512)
127 #define BLE_GATTS_SRVC_TYPE_INVALID 0x00
128 #define BLE_GATTS_SRVC_TYPE_PRIMARY 0x01
129 #define BLE_GATTS_SRVC_TYPE_SECONDARY 0x02
135 #define BLE_GATTS_ATTR_TYPE_INVALID 0x00
136 #define BLE_GATTS_ATTR_TYPE_PRIM_SRVC_DECL 0x01
137 #define BLE_GATTS_ATTR_TYPE_SEC_SRVC_DECL 0x02
138 #define BLE_GATTS_ATTR_TYPE_INC_DECL 0x03
139 #define BLE_GATTS_ATTR_TYPE_CHAR_DECL 0x04
140 #define BLE_GATTS_ATTR_TYPE_CHAR_VAL 0x05
141 #define BLE_GATTS_ATTR_TYPE_DESC 0x06
142 #define BLE_GATTS_ATTR_TYPE_OTHER 0x07
148 #define BLE_GATTS_OP_INVALID 0x00
149 #define BLE_GATTS_OP_WRITE_REQ 0x01
150 #define BLE_GATTS_OP_WRITE_CMD 0x02
151 #define BLE_GATTS_OP_SIGN_WRITE_CMD 0x03
152 #define BLE_GATTS_OP_PREP_WRITE_REQ 0x04
153 #define BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL 0x05
154 #define BLE_GATTS_OP_EXEC_WRITE_REQ_NOW 0x06
159 #define BLE_GATTS_VLOC_INVALID 0x00
160 #define BLE_GATTS_VLOC_STACK 0x01
161 #define BLE_GATTS_VLOC_USER 0x02
167 #define BLE_GATTS_AUTHORIZE_TYPE_INVALID 0x00
168 #define BLE_GATTS_AUTHORIZE_TYPE_READ 0x01
169 #define BLE_GATTS_AUTHORIZE_TYPE_WRITE 0x02
174 #define BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS (1 << 0)
175 #define BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS (1 << 1)
181 #define BLE_GATTS_SERVICE_CHANGED_DEFAULT (1)
187 #define BLE_GATTS_ATTR_TAB_SIZE_MIN (248)
188 #define BLE_GATTS_ATTR_TAB_SIZE_DEFAULT (1408)
194 #define BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT 1
205 typedef struct
206 {
207  uint8_t hvn_tx_queue_size;
210 
212 typedef struct
213 {
214  ble_gap_conn_sec_mode_t read_perm;
216  uint8_t vlen :1;
217  uint8_t vloc :2;
218  uint8_t rd_auth :1;
219  uint8_t wr_auth :1;
221 
222 
224 typedef struct
225 {
226  ble_uuid_t const *p_uuid;
227  ble_gatts_attr_md_t const *p_attr_md;
228  uint16_t init_len;
229  uint16_t init_offs;
230  uint16_t max_len;
231  uint8_t *p_value;
235 
237 typedef struct
238 {
239  uint16_t len;
240  uint16_t offset;
241  uint8_t *p_value;
245 
246 
248 typedef struct
249 {
250  uint8_t format;
251  int8_t exponent;
252  uint16_t unit;
253  uint8_t name_space;
254  uint16_t desc;
256 
257 
259 typedef struct
260 {
261  ble_gatt_char_props_t char_props;
262  ble_gatt_char_ext_props_t char_ext_props;
263  uint8_t const *p_char_user_desc;
264  uint16_t char_user_desc_max_size;
265  uint16_t char_user_desc_size;
266  ble_gatts_char_pf_t const *p_char_pf;
267  ble_gatts_attr_md_t const *p_user_desc_md;
268  ble_gatts_attr_md_t const *p_cccd_md;
269  ble_gatts_attr_md_t const *p_sccd_md;
271 
272 
274 typedef struct
275 {
276  uint16_t value_handle;
277  uint16_t user_desc_handle;
278  uint16_t cccd_handle;
279  uint16_t sccd_handle;
281 
282 
284 typedef struct
285 {
286  uint16_t handle;
287  uint8_t type;
288  uint16_t offset;
289  uint16_t *p_len;
290  uint8_t const *p_data;
292 
294 typedef struct
295 {
296  uint16_t gatt_status;
297  uint8_t update : 1;
300  uint16_t offset;
301  uint16_t len;
302  uint8_t const *p_data;
304 
306 typedef struct
307 {
308  uint8_t type;
309  union {
312  } params;
314 
316 typedef struct
317 {
318  uint8_t service_changed : 1;
320 
328 typedef struct
329 {
330  uint32_t attr_tab_size;
332 
334 typedef union
335 {
336  ble_gatts_cfg_service_changed_t service_changed;
339 
340 
342 typedef struct
343 {
344  uint16_t handle;
345  ble_uuid_t uuid;
346  uint8_t op;
347  uint8_t auth_required;
348  uint16_t offset;
349  uint16_t len;
350  uint8_t data[1];
353 
355 typedef struct
356 {
357  uint16_t handle;
358  ble_uuid_t uuid;
359  uint16_t offset;
361 
363 typedef struct
364 {
365  uint8_t type;
366  union {
367  ble_gatts_evt_read_t read;
369  } request;
371 
373 typedef struct
374 {
375  uint8_t hint;
377 
378 
380 typedef struct
381 {
382  uint16_t handle;
384 
386 typedef struct
387 {
388  uint16_t client_rx_mtu;
390 
392 typedef struct
393 {
394  uint8_t src;
396 
398 typedef struct
399 {
400  uint8_t count;
402 
404 typedef struct
405 {
406  uint16_t conn_handle;
407  union
408  {
409  ble_gatts_evt_write_t write;
416  } params;
418 
443 SVCALL(SD_BLE_GATTS_SERVICE_ADD, uint32_t, sd_ble_gatts_service_add(uint8_t type, ble_uuid_t const *p_uuid, uint16_t *p_handle));
444 
445 
469 SVCALL(SD_BLE_GATTS_INCLUDE_ADD, uint32_t, sd_ble_gatts_include_add(uint16_t service_handle, uint16_t inc_srvc_handle, uint16_t *p_include_handle));
470 
471 
498 SVCALL(SD_BLE_GATTS_CHARACTERISTIC_ADD, uint32_t, sd_ble_gatts_characteristic_add(uint16_t service_handle, ble_gatts_char_md_t const *p_char_md, ble_gatts_attr_t const *p_attr_char_value, ble_gatts_char_handles_t *p_handles));
499 
500 
521 SVCALL(SD_BLE_GATTS_DESCRIPTOR_ADD, uint32_t, sd_ble_gatts_descriptor_add(uint16_t char_handle, ble_gatts_attr_t const *p_attr, uint16_t *p_handle));
522 
544 SVCALL(SD_BLE_GATTS_VALUE_SET, uint32_t, sd_ble_gatts_value_set(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t *p_value));
545 
568 SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t *p_value));
569 
629 SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const *p_hvx_params));
630 
664 SVCALL(SD_BLE_GATTS_SERVICE_CHANGED, uint32_t, sd_ble_gatts_service_changed(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle));
665 
696 SVCALL(SD_BLE_GATTS_RW_AUTHORIZE_REPLY, uint32_t, sd_ble_gatts_rw_authorize_reply(uint16_t conn_handle, ble_gatts_rw_authorize_reply_params_t const *p_rw_authorize_reply_params));
697 
698 
740 SVCALL(SD_BLE_GATTS_SYS_ATTR_SET, uint32_t, sd_ble_gatts_sys_attr_set(uint16_t conn_handle, uint8_t const *p_sys_attr_data, uint16_t len, uint32_t flags));
741 
742 
773 SVCALL(SD_BLE_GATTS_SYS_ATTR_GET, uint32_t, sd_ble_gatts_sys_attr_get(uint16_t conn_handle, uint8_t *p_sys_attr_data, uint16_t *p_len, uint32_t flags));
774 
775 
784 
796 SVCALL(SD_BLE_GATTS_ATTR_GET, uint32_t, sd_ble_gatts_attr_get(uint16_t handle, ble_uuid_t * p_uuid, ble_gatts_attr_md_t * p_md));
797 
825 SVCALL(SD_BLE_GATTS_EXCHANGE_MTU_REPLY, uint32_t, sd_ble_gatts_exchange_mtu_reply(uint16_t conn_handle, uint16_t server_rx_mtu));
828 #ifdef __cplusplus
829 }
830 #endif
831 #endif // BLE_GATTS_H__
832