1 /** 2 **************************************************************************************** 3 * 4 * @file ble_gatts.h 5 * 6 * @brief BLE GATTS API 7 * 8 **************************************************************************************** 9 * @attention 10 #####Copyright (c) 2019 GOODIX 11 All rights reserved. 12 13 Redistribution and use in source and binary forms, with or without 14 modification, are permitted provided that the following conditions are met: 15 * Redistributions of source code must retain the above copyright 16 notice, this list of conditions and the following disclaimer. 17 * Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in the 19 documentation and/or other materials provided with the distribution. 20 * Neither the name of GOODIX nor the names of its contributors may be used 21 to endorse or promote products derived from this software without 22 specific prior written permission. 23 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 POSSIBILITY OF SUCH DAMAGE. 35 ***************************************************************************************** 36 */ 37 38 /** 39 * @addtogroup BLE 40 * @{ 41 */ 42 43 /** 44 * @addtogroup BLE_GATT Generic Attribute Profile (GATT) 45 * @{ 46 * @brief Definitions and prototypes for the GATT interface. 47 */ 48 49 /** 50 @addtogroup BLE_SDK_GATTS Generic Attribute Profile (GATT) Server 51 @{ 52 @brief Definitions and prototypes for the GATT server interface. 53 */ 54 55 56 #ifndef __BLE_GATTS_H__ 57 #define __BLE_GATTS_H__ 58 59 #include <stdint.h> 60 #include "ble_gatt.h" 61 62 /** @addtogroup BLE_GATTS_DEFINES Defines 63 * @{ */ 64 65 /** @defgroup BLE_GATTS_MAX_INC_SRVC_NUM Max Number of Included Services 66 * @{ */ 67 #define MAX_INC_SRVC_NUM (5) /**< The max number of Included Services a Primary/Secondary service 68 can have. Used by @ref gatts_create_db_t. */ 69 /** @} */ 70 71 /** @defgroup BLE_GATTS_ATTR_PERM_BIT Attribute Permission Bit 72 * @{ */ 73 #define BROADCAST (0x01) /**< In one byte, bit0 means: Broadcast bit. 74 Used by @ref BROADCAST_ENABLE. */ 75 #define READ (0x02) /**< In one byte, bit1 means: Read bit. 76 Used by @ref READ_PERM_UNSEC, @ref READ_PERM */ 77 #define WRITE_CMD (0x04) /**< In one byte, bit2 means: Write_cmd bit. 78 Used by @ref WRITE_CMD_PERM_UNSEC, @ref WRITE_CMD_PERM. */ 79 #define WRITE_REQ (0x08) /**< In one byte, bit3 means: Write_req bit. 80 Used by @ref WRITE_REQ_PERM_UNSEC, @ref WRITE_REQ_PERM. */ 81 #define NOTIFY (0x10) /**< In one byte, bit4 means: Notify bit. 82 Used by @ref NOTIFY_PERM_UNSEC, @ref NOTIFY_PERM. */ 83 #define INDICATE (0x20) /**< In one byte, bit5 means: Indicate bit. 84 Used by @ref INDICATE_PERM_UNSEC, @ref INDICATE_PERM */ 85 #define WRITE_SIGNED (0x40) /**< In one byte, bit6 means: Write_signed bit. 86 Used by @ref WRITE_SIGNED_PERM_UNSEC, @ref WRITE_SIGNED_PERM. */ 87 #define EXT_PROP (0x80) /**< In one byte, bit7 means: Ext_property bit. 88 Used by @ref EXT_PROP_ENABLE. */ 89 /** @} */ 90 91 /** @defgroup BLE_GATTS_ATTR_PERM_POS Attribute Permission Value Position 92 * @{ */ 93 #define READ_POS (0x00) /**< Bit position of read permission. Used by @ref READ_PERM. */ 94 #define WRITE_POS (0x02) /**< Bit position of write permission. Used by @ref WRITE_CMD_PERM, 95 @ref WRITE_REQ_PERM, @ref WRITE_SIGNED_PERM. */ 96 #define INDICATE_POS (0x04) /**< Bit position of indicate bit. Used by @ref INDICATE_PERM. */ 97 #define NOTIFY_POS (0x06) /**< Bit position of notify bit. Used by @ref NOTIFY_PERM. */ 98 /** @} */ 99 100 /** @defgroup BLE_GATTS_SEC_LEVEL Attribute and Service Access Rights 101 * @{ */ 102 103 #define NOAUTH (0x00) /**< LE security mode 1, level 1. 104 Link does not need to be encrypted or authenticated. 105 Parameter of @ref SRVC_PERM, @ref READ_PERM, 106 @ref WRITE_REQ_PERM, @ref WRITE_CMD_PERM, 107 @ref WRITE_SIGNED_PERM, @ref INDICATE_PERM, @ref NOTIFY_PERM. */ 108 #define UNAUTH (0x01) /**< LE security mode 1, level 2. 109 Link needs to be encrypted, but not to be authenticated. 110 Parameter of @ref SRVC_PERM, @ref READ_PERM, @ref WRITE_REQ_PERM, 111 @ref WRITE_CMD_PERM, @ref WRITE_SIGNED_PERM, @ref INDICATE_PERM, 112 @ref NOTIFY_PERM. */ 113 #define AUTH (0x02) /**< LE security mode 1, level 3. 114 Link needs to be encrypted and authenticated (MITM). 115 Parameter of @ref SRVC_PERM, @ref READ_PERM, @ref WRITE_REQ_PERM, 116 @ref WRITE_CMD_PERM, @ref WRITE_SIGNED_PERM, @ref INDICATE_PERM, 117 @ref NOTIFY_PERM. */ 118 #define SEC_CON (0x03) /**< LE security mode 1, level 4. 119 Link needs to be encrypted and authenticated (secure connections). 120 Parameter of @ref SRVC_PERM, @ref READ_PERM, @ref WRITE_REQ_PERM, 121 @ref WRITE_CMD_PERM, @ref WRITE_SIGNED_PERM, @ref INDICATE_PERM, 122 @ref NOTIFY_PERM. */ 123 /** @} */ 124 125 /** @defgroup BLE_GATTS_SEC_LEVEL_MASK Attribute and Service Security Level Mask 126 * @{ */ 127 #define SEC_LEVEL_MASK (0x03) /**< Security level mask. 128 Used by @ref SRVC_PERM, @ref READ_PERM, @ref WRITE_REQ_PERM, 129 @ref WRITE_CMD_PERM, @ref WRITE_SIGNED_PERM, @ref INDICATE_PERM, 130 @ref NOTIFY_PERM. */ 131 /** @} */ 132 133 /** @defgroup BLE_GATTS_UUID_TYPE Attribute and Service UUID Type 134 * @{ */ 135 #define UUID_TYPE_16 (0x00) /**< 16-bit UUID length. 136 Parameter of @ref SRVC_UUID_TYPE_SET, @ref ATT_UUID_TYPE_SET. */ 137 #define UUID_TYPE_128 (0x02) /**< 128-bit UUID length. 138 Parameter of @ref SRVC_UUID_TYPE_SET, @ref ATT_UUID_TYPE_SET. */ 139 /** @} */ 140 141 /** 142 * Service permissions 143 * 144 * | 7 | 6--5 | 4 | 3--2 | 1 | 0 | 145 * |----|--------|----|--------|----|----| 146 * |SEC |UUID_LEN|DIS | AUTH |EKS | MI | 147 * 148 * Bit [0] : Service is multi-instantiated (0 = not support; 1 = support) \n 149 * Bit [1] : Encryption key size must be 16 bytes (0 = not need; 1 = need) \n 150 * Bit [2-3]: Service permission (0 = NOAUTH; 1 = UNAUTH; 2 = AUTH; 3 = SEC_CON) \n 151 * Bit [4] : Disable the service (0 = no; 1 = yes) \n 152 * Bit [5-6]: UUID Length Type (0 = 16 bits; 2 = 128 bits) \n 153 * Bit [7] : Secondary Service (0 = Primary Service; 1 = Secondary Service) \n 154 */ 155 156 /** @defgroup BLE_GATTS_SRVC_PERM Service Permission 157 * @{ */ 158 #define SRVC_SECONDARY_SET (0x80) /**< Secondary service set. */ 159 #define SRVC_DISABLE (0x10) /**< Service disable. */ 160 #define SRVC_ENCRP_KEY_SIZE_16 (0x02) /**< 16 bytes service encryption key size . */ 161 #define SRVC_MULTI_ENABLE (0x01) /**< Service is multi-instantiated. */ 162 163 /**< Service UUID length set. See @ref BLE_GATTS_UUID_TYPE. */ 164 #define SRVC_UUID_TYPE_SET(uuid_len) ((uuid_len) << 5) 165 166 /**< Service permission authentication. See @ref BLE_GATTS_SEC_LEVEL. */ 167 #define SRVC_PERM(sec_level) (((sec_level) & SEC_LEVEL_MASK) << 2) 168 /** @} */ 169 170 /** 171 * Attribute permission 172 * 173 * | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7--6 | 5--4 | 3--2 | 1--0 | 174 * |----|----|----|----|----|----|----|----|--------|--------|--------|--------| 175 * |EXT | WS | I | N | WR | WC | RD | B | NP | IP | WP | RP | 176 * 177 * Bit [0-1]: Read permission (0 = NOAUTH; 1 = UNAUTH; 2 = AUTH; 3 = SEC_CON) \n 178 * Bit [2-3]: Write permission (0 = NOAUTH; 1 = UNAUTH; 2 = AUTH; 3 = SEC_CON) \n 179 * Bit [4-5]: Indicate permission (0 = NOAUTH; 1 = UNAUTH; 2 = AUTH; 3 = SEC_CON) \n 180 * Bit [6-7]: Notify permission (0 = NOAUTH; 1 = UNAUTH; 2 = AUTH; 3 = SEC_CON) \n 181 * 182 * Bit [8] : Broadcast permission \n 183 * Bit [9] : Read accepted \n 184 * Bit [10] : Write Command accepted \n 185 * Bit [11] : Write Request accepted \n 186 * Bit [12] : Notify accepted \n 187 * Bit [13] : Indicate accepted \n 188 * Bit [14] : Write Signed accepted \n 189 * Bit [15] : Extended Properties present \n 190 */ 191 192 /** @defgroup BLE_GATTS_ATTR_PERM Attribute Permission 193 * @{ */ 194 /**< Default Read permission. */ 195 #define READ_PERM_UNSEC (READ << 8) 196 /**< Read permission set. See @ref BLE_GATTS_SEC_LEVEL. */ 197 #define READ_PERM(sec_level) (READ << 8 | (((sec_level) & SEC_LEVEL_MASK) << READ_POS)) 198 /**< Default Write Permission. */ 199 #define WRITE_REQ_PERM_UNSEC (WRITE_REQ << 8) 200 /**< Write permission set. See @ref BLE_GATTS_SEC_LEVEL. */ 201 #define WRITE_REQ_PERM(sec_level) (WRITE_REQ << 8 | (((sec_level) & SEC_LEVEL_MASK) << WRITE_POS)) 202 /**< Default Write without Response Permission. */ 203 #define WRITE_CMD_PERM_UNSEC (WRITE_CMD << 8) 204 /**< Write without Response permission set. See @ref BLE_GATTS_SEC_LEVEL. */ 205 #define WRITE_CMD_PERM(sec_level) (WRITE_CMD << 8 | (((sec_level) & SEC_LEVEL_MASK) << WRITE_POS)) 206 /**< Default Authenticated Signed Write Permission. */ 207 #define WRITE_SIGNED_PERM_UNSEC (WRITE_SIGNED << 8) 208 /**< Authenticated Signed Write permission set. See @ref BLE_GATTS_SEC_LEVEL. */ 209 #define WRITE_SIGNED_PERM(sec_level) (WRITE_SIGNED << 8 | (((sec_level) & SEC_LEVEL_MASK) << WRITE_POS)) 210 /**< Default Indicate Permission. */ 211 #define INDICATE_PERM_UNSEC (INDICATE << 8) 212 /**< Indicate permission set. See @ref BLE_GATTS_SEC_LEVEL. */ 213 #define INDICATE_PERM(sec_level) (INDICATE << 8 | (((sec_level) & SEC_LEVEL_MASK) << INDICATE_POS)) 214 /**< Default Notify Permission. */ 215 #define NOTIFY_PERM_UNSEC (NOTIFY << 8) 216 /**< Notify permission set. See @ref BLE_GATTS_SEC_LEVEL. */ 217 #define NOTIFY_PERM(sec_level) (NOTIFY << 8 | (((sec_level) & SEC_LEVEL_MASK) << NOTIFY_POS)) 218 /**< Broadcast enable. */ 219 #define BROADCAST_ENABLE (BROADCAST << 8) 220 /**< Extended Properties enable. */ 221 #define EXT_PROP_ENABLE (EXT_PROP << 8) 222 /** @} */ 223 224 /** 225 * Attribute extend permission 226 * 227 * | 15 | 14--13 | 12 | 11--0 | 228 * |----|---------|----|-----------------------------------------------------------| 229 * | VL |UUID_LEN |EKS | RESERVED | 230 * 231 * Bit [0-11] : Reserved \n 232 * Bit [12] : Encryption key size must be 16 bytes (0 = not need; 1 = need) \n 233 * Bit [14-13]: UUID length type (0 = 16 bits; 2 = 128 bits) \n 234 * Bit [15] : Value location (0 = value saved in BLE Stack; 1 = value saved in user space) \n 235 */ 236 237 /** @defgroup BLE_GATTS_ATTR_EXT_PERM Attribute Extend Permission 238 * @{ */ 239 #define ATT_VAL_LOC_USER (1 << 15) /**< Value location which means value saved in user space, 240 the profile's read/write callback will be called. */ 241 #define ATT_VAL_LOC_STACK (0 << 15) /**< Value location which means value saved in BLE Stack. */ 242 #define ATT_ENC_KEY_SIZE_16 (0x1000) /**< 16 bytes attribute encryption key size . */ 243 244 /**< Attribute UUID length set. See @ref BLE_GATTS_UUID_TYPE */ 245 #define ATT_UUID_TYPE_SET(uuid_len) ((uuid_len) << 13) 246 /** @} */ 247 248 /** @} */ 249 250 /** @addtogroup BLE_GATTS_ENUMERATIONS Enumerations 251 * @{ */ 252 253 /** 254 * @brief Service table type. 255 */ 256 typedef enum { 257 SERVICE_TABLE_TYPE_16 = 0x00, /**< 16-bit service table type. */ 258 SERVICE_TABLE_TYPE_128, /**< 128-bit service table type. */ 259 } gatts_service_type_t; 260 261 /** @} */ 262 263 /** @addtogroup BLE_GATTS_STRUCTURES Structures 264 * @{ */ 265 266 /** 267 * @brief Service(16-bit UUID) description. 268 */ 269 typedef struct { 270 uint16_t uuid; /**< 16-bit LSB-first UUID */ 271 uint16_t perm; /**< Attribute permissions, see @ref BLE_GATTS_ATTR_PERM. \n 272 - For Primary/Secondary/Included Services, must be @ref READ_PERM_UNSEC. \n 273 - For Characteristic Declaration, must be @ref READ_PERM_UNSEC. \n 274 - For Characteristic Extended Properties, must be @ref READ_PERM_UNSEC. \n 275 - For Characteristic Presentation Format, must be @ref READ_PERM_UNSEC. \n 276 - For Characteristic Aggregate Format, must be @ref READ_PERM_UNSEC. */ 277 278 uint16_t ext_perm; /**< Attribute extended permissions, see @ref BLE_GATTS_ATTR_EXT_PERM. \n 279 - For Primary/Secondary/Included Services, this field is not used and should be set to 0.\n 280 - For Characteristic Declaration, this field is not used and should be set to 0. \n 281 - For Characteristic Extended Properties, this field is not used and should be set to 0. \n 282 - For Client Characteristic Configuration and Server Characteristic Configuration, 283 value must be saved in user space, user needn't to set this value location bit. 284 The UUID length type must be set to 0. */ 285 286 uint16_t max_size; /**< Attribute max size. \n 287 - For Primary/Secondary/Included Services, this field is not used, set to 0. \n 288 - For Characteristic Declaration, this field is not used, set to 0. \n 289 - For Characteristic Extended Properties, this field contains 2-byte value. \n 290 - For Client Characteristic Configuration and Server Characteristic Configuration, 291 this field is not used, set to 0. \n 292 - For others, this field is attribute max size. */ 293 } attm_desc_t; 294 295 /** 296 * @brief Service(128 bits UUID) description. 297 */ 298 typedef struct { 299 uint8_t uuid[16]; /**< 128 bits UUID LSB First. */ 300 uint16_t perm; /**< Attribute permissions, see @ref BLE_GATTS_ATTR_PERM. \n 301 - For Primary/Secondary/Included Services, must be @ref READ_PERM_UNSEC. \n 302 - For Characteristic Declaration, must be @ref READ_PERM_UNSEC. \n 303 - For Characteristic Extended Properties, must be @ref READ_PERM_UNSEC. \n 304 - For Characteristic Presentation Format, must be @ref READ_PERM_UNSEC. \n 305 - For Characteristic Aggregate Format, must be @ref READ_PERM_UNSEC. */ 306 307 uint16_t ext_perm; /**< Attribute extended permissions, see @ref BLE_GATTS_ATTR_EXT_PERM. \n 308 - For Primary/Secondary/Included Services, this field is not used, set to 0. \n 309 - For Characteristic Declaration, this field is not used, set to 0. \n 310 - For Characteristic Extended Properties, this field is not used, set to 0. \n 311 - For Client Characteristic Configuration and Server Characteristic Configuration, 312 value must be saved in user space, user needn't to set this value location bit. 313 The UUID length type must be set to 0. */ 314 315 uint16_t max_size; /**< Attribute max size. \n 316 - For Primary/Secondary/Included Services, this field is not used, set to 0. \n 317 - For Characteristic Declaration, this field is not used, set to 0. \n 318 - For Characteristic Extended Properties, this field contains 2-byte value. \n 319 - For Client Characteristic Configuration and Server Characteristic Configuration, 320 this field is not used, set to 0. \n 321 - For others, this field is attribute max size. */ 322 } attm_desc_128_t; 323 324 /** 325 * @brief Parameter of Added service description. 326 */ 327 typedef struct { 328 uint16_t *shdl; /**< Service start handle pointer. 329 If *shdl = 0, it returns a handle using the first available handle (*shdl is modified); 330 otherwise it verifies if the given start handle can be used to allocate handle range. */ 331 const uint8_t *uuid; /**< Service UUID pointer. The pointer points to the Service UUID LSB. */ 332 uint8_t *attr_tab_cfg; /**< Attribute table selector pointer. It can be set to NULL to select all items of 333 attribute table. Each bit matches with an attribute of attribute table. \n 334 EXAMPLE:if attr_tab_cfg points to array {0x3F, 0x03},it means that 335 the 0.1.2.3.4.5.8.9 items of attribute table will be added to database. */ 336 337 uint8_t max_nb_attr; /**< Number of attributes in attribute table. */ 338 union attribute_table { /**< Attribute table. */ 339 const attm_desc_t *attr_tab_16; /**< 16 bits service description. The pointer point to attribute 340 table of 16 bits service. See @ref attm_desc_t. */ 341 const attm_desc_128_t *attr_tab_128; /**< 128 bits service description. The pointer point to attribute 342 table of 128 bits service. See @ref attm_desc_128_t. */ 343 } attr_tab; /**< Attribute table. */ 344 uint16_t *inc_srvc_handle[MAX_INC_SRVC_NUM]; /**< Pointer array of Included Service start handle's address. */ 345 uint16_t inc_srvc_num; /**< Included Service number for this service. */ 346 uint8_t srvc_perm; /**< Service permission. See @ref BLE_GATTS_SRVC_PERM. */ 347 gatts_service_type_t attr_tab_type; /**< Service table type. See @ref gatts_service_type_t. */ 348 } gatts_create_db_t; 349 350 /** 351 * @brief GATT read attribute result description. 352 */ 353 typedef struct { 354 uint16_t handle; /**< Handle of the read attribute. */ 355 uint16_t length; /**< Length of read data. */ 356 uint8_t status; /**< Status of read operation by upper layers. See @ref BLE_STACK_ERROR_CODES.*/ 357 uint8_t *value; /**< Attribute value pointer. */ 358 } gatts_read_cfm_t; 359 360 /** 361 * @brief GATT write attribute result description. 362 */ 363 typedef struct { 364 uint16_t handle; /**< Handle of the attribute written. */ 365 uint8_t status; /**< Status of write operation by upper layers. See @ref BLE_STACK_ERROR_CODES.*/ 366 } gatts_write_cfm_t; 367 368 /** 369 * @brief GATT prepare write result description. 370 */ 371 typedef struct { 372 uint16_t handle; /**< Handle of the attribute in prepare write operation. */ 373 uint16_t length; /**< Current length of the attribute. */ 374 uint8_t status; /**< Status of prepare write operation by upper layers. See @ref BLE_STACK_ERROR_CODES.*/ 375 } gatts_prep_write_cfm_t; 376 377 378 /** 379 * @brief GATT sending Notification or Indication event param description. 380 */ 381 typedef struct { 382 gatt_evt_type_t type; /**< Request type (Notification/Indication). see @ref gatt_evt_type_t. */ 383 uint16_t handle; /**< Characteristic Value handle to be notified or indicated. */ 384 uint16_t length; /**< Length of Characteristic Value to be sent. */ 385 uint8_t *value; /**< Characteristic Value pointer. */ 386 } gatts_noti_ind_t; 387 388 /** @} */ 389 390 391 /** @addtogroup BLE_GATTS_FUNCTIONS Functions 392 * @{ */ 393 /** 394 **************************************************************************************** 395 * @brief Register a service's attribute list. 396 * 397 * @param[in, out] p_param: Pointer to the parameter used in creating databases. see @ref gatts_create_db_t. 398 * 399 * @retval ::SDK_SUCCESS: Database has been registered successfully. 400 * @retval ::SDK_ERR_POINTER_NULL: Param is NULL or param's members are NULL. 401 * @retval ::SDK_ERR_INVALID_PARAM: The member of param is invalid. 402 * @retval ::SDK_ERR_INVALID_HANDLE: The service handles can not be allocated. 403 * @retval ::SDK_ERR_NO_RESOURCES: There is not enough memory to allocate service buffer. 404 * @retval ::SDK_ERR_INVALID_PERM: Permissions of Client Characteristic Configuration or 405 * Server Characteristic Configuration are not set correctly. 406 **************************************************************************************** 407 */ 408 uint16_t ble_gatts_srvc_db_create(gatts_create_db_t *p_param); 409 410 /** 411 **************************************************************************************** 412 * @brief Update attribute value only if the attribute value is saved in the BLE Stack space. 413 * 414 * @param[in] handle: Attribute handle. 415 * @param[in] length: Size of the value to set. 416 * @param[in] offset: Data offset of the value in attribute value. 417 * @param[in] p_value: The value to set. If offset = 0, the value is the new attribute value; otherwise, 418 * the value is part of the new attribute value. 419 * 420 * @retval ::SDK_SUCCESS: Successfully update the attribute value. 421 * @retval ::SDK_ERR_POINTER_NULL: Value is NULL. 422 * @retval ::SDK_ERR_INVALID_HANDLE: Handle not exist in database. 423 * @retval ::SDK_ERR_REQ_NOT_SUPPORTED: Attribute data is not present in database or cannot be modified. 424 * @retval ::SDK_ERR_INVALID_ATT_VAL_LEN: New value length exceeds maximum attribute value length. 425 * @retval ::SDK_ERR_INVALID_OFFSET: Offset exceeds current attribute value length. 426 **************************************************************************************** 427 */ 428 uint16_t ble_gatts_value_set(uint16_t handle, uint16_t length, uint16_t offset, const uint8_t* p_value); 429 430 /** 431 **************************************************************************************** 432 * @brief Retrieve attribute value only if the attribute value is saved in the BLE Stack space. 433 * 434 * @param[in] handle: Attribute handle. 435 * @param[in,out] p_length: Input as buffer size and output as attribute value length. 436 * @param[out] p_value: Buffer to store attribute value when buffer size is enough. 437 * 438 * @retval ::SDK_SUCCESS: Attribute value retrieved successfully. 439 * @retval ::SDK_ERR_POINTER_NULL: The pointer to input buffer size or input buffer is NULL. 440 * @retval ::SDK_ERR_INVALID_HANDLE: Handle not exist in the database. 441 * @retval ::SDK_ERR_REQ_NOT_SUPPORTED: Attribute data is not present in database. 442 * @retval ::SDK_ERR_INVALID_ATT_VAL_LEN: Attribute data value size is bigger than buffer size. 443 * @retval ::SDK_ERR_APP_ERROR: Database is not correctly initialized by application. 444 **************************************************************************************** 445 */ 446 uint16_t ble_gatts_value_get(uint16_t handle, uint16_t* p_length, uint8_t* p_value); 447 448 /** 449 **************************************************************************************** 450 * @brief Update attribute permission. 451 * @note The modifications of attribute permission to 452 * service/character/include/character_extended_properties_descriptor declaration: not supported. \n 453 * The modifications of attribute permission to others: perm can be updated and EKS of ext_perm can be updated. 454 * See @ref BLE_GATTS_ATTR_PERM. 455 * 456 * @param[in] handle: Attribute handle. 457 * @param[in] perm: New attribute permission. 458 * @param[in] ext_perm: New attribute extended permission. 459 * 460 * @retval ::SDK_SUCCESS: Update attribute permission successfully. 461 * @retval ::SDK_ERR_INVALID_HANDLE: Handle not exist in the database. 462 * @retval ::SDK_ERR_REQ_NOT_SUPPORTED: Attribute permission can't be modified. 463 **************************************************************************************** 464 */ 465 uint16_t ble_gatts_attr_permission_set(uint16_t handle, uint16_t perm, uint16_t ext_perm); 466 467 /** 468 **************************************************************************************** 469 * @brief Retrieve attribute permission. 470 * 471 * @param[in] handle: Attribute handle. 472 * @param[out] p_perm: Attribute permission value to be returned. 473 * @param[out] p_ext_perm: Attribute extended permission value to be returned. 474 * 475 * @retval ::SDK_SUCCESS: Retrieve attribute permission successfully. 476 * @retval ::SDK_ERR_POINTER_NULL: Perm or ext_perm is NULL. 477 * @retval ::SDK_ERR_INVALID_HANDLE: Handle not exist in the database. 478 **************************************************************************************** 479 */ 480 uint16_t ble_gatts_attr_permission_get(uint16_t handle, uint16_t *p_perm, uint16_t *p_ext_perm); 481 482 /** 483 **************************************************************************************** 484 * @brief Respond to an attribute read request. It is used in profile read callback function 485 * @ref gatts_prf_cbs_t::app_gatts_read_cb 486 * to send attribute value to stack which is saved in user space. 487 * 488 * @note The status member gatts_read_cfm_t::status should be set to @ref BLE_ATT_ERR_INSUFF_AUTHOR 489 * to control the authorization of particular read operations of a client. 490 * 491 * @param[in] conn_idx: Current connection index. 492 * @param[in] p_param: Pointer to the parameters filled by profile. See @ref gatts_read_cfm_t. 493 * 494 * @retval ::SDK_SUCCESS: Send read confirm value to stack successfully. 495 * @retval ::SDK_ERR_POINTER_NULL: Param is NULL. 496 * @retval ::SDK_ERR_INVALID_CONN_IDX: Conidx is invalid. 497 * @retval ::SDK_ERR_NO_RESOURCES: Not enough resources. 498 **************************************************************************************** 499 */ 500 uint16_t ble_gatts_read_cfm(uint8_t conn_idx, const gatts_read_cfm_t *p_param); 501 502 /** 503 **************************************************************************************** 504 * @brief Respond to an attribute write request. It is used in profile write callback function 505 * @ref gatts_prf_cbs_t::app_gatts_write_cb to send write operation status to stack. 506 * 507 * @note The status member gatts_write_cfm_t::status should be set to @ref BLE_ATT_ERR_INSUFF_AUTHOR 508 * to control the authorization of particular client's write operation. 509 * 510 * @param[in] conn_idx: Current connection index. 511 * @param[in] p_param: Pointer to the parameters filled by profile. see @ref gatts_write_cfm_t. 512 * 513 * @retval ::SDK_SUCCESS: Send write confirm status to stack successfully. 514 * @retval ::SDK_ERR_POINTER_NULL: Param is NULL. 515 * @retval ::SDK_ERR_INVALID_CONN_IDX: Conidx is invalid. 516 * @retval ::SDK_ERR_NO_RESOURCES: Not enough resources. 517 **************************************************************************************** 518 */ 519 uint16_t ble_gatts_write_cfm(uint8_t conn_idx, const gatts_write_cfm_t *p_param); 520 521 /** 522 **************************************************************************************** 523 * @brief Respond to an attribute prepare write request. It is used in profile prepare write callback 524 * function @ref gatts_prf_cbs_t::app_gatts_prep_write_cb to send prepare write operation status to stack. 525 * 526 * @note The status member gatts_prep_write_cfm_t::status should be set to @ref BLE_ATT_ERR_INSUFF_AUTHOR 527 * to control the authorization of particular client's write operation. 528 * 529 * @param[in] conn_idx: Current connection index. 530 * @param[in] p_param: Pointer to the parameters filled by profile. see @ref gatts_prep_write_cfm_t. 531 * 532 * @retval ::SDK_SUCCESS: Send prepare write confirm status to stack successfully. 533 * @retval ::SDK_ERR_POINTER_NULL: Param is NULL. 534 * @retval ::SDK_ERR_INVALID_CONN_IDX: Conidx is invalid. 535 * @retval ::SDK_ERR_NO_RESOURCES: Not enough resources. 536 **************************************************************************************** 537 */ 538 uint16_t ble_gatts_prepare_write_cfm(uint8_t conn_idx, const gatts_prep_write_cfm_t *p_param); 539 540 /** 541 **************************************************************************************** 542 * @brief Send out a notification or an indication. The execution status of sending notification or 543 * indication will be retrieved in the complete callback function @ref gatts_prf_cbs_t::app_gatts_ntf_ind_cb. 544 * 545 * @note Check whether the relevant Client Characteristic Configuration Descriptor is enabled before using this API. 546 * 547 * @param[in] conn_idx: Current connection index. 548 * @param[in] p_param: Pointer to the parameters filled by profile. see @ref gatts_noti_ind_t. 549 * 550 * @retval ::SDK_SUCCESS: Send Notification or Indication event to stack successfully. 551 * @retval ::SDK_ERR_POINTER_NULL: Param is NULL. 552 * @retval ::SDK_ERR_INVALID_CONN_IDX: Conidx is invalid. 553 * @retval ::SDK_ERR_INVALID_PARAM: Type is invalid. 554 * @retval ::SDK_ERR_INVALID_HANDLE: Handle not exist in the database. 555 * @retval ::SDK_ERR_NO_RESOURCES: Not enough resources. 556 **************************************************************************************** 557 */ 558 uint16_t ble_gatts_noti_ind(uint8_t conn_idx, const gatts_noti_ind_t *p_param); 559 560 /** 561 **************************************************************************************** 562 * @brief When service on local device finishes upgrade, call this API to send service upgrade to stack. 563 * If the bonded device connects again, the stack will send service change to the bonded device until the bonded 564 * device has sent back indication confirmation. 565 **************************************************************************************** 566 */ 567 void ble_gatts_service_changed(void); 568 /** @} */ 569 570 #endif // BLE_SDK_GATTS_H_ 571 /** @} */ 572 573 /** @} */ 574 /** @} */ 575 576