For scoop
Fork of nRF51822 by
Embed:
(wiki syntax)
Show/hide line numbers
ble_gatts.h
00001 /* 00002 * Copyright (c) Nordic Semiconductor ASA 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 00016 * contributors to this software may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * 4. This software must only be used in a processor manufactured by Nordic 00020 * Semiconductor ASA, or in a processor manufactured by a third party that 00021 * is used in combination with a processor manufactured by Nordic Semiconductor. 00022 * 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00025 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00026 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00028 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00031 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 */ 00036 00037 /** 00038 @addtogroup BLE_GATTS Generic Attribute Profile (GATT) Server 00039 @{ 00040 @brief Definitions and prototypes for the GATTS interface. 00041 */ 00042 00043 #ifndef BLE_GATTS_H__ 00044 #define BLE_GATTS_H__ 00045 00046 #include "ble_types.h" 00047 #include "ble_ranges.h" 00048 #include "ble_l2cap.h" 00049 #include "ble_gap.h" 00050 #include "ble_gatt.h" 00051 #include "nrf_svc.h" 00052 00053 /** @addtogroup BLE_GATTS_ENUMERATIONS Enumerations 00054 * @{ */ 00055 00056 /** 00057 * @brief GATTS API SVC numbers. 00058 */ 00059 enum BLE_GATTS_SVCS 00060 { 00061 SD_BLE_GATTS_SERVICE_ADD = BLE_GATTS_SVC_BASE, /**< Add a service. */ 00062 SD_BLE_GATTS_INCLUDE_ADD, /**< Add an included service. */ 00063 SD_BLE_GATTS_CHARACTERISTIC_ADD, /**< Add a characteristic. */ 00064 SD_BLE_GATTS_DESCRIPTOR_ADD, /**< Add a generic attribute. */ 00065 SD_BLE_GATTS_VALUE_SET, /**< Set an attribute value. */ 00066 SD_BLE_GATTS_VALUE_GET, /**< Get an attribute value. */ 00067 SD_BLE_GATTS_HVX, /**< Handle Value Notification or Indication. */ 00068 SD_BLE_GATTS_SERVICE_CHANGED, /**< Perform a Service Changed Indication to one or more peers. */ 00069 SD_BLE_GATTS_RW_AUTHORIZE_REPLY, /**< Reply to an authorization request for a read or write operation on one or more attributes. */ 00070 SD_BLE_GATTS_SYS_ATTR_SET, /**< Set the persistent system attributes for a connection. */ 00071 SD_BLE_GATTS_SYS_ATTR_GET, /**< Retrieve the persistent system attributes. */ 00072 }; 00073 00074 /** 00075 * @brief GATT Server Event IDs. 00076 */ 00077 enum BLE_GATTS_EVTS 00078 { 00079 BLE_GATTS_EVT_WRITE = BLE_GATTS_EVT_BASE, /**< Write operation performed. @ref ble_gatts_evt_write_t */ 00080 BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST, /**< Read/Write Authorization request.@ref ble_gatts_evt_rw_authorize_request_t */ 00081 BLE_GATTS_EVT_SYS_ATTR_MISSING, /**< A persistent system attribute access is pending, awaiting a sd_ble_gatts_sys_attr_set(). @ref ble_gatts_evt_sys_attr_missing_t */ 00082 BLE_GATTS_EVT_HVC, /**< Handle Value Confirmation. @ref ble_gatts_evt_hvc_t */ 00083 BLE_GATTS_EVT_SC_CONFIRM, /**< Service Changed Confirmation. No additional event structure applies. */ 00084 BLE_GATTS_EVT_TIMEOUT /**< Timeout. @ref ble_gatts_evt_timeout_t */ 00085 }; 00086 /** @} */ 00087 00088 /** @addtogroup BLE_GATTS_DEFINES Defines 00089 * @{ */ 00090 00091 /** @defgroup BLE_ERRORS_GATTS SVC return values specific to GATTS 00092 * @{ */ 00093 #define BLE_ERROR_GATTS_INVALID_ATTR_TYPE (NRF_GATTS_ERR_BASE + 0x000) /**< Invalid attribute type. */ 00094 #define BLE_ERROR_GATTS_SYS_ATTR_MISSING (NRF_GATTS_ERR_BASE + 0x001) /**< System Attributes missing. */ 00095 /** @} */ 00096 00097 /** @defgroup BLE_GATTS_ATTR_LENS_MAX Maximum attribute lengths 00098 * @{ */ 00099 #define BLE_GATTS_FIX_ATTR_LEN_MAX (510) /**< Maximum length for fixed length Attribute Values. */ 00100 #define BLE_GATTS_VAR_ATTR_LEN_MAX (512) /**< Maximum length for variable length Attribute Values. */ 00101 /** @} */ 00102 00103 /** @defgroup BLE_GATTS_SRVC_TYPES GATT Server Service Types 00104 * @{ */ 00105 #define BLE_GATTS_SRVC_TYPE_INVALID 0x00 /**< Invalid Service Type. */ 00106 #define BLE_GATTS_SRVC_TYPE_PRIMARY 0x01 /**< Primary Service. */ 00107 #define BLE_GATTS_SRVC_TYPE_SECONDARY 0x02 /**< Secondary Type. */ 00108 /** @} */ 00109 00110 00111 /** @defgroup BLE_GATTS_ATTR_TYPES GATT Server Attribute Types 00112 * @{ */ 00113 #define BLE_GATTS_ATTR_TYPE_INVALID 0x00 /**< Invalid Attribute Type. */ 00114 #define BLE_GATTS_ATTR_TYPE_PRIM_SRVC_DECL 0x01 /**< Primary Service Declaration. */ 00115 #define BLE_GATTS_ATTR_TYPE_SEC_SRVC_DECL 0x02 /**< Secondary Service Declaration. */ 00116 #define BLE_GATTS_ATTR_TYPE_INC_DECL 0x03 /**< Include Declaration. */ 00117 #define BLE_GATTS_ATTR_TYPE_CHAR_DECL 0x04 /**< Characteristic Declaration. */ 00118 #define BLE_GATTS_ATTR_TYPE_CHAR_VAL 0x05 /**< Characteristic Value. */ 00119 #define BLE_GATTS_ATTR_TYPE_DESC 0x06 /**< Descriptor. */ 00120 #define BLE_GATTS_ATTR_TYPE_OTHER 0x07 /**< Other, non-GATT specific type. */ 00121 /** @} */ 00122 00123 00124 /** @defgroup BLE_GATTS_OPS GATT Server Operations 00125 * @{ */ 00126 #define BLE_GATTS_OP_INVALID 0x00 /**< Invalid Operation. */ 00127 #define BLE_GATTS_OP_WRITE_REQ 0x01 /**< Write Request. */ 00128 #define BLE_GATTS_OP_WRITE_CMD 0x02 /**< Write Command. */ 00129 #define BLE_GATTS_OP_SIGN_WRITE_CMD 0x03 /**< Signed Write Command. */ 00130 #define BLE_GATTS_OP_PREP_WRITE_REQ 0x04 /**< Prepare Write Request. */ 00131 #define BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL 0x05 /**< Execute Write Request: Cancel all prepared writes. */ 00132 #define BLE_GATTS_OP_EXEC_WRITE_REQ_NOW 0x06 /**< Execute Write Request: Immediately execute all prepared writes. */ 00133 /** @} */ 00134 00135 /** @defgroup BLE_GATTS_VLOCS GATT Value Locations 00136 * @{ */ 00137 #define BLE_GATTS_VLOC_INVALID 0x00 /**< Invalid Location. */ 00138 #define BLE_GATTS_VLOC_STACK 0x01 /**< Attribute Value is located in stack memory, no user memory is required. */ 00139 #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 00140 will read and write directly to the memory using the pointer provided in the APIs. There are no alignment requirements for the buffer. */ 00141 /** @} */ 00142 00143 /** @defgroup BLE_GATTS_AUTHORIZE_TYPES GATT Server Authorization Types 00144 * @{ */ 00145 #define BLE_GATTS_AUTHORIZE_TYPE_INVALID 0x00 /**< Invalid Type. */ 00146 #define BLE_GATTS_AUTHORIZE_TYPE_READ 0x01 /**< Authorize a Read Operation. */ 00147 #define BLE_GATTS_AUTHORIZE_TYPE_WRITE 0x02 /**< Authorize a Write Request Operation. */ 00148 /** @} */ 00149 00150 /** @defgroup BLE_GATTS_SYS_ATTR_FLAGS System Attribute Flags 00151 * @{ */ 00152 #define BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS (1 << 0) /**< Restrict system attributes to system services only. */ 00153 #define BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS (1 << 1) /**< Restrict system attributes to user services only. */ 00154 /** @} */ 00155 00156 /** @defgroup BLE_GATTS_ATTR_TAB_SIZE Attribute Table size 00157 * @{ 00158 */ 00159 #define BLE_GATTS_ATTR_TAB_SIZE_MIN 216 /**< Minimum Attribute Table size */ 00160 #define BLE_GATTS_ATTR_TAB_SIZE_DEFAULT 0x0000 /**< Default Attribute Table size (0x600 bytes for this version of the SoftDevice). */ 00161 /** @} */ 00162 00163 /** @} */ 00164 00165 /** @addtogroup BLE_GATTS_STRUCTURES Structures 00166 * @{ */ 00167 00168 /** 00169 * @brief BLE GATTS init options 00170 */ 00171 typedef struct 00172 { 00173 uint8_t service_changed:1; /**< Include the Service Changed characteristic in the Attribute Table. */ 00174 uint32_t attr_tab_size; /**< Attribute Table size in bytes. The size must be a multiple of 4. @ref BLE_GATTS_ATTR_TAB_SIZE_DEFAULT is used to set the default size. */ 00175 } ble_gatts_enable_params_t; 00176 00177 /**@brief Attribute metadata. */ 00178 typedef struct 00179 { 00180 ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */ 00181 ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */ 00182 uint8_t vlen :1; /**< Variable length attribute. */ 00183 uint8_t vloc :2; /**< Value location, see @ref BLE_GATTS_VLOCS.*/ 00184 uint8_t rd_auth :1; /**< Read authorization and value will be requested from the application on every read operation. */ 00185 uint8_t wr_auth :1; /**< Write authorization will be requested from the application on every Write Request operation (but not Write Command). */ 00186 } ble_gatts_attr_md_t; 00187 00188 00189 /**@brief GATT Attribute. */ 00190 typedef struct 00191 { 00192 ble_uuid_t *p_uuid; /**< Pointer to the attribute UUID. */ 00193 ble_gatts_attr_md_t *p_attr_md; /**< Pointer to the attribute metadata structure. */ 00194 uint16_t init_len; /**< Initial attribute value length in bytes. */ 00195 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. */ 00196 uint16_t max_len; /**< Maximum attribute value length in bytes, see @ref BLE_GATTS_ATTR_LENS_MAX for maximum values. */ 00197 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 00198 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. 00199 The stack may access that memory directly without the application's knowledge. For writable characteristics, this value must not be a location in flash memory.*/ 00200 } ble_gatts_attr_t; 00201 00202 /**@brief GATT Attribute Value. */ 00203 typedef struct 00204 { 00205 uint16_t len; /**< Length in bytes to be written or read. Length in bytes written or read after successful return.*/ 00206 uint16_t offset; /**< Attribute value offset. */ 00207 uint8_t *p_value; /**< Pointer to where value is stored or will be stored. 00208 If value is stored in user memory, only the attribute length is updated when p_value == NULL. 00209 Set to NULL when reading to obtain the complete length of the attribute value */ 00210 } ble_gatts_value_t; 00211 00212 00213 /**@brief GATT Attribute Context. */ 00214 typedef struct 00215 { 00216 ble_uuid_t srvc_uuid; /**< Service UUID. */ 00217 ble_uuid_t char_uuid; /**< Characteristic UUID if applicable (BLE_UUID_TYPE_UNKNOWN otherwise). */ 00218 ble_uuid_t desc_uuid; /**< Descriptor UUID if applicable (BLE_UUID_TYPE_UNKNOWN otherwise). */ 00219 uint16_t srvc_handle; /**< Service Handle. */ 00220 uint16_t value_handle; /**< Characteristic Value Handle if applicable (BLE_GATT_HANDLE_INVALID otherwise). */ 00221 uint8_t type; /**< Attribute Type, see @ref BLE_GATTS_ATTR_TYPES. */ 00222 } ble_gatts_attr_context_t; 00223 00224 00225 /**@brief GATT Characteristic Presentation Format. */ 00226 typedef struct 00227 { 00228 uint8_t format; /**< Format of the value, see @ref BLE_GATT_CPF_FORMATS. */ 00229 int8_t exponent; /**< Exponent for integer data types. */ 00230 uint16_t unit; /**< Unit from Bluetooth Assigned Numbers. */ 00231 uint8_t name_space; /**< Namespace from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */ 00232 uint16_t desc; /**< Namespace description from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */ 00233 } ble_gatts_char_pf_t; 00234 00235 00236 /**@brief GATT Characteristic metadata. */ 00237 typedef struct 00238 { 00239 ble_gatt_char_props_t char_props; /**< Characteristic Properties. */ 00240 ble_gatt_char_ext_props_t char_ext_props; /**< Characteristic Extended Properties. */ 00241 uint8_t *p_char_user_desc; /**< Pointer to a UTF-8 encoded string (non-NULL terminated), NULL if the descriptor is not required. */ 00242 uint16_t char_user_desc_max_size; /**< The maximum size in bytes of the user description descriptor. */ 00243 uint16_t char_user_desc_size; /**< The size of the user description, must be smaller or equal to char_user_desc_max_size. */ 00244 ble_gatts_char_pf_t* p_char_pf; /**< Pointer to a presentation format structure or NULL if the CPF descriptor is not required. */ 00245 ble_gatts_attr_md_t* p_user_desc_md; /**< Attribute metadata for the User Description descriptor, or NULL for default values. */ 00246 ble_gatts_attr_md_t* p_cccd_md; /**< Attribute metadata for the Client Characteristic Configuration Descriptor, or NULL for default values. */ 00247 ble_gatts_attr_md_t* p_sccd_md; /**< Attribute metadata for the Server Characteristic Configuration Descriptor, or NULL for default values. */ 00248 } ble_gatts_char_md_t; 00249 00250 00251 /**@brief GATT Characteristic Definition Handles. */ 00252 typedef struct 00253 { 00254 uint16_t value_handle; /**< Handle to the characteristic value. */ 00255 uint16_t user_desc_handle; /**< Handle to the User Description descriptor, or @ref BLE_GATT_HANDLE_INVALID if not present. */ 00256 uint16_t cccd_handle; /**< Handle to the Client Characteristic Configuration Descriptor, or @ref BLE_GATT_HANDLE_INVALID if not present. */ 00257 uint16_t sccd_handle; /**< Handle to the Server Characteristic Configuration Descriptor, or @ref BLE_GATT_HANDLE_INVALID if not present. */ 00258 } ble_gatts_char_handles_t; 00259 00260 00261 /**@brief GATT HVx parameters. */ 00262 typedef struct 00263 { 00264 uint16_t handle; /**< Characteristic Value Handle. */ 00265 uint8_t type; /**< Indication or Notification, see @ref BLE_GATT_HVX_TYPES. */ 00266 uint16_t offset; /**< Offset within the attribute value. */ 00267 uint16_t *p_len; /**< Length in bytes to be written, length in bytes written after successful return. */ 00268 uint8_t *p_data; /**< Actual data content, use NULL to use the current attribute value. */ 00269 } ble_gatts_hvx_params_t; 00270 00271 /**@brief GATT Read Authorization parameters. */ 00272 typedef struct 00273 { 00274 uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */ 00275 uint8_t update : 1; /**< If set, data supplied in p_data will be used in the ATT response. */ 00276 uint16_t offset; /**< Offset of the attribute value being updated. */ 00277 uint16_t len; /**< Length in bytes of the value in p_data pointer, see @ref BLE_GATTS_ATTR_LENS_MAX. */ 00278 uint8_t *p_data; /**< Pointer to new value used to update the attribute value. */ 00279 } ble_gatts_read_authorize_params_t; 00280 00281 /**@brief GATT Write Authorization parameters. */ 00282 typedef struct 00283 { 00284 uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */ 00285 } ble_gatts_write_authorize_params_t; 00286 00287 /**@brief GATT Read or Write Authorize Reply parameters. */ 00288 typedef struct 00289 { 00290 uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */ 00291 union { 00292 ble_gatts_read_authorize_params_t read; /**< Read authorization parameters. */ 00293 ble_gatts_write_authorize_params_t write; /**< Write authorization parameters. */ 00294 } params; /**< Reply Parameters. */ 00295 } ble_gatts_rw_authorize_reply_params_t; 00296 00297 00298 00299 /**@brief Event structure for @ref BLE_GATTS_EVT_WRITE. */ 00300 typedef struct 00301 { 00302 uint16_t handle; /**< Attribute Handle. */ 00303 uint8_t op; /**< Type of write operation, see @ref BLE_GATTS_OPS. */ 00304 ble_gatts_attr_context_t context; /**< Attribute Context. */ 00305 uint16_t offset; /**< Offset for the write operation. */ 00306 uint16_t len; /**< Length of the received data. */ 00307 uint8_t data[1]; /**< Received data, variable length. */ 00308 } ble_gatts_evt_write_t; 00309 00310 /**@brief Event substructure for authorized read requests, see @ref ble_gatts_evt_rw_authorize_request_t. */ 00311 typedef struct 00312 { 00313 uint16_t handle; /**< Attribute Handle. */ 00314 ble_gatts_attr_context_t context; /**< Attribute Context. */ 00315 uint16_t offset; /**< Offset for the read operation. */ 00316 } ble_gatts_evt_read_t; 00317 00318 /**@brief Event structure for @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. */ 00319 typedef struct 00320 { 00321 uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */ 00322 union { 00323 ble_gatts_evt_read_t read; /**< Attribute Read Parameters. */ 00324 ble_gatts_evt_write_t write; /**< Attribute Write Parameters. */ 00325 } request; /**< Request Parameters. */ 00326 } ble_gatts_evt_rw_authorize_request_t; 00327 00328 /**@brief Event structure for @ref BLE_GATTS_EVT_SYS_ATTR_MISSING. */ 00329 typedef struct 00330 { 00331 uint8_t hint; /**< Hint (currently unused). */ 00332 } ble_gatts_evt_sys_attr_missing_t; 00333 00334 00335 /**@brief Event structure for @ref BLE_GATTS_EVT_HVC. */ 00336 typedef struct 00337 { 00338 uint16_t handle; /**< Attribute Handle. */ 00339 } ble_gatts_evt_hvc_t; 00340 00341 /**@brief Event structure for @ref BLE_GATTS_EVT_TIMEOUT. */ 00342 typedef struct 00343 { 00344 uint8_t src; /**< Timeout source, see @ref BLE_GATT_TIMEOUT_SOURCES. */ 00345 } ble_gatts_evt_timeout_t; 00346 00347 00348 /**@brief GATT Server event callback event structure. */ 00349 typedef struct 00350 { 00351 uint16_t conn_handle; /**< Connection Handle on which the event occurred. */ 00352 union 00353 { 00354 ble_gatts_evt_write_t write; /**< Write Event Parameters. */ 00355 ble_gatts_evt_rw_authorize_request_t authorize_request; /**< Read or Write Authorize Request Parameters. */ 00356 ble_gatts_evt_sys_attr_missing_t sys_attr_missing; /**< System attributes missing. */ 00357 ble_gatts_evt_hvc_t hvc; /**< Handle Value Confirmation Event Parameters. */ 00358 ble_gatts_evt_timeout_t timeout; /**< Timeout Event. */ 00359 } params; /**< Event Parameters. */ 00360 } ble_gatts_evt_t; 00361 00362 /** @} */ 00363 00364 /** @addtogroup BLE_GATTS_FUNCTIONS Functions 00365 * @{ */ 00366 00367 /**@brief Add a service declaration to the Attribute Table. 00368 * 00369 * @param[in] type Toggles between primary and secondary services, see @ref BLE_GATTS_SRVC_TYPES. 00370 * @param[in] p_uuid Pointer to service UUID. 00371 * @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored. 00372 * 00373 * @note Secondary Services are only relevant in the context of the entity that references them, it is therefore forbidden to 00374 * add a secondary service declaration that is not referenced by another service later in the Attribute Table. 00375 * 00376 * @retval ::NRF_SUCCESS Successfully added a service declaration. 00377 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00378 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, Vendor Specific UUIDs need to be present in the table. 00379 * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack. 00380 * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation. 00381 */ 00382 SVCALL(SD_BLE_GATTS_SERVICE_ADD, uint32_t, sd_ble_gatts_service_add(uint8_t type, ble_uuid_t const *p_uuid, uint16_t *p_handle)); 00383 00384 00385 /**@brief Add an include declaration to the Attribute Table. 00386 * 00387 * @note It is currently only possible to add an include declaration to the last added service (i.e. only sequential population is supported at this time). 00388 * 00389 * @note The included service must already be present in the Attribute Table prior to this call. 00390 * 00391 * @param[in] service_handle Handle of the service where the included service is to be placed, if @ref BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially. 00392 * @param[in] inc_srvc_handle Handle of the included service. 00393 * @param[out] p_include_handle Pointer to a 16-bit word where the assigned handle will be stored. 00394 * 00395 * @retval ::NRF_SUCCESS Successfully added an include declaration. 00396 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00397 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, handle values need to match previously added services. 00398 * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation. 00399 * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, self inclusions are not allowed. 00400 * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation. 00401 * @retval ::NRF_ERROR_NOT_FOUND Attribute not found. 00402 */ 00403 SVCALL(SD_BLE_GATTS_INCLUDE_ADD, uint32_t, sd_ble_gatts_include_add(uint16_t service_handle, uint16_t inc_srvc_handle, uint16_t *p_include_handle)); 00404 00405 00406 /**@brief Add a characteristic declaration, a characteristic value declaration and optional characteristic descriptor declarations to the Attribute Table. 00407 * 00408 * @note It is currently only possible to add a characteristic to the last added service (i.e. only sequential population is supported at this time). 00409 * 00410 * @note Several restrictions apply to the parameters, such as matching permissions between the user description descriptor and the writeable auxiliaries bits, 00411 * readable (no security) and writeable (selectable) CCCDs and SCCDs and valid presentation format values. 00412 * 00413 * @note If no metadata is provided for the optional descriptors, their permissions will be derived from the characteristic permissions. 00414 * 00415 * @param[in] service_handle Handle of the service where the characteristic is to be placed, if @ref BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially. 00416 * @param[in] p_char_md Characteristic metadata. 00417 * @param[in] p_attr_char_value Pointer to the attribute structure corresponding to the characteristic value. 00418 * @param[out] p_handles Pointer to the structure where the assigned handles will be stored. 00419 * 00420 * @retval ::NRF_SUCCESS Successfully added a characteristic. 00421 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00422 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, service handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints. 00423 * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation, a service context is required. 00424 * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack. 00425 * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation. 00426 * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX. 00427 */ 00428 SVCALL(SD_BLE_GATTS_CHARACTERISTIC_ADD, uint32_t, sd_ble_gatts_characteristic_add(uint16_t service_handle, ble_gatts_char_md_t const *p_char_md, ble_gatts_attr_t const *p_attr_char_value, ble_gatts_char_handles_t *p_handles)); 00429 00430 00431 /**@brief Add a descriptor to the Attribute Table. 00432 * 00433 * @note It is currently only possible to add a descriptor to the last added characteristic (i.e. only sequential population is supported at this time). 00434 * 00435 * @param[in] char_handle Handle of the characteristic where the descriptor is to be placed, if @ref BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially. 00436 * @param[in] p_attr Pointer to the attribute structure. 00437 * @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored. 00438 * 00439 * @retval ::NRF_SUCCESS Successfully added a descriptor. 00440 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00441 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, characteristic handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints. 00442 * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation, a characteristic context is required. 00443 * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack. 00444 * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation. 00445 * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX. 00446 */ 00447 SVCALL(SD_BLE_GATTS_DESCRIPTOR_ADD, uint32_t, sd_ble_gatts_descriptor_add(uint16_t char_handle, ble_gatts_attr_t const *p_attr, uint16_t *p_handle)); 00448 00449 /**@brief Set the value of a given attribute. 00450 * 00451 * @param[in] conn_handle Connection handle. If the value does not belong to a system attribute then @ref BLE_CONN_HANDLE_INVALID can be used. 00452 * @param[in] handle Attribute handle. 00453 * @param[in,out] p_value Attribute value information. 00454 * 00455 * @note Values other than system attributes can be set at any time, regardless of wheter any active connections exist. 00456 * 00457 * @retval ::NRF_SUCCESS Successfully set the value of the attribute. 00458 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00459 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied. 00460 * @retval ::NRF_ERROR_NOT_FOUND Attribute not found. 00461 * @retval ::NRF_ERROR_FORBIDDEN Forbidden handle supplied, certain attributes are not modifiable by the application. 00462 * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX. 00463 * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied. 00464 * @retval ::BLE_ERROR_GATTS_INVALID_ATTR_TYPE @ref BLE_CONN_HANDLE_INVALID supplied on a system attribute. 00465 */ 00466 SVCALL(SD_BLE_GATTS_VALUE_SET, uint32_t, sd_ble_gatts_value_set(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t *p_value)); 00467 00468 /**@brief Get the value of a given attribute. 00469 * 00470 * @param[in] conn_handle Connection handle. If the value does not belong to a system attribute then @ref BLE_CONN_HANDLE_INVALID can be used. 00471 * @param[in] handle Attribute handle. 00472 * @param[in,out] p_value Attribute value information. 00473 * 00474 * @note If the attribute value is longer than the size of the supplied buffer, 00475 * p_len will return the total attribute value length (excluding offset), 00476 * and not the number of bytes actually returned in p_data. 00477 * The application may use this information to allocate a suitable buffer size. 00478 * 00479 * @note When retrieving system attribute values with this function, the connection handle 00480 * may refer to an already disconnected connection. Refer to the documentation of 00481 * @ref sd_ble_gatts_sys_attr_get for further information. 00482 * 00483 * @retval ::NRF_SUCCESS Successfully retrieved the value of the attribute. 00484 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00485 * @retval ::NRF_ERROR_NOT_FOUND Attribute not found. 00486 * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied. 00487 * @retval ::BLE_ERROR_GATTS_INVALID_ATTR_TYPE @ref BLE_CONN_HANDLE_INVALID supplied on a system attribute. 00488 */ 00489 SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t *p_value)); 00490 00491 /**@brief Notify or Indicate an attribute value. 00492 * 00493 * @details This function checks for the relevant Client Characteristic Configuration descriptor value to verify that the relevant operation 00494 * (notification or indication) has been enabled by the client. It is also able to update the attribute value before issuing the PDU, so that 00495 * the application can atomically perform a value update and a server initiated transaction with a single API call. 00496 * If the application chooses to indicate an attribute value, a @ref BLE_GATTS_EVT_HVC event will be issued as soon as the confirmation arrives from 00497 * the peer. 00498 * 00499 * @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. 00500 * When receiveing the error codes @ref NRF_ERROR_INVALID_STATE, @ref NRF_ERROR_BUSY, @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING and 00501 * @ref BLE_ERROR_NO_TX_BUFFERS the Attribute Table has been updated. 00502 * The caller can check whether the value has been updated by looking at the contents of *(p_hvx_params->p_len). 00503 * 00504 * @note It is important to note that a notification will <b>consume an application buffer</b>, and will therefore 00505 * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. An indication on the other hand will use the 00506 * standard server internal buffer and thus will only generate a @ref BLE_GATTS_EVT_HVC event as soon as the confirmation 00507 * has been received from the peer. Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details. 00508 * 00509 * @param[in] conn_handle Connection handle. 00510 * @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 00511 * the contents pointed by it before sending the notification or indication. 00512 * 00513 * @retval ::NRF_SUCCESS Successfully queued a notification or indication for transmission, and optionally updated the attribute value. 00514 * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00515 * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or notifications and/or indications not enabled in the CCCD. 00516 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00517 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied. 00518 * @retval ::BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied. Only attributes added directly by the application are available to notify and indicate. 00519 * @retval ::BLE_ERROR_GATTS_INVALID_ATTR_TYPE Invalid attribute type(s) supplied, only characteristic values may be notified and indicated. 00520 * @retval ::NRF_ERROR_NOT_FOUND Attribute not found. 00521 * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied. 00522 * @retval ::NRF_ERROR_BUSY Procedure already in progress. 00523 * @retval ::BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value. 00524 * @retval ::BLE_ERROR_NO_TX_BUFFERS There are no available buffers to send the data, applies only to notifications. 00525 */ 00526 SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const *p_hvx_params)); 00527 00528 /**@brief Indicate the Service Changed attribute value. 00529 * 00530 * @details This call will send a Handle Value Indication to one or more peers connected to inform them that the Attribute 00531 * Table layout has changed. As soon as the peer has confirmed the indication, a @ref BLE_GATTS_EVT_SC_CONFIRM event will 00532 * be issued. 00533 * 00534 * @note Some of the restrictions and limitations that apply to @ref sd_ble_gatts_hvx also apply here. 00535 * 00536 * @param[in] conn_handle Connection handle. 00537 * @param[in] start_handle Start of affected attribute handle range. 00538 * @param[in] end_handle End of affected attribute handle range. 00539 * 00540 * @retval ::NRF_SUCCESS Successfully queued the Service Changed indication for transmission. 00541 * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00542 * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or notifications and/or indications not enabled in the CCCD. 00543 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied. 00544 * @retval ::BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied, handles must be in the range populated by the application. 00545 * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD. 00546 * @retval ::NRF_ERROR_BUSY Procedure already in progress. 00547 * @retval ::BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value. 00548 */ 00549 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)); 00550 00551 /**@brief Respond to a Read/Write authorization request. 00552 * 00553 * @note This call should only be used as a response to a @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event issued to the application. 00554 * 00555 * @param[in] conn_handle Connection handle. 00556 * @param[in] p_rw_authorize_reply_params Pointer to a structure with the attribute provided by the application. 00557 * 00558 * @retval ::NRF_SUCCESS Successfully queued a response to the peer, and in the case of a write operation, Attribute Table updated. 00559 * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00560 * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or no authorization request pending. 00561 * @retval ::NRF_ERROR_INVALID_PARAM Authorization op invalid, 00562 * or for Read Authorization reply: requested handles not replied with, 00563 * or for Write Authorization reply: handle supplied does not match requested handle. 00564 * @retval ::NRF_ERROR_BUSY The stack is busy. Retry at later time. 00565 */ 00566 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 *p_rw_authorize_reply_params)); 00567 00568 00569 /**@brief Update persistent system attribute information. 00570 * 00571 * @details Supply information about persistent system attributes to the stack, 00572 * previously obtained using @ref sd_ble_gatts_sys_attr_get. 00573 * This call is only allowed for active connections, and is usually 00574 * made immediately after a connection is established with an known bonded device, 00575 * often as a response to a @ref BLE_GATTS_EVT_SYS_ATTR_MISSING. 00576 * 00577 * p_sysattrs may point directly to the application's stored copy of the system attributes 00578 * obtained using @ref sd_ble_gatts_sys_attr_get. 00579 * If the pointer is NULL, the system attribute info is initialized, assuming that 00580 * the application does not have any previously saved system attribute data for this device. 00581 * 00582 * @note The state of persistent system attributes is reset upon connection establishment and then remembered for its duration. 00583 * 00584 * @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. 00585 * 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 00586 * reset the SoftDevice to return to a known state. 00587 * 00588 * @note When the @ref BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS is used with this function, only the system attributes included in system services will be modified. 00589 * @note When the @ref BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS is used with this function, only the system attributes included in user services will be modified. 00590 * 00591 * @param[in] conn_handle Connection handle. 00592 * @param[in] p_sys_attr_data Pointer to a saved copy of system attributes supplied to the stack, or NULL. 00593 * @param[in] len Size of data pointed by p_sys_attr_data, in octets. 00594 * @param[in] flags Optional additional flags, see @ref BLE_GATTS_SYS_ATTR_FLAGS 00595 * 00596 * @retval ::NRF_SUCCESS Successfully set the system attribute information. 00597 * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00598 * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State. 00599 * @retval ::NRF_ERROR_INVALID_DATA Invalid data supplied, the data should be exactly the same as retrieved with @ref sd_ble_gatts_sys_attr_get. 00600 * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation. 00601 * @retval ::NRF_ERROR_BUSY The stack is busy. Retry at later time. 00602 */ 00603 SVCALL(SD_BLE_GATTS_SYS_ATTR_SET, uint32_t, sd_ble_gatts_sys_attr_set(uint16_t conn_handle, uint8_t const *p_sys_attr_data, uint16_t len, uint32_t flags)); 00604 00605 00606 /**@brief Retrieve persistent system attribute information from the stack. 00607 * 00608 * @details This call is used to retrieve information about values to be stored perisistently by the application 00609 * during the lifetime of a connection or after it has been terminated. When a new connection is established with the same bonded device, 00610 * the system attribute information retrieved with this function should be restored using using @ref sd_ble_gatts_sys_attr_set. 00611 * If retrieved after disconnection, the data should be read before a new connection established. The connection handle for 00612 * the previous, now disconnected, connection will remain valid until a new one is created to allow this API call to refer to it. 00613 * Connection handles belonging to active connections can be used as well, but care should be taken since the system attributes 00614 * may be written to at any time by the peer during a connection's lifetime. 00615 * 00616 * @note When the @ref BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS is used with this function, only the system attributes included in system services will be returned. 00617 * @note When the @ref BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS is used with this function, only the system attributes included in user services will be returned. 00618 * 00619 * @param[in] conn_handle Connection handle of the recently terminated connection. 00620 * @param[out] p_sys_attr_data Pointer to a buffer where updated information about system attributes will be filled in. NULL can be provided to 00621 * obtain the length of the data 00622 * @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. 00623 * @param[in] flags Optional additional flags, see @ref BLE_GATTS_SYS_ATTR_FLAGS 00624 * 00625 * @retval ::NRF_SUCCESS Successfully retrieved the system attribute information. 00626 * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00627 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00628 * @retval ::NRF_ERROR_DATA_SIZE The system attribute information did not fit into the provided buffer. 00629 * @retval ::NRF_ERROR_NOT_FOUND No system attributes found. 00630 */ 00631 SVCALL(SD_BLE_GATTS_SYS_ATTR_GET, uint32_t, sd_ble_gatts_sys_attr_get(uint16_t conn_handle, uint8_t *p_sys_attr_data, uint16_t *p_len, uint32_t flags)); 00632 00633 /** @} */ 00634 00635 #endif // BLE_GATTS_H__ 00636 00637 /** 00638 @} 00639 */
Generated on Tue Jul 12 2022 19:22:46 by 1.7.2