Lines Matching refs:p_tcb

71 static void gatt_send_conn_cback(tGATT_TCB* p_tcb);
190 bool gatt_connect(const RawAddress& rem_bda, tGATT_TCB* p_tcb, in gatt_connect() argument
193 if (gatt_get_ch_state(p_tcb) != GATT_CH_OPEN) in gatt_connect()
194 gatt_set_ch_state(p_tcb, GATT_CH_CONN); in gatt_connect()
197 p_tcb->att_lcid = L2CA_ConnectReq(BT_PSM_ATT, rem_bda); in gatt_connect()
198 return p_tcb->att_lcid != 0; in gatt_connect()
202 if (gatt_get_ch_state(p_tcb) == GATT_CH_OPEN) { in gatt_connect()
203 gatt_update_app_use_link_flag(gatt_if, p_tcb, true, true); in gatt_connect()
207 p_tcb->att_lcid = L2CAP_ATT_CID; in gatt_connect()
223 bool gatt_disconnect(tGATT_TCB* p_tcb) { in gatt_disconnect() argument
226 if (!p_tcb) return false; in gatt_disconnect()
228 tGATT_CH_STATE ch_state = gatt_get_ch_state(p_tcb); in gatt_disconnect()
235 if (p_tcb->att_lcid == L2CAP_ATT_CID) { in gatt_disconnect()
238 ret = L2CA_RemoveFixedChnl(L2CAP_ATT_CID, p_tcb->peer_bda); in gatt_disconnect()
240 L2CA_CancelBleConnectReq(p_tcb->peer_bda); in gatt_disconnect()
241 gatt_cleanup_upon_disc(p_tcb->peer_bda, HCI_ERR_CONN_CAUSE_LOCAL_HOST, p_tcb->transport); in gatt_disconnect()
244 gatt_set_ch_state(p_tcb, GATT_CH_CLOSING); in gatt_disconnect()
247 ret = L2CA_DisconnectReq(p_tcb->att_lcid); in gatt_disconnect()
265 bool gatt_update_app_hold_link_status(tGATT_IF gatt_if, tGATT_TCB* p_tcb, in gatt_update_app_hold_link_status() argument
267 auto& holders = p_tcb->app_hold_link; in gatt_update_app_hold_link_status()
301 void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb, in gatt_update_app_use_link_flag() argument
306 if (!p_tcb) return; in gatt_update_app_use_link_flag()
310 if (!gatt_update_app_hold_link_status(gatt_if, p_tcb, is_add)) return; in gatt_update_app_use_link_flag()
317 (BTM_GetHCIConnHandle(p_tcb->peer_bda, p_tcb->transport) != in gatt_update_app_use_link_flag()
321 if (p_tcb->att_lcid == L2CAP_ATT_CID && is_valid_handle) { in gatt_update_app_use_link_flag()
324 GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_NO_IDLE_TIMEOUT, in gatt_update_app_use_link_flag()
325 p_tcb->transport); in gatt_update_app_use_link_flag()
328 if (p_tcb->app_hold_link.empty()) { in gatt_update_app_use_link_flag()
330 if (p_tcb->att_lcid == L2CAP_ATT_CID && is_valid_handle) { in gatt_update_app_use_link_flag()
335 GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP, in gatt_update_app_use_link_flag()
336 p_tcb->transport); in gatt_update_app_use_link_flag()
339 gatt_disconnect(p_tcb); in gatt_update_app_use_link_flag()
347 tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); in gatt_act_connect() local
348 if (p_tcb != NULL) { in gatt_act_connect()
350 uint8_t st = gatt_get_ch_state(p_tcb); in gatt_act_connect()
351 if (st == GATT_CH_OPEN && p_tcb->app_hold_link.empty() && in gatt_act_connect()
353 if (!gatt_connect(bd_addr, p_tcb, transport, initiating_phys, in gatt_act_connect()
365 p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, transport); in gatt_act_connect()
366 if (!p_tcb) { in gatt_act_connect()
371 if (!gatt_connect(bd_addr, p_tcb, transport, initiating_phys, in gatt_act_connect()
374 fixed_queue_free(p_tcb->pending_ind_q, NULL); in gatt_act_connect()
375 *p_tcb = tGATT_TCB(); in gatt_act_connect()
394 tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); in gatt_le_connect_cback() local
419 if (p_tcb) { in gatt_le_connect_cback()
421 if (gatt_get_ch_state(p_tcb) == GATT_CH_CONN) { in gatt_le_connect_cback()
423 gatt_set_ch_state(p_tcb, GATT_CH_OPEN); in gatt_le_connect_cback()
424 p_tcb->payload_size = GATT_DEF_BLE_MTU_SIZE; in gatt_le_connect_cback()
426 gatt_send_conn_cback(p_tcb); in gatt_le_connect_cback()
433 p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, BT_TRANSPORT_LE); in gatt_le_connect_cback()
434 if (!p_tcb) { in gatt_le_connect_cback()
439 p_tcb->att_lcid = L2CAP_ATT_CID; in gatt_le_connect_cback()
441 gatt_set_ch_state(p_tcb, GATT_CH_OPEN); in gatt_le_connect_cback()
443 p_tcb->payload_size = GATT_DEF_BLE_MTU_SIZE; in gatt_le_connect_cback()
445 gatt_send_conn_cback(p_tcb); in gatt_le_connect_cback()
453 static void gatt_channel_congestion(tGATT_TCB* p_tcb, bool congested) { in gatt_channel_congestion() argument
459 if (p_tcb != NULL && !congested) { in gatt_channel_congestion()
460 gatt_cl_send_next_cmd_inq(*p_tcb); in gatt_channel_congestion()
466 conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); in gatt_channel_congestion()
481 tGATT_TCB* p_tcb = in gatt_notify_phy_updated() local
483 if (!p_tcb) return; in gatt_notify_phy_updated()
488 uint16_t conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); in gatt_notify_phy_updated()
501 tGATT_TCB* p_tcb = in gatt_notify_conn_update() local
503 if (!p_tcb) return; in gatt_notify_conn_update()
508 uint16_t conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); in gatt_notify_conn_update()
518 tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(remote_bda, BT_TRANSPORT_LE); in gatt_le_cong_cback() local
519 if (!p_tcb) return; in gatt_le_cong_cback()
522 gatt_channel_congestion(p_tcb, congested); in gatt_le_cong_cback()
545 tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE); in gatt_le_data_ind() local
546 if (p_tcb) { in gatt_le_data_ind()
547 if (gatt_get_ch_state(p_tcb) < GATT_CH_OPEN) { in gatt_le_data_ind()
549 << +gatt_get_ch_state(p_tcb); in gatt_le_data_ind()
551 gatt_data_process(*p_tcb, p_buf); in gatt_le_data_ind()
575 tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_BR_EDR); in gatt_l2cif_connect_ind_cback() local
576 if (p_tcb == NULL) { in gatt_l2cif_connect_ind_cback()
578 p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, BT_TRANSPORT_BR_EDR); in gatt_l2cif_connect_ind_cback()
579 if (p_tcb == NULL) { in gatt_l2cif_connect_ind_cback()
583 p_tcb->att_lcid = lcid; in gatt_l2cif_connect_ind_cback()
597 gatt_set_ch_state(p_tcb, GATT_CH_CFG); in gatt_l2cif_connect_ind_cback()
610 tGATT_TCB* p_tcb; in gatt_l2cif_connect_cfm_cback() local
614 p_tcb = gatt_find_tcb_by_cid(lcid); in gatt_l2cif_connect_cfm_cback()
615 if (!p_tcb) return; in gatt_l2cif_connect_cfm_cback()
619 gatt_get_ch_state(p_tcb), p_tcb->att_lcid); in gatt_l2cif_connect_cfm_cback()
622 if (gatt_get_ch_state(p_tcb) == GATT_CH_CONN) { in gatt_l2cif_connect_cfm_cback()
626 gatt_set_ch_state(p_tcb, GATT_CH_CFG); in gatt_l2cif_connect_cfm_cback()
636 gatt_cleanup_upon_disc(p_tcb->peer_bda, result, GATT_TRANSPORT_BR_EDR); in gatt_l2cif_connect_cfm_cback()
652 tGATT_TCB* p_tcb = gatt_find_tcb_by_cid(lcid); in gatt_l2cif_config_cfm_cback() local
653 if (!p_tcb) return; in gatt_l2cif_config_cfm_cback()
656 if (gatt_get_ch_state(p_tcb) != GATT_CH_CFG) return; in gatt_l2cif_config_cfm_cback()
666 p_tcb->ch_flags |= GATT_L2C_CFG_CFM_DONE; in gatt_l2cif_config_cfm_cback()
669 if (!(p_tcb->ch_flags & GATT_L2C_CFG_IND_DONE)) return; in gatt_l2cif_config_cfm_cback()
671 gatt_set_ch_state(p_tcb, GATT_CH_OPEN); in gatt_l2cif_config_cfm_cback()
674 gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda); in gatt_l2cif_config_cfm_cback()
678 if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) in gatt_l2cif_config_cfm_cback()
679 gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); in gatt_l2cif_config_cfm_cback()
683 gatt_send_conn_cback(p_tcb); in gatt_l2cif_config_cfm_cback()
690 tGATT_TCB* p_tcb = gatt_find_tcb_by_cid(lcid); in gatt_l2cif_config_ind_cback() local
691 if (!p_tcb) return; in gatt_l2cif_config_ind_cback()
696 p_tcb->payload_size = p_cfg->mtu; in gatt_l2cif_config_ind_cback()
698 p_tcb->payload_size = L2CAP_DEFAULT_MTU; in gatt_l2cif_config_ind_cback()
706 if ((p_tcb->ch_flags & GATT_L2C_CFG_IND_DONE)) return; in gatt_l2cif_config_ind_cback()
709 p_tcb->ch_flags |= GATT_L2C_CFG_IND_DONE; in gatt_l2cif_config_ind_cback()
712 if ((p_tcb->ch_flags & GATT_L2C_CFG_CFM_DONE) == 0) return; in gatt_l2cif_config_ind_cback()
714 gatt_set_ch_state(p_tcb, GATT_CH_OPEN); in gatt_l2cif_config_ind_cback()
715 p_srv_chg_clt = gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda); in gatt_l2cif_config_ind_cback()
719 if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) in gatt_l2cif_config_ind_cback()
720 gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); in gatt_l2cif_config_ind_cback()
724 gatt_send_conn_cback(p_tcb); in gatt_l2cif_config_ind_cback()
731 tGATT_TCB* p_tcb = gatt_find_tcb_by_cid(lcid); in gatt_l2cif_disconnect_ind_cback() local
732 if (!p_tcb) return; in gatt_l2cif_disconnect_ind_cback()
739 if (gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda) == NULL) { in gatt_l2cif_disconnect_ind_cback()
740 if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) in gatt_l2cif_disconnect_ind_cback()
741 gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); in gatt_l2cif_disconnect_ind_cback()
745 uint16_t reason = L2CA_GetDisconnectReason(p_tcb->peer_bda, p_tcb->transport); in gatt_l2cif_disconnect_ind_cback()
749 gatt_cleanup_upon_disc(p_tcb->peer_bda, reason, GATT_TRANSPORT_BR_EDR); in gatt_l2cif_disconnect_ind_cback()
757 tGATT_TCB* p_tcb = gatt_find_tcb_by_cid(lcid); in gatt_l2cif_disconnect_cfm_cback() local
758 if (!p_tcb) return; in gatt_l2cif_disconnect_cfm_cback()
761 if (gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda) == NULL) { in gatt_l2cif_disconnect_cfm_cback()
762 if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) in gatt_l2cif_disconnect_cfm_cback()
763 gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); in gatt_l2cif_disconnect_cfm_cback()
769 uint16_t reason = L2CA_GetDisconnectReason(p_tcb->peer_bda, p_tcb->transport); in gatt_l2cif_disconnect_cfm_cback()
772 gatt_cleanup_upon_disc(p_tcb->peer_bda, reason, GATT_TRANSPORT_BR_EDR); in gatt_l2cif_disconnect_cfm_cback()
778 tGATT_TCB* p_tcb = gatt_find_tcb_by_cid(lcid); in gatt_l2cif_data_ind_cback() local
779 if (p_tcb && gatt_get_ch_state(p_tcb) == GATT_CH_OPEN) { in gatt_l2cif_data_ind_cback()
781 gatt_data_process(*p_tcb, p_buf); in gatt_l2cif_data_ind_cback()
789 tGATT_TCB* p_tcb = gatt_find_tcb_by_cid(lcid); in gatt_l2cif_congest_cback() local
791 if (p_tcb != NULL) { in gatt_l2cif_congest_cback()
792 gatt_channel_congestion(p_tcb, congested); in gatt_l2cif_congest_cback()
797 static void gatt_send_conn_cback(tGATT_TCB* p_tcb) { in gatt_send_conn_cback() argument
803 connection_manager::get_apps_connecting_to(p_tcb->peer_bda); in gatt_send_conn_cback()
810 gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true); in gatt_send_conn_cback()
813 conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); in gatt_send_conn_cback()
814 (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, p_tcb->peer_bda, conn_id, true, in gatt_send_conn_cback()
815 0, p_tcb->transport); in gatt_send_conn_cback()
820 connection_manager::on_connection_complete(p_tcb->peer_bda); in gatt_send_conn_cback()
822 if (!p_tcb->app_hold_link.empty() && p_tcb->att_lcid == L2CAP_ATT_CID) { in gatt_send_conn_cback()
825 GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_NO_IDLE_TIMEOUT, in gatt_send_conn_cback()
826 p_tcb->transport); in gatt_send_conn_cback()
976 tGATT_TCB* p_tcb = &gatt_cb.tcb[found_idx]; in gatt_proc_srv_chg() local
980 if (gatt_is_srv_chg_ind_pending(p_tcb)) { in gatt_proc_srv_chg()
1003 void gatt_set_ch_state(tGATT_TCB* p_tcb, tGATT_CH_STATE ch_state) { in gatt_set_ch_state() argument
1004 if (!p_tcb) return; in gatt_set_ch_state()
1006 VLOG(1) << __func__ << ": old=" << +p_tcb->ch_state in gatt_set_ch_state()
1008 p_tcb->ch_state = ch_state; in gatt_set_ch_state()
1012 tGATT_CH_STATE gatt_get_ch_state(tGATT_TCB* p_tcb) { in gatt_get_ch_state() argument
1013 if (!p_tcb) return GATT_CH_CLOSE; in gatt_get_ch_state()
1015 VLOG(1) << "gatt_get_ch_state: ch_state=" << +p_tcb->ch_state; in gatt_get_ch_state()
1016 return p_tcb->ch_state; in gatt_get_ch_state()