BLE FOTA APP

Dependencies:   BLE_API mbed

It doesn't work with the default FOTA bootloader. It use NVIC_SystemReset() to enter a bootloader.

Committer:
yihui
Date:
Fri Oct 10 03:36:28 2014 +0000
Revision:
1:a607cd9655d7
use NVIC_SystemReset() to run bootloader

Who changed what in which revision?

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