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_GATTS Generic Attribute Profile (GATT) Server
yihui 1:a607cd9655d7 10 @{
yihui 1:a607cd9655d7 11 @brief Definitions and prototypes for the GATTS interface.
yihui 1:a607cd9655d7 12 */
yihui 1:a607cd9655d7 13
yihui 1:a607cd9655d7 14 #ifndef BLE_GATTS_H__
yihui 1:a607cd9655d7 15 #define BLE_GATTS_H__
yihui 1:a607cd9655d7 16
yihui 1:a607cd9655d7 17 #include "ble_types.h"
yihui 1:a607cd9655d7 18 #include "ble_ranges.h"
yihui 1:a607cd9655d7 19 #include "ble_l2cap.h"
yihui 1:a607cd9655d7 20 #include "ble_gap.h"
yihui 1:a607cd9655d7 21 #include "ble_gatt.h"
yihui 1:a607cd9655d7 22 #include "nrf_svc.h"
yihui 1:a607cd9655d7 23
yihui 1:a607cd9655d7 24 /** @addtogroup BLE_GATTS_ENUMERATIONS Enumerations
yihui 1:a607cd9655d7 25 * @{ */
yihui 1:a607cd9655d7 26
yihui 1:a607cd9655d7 27 /**
yihui 1:a607cd9655d7 28 * @brief GATTS API SVC numbers.
yihui 1:a607cd9655d7 29 */
yihui 1:a607cd9655d7 30 enum BLE_GATTS_SVCS
yihui 1:a607cd9655d7 31 {
yihui 1:a607cd9655d7 32 SD_BLE_GATTS_SERVICE_ADD = BLE_GATTS_SVC_BASE, /**< Add a service. */
yihui 1:a607cd9655d7 33 SD_BLE_GATTS_INCLUDE_ADD, /**< Add an included service. */
yihui 1:a607cd9655d7 34 SD_BLE_GATTS_CHARACTERISTIC_ADD, /**< Add a characteristic. */
yihui 1:a607cd9655d7 35 SD_BLE_GATTS_DESCRIPTOR_ADD, /**< Add a generic attribute. */
yihui 1:a607cd9655d7 36 SD_BLE_GATTS_VALUE_SET, /**< Set an attribute value. */
yihui 1:a607cd9655d7 37 SD_BLE_GATTS_VALUE_GET, /**< Get an attribute value. */
yihui 1:a607cd9655d7 38 SD_BLE_GATTS_HVX, /**< Handle Value Notification or Indication. */
yihui 1:a607cd9655d7 39 SD_BLE_GATTS_SERVICE_CHANGED, /**< Perform a Service Changed Indication to one or more peers. */
yihui 1:a607cd9655d7 40 SD_BLE_GATTS_RW_AUTHORIZE_REPLY, /**< Reply to an authorization request for a read or write operation on one or more attributes. */
yihui 1:a607cd9655d7 41 SD_BLE_GATTS_SYS_ATTR_SET, /**< Set the persistent system attributes for a connection. */
yihui 1:a607cd9655d7 42 SD_BLE_GATTS_SYS_ATTR_GET, /**< Get updated persistent system attributes after terminating a connection. */
yihui 1:a607cd9655d7 43 };
yihui 1:a607cd9655d7 44
yihui 1:a607cd9655d7 45 /** @} */
yihui 1:a607cd9655d7 46
yihui 1:a607cd9655d7 47 /** @addtogroup BLE_GATTS_DEFINES Defines
yihui 1:a607cd9655d7 48 * @{ */
yihui 1:a607cd9655d7 49
yihui 1:a607cd9655d7 50 /** @brief Only the default MTU size of 23 is currently supported. */
yihui 1:a607cd9655d7 51 #define GATT_RX_MTU 23
yihui 1:a607cd9655d7 52
yihui 1:a607cd9655d7 53 /** @defgroup BLE_ERRORS_GATTS SVC return values specific to GATTS
yihui 1:a607cd9655d7 54 * @{ */
yihui 1:a607cd9655d7 55 #define BLE_ERROR_GATTS_INVALID_ATTR_TYPE (NRF_GATTS_ERR_BASE + 0x000) /**< Invalid attribute type. */
yihui 1:a607cd9655d7 56 #define BLE_ERROR_GATTS_SYS_ATTR_MISSING (NRF_GATTS_ERR_BASE + 0x001) /**< System Attributes missing. */
yihui 1:a607cd9655d7 57 /** @} */
yihui 1:a607cd9655d7 58
yihui 1:a607cd9655d7 59 /** @defgroup BLE_GATTS_ATTR_LENS_MAX Maximum attribute lengths
yihui 1:a607cd9655d7 60 * @{ */
yihui 1:a607cd9655d7 61 #define BLE_GATTS_FIX_ATTR_LEN_MAX (510) /**< Maximum length for fixed length Attribute Values. */
yihui 1:a607cd9655d7 62 #define BLE_GATTS_VAR_ATTR_LEN_MAX (512) /**< Maximum length for variable length Attribute Values. */
yihui 1:a607cd9655d7 63 /** @} */
yihui 1:a607cd9655d7 64
yihui 1:a607cd9655d7 65 /** @defgroup BLE_GATTS_SRVC_TYPES GATT Server Service Types
yihui 1:a607cd9655d7 66 * @{ */
yihui 1:a607cd9655d7 67 #define BLE_GATTS_SRVC_TYPE_INVALID 0x00 /**< Invalid Service Type. */
yihui 1:a607cd9655d7 68 #define BLE_GATTS_SRVC_TYPE_PRIMARY 0x01 /**< Primary Service. */
yihui 1:a607cd9655d7 69 #define BLE_GATTS_SRVC_TYPE_SECONDARY 0x02 /**< Secondary Type. */
yihui 1:a607cd9655d7 70 /** @} */
yihui 1:a607cd9655d7 71
yihui 1:a607cd9655d7 72
yihui 1:a607cd9655d7 73 /** @defgroup BLE_GATTS_ATTR_TYPES GATT Server Attribute Types
yihui 1:a607cd9655d7 74 * @{ */
yihui 1:a607cd9655d7 75 #define BLE_GATTS_ATTR_TYPE_INVALID 0x00 /**< Invalid Attribute Type. */
yihui 1:a607cd9655d7 76 #define BLE_GATTS_ATTR_TYPE_PRIM_SRVC_DECL 0x01 /**< Primary Service Declaration. */
yihui 1:a607cd9655d7 77 #define BLE_GATTS_ATTR_TYPE_SEC_SRVC_DECL 0x02 /**< Secondary Service Declaration. */
yihui 1:a607cd9655d7 78 #define BLE_GATTS_ATTR_TYPE_INC_DECL 0x03 /**< Include Declaration. */
yihui 1:a607cd9655d7 79 #define BLE_GATTS_ATTR_TYPE_CHAR_DECL 0x04 /**< Characteristic Declaration. */
yihui 1:a607cd9655d7 80 #define BLE_GATTS_ATTR_TYPE_CHAR_VAL 0x05 /**< Characteristic Value. */
yihui 1:a607cd9655d7 81 #define BLE_GATTS_ATTR_TYPE_DESC 0x06 /**< Descriptor. */
yihui 1:a607cd9655d7 82 #define BLE_GATTS_ATTR_TYPE_OTHER 0x07 /**< Other, non-GATT specific type. */
yihui 1:a607cd9655d7 83 /** @} */
yihui 1:a607cd9655d7 84
yihui 1:a607cd9655d7 85
yihui 1:a607cd9655d7 86 /** @defgroup BLE_GATTS_OPS GATT Server Operations
yihui 1:a607cd9655d7 87 * @{ */
yihui 1:a607cd9655d7 88 #define BLE_GATTS_OP_INVALID 0x00 /**< Invalid Operation. */
yihui 1:a607cd9655d7 89 #define BLE_GATTS_OP_WRITE_REQ 0x01 /**< Write Request. */
yihui 1:a607cd9655d7 90 #define BLE_GATTS_OP_WRITE_CMD 0x02 /**< Write Command. */
yihui 1:a607cd9655d7 91 #define BLE_GATTS_OP_SIGN_WRITE_CMD 0x03 /**< Signed Write Command. */
yihui 1:a607cd9655d7 92 #define BLE_GATTS_OP_PREP_WRITE_REQ 0x04 /**< Prepare Write Request. */
yihui 1:a607cd9655d7 93 #define BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL 0x05 /**< Execute Write Request: Cancel all prepared writes. */
yihui 1:a607cd9655d7 94 #define BLE_GATTS_OP_EXEC_WRITE_REQ_NOW 0x06 /**< Execute Write Request: Immediately execute all prepared writes. */
yihui 1:a607cd9655d7 95 /** @} */
yihui 1:a607cd9655d7 96
yihui 1:a607cd9655d7 97 /** @defgroup BLE_GATTS_VLOCS GATT Value Locations
yihui 1:a607cd9655d7 98 * @{ */
yihui 1:a607cd9655d7 99 #define BLE_GATTS_VLOC_INVALID 0x00 /**< Invalid Location. */
yihui 1:a607cd9655d7 100 #define BLE_GATTS_VLOC_STACK 0x01 /**< Attribute Value is located in stack memory, no user memory is required. */
yihui 1:a607cd9655d7 101 #define BLE_GATTS_VLOC_USER 0x02 /**< Attribute Value is located in user memory. This requires the user to maintain a valid buffer through the lifetime of the attribute, since the stack
yihui 1:a607cd9655d7 102 will read and write directly to the memory using the pointer provided in the APIs. There are no alignment requirements for the buffer. */
yihui 1:a607cd9655d7 103 /** @} */
yihui 1:a607cd9655d7 104
yihui 1:a607cd9655d7 105 /** @defgroup BLE_GATTS_AUTHORIZE_TYPES GATT Server Authorization Types
yihui 1:a607cd9655d7 106 * @{ */
yihui 1:a607cd9655d7 107 #define BLE_GATTS_AUTHORIZE_TYPE_INVALID 0x00 /**< Invalid Type. */
yihui 1:a607cd9655d7 108 #define BLE_GATTS_AUTHORIZE_TYPE_READ 0x01 /**< Authorize a Read Operation. */
yihui 1:a607cd9655d7 109 #define BLE_GATTS_AUTHORIZE_TYPE_WRITE 0x02 /**< Authorize a Write Request Operation. */
yihui 1:a607cd9655d7 110 /** @} */
yihui 1:a607cd9655d7 111
yihui 1:a607cd9655d7 112
yihui 1:a607cd9655d7 113 /** @} */
yihui 1:a607cd9655d7 114
yihui 1:a607cd9655d7 115 /** @addtogroup BLE_GATTS_STRUCTURES Structures
yihui 1:a607cd9655d7 116 * @{ */
yihui 1:a607cd9655d7 117
yihui 1:a607cd9655d7 118 /**
yihui 1:a607cd9655d7 119 * @brief BLE GATTS init options
yihui 1:a607cd9655d7 120 */
yihui 1:a607cd9655d7 121 typedef struct
yihui 1:a607cd9655d7 122 {
yihui 1:a607cd9655d7 123 uint8_t service_changed:1; /**< Include the Service Changed characteristic in the local attributes. */
yihui 1:a607cd9655d7 124 } ble_gatts_enable_params_t;
yihui 1:a607cd9655d7 125
yihui 1:a607cd9655d7 126 /**@brief Attribute metadata. */
yihui 1:a607cd9655d7 127 typedef struct
yihui 1:a607cd9655d7 128 {
yihui 1:a607cd9655d7 129 ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */
yihui 1:a607cd9655d7 130 ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */
yihui 1:a607cd9655d7 131 uint8_t vlen :1; /**< Variable length attribute. */
yihui 1:a607cd9655d7 132 uint8_t vloc :2; /**< Value location, see @ref BLE_GATTS_VLOCS.*/
yihui 1:a607cd9655d7 133 uint8_t rd_auth :1; /**< Read Authorization and value will be requested from the application on every read operation. */
yihui 1:a607cd9655d7 134 uint8_t wr_auth :1; /**< Write Authorization will be requested from the application on every Write Request operation (but not Write Command). */
yihui 1:a607cd9655d7 135 } ble_gatts_attr_md_t;
yihui 1:a607cd9655d7 136
yihui 1:a607cd9655d7 137
yihui 1:a607cd9655d7 138 /**@brief GATT Attribute. */
yihui 1:a607cd9655d7 139 typedef struct
yihui 1:a607cd9655d7 140 {
yihui 1:a607cd9655d7 141 ble_uuid_t* p_uuid; /**< Pointer to the attribute UUID. */
yihui 1:a607cd9655d7 142 ble_gatts_attr_md_t* p_attr_md; /**< Pointer to the attribute metadata structure. */
yihui 1:a607cd9655d7 143 uint16_t init_len; /**< Initial attribute value length in bytes. */
yihui 1:a607cd9655d7 144 uint16_t init_offs; /**< Initial attribute value offset in bytes. If different from zero, the first init_offs bytes of the attribute value will be left uninitialized. */
yihui 1:a607cd9655d7 145 uint16_t max_len; /**< Maximum attribute value length in bytes, see @ref BLE_GATTS_ATTR_LENS_MAX for maximum values. */
yihui 1:a607cd9655d7 146 uint8_t* p_value; /**< Pointer to the attribute data. Please note that if the @ref BLE_GATTS_VLOC_USER value location is selected in the attribute metadata, this will have to point to a buffer
yihui 1:a607cd9655d7 147 that remains valid through the lifetime of the attribute. This excludes usage of automatic variables that may go out of scope or any other temporary location.
yihui 1:a607cd9655d7 148 The stack may access that memory directly without the application's knowledge. */
yihui 1:a607cd9655d7 149 } ble_gatts_attr_t;
yihui 1:a607cd9655d7 150
yihui 1:a607cd9655d7 151
yihui 1:a607cd9655d7 152 /**@brief GATT Attribute Context. */
yihui 1:a607cd9655d7 153 typedef struct
yihui 1:a607cd9655d7 154 {
yihui 1:a607cd9655d7 155 ble_uuid_t srvc_uuid; /**< Service UUID. */
yihui 1:a607cd9655d7 156 ble_uuid_t char_uuid; /**< Characteristic UUID if applicable (BLE_UUID_TYPE_UNKNOWN if N/A). */
yihui 1:a607cd9655d7 157 ble_uuid_t desc_uuid; /**< Descriptor UUID if applicable (BLE_UUID_TYPE_UNKNOWN if N/A). */
yihui 1:a607cd9655d7 158 uint16_t srvc_handle; /**< Service Handle. */
yihui 1:a607cd9655d7 159 uint16_t value_handle; /**< Characteristic Handle if applicable (BLE_GATT_HANDLE_INVALID if N/A). */
yihui 1:a607cd9655d7 160 uint8_t type; /**< Attribute Type, see @ref BLE_GATTS_ATTR_TYPES. */
yihui 1:a607cd9655d7 161 } ble_gatts_attr_context_t;
yihui 1:a607cd9655d7 162
yihui 1:a607cd9655d7 163
yihui 1:a607cd9655d7 164 /**@brief GATT Characteristic Presentation Format. */
yihui 1:a607cd9655d7 165 typedef struct
yihui 1:a607cd9655d7 166 {
yihui 1:a607cd9655d7 167 uint8_t format; /**< Format of the value, see @ref BLE_GATT_CPF_FORMATS. */
yihui 1:a607cd9655d7 168 int8_t exponent; /**< Exponent for integer data types. */
yihui 1:a607cd9655d7 169 uint16_t unit; /**< UUID from Bluetooth Assigned Numbers. */
yihui 1:a607cd9655d7 170 uint8_t name_space; /**< Namespace from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
yihui 1:a607cd9655d7 171 uint16_t desc; /**< Namespace description from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
yihui 1:a607cd9655d7 172 } ble_gatts_char_pf_t;
yihui 1:a607cd9655d7 173
yihui 1:a607cd9655d7 174
yihui 1:a607cd9655d7 175 /**@brief GATT Characteristic metadata. */
yihui 1:a607cd9655d7 176 typedef struct
yihui 1:a607cd9655d7 177 {
yihui 1:a607cd9655d7 178 ble_gatt_char_props_t char_props; /**< Characteristic Properties. */
yihui 1:a607cd9655d7 179 ble_gatt_char_ext_props_t char_ext_props; /**< Characteristic Extended Properties. */
yihui 1:a607cd9655d7 180 uint8_t* p_char_user_desc; /**< Pointer to a UTF-8, NULL if the descriptor is not required. */
yihui 1:a607cd9655d7 181 uint16_t char_user_desc_max_size; /**< The maximum size in bytes of the user description descriptor. */
yihui 1:a607cd9655d7 182 uint16_t char_user_desc_size; /**< The size of the user description, must be smaller or equal to char_user_desc_max_size. */
yihui 1:a607cd9655d7 183 ble_gatts_char_pf_t* p_char_pf; /**< Pointer to a presentation format structure or NULL if the descriptor is not required. */
yihui 1:a607cd9655d7 184 ble_gatts_attr_md_t* p_user_desc_md; /**< Attribute metadata for the User Description descriptor, or NULL for default values. */
yihui 1:a607cd9655d7 185 ble_gatts_attr_md_t* p_cccd_md; /**< Attribute metadata for the Client Characteristic Configuration Descriptor, or NULL for default values. */
yihui 1:a607cd9655d7 186 ble_gatts_attr_md_t* p_sccd_md; /**< Attribute metadata for the Server Characteristic Configuration Descriptor, or NULL for default values. */
yihui 1:a607cd9655d7 187 } ble_gatts_char_md_t;
yihui 1:a607cd9655d7 188
yihui 1:a607cd9655d7 189
yihui 1:a607cd9655d7 190 /**@brief GATT Characteristic Definition Handles. */
yihui 1:a607cd9655d7 191 typedef struct
yihui 1:a607cd9655d7 192 {
yihui 1:a607cd9655d7 193 uint16_t value_handle; /**< Handle to the characteristic value. */
yihui 1:a607cd9655d7 194 uint16_t user_desc_handle; /**< Handle to the User Description descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
yihui 1:a607cd9655d7 195 uint16_t cccd_handle; /**< Handle to the Client Characteristic Configuration Descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
yihui 1:a607cd9655d7 196 uint16_t sccd_handle; /**< Handle to the Server Characteristic Configuration Descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
yihui 1:a607cd9655d7 197 } ble_gatts_char_handles_t;
yihui 1:a607cd9655d7 198
yihui 1:a607cd9655d7 199
yihui 1:a607cd9655d7 200 /**@brief GATT HVx parameters. */
yihui 1:a607cd9655d7 201 typedef struct
yihui 1:a607cd9655d7 202 {
yihui 1:a607cd9655d7 203 uint16_t handle; /**< Characteristic Value Handle. */
yihui 1:a607cd9655d7 204 uint8_t type; /**< Indication or Notification, see @ref BLE_GATT_HVX_TYPES. */
yihui 1:a607cd9655d7 205 uint16_t offset; /**< Offset within the attribute value. */
yihui 1:a607cd9655d7 206 uint16_t* p_len; /**< Length in bytes to be written, length in bytes written after successful return. */
yihui 1:a607cd9655d7 207 uint8_t* p_data; /**< Actual data content, use NULL to use the current attribute value. */
yihui 1:a607cd9655d7 208 } ble_gatts_hvx_params_t;
yihui 1:a607cd9655d7 209
yihui 1:a607cd9655d7 210 /**@brief GATT Read Authorization parameters. */
yihui 1:a607cd9655d7 211 typedef struct
yihui 1:a607cd9655d7 212 {
yihui 1:a607cd9655d7 213 uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */
yihui 1:a607cd9655d7 214 uint8_t update : 1; /**< If set, data supplied in p_data will be used in the ATT response. */
yihui 1:a607cd9655d7 215 uint16_t offset; /**< Offset of the attribute value being updated. */
yihui 1:a607cd9655d7 216 uint16_t len; /**< Length in bytes of the value in p_data pointer, see @ref BLE_GATTS_ATTR_LENS_MAX. */
yihui 1:a607cd9655d7 217 uint8_t* p_data; /**< Pointer to new value used to update the attribute value. */
yihui 1:a607cd9655d7 218 } ble_gatts_read_authorize_params_t;
yihui 1:a607cd9655d7 219
yihui 1:a607cd9655d7 220 /**@brief GATT Write Authorisation parameters. */
yihui 1:a607cd9655d7 221 typedef struct
yihui 1:a607cd9655d7 222 {
yihui 1:a607cd9655d7 223 uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */
yihui 1:a607cd9655d7 224 } ble_gatts_write_authorize_params_t;
yihui 1:a607cd9655d7 225
yihui 1:a607cd9655d7 226 /**@brief GATT Read or Write Authorize Reply parameters. */
yihui 1:a607cd9655d7 227 typedef struct
yihui 1:a607cd9655d7 228 {
yihui 1:a607cd9655d7 229 uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */
yihui 1:a607cd9655d7 230 union {
yihui 1:a607cd9655d7 231 ble_gatts_read_authorize_params_t read; /**< Read authorization parameters. */
yihui 1:a607cd9655d7 232 ble_gatts_write_authorize_params_t write; /**< Write authorization parameters. */
yihui 1:a607cd9655d7 233 } params;
yihui 1:a607cd9655d7 234 } ble_gatts_rw_authorize_reply_params_t;
yihui 1:a607cd9655d7 235
yihui 1:a607cd9655d7 236
yihui 1:a607cd9655d7 237 /**
yihui 1:a607cd9655d7 238 * @brief GATT Server Event IDs.
yihui 1:a607cd9655d7 239 */
yihui 1:a607cd9655d7 240 enum BLE_GATTS_EVTS
yihui 1:a607cd9655d7 241 {
yihui 1:a607cd9655d7 242 BLE_GATTS_EVT_WRITE = BLE_GATTS_EVT_BASE, /**< Write operation performed. */
yihui 1:a607cd9655d7 243 BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST, /**< Read/Write Authorization request. */
yihui 1:a607cd9655d7 244 BLE_GATTS_EVT_SYS_ATTR_MISSING, /**< A persistent system attribute access is pending, awaiting a sd_ble_gatts_sys_attr_set(). */
yihui 1:a607cd9655d7 245 BLE_GATTS_EVT_HVC, /**< Handle Value Confirmation. */
yihui 1:a607cd9655d7 246 BLE_GATTS_EVT_SC_CONFIRM, /**< Service Changed Confirmation. */
yihui 1:a607cd9655d7 247 BLE_GATTS_EVT_TIMEOUT /**< Timeout. */
yihui 1:a607cd9655d7 248 };
yihui 1:a607cd9655d7 249
yihui 1:a607cd9655d7 250
yihui 1:a607cd9655d7 251 /**@brief Event structure for BLE_GATTS_EVT_WRITE. */
yihui 1:a607cd9655d7 252 typedef struct
yihui 1:a607cd9655d7 253 {
yihui 1:a607cd9655d7 254 uint16_t handle; /**< Attribute Handle. */
yihui 1:a607cd9655d7 255 uint8_t op; /**< Type of write operation, see @ref BLE_GATTS_OPS. */
yihui 1:a607cd9655d7 256 ble_gatts_attr_context_t context; /**< Attribute Context. */
yihui 1:a607cd9655d7 257 uint16_t offset; /**< Offset for the write operation. */
yihui 1:a607cd9655d7 258 uint16_t len; /**< Length of the incoming data. */
yihui 1:a607cd9655d7 259 uint8_t data[1]; /**< Incoming data, variable length. */
yihui 1:a607cd9655d7 260 } ble_gatts_evt_write_t;
yihui 1:a607cd9655d7 261
yihui 1:a607cd9655d7 262 /**@brief Event structure for authorize read request. */
yihui 1:a607cd9655d7 263 typedef struct
yihui 1:a607cd9655d7 264 {
yihui 1:a607cd9655d7 265 uint16_t handle; /**< Attribute Handle. */
yihui 1:a607cd9655d7 266 ble_gatts_attr_context_t context; /**< Attribute Context. */
yihui 1:a607cd9655d7 267 uint16_t offset; /**< Offset for the read operation. */
yihui 1:a607cd9655d7 268 } ble_gatts_evt_read_t;
yihui 1:a607cd9655d7 269
yihui 1:a607cd9655d7 270 /**@brief Event structure for BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. */
yihui 1:a607cd9655d7 271 typedef struct
yihui 1:a607cd9655d7 272 {
yihui 1:a607cd9655d7 273 uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */
yihui 1:a607cd9655d7 274 union {
yihui 1:a607cd9655d7 275 ble_gatts_evt_read_t read; /**< Attribute Read Parameters. */
yihui 1:a607cd9655d7 276 ble_gatts_evt_write_t write; /**< Attribute Write Parameters. */
yihui 1:a607cd9655d7 277 } request;
yihui 1:a607cd9655d7 278 } ble_gatts_evt_rw_authorize_request_t;
yihui 1:a607cd9655d7 279
yihui 1:a607cd9655d7 280 /**@brief Event structure for BLE_GATTS_EVT_SYS_ATTR_MISSING. */
yihui 1:a607cd9655d7 281 typedef struct
yihui 1:a607cd9655d7 282 {
yihui 1:a607cd9655d7 283 uint8_t hint;
yihui 1:a607cd9655d7 284 } ble_gatts_evt_sys_attr_missing_t;
yihui 1:a607cd9655d7 285
yihui 1:a607cd9655d7 286
yihui 1:a607cd9655d7 287 /**@brief Event structure for BLE_GATTS_EVT_HVC. */
yihui 1:a607cd9655d7 288 typedef struct
yihui 1:a607cd9655d7 289 {
yihui 1:a607cd9655d7 290 uint16_t handle; /**< Attribute Handle. */
yihui 1:a607cd9655d7 291 } ble_gatts_evt_hvc_t;
yihui 1:a607cd9655d7 292
yihui 1:a607cd9655d7 293 /**@brief Event structure for BLE_GATTS_EVT_TIMEOUT. */
yihui 1:a607cd9655d7 294 typedef struct
yihui 1:a607cd9655d7 295 {
yihui 1:a607cd9655d7 296 uint8_t src; /**< Timeout source, see @ref BLE_GATT_TIMEOUT_SOURCES. */
yihui 1:a607cd9655d7 297 } ble_gatts_evt_timeout_t;
yihui 1:a607cd9655d7 298
yihui 1:a607cd9655d7 299
yihui 1:a607cd9655d7 300 /**@brief GATT Server event callback event structure. */
yihui 1:a607cd9655d7 301 typedef struct
yihui 1:a607cd9655d7 302 {
yihui 1:a607cd9655d7 303 uint16_t conn_handle; /**< Connection Handle on which event occurred. */
yihui 1:a607cd9655d7 304 union
yihui 1:a607cd9655d7 305 {
yihui 1:a607cd9655d7 306 ble_gatts_evt_write_t write; /**< Write Event Parameters. */
yihui 1:a607cd9655d7 307 ble_gatts_evt_rw_authorize_request_t authorize_request; /**< Read or Write Authorize Request Parameters. */
yihui 1:a607cd9655d7 308 ble_gatts_evt_sys_attr_missing_t sys_attr_missing; /**< System attributes missing. */
yihui 1:a607cd9655d7 309 ble_gatts_evt_hvc_t hvc; /**< Handle Value Confirmation Event Parameters. */
yihui 1:a607cd9655d7 310 ble_gatts_evt_timeout_t timeout; /**< Timeout Event. */
yihui 1:a607cd9655d7 311 } params;
yihui 1:a607cd9655d7 312 } ble_gatts_evt_t;
yihui 1:a607cd9655d7 313
yihui 1:a607cd9655d7 314 /** @} */
yihui 1:a607cd9655d7 315
yihui 1:a607cd9655d7 316 /** @addtogroup BLE_GATTS_FUNCTIONS Functions
yihui 1:a607cd9655d7 317 * @{ */
yihui 1:a607cd9655d7 318
yihui 1:a607cd9655d7 319 /**@brief Add a service declaration to the local server ATT table.
yihui 1:a607cd9655d7 320 *
yihui 1:a607cd9655d7 321 * @param[in] type Toggles between primary and secondary services, see @ref BLE_GATTS_SRVC_TYPES.
yihui 1:a607cd9655d7 322 * @param[in] p_uuid Pointer to service UUID.
yihui 1:a607cd9655d7 323 * @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored.
yihui 1:a607cd9655d7 324 *
yihui 1:a607cd9655d7 325 * @note Secondary Services are only relevant in the context of the entity that references them, it is therefore forbidden to
yihui 1:a607cd9655d7 326 * add a secondary service declaration that is not referenced by another service later in the ATT table.
yihui 1:a607cd9655d7 327 *
yihui 1:a607cd9655d7 328 * @return @ref NRF_SUCCESS Successfully added a service declaration.
yihui 1:a607cd9655d7 329 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
yihui 1:a607cd9655d7 330 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, Vendor Specific UUIDs need to be present in the table.
yihui 1:a607cd9655d7 331 * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
yihui 1:a607cd9655d7 332 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
yihui 1:a607cd9655d7 333 */
yihui 1:a607cd9655d7 334 SVCALL(SD_BLE_GATTS_SERVICE_ADD, uint32_t, sd_ble_gatts_service_add(uint8_t type, ble_uuid_t const*const p_uuid, uint16_t *const p_handle));
yihui 1:a607cd9655d7 335
yihui 1:a607cd9655d7 336
yihui 1:a607cd9655d7 337 /**@brief Add an include declaration to the local server ATT table.
yihui 1:a607cd9655d7 338 *
yihui 1:a607cd9655d7 339 * @note It is currently only possible to add an include declaration to the last added service (i.e. only sequential addition is supported at this time).
yihui 1:a607cd9655d7 340 *
yihui 1:a607cd9655d7 341 * @note The included service must already be present in the ATT table prior to this call.
yihui 1:a607cd9655d7 342 *
yihui 1:a607cd9655d7 343 * @param[in] service_handle Handle of the service where the included service is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
yihui 1:a607cd9655d7 344 * @param[in] inc_srvc_handle Handle of the included service.
yihui 1:a607cd9655d7 345 * @param[out] p_include_handle Pointer to a 16-bit word where the assigned handle will be stored.
yihui 1:a607cd9655d7 346 *
yihui 1:a607cd9655d7 347 * @return @ref NRF_SUCCESS Successfully added an include declaration.
yihui 1:a607cd9655d7 348 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
yihui 1:a607cd9655d7 349 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, handle values need to match previously added services.
yihui 1:a607cd9655d7 350 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
yihui 1:a607cd9655d7 351 * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, self inclusions are not allowed.
yihui 1:a607cd9655d7 352 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
yihui 1:a607cd9655d7 353 * @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
yihui 1:a607cd9655d7 354 */
yihui 1:a607cd9655d7 355 SVCALL(SD_BLE_GATTS_INCLUDE_ADD, uint32_t, sd_ble_gatts_include_add(uint16_t service_handle, uint16_t inc_srvc_handle, uint16_t *const p_include_handle));
yihui 1:a607cd9655d7 356
yihui 1:a607cd9655d7 357
yihui 1:a607cd9655d7 358 /**@brief Add a characteristic declaration, a characteristic value declaration and optional characteristic descriptor declarations to the local server ATT table.
yihui 1:a607cd9655d7 359 *
yihui 1:a607cd9655d7 360 * @note It is currently only possible to add a characteristic to the last added service (i.e. only sequential addition is supported at this time).
yihui 1:a607cd9655d7 361 *
yihui 1:a607cd9655d7 362 * @note Several restrictions apply to the parameters, such as matching permissions between the user description descriptor and the writeable auxiliaries bits,
yihui 1:a607cd9655d7 363 * readable (no security) and writeable (selectable) CCCDs and SCCDs and valid presentation format values.
yihui 1:a607cd9655d7 364 *
yihui 1:a607cd9655d7 365 * @note If no metadata is provided for the optional descriptors, their permissions will be derived from the characteristic permissions.
yihui 1:a607cd9655d7 366 *
yihui 1:a607cd9655d7 367 * @param[in] service_handle Handle of the service where the characteristic is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
yihui 1:a607cd9655d7 368 * @param[in] p_char_md Characteristic metadata.
yihui 1:a607cd9655d7 369 * @param[in] p_attr_char_value Pointer to the attribute structure corresponding to the characteristic value.
yihui 1:a607cd9655d7 370 * @param[out] p_handles Pointer to the structure where the assigned handles will be stored.
yihui 1:a607cd9655d7 371 *
yihui 1:a607cd9655d7 372 * @return @ref NRF_SUCCESS Successfully added a characteristic.
yihui 1:a607cd9655d7 373 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
yihui 1:a607cd9655d7 374 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, service handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
yihui 1:a607cd9655d7 375 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, a service context is required.
yihui 1:a607cd9655d7 376 * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
yihui 1:a607cd9655d7 377 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
yihui 1:a607cd9655d7 378 * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
yihui 1:a607cd9655d7 379 */
yihui 1:a607cd9655d7 380 SVCALL(SD_BLE_GATTS_CHARACTERISTIC_ADD, uint32_t, sd_ble_gatts_characteristic_add(uint16_t service_handle, ble_gatts_char_md_t const*const p_char_md, ble_gatts_attr_t const*const p_attr_char_value, ble_gatts_char_handles_t *const p_handles));
yihui 1:a607cd9655d7 381
yihui 1:a607cd9655d7 382
yihui 1:a607cd9655d7 383 /**@brief Add a descriptor to the local server ATT table.
yihui 1:a607cd9655d7 384 *
yihui 1:a607cd9655d7 385 * @note It is currently only possible to add a descriptor to the last added characteristic (i.e. only sequential addition is supported at this time).
yihui 1:a607cd9655d7 386 *
yihui 1:a607cd9655d7 387 * @param[in] char_handle Handle of the characteristic where the descriptor is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
yihui 1:a607cd9655d7 388 * @param[in] p_attr Pointer to the attribute structure.
yihui 1:a607cd9655d7 389 * @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored.
yihui 1:a607cd9655d7 390 *
yihui 1:a607cd9655d7 391 * @return @ref NRF_SUCCESS Successfully added a descriptor.
yihui 1:a607cd9655d7 392 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
yihui 1:a607cd9655d7 393 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, characteristic handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
yihui 1:a607cd9655d7 394 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, a characteristic context is required.
yihui 1:a607cd9655d7 395 * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
yihui 1:a607cd9655d7 396 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
yihui 1:a607cd9655d7 397 * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
yihui 1:a607cd9655d7 398 */
yihui 1:a607cd9655d7 399 SVCALL(SD_BLE_GATTS_DESCRIPTOR_ADD, uint32_t, sd_ble_gatts_descriptor_add(uint16_t char_handle, ble_gatts_attr_t const * const p_attr, uint16_t* const p_handle));
yihui 1:a607cd9655d7 400
yihui 1:a607cd9655d7 401 /**@brief Set the value of a given attribute.
yihui 1:a607cd9655d7 402 *
yihui 1:a607cd9655d7 403 * @param[in] handle Attribute handle.
yihui 1:a607cd9655d7 404 * @param[in] offset Offset in bytes to write from.
yihui 1:a607cd9655d7 405 * @param[in,out] p_len Length in bytes to be written, length in bytes written after successful return.
yihui 1:a607cd9655d7 406 * @param[in] p_value Pointer to a buffer (at least len bytes long) containing the desired attribute value. If value is stored in user memory, only the attribute length is updated when p_value == NULL.
yihui 1:a607cd9655d7 407 *
yihui 1:a607cd9655d7 408 * @return @ref NRF_SUCCESS Successfully set the value of the attribute.
yihui 1:a607cd9655d7 409 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
yihui 1:a607cd9655d7 410 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
yihui 1:a607cd9655d7 411 * @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
yihui 1:a607cd9655d7 412 * @return @ref NRF_ERROR_FORBIDDEN Forbidden handle supplied, certain attributes are not modifiable by the application.
yihui 1:a607cd9655d7 413 * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
yihui 1:a607cd9655d7 414 */
yihui 1:a607cd9655d7 415 SVCALL(SD_BLE_GATTS_VALUE_SET, uint32_t, sd_ble_gatts_value_set(uint16_t handle, uint16_t offset, uint16_t* const p_len, uint8_t const * const p_value));
yihui 1:a607cd9655d7 416
yihui 1:a607cd9655d7 417 /**@brief Get the value of a given attribute.
yihui 1:a607cd9655d7 418 *
yihui 1:a607cd9655d7 419 * @param[in] handle Attribute handle.
yihui 1:a607cd9655d7 420 * @param[in] offset Offset in bytes to read from.
yihui 1:a607cd9655d7 421 * @param[in,out] p_len Length in bytes to be read, total length of attribute value (in bytes, starting from offset) after successful return.
yihui 1:a607cd9655d7 422 * @param[in,out] p_data Pointer to a buffer (at least len bytes long) where to store the attribute value. Set to NULL to obtain the complete length of attribute value.
yihui 1:a607cd9655d7 423 *
yihui 1:a607cd9655d7 424 * @note If the attribute value is longer than the size of the supplied buffer,
yihui 1:a607cd9655d7 425 * p_len will return the total attribute value length (excluding offset),
yihui 1:a607cd9655d7 426 * and not the number of bytes actually returned in p_data.
yihui 1:a607cd9655d7 427 * The application may use this information to allocate a suitable buffer size.
yihui 1:a607cd9655d7 428 *
yihui 1:a607cd9655d7 429 * @return @ref NRF_SUCCESS Successfully retrieved the value of the attribute.
yihui 1:a607cd9655d7 430 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
yihui 1:a607cd9655d7 431 * @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
yihui 1:a607cd9655d7 432 */
yihui 1:a607cd9655d7 433 SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t handle, uint16_t offset, uint16_t *const p_len, uint8_t* const p_data));
yihui 1:a607cd9655d7 434
yihui 1:a607cd9655d7 435 /**@brief Notify or Indicate an attribute value.
yihui 1:a607cd9655d7 436 *
yihui 1:a607cd9655d7 437 * @details This function checks for the relevant Client Characteristic Configuration descriptor value to verify that the relevant operation
yihui 1:a607cd9655d7 438 * (notification or indication) has been enabled by the client. It is also able to update the attribute value before issuing the PDU, so that
yihui 1:a607cd9655d7 439 * the application can atomically perform a value update and a server initiated transaction with a single API call.
yihui 1:a607cd9655d7 440 * If the application chooses to indicate an attribute value, a @ref BLE_GATTS_EVT_HVC will be sent up as soon as the confirmation arrives from
yihui 1:a607cd9655d7 441 * the peer.
yihui 1:a607cd9655d7 442 *
yihui 1:a607cd9655d7 443 * @note The local attribute value may be updated even if an outgoing packet is not sent to the peer due to an error during execution.
yihui 1:a607cd9655d7 444 * When receiveing the error codes @ref NRF_ERROR_INVALID_STATE, @ref NRF_ERROR_BUSY, @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING and
yihui 1:a607cd9655d7 445 * @ref BLE_ERROR_NO_TX_BUFFERS the ATT table has been updated.
yihui 1:a607cd9655d7 446 * The caller can check whether the value has been updated by looking at the contents of *(p_hvx_params->p_len).
yihui 1:a607cd9655d7 447 *
yihui 1:a607cd9655d7 448 * @note It is important to note that a notification will <b>consume an application buffer</b>, and will therefore
yihui 1:a607cd9655d7 449 * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. An indication on the other hand will use the
yihui 1:a607cd9655d7 450 * standard server internal buffer and thus will only generate a @ref BLE_GATTS_EVT_HVC event as soon as the confirmation
yihui 1:a607cd9655d7 451 * has been received from the peer. Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
yihui 1:a607cd9655d7 452 *
yihui 1:a607cd9655d7 453 * @param[in] conn_handle Connection handle.
yihui 1:a607cd9655d7 454 * @param[in] p_hvx_params Pointer to an HVx parameters structure. If the p_data member contains a non-NULL pointer the attribute value will be updated with
yihui 1:a607cd9655d7 455 * the contents pointed by it before sending the notification or indication.
yihui 1:a607cd9655d7 456 *
yihui 1:a607cd9655d7 457 * @return @ref NRF_SUCCESS Successfully queued a notification or indication for transmission, and optionally updated the attribute value.
yihui 1:a607cd9655d7 458 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
yihui 1:a607cd9655d7 459 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
yihui 1:a607cd9655d7 460 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
yihui 1:a607cd9655d7 461 * @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied. Only attributes added directly by the application are available to notify and indicate.
yihui 1:a607cd9655d7 462 * @return @ref BLE_ERROR_GATTS_INVALID_ATTR_TYPE Invalid attribute type(s) supplied, only characteristic values may be notified and indicated.
yihui 1:a607cd9655d7 463 * @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
yihui 1:a607cd9655d7 464 * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
yihui 1:a607cd9655d7 465 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD.
yihui 1:a607cd9655d7 466 * @return @ref NRF_ERROR_BUSY Procedure already in progress.
yihui 1:a607cd9655d7 467 * @return @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
yihui 1:a607cd9655d7 468 * @return @ref BLE_ERROR_NO_TX_BUFFERS There are no available buffers to send the data, applies only to notifications.
yihui 1:a607cd9655d7 469 */
yihui 1:a607cd9655d7 470 SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const*const p_hvx_params));
yihui 1:a607cd9655d7 471
yihui 1:a607cd9655d7 472 /**@brief Indicate the Service Changed attribute value.
yihui 1:a607cd9655d7 473 *
yihui 1:a607cd9655d7 474 * @details This call will send a Handle Value Indication to one or more peers connected to inform them that the attribute
yihui 1:a607cd9655d7 475 * table layout has changed. As soon as the peer has confirmed the indication, a @ref BLE_GATTS_EVT_SC_CONFIRM event will
yihui 1:a607cd9655d7 476 * be issued.
yihui 1:a607cd9655d7 477 *
yihui 1:a607cd9655d7 478 * @note Some of the restrictions and limitations that apply to @ref sd_ble_gatts_hvx also apply here.
yihui 1:a607cd9655d7 479 *
yihui 1:a607cd9655d7 480 * @param[in] conn_handle Connection handle.
yihui 1:a607cd9655d7 481 * @param[in] start_handle Start of affected attribute handle range.
yihui 1:a607cd9655d7 482 * @param[in] end_handle End of affected attribute handle range.
yihui 1:a607cd9655d7 483 *
yihui 1:a607cd9655d7 484 * @return @ref NRF_SUCCESS Successfully queued the Service Changed indication for transmission.
yihui 1:a607cd9655d7 485 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
yihui 1:a607cd9655d7 486 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
yihui 1:a607cd9655d7 487 * @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied, handles must be in the range populated by the application.
yihui 1:a607cd9655d7 488 * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD.
yihui 1:a607cd9655d7 489 * @return @ref NRF_ERROR_BUSY Procedure already in progress.
yihui 1:a607cd9655d7 490 * @return @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
yihui 1:a607cd9655d7 491 */
yihui 1:a607cd9655d7 492 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));
yihui 1:a607cd9655d7 493
yihui 1:a607cd9655d7 494 /**@brief Respond to a Read/Write authorization request.
yihui 1:a607cd9655d7 495 *
yihui 1:a607cd9655d7 496 * @note This call should only be used as a response to a @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event issued to the application.
yihui 1:a607cd9655d7 497 *
yihui 1:a607cd9655d7 498 * @param[in] conn_handle Connection handle.
yihui 1:a607cd9655d7 499 * @param[in] p_rw_authorize_reply_params Pointer to a structure with the attribute provided by the application.
yihui 1:a607cd9655d7 500 *
yihui 1:a607cd9655d7 501 * @return @ref NRF_SUCCESS Successfully queued a response to the peer, and in the case of a write operation, ATT table updated.
yihui 1:a607cd9655d7 502 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
yihui 1:a607cd9655d7 503 * @return @ref NRF_ERROR_INVALID_STATE No authorization request pending.
yihui 1:a607cd9655d7 504 * @return @ref NRF_ERROR_INVALID_PARAM Authorization op invalid,
yihui 1:a607cd9655d7 505 * or for Read Authorization reply: requested handles not replied with,
yihui 1:a607cd9655d7 506 * or for Write Authorization reply: handle supplied does not match requested handle.
yihui 1:a607cd9655d7 507 */
yihui 1:a607cd9655d7 508 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*const p_rw_authorize_reply_params));
yihui 1:a607cd9655d7 509
yihui 1:a607cd9655d7 510
yihui 1:a607cd9655d7 511 /**@brief Update persistent system attribute information.
yihui 1:a607cd9655d7 512 *
yihui 1:a607cd9655d7 513 * @details Supply to the stack information about persistent system attributes.
yihui 1:a607cd9655d7 514 * This call is legal in the connected state only, and is usually
yihui 1:a607cd9655d7 515 * made immediately after a connection is established and the bond identified.
yihui 1:a607cd9655d7 516 * usually as a response to a BLE_GATTS_EVT_SYS_ATTR_MISSING.
yihui 1:a607cd9655d7 517 *
yihui 1:a607cd9655d7 518 * p_sysattrs may point directly to the application's stored copy of the struct.
yihui 1:a607cd9655d7 519 * If the pointer is NULL, the system attribute info is initialized, assuming that
yihui 1:a607cd9655d7 520 * the application does not have any previously saved data for this bond.
yihui 1:a607cd9655d7 521 *
yihui 1:a607cd9655d7 522 * @note The state of persistent system attributes is reset upon connection and then remembered for its duration.
yihui 1:a607cd9655d7 523 *
yihui 1:a607cd9655d7 524 * @note If this call returns with an error code different from @ref NRF_SUCCESS, the storage of persistent system attributes may have been completed only partially.
yihui 1:a607cd9655d7 525 * This means that the state of the attribute table is undefined, and the application should either provide a new set of attributes using this same call or
yihui 1:a607cd9655d7 526 * reset the SoftDevice to return to a known state.
yihui 1:a607cd9655d7 527 *
yihui 1:a607cd9655d7 528 * @param[in] conn_handle Connection handle.
yihui 1:a607cd9655d7 529 * @param[in] p_sys_attr_data Pointer to a saved copy of system attributes supplied to the stack, or NULL.
yihui 1:a607cd9655d7 530 * @param[in] len Size of data pointed by p_sys_attr_data, in octets.
yihui 1:a607cd9655d7 531 *
yihui 1:a607cd9655d7 532 * @return @ref NRF_SUCCESS Successfully set the system attribute information.
yihui 1:a607cd9655d7 533 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
yihui 1:a607cd9655d7 534 * @return @ref NRF_ERROR_INVALID_DATA Invalid data supplied, the data should be exactly the same as retrieved with @ref sd_ble_gatts_sys_attr_get.
yihui 1:a607cd9655d7 535 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
yihui 1:a607cd9655d7 536 */
yihui 1:a607cd9655d7 537 SVCALL(SD_BLE_GATTS_SYS_ATTR_SET, uint32_t, sd_ble_gatts_sys_attr_set(uint16_t conn_handle, uint8_t const*const p_sys_attr_data, uint16_t len));
yihui 1:a607cd9655d7 538
yihui 1:a607cd9655d7 539
yihui 1:a607cd9655d7 540 /**@brief Retrieve persistent system attribute information from the stack.
yihui 1:a607cd9655d7 541 *
yihui 1:a607cd9655d7 542 * @details This call is used to retrieve information about values to be stored perisistently by the application
yihui 1:a607cd9655d7 543 * after a connection has been terminated. When a new connection is made to the same bond, the values
yihui 1:a607cd9655d7 544 * should be restored using @ref sd_ble_gatts_sys_attr_set.
yihui 1:a607cd9655d7 545 * The data should be read before any new advertising is started, or any new connection established. The connection handle for
yihui 1:a607cd9655d7 546 * the previous now defunct connection will remain valid until a new one is created to allow this API call to refer to it.
yihui 1:a607cd9655d7 547 *
yihui 1:a607cd9655d7 548 * @param[in] conn_handle Connection handle of the recently terminated connection.
yihui 1:a607cd9655d7 549 * @param[in] p_sys_attr_data Pointer to a buffer where updated information about system attributes will be filled in. NULL can be provided to
yihui 1:a607cd9655d7 550 * obtain the length of the data
yihui 1:a607cd9655d7 551 * @param[in,out] p_len Size of application buffer if p_sys_attr_data is not NULL. Unconditially updated to actual length of system attribute data.
yihui 1:a607cd9655d7 552 *
yihui 1:a607cd9655d7 553 * @return @ref NRF_SUCCESS Successfully retrieved the system attribute information.
yihui 1:a607cd9655d7 554 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
yihui 1:a607cd9655d7 555 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
yihui 1:a607cd9655d7 556 * @return @ref NRF_ERROR_DATA_SIZE The system attribute information did not fit into the provided buffer.
yihui 1:a607cd9655d7 557 */
yihui 1:a607cd9655d7 558 SVCALL(SD_BLE_GATTS_SYS_ATTR_GET, uint32_t, sd_ble_gatts_sys_attr_get(uint16_t conn_handle, uint8_t * const p_sys_attr_data, uint16_t* const p_len));
yihui 1:a607cd9655d7 559
yihui 1:a607cd9655d7 560 /** @} */
yihui 1:a607cd9655d7 561
yihui 1:a607cd9655d7 562 #endif // BLE_GATTS_H__
yihui 1:a607cd9655d7 563
yihui 1:a607cd9655d7 564 /**
yihui 1:a607cd9655d7 565 @}
yihui 1:a607cd9655d7 566 */