dragoon  4383
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ble_gattc.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_GATTC_H__
46 #define BLE_GATTC_H__
47 
48 #include "ble_gatt.h"
49 #include "ble_types.h"
50 #include "ble_ranges.h"
51 #include "nrf_svc.h"
52 #include "nrf_error.h"
53 #include "nrf.h"
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
64 {
76 };
77 
82 {
96 };
97 
105 #define BLE_ERROR_GATTC_PROC_NOT_PERMITTED (NRF_GATTC_ERR_BASE + 0x000)
110 #define BLE_GATTC_ATTR_INFO_FORMAT_16BIT 1
111 #define BLE_GATTC_ATTR_INFO_FORMAT_128BIT 2
116 #define BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT 1
127 typedef struct
128 {
129  uint8_t write_cmd_tx_queue_size;
132 
134 typedef struct
135 {
136  uint16_t start_handle;
137  uint16_t end_handle;
139 
140 
142 typedef struct
143 {
147 
148 
150 typedef struct
151 {
152  uint16_t handle;
155 
156 
158 typedef struct
159 {
162  uint8_t char_ext_props : 1;
163  uint16_t handle_decl;
164  uint16_t handle_value;
166 
167 
169 typedef struct
170 {
171  uint16_t handle;
174 
175 
177 typedef struct
178 {
179  uint8_t write_op;
180  uint8_t flags;
181  uint16_t handle;
182  uint16_t offset;
183  uint16_t len;
184  uint8_t const *p_value;
186 
188 typedef struct
189 {
190  uint16_t handle;
193 
195 typedef struct
196 {
197  uint16_t handle;
200 
202 typedef struct
203 {
204  uint16_t count;
205  ble_gattc_service_t services[1];
208 
210 typedef struct
211 {
212  uint16_t count;
213  ble_gattc_include_t includes[1];
216 
218 typedef struct
219 {
220  uint16_t count;
221  ble_gattc_char_t chars[1];
224 
226 typedef struct
227 {
228  uint16_t count;
229  ble_gattc_desc_t descs[1];
232 
234 typedef struct
235 {
236  uint16_t count;
237  uint8_t format;
238  union {
239  ble_gattc_attr_info16_t attr_info16[1];
242  ble_gattc_attr_info128_t attr_info128[1];
245  } info;
247 
249 typedef struct
250 {
251  uint16_t handle;
252  uint8_t *p_value;
254 
256 typedef struct
257 {
258  uint16_t count;
259  uint16_t value_len;
260  uint8_t handle_value[1];
264 
266 typedef struct
267 {
268  uint16_t handle;
269  uint16_t offset;
270  uint16_t len;
271  uint8_t data[1];
274 
276 typedef struct
277 {
278  uint16_t len;
279  uint8_t values[1];
282 
284 typedef struct
285 {
286  uint16_t handle;
287  uint8_t write_op;
288  uint16_t offset;
289  uint16_t len;
290  uint8_t data[1];
293 
295 typedef struct
296 {
297  uint16_t handle;
298  uint8_t type;
299  uint16_t len;
300  uint8_t data[1];
303 
305 typedef struct
306 {
307  uint16_t server_rx_mtu;
309 
311 typedef struct
312 {
313  uint8_t src;
315 
317 typedef struct
318 {
319  uint8_t count;
321 
323 typedef struct
324 {
325  uint16_t conn_handle;
326  uint16_t gatt_status;
327  uint16_t error_handle;
328  union
329  {
343  } params;
376 SVCALL(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER, uint32_t, sd_ble_gattc_primary_services_discover(uint16_t conn_handle, uint16_t start_handle, ble_uuid_t const *p_srvc_uuid));
377 
378 
402 SVCALL(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, uint32_t, sd_ble_gattc_relationships_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
403 
404 
430 SVCALL(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, uint32_t, sd_ble_gattc_characteristics_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
431 
432 
455 SVCALL(SD_BLE_GATTC_DESCRIPTORS_DISCOVER, uint32_t, sd_ble_gattc_descriptors_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
456 
457 
481 SVCALL(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, uint32_t, sd_ble_gattc_char_value_by_uuid_read(uint16_t conn_handle, ble_uuid_t const *p_uuid, ble_gattc_handle_range_t const *p_handle_range));
482 
483 
507 SVCALL(SD_BLE_GATTC_READ, uint32_t, sd_ble_gattc_read(uint16_t conn_handle, uint16_t handle, uint16_t offset));
508 
509 
532 SVCALL(SD_BLE_GATTC_CHAR_VALUES_READ, uint32_t, sd_ble_gattc_char_values_read(uint16_t conn_handle, uint16_t const *p_handles, uint16_t handle_count));
533 
534 
578 SVCALL(SD_BLE_GATTC_WRITE, uint32_t, sd_ble_gattc_write(uint16_t conn_handle, ble_gattc_write_params_t const *p_write_params));
579 
580 
595 SVCALL(SD_BLE_GATTC_HV_CONFIRM, uint32_t, sd_ble_gattc_hv_confirm(uint16_t conn_handle, uint16_t handle));
596 
612 SVCALL(SD_BLE_GATTC_ATTR_INFO_DISCOVER, uint32_t, sd_ble_gattc_attr_info_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * p_handle_range));
613 
644 SVCALL(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST, uint32_t, sd_ble_gattc_exchange_mtu_request(uint16_t conn_handle, uint16_t client_rx_mtu));
645 
670 
673 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
674 
676 {
677  uint32_t value_len = p_gattc_evt->params.char_val_by_uuid_read_rsp.value_len;
678  uint8_t *p_first = p_gattc_evt->params.char_val_by_uuid_read_rsp.handle_value;
679  uint8_t *p_next = p_iter->p_value ? p_iter->p_value + value_len : p_first;
680 
681  if ((p_next - p_first) / (sizeof(uint16_t) + value_len) < p_gattc_evt->params.char_val_by_uuid_read_rsp.count)
682  {
683  p_iter->handle = (uint16_t)p_next[1] << 8 | p_next[0];
684  p_iter->p_value = p_next + sizeof(uint16_t);
685  return NRF_SUCCESS;
686  }
687  else
688  {
689  return NRF_ERROR_NOT_FOUND;
690  }
691 }
692 
693 #endif /* SUPPRESS_INLINE_IMPLEMENTATION */
694 
695 #ifdef __cplusplus
696 }
697 #endif
698 #endif /* BLE_GATTC_H__ */
699