User | Revision | Line number | New contents of line |
jinu |
0:6ba9b94b8997
|
1
|
/* Copyright (c) Nordic Semiconductor ASA
|
jinu |
0:6ba9b94b8997
|
2
|
* All rights reserved.
|
jinu |
0:6ba9b94b8997
|
3
|
*
|
jinu |
0:6ba9b94b8997
|
4
|
* Redistribution and use in source and binary forms, with or without modification,
|
jinu |
0:6ba9b94b8997
|
5
|
* are permitted provided that the following conditions are met:
|
jinu |
0:6ba9b94b8997
|
6
|
*
|
jinu |
0:6ba9b94b8997
|
7
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
jinu |
0:6ba9b94b8997
|
8
|
* list of conditions and the following disclaimer.
|
jinu |
0:6ba9b94b8997
|
9
|
*
|
jinu |
0:6ba9b94b8997
|
10
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this
|
jinu |
0:6ba9b94b8997
|
11
|
* list of conditions and the following disclaimer in the documentation and/or
|
jinu |
0:6ba9b94b8997
|
12
|
* other materials provided with the distribution.
|
jinu |
0:6ba9b94b8997
|
13
|
*
|
jinu |
0:6ba9b94b8997
|
14
|
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
|
jinu |
0:6ba9b94b8997
|
15
|
* contributors to this software may be used to endorse or promote products
|
jinu |
0:6ba9b94b8997
|
16
|
* derived from this software without specific prior written permission.
|
jinu |
0:6ba9b94b8997
|
17
|
*
|
jinu |
0:6ba9b94b8997
|
18
|
* 4. This software must only be used in a processor manufactured by Nordic
|
jinu |
0:6ba9b94b8997
|
19
|
* Semiconductor ASA, or in a processor manufactured by a third party that
|
jinu |
0:6ba9b94b8997
|
20
|
* is used in combination with a processor manufactured by Nordic Semiconductor.
|
jinu |
0:6ba9b94b8997
|
21
|
*
|
jinu |
0:6ba9b94b8997
|
22
|
*
|
jinu |
0:6ba9b94b8997
|
23
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
jinu |
0:6ba9b94b8997
|
24
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
jinu |
0:6ba9b94b8997
|
25
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
jinu |
0:6ba9b94b8997
|
26
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
jinu |
0:6ba9b94b8997
|
27
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
jinu |
0:6ba9b94b8997
|
28
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
jinu |
0:6ba9b94b8997
|
29
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
jinu |
0:6ba9b94b8997
|
30
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
jinu |
0:6ba9b94b8997
|
31
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
jinu |
0:6ba9b94b8997
|
32
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
jinu |
0:6ba9b94b8997
|
33
|
*/
|
jinu |
0:6ba9b94b8997
|
34
|
/**
|
jinu |
0:6ba9b94b8997
|
35
|
@addtogroup BLE_COMMON BLE SoftDevice Common
|
jinu |
0:6ba9b94b8997
|
36
|
@{
|
jinu |
0:6ba9b94b8997
|
37
|
@defgroup ble_api Events, type definitions and API calls
|
jinu |
0:6ba9b94b8997
|
38
|
@{
|
jinu |
0:6ba9b94b8997
|
39
|
|
jinu |
0:6ba9b94b8997
|
40
|
@brief Module independent events, type definitions and API calls for the S110 SoftDevice.
|
jinu |
0:6ba9b94b8997
|
41
|
|
jinu |
0:6ba9b94b8997
|
42
|
*/
|
jinu |
0:6ba9b94b8997
|
43
|
|
jinu |
0:6ba9b94b8997
|
44
|
#ifndef BLE_H__
|
jinu |
0:6ba9b94b8997
|
45
|
#define BLE_H__
|
jinu |
0:6ba9b94b8997
|
46
|
|
jinu |
0:6ba9b94b8997
|
47
|
#include "ble_ranges.h"
|
jinu |
0:6ba9b94b8997
|
48
|
#include "ble_types.h"
|
jinu |
0:6ba9b94b8997
|
49
|
#include "ble_gap.h"
|
jinu |
0:6ba9b94b8997
|
50
|
#include "ble_l2cap.h"
|
jinu |
0:6ba9b94b8997
|
51
|
#include "ble_gatt.h"
|
jinu |
0:6ba9b94b8997
|
52
|
#include "ble_gattc.h"
|
jinu |
0:6ba9b94b8997
|
53
|
#include "ble_gatts.h"
|
jinu |
0:6ba9b94b8997
|
54
|
|
jinu |
0:6ba9b94b8997
|
55
|
/** @addtogroup BLE_COMMON_ENUMERATIONS Enumerations
|
jinu |
0:6ba9b94b8997
|
56
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
57
|
|
jinu |
0:6ba9b94b8997
|
58
|
/**
|
jinu |
0:6ba9b94b8997
|
59
|
* @brief Common API SVC numbers.
|
jinu |
0:6ba9b94b8997
|
60
|
*/
|
jinu |
0:6ba9b94b8997
|
61
|
enum BLE_COMMON_SVCS
|
jinu |
0:6ba9b94b8997
|
62
|
{
|
jinu |
0:6ba9b94b8997
|
63
|
SD_BLE_ENABLE = BLE_SVC_BASE, /**< Enable and initialize the BLE stack */
|
jinu |
0:6ba9b94b8997
|
64
|
SD_BLE_EVT_GET, /**< Get an event from the pending events queue. */
|
jinu |
0:6ba9b94b8997
|
65
|
SD_BLE_TX_BUFFER_COUNT_GET, /**< Get the total number of available application transmission buffers from the stack. */
|
jinu |
0:6ba9b94b8997
|
66
|
SD_BLE_UUID_VS_ADD, /**< Add a Vendor Specific UUID. */
|
jinu |
0:6ba9b94b8997
|
67
|
SD_BLE_UUID_DECODE, /**< Decode UUID bytes. */
|
jinu |
0:6ba9b94b8997
|
68
|
SD_BLE_UUID_ENCODE, /**< Encode UUID bytes. */
|
jinu |
0:6ba9b94b8997
|
69
|
SD_BLE_VERSION_GET, /**< Get the local version information (company id, Link Layer Version, Link Layer Subversion). */
|
jinu |
0:6ba9b94b8997
|
70
|
SD_BLE_USER_MEM_REPLY, /**< User Memory Reply. */
|
jinu |
0:6ba9b94b8997
|
71
|
SD_BLE_OPT_SET, /**< Set a BLE option. */
|
jinu |
0:6ba9b94b8997
|
72
|
SD_BLE_OPT_GET, /**< Get a BLE option. */
|
jinu |
0:6ba9b94b8997
|
73
|
};
|
jinu |
0:6ba9b94b8997
|
74
|
|
jinu |
0:6ba9b94b8997
|
75
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
76
|
|
jinu |
0:6ba9b94b8997
|
77
|
/** @addtogroup BLE_COMMON_DEFINES Defines
|
jinu |
0:6ba9b94b8997
|
78
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
79
|
|
jinu |
0:6ba9b94b8997
|
80
|
/** @brief Required pointer alignment for BLE Events.
|
jinu |
0:6ba9b94b8997
|
81
|
*/
|
jinu |
0:6ba9b94b8997
|
82
|
#define BLE_EVTS_PTR_ALIGNMENT 4
|
jinu |
0:6ba9b94b8997
|
83
|
|
jinu |
0:6ba9b94b8997
|
84
|
/** @defgroup BLE_USER_MEM_TYPES User Memory Types
|
jinu |
0:6ba9b94b8997
|
85
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
86
|
#define BLE_USER_MEM_TYPE_INVALID 0x00 /**< Invalid User Memory Types. */
|
jinu |
0:6ba9b94b8997
|
87
|
#define BLE_USER_MEM_TYPE_GATTS_QUEUED_WRITES 0x01 /**< User Memory for GATTS queued writes. */
|
jinu |
0:6ba9b94b8997
|
88
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
89
|
|
jinu |
0:6ba9b94b8997
|
90
|
/** @brief Maximum number of Vendor Specific UUIDs.
|
jinu |
0:6ba9b94b8997
|
91
|
*/
|
jinu |
0:6ba9b94b8997
|
92
|
#define BLE_UUID_VS_MAX_COUNT 10
|
jinu |
0:6ba9b94b8997
|
93
|
|
jinu |
0:6ba9b94b8997
|
94
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
95
|
|
jinu |
0:6ba9b94b8997
|
96
|
/** @addtogroup BLE_COMMON_STRUCTURES Structures
|
jinu |
0:6ba9b94b8997
|
97
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
98
|
|
jinu |
0:6ba9b94b8997
|
99
|
/**
|
jinu |
0:6ba9b94b8997
|
100
|
* @brief BLE Module Independent Event IDs.
|
jinu |
0:6ba9b94b8997
|
101
|
*/
|
jinu |
0:6ba9b94b8997
|
102
|
enum BLE_COMMON_EVTS
|
jinu |
0:6ba9b94b8997
|
103
|
{
|
jinu |
0:6ba9b94b8997
|
104
|
BLE_EVT_TX_COMPLETE = BLE_EVT_BASE, /**< Transmission Complete. */
|
jinu |
0:6ba9b94b8997
|
105
|
BLE_EVT_USER_MEM_REQUEST, /**< User Memory request. */
|
jinu |
0:6ba9b94b8997
|
106
|
BLE_EVT_USER_MEM_RELEASE /**< User Memory release. */
|
jinu |
0:6ba9b94b8997
|
107
|
};
|
jinu |
0:6ba9b94b8997
|
108
|
|
jinu |
0:6ba9b94b8997
|
109
|
/**@brief User Memory Block. */
|
jinu |
0:6ba9b94b8997
|
110
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
111
|
{
|
jinu |
0:6ba9b94b8997
|
112
|
uint8_t* p_mem; /**< Pointer to the start of the user memory block. */
|
jinu |
0:6ba9b94b8997
|
113
|
uint16_t len; /**< Length in bytes of the user memory block. */
|
jinu |
0:6ba9b94b8997
|
114
|
} ble_user_mem_block_t;
|
jinu |
0:6ba9b94b8997
|
115
|
|
jinu |
0:6ba9b94b8997
|
116
|
/**
|
jinu |
0:6ba9b94b8997
|
117
|
* @brief TX complete event.
|
jinu |
0:6ba9b94b8997
|
118
|
*/
|
jinu |
0:6ba9b94b8997
|
119
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
120
|
{
|
jinu |
0:6ba9b94b8997
|
121
|
uint8_t count; /**< Number of packets transmitted. */
|
jinu |
0:6ba9b94b8997
|
122
|
} ble_evt_tx_complete_t;
|
jinu |
0:6ba9b94b8997
|
123
|
|
jinu |
0:6ba9b94b8997
|
124
|
/**@brief Event structure for BLE_EVT_USER_MEM_REQUEST. */
|
jinu |
0:6ba9b94b8997
|
125
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
126
|
{
|
jinu |
0:6ba9b94b8997
|
127
|
uint8_t type; /**< User memory type, see @ref BLE_USER_MEM_TYPES. */
|
jinu |
0:6ba9b94b8997
|
128
|
} ble_evt_user_mem_request_t;
|
jinu |
0:6ba9b94b8997
|
129
|
|
jinu |
0:6ba9b94b8997
|
130
|
/**@brief Event structure for BLE_EVT_USER_MEM_RELEASE. */
|
jinu |
0:6ba9b94b8997
|
131
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
132
|
{
|
jinu |
0:6ba9b94b8997
|
133
|
uint8_t type; /**< User memory type, see @ref BLE_USER_MEM_TYPES. */
|
jinu |
0:6ba9b94b8997
|
134
|
ble_user_mem_block_t mem_block; /**< User memory block */
|
jinu |
0:6ba9b94b8997
|
135
|
} ble_evt_user_mem_release_t;
|
jinu |
0:6ba9b94b8997
|
136
|
|
jinu |
0:6ba9b94b8997
|
137
|
|
jinu |
0:6ba9b94b8997
|
138
|
/**@brief Event structure for events not associated with a specific function module. */
|
jinu |
0:6ba9b94b8997
|
139
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
140
|
{
|
jinu |
0:6ba9b94b8997
|
141
|
uint16_t conn_handle; /**< Connection Handle on which this event occured. */
|
jinu |
0:6ba9b94b8997
|
142
|
union
|
jinu |
0:6ba9b94b8997
|
143
|
{
|
jinu |
0:6ba9b94b8997
|
144
|
ble_evt_tx_complete_t tx_complete; /**< Transmission Complete. */
|
jinu |
0:6ba9b94b8997
|
145
|
ble_evt_user_mem_request_t user_mem_request; /**< User Memory Request Event Parameters. */
|
jinu |
0:6ba9b94b8997
|
146
|
ble_evt_user_mem_release_t user_mem_release; /**< User Memory Release Event Parameters. */
|
jinu |
0:6ba9b94b8997
|
147
|
} params;
|
jinu |
0:6ba9b94b8997
|
148
|
} ble_common_evt_t;
|
jinu |
0:6ba9b94b8997
|
149
|
|
jinu |
0:6ba9b94b8997
|
150
|
/**@brief BLE Event header. */
|
jinu |
0:6ba9b94b8997
|
151
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
152
|
{
|
jinu |
0:6ba9b94b8997
|
153
|
uint16_t evt_id; /**< Value from a BLE_<module>_EVT series. */
|
jinu |
0:6ba9b94b8997
|
154
|
uint16_t evt_len; /**< Length in octets excluding this header. */
|
jinu |
0:6ba9b94b8997
|
155
|
} ble_evt_hdr_t;
|
jinu |
0:6ba9b94b8997
|
156
|
|
jinu |
0:6ba9b94b8997
|
157
|
/**@brief Common BLE Event type, wrapping the module specific event reports. */
|
jinu |
0:6ba9b94b8997
|
158
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
159
|
{
|
jinu |
0:6ba9b94b8997
|
160
|
ble_evt_hdr_t header; /**< Event header. */
|
jinu |
0:6ba9b94b8997
|
161
|
union
|
jinu |
0:6ba9b94b8997
|
162
|
{
|
jinu |
0:6ba9b94b8997
|
163
|
ble_common_evt_t common_evt; /**< Common Event, evt_id in BLE_EVT_* series. */
|
jinu |
0:6ba9b94b8997
|
164
|
ble_gap_evt_t gap_evt; /**< GAP originated event, evt_id in BLE_GAP_EVT_* series. */
|
jinu |
0:6ba9b94b8997
|
165
|
ble_l2cap_evt_t l2cap_evt; /**< L2CAP originated event, evt_id in BLE_L2CAP_EVT* series. */
|
jinu |
0:6ba9b94b8997
|
166
|
ble_gattc_evt_t gattc_evt; /**< GATT client originated event, evt_id in BLE_GATTC_EVT* series. */
|
jinu |
0:6ba9b94b8997
|
167
|
ble_gatts_evt_t gatts_evt; /**< GATT server originated event, evt_id in BLE_GATTS_EVT* series. */
|
jinu |
0:6ba9b94b8997
|
168
|
} evt;
|
jinu |
0:6ba9b94b8997
|
169
|
} ble_evt_t;
|
jinu |
0:6ba9b94b8997
|
170
|
|
jinu |
0:6ba9b94b8997
|
171
|
|
jinu |
0:6ba9b94b8997
|
172
|
/**
|
jinu |
0:6ba9b94b8997
|
173
|
* @brief Version Information.
|
jinu |
0:6ba9b94b8997
|
174
|
*/
|
jinu |
0:6ba9b94b8997
|
175
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
176
|
{
|
jinu |
0:6ba9b94b8997
|
177
|
uint8_t version_number; /**< Link Layer Version number for BT 4.1 spec is 7 (https://www.bluetooth.org/en-us/specification/assigned-numbers/link-layer). */
|
jinu |
0:6ba9b94b8997
|
178
|
uint16_t company_id; /**< Company ID, Nordic Semiconductor's company ID is 89 (0x0059) (https://www.bluetooth.org/apps/content/Default.aspx?doc_id=49708). */
|
jinu |
0:6ba9b94b8997
|
179
|
uint16_t subversion_number; /**< Link Layer Sub Version number, corresponds to the SoftDevice Config ID or Firmware ID (FWID). */
|
jinu |
0:6ba9b94b8997
|
180
|
} ble_version_t;
|
jinu |
0:6ba9b94b8997
|
181
|
|
jinu |
0:6ba9b94b8997
|
182
|
/**@brief Common BLE Option type, wrapping the module specific options. */
|
jinu |
0:6ba9b94b8997
|
183
|
typedef union
|
jinu |
0:6ba9b94b8997
|
184
|
{
|
jinu |
0:6ba9b94b8997
|
185
|
ble_gap_opt_t gap; /**< GAP option, opt_id in BLE_GAP_OPT_* series. */
|
jinu |
0:6ba9b94b8997
|
186
|
} ble_opt_t;
|
jinu |
0:6ba9b94b8997
|
187
|
|
jinu |
0:6ba9b94b8997
|
188
|
/**
|
jinu |
0:6ba9b94b8997
|
189
|
* @brief BLE GATTS init options
|
jinu |
0:6ba9b94b8997
|
190
|
*/
|
jinu |
0:6ba9b94b8997
|
191
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
192
|
{
|
jinu |
0:6ba9b94b8997
|
193
|
ble_gatts_enable_params_t gatts_enable_params; /**< GATTS init options @ref ble_gatts_enable_params_t. */
|
jinu |
0:6ba9b94b8997
|
194
|
} ble_enable_params_t;
|
jinu |
0:6ba9b94b8997
|
195
|
|
jinu |
0:6ba9b94b8997
|
196
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
197
|
|
jinu |
0:6ba9b94b8997
|
198
|
/** @addtogroup BLE_COMMON_FUNCTIONS Functions
|
jinu |
0:6ba9b94b8997
|
199
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
200
|
|
jinu |
0:6ba9b94b8997
|
201
|
/**@brief Enable the bluetooth stack
|
jinu |
0:6ba9b94b8997
|
202
|
*
|
jinu |
0:6ba9b94b8997
|
203
|
* @param[in] p_ble_enable_params Pointer to ble_enable_params_t
|
jinu |
0:6ba9b94b8997
|
204
|
*
|
jinu |
0:6ba9b94b8997
|
205
|
* @details This call initializes the bluetooth stack, no other BLE related call can be called before this one has been executed.
|
jinu |
0:6ba9b94b8997
|
206
|
*
|
jinu |
0:6ba9b94b8997
|
207
|
* @return @ref NRF_SUCCESS BLE stack has been initialized successfully
|
jinu |
0:6ba9b94b8997
|
208
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid or not sufficiently aligned pointer supplied.
|
jinu |
0:6ba9b94b8997
|
209
|
*/
|
jinu |
0:6ba9b94b8997
|
210
|
SVCALL(SD_BLE_ENABLE, uint32_t, sd_ble_enable(ble_enable_params_t * p_ble_enable_params));
|
jinu |
0:6ba9b94b8997
|
211
|
|
jinu |
0:6ba9b94b8997
|
212
|
/**@brief Get an event from the pending events queue.
|
jinu |
0:6ba9b94b8997
|
213
|
*
|
jinu |
0:6ba9b94b8997
|
214
|
* @param[in] p_dest Pointer to buffer to be filled in with an event, or NULL to retrieve the event length. This buffer <b>must be 4-byte aligned in memory</b>.
|
jinu |
0:6ba9b94b8997
|
215
|
* @param[in, out] p_len Pointer the length of the buffer, on return it is filled with the event length.
|
jinu |
0:6ba9b94b8997
|
216
|
*
|
jinu |
0:6ba9b94b8997
|
217
|
* @details This call allows the application to pull a BLE event from the BLE stack. The application is signalled that an event is
|
jinu |
0:6ba9b94b8997
|
218
|
* available from the BLE Stack by the triggering of the SD_EVT_IRQn interrupt (mapped to IRQ 22).
|
jinu |
0:6ba9b94b8997
|
219
|
* The application is free to choose whether to call this function from thread mode (main context) or directly from the Interrupt Service Routine
|
jinu |
0:6ba9b94b8997
|
220
|
* that maps to SD_EVT_IRQn. In any case however, and because the BLE stack runs at a higher priority than the application, this function should be called
|
jinu |
0:6ba9b94b8997
|
221
|
* in a loop (until @ref NRF_ERROR_NOT_FOUND is returned) every time SD_EVT_IRQn is raised to ensure that all available events are pulled from the stack.
|
jinu |
0:6ba9b94b8997
|
222
|
* Failure to do so could potentially leave events in the internal queue without the application being aware of this fact.
|
jinu |
0:6ba9b94b8997
|
223
|
* Sizing the p_dest buffer is equally important, since the application needs to provide all the memory necessary for the event to be copied into
|
jinu |
0:6ba9b94b8997
|
224
|
* application memory. If the buffer provided is not large enough to fit the entire contents of the event, @ref NRF_ERROR_DATA_SIZE will be returned
|
jinu |
0:6ba9b94b8997
|
225
|
* and the application can then call again with a larger buffer size.
|
jinu |
0:6ba9b94b8997
|
226
|
* Please note that because of the variable length nature of some events, sizeof(ble_evt_t) will not always be large enough to fit certain events,
|
jinu |
0:6ba9b94b8997
|
227
|
* and so it is the application's responsability to provide an amount of memory large enough so that the relevant event is copied in full.
|
jinu |
0:6ba9b94b8997
|
228
|
* The application may "peek" the event length by providing p_dest as a NULL pointer and inspecting the value of *p_len upon return.
|
jinu |
0:6ba9b94b8997
|
229
|
*
|
jinu |
0:6ba9b94b8997
|
230
|
* @note The pointer supplied must be aligned to the extend defined by @ref BLE_EVTS_PTR_ALIGNMENT
|
jinu |
0:6ba9b94b8997
|
231
|
*
|
jinu |
0:6ba9b94b8997
|
232
|
* @return @ref NRF_SUCCESS Event pulled and stored into the supplied buffer.
|
jinu |
0:6ba9b94b8997
|
233
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid or not sufficiently aligned pointer supplied.
|
jinu |
0:6ba9b94b8997
|
234
|
* @return @ref NRF_ERROR_NOT_FOUND No events ready to be pulled.
|
jinu |
0:6ba9b94b8997
|
235
|
* @return @ref NRF_ERROR_DATA_SIZE Event ready but could not fit into the supplied buffer.
|
jinu |
0:6ba9b94b8997
|
236
|
*/
|
jinu |
0:6ba9b94b8997
|
237
|
SVCALL(SD_BLE_EVT_GET, uint32_t, sd_ble_evt_get(uint8_t* p_dest, uint16_t *p_len));
|
jinu |
0:6ba9b94b8997
|
238
|
|
jinu |
0:6ba9b94b8997
|
239
|
|
jinu |
0:6ba9b94b8997
|
240
|
/**@brief Get the total number of available application transmission buffers in the BLE stack.
|
jinu |
0:6ba9b94b8997
|
241
|
*
|
jinu |
0:6ba9b94b8997
|
242
|
* @details This call allows the application to obtain the total number of
|
jinu |
0:6ba9b94b8997
|
243
|
* transmission buffers available for application data. Please note that
|
jinu |
0:6ba9b94b8997
|
244
|
* this does not give the number of free buffers, but rather the total amount of them.
|
jinu |
0:6ba9b94b8997
|
245
|
* The application has two options to handle its own application transmission buffers:
|
jinu |
0:6ba9b94b8997
|
246
|
* - Use a simple arithmetic calculation: at boot time the application should use this function
|
jinu |
0:6ba9b94b8997
|
247
|
* to find out the total amount of buffers available to it and store it in a variable.
|
jinu |
0:6ba9b94b8997
|
248
|
* Every time a packet that consumes an application buffer is sent using any of the
|
jinu |
0:6ba9b94b8997
|
249
|
* exposed functions in this BLE API, the application should decrement that variable.
|
jinu |
0:6ba9b94b8997
|
250
|
* Conversely, whenever a @ref BLE_EVT_TX_COMPLETE event is received by the application
|
jinu |
0:6ba9b94b8997
|
251
|
* it should retrieve the count field in such event and add that number to the same
|
jinu |
0:6ba9b94b8997
|
252
|
* variable storing the number of available packets.
|
jinu |
0:6ba9b94b8997
|
253
|
* This mechanism allows the application to be aware at any time of the number of
|
jinu |
0:6ba9b94b8997
|
254
|
* application packets available in the BLE stack's internal buffers, and therefore
|
jinu |
0:6ba9b94b8997
|
255
|
* it can know with certainty whether it is possible to send more data or it has to
|
jinu |
0:6ba9b94b8997
|
256
|
* wait for a @ref BLE_EVT_TX_COMPLETE event before it proceeds.
|
jinu |
0:6ba9b94b8997
|
257
|
* - Choose to simply not keep track of available buffers at all, and instead handle the
|
jinu |
0:6ba9b94b8997
|
258
|
* @ref BLE_ERROR_NO_TX_BUFFERS error by queueing the packet to be transmitted and
|
jinu |
0:6ba9b94b8997
|
259
|
* try again as soon as a @ref BLE_EVT_TX_COMPLETE event arrives.
|
jinu |
0:6ba9b94b8997
|
260
|
*
|
jinu |
0:6ba9b94b8997
|
261
|
* The API functions that <b>may</b> consume an application buffer depending on
|
jinu |
0:6ba9b94b8997
|
262
|
* the parameters supplied to them can be found below:
|
jinu |
0:6ba9b94b8997
|
263
|
*
|
jinu |
0:6ba9b94b8997
|
264
|
* - @ref sd_ble_gattc_write (write witout response only)
|
jinu |
0:6ba9b94b8997
|
265
|
* - @ref sd_ble_gatts_hvx (notifications only)
|
jinu |
0:6ba9b94b8997
|
266
|
* - @ref sd_ble_l2cap_tx (all packets)
|
jinu |
0:6ba9b94b8997
|
267
|
*
|
jinu |
0:6ba9b94b8997
|
268
|
* @param[out] p_count Pointer to a uint8_t which will contain the number of application transmission buffers upon
|
jinu |
0:6ba9b94b8997
|
269
|
* successful return.
|
jinu |
0:6ba9b94b8997
|
270
|
*
|
jinu |
0:6ba9b94b8997
|
271
|
* @return @ref NRF_SUCCESS Number of application transmission buffers retrieved successfully.
|
jinu |
0:6ba9b94b8997
|
272
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
273
|
*/
|
jinu |
0:6ba9b94b8997
|
274
|
SVCALL(SD_BLE_TX_BUFFER_COUNT_GET, uint32_t, sd_ble_tx_buffer_count_get(uint8_t* p_count));
|
jinu |
0:6ba9b94b8997
|
275
|
|
jinu |
0:6ba9b94b8997
|
276
|
|
jinu |
0:6ba9b94b8997
|
277
|
/**@brief Add a Vendor Specific UUID.
|
jinu |
0:6ba9b94b8997
|
278
|
*
|
jinu |
0:6ba9b94b8997
|
279
|
* @details This call enables the application to add a vendor specific UUID to the BLE stack's table,
|
jinu |
0:6ba9b94b8997
|
280
|
* for later use all other modules and APIs. This then allows the application to use the shorter,
|
jinu |
0:6ba9b94b8997
|
281
|
* 24-bit @ref ble_uuid_t format when dealing with both 16-bit and 128-bit UUIDs without having to
|
jinu |
0:6ba9b94b8997
|
282
|
* check for lengths and having split code paths. The way that this is accomplished is by extending the
|
jinu |
0:6ba9b94b8997
|
283
|
* grouping mechanism that the Bluetooth SIG standard base UUID uses for all other 128-bit UUIDs. The
|
jinu |
0:6ba9b94b8997
|
284
|
* type field in the @ref ble_uuid_t structure is an index (relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN)
|
jinu |
0:6ba9b94b8997
|
285
|
* to the table populated by multiple calls to this function, and the uuid field in the same structure
|
jinu |
0:6ba9b94b8997
|
286
|
* contains the 2 bytes at indices 12 and 13. The number of possible 128-bit UUIDs available to the
|
jinu |
0:6ba9b94b8997
|
287
|
* application is therefore the number of Vendor Specific UUIDs added with the help of this function times 65536,
|
jinu |
0:6ba9b94b8997
|
288
|
* although restricted to modifying bytes 12 and 13 for each of the entries in the supplied array.
|
jinu |
0:6ba9b94b8997
|
289
|
*
|
jinu |
0:6ba9b94b8997
|
290
|
* @note Bytes 12 and 13 of the provided UUID will not be used internally, since those are always replaced by
|
jinu |
0:6ba9b94b8997
|
291
|
* the 16-bit uuid field in @ref ble_uuid_t.
|
jinu |
0:6ba9b94b8997
|
292
|
*
|
jinu |
0:6ba9b94b8997
|
293
|
*
|
jinu |
0:6ba9b94b8997
|
294
|
* @param[in] p_vs_uuid Pointer to a 16-octet (128-bit) little endian Vendor Specific UUID disregarding
|
jinu |
0:6ba9b94b8997
|
295
|
* bytes 12 and 13.
|
jinu |
0:6ba9b94b8997
|
296
|
* @param[out] p_uuid_type Pointer where the type field in @ref ble_uuid_t corresponding to this UUID will be stored.
|
jinu |
0:6ba9b94b8997
|
297
|
*
|
jinu |
0:6ba9b94b8997
|
298
|
* @return @ref NRF_SUCCESS Successfully added the Vendor Specific UUID.
|
jinu |
0:6ba9b94b8997
|
299
|
* @return @ref NRF_ERROR_INVALID_ADDR If p_vs_uuid or p_uuid_type is NULL or invalid.
|
jinu |
0:6ba9b94b8997
|
300
|
* @return @ref NRF_ERROR_NO_MEM If there are no more free slots for VS UUIDs.
|
jinu |
0:6ba9b94b8997
|
301
|
* @return @ref NRF_ERROR_FORBIDDEN If p_vs_uuid has already been added to the VS UUID table.
|
jinu |
0:6ba9b94b8997
|
302
|
*/
|
jinu |
0:6ba9b94b8997
|
303
|
SVCALL(SD_BLE_UUID_VS_ADD, uint32_t, sd_ble_uuid_vs_add(ble_uuid128_t const * const p_vs_uuid, uint8_t * const p_uuid_type));
|
jinu |
0:6ba9b94b8997
|
304
|
|
jinu |
0:6ba9b94b8997
|
305
|
|
jinu |
0:6ba9b94b8997
|
306
|
/** @brief Decode little endian raw UUID bytes (16-bit or 128-bit) into a 24 bit @ref ble_uuid_t structure.
|
jinu |
0:6ba9b94b8997
|
307
|
*
|
jinu |
0:6ba9b94b8997
|
308
|
* @details The raw UUID bytes excluding bytes 12 and 13 (i.e. bytes 0-11 and 14-15) of p_uuid_le are compared
|
jinu |
0:6ba9b94b8997
|
309
|
* to the corresponding ones in each entry of the table of vendor specific UUIDs pouplated with @ref sd_ble_uuid_vs_add
|
jinu |
0:6ba9b94b8997
|
310
|
* to look for a match. If there is such a match, bytes 12 and 13 are returned as p_uuid->uuid and the index
|
jinu |
0:6ba9b94b8997
|
311
|
* relative to @ref BLE_UUID_TYPE_VENDOR_BEGIN as p_uuid->type.
|
jinu |
0:6ba9b94b8997
|
312
|
*
|
jinu |
0:6ba9b94b8997
|
313
|
* @note If the UUID length supplied is 2, then the type set by this call will always be @ref BLE_UUID_TYPE_BLE.
|
jinu |
0:6ba9b94b8997
|
314
|
*
|
jinu |
0:6ba9b94b8997
|
315
|
* @param[in] uuid_le_len Length in bytes of the buffer pointed to by p_uuid_le (must be 2 or 16 bytes).
|
jinu |
0:6ba9b94b8997
|
316
|
* @param[in] p_uuid_le Pointer pointing to little endian raw UUID bytes.
|
jinu |
0:6ba9b94b8997
|
317
|
* @param[in,out] p_uuid Pointer to a @ref ble_uuid_t structure to be filled in.
|
jinu |
0:6ba9b94b8997
|
318
|
*
|
jinu |
0:6ba9b94b8997
|
319
|
* @return @ref NRF_SUCCESS Successfully decoded into the @ref ble_uuid_t structure.
|
jinu |
0:6ba9b94b8997
|
320
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
321
|
* @return @ref NRF_ERROR_INVALID_LENGTH Invalid UUID length.
|
jinu |
0:6ba9b94b8997
|
322
|
* @return @ref NRF_ERROR_NOT_FOUND For a 128-bit UUID, no match in the populated table of UUIDs.
|
jinu |
0:6ba9b94b8997
|
323
|
*/
|
jinu |
0:6ba9b94b8997
|
324
|
SVCALL(SD_BLE_UUID_DECODE, uint32_t, sd_ble_uuid_decode(uint8_t uuid_le_len, uint8_t const * const p_uuid_le, ble_uuid_t * const p_uuid));
|
jinu |
0:6ba9b94b8997
|
325
|
|
jinu |
0:6ba9b94b8997
|
326
|
|
jinu |
0:6ba9b94b8997
|
327
|
/** @brief Encode a @ref ble_uuid_t structure into little endian raw UUID bytes (16-bit or 128-bit).
|
jinu |
0:6ba9b94b8997
|
328
|
*
|
jinu |
0:6ba9b94b8997
|
329
|
* @note The pointer to the destination buffer p_uuid_le may be NULL, in which case only the validitiy and size of p_uuid is computed.
|
jinu |
0:6ba9b94b8997
|
330
|
*
|
jinu |
0:6ba9b94b8997
|
331
|
* @param[in] p_uuid Pointer to a @ref ble_uuid_t structure that will be encoded into bytes.
|
jinu |
0:6ba9b94b8997
|
332
|
* @param[out] p_uuid_le_len Pointer to a uint8_t that will be filled with the encoded length (2 or 16 bytes).
|
jinu |
0:6ba9b94b8997
|
333
|
* @param[out] p_uuid_le Pointer to a buffer where the little endian raw UUID bytes (2 or 16) will be stored.
|
jinu |
0:6ba9b94b8997
|
334
|
*
|
jinu |
0:6ba9b94b8997
|
335
|
* @return @ref NRF_SUCCESS Successfully encoded into the buffer.
|
jinu |
0:6ba9b94b8997
|
336
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
337
|
* @return @ref NRF_ERROR_INVALID_PARAM Invalid UUID type.
|
jinu |
0:6ba9b94b8997
|
338
|
*/
|
jinu |
0:6ba9b94b8997
|
339
|
SVCALL(SD_BLE_UUID_ENCODE, uint32_t, sd_ble_uuid_encode(ble_uuid_t const * const p_uuid, uint8_t * const p_uuid_le_len, uint8_t * const p_uuid_le));
|
jinu |
0:6ba9b94b8997
|
340
|
|
jinu |
0:6ba9b94b8997
|
341
|
|
jinu |
0:6ba9b94b8997
|
342
|
/**@brief Get Version Information.
|
jinu |
0:6ba9b94b8997
|
343
|
*
|
jinu |
0:6ba9b94b8997
|
344
|
* @details This call allows the application to get the BLE stack version information.
|
jinu |
0:6ba9b94b8997
|
345
|
*
|
jinu |
0:6ba9b94b8997
|
346
|
* @param[in] p_version Pointer to ble_version_t structure to be filled in.
|
jinu |
0:6ba9b94b8997
|
347
|
*
|
jinu |
0:6ba9b94b8997
|
348
|
* @return @ref NRF_SUCCESS Version information stored successfully.
|
jinu |
0:6ba9b94b8997
|
349
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
350
|
* @return @ref NRF_ERROR_BUSY The stack is busy (typically doing a locally-initiated disconnection procedure).
|
jinu |
0:6ba9b94b8997
|
351
|
*/
|
jinu |
0:6ba9b94b8997
|
352
|
SVCALL(SD_BLE_VERSION_GET, uint32_t, sd_ble_version_get(ble_version_t * p_version));
|
jinu |
0:6ba9b94b8997
|
353
|
|
jinu |
0:6ba9b94b8997
|
354
|
|
jinu |
0:6ba9b94b8997
|
355
|
/**@brief Provide a user memory block.
|
jinu |
0:6ba9b94b8997
|
356
|
*
|
jinu |
0:6ba9b94b8997
|
357
|
* @note This call can only be used as a response to a @ref BLE_EVT_USER_MEM_REQUEST event issued to the application.
|
jinu |
0:6ba9b94b8997
|
358
|
*
|
jinu |
0:6ba9b94b8997
|
359
|
* @param[in] conn_handle Connection handle.
|
jinu |
0:6ba9b94b8997
|
360
|
* @param[in] p_block Pointer to a user memory block structure.
|
jinu |
0:6ba9b94b8997
|
361
|
*
|
jinu |
0:6ba9b94b8997
|
362
|
* @return @ref NRF_SUCCESS Successfully queued a response to the peer.
|
jinu |
0:6ba9b94b8997
|
363
|
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
|
jinu |
0:6ba9b94b8997
|
364
|
* @return @ref NRF_ERROR_INVALID_STATE No execute write request pending.
|
jinu |
0:6ba9b94b8997
|
365
|
*/
|
jinu |
0:6ba9b94b8997
|
366
|
SVCALL(SD_BLE_USER_MEM_REPLY, uint32_t, sd_ble_user_mem_reply(uint16_t conn_handle, ble_user_mem_block_t *p_block));
|
jinu |
0:6ba9b94b8997
|
367
|
|
jinu |
0:6ba9b94b8997
|
368
|
|
jinu |
0:6ba9b94b8997
|
369
|
/**@brief Set a BLE option.
|
jinu |
0:6ba9b94b8997
|
370
|
*
|
jinu |
0:6ba9b94b8997
|
371
|
* @details This call allows the application to set the value of an option.
|
jinu |
0:6ba9b94b8997
|
372
|
*
|
jinu |
0:6ba9b94b8997
|
373
|
* @param[in] opt_id Option ID.
|
jinu |
0:6ba9b94b8997
|
374
|
* @param[in] p_opt Pointer to a ble_opt_t structure containing the option value.
|
jinu |
0:6ba9b94b8997
|
375
|
*
|
jinu |
0:6ba9b94b8997
|
376
|
* @retval ::NRF_SUCCESS Option set successfully.
|
jinu |
0:6ba9b94b8997
|
377
|
* @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
378
|
* @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
|
jinu |
0:6ba9b94b8997
|
379
|
* @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints.
|
jinu |
0:6ba9b94b8997
|
380
|
* @retval ::NRF_ERROR_INVALID_STATE Unable to set the parameter at this time.
|
jinu |
0:6ba9b94b8997
|
381
|
* @retval ::NRF_ERROR_BUSY The stack is busy or the previous procedure has not completed.
|
jinu |
0:6ba9b94b8997
|
382
|
*/
|
jinu |
0:6ba9b94b8997
|
383
|
SVCALL(SD_BLE_OPT_SET, uint32_t, sd_ble_opt_set(uint32_t opt_id, ble_opt_t const *p_opt));
|
jinu |
0:6ba9b94b8997
|
384
|
|
jinu |
0:6ba9b94b8997
|
385
|
|
jinu |
0:6ba9b94b8997
|
386
|
/**@brief Get a BLE option.
|
jinu |
0:6ba9b94b8997
|
387
|
*
|
jinu |
0:6ba9b94b8997
|
388
|
* @details This call allows the application to retrieve the value of an option.
|
jinu |
0:6ba9b94b8997
|
389
|
*
|
jinu |
0:6ba9b94b8997
|
390
|
* @param[in] opt_id Option ID.
|
jinu |
0:6ba9b94b8997
|
391
|
* @param[out] p_opt Pointer to a ble_opt_t structure to be filled in.
|
jinu |
0:6ba9b94b8997
|
392
|
*
|
jinu |
0:6ba9b94b8997
|
393
|
* @retval ::NRF_SUCCESS Option retrieved successfully.
|
jinu |
0:6ba9b94b8997
|
394
|
* @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
395
|
* @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
|
jinu |
0:6ba9b94b8997
|
396
|
* @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check parameter limits and constraints.
|
jinu |
0:6ba9b94b8997
|
397
|
* @retval ::NRF_ERROR_INVALID_STATE Unable to retrieve the parameter at this time.
|
jinu |
0:6ba9b94b8997
|
398
|
* @retval ::NRF_ERROR_BUSY The stack is busy or the previous procedure has not completed.
|
jinu |
0:6ba9b94b8997
|
399
|
* @retval ::NRF_ERROR_NOT_SUPPORTED This option is not supported.
|
jinu |
0:6ba9b94b8997
|
400
|
*
|
jinu |
0:6ba9b94b8997
|
401
|
*/
|
jinu |
0:6ba9b94b8997
|
402
|
SVCALL(SD_BLE_OPT_GET, uint32_t, sd_ble_opt_get(uint32_t opt_id, ble_opt_t *p_opt));
|
jinu |
0:6ba9b94b8997
|
403
|
|
jinu |
0:6ba9b94b8997
|
404
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
405
|
|
jinu |
0:6ba9b94b8997
|
406
|
#endif /* BLE_H__ */
|
jinu |
0:6ba9b94b8997
|
407
|
|
jinu |
0:6ba9b94b8997
|
408
|
/**
|
jinu |
0:6ba9b94b8997
|
409
|
@}
|
jinu |
0:6ba9b94b8997
|
410
|
@}
|
jinu |
0:6ba9b94b8997
|
411
|
*/
|
jinu |
0:6ba9b94b8997
|
412
|
|