1 /* 2 * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 **************************************************************************************** 18 * 19 * @file sonata_gatt_api.h 20 * 21 * @brief header file - gatt application interface 22 * 23 **************************************************************************************** 24 */ 25 26 #ifndef _SONATA_GATT_API_H_ 27 #define _SONATA_GATT_API_H_ 28 29 /* 30 * INCLUDE FILES 31 **************************************************************************************** 32 */ 33 #include "sonata_config.h" 34 /// @cond 35 #if defined(STACK_BLE_HOST_PRESENT) || defined(BLE_HOST_PRESENT) 36 /// @endcond 37 38 #include "sonata_utils_api.h" 39 #include "sonata_att.h" 40 41 /** 42 * @defgroup SONATA_GATT_API GATT_API 43 * @{ 44 */ 45 46 /* 47 * MACRO DEFINITIONS 48 **************************************************************************************** 49 */ 50 51 /// GATT read perm auth (0x0202) 52 #define PRD_AU (SONATA_PERM(RD, ENABLE) | SONATA_PERM(RP, AUTH)) 53 /// GATT write perm auth (0x0808) 54 #define PWR_AU (SONATA_PERM(WRITE_REQ, ENABLE) | SONATA_PERM(WP, AUTH)) 55 /// GATT ind perm auth (0X2020) 56 #define PIND_AU (SONATA_PERM(IND, ENABLE) | SONATA_PERM(IP, AUTH)) 57 /// GATT notify perm auth (0x1080) 58 #define PNTF_AU (SONATA_PERM(NTF, ENABLE) | SONATA_PERM(NP, AUTH)) 59 60 /// GATT read perm unauth (0x0201) 61 #define PRD_UA (SONATA_PERM(RD, ENABLE) | SONATA_PERM(RP, UNAUTH)) 62 /// GATT write perm unauth (0x0804) 63 #define PWR_UA (SONATA_PERM(WRITE_REQ, ENABLE) | SONATA_PERM(WP, UNAUTH)) 64 /// GATT ind perm unauth (0X2010) 65 #define PIND_UA (SONATA_PERM(IND, ENABLE) | SONATA_PERM(IP, UNAUTH)) 66 /// GATT notify perm unauth (0x1040) 67 #define PNTF_UA (SONATA_PERM(NTF, ENABLE) | SONATA_PERM(NP, UNAUTH)) 68 69 /// GATT read perm no auth (0x0200) 70 #define PRD_NA (SONATA_PERM(RD, ENABLE) | SONATA_PERM(RP, NO_AUTH)) 71 /// GATT write perm no auth (0x0800) 72 #define PWR_NA (SONATA_PERM(WRITE_REQ, ENABLE) | SONATA_PERM(WP, NO_AUTH)) 73 /// GATT ind perm no auth (0X2000) 74 #define PIND_NA (SONATA_PERM(IND, ENABLE) | SONATA_PERM(IP, NO_AUTH)) 75 /// GATT notify perm no auth(0x1000) 76 #define PNTF_NA (SONATA_PERM(NTF, ENABLE) | SONATA_PERM(NP, NO_AUTH)) 77 78 /// extended Descriptor Present (0X8000) 79 #define PEXT (SONATA_PERM(EXT,ENABLE)) 80 /// enable Read Indication (1 = Value not present in Database) (0x8000) 81 #define PRI (SONATA_PERM(RI, ENABLE)) 82 83 #define PWC_NA (SONATA_PERM(WRITE_COMMAND, ENABLE) | SONATA_PERM(WP, NO_AUTH)) 84 85 /* 86 * ENUM DEFINITIONS 87 **************************************************************************************** 88 */ 89 /*! 90 * @brief request operation type - application interface 91 */ 92 typedef enum { 93 /* Attribute Client Flags */ 94 /* No Operation (if nothing has been requested) */ 95 /* ************************************************ */ 96 /// No operation 97 SONATA_GATT_NO_OP = 0x00, 98 99 /* Operation flags for MTU Exchange */ 100 /* ************************************************ */ 101 /// Perform MTU exchange 102 SONATA_GATT_MTU_EXCH = 0x01, 103 104 /* Operation flags for discovery operation */ 105 /* ************************************************ */ 106 /// Discover all services 107 SONATA_GATT_DISC_ALL_SVC = 0x02, 108 /// Discover services by UUID 109 SONATA_GATT_DISC_BY_UUID_SVC = 0x03, 110 /// Discover included services 111 SONATA_GATT_DISC_INCLUDED_SVC = 0x04, 112 /// Discover all characteristics 113 SONATA_GATT_DISC_ALL_CHAR = 0x05, 114 /// Discover characteristic by UUID 115 SONATA_GATT_DISC_BY_UUID_CHAR = 0x06, 116 /// Discover characteristic descriptor 117 SONATA_GATT_DISC_DESC_CHAR = 0x07, 118 119 /* Operation flags for reading attributes */ 120 /* ************************************************ */ 121 /// Read attribute 122 SONATA_GATT_READ = 0x08, 123 /// Read long attribute 124 SONATA_GATT_READ_LONG = 0x09, 125 /// Read attribute by UUID 126 SONATA_GATT_READ_BY_UUID = 0x0A, 127 /// Read multiple attribute 128 SONATA_GATT_READ_MULTIPLE = 0x0B, 129 130 /* Operation flags for writing/modifying attributes */ 131 /* ************************************************ */ 132 /// Write attribute 133 SONATA_GATT_WRITE = 0x0C, 134 /// Write no response 135 SONATA_GATT_WRITE_NO_RESPONSE = 0x0D, 136 /// Write signed 137 SONATA_GATT_WRITE_SIGNED = 0x0E, 138 /// Execute write 139 SONATA_GATT_EXEC_WRITE = 0x0F, 140 141 /* Operation flags for registering to peer device */ 142 /* events */ 143 /* ************************************************ */ 144 /// Register to peer device events 145 SONATA_GATT_REGISTER = 0x10, 146 /// Unregister from peer device events 147 SONATA_GATT_UNREGISTER = 0x11, 148 149 /* Operation flags for sending events to peer devicd */ 150 /* ************************************************ */ 151 /// Send an attribute notification 152 SONATA_GATT_NOTIFY = 0x12, 153 /// Send an attribute indication 154 SONATA_GATT_INDICATE = 0x13, 155 156 /* Service Discovery Procedure */ 157 /* ************************************************ */ 158 /// Search specific service 159 SONATA_GATT_SDP_DISC_SVC = 0x15, 160 /// Search for all services 161 SONATA_GATT_SDP_DISC_SVC_ALL = 0x16, 162 /// Cancel Service Discovery Procedure 163 SONATA_GATT_SDP_DISC_CANCEL = 0x17, 164 165 /* Robust Cache */ 166 /* ************************************************ */ 167 /// Read peer database hash 168 SONATA_GATT_READ_DB_HASH = 0x20, 169 /// Enable Robust database cache feature 170 SONATA_GATT_ROBUST_DB_CACHE_EN = 0x21, 171 172 /* Internal API */ 173 /* ************************************************ */ 174 /// Send a service changed indication 175 SONATA_GATT_SVC_CHANGED = 0x40, 176 } sonata_gatt_operation; 177 178 /// GATT response type 179 typedef enum { 180 /// Add service in database response 181 SONATA_GATT_ADD_SVC_RSP = 0x0B01, 182 /// Get permission settings of service response 183 SONATA_GATT_SVC_GET_PERMISSION_RSP = 0x0B03, 184 /// Set permission settings of service response 185 SONATA_GATT_SVC_SET_PERMISSION_RSP = 0x0B05, 186 /// Get permission settings of attribute response 187 SONATA_GATT_ATT_GET_PERMISSION_RSP = 0x0B07, 188 /// Set permission settings of attribute response 189 SONATA_GATT_ATT_SET_PERMISSION_RSP = 0x0B09, 190 /// Get attribute value response 191 SONATA_GATT_ATT_GET_VALUE_RSP = 0x0B0B, 192 /// Set attribute value request 193 SONATA_GATT_ATT_SET_VALUE_RSP = 0x0B0D, 194 /// DEBUG ONLY: Destroy Attribute database request 195 SONATA_GATT_DESTROY_DB_RSP = 0x0B10, 196 /// DEBUG ONLY: Retrieve list of services response 197 SONATA_GATT_SVC_GET_LIST_RSP = 0x0B12, 198 /// DEBUG ONLY: Retrieve information of attribute response 199 SONATA_GATT_ATT_GET_INFO_RSP = 0x0B14, 200 /// DEBUG ONLY: Set Service visibility response 201 SONATA_GATT_SVC_VISIBILITY_SET_RSP = 0x0B16, 202 /// Compute hash value of the attribute database response 203 SONATA_GATT_ATT_DB_HASH_COMP_RSP = 0x0B21, 204 } sonata_ble_response_type; 205 206 /* 207 * Type Definition 208 **************************************************************************************** 209 */ 210 211 /** 212 * Attribute Description 213 */ 214 /* @TRACE */ 215 typedef struct sonata_gatt_att_desc { 216 /** Attribute UUID (LSB First) */ 217 uint8_t uuid[SONATA_ATT_UUID_128_LEN]; 218 219 /** 220 * Attribute Permission (@see attm_perm_mask) 221 */ 222 uint16_t perm; 223 224 /** 225 * Maximum length of the attribute 226 * 227 * Note: 228 * For Included Services and Characteristic Declarations, this field contains targeted 229 * handle. 230 * 231 * For Characteristic Extended Properties, this field contains 2 byte value 232 * 233 * Not used Client Characteristic Configuration and Server Characteristic Configuration, 234 * this field is not used. 235 */ 236 uint16_t max_len; 237 238 /** 239 * Attribute Extended permissions 240 * 241 * Extended Value permission bit field 242 * 243 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 244 * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ 245 * | RI |UUID_LEN |EKS | Reserved | 246 * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ 247 * 248 * Bit [0-11] : Reserved 249 * Bit [12] : Encryption key Size must be 16 bytes 250 * Bit [13-14]: UUID Length (0 = 16 bits, 1 = 32 bits, 2 = 128 bits, 3 = RFU) 251 * Bit [15] : Trigger Read Indication (0 = Value present in Database, 1 = Value not present in Database) 252 */ 253 uint16_t ext_perm; 254 } sonata_gatt_att_desc_t; 255 256 /// Service information 257 /* @TRACE */ 258 typedef struct sonata_gatt_svc_info { 259 /// Service start handle 260 uint16_t start_hdl; 261 /// Service end handle 262 uint16_t end_hdl; 263 /// Service task_id 264 uint16_t task_id; 265 /// Service permission 266 uint8_t perm; 267 } sonata_gatt_svc_info_t; 268 269 /// @brief Callbacks for GATT module 270 typedef struct { 271 /*************** GATT Controller ***************/ 272 /// @deprecated use @see ble_complete_callback 273 void (*gatt_disc_all_svc_complete)(uint8_t conidx, uint16_t status); 274 /// @deprecated use @see ble_complete_callback 275 void (*gatt_read_complete)(uint8_t conidx, uint16_t status); 276 277 /// Callback for discover services 278 uint16_t (*gatt_disc_svc)(uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl, uint8_t uuid_len, uint8_t *uuid); 279 280 /// Callback when discover all inclued service complete 281 uint16_t (*gatt_disc_svc_incl)(uint8_t conidx, uint16_t attr_hdl, uint16_t start_hdl, uint16_t end_hdl, 282 uint8_t uuid_len, uint8_t *uuid); 283 284 /// Callback for discover characteristic 285 uint16_t (*gatt_disc_char)(uint8_t conidx, uint16_t attr_hdl, uint16_t pointer_hdl, uint8_t prop, uint8_t uuid_len, 286 uint8_t *uuid); /* void(*gatt_disc_char_desc)(void); */ 287 288 /// Callback for discover characteristic description 289 uint16_t (*gatt_disc_char_desc)(uint8_t conidx, uint16_t attr_hdl, uint8_t uuid_len, 290 uint8_t *uuid); /* void(*gatt_disc_char_desc)(void); */ 291 292 /// Callback for GATT read complete 293 uint16_t (*gatt_read)(uint8_t conidx, uint16_t handle, uint16_t offset, uint16_t length, uint8_t *value); 294 /// Callback for GATT read request 295 uint16_t (*gatt_read_req)(uint8_t conidx, uint16_t handle); 296 /// Callback for GATT write request 297 uint16_t (*gatt_write_req)(uint8_t conidx, uint16_t handle, uint16_t offset, uint16_t length, uint8_t *value); 298 299 /// Callback for GATT mtu changed indicate 300 uint16_t (*gatt_mtu_changed)(uint8_t conidx, uint16_t mtu); 301 302 /// Callback for GATT ATT information request 303 uint16_t (*gatt_att_info_req)(uint8_t conidx, uint16_t handle); 304 305 /// Callback for GATT SDP service 306 uint16_t (*gatt_sdp_service)(uint8_t conidx, uint16_t handle); 307 308 /// Callback for GATT event 309 uint16_t (*gatt_event)(uint8_t conidx, uint16_t handle, uint16_t type, uint16_t length, uint8_t *value); 310 311 /// Callback for GATT service change request 312 uint16_t (*gatt_service_change_req)(uint8_t conidx, uint16_t start_handle, uint16_t end_handle); 313 314 /// Callback for connection information(about GATT for current connection that can be reuse on another connection) 315 uint16_t (*gatt_connection_info)(uint8_t conidx, uint16_t gatt_start_handle, uint16_t gatt_end_handle, 316 uint16_t svc_chg_handle, 317 uint8_t cli_info, uint8_t cli_feat); 318 319 /*************** GATT Manager ***************/ 320 } ble_gatt_callback; 321 322 /* 323 * FUNCTION DECLARATIONS 324 **************************************************************************************** 325 */ 326 327 /*! 328 * @brief Exchange mtu 329 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 330 * @return API_SUCCESS 331 */ 332 uint16_t sonata_ble_gatt_exchange_mtu(uint8_t conidx); 333 /*! 334 * @brief Discover All Services 335 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 336 * @return API_SUCCESS 337 */ 338 uint16_t sonata_ble_gatt_disc_all_svc(uint8_t conidx); 339 340 /*! 341 * @brief Disc service by uudi 342 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 343 * @param start_hdl Service start handle 344 * @param end_hdl Service end handle 345 * @param uuid_len UUID length 346 * @param uuid UUID 347 * @return API_SUCCESS 348 */ 349 uint16_t sonata_ble_gatt_disc_svc_by_uuid(uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl, uint8_t uuid_len, 350 uint8_t *uuid); 351 352 /*! 353 * @brief Disc included servcie 354 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 355 * @param start_hdl Service start handle 356 * @param end_hdl Service end handle 357 * @return API_SUCCESS 358 */ 359 uint16_t sonata_ble_gatt_disc_included_svc(uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl); 360 /*! 361 * @brief Discover All characteristic 362 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 363 * @param start_hdl Service start handle 364 * @param end_hdl Service end handle 365 * @return API_SUCCESS 366 */ 367 uint16_t sonata_ble_gatt_disc_all_characteristic(uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl); 368 369 /*! 370 * @brief Disc characteristic by uuid 371 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 372 * @param start_hdl Service start handle 373 * @param end_hdl Service end handle 374 * @param uuid_len UUID length 375 * @param uuid UUID 376 * @return API_SUCCESS 377 */ 378 uint16_t sonata_ble_gatt_disc_characteristic_by_uuid(uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl, 379 uint8_t uuid_len, uint8_t *uuid); 380 /*! 381 * @brief Discover All desc 382 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 383 * @param start_hdl Service start handle 384 * @param end_hdl Service end handle 385 * @return API_SUCCESS 386 */ 387 uint16_t sonata_ble_gatt_disc_all_descriptor(uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl); 388 /*! 389 * @brief Read GATT value by handler 390 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 391 * @param handle_id : attribute handle 392 * @return API_SUCCESS 393 */ 394 uint16_t sonata_ble_gatt_read_by_handle(uint8_t conidx, uint16_t handle_id); 395 396 /*! 397 * @brief Send NTF event 398 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 399 * @param handle handle id 400 * @param length value length 401 * @param value value 402 * @return API_SUCCESS 403 */ 404 uint16_t sonata_ble_gatt_send_notify_event(uint8_t conidx, uint16_t handle, uint16_t length, uint8_t *value); 405 406 /*! 407 * @brief Send indicate event 408 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 409 * @param handle handle id 410 * @param length value length 411 * @param value value 412 * @return API_SUCCESS 413 */ 414 uint16_t sonata_ble_gatt_send_indicate_event(uint8_t conidx, uint16_t handle, uint16_t length, uint8_t *value); 415 416 /*! 417 * @brief Gatt read 418 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 419 * @param handle handle id 420 * @param offset start offset in data payload 421 * @param length Length of data to read (0 = read all) 422 * @return API_SUCCESS 423 */ 424 uint16_t sonata_ble_gatt_read(uint8_t conidx, uint16_t handle, uint16_t offset, uint16_t length); 425 426 /*! 427 * @brief Gatt read long 428 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 429 * @param handle handle id 430 * @param offset start offset in data payload 431 * @param length Length of data to read (0 = read all) 432 * @return API_SUCCESS 433 */ 434 uint16_t sonata_ble_gatt_gatt_read_long(uint8_t conidx, uint16_t handle, uint16_t offset, uint16_t length); 435 436 /*! 437 * @brief Gatt read by UUID 438 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 439 * @param seq_num 440 * @param start_hdl Service start handle 441 * @param end_hdl End handle 442 * @param uuid_len UUID length 443 * @param uuid UUID 444 * @return API_SUCCESS 445 */ 446 uint16_t sonata_ble_gatt_read_by_uuid(uint8_t conidx, uint16_t seq_num, uint16_t start_hdl, uint16_t end_hdl, 447 uint8_t uuid_len, uint8_t *uuid); 448 449 /*! 450 * @brief Gatt write 451 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 452 * @param handle handle id 453 * @param offset Write offset 454 * @param cursor Internal write cursor shall be initialized to 0 455 * @param length Write length 456 * @param value Value to write 457 * @return API_SUCCESS 458 */ 459 uint16_t sonata_ble_gatt_write(uint8_t conidx, uint16_t handle, uint16_t offset, uint16_t cursor, uint16_t length, 460 uint8_t *value); 461 462 /*! 463 * @brief Gatt write no response 464 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 465 * @param handle handle id 466 * @param offset Write offset 467 * @param cursor Internal write cursor shall be initialized to 0 468 * @param length Write length 469 * @param value Value to write 470 * @return API_SUCCESS 471 */ 472 uint16_t sonata_ble_gatt_write_no_response(uint8_t conidx, uint16_t handle, uint16_t offset, uint16_t cursor, 473 uint16_t length, uint8_t *value); 474 475 /*! 476 * @brief Gatt write signed 477 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 478 * @param handle handle id 479 * @param offset Write offset 480 * @param cursor Internal write cursor shall be initialized to 0 481 * @param length Write length 482 * @param value Value to write 483 * @return API_SUCCESS 484 */ 485 uint16_t sonata_ble_gatt_write_signed(uint8_t conidx, uint16_t handle, uint16_t offset, uint16_t cursor, 486 uint16_t length, uint8_t *value); 487 488 /*! 489 * @brief Gatt excute write 490 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 491 * @param execute [True = perform/False cancel] pending write operations 492 * @return API_SUCCESS 493 */ 494 uint16_t sonata_ble_gatt_execute_write(uint8_t conidx, bool execute); 495 496 /*! 497 * @brief Gatt register to peer device event 498 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 499 * @param start_hdl Service start handle 500 * @param end_hdl End handle 501 * @return API_SUCCESS 502 */ 503 uint16_t sonata_ble_gatt_register_to_peer_device_event(uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl); 504 505 /*! 506 * @brief Gatt unregister to peer device event 507 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 508 * @param start_hdl Service start handle 509 * @param end_hdl End handle 510 * @return API_SUCCESS 511 */ 512 uint16_t sonata_ble_gatt_unregister_to_peer_device_event(uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl); 513 514 /*! 515 * @brief Gatt SDP discovery service 516 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 517 * @param start_hdl Service start handle 518 * @param end_hdl End handle 519 * @param uuid_len UUID length 520 * @param uuid UUID 521 * @return API_SUCCESS 522 */ 523 uint16_t sonata_ble_gatt_sdp_discovery_service(uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl, uint8_t uuid_len, 524 uint8_t *uuid); 525 526 /*! 527 * @brief Gatt sdp cancel discovery 528 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 529 * @return API_SUCCESS 530 */ 531 uint16_t sonata_ble_gatt_sdp_cancel_discovery(uint8_t conidx); 532 533 /*! 534 * @brief Gatt sdp discovery all service 535 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 536 * @param start_hdl Service start handle 537 * @param end_hdl Service end handle 538 * @param uuid_len UUID length 539 * @param uuid UUID 540 * @return API_SUCCESS 541 */ 542 uint16_t sonata_ble_gatt_sdp_discovery_all_service(uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl, 543 uint8_t uuid_len, uint8_t *uuid); 544 545 /*! 546 * @brief Gatt enable robust database cache 547 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 548 * @return API_SUCCESS 549 */ 550 uint16_t sonata_ble_gatt_robust_db_cache_enable(uint8_t conidx); 551 552 /*! 553 * @brief Gatt read database hase 554 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 555 * @return API_SUCCESS 556 */ 557 uint16_t sonata_ble_gatt_read_db_hash_cmd_handler(uint8_t conidx); 558 559 /*! 560 * @brief Gatt send servcie changed event 561 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 562 * @param handle handle id 563 * @param start_handle Start handle 564 * @param end_handle End handle 565 * @return API_SUCCESS 566 */ 567 uint16_t sonata_ble_gatt_send_service_changed_event(uint8_t conidx, uint16_t handle, uint16_t start_handle, 568 uint16_t end_handle); 569 570 /*! 571 * @brief Gatt send event confirm message 572 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 573 * @param handle handle id 574 * @return API_SUCCESS 575 */ 576 uint16_t sonata_ble_gatt_send_event_confirm(uint8_t conidx, uint16_t handle); 577 578 /*! 579 * @brief Gatt send att info confirm message 580 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 581 * @param handle handle id 582 * @param length Current length of the attribute 583 * @param status use to know if it's possible to modify the attribute can contains authorization or application error code. 584 * @return API_SUCCESS 585 */ 586 uint16_t sonata_ble_gatt_send_att_info_confirm(uint8_t conidx, uint16_t handle, uint16_t length, uint8_t status); 587 588 /*! 589 * @brief Gatt send service changed confirm message 590 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 591 * @param handle handle id 592 * @return API_SUCCESS 593 */ 594 uint16_t sonata_ble_gatt_send_svc_change_confirm(uint8_t conidx, uint16_t handle); 595 596 /*! 597 * @brief Add gatt service request 598 * @param start_hdl Service start handle Attribute Start Handle (0 = dynamically allocated) 599 * @param perm |SEC |UUID_LEN |DIS | AUTH |EKS | MI | 600 * @param uuid Service UUID 601 * @param nb_att Number of attributes 602 * @param atts List of attribute description present in service. 603 * @return API_SUCCESS 604 */ 605 uint16_t sonata_ble_gatt_add_service(uint16_t start_hdl, uint8_t perm, uint8_t *uuid, 606 uint8_t nb_att, sonata_gatt_att_desc_t *atts); 607 608 /// @deprecated use sonata_ble_gatt_add_service() 609 uint16_t sonata_ble_gatt_add_service_request(uint16_t start_hdl, uint8_t perm, uint8_t *uuid, 610 uint8_t nb_att, sonata_gatt_att_desc_t *atts); 611 612 /*! 613 * @brief Gatt get value 614 * @param handle handle id 615 * @return API_SUCCESS 616 */ 617 uint16_t sonata_ble_gatt_att_get_value(uint16_t handle); 618 /*! 619 * @brief Gatt set value 620 * @param handle handle id 621 * @param length Attribute value length 622 * @param value Attribute value 623 * @return API_SUCCESS 624 */ 625 uint16_t sonata_ble_gatt_att_set_value(uint16_t handle, uint16_t length, uint8_t *value); 626 /*! 627 * @brief Gatt destory database(for debug) 628 * @param gap_hdl New Gap Start Handle 629 * @param gatt_hdl New Gatt Start Handle 630 * @return API_SUCCESS 631 */ 632 uint16_t sonata_ble_gatt_destroy_db(uint16_t gap_hdl, uint16_t gatt_hdl); 633 /*! 634 * @brief Gatt get service list 635 * @param status 636 * @param nb_svc Number of services 637 * @param svc Array of information about services 638 * @return API_SUCCESS 639 */ 640 uint16_t sonata_ble_gatt_get_service_list(uint8_t status, uint8_t nb_svc, sonata_gatt_svc_info_t *svc); 641 /*! 642 * @brief Gatt get information 643 * @param handle handle id 644 * @return API_SUCCESS 645 */ 646 uint16_t sonata_ble_gatt_att_get_info(uint16_t handle); 647 /*! 648 * @brief Gatt set visibility of a service 649 * @param handle handle id 650 * @param visible True to set service visible, false to hide it 651 * @return API_SUCCESS 652 */ 653 uint16_t sonata_ble_gatt_set_service_visibility(uint16_t handle, bool visible); 654 /*! 655 * @brief Gatt get database hash 656 * @return API_SUCCESS 657 */ 658 uint16_t sonata_ble_gatt_att_compute_db_hash(void); 659 /*! 660 * @brief GATT send read confirm message 661 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 662 * @param handle gatt att handle id 663 * @param status status 664 * @param length value length 665 * @param value value array 666 * @return API_SUCCESS 667 */ 668 uint16_t sonata_ble_gatt_send_read_confirm(uint8_t conidx, uint16_t handle, uint8_t status, uint16_t length, 669 uint8_t *value); 670 671 /*! 672 * @brief GATT send write confirm message 673 * @param conidx connecting index, used for multiple connection. for single connection, set it to 0. 674 * @param handle gatt att handle id 675 * @param status status 676 * @return API_SUCCESS 677 */ 678 uint16_t sonata_ble_gatt_send_write_confirm(uint8_t conidx, uint16_t handle, uint8_t status); 679 680 /*! 681 * @brief Register GATT callback functions for ble module 682 * @param cb @see ble_gatt_callback 683 * @return API_SUCCESS 684 */ 685 uint16_t sonata_ble_register_gatt_callback(ble_gatt_callback *cb); 686 687 /** @}*/ 688 689 #endif // BLE_HOST_PRESENT 690 691 #endif // _SONATA_GATT_API_H_ 692 693