To get started with Seeed Tiny BLE, include detecting motion, button and battery level.

Dependencies:   BLE_API eMPL_MPU6050 mbed nRF51822

Committer:
yihui
Date:
Wed Apr 22 07:47:17 2015 +0000
Revision:
1:fc2f9d636751
update libraries; ; delete nRF51822/nordic-sdk/components/gpiote/app_gpiote.c to solve GPIOTE_IRQHandler multiply defined issue. temperarily change nRF51822 library to folder

Who changed what in which revision?

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