1 /****************************************************************************** 2 * 3 * Copyright (C) 2003-2013 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 /****************************************************************************** 20 * 21 * This is the public interface file for BTA GATT. 22 * 23 ******************************************************************************/ 24 25 #ifndef BTA_GATT_API_H 26 #define BTA_GATT_API_H 27 28 #include "bta/bta_api.h" 29 #include "stack/gatt_api.h" 30 #include "osi/list.h" 31 32 #ifndef BTA_GATT_INCLUDED 33 #define BTA_GATT_INCLUDED FALSE 34 #endif 35 36 #if ((BLE_INCLUDED == FALSE) && (BTA_GATT_INCLUDED == TRUE)) 37 #undef BTA_GATT_INCLUDED 38 #define BTA_GATT_INCLUDED FALSE 39 #endif 40 41 42 #ifndef BTA_GATT_DEBUG 43 #define BTA_GATT_DEBUG FALSE 44 #endif 45 46 typedef enum { 47 BTGATT_DB_PRIMARY_SERVICE, 48 BTGATT_DB_SECONDARY_SERVICE, 49 BTGATT_DB_CHARACTERISTIC, 50 BTGATT_DB_DESCRIPTOR, 51 BTGATT_DB_INCLUDED_SERVICE, 52 }bt_gatt_db_attribute_type_t; 53 54 typedef enum { 55 GATT_OP_GET_SVC_BY_UUID, 56 GATT_OP_GET_ALL_CHAR, 57 GATT_OP_GET_ALL_DESCRI, 58 GATT_OP_GET_CHAR_BY_UUID, 59 GATT_OP_GET_DESCRI_BY_UUID, 60 GATT_OP_GET_DESCRI_BY_HANDLE, 61 GATT_OP_GET_INCLUDE_SVC, 62 }bt_gatt_get_db_op_t; 63 64 typedef struct { 65 bt_gatt_db_attribute_type_t type; 66 UINT16 attribute_handle; 67 UINT16 start_handle; 68 UINT16 end_handle; 69 UINT16 id; 70 UINT8 properties; 71 bt_uuid_t uuid; 72 }btgatt_db_element_t; 73 74 /***************************************************************************** 75 ** Constants and data types 76 *****************************************************************************/ 77 /************************** 78 ** Common Definitions 79 ***************************/ 80 /* GATT ID */ 81 typedef struct { 82 tBT_UUID uuid; /* uuid of the attribute */ 83 UINT8 inst_id; /* instance ID */ 84 } __attribute__((packed)) tBTA_GATT_ID; 85 86 /* relate to ESP_GATT_xxx in esp_gatt_def.h */ 87 /* Success code and error codes */ 88 #define BTA_GATT_OK GATT_SUCCESS 89 #define BTA_GATT_INVALID_HANDLE GATT_INVALID_HANDLE /* 0x0001 */ 90 #define BTA_GATT_READ_NOT_PERMIT GATT_READ_NOT_PERMIT /* 0x0002 */ 91 #define BTA_GATT_WRITE_NOT_PERMIT GATT_WRITE_NOT_PERMIT /* 0x0003 */ 92 #define BTA_GATT_INVALID_PDU GATT_INVALID_PDU /* 0x0004 */ 93 #define BTA_GATT_INSUF_AUTHENTICATION GATT_INSUF_AUTHENTICATION /* 0x0005 */ 94 #define BTA_GATT_REQ_NOT_SUPPORTED GATT_REQ_NOT_SUPPORTED /* 0x0006 */ 95 #define BTA_GATT_INVALID_OFFSET GATT_INVALID_OFFSET /* 0x0007 */ 96 #define BTA_GATT_INSUF_AUTHORIZATION GATT_INSUF_AUTHORIZATION /* 0x0008 */ 97 #define BTA_GATT_PREPARE_Q_FULL GATT_PREPARE_Q_FULL /* 0x0009 */ 98 #define BTA_GATT_NOT_FOUND GATT_NOT_FOUND /* 0x000a */ 99 #define BTA_GATT_NOT_LONG GATT_NOT_LONG /* 0x000b */ 100 #define BTA_GATT_INSUF_KEY_SIZE GATT_INSUF_KEY_SIZE /* 0x000c */ 101 #define BTA_GATT_INVALID_ATTR_LEN GATT_INVALID_ATTR_LEN /* 0x000d */ 102 #define BTA_GATT_ERR_UNLIKELY GATT_ERR_UNLIKELY /* 0x000e */ 103 #define BTA_GATT_INSUF_ENCRYPTION GATT_INSUF_ENCRYPTION /* 0x000f */ 104 #define BTA_GATT_UNSUPPORT_GRP_TYPE GATT_UNSUPPORT_GRP_TYPE /* 0x0010 */ 105 #define BTA_GATT_INSUF_RESOURCE GATT_INSUF_RESOURCE /* 0x0011 */ 106 107 108 #define BTA_GATT_NO_RESOURCES GATT_NO_RESOURCES /* 0x80 */ 109 #define BTA_GATT_INTERNAL_ERROR GATT_INTERNAL_ERROR /* 0x81 */ 110 #define BTA_GATT_WRONG_STATE GATT_WRONG_STATE /* 0x82 */ 111 #define BTA_GATT_DB_FULL GATT_DB_FULL /* 0x83 */ 112 #define BTA_GATT_BUSY GATT_BUSY /* 0x84 */ 113 #define BTA_GATT_ERROR GATT_ERROR /* 0x85 */ 114 #define BTA_GATT_CMD_STARTED GATT_CMD_STARTED /* 0x86 */ 115 #define BTA_GATT_ILLEGAL_PARAMETER GATT_ILLEGAL_PARAMETER /* 0x87 */ 116 #define BTA_GATT_PENDING GATT_PENDING /* 0x88 */ 117 #define BTA_GATT_AUTH_FAIL GATT_AUTH_FAIL /* 0x89 */ 118 #define BTA_GATT_MORE GATT_MORE /* 0x8a */ 119 #define BTA_GATT_INVALID_CFG GATT_INVALID_CFG /* 0x8b */ 120 #define BTA_GATT_SERVICE_STARTED GATT_SERVICE_STARTED /* 0x8c */ 121 #define BTA_GATT_ENCRYPED_MITM GATT_ENCRYPED_MITM /* GATT_SUCCESS */ 122 #define BTA_GATT_ENCRYPED_NO_MITM GATT_ENCRYPED_NO_MITM /* 0x8d */ 123 #define BTA_GATT_NOT_ENCRYPTED GATT_NOT_ENCRYPTED /* 0x8e */ 124 #define BTA_GATT_CONGESTED GATT_CONGESTED /* 0x8f */ 125 126 #define BTA_GATT_DUP_REG GATT_DUP_REG /* 0x90 */ 127 #define BTA_GATT_ALREADY_OPEN GATT_ALREADY_OPEN /* 0x91 */ 128 #define BTA_GATT_CANCEL GATT_CANCEL /* 0x92 */ 129 130 /* 0xE0 ~ 0xFC reserved for future use */ 131 #define BTA_GATT_STACK_RSP GATT_STACK_RSP /* 0xE0 */ 132 #define BTA_GATT_APP_RSP GATT_APP_RSP /* 0xE1 */ 133 //Error caused by customer application or stack bug 134 #define BTA_GATT_UNKNOWN_ERROR GATT_UNKNOWN_ERROR /* 0XEF */ 135 /* 0xE0 ~ 0xFC reserved for future use */ 136 #define BTA_GATT_CCC_CFG_ERR GATT_CCC_CFG_ERR /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */ 137 #define BTA_GATT_PRC_IN_PROGRESS GATT_PRC_IN_PROGRESS /* 0xFE Procedure Already in progress */ 138 #define BTA_GATT_OUT_OF_RANGE GATT_OUT_OF_RANGE /* 0xFFAttribute value out of range */ 139 140 typedef UINT8 tBTA_GATT_STATUS; 141 142 #define BTA_GATT_INVALID_CONN_ID GATT_INVALID_CONN_ID 143 144 145 /* Client callback function events */ 146 #define BTA_GATTC_REG_EVT 0 /* GATT client is registered. */ 147 #define BTA_GATTC_DEREG_EVT 1 /* GATT client deregistered event */ 148 #define BTA_GATTC_OPEN_EVT 2 /* GATTC open request status event */ 149 #define BTA_GATTC_READ_CHAR_EVT 3 /* GATT read characteristic event */ 150 #define BTA_GATTC_WRITE_CHAR_EVT 4 /* GATT write characteristic or char descriptor event */ 151 #define BTA_GATTC_CLOSE_EVT 5 /* GATTC close request status event */ 152 #define BTA_GATTC_SEARCH_CMPL_EVT 6 /* GATT discovery complete event */ 153 #define BTA_GATTC_SEARCH_RES_EVT 7 /* GATT discovery result event */ 154 #define BTA_GATTC_READ_DESCR_EVT 8 /* GATT read characteristic descriptor event */ 155 #define BTA_GATTC_WRITE_DESCR_EVT 9 /* GATT write characteristic descriptor event */ 156 #define BTA_GATTC_NOTIF_EVT 10 /* GATT attribute notification event */ 157 #define BTA_GATTC_PREP_WRITE_EVT 11 /* GATT prepare write event */ 158 #define BTA_GATTC_EXEC_EVT 12 /* execute write complete event */ 159 #define BTA_GATTC_ACL_EVT 13 /* ACL up event */ 160 #define BTA_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */ 161 #define BTA_GATTC_SRVC_CHG_EVT 15 /* service change event */ 162 #define BTA_GATTC_LISTEN_EVT 16 /* listen event */ 163 #define BTA_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */ 164 #define BTA_GATTC_CFG_MTU_EVT 18 /* configure MTU complete event */ 165 #define BTA_GATTC_ADV_DATA_EVT 19 /* ADV data event */ 166 #define BTA_GATTC_MULT_ADV_ENB_EVT 20 /* Enable Multi ADV event */ 167 #define BTA_GATTC_MULT_ADV_UPD_EVT 21 /* Update parameter event */ 168 #define BTA_GATTC_MULT_ADV_DATA_EVT 22 /* Multi ADV data event */ 169 #define BTA_GATTC_MULT_ADV_DIS_EVT 23 /* Disable Multi ADV event */ 170 #define BTA_GATTC_CONGEST_EVT 24 /* Congestion event */ 171 #define BTA_GATTC_BTH_SCAN_ENB_EVT 25 /* Enable batch scan event */ 172 #define BTA_GATTC_BTH_SCAN_CFG_EVT 26 /* Config storage event */ 173 #define BTA_GATTC_BTH_SCAN_RD_EVT 27 /* Batch scan reports read event */ 174 #define BTA_GATTC_BTH_SCAN_THR_EVT 28 /* Batch scan threshold event */ 175 #define BTA_GATTC_BTH_SCAN_PARAM_EVT 29 /* Batch scan param event */ 176 #define BTA_GATTC_BTH_SCAN_DIS_EVT 30 /* Disable batch scan event */ 177 #define BTA_GATTC_SCAN_FLT_CFG_EVT 31 /* Scan filter config event */ 178 #define BTA_GATTC_SCAN_FLT_PARAM_EVT 32 /* Param filter event */ 179 #define BTA_GATTC_SCAN_FLT_STATUS_EVT 33 /* Filter status event */ 180 #define BTA_GATTC_ADV_VSC_EVT 34 /* ADV VSC event */ 181 #define BTA_GATTC_CONNECT_EVT 35 /* GATTC CONNECT event */ 182 #define BTA_GATTC_DISCONNECT_EVT 36 /* GATTC DISCONNECT event */ 183 #define BTA_GATTC_READ_MULTIPLE_EVT 37 /* GATTC Read multiple event */ 184 #define BTA_GATTC_QUEUE_FULL_EVT 38 /* GATTC queue full event */ 185 #define BTA_GATTC_ASSOC_EVT 39 /* GATTC association address event */ 186 #define BTA_GATTC_GET_ADDR_LIST_EVT 40 /* GATTC get address list in the cache event */ 187 #define BTA_GATTC_DIS_SRVC_CMPL_EVT 41 /* GATTC discover service complete */ 188 #define BTA_GATTC_READ_MULTI_VAR_EVT 42 /* GATTC read multiple variable event */ 189 190 typedef UINT8 tBTA_GATTC_EVT; 191 192 typedef tGATT_IF tBTA_GATTC_IF; 193 194 typedef UINT8 tBTA_ADDR_TYPE; 195 196 typedef struct { 197 UINT16 unit; /* as UUIUD defined by SIG */ 198 UINT16 descr; /* as UUID as defined by SIG */ 199 tGATT_FORMAT format; 200 INT8 exp; 201 UINT8 name_spc; /* The name space of the description */ 202 } tBTA_GATT_CHAR_PRES; 203 204 typedef struct { 205 UINT16 interval; 206 UINT16 latency; 207 UINT16 timeout; 208 } tBTA_GATT_CONN_PARAMS; 209 210 #define BTA_GATT_CLT_CONFIG_NONE GATT_CLT_CONFIG_NONE /* 0x0000 */ 211 #define BTA_GATT_CLT_CONFIG_NOTIFICATION GATT_CLT_CONFIG_NOTIFICATION /* 0x0001 */ 212 #define BTA_GATT_CLT_CONFIG_INDICATION GATT_CLT_CONFIG_INDICATION /* 0x0002 */ 213 typedef UINT16 tBTA_GATT_CLT_CHAR_CONFIG; 214 215 /* characteristic descriptor: server configuration value 216 */ 217 #define BTA_GATT_SVR_CONFIG_NONE GATT_SVR_CONFIG_NONE /* 0x0000 */ 218 #define BTA_GATT_SVR_CONFIG_BROADCAST GATT_SVR_CONFIG_BROADCAST /* 0x0001 */ 219 typedef UINT16 tBTA_GATT_SVR_CHAR_CONFIG; 220 221 /* Characteristic Aggregate Format attribute value 222 */ 223 #define BTA_GATT_AGGR_HANDLE_NUM_MAX 10 224 typedef struct { 225 UINT8 num_handle; 226 UINT16 handle_list[BTA_GATT_AGGR_HANDLE_NUM_MAX]; 227 } tBTA_GATT_CHAR_AGGRE; 228 typedef tGATT_VALID_RANGE tBTA_GATT_VALID_RANGE; 229 230 typedef struct { 231 UINT16 len; 232 UINT8 *p_value; 233 } tBTA_GATT_UNFMT; 234 235 #define BTA_GATT_MAX_ATTR_LEN GATT_MAX_ATTR_LEN 236 237 #define BTA_GATTC_TYPE_WRITE GATT_WRITE 238 #define BTA_GATTC_TYPE_WRITE_NO_RSP GATT_WRITE_NO_RSP 239 typedef UINT8 tBTA_GATTC_WRITE_TYPE; 240 241 /* relate to ESP_GATT_CONN_xxx in esp_gatt_defs.h */ 242 #define BTA_GATT_CONN_UNKNOWN 0 243 #define BTA_GATT_CONN_L2C_FAILURE GATT_CONN_L2C_FAILURE /* general l2cap resource failure */ 244 #define BTA_GATT_CONN_TIMEOUT GATT_CONN_TIMEOUT /* 0x08 connection timeout */ 245 #define BTA_GATT_CONN_TERMINATE_PEER_USER GATT_CONN_TERMINATE_PEER_USER /* 0x13 connection terminate by peer user */ 246 #define BTA_GATT_CONN_TERMINATE_LOCAL_HOST GATT_CONN_TERMINATE_LOCAL_HOST/* 0x16 connectionterminated by local host */ 247 #define BTA_GATT_CONN_FAIL_ESTABLISH GATT_CONN_FAIL_ESTABLISH /* 0x03E connection fail to establish */ 248 #define BTA_GATT_CONN_LMP_TIMEOUT GATT_CONN_LMP_TIMEOUT /* 0x22 connection fail for LMP response tout */ 249 #define BTA_GATT_CONN_CANCEL GATT_CONN_CANCEL /* 0x0100 L2CAP connection cancelled */ 250 #define BTA_GATT_CONN_NONE 0x0101 /* 0x0101 no connection to cancel */ 251 typedef UINT16 tBTA_GATT_REASON; 252 253 typedef struct { 254 tBTA_GATT_ID id; 255 BOOLEAN is_primary; 256 } tBTA_GATT_SRVC_ID; 257 258 259 #define BTA_GATTC_MULTI_MAX GATT_MAX_READ_MULTI_HANDLES 260 261 typedef struct { 262 UINT8 num_attr; 263 UINT16 handles[BTA_GATTC_MULTI_MAX]; 264 }tBTA_GATTC_MULTI; 265 266 /* relate to ESP_GATT_xxx in esp_gatt_def.h */ 267 #define BTA_GATT_AUTH_REQ_NONE GATT_AUTH_REQ_NONE 268 #define BTA_GATT_AUTH_REQ_NO_MITM GATT_AUTH_REQ_NO_MITM /* unauthenticated encryption */ 269 #define BTA_GATT_AUTH_REQ_MITM GATT_AUTH_REQ_MITM /* authenticated encryption */ 270 #define BTA_GATT_AUTH_REQ_SIGNED_NO_MITM GATT_AUTH_REQ_SIGNED_NO_MITM 271 #define BTA_GATT_AUTH_REQ_SIGNED_MITM GATT_AUTH_REQ_SIGNED_MITM 272 273 typedef tGATT_AUTH_REQ tBTA_GATT_AUTH_REQ; 274 275 enum { 276 BTA_GATTC_ATTR_TYPE_INCL_SRVC, 277 BTA_GATTC_ATTR_TYPE_CHAR, 278 BTA_GATTC_ATTR_TYPE_CHAR_DESCR, 279 BTA_GATTC_ATTR_TYPE_SRVC 280 }; 281 typedef UINT8 tBTA_GATTC_ATTR_TYPE; 282 283 284 typedef struct { 285 tBT_UUID uuid; 286 UINT16 s_handle; 287 UINT16 e_handle; /* used for service only */ 288 UINT8 attr_type; 289 UINT8 id; 290 UINT8 prop; /* used when attribute type is characteristic */ 291 BOOLEAN is_primary; /* used when attribute type is service */ 292 UINT16 incl_srvc_s_handle; /* used when attribute type is included service */ 293 UINT16 incl_srvc_e_handle; /* used when attribute type is included service */ 294 }tBTA_GATTC_NV_ATTR; 295 296 /* callback data structure */ 297 typedef struct { 298 tBTA_GATT_STATUS status; 299 tBTA_GATTC_IF client_if; 300 tBT_UUID app_uuid; 301 }tBTA_GATTC_REG; 302 303 typedef struct { 304 UINT16 conn_id; 305 tBTA_GATT_STATUS status; 306 UINT16 handle; 307 tBTA_GATT_UNFMT *p_value; 308 }tBTA_GATTC_READ; 309 310 typedef struct { 311 UINT16 conn_id; 312 tBTA_GATT_STATUS status; 313 UINT16 handle; 314 UINT16 offset; 315 }tBTA_GATTC_WRITE; 316 317 typedef struct { 318 UINT16 conn_id; 319 tBTA_GATT_STATUS status; 320 } tBTA_GATTC_EXEC_CMPL; 321 322 typedef struct { 323 UINT16 conn_id; 324 tBTA_GATT_STATUS status; 325 UINT8 searched_service_source; 326 } tBTA_GATTC_SEARCH_CMPL; 327 328 typedef struct { 329 UINT16 conn_id; 330 tBTA_GATT_STATUS status; 331 }tBTA_GATTC_DIS_CMPL; 332 333 typedef struct { 334 UINT16 conn_id; 335 UINT16 start_handle; 336 UINT16 end_handle; 337 tBTA_GATT_ID service_uuid; 338 bool is_primary; 339 }tBTA_GATTC_SRVC_RES; 340 341 typedef struct { 342 UINT16 conn_id; 343 tBTA_GATT_STATUS status; 344 UINT16 mtu; 345 } tBTA_GATTC_CFG_MTU; 346 347 typedef struct { 348 tBTA_GATT_STATUS status; 349 UINT16 conn_id; 350 tBTA_GATTC_IF client_if; 351 BD_ADDR remote_bda; 352 tBTA_TRANSPORT transport; 353 UINT16 mtu; 354 } tBTA_GATTC_OPEN; 355 356 typedef struct { 357 tBTA_GATT_STATUS status; 358 UINT16 conn_id; 359 tBTA_GATTC_IF client_if; 360 BD_ADDR remote_bda; 361 tBTA_GATT_REASON reason; /* disconnect reason code, not useful when connect event is reported */ 362 } tBTA_GATTC_CLOSE; 363 364 typedef struct { 365 UINT16 conn_id; 366 BD_ADDR bda; 367 UINT16 handle; 368 UINT16 len; 369 UINT8 value[BTA_GATT_MAX_ATTR_LEN]; 370 BOOLEAN is_notify; 371 } tBTA_GATTC_NOTIFY; 372 373 typedef struct { 374 UINT16 conn_id; 375 BOOLEAN congested; /* congestion indicator */ 376 } tBTA_GATTC_CONGEST; 377 378 typedef struct { 379 tBTA_GATT_STATUS status; 380 UINT16 conn_id; 381 BOOLEAN is_full; 382 } tBTA_GATTC_QUEUE_FULL; 383 384 typedef struct { 385 tBTA_GATT_STATUS status; 386 tBTA_GATTC_IF client_if; 387 } tBTA_GATTC_SET_ASSOC; 388 389 typedef struct { 390 tBTA_GATT_STATUS status; 391 tBTA_GATTC_IF client_if; 392 UINT8 num_addr; 393 BD_ADDR *bda_list; 394 } tBTA_GATTC_GET_ADDR_LIST; 395 396 typedef struct { 397 tBTA_GATT_STATUS status; 398 tBTA_GATTC_IF client_if; 399 UINT16 conn_id; 400 BD_ADDR remote_bda; 401 } tBTA_GATTC_OPEN_CLOSE; 402 403 typedef struct { 404 tBTA_GATTC_IF client_if; 405 BD_ADDR remote_bda; 406 } tBTA_GATTC_ENC_CMPL_CB; 407 408 typedef struct { 409 UINT16 conn_id; 410 UINT8 link_role; 411 tBTA_GATTC_IF client_if; 412 BD_ADDR remote_bda; 413 tBTA_GATT_CONN_PARAMS conn_params; 414 UINT8 ble_addr_type; 415 UINT16 conn_handle; 416 } tBTA_GATTC_CONNECT; 417 418 typedef struct { 419 tGATT_DISCONN_REASON reason; 420 UINT16 conn_id; 421 tBTA_GATTC_IF client_if; 422 BD_ADDR remote_bda; 423 } tBTA_GATTC_DISCONNECT; 424 425 typedef struct { 426 UINT16 conn_id; 427 BD_ADDR remote_bda; 428 } tBTA_GATTC_SERVICE_CHANGE; 429 430 typedef union { 431 tBTA_GATT_STATUS status; 432 tBTA_GATTC_DIS_CMPL dis_cmpl; /* discovery complete */ 433 tBTA_GATTC_SEARCH_CMPL search_cmpl; /* search complete */ 434 tBTA_GATTC_SRVC_RES srvc_res; /* discovery result */ 435 tBTA_GATTC_REG reg_oper; /* registration data */ 436 tBTA_GATTC_OPEN open; 437 tBTA_GATTC_CONNECT connect; 438 tBTA_GATTC_CLOSE close; 439 tBTA_GATTC_DISCONNECT disconnect; 440 tBTA_GATTC_READ read; /* read attribute/descriptor data */ 441 tBTA_GATTC_WRITE write; /* write complete data */ 442 tBTA_GATTC_EXEC_CMPL exec_cmpl; /* execute complete */ 443 tBTA_GATTC_NOTIFY notify; /* notification/indication event data */ 444 tBTA_GATTC_ENC_CMPL_CB enc_cmpl; 445 tBTA_GATTC_CFG_MTU cfg_mtu; /* configure MTU operation */ 446 tBTA_GATTC_CONGEST congest; 447 tBTA_GATTC_QUEUE_FULL queue_full; 448 tBTA_GATTC_SERVICE_CHANGE srvc_chg; /* service change event */ 449 tBTA_GATTC_SET_ASSOC set_assoc; 450 tBTA_GATTC_GET_ADDR_LIST get_addr_list; 451 } tBTA_GATTC; 452 453 /* GATTC enable callback function */ 454 typedef void (tBTA_GATTC_ENB_CBACK)(tBTA_GATT_STATUS status); 455 456 /* Client callback function */ 457 typedef void (tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC *p_data); 458 459 /* GATT Server Data Structure */ 460 /* Server callback function events */ 461 #define BTA_GATTS_REG_EVT 0 462 #define BTA_GATTS_READ_EVT GATTS_REQ_TYPE_READ /* 1 */ 463 #define BTA_GATTS_WRITE_EVT GATTS_REQ_TYPE_WRITE /* 2 */ 464 #define BTA_GATTS_EXEC_WRITE_EVT GATTS_REQ_TYPE_WRITE_EXEC /* 3 */ 465 #define BTA_GATTS_MTU_EVT GATTS_REQ_TYPE_MTU /* 4 */ 466 #define BTA_GATTS_CONF_EVT GATTS_REQ_TYPE_CONF /* 5 */ 467 #define BTA_GATTS_DEREG_EVT 6 468 #define BTA_GATTS_CREATE_EVT 7 469 #define BTA_GATTS_ADD_INCL_SRVC_EVT 8 470 #define BTA_GATTS_ADD_CHAR_EVT 9 471 #define BTA_GATTS_ADD_CHAR_DESCR_EVT 10 472 #define BTA_GATTS_DELELTE_EVT 11 473 #define BTA_GATTS_START_EVT 12 474 #define BTA_GATTS_STOP_EVT 13 475 #define BTA_GATTS_CONNECT_EVT 14 476 #define BTA_GATTS_DISCONNECT_EVT 15 477 #define BTA_GATTS_OPEN_EVT 16 478 #define BTA_GATTS_CANCEL_OPEN_EVT 17 479 #define BTA_GATTS_CLOSE_EVT 18 480 #define BTA_GATTS_LISTEN_EVT 19 481 #define BTA_GATTS_CONGEST_EVT 20 482 #define BTA_GATTS_SET_ATTR_VAL_EVT 23 483 #define BTA_GATTS_SEND_SERVICE_CHANGE_EVT 24 484 485 typedef UINT8 tBTA_GATTS_EVT; 486 typedef tGATT_IF tBTA_GATTS_IF; 487 488 /* Attribute permissions 489 */ 490 #define BTA_GATT_PERM_READ GATT_PERM_READ /* bit 0 - 0x0001 */ 491 #define BTA_GATT_PERM_READ_ENCRYPTED GATT_PERM_READ_ENCRYPTED /* bit 1 - 0x0002 */ 492 #define BTA_GATT_PERM_READ_ENC_MITM GATT_PERM_READ_ENC_MITM /* bit 2 - 0x0004 */ 493 #define BTA_GATT_PERM_WRITE GATT_PERM_WRITE /* bit 4 - 0x0010 */ 494 #define BTA_GATT_PERM_WRITE_ENCRYPTED GATT_PERM_WRITE_ENCRYPTED /* bit 5 - 0x0020 */ 495 #define BTA_GATT_PERM_WRITE_ENC_MITM GATT_PERM_WRITE_ENC_MITM /* bit 6 - 0x0040 */ 496 #define BTA_GATT_PERM_WRITE_SIGNED GATT_PERM_WRITE_SIGNED /* bit 7 - 0x0080 */ 497 #define BTA_GATT_PERM_WRITE_SIGNED_MITM GATT_PERM_WRITE_SIGNED_MITM /* bit 8 - 0x0100 */ 498 #define BTA_GATT_PERM_READ_AUTHORIZATION GATT_PERM_READ_AUTHORIZATION /* bit 9 - 0x0200 */ 499 #define BTA_GATT_PERM_WRITE_AUTHORIZATION GATT_PERM_WRITE_AUTHORIZATION /* bit 10 - 0x0400 */ 500 typedef UINT16 tBTA_GATT_PERM; 501 typedef tGATT_ATTR_VAL tBTA_GATT_ATTR_VAL; 502 typedef tGATTS_ATTR_CONTROL tBTA_GATTS_ATTR_CONTROL; 503 504 #define BTA_GATTS_INVALID_APP 0xff 505 506 #define BTA_GATTS_INVALID_IF 0 507 508 /* definition of characteristic properties */ 509 #define BTA_GATT_CHAR_PROP_BIT_BROADCAST GATT_CHAR_PROP_BIT_BROADCAST /* 0x01 */ 510 #define BTA_GATT_CHAR_PROP_BIT_READ GATT_CHAR_PROP_BIT_READ /* 0x02 */ 511 #define BTA_GATT_CHAR_PROP_BIT_WRITE_NR GATT_CHAR_PROP_BIT_WRITE_NR /* 0x04 */ 512 #define BTA_GATT_CHAR_PROP_BIT_WRITE GATT_CHAR_PROP_BIT_WRITE /* 0x08 */ 513 #define BTA_GATT_CHAR_PROP_BIT_NOTIFY GATT_CHAR_PROP_BIT_NOTIFY /* 0x10 */ 514 #define BTA_GATT_CHAR_PROP_BIT_INDICATE GATT_CHAR_PROP_BIT_INDICATE /* 0x20 */ 515 #define BTA_GATT_CHAR_PROP_BIT_AUTH GATT_CHAR_PROP_BIT_AUTH /* 0x40 */ 516 #define BTA_GATT_CHAR_PROP_BIT_EXT_PROP GATT_CHAR_PROP_BIT_EXT_PROP /* 0x80 */ 517 typedef UINT8 tBTA_GATT_CHAR_PROP; 518 519 #ifndef BTA_GATTC_CHAR_DESCR_MAX 520 #define BTA_GATTC_CHAR_DESCR_MAX 7 521 #endif 522 523 /*********************** NV callback Data Definitions ********************** 524 */ 525 typedef struct { 526 tBT_UUID app_uuid128; 527 tBT_UUID svc_uuid; 528 UINT16 svc_inst; 529 UINT16 s_handle; 530 UINT16 e_handle; 531 BOOLEAN is_primary; /* primary service or secondary */ 532 } tBTA_GATTS_HNDL_RANGE; 533 534 #define BTA_GATTS_SRV_CHG_CMD_ADD_CLIENT GATTS_SRV_CHG_CMD_ADD_CLIENT 535 #define BTA_GATTS_SRV_CHG_CMD_UPDATE_CLIENT GATTS_SRV_CHG_CMD_UPDATE_CLIENT 536 #define BTA_GATTS_SRV_CHG_CMD_REMOVE_CLIENT GATTS_SRV_CHG_CMD_REMOVE_CLIENT 537 #define BTA_GATTS_SRV_CHG_CMD_READ_NUM_CLENTS GATTS_SRV_CHG_CMD_READ_NUM_CLENTS 538 #define BTA_GATTS_SRV_CHG_CMD_READ_CLENT GATTS_SRV_CHG_CMD_READ_CLENT 539 typedef tGATTS_SRV_CHG_CMD tBTA_GATTS_SRV_CHG_CMD; 540 541 typedef tGATTS_SRV_CHG tBTA_GATTS_SRV_CHG; 542 typedef tGATTS_SRV_CHG_REQ tBTA_GATTS_SRV_CHG_REQ; 543 typedef tGATTS_SRV_CHG_RSP tBTA_GATTS_SRV_CHG_RSP; 544 545 #define BTA_GATT_TRANSPORT_LE GATT_TRANSPORT_LE 546 #define BTA_GATT_TRANSPORT_BR_EDR GATT_TRANSPORT_BR_EDR 547 #define BTA_GATT_TRANSPORT_LE_BR_EDR GATT_TRANSPORT_LE_BR_EDR 548 typedef UINT8 tBTA_GATT_TRANSPORT; 549 550 /* attribute value */ 551 typedef tGATT_VALUE tBTA_GATT_VALUE; 552 553 /* attribute response data */ 554 typedef tGATTS_RSP tBTA_GATTS_RSP; 555 556 /* relate to ESP_GATT_PREP_WRITE_xxx in esp_gatt_defs.h */ 557 /* attribute request data from the client */ 558 #define BTA_GATT_PREP_WRITE_CANCEL 0x00 559 #define BTA_GATT_PREP_WRITE_EXEC 0x01 560 typedef tGATT_EXEC_FLAG tBTA_GATT_EXEC_FLAG; 561 562 /* read request always based on UUID */ 563 typedef tGATT_READ_REQ tBTA_GATT_READ_REQ; 564 565 /* write request data */ 566 typedef tGATT_WRITE_REQ tBTA_GATT_WRITE_REQ; 567 568 /* callback data for server access request from client */ 569 typedef tGATTS_DATA tBTA_GATTS_REQ_DATA; 570 571 typedef struct { 572 tBTA_GATT_STATUS status; 573 BD_ADDR remote_bda; 574 UINT32 trans_id; 575 UINT16 conn_id; 576 UINT16 handle; 577 tBTA_GATTS_REQ_DATA *p_data; 578 UINT16 data_len; 579 UINT8 *value; 580 } tBTA_GATTS_REQ; 581 582 typedef struct { 583 tBTA_GATTS_IF server_if; 584 tBTA_GATT_STATUS status; 585 tBT_UUID uuid; 586 }tBTA_GATTS_REG_OPER; 587 588 589 typedef struct { 590 tBTA_GATTS_IF server_if; 591 UINT16 service_id; 592 UINT16 svc_instance; 593 BOOLEAN is_primary; 594 tBTA_GATT_STATUS status; 595 tBT_UUID uuid; 596 }tBTA_GATTS_CREATE; 597 598 typedef struct { 599 tBTA_GATTS_IF server_if; 600 UINT16 service_id; 601 UINT16 attr_id; 602 tBTA_GATT_STATUS status; 603 tBT_UUID char_uuid; 604 }tBTA_GATTS_ADD_RESULT; 605 typedef struct{ 606 tBTA_GATTS_IF server_if; 607 UINT16 service_id; 608 UINT16 attr_id; 609 tBTA_GATT_STATUS status; 610 }tBAT_GATTS_ATTR_VAL_RESULT; 611 612 typedef struct { 613 tBTA_GATTS_IF server_if; 614 UINT16 service_id; 615 tBTA_GATT_STATUS status; 616 } tBTA_GATTS_SRVC_OPER; 617 618 619 typedef struct { 620 tBTA_GATTS_IF server_if; 621 BD_ADDR remote_bda; 622 UINT16 conn_id; 623 UINT8 link_role; 624 tBTA_GATT_REASON reason; /* report disconnect reason */ 625 tBTA_GATT_TRANSPORT transport; 626 tBTA_GATT_CONN_PARAMS conn_params; 627 UINT8 ble_addr_type; 628 UINT16 conn_handle; 629 } tBTA_GATTS_CONN; 630 631 typedef struct { 632 UINT16 conn_id; 633 BOOLEAN congested; /* report channel congestion indicator */ 634 } tBTA_GATTS_CONGEST; 635 636 typedef struct { 637 UINT16 conn_id; /* connection ID */ 638 tBTA_GATT_STATUS status; /* notification/indication status */ 639 } tBTA_GATTS_CONF; 640 641 typedef struct { 642 tBTA_GATT_STATUS status; 643 UINT16 conn_id; /* connection ID */ 644 } tBTA_GATTS_CLOSE; 645 646 typedef struct { 647 tBTA_GATT_STATUS status; 648 tBTA_GATTS_IF server_if; 649 } tBTA_GATTS_SERVICE_CHANGE; 650 651 typedef struct { 652 tBTA_GATT_STATUS status; 653 tBTA_GATTS_IF server_if; 654 } tBTA_GATTS_OPEN; 655 656 typedef struct { 657 tBTA_GATT_STATUS status; 658 tBTA_GATTS_IF server_if; 659 } tBTA_GATTS_CANCEL_OPEN; 660 /* GATTS callback data */ 661 typedef union { 662 tBTA_GATTS_REG_OPER reg_oper; 663 tBTA_GATTS_CREATE create; 664 tBTA_GATTS_SRVC_OPER srvc_oper; 665 tBTA_GATT_STATUS status; /* BTA_GATTS_LISTEN_EVT */ 666 tBTA_GATTS_ADD_RESULT add_result; /* add included service: BTA_GATTS_ADD_INCL_SRVC_EVT 667 add char : BTA_GATTS_ADD_CHAR_EVT 668 add char descriptor: BTA_GATTS_ADD_CHAR_DESCR_EVT */ 669 tBAT_GATTS_ATTR_VAL_RESULT attr_val; 670 tBTA_GATTS_REQ req_data; 671 tBTA_GATTS_CONN conn; /* BTA_GATTS_CONN_EVT */ 672 tBTA_GATTS_CONGEST congest; /* BTA_GATTS_CONGEST_EVT callback data */ 673 tBTA_GATTS_CONF confirm; /* BTA_GATTS_CONF_EVT callback data */ 674 tBTA_GATTS_CLOSE close; /* BTA_GATTS_CLOSE_EVT callback data */ 675 tBTA_GATTS_OPEN open; /* BTA_GATTS_OPEN_EVT callback data */ 676 tBTA_GATTS_CANCEL_OPEN cancel_open; /* tBTA_GATTS_CANCEL_OPEN callback data */ 677 tBTA_GATTS_SERVICE_CHANGE service_change; 678 679 } tBTA_GATTS; 680 681 /* GATTC wait for service change ccc timer callback data */ 682 typedef struct { 683 UINT16 conn_id; 684 BD_ADDR remote_bda; 685 UINT8 count; 686 UINT8 last_status; 687 }tBTA_GATTC_WAIT_CCC_TIMER; 688 689 /* GATTS enable callback function */ 690 typedef void (tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status); 691 692 /* Server callback function */ 693 typedef void (tBTA_GATTS_CBACK)(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); 694 typedef struct 695 { 696 tBT_UUID uuid; 697 BOOLEAN is_primary; 698 UINT16 handle; 699 UINT16 s_handle; 700 UINT16 e_handle; 701 list_t *characteristics; /* list of tBTA_GATTC_CHARACTERISTIC */ 702 list_t *included_svc; /* list of tBTA_GATTC_INCLUDED_SVC */ 703 } __attribute__((packed)) tBTA_GATTC_SERVICE; 704 705 typedef struct 706 { 707 tBT_UUID uuid; 708 UINT16 handle; 709 tBTA_GATT_CHAR_PROP properties; 710 tBTA_GATTC_SERVICE *service; /* owning service*/ 711 list_t *descriptors; /* list of tBTA_GATTC_DESCRIPTOR */ 712 } __attribute__((packed)) tBTA_GATTC_CHARACTERISTIC; 713 714 typedef struct 715 { 716 tBT_UUID uuid; 717 UINT16 handle; 718 tBTA_GATTC_CHARACTERISTIC *characteristic; /* owning characteristic */ 719 } __attribute__((packed)) tBTA_GATTC_DESCRIPTOR; 720 721 typedef struct 722 { 723 tBT_UUID uuid; 724 UINT16 handle; 725 UINT16 incl_srvc_s_handle; 726 UINT16 incl_srvc_e_handle; 727 tBTA_GATTC_SERVICE *owning_service; /* owning service*/ 728 tBTA_GATTC_SERVICE *included_service; 729 } __attribute__((packed)) tBTA_GATTC_INCLUDED_SVC; 730 731 typedef struct { 732 UINT16 scan_interval; 733 UINT16 scan_window; 734 UINT16 interval_min; 735 UINT16 interval_max; 736 UINT16 latency; 737 UINT16 supervision_timeout; 738 UINT16 min_ce_len; 739 UINT16 max_ce_len; 740 } tBTA_BLE_CONN_PARAMS; 741 742 #define BTA_BLE_PHY_1M_MASK (1 << 0) 743 #define BTA_BLE_PHY_2M_MASK (1 << 1) 744 #define BTA_BLE_PHY_CODED_MASK (1 << 2) 745 746 /***************************************************************************** 747 ** External Function Declarations 748 *****************************************************************************/ 749 750 #ifdef __cplusplus 751 extern "C" 752 { 753 #endif 754 755 /************************** 756 ** Client Functions 757 ***************************/ 758 759 /******************************************************************************* 760 ** 761 ** Function BTA_GATTC_Disable 762 ** 763 ** Description This function is called to disable the GATTC module 764 ** 765 ** Parameters None. 766 ** 767 ** Returns None 768 ** 769 *******************************************************************************/ 770 extern void BTA_GATTC_Disable(void); 771 772 /******************************************************************************* 773 ** 774 ** Function BTA_GATTC_AppRegister 775 ** 776 ** Description This function is called to register application callbacks 777 ** with BTA GATTC module. 778 ** 779 ** Parameters p_app_uuid - application UUID 780 ** p_client_cb - pointer to the application callback function. 781 ** 782 ** Returns None 783 ** 784 *******************************************************************************/ 785 extern void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb); 786 787 /******************************************************************************* 788 ** 789 ** Function BTA_GATTC_AppDeregister 790 ** 791 ** Description This function is called to deregister an application 792 ** from BTA GATTC module. 793 ** 794 ** Parameters client_if - client interface identifier. 795 ** 796 ** Returns None 797 ** 798 *******************************************************************************/ 799 extern void BTA_GATTC_AppDeregister (tBTA_GATTC_IF client_if); 800 801 802 /******************************************************************************* 803 ** 804 ** Function BTA_GATTC_Enh_Open 805 ** 806 ** Description Open a direct connection or add a background auto connection 807 ** bd address 808 ** 809 ** Parameters client_if: server interface. 810 ** remote_bda: remote device BD address. 811 ** remote_addr_type: remote device BD address type. 812 ** is_direct: direct connection or background auto connection. 813 ** own_addr_type: own address type. 814 ** 815 ** Returns void 816 ** 817 *******************************************************************************/ 818 extern void BTA_GATTC_Enh_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type, 819 BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux, tBTA_ADDR_TYPE own_addr_type, 820 UINT8 phy_mask, tBTA_BLE_CONN_PARAMS *phy_1m_conn_params, tBTA_BLE_CONN_PARAMS *phy_2m_conn_params, 821 tBTA_BLE_CONN_PARAMS *phy_coded_conn_params); 822 823 /******************************************************************************* 824 ** 825 ** Function BTA_GATTC_CancelOpen 826 ** 827 ** Description Open a direct connection or add a background auto connection 828 ** bd address 829 ** 830 ** Parameters client_if: server interface. 831 ** remote_bda: remote device BD address. 832 ** is_direct: direct connection or background auto connection 833 ** 834 ** Returns void 835 ** 836 *******************************************************************************/ 837 extern void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct); 838 839 /******************************************************************************* 840 ** 841 ** Function BTA_GATTC_Close 842 ** 843 ** Description Close a connection to a GATT server. 844 ** 845 ** Parameters conn_id: connection ID to be closed. 846 ** 847 ** Returns void 848 ** 849 *******************************************************************************/ 850 extern void BTA_GATTC_Close(UINT16 conn_id); 851 852 /******************************************************************************* 853 ** 854 ** Function BTA_GATTC_ServiceSearchRequest 855 ** 856 ** Description This function is called to request a GATT service discovery 857 ** on a GATT server. This function report service search result 858 ** by a callback event, and followed by a service search complete 859 ** event. 860 ** 861 ** Parameters conn_id: connection ID. 862 ** p_srvc_uuid: a UUID of the service application is interested in. 863 ** If Null, discover for all services. 864 ** 865 ** Returns None 866 ** 867 *******************************************************************************/ 868 extern void BTA_GATTC_ServiceSearchRequest(UINT16 conn_id, tBT_UUID *p_srvc_uuid); 869 870 /******************************************************************************* 871 ** 872 ** Function BTA_GATTC_GetServices 873 ** 874 ** Description This function is called to find the services on the given server. 875 ** 876 ** Parameters conn_id: connection ID which identify the server. 877 ** 878 ** Returns returns list_t of tBTA_GATTC_SERVICE or NULL. 879 ** 880 *******************************************************************************/ 881 extern const list_t* BTA_GATTC_GetServices(UINT16 conn_id); 882 883 /******************************************************************************* 884 ** 885 ** Function BTA_GATTC_GetCharacteristic 886 ** 887 ** Description This function is called to find the characteristic on the given server. 888 ** 889 ** Parameters conn_id: connection ID which identify the server. 890 ** handle: characteristic handle 891 ** 892 ** Returns returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL. 893 ** 894 *******************************************************************************/ 895 extern const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_id, UINT16 handle); 896 897 /******************************************************************************* 898 ** 899 ** Function BTA_GATTC_GetDescriptor 900 ** 901 ** Description This function is called to find the characteristic on the given server. 902 ** 903 ** Parameters conn_id: connection ID which identify the server. 904 ** handle: descriptor handle 905 ** 906 ** Returns returns pointer to tBTA_GATTC_DESCRIPTOR or NULL. 907 ** 908 *******************************************************************************/ 909 extern const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(UINT16 conn_id, UINT16 handle); 910 911 extern void BTA_GATTC_GetServiceWithUUID(UINT16 conn_id, tBT_UUID *svc_uuid, 912 btgatt_db_element_t **db, UINT16 *count); 913 914 extern void BTA_GATTC_GetAllChar(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, 915 btgatt_db_element_t **db, UINT16 *count); 916 917 extern void BTA_GATTC_GetAllDescriptor(UINT16 conn_id, UINT16 char_handle, 918 btgatt_db_element_t **db, UINT16 *count); 919 920 extern void BTA_GATTC_GetCharByUUID(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, tBT_UUID char_uuid, 921 btgatt_db_element_t **db, UINT16 *count); 922 923 extern void BTA_GATTC_GetDescrByUUID(UINT16 conn_id, uint16_t start_handle, uint16_t end_handle, 924 tBT_UUID char_uuid, tBT_UUID descr_uuid, 925 btgatt_db_element_t **db, UINT16 *count); 926 927 extern void BTA_GATTC_GetDescrByCharHandle(UINT16 conn_id, UINT16 char_handle, tBT_UUID descr_uuid, 928 btgatt_db_element_t **db, UINT16 *count); 929 930 extern void BTA_GATTC_GetIncludeService(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, 931 tBT_UUID *incl_uuid, btgatt_db_element_t **db, UINT16 *count); 932 933 extern void BTA_GATTC_GetDBSize(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, UINT16 *count); 934 935 extern void BTA_GATTC_GetDBSizeByType(UINT16 conn_id, bt_gatt_db_attribute_type_t type, 936 UINT16 start_handle, UINT16 end_handle, UINT16 char_handle, UINT16 *count); 937 938 /******************************************************************************* 939 ** 940 ** Function BTA_GATTC_GetGattDb 941 ** 942 ** Description This function is called to get gatt db. 943 ** 944 ** Parameters conn_id: connection ID which identify the server. 945 ** db: output parameter which will contain gatt db copy. 946 ** Caller is responsible for freeing it. 947 ** count: number of elements in db. 948 ** 949 *******************************************************************************/ 950 extern void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, 951 btgatt_db_element_t **db, UINT16 *count); 952 953 /******************************************************************************* 954 ** 955 ** Function BTA_GATTC_ReadCharacteristic 956 ** 957 ** Description This function is called to read a characteristics value 958 ** 959 ** Parameters conn_id - connection ID. 960 ** handle - characteristic handle to read. 961 ** 962 ** Returns None 963 ** 964 *******************************************************************************/ 965 void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req); 966 967 /******************************************************************************* 968 ** 969 ** Function BTA_GATTC_Read_by_type 970 ** 971 ** Description This function is called to read a attribute value by uuid 972 ** 973 ** Parameters conn_id - connection ID. 974 ** s_handle - start handle. 975 ** e_handle - end handle 976 ** uuid - The attribute UUID. 977 ** 978 ** Returns None 979 ** 980 *******************************************************************************/ 981 void BTA_GATTC_Read_by_type(UINT16 conn_id, UINT16 s_handle,UINT16 e_handle, tBT_UUID *uuid, tBTA_GATT_AUTH_REQ auth_req); 982 983 /******************************************************************************* 984 ** 985 ** Function BTA_GATTC_ReadCharDescr 986 ** 987 ** Description This function is called to read a descriptor value. 988 ** 989 ** Parameters conn_id - connection ID. 990 ** handle - descriptor handle to read. 991 ** 992 ** Returns None 993 ** 994 *******************************************************************************/ 995 void BTA_GATTC_ReadCharDescr (UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req); 996 997 /******************************************************************************* 998 ** 999 ** Function BTA_GATTC_WriteCharValue 1000 ** 1001 ** Description This function is called to write characteristic value. 1002 ** 1003 ** Parameters conn_id - connection ID. 1004 ** handle - characteristic handle to write. 1005 ** write_type - type of write. 1006 ** len: length of the data to be written. 1007 ** p_value - the value to be written. 1008 ** 1009 ** Returns None 1010 ** 1011 *******************************************************************************/ 1012 void BTA_GATTC_WriteCharValue ( UINT16 conn_id, 1013 UINT16 handle, 1014 tBTA_GATTC_WRITE_TYPE write_type, 1015 UINT16 len, 1016 UINT8 *p_value, 1017 tBTA_GATT_AUTH_REQ auth_req); 1018 1019 /******************************************************************************* 1020 ** 1021 ** Function BTA_GATTC_WriteCharDescr 1022 ** 1023 ** Description This function is called to write descriptor value. 1024 ** 1025 ** Parameters conn_id - connection ID 1026 ** handle - descriptor handle to write. 1027 ** write_type - type of write. 1028 ** p_value - the value to be written. 1029 ** 1030 ** Returns None 1031 ** 1032 *******************************************************************************/ 1033 void BTA_GATTC_WriteCharDescr (UINT16 conn_id, 1034 UINT16 handle, 1035 tBTA_GATTC_WRITE_TYPE write_type, 1036 tBTA_GATT_UNFMT *p_data, 1037 tBTA_GATT_AUTH_REQ auth_req); 1038 1039 /******************************************************************************* 1040 ** 1041 ** Function BTA_GATTC_SendIndConfirm 1042 ** 1043 ** Description This function is called to send handle value confirmation. 1044 ** 1045 ** Parameters conn_id - connection ID. 1046 ** handle - characteristic handle to confirm. 1047 ** 1048 ** Returns None 1049 ** 1050 *******************************************************************************/ 1051 extern void BTA_GATTC_SendIndConfirm (UINT16 conn_id, UINT16 handle); 1052 1053 /******************************************************************************* 1054 ** 1055 ** Function BTA_GATTC_RegisterForNotifications 1056 ** 1057 ** Description This function is called to register for notification of a service. 1058 ** 1059 ** Parameters client_if - client interface. 1060 ** remote_bda - target GATT server. 1061 ** handle - GATT characteristic handle. 1062 ** 1063 ** Returns OK if registration succeed, otherwise failed. 1064 ** 1065 *******************************************************************************/ 1066 extern tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if, 1067 BD_ADDR remote_bda, 1068 UINT16 handle); 1069 1070 /******************************************************************************* 1071 ** 1072 ** Function BTA_GATTC_DeregisterForNotifications 1073 ** 1074 ** Description This function is called to de-register for notification of a servbice. 1075 ** 1076 ** Parameters client_if - client interface. 1077 ** remote_bda - target GATT server. 1078 ** handle - GATT characteristic handle. 1079 ** 1080 ** Returns OK if deregistration succeed, otherwise failed. 1081 ** 1082 *******************************************************************************/ 1083 extern tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF client_if, 1084 BD_ADDR remote_bda, 1085 UINT16 handle); 1086 1087 /******************************************************************************* 1088 ** 1089 ** Function BTA_GATTC_PrepareWrite 1090 ** 1091 ** Description This function is called to prepare write a characteristic value. 1092 ** 1093 ** Parameters conn_id - connection ID. 1094 ** handle - GATT characteristic handle. 1095 ** offset - offset of the write value. 1096 ** len - length of the data to be written. 1097 ** p_value - the value to be written. 1098 ** 1099 ** Returns None 1100 ** 1101 *******************************************************************************/ 1102 extern void BTA_GATTC_PrepareWrite (UINT16 conn_id, 1103 UINT16 handle, 1104 UINT16 offset, 1105 UINT16 len, 1106 UINT8 *p_value, 1107 tBTA_GATT_AUTH_REQ auth_req); 1108 1109 /******************************************************************************* 1110 ** 1111 ** Function BTA_GATTC_PrepareWriteCharDescr 1112 ** 1113 ** Description This function is called to prepare write a characteristic descriptor value. 1114 ** 1115 ** Parameters conn_id - connection ID. 1116 ** p_char_descr_id - GATT characteristic descriptor ID of the service. 1117 ** offset - offset of the write value. 1118 ** len: length of the data to be written. 1119 ** p_value - the value to be written. 1120 ** 1121 ** Returns None 1122 ** 1123 *******************************************************************************/ 1124 extern void BTA_GATTC_PrepareWriteCharDescr (UINT16 conn_id, 1125 UINT16 handle, 1126 UINT16 offset, 1127 tBTA_GATT_UNFMT *p_data, 1128 tBTA_GATT_AUTH_REQ auth_req); 1129 /******************************************************************************* 1130 ** 1131 ** Function BTA_GATTC_ExecuteWrite 1132 ** 1133 ** Description This function is called to execute write a prepare write sequence. 1134 ** 1135 ** Parameters conn_id - connection ID. 1136 ** is_execute - execute or cancel. 1137 ** 1138 ** Returns None 1139 ** 1140 *******************************************************************************/ 1141 extern void BTA_GATTC_ExecuteWrite (UINT16 conn_id, BOOLEAN is_execute); 1142 1143 /******************************************************************************* 1144 ** 1145 ** Function BTA_GATTC_ReadMultiple 1146 ** 1147 ** Description This function is called to read multiple characteristic or 1148 ** characteristic descriptors. 1149 ** 1150 ** Parameters conn_id - connection ID. 1151 ** p_read_multi - read multiple parameters. 1152 ** 1153 ** Returns None 1154 ** 1155 *******************************************************************************/ 1156 extern void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi, 1157 tBTA_GATT_AUTH_REQ auth_req); 1158 1159 /******************************************************************************* 1160 ** 1161 ** Function BTA_GATTC_ReadMultiple 1162 ** 1163 ** Description This function is called to read multiple variable length characteristic or 1164 ** characteristic descriptors. 1165 ** 1166 ** Parameters conn_id - connection ID. 1167 ** p_read_multi - read multiple parameters. 1168 ** 1169 ** Returns None 1170 ** 1171 *******************************************************************************/ 1172 extern void BTA_GATTC_ReadMultipleVariable(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi, 1173 tBTA_GATT_AUTH_REQ auth_req); 1174 1175 /******************************************************************************* 1176 ** 1177 ** Function BTA_GATTC_Refresh 1178 ** 1179 ** Description Refresh the server cache of the remote device 1180 ** 1181 ** Parameters remote_bda: remote device BD address. 1182 ** erase_flash: delete cache from nvs flash 1183 ** 1184 ** Returns void 1185 ** 1186 *******************************************************************************/ 1187 extern void BTA_GATTC_Refresh(BD_ADDR remote_bda, bool erase_flash); 1188 1189 extern void BTA_GATTC_CacheAssoc(tBTA_GATTC_IF client_if, BD_ADDR src_addr, BD_ADDR assoc_addr, BOOLEAN is_assoc); 1190 1191 extern void BTA_GATTC_CacheGetAddrList(tBTA_GATTC_IF client_if); 1192 1193 /******************************************************************************* 1194 ** 1195 ** Function BTA_GATTC_Clean 1196 ** 1197 ** Description Clean the server cache of the remote device 1198 ** 1199 ** Parameters remote_bda: remote device BD address. 1200 ** 1201 ** Returns void 1202 ** 1203 *******************************************************************************/ 1204 extern void BTA_GATTC_Clean(BD_ADDR remote_bda); 1205 1206 /******************************************************************************* 1207 ** 1208 ** Function BTA_GATTC_Listen 1209 ** 1210 ** Description Start advertisement to listen for connection request. 1211 ** 1212 ** Parameters client_if: server interface. 1213 ** start: to start or stop listening for connection 1214 ** remote_bda: remote device BD address, if listen to all device 1215 ** use NULL. 1216 ** 1217 ** Returns void 1218 ** 1219 *******************************************************************************/ 1220 extern void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target_bda); 1221 1222 /******************************************************************************* 1223 ** 1224 ** Function BTA_GATTC_Broadcast 1225 ** 1226 ** Description Start broadcasting (non-connectable advertisements) 1227 ** 1228 ** Parameters client_if: client interface. 1229 ** start: to start or stop listening for connection 1230 ** 1231 ** Returns void 1232 ** 1233 *******************************************************************************/ 1234 extern void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start); 1235 1236 1237 /******************************************************************************* 1238 ** 1239 ** Function BTA_GATTC_ConfigureMTU 1240 ** 1241 ** Description Configure the MTU size in the GATT channel. This can be done 1242 ** only once per connection. 1243 ** 1244 ** Parameters conn_id: connection ID. 1245 ** 1246 ** 1247 ** Returns void 1248 ** 1249 *******************************************************************************/ 1250 extern void BTA_GATTC_ConfigureMTU (UINT16 conn_id); 1251 1252 /******************************************************************************* 1253 ** BTA GATT Server API 1254 ********************************************************************************/ 1255 1256 /******************************************************************************* 1257 ** 1258 ** Function BTA_GATTS_Init 1259 ** 1260 ** Description This function is called to initialize GATTS module 1261 ** 1262 ** Parameters None 1263 ** 1264 ** Returns None 1265 ** 1266 *******************************************************************************/ 1267 extern void BTA_GATTS_Init(void); 1268 1269 /******************************************************************************* 1270 ** 1271 ** Function BTA_GATTS_Disable 1272 ** 1273 ** Description This function is called to disable GATTS module 1274 ** 1275 ** Parameters None. 1276 ** 1277 ** Returns None 1278 ** 1279 *******************************************************************************/ 1280 extern void BTA_GATTS_Disable(void); 1281 1282 /******************************************************************************* 1283 ** 1284 ** Function BTA_GATTS_AppRegister 1285 ** 1286 ** Description This function is called to register application callbacks 1287 ** with BTA GATTS module. 1288 ** 1289 ** Parameters p_app_uuid - application UUID 1290 ** p_cback - pointer to the application callback function. 1291 ** 1292 ** Returns None 1293 ** 1294 *******************************************************************************/ 1295 extern void BTA_GATTS_AppRegister(const tBT_UUID * p_app_uuid, tBTA_GATTS_CBACK *p_cback); 1296 1297 1298 /******************************************************************************* 1299 ** 1300 ** Function BTA_GATTS_AppDeregister 1301 ** 1302 ** Description De-register with BTA GATT Server. 1303 ** 1304 ** Parameters server_if: server interface 1305 ** 1306 ** Returns void 1307 ** 1308 *******************************************************************************/ 1309 extern void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if); 1310 1311 /******************************************************************************* 1312 ** 1313 ** Function BTA_GATTS_CreateService 1314 ** 1315 ** Description Create a service. When service creation is done, a callback 1316 ** event BTA_GATTS_CREATE_EVT is called to report status 1317 ** and service ID to the profile. The service ID obtained in 1318 ** the callback function needs to be used when adding included 1319 ** service and characteristics/descriptors into the service. 1320 ** 1321 ** Parameters server_if: server interface. 1322 ** p_service_uuid: service UUID. 1323 ** inst: instance ID number of this service. 1324 ** num_handle: numble of handle requessted for this service. 1325 ** is_primary: is this service a primary one or not. 1326 ** 1327 ** Returns void 1328 ** 1329 *******************************************************************************/ 1330 extern void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, const tBT_UUID * p_service_uuid, 1331 UINT8 inst, UINT16 num_handle, BOOLEAN is_primary); 1332 1333 /******************************************************************************* 1334 ** 1335 ** Function BTA_GATTS_AddIncludeService 1336 ** 1337 ** Description This function is called to add an included service. After included 1338 ** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT 1339 ** is reported the included service ID. 1340 ** 1341 ** Parameters service_id: service ID to which this included service is to 1342 ** be added. 1343 ** included_service_id: the service ID to be included. 1344 ** 1345 ** Returns void 1346 ** 1347 *******************************************************************************/ 1348 extern void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id); 1349 1350 /******************************************************************************* 1351 ** 1352 ** Function BTA_GATTS_AddCharacteristic 1353 ** 1354 ** Description This function is called to add a characteristic into a service. 1355 ** 1356 ** Parameters service_id: service ID to which this included service is to 1357 ** be added. 1358 ** p_char_uuid : Characteristic UUID. 1359 ** perm : Characteristic value declaration attribute permission. 1360 ** property : Characteristic Properties 1361 ** 1362 ** Returns None 1363 ** 1364 *******************************************************************************/ 1365 extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, const tBT_UUID * p_char_uuid, 1366 tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property, tGATT_ATTR_VAL *attr_val, 1367 tBTA_GATTS_ATTR_CONTROL *control); 1368 1369 /******************************************************************************* 1370 ** 1371 ** Function BTA_GATTS_AddCharDescriptor 1372 ** 1373 ** Description This function is called to add characteristic descriptor. When 1374 ** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called 1375 ** to report the status and an ID number for this descriptor. 1376 ** 1377 ** Parameters service_id: service ID to which this charatceristic descriptor is to 1378 ** be added. 1379 ** perm: descriptor access permission. 1380 ** p_descr_uuid: descriptor UUID. 1381 ** p_descr_params: descriptor value if it's read only descriptor. 1382 ** 1383 ** Returns returns status. 1384 ** 1385 *******************************************************************************/ 1386 extern void BTA_GATTS_AddCharDescriptor (UINT16 service_id, 1387 tBTA_GATT_PERM perm, 1388 const tBT_UUID * p_descr_uuid, tBTA_GATT_ATTR_VAL *attr_val, 1389 tBTA_GATTS_ATTR_CONTROL *control); 1390 1391 /******************************************************************************* 1392 ** 1393 ** Function BTA_GATTS_DeleteService 1394 ** 1395 ** Description This function is called to delete a service. When this is done, 1396 ** a callback event BTA_GATTS_DELETE_EVT is report with the status. 1397 ** 1398 ** Parameters service_id: service_id to be deleted. 1399 ** 1400 ** Returns returns none. 1401 ** 1402 *******************************************************************************/ 1403 extern void BTA_GATTS_DeleteService(UINT16 service_id); 1404 1405 /******************************************************************************* 1406 ** 1407 ** Function BTA_GATTS_StartService 1408 ** 1409 ** Description This function is called to start a service. 1410 ** 1411 ** Parameters service_id: the service ID to be started. 1412 ** sup_transport: supported transport. 1413 ** 1414 ** Returns None. 1415 ** 1416 *******************************************************************************/ 1417 extern void BTA_GATTS_StartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transport); 1418 1419 /******************************************************************************* 1420 ** 1421 ** Function BTA_GATTS_StopService 1422 ** 1423 ** Description This function is called to stop a service. 1424 ** 1425 ** Parameters service_id - service to be topped. 1426 ** 1427 ** Returns None 1428 ** 1429 *******************************************************************************/ 1430 extern void BTA_GATTS_StopService(UINT16 service_id); 1431 1432 /******************************************************************************* 1433 ** 1434 ** Function BTA_GATTS_HandleValueIndication 1435 ** 1436 ** Description This function is called to read a characteristics descriptor. 1437 ** 1438 ** Parameters conn_id - connection identifier. 1439 ** attr_id - attribute ID to indicate. 1440 ** data_len - indicate data length. 1441 ** p_data: data to indicate. 1442 ** need_confirm - if this indication expects a confirmation or not. 1443 ** 1444 ** Returns None 1445 ** 1446 *******************************************************************************/ 1447 extern void BTA_GATTS_HandleValueIndication (UINT16 conn_id, UINT16 attr_id, 1448 UINT16 data_len, 1449 UINT8 *p_data, 1450 BOOLEAN need_confirm); 1451 1452 /******************************************************************************* 1453 ** 1454 ** Function BTA_GATTS_SendRsp 1455 ** 1456 ** Description This function is called to send a response to a request. 1457 ** 1458 ** Parameters conn_id - connection identifier. 1459 ** trans_id - transaction ID. 1460 ** status - response status 1461 ** p_msg - response data. 1462 ** 1463 ** Returns None 1464 ** 1465 *******************************************************************************/ 1466 extern void BTA_GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id, 1467 tBTA_GATT_STATUS status, tBTA_GATTS_RSP *p_msg); 1468 1469 1470 1471 /******************************************************************************* 1472 ** 1473 ** Function BTA_SetAttributeValue 1474 ** 1475 ** Description This function is called to set the attribute value in the gatt database 1476 ** 1477 ** Parameters attr_handle - the attribute value handle. 1478 ** length - the value length which has been set to the attribute. 1479 ** value - the pointer to the value 1480 ** 1481 ** Returns None 1482 ** 1483 *******************************************************************************/ 1484 extern void BTA_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *value); 1485 1486 1487 /******************************************************************************* 1488 ** 1489 ** Function BTA_GetAttributeValue 1490 ** 1491 ** Description This function is called to get the attribute value in the gatt database 1492 ** 1493 ** Parameters attr_handle - the attribute value handle. 1494 ** length - the value length which has been set to the attribute. 1495 ** value - the pointer to the value 1496 ** 1497 ** Returns tBTA_GATT_STATUS 1498 ** 1499 *******************************************************************************/ 1500 extern tBTA_GATT_STATUS BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value); 1501 1502 /******************************************************************************* 1503 ** 1504 ** Function BTA_GATTS_Open 1505 ** 1506 ** Description Open a direct open connection or add a background auto connection 1507 ** bd address 1508 ** 1509 ** Parameters server_if: server interface. 1510 ** remote_bda: remote device BD address. 1511 ** is_direct: direct connection or background auto connection 1512 ** 1513 ** Returns void 1514 ** 1515 *******************************************************************************/ 1516 extern void BTA_GATTS_Open(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, 1517 BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport); 1518 1519 1520 /******************************************************************************* 1521 ** 1522 ** Function BTA_GATTS_CancelOpen 1523 ** 1524 ** Description Cancel a direct open connection or remove a background auto connection 1525 ** bd address 1526 ** 1527 ** Parameters server_if: server interface. 1528 ** remote_bda: remote device BD address. 1529 ** is_direct: direct connection or background auto connection 1530 ** 1531 ** Returns void 1532 ** 1533 *******************************************************************************/ 1534 extern void BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct); 1535 1536 1537 /******************************************************************************* 1538 ** 1539 ** Function BTA_GATTS_Close 1540 ** 1541 ** Description Close a connection a remote device. 1542 ** 1543 ** Parameters conn_id: connection ID to be closed. 1544 ** 1545 ** Returns void 1546 ** 1547 *******************************************************************************/ 1548 extern void BTA_GATTS_Close(UINT16 conn_id); 1549 1550 /******************************************************************************* 1551 ** 1552 ** Function BTA_GATTS_SendServiceChangeIndication 1553 ** 1554 ** Description send a service change indication. 1555 ** 1556 ** Returns void 1557 ** 1558 *******************************************************************************/ 1559 1560 void BTA_GATTS_SendServiceChangeIndication(tBTA_GATTS_IF server_if, BD_ADDR remote_bda); 1561 1562 /******************************************************************************* 1563 ** 1564 ** Function BTA_GATTS_Listen 1565 ** 1566 ** Description Start advertisement to listen for connection request for a 1567 ** GATT server 1568 ** 1569 ** Parameters server_if: server interface. 1570 ** start: to start or stop listening for connection 1571 ** remote_bda: remote device BD address, if listen to all device 1572 ** use NULL. 1573 ** 1574 ** Returns void 1575 ** 1576 *******************************************************************************/ 1577 extern void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, BOOLEAN start, 1578 BD_ADDR_PTR target_bda); 1579 1580 /******************************************************************************* 1581 ** 1582 ** Function BTA_GATTS_ShowLocalDatabase 1583 ** 1584 ** Description print local service database. 1585 ** 1586 ** Returns void 1587 ** 1588 *******************************************************************************/ 1589 extern void BTA_GATTS_ShowLocalDatabase(void); 1590 1591 extern void bta_gattc_clcb_dealloc_by_conn_id(UINT16 conn_id); 1592 1593 #ifdef __cplusplus 1594 1595 } 1596 #endif 1597 1598 1599 #endif /* BTA_GATT_API_H */ 1600