1 /****************************************************************************** 2 * 3 * Copyright 1999-2012 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 #ifndef GATT_INT_H 20 #define GATT_INT_H 21 22 #include "bt_target.h" 23 24 #include "btm_ble_api.h" 25 #include "btu.h" 26 #include "gatt_api.h" 27 #include "osi/include/fixed_queue.h" 28 29 #include <base/strings/stringprintf.h> 30 #include <string.h> 31 #include <list> 32 #include <unordered_set> 33 #include <vector> 34 35 #define GATT_CREATE_CONN_ID(tcb_idx, gatt_if) \ 36 ((uint16_t)((((uint8_t)(tcb_idx)) << 8) | ((uint8_t)(gatt_if)))) 37 #define GATT_GET_TCB_IDX(conn_id) ((uint8_t)(((uint16_t)(conn_id)) >> 8)) 38 #define GATT_GET_GATT_IF(conn_id) ((tGATT_IF)((uint8_t)(conn_id))) 39 40 #define GATT_TRANS_ID_MAX 0x0fffffff /* 4 MSB is reserved */ 41 42 /* security action for GATT write and read request */ 43 #define GATT_SEC_NONE 0 44 #define GATT_SEC_OK 1 45 #define GATT_SEC_SIGN_DATA 2 /* compute the signature for the write cmd */ 46 #define GATT_SEC_ENCRYPT 3 /* encrypt the link with current key */ 47 #define GATT_SEC_ENCRYPT_NO_MITM 4 /* unauthenticated encryption or better */ 48 #define GATT_SEC_ENCRYPT_MITM 5 /* authenticated encryption */ 49 #define GATT_SEC_ENC_PENDING 6 /* wait for link encryption pending */ 50 typedef uint8_t tGATT_SEC_ACTION; 51 52 #define GATT_ATTR_OP_SPT_MTU (0x00000001 << 0) 53 #define GATT_ATTR_OP_SPT_FIND_INFO (0x00000001 << 1) 54 #define GATT_ATTR_OP_SPT_FIND_BY_TYPE (0x00000001 << 2) 55 #define GATT_ATTR_OP_SPT_READ_BY_TYPE (0x00000001 << 3) 56 #define GATT_ATTR_OP_SPT_READ (0x00000001 << 4) 57 #define GATT_ATTR_OP_SPT_MULT_READ (0x00000001 << 5) 58 #define GATT_ATTR_OP_SPT_READ_BLOB (0x00000001 << 6) 59 #define GATT_ATTR_OP_SPT_READ_BY_GRP_TYPE (0x00000001 << 7) 60 #define GATT_ATTR_OP_SPT_WRITE (0x00000001 << 8) 61 #define GATT_ATTR_OP_SPT_WRITE_CMD (0x00000001 << 9) 62 #define GATT_ATTR_OP_SPT_PREP_WRITE (0x00000001 << 10) 63 #define GATT_ATTR_OP_SPT_EXE_WRITE (0x00000001 << 11) 64 #define GATT_ATTR_OP_SPT_HDL_VALUE_CONF (0x00000001 << 12) 65 #define GATT_ATTR_OP_SP_SIGN_WRITE (0x00000001 << 13) 66 67 #define GATT_INDEX_INVALID 0xff 68 69 #define GATT_PENDING_REQ_NONE 0 70 71 #define GATT_WRITE_CMD_MASK 0xc0 /*0x1100-0000*/ 72 #define GATT_AUTH_SIGN_MASK 0x80 /*0x1000-0000*/ 73 #define GATT_AUTH_SIGN_LEN 12 74 75 #define GATT_HDR_SIZE 3 /* 1B opcode + 2B handle */ 76 77 /* wait for ATT cmd response timeout value */ 78 #define GATT_WAIT_FOR_RSP_TIMEOUT_MS (30 * 1000) 79 #define GATT_WAIT_FOR_DISC_RSP_TIMEOUT_MS (5 * 1000) 80 #define GATT_REQ_RETRY_LIMIT 2 81 82 /* characteristic descriptor type */ 83 #define GATT_DESCR_EXT_DSCPTOR 1 /* Characteristic Extended Properties */ 84 #define GATT_DESCR_USER_DSCPTOR 2 /* Characteristic User Description */ 85 #define GATT_DESCR_CLT_CONFIG 3 /* Client Characteristic Configuration */ 86 #define GATT_DESCR_SVR_CONFIG 4 /* Server Characteristic Configuration */ 87 #define GATT_DESCR_PRES_FORMAT 5 /* Characteristic Presentation Format */ 88 #define GATT_DESCR_AGGR_FORMAT 6 /* Characteristic Aggregate Format */ 89 #define GATT_DESCR_VALID_RANGE 7 /* Characteristic Valid Range */ 90 #define GATT_DESCR_UNKNOWN 0xff 91 92 #define GATT_SEC_FLAG_LKEY_UNAUTHED BTM_SEC_FLAG_LKEY_KNOWN 93 #define GATT_SEC_FLAG_LKEY_AUTHED BTM_SEC_FLAG_LKEY_AUTHED 94 #define GATT_SEC_FLAG_ENCRYPTED BTM_SEC_FLAG_ENCRYPTED 95 typedef uint8_t tGATT_SEC_FLAG; 96 97 /* Find Information Response Type 98 */ 99 #define GATT_INFO_TYPE_PAIR_16 0x01 100 #define GATT_INFO_TYPE_PAIR_128 0x02 101 102 /* GATT client FIND_TYPE_VALUE_Request data */ 103 typedef struct { 104 bluetooth::Uuid uuid; /* type of attribute to be found */ 105 uint16_t s_handle; /* starting handle */ 106 uint16_t e_handle; /* ending handle */ 107 uint16_t value_len; /* length of the attribute value */ 108 uint8_t 109 value[GATT_MAX_MTU_SIZE]; /* pointer to the attribute value to be found */ 110 } tGATT_FIND_TYPE_VALUE; 111 112 /* client request message to ATT protocol 113 */ 114 typedef union { 115 tGATT_READ_BY_TYPE browse; /* read by type request */ 116 tGATT_FIND_TYPE_VALUE find_type_value; /* find by type value */ 117 tGATT_READ_MULTI read_multi; /* read multiple request */ 118 tGATT_READ_PARTIAL read_blob; /* read blob */ 119 tGATT_VALUE attr_value; /* write request */ 120 /* prepare write */ 121 /* write blob */ 122 uint16_t handle; /* read, handle value confirmation */ 123 uint16_t mtu; 124 tGATT_EXEC_FLAG exec_write; /* execute write */ 125 } tGATT_CL_MSG; 126 127 /* error response strucutre */ 128 typedef struct { 129 uint16_t handle; 130 uint8_t cmd_code; 131 uint8_t reason; 132 } tGATT_ERROR; 133 134 /* server response message to ATT protocol 135 */ 136 typedef union { 137 /* data type member event */ 138 tGATT_VALUE attr_value; /* READ, HANDLE_VALUE_IND, PREPARE_WRITE */ 139 /* READ_BLOB, READ_BY_TYPE */ 140 tGATT_ERROR error; /* ERROR_RSP */ 141 uint16_t handle; /* WRITE, WRITE_BLOB */ 142 uint16_t mtu; /* exchange MTU request */ 143 } tGATT_SR_MSG; 144 145 /* Characteristic declaration attribute value 146 */ 147 typedef struct { 148 tGATT_CHAR_PROP property; 149 uint16_t char_val_handle; 150 } tGATT_CHAR_DECL; 151 152 /* attribute value maintained in the server database 153 */ 154 typedef union { 155 bluetooth::Uuid uuid; /* service declaration */ 156 tGATT_CHAR_DECL char_decl; /* characteristic declaration */ 157 tGATT_INCL_SRVC incl_handle; /* included service */ 158 } tGATT_ATTR_VALUE; 159 160 /* Attribute UUID type 161 */ 162 #define GATT_ATTR_UUID_TYPE_16 0 163 #define GATT_ATTR_UUID_TYPE_128 1 164 #define GATT_ATTR_UUID_TYPE_32 2 165 typedef uint8_t tGATT_ATTR_UUID_TYPE; 166 167 /* 16 bits UUID Attribute in server database 168 */ 169 typedef struct { 170 std::unique_ptr<tGATT_ATTR_VALUE> p_value; 171 tGATT_PERM permission; 172 uint16_t handle; 173 bluetooth::Uuid uuid; 174 bt_gatt_db_attribute_type_t gatt_type; 175 } tGATT_ATTR; 176 177 /* Service Database definition 178 */ 179 typedef struct { 180 std::vector<tGATT_ATTR> attr_list; /* pointer to the attributes */ 181 uint16_t end_handle; /* Last handle number */ 182 uint16_t next_handle; /* Next usable handle value */ 183 } tGATT_SVC_DB; 184 185 /* Data Structure used for GATT server */ 186 /* An GATT registration record consists of a handle, and 1 or more attributes */ 187 /* A service registration information record consists of beginning and ending */ 188 /* attribute handle, service UUID and a set of GATT server callback. */ 189 190 typedef struct { 191 bluetooth::Uuid app_uuid128; 192 tGATT_CBACK app_cb; 193 tGATT_IF gatt_if; /* one based */ 194 bool in_use; 195 uint8_t listening; /* if adv for all has been enabled */ 196 } tGATT_REG; 197 198 struct tGATT_CLCB; 199 200 /* command queue for each connection */ 201 typedef struct { 202 BT_HDR* p_cmd; 203 tGATT_CLCB* p_clcb; 204 uint8_t op_code; 205 bool to_send; 206 } tGATT_CMD_Q; 207 208 #if GATT_MAX_SR_PROFILES <= 8 209 typedef uint8_t tGATT_APP_MASK; 210 #elif GATT_MAX_SR_PROFILES <= 16 211 typedef uint16_t tGATT_APP_MASK; 212 #elif GATT_MAX_SR_PROFILES <= 32 213 typedef uint32_t tGATT_APP_MASK; 214 #endif 215 216 /* command details for each connection */ 217 typedef struct { 218 BT_HDR* p_rsp_msg; 219 uint32_t trans_id; 220 tGATT_READ_MULTI multi_req; 221 fixed_queue_t* multi_rsp_q; 222 uint16_t handle; 223 uint8_t op_code; 224 uint8_t status; 225 uint8_t cback_cnt[GATT_MAX_APPS]; 226 } tGATT_SR_CMD; 227 228 #define GATT_CH_CLOSE 0 229 #define GATT_CH_CLOSING 1 230 #define GATT_CH_CONN 2 231 #define GATT_CH_CFG 3 232 #define GATT_CH_OPEN 4 233 234 typedef uint8_t tGATT_CH_STATE; 235 236 #define GATT_GATT_START_HANDLE 1 237 #define GATT_GAP_START_HANDLE 20 238 #define GATT_APP_START_HANDLE 40 239 240 typedef struct hdl_cfg { 241 uint16_t gatt_start_hdl; 242 uint16_t gap_start_hdl; 243 uint16_t app_start_hdl; 244 } tGATT_HDL_CFG; 245 246 typedef struct hdl_list_elem { 247 tGATTS_HNDL_RANGE asgn_range; /* assigned handle range */ 248 tGATT_SVC_DB svc_db; 249 } tGATT_HDL_LIST_ELEM; 250 251 /* Data Structure used for GATT server */ 252 /* A GATT registration record consists of a handle, and 1 or more attributes */ 253 /* A service registration information record consists of beginning and ending */ 254 /* attribute handle, service UUID and a set of GATT server callback. */ 255 typedef struct { 256 tGATT_SVC_DB* p_db; /* pointer to the service database */ 257 bluetooth::Uuid app_uuid; /* application UUID */ 258 uint32_t sdp_handle; /* primamry service SDP handle */ 259 uint16_t type; /* service type UUID, primary or secondary */ 260 uint16_t s_hdl; /* service starting handle */ 261 uint16_t e_hdl; /* service ending handle */ 262 tGATT_IF gatt_if; /* this service is belong to which application */ 263 bool is_primary; 264 } tGATT_SRV_LIST_ELEM; 265 266 typedef struct { 267 std::queue<tGATT_CLCB*> pending_enc_clcb; /* pending encryption channel q */ 268 tGATT_SEC_ACTION sec_act; 269 RawAddress peer_bda; 270 tBT_TRANSPORT transport; 271 uint32_t trans_id; 272 273 uint16_t att_lcid; /* L2CAP channel ID for ATT */ 274 uint16_t payload_size; 275 276 tGATT_CH_STATE ch_state; 277 uint8_t ch_flags; 278 279 std::unordered_set<uint8_t> app_hold_link; 280 281 /* server needs */ 282 /* server response data */ 283 tGATT_SR_CMD sr_cmd; 284 uint16_t indicate_handle; 285 fixed_queue_t* pending_ind_q; 286 287 alarm_t* conf_timer; /* peer confirm to indication timer */ 288 289 uint8_t prep_cnt[GATT_MAX_APPS]; 290 uint8_t ind_count; 291 292 std::queue<tGATT_CMD_Q> cl_cmd_q; 293 alarm_t* ind_ack_timer; /* local app confirm to indication timer */ 294 295 bool in_use; 296 uint8_t tcb_idx; 297 } tGATT_TCB; 298 299 /* logic channel */ 300 typedef struct { 301 uint16_t 302 next_disc_start_hdl; /* starting handle for the next inc srvv discovery */ 303 tGATT_DISC_RES result; 304 bool wait_for_read_rsp; 305 } tGATT_READ_INC_UUID128; 306 struct tGATT_CLCB { 307 tGATT_TCB* p_tcb; /* associated TCB of this CLCB */ 308 tGATT_REG* p_reg; /* owner of this CLCB */ 309 uint8_t sccb_idx; 310 uint8_t* p_attr_buf; /* attribute buffer for read multiple, prepare write */ 311 bluetooth::Uuid uuid; 312 uint16_t conn_id; /* connection handle */ 313 uint16_t s_handle; /* starting handle of the active request */ 314 uint16_t e_handle; /* ending handle of the active request */ 315 uint16_t counter; /* used as offset, attribute length, num of prepare write */ 316 uint16_t start_offset; 317 tGATT_AUTH_REQ auth_req; /* authentication requirement */ 318 uint8_t operation; /* one logic channel can have one operation active */ 319 uint8_t op_subtype; /* operation subtype */ 320 uint8_t status; /* operation status */ 321 bool first_read_blob_after_read; 322 tGATT_READ_INC_UUID128 read_uuid128; 323 bool in_use; 324 alarm_t* gatt_rsp_timer_ent; /* peer response timer */ 325 uint8_t retry_count; 326 uint16_t read_req_current_mtu; /* This is the MTU value that the read was 327 initiated with */ 328 }; 329 330 typedef struct { 331 uint16_t handle; 332 uint16_t uuid; 333 uint32_t service_change; 334 } tGATT_SVC_CHG; 335 336 #define GATT_SVC_CHANGED_CONNECTING 1 /* wait for connection */ 337 #define GATT_SVC_CHANGED_SERVICE 2 /* GATT service discovery */ 338 #define GATT_SVC_CHANGED_CHARACTERISTIC 3 /* service change char discovery */ 339 #define GATT_SVC_CHANGED_DESCRIPTOR 4 /* service change CCC discoery */ 340 #define GATT_SVC_CHANGED_CONFIGURE_CCCD 5 /* config CCC */ 341 342 typedef struct { 343 uint16_t conn_id; 344 bool in_use; 345 bool connected; 346 RawAddress bda; 347 tBT_TRANSPORT transport; 348 349 /* GATT service change CCC related variables */ 350 uint8_t ccc_stage; 351 uint8_t ccc_result; 352 uint16_t s_handle; 353 uint16_t e_handle; 354 } tGATT_PROFILE_CLCB; 355 356 typedef struct { 357 tGATT_TCB tcb[GATT_MAX_PHY_CHANNEL]; 358 fixed_queue_t* sign_op_queue; 359 360 uint16_t next_handle; /* next available handle */ 361 uint16_t last_service_handle; /* handle of last service */ 362 tGATT_SVC_CHG gattp_attr; /* GATT profile attribute service change */ 363 tGATT_IF gatt_if; 364 std::list<tGATT_HDL_LIST_ELEM>* hdl_list_info; 365 std::list<tGATT_SRV_LIST_ELEM>* srv_list_info; 366 367 fixed_queue_t* srv_chg_clt_q; /* service change clients queue */ 368 tGATT_REG cl_rcb[GATT_MAX_APPS]; 369 tGATT_CLCB clcb[GATT_CL_MAX_LCB]; /* connection link control block*/ 370 uint16_t def_mtu_size; 371 372 #if (GATT_CONFORMANCE_TESTING == TRUE) 373 bool enable_err_rsp; 374 uint8_t req_op_code; 375 uint8_t err_status; 376 uint16_t handle; 377 #endif 378 379 tGATT_PROFILE_CLCB profile_clcb[GATT_MAX_APPS]; 380 uint16_t 381 handle_of_h_r; /* Handle of the handles reused characteristic value */ 382 383 tGATT_APPL_INFO cb_info; 384 385 tGATT_HDL_CFG hdl_cfg; 386 } tGATT_CB; 387 388 #define GATT_SIZE_OF_SRV_CHG_HNDL_RANGE 4 389 390 /* Global GATT data */ 391 extern tGATT_CB gatt_cb; 392 393 #if (GATT_CONFORMANCE_TESTING == TRUE) 394 extern void gatt_set_err_rsp(bool enable, uint8_t req_op_code, 395 uint8_t err_status); 396 #endif 397 398 /* from gatt_main.cc */ 399 extern bool gatt_disconnect(tGATT_TCB* p_tcb); 400 extern bool gatt_act_connect(tGATT_REG* p_reg, const RawAddress& bd_addr, 401 tBT_TRANSPORT transport, int8_t initiating_phys); 402 extern bool gatt_connect(const RawAddress& rem_bda, tGATT_TCB* p_tcb, 403 tBT_TRANSPORT transport, uint8_t initiating_phys, 404 tGATT_IF gatt_if); 405 extern void gatt_data_process(tGATT_TCB& p_tcb, BT_HDR* p_buf); 406 extern void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb, 407 bool is_add, bool check_acl_link); 408 409 extern void gatt_profile_db_init(void); 410 extern void gatt_set_ch_state(tGATT_TCB* p_tcb, tGATT_CH_STATE ch_state); 411 extern tGATT_CH_STATE gatt_get_ch_state(tGATT_TCB* p_tcb); 412 extern void gatt_init_srv_chg(void); 413 extern void gatt_proc_srv_chg(void); 414 extern void gatt_send_srv_chg_ind(const RawAddress& peer_bda); 415 extern void gatt_chk_srv_chg(tGATTS_SRV_CHG* p_srv_chg_clt); 416 extern void gatt_add_a_bonded_dev_for_srv_chg(const RawAddress& bda); 417 418 /* from gatt_attr.cc */ 419 extern uint16_t gatt_profile_find_conn_id_by_bd_addr(const RawAddress& bda); 420 421 /* Functions provided by att_protocol.cc */ 422 extern tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, 423 uint8_t op_code, tGATT_CL_MSG* p_msg); 424 extern BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, 425 tGATT_SR_MSG* p_msg); 426 extern tGATT_STATUS attp_send_sr_msg(tGATT_TCB& tcb, BT_HDR* p_msg); 427 extern tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB& tcb, BT_HDR* p_toL2CAP); 428 429 /* utility functions */ 430 extern uint8_t* gatt_dbg_op_name(uint8_t op_code); 431 extern uint32_t gatt_add_sdp_record(const bluetooth::Uuid& uuid, 432 uint16_t start_hdl, uint16_t end_hdl); 433 extern bool gatt_parse_uuid_from_cmd(bluetooth::Uuid* p_uuid, uint16_t len, 434 uint8_t** p_data); 435 extern uint8_t gatt_build_uuid_to_stream_len(const bluetooth::Uuid& uuid); 436 extern uint8_t gatt_build_uuid_to_stream(uint8_t** p_dst, 437 const bluetooth::Uuid& uuid); 438 extern void gatt_sr_get_sec_info(const RawAddress& rem_bda, 439 tBT_TRANSPORT transport, uint8_t* p_sec_flag, 440 uint8_t* p_key_size); 441 extern void gatt_start_rsp_timer(tGATT_CLCB* p_clcb); 442 extern void gatt_start_conf_timer(tGATT_TCB* p_tcb); 443 extern void gatt_rsp_timeout(void* data); 444 extern void gatt_indication_confirmation_timeout(void* data); 445 extern void gatt_ind_ack_timeout(void* data); 446 extern void gatt_start_ind_ack_timer(tGATT_TCB& tcb); 447 extern tGATT_STATUS gatt_send_error_rsp(tGATT_TCB& tcb, uint8_t err_code, 448 uint8_t op_code, uint16_t handle, 449 bool deq); 450 451 extern bool gatt_is_srv_chg_ind_pending(tGATT_TCB* p_tcb); 452 extern tGATTS_SRV_CHG* gatt_is_bda_in_the_srv_chg_clt_list( 453 const RawAddress& bda); 454 455 extern bool gatt_find_the_connected_bda(uint8_t start_idx, RawAddress& bda, 456 uint8_t* p_found_idx, 457 tBT_TRANSPORT* p_transport); 458 extern void gatt_set_srv_chg(void); 459 extern void gatt_delete_dev_from_srv_chg_clt_list(const RawAddress& bd_addr); 460 extern void gatt_add_pending_ind(tGATT_TCB* p_tcb, tGATT_VALUE* p_ind); 461 extern void gatt_free_srvc_db_buffer_app_id(const bluetooth::Uuid& app_id); 462 extern bool gatt_cl_send_next_cmd_inq(tGATT_TCB& tcb); 463 464 /* reserved handle list */ 465 extern std::list<tGATT_HDL_LIST_ELEM>::iterator gatt_find_hdl_buffer_by_app_id( 466 const bluetooth::Uuid& app_uuid128, bluetooth::Uuid* p_svc_uuid, 467 uint16_t svc_inst); 468 extern tGATT_HDL_LIST_ELEM* gatt_find_hdl_buffer_by_handle(uint16_t handle); 469 extern tGATTS_SRV_CHG* gatt_add_srv_chg_clt(tGATTS_SRV_CHG* p_srv_chg); 470 471 /* for background connection */ 472 extern bool gatt_auto_connect_dev_remove(tGATT_IF gatt_if, 473 const RawAddress& bd_addr); 474 475 /* server function */ 476 extern std::list<tGATT_SRV_LIST_ELEM>::iterator gatt_sr_find_i_rcb_by_handle( 477 uint16_t handle); 478 extern tGATT_STATUS gatt_sr_process_app_rsp(tGATT_TCB& tcb, tGATT_IF gatt_if, 479 uint32_t trans_id, uint8_t op_code, 480 tGATT_STATUS status, 481 tGATTS_RSP* p_msg); 482 extern void gatt_server_handle_client_req(tGATT_TCB& p_tcb, uint8_t op_code, 483 uint16_t len, uint8_t* p_data); 484 extern void gatt_sr_send_req_callback(uint16_t conn_id, uint32_t trans_id, 485 uint8_t op_code, tGATTS_DATA* p_req_data); 486 extern uint32_t gatt_sr_enqueue_cmd(tGATT_TCB& tcb, uint8_t op_code, 487 uint16_t handle); 488 extern bool gatt_cancel_open(tGATT_IF gatt_if, const RawAddress& bda); 489 extern void gatt_notify_phy_updated(uint8_t status, uint16_t handle, 490 uint8_t tx_phy, uint8_t rx_phy); 491 /* */ 492 493 extern tGATT_REG* gatt_get_regcb(tGATT_IF gatt_if); 494 extern bool gatt_is_clcb_allocated(uint16_t conn_id); 495 extern tGATT_CLCB* gatt_clcb_alloc(uint16_t conn_id); 496 extern void gatt_clcb_dealloc(tGATT_CLCB* p_clcb); 497 498 extern void gatt_sr_copy_prep_cnt_to_cback_cnt(tGATT_TCB& p_tcb); 499 extern bool gatt_sr_is_cback_cnt_zero(tGATT_TCB& p_tcb); 500 extern bool gatt_sr_is_prep_cnt_zero(tGATT_TCB& p_tcb); 501 extern void gatt_sr_reset_cback_cnt(tGATT_TCB& p_tcb); 502 extern void gatt_sr_reset_prep_cnt(tGATT_TCB& tcb); 503 extern void gatt_sr_update_cback_cnt(tGATT_TCB& p_tcb, tGATT_IF gatt_if, 504 bool is_inc, bool is_reset_first); 505 extern void gatt_sr_update_prep_cnt(tGATT_TCB& tcb, tGATT_IF gatt_if, 506 bool is_inc, bool is_reset_first); 507 508 extern uint8_t gatt_num_clcb_by_bd_addr(const RawAddress& bda); 509 extern tGATT_TCB* gatt_find_tcb_by_cid(uint16_t lcid); 510 extern tGATT_TCB* gatt_allocate_tcb_by_bdaddr(const RawAddress& bda, 511 tBT_TRANSPORT transport); 512 extern tGATT_TCB* gatt_get_tcb_by_idx(uint8_t tcb_idx); 513 extern tGATT_TCB* gatt_find_tcb_by_addr(const RawAddress& bda, 514 tBT_TRANSPORT transport); 515 extern bool gatt_send_ble_burst_data(const RawAddress& remote_bda, 516 BT_HDR* p_buf); 517 518 /* GATT client functions */ 519 extern void gatt_dequeue_sr_cmd(tGATT_TCB& tcb); 520 extern uint8_t gatt_send_write_msg(tGATT_TCB& p_tcb, tGATT_CLCB* p_clcb, 521 uint8_t op_code, uint16_t handle, 522 uint16_t len, uint16_t offset, 523 uint8_t* p_data); 524 extern void gatt_cleanup_upon_disc(const RawAddress& bda, uint16_t reason, 525 tBT_TRANSPORT transport); 526 extern void gatt_end_operation(tGATT_CLCB* p_clcb, tGATT_STATUS status, 527 void* p_data); 528 529 extern void gatt_act_discovery(tGATT_CLCB* p_clcb); 530 extern void gatt_act_read(tGATT_CLCB* p_clcb, uint16_t offset); 531 extern void gatt_act_write(tGATT_CLCB* p_clcb, uint8_t sec_act); 532 extern tGATT_CLCB* gatt_cmd_dequeue(tGATT_TCB& tcb, uint8_t* p_opcode); 533 extern void gatt_cmd_enq(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, bool to_send, 534 uint8_t op_code, BT_HDR* p_buf); 535 extern void gatt_client_handle_server_rsp(tGATT_TCB& tcb, uint8_t op_code, 536 uint16_t len, uint8_t* p_data); 537 extern void gatt_send_queue_write_cancel(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, 538 tGATT_EXEC_FLAG flag); 539 540 /* gatt_auth.cc */ 541 extern bool gatt_security_check_start(tGATT_CLCB* p_clcb); 542 extern void gatt_verify_signature(tGATT_TCB& tcb, BT_HDR* p_buf); 543 extern tGATT_STATUS gatt_get_link_encrypt_status(tGATT_TCB& tcb); 544 extern tGATT_SEC_ACTION gatt_get_sec_act(tGATT_TCB* p_tcb); 545 extern void gatt_set_sec_act(tGATT_TCB* p_tcb, tGATT_SEC_ACTION sec_act); 546 547 /* gatt_db.cc */ 548 extern void gatts_init_service_db(tGATT_SVC_DB& db, 549 const bluetooth::Uuid& service, bool is_pri, 550 uint16_t s_hdl, uint16_t num_handle); 551 extern uint16_t gatts_add_included_service(tGATT_SVC_DB& db, uint16_t s_handle, 552 uint16_t e_handle, 553 const bluetooth::Uuid& service); 554 extern uint16_t gatts_add_characteristic(tGATT_SVC_DB& db, tGATT_PERM perm, 555 tGATT_CHAR_PROP property, 556 const bluetooth::Uuid& char_uuid); 557 extern uint16_t gatts_add_char_descr(tGATT_SVC_DB& db, tGATT_PERM perm, 558 const bluetooth::Uuid& dscp_uuid); 559 extern tGATT_STATUS gatts_db_read_attr_value_by_type( 560 tGATT_TCB& tcb, tGATT_SVC_DB* p_db, uint8_t op_code, BT_HDR* p_rsp, 561 uint16_t s_handle, uint16_t e_handle, const bluetooth::Uuid& type, 562 uint16_t* p_len, tGATT_SEC_FLAG sec_flag, uint8_t key_size, 563 uint32_t trans_id, uint16_t* p_cur_handle); 564 extern tGATT_STATUS gatts_read_attr_value_by_handle( 565 tGATT_TCB& tcb, tGATT_SVC_DB* p_db, uint8_t op_code, uint16_t handle, 566 uint16_t offset, uint8_t* p_value, uint16_t* p_len, uint16_t mtu, 567 tGATT_SEC_FLAG sec_flag, uint8_t key_size, uint32_t trans_id); 568 extern tGATT_STATUS gatts_write_attr_perm_check( 569 tGATT_SVC_DB* p_db, uint8_t op_code, uint16_t handle, uint16_t offset, 570 uint8_t* p_data, uint16_t len, tGATT_SEC_FLAG sec_flag, uint8_t key_size); 571 extern tGATT_STATUS gatts_read_attr_perm_check(tGATT_SVC_DB* p_db, bool is_long, 572 uint16_t handle, 573 tGATT_SEC_FLAG sec_flag, 574 uint8_t key_size); 575 extern bluetooth::Uuid* gatts_get_service_uuid(tGATT_SVC_DB* p_db); 576 577 #endif 578