Lines Matching refs:p_ccb
103 static void gap_release_ccb(tGAP_CCB* p_ccb);
104 static void gap_checks_con_flags(tGAP_CCB* p_ccb);
174 tGAP_CCB* p_ccb; in GAP_ConnOpen() local
180 p_ccb = gap_allocate_ccb(); in GAP_ConnOpen()
181 if (p_ccb == NULL) return (GAP_INVALID_HANDLE); in GAP_ConnOpen()
184 p_ccb->transport = transport; in GAP_ConnOpen()
187 p_ccb->service_id = service_id; in GAP_ConnOpen()
192 if (*p_rem_bda != RawAddress::kAny) p_ccb->rem_addr_specified = true; in GAP_ConnOpen()
194 p_ccb->rem_dev_address = *p_rem_bda; in GAP_ConnOpen()
201 if (!p_ccb->rem_addr_specified && !is_server) { in GAP_ConnOpen()
202 gap_release_ccb(p_ccb); in GAP_ConnOpen()
209 if (p_cfg) p_ccb->cfg = *p_cfg; in GAP_ConnOpen()
213 p_ccb->local_coc_cfg.credits = L2CAP_LE_CREDIT_DEFAULT; in GAP_ConnOpen()
214 p_ccb->local_coc_cfg.mtu = p_cfg->mtu; in GAP_ConnOpen()
221 p_ccb->local_coc_cfg.mps = le_mps; in GAP_ConnOpen()
223 VLOG(2) << __func__ << ": credits=" << p_ccb->local_coc_cfg.credits in GAP_ConnOpen()
224 << ", mps=" << p_ccb->local_coc_cfg.mps in GAP_ConnOpen()
225 << ", mtu=" << p_ccb->local_coc_cfg.mtu; in GAP_ConnOpen()
228 p_ccb->p_callback = p_cb; in GAP_ConnOpen()
238 p_ccb->psm = L2CA_REGISTER(psm, &conn.reg_info, false /* enable_snoop */); in GAP_ConnOpen()
239 if (p_ccb->psm == 0) { in GAP_ConnOpen()
242 gap_release_ccb(p_ccb); in GAP_ConnOpen()
248 p_ccb->psm = L2CA_REGISTER_COC( in GAP_ConnOpen()
250 if (p_ccb->psm == 0) { in GAP_ConnOpen()
253 gap_release_ccb(p_ccb); in GAP_ConnOpen()
259 if (!BTM_SetSecurityLevel((uint8_t)!is_server, p_serv_name, p_ccb->service_id, in GAP_ConnOpen()
260 security, p_ccb->psm, 0, 0)) { in GAP_ConnOpen()
262 gap_release_ccb(p_ccb); in GAP_ConnOpen()
267 if (p_ccb->cfg.fcr_present) { in GAP_ConnOpen()
269 p_ccb->ertm_info.preferred_mode = p_ccb->cfg.fcr.mode; in GAP_ConnOpen()
270 p_ccb->ertm_info.user_rx_buf_size = GAP_DATA_BUF_SIZE; in GAP_ConnOpen()
271 p_ccb->ertm_info.user_tx_buf_size = GAP_DATA_BUF_SIZE; in GAP_ConnOpen()
272 p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_INVALID_ERM_BUF_SIZE; in GAP_ConnOpen()
273 p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_INVALID_ERM_BUF_SIZE; in GAP_ConnOpen()
275 p_ccb->ertm_info = *ertm_info; in GAP_ConnOpen()
281 p_ccb->ertm_info.allowed_modes = in GAP_ConnOpen()
286 p_ccb->con_flags |= in GAP_ConnOpen()
288 p_ccb->con_state = GAP_CCB_STATE_LISTENING; in GAP_ConnOpen()
289 return (p_ccb->gap_handle); in GAP_ConnOpen()
292 p_ccb->con_flags = GAP_CCB_FLAGS_IS_ORIG; in GAP_ConnOpen()
296 p_ccb->con_state = GAP_CCB_STATE_CONN_SETUP; in GAP_ConnOpen()
301 p_ccb->con_flags |= GAP_CCB_FLAGS_SEC_DONE; in GAP_ConnOpen()
305 cid = L2CA_CONNECT_REQ(p_ccb->psm, *p_rem_bda, &p_ccb->ertm_info); in GAP_ConnOpen()
307 p_ccb->connection_id = cid; in GAP_ConnOpen()
308 return (p_ccb->gap_handle); in GAP_ConnOpen()
313 cid = L2CA_CONNECT_COC_REQ(p_ccb->psm, *p_rem_bda, &p_ccb->local_coc_cfg); in GAP_ConnOpen()
315 p_ccb->connection_id = cid; in GAP_ConnOpen()
316 return (p_ccb->gap_handle); in GAP_ConnOpen()
320 gap_release_ccb(p_ccb); in GAP_ConnOpen()
338 tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); in GAP_ConnClose() local
342 if (p_ccb) { in GAP_ConnClose()
344 if (p_ccb->con_state != GAP_CCB_STATE_LISTENING) in GAP_ConnClose()
345 L2CA_DISCONNECT_REQ(p_ccb->connection_id); in GAP_ConnClose()
347 gap_release_ccb(p_ccb); in GAP_ConnClose()
374 tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); in GAP_ConnReadData() local
377 if (!p_ccb) return (GAP_ERR_BAD_HANDLE); in GAP_ConnReadData()
381 if (fixed_queue_is_empty(p_ccb->rx_queue)) return (GAP_NO_DATA_AVAIL); in GAP_ConnReadData()
387 static_cast<BT_HDR*>(fixed_queue_try_peek_first(p_ccb->rx_queue)); in GAP_ConnReadData()
403 osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue)); in GAP_ConnReadData()
406 p_ccb->rx_queue_size -= *p_len; in GAP_ConnReadData()
412 p_ccb->rx_queue_size, *p_len); in GAP_ConnReadData()
429 tGAP_CCB* p_ccb; in GAP_GetRxQueueCnt() local
434 p_ccb = &conn.ccb_pool[handle]; in GAP_GetRxQueueCnt()
436 if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) { in GAP_GetRxQueueCnt()
437 *p_rx_queue_count = p_ccb->rx_queue_size; in GAP_GetRxQueueCnt()
465 tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); in GAP_ConnBTRead() local
468 if (!p_ccb) return (GAP_ERR_BAD_HANDLE); in GAP_ConnBTRead()
470 p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->rx_queue); in GAP_ConnBTRead()
475 p_ccb->rx_queue_size -= p_buf->len; in GAP_ConnBTRead()
485 static bool gap_try_write_queued_data(tGAP_CCB* p_ccb) { in gap_try_write_queued_data() argument
486 if (p_ccb->is_congested) return true; in gap_try_write_queued_data()
490 while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL) { in gap_try_write_queued_data()
491 uint8_t status = L2CA_DATA_WRITE(p_ccb->connection_id, p_buf); in gap_try_write_queued_data()
494 p_ccb->is_congested = true; in gap_try_write_queued_data()
520 tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); in GAP_ConnWriteData() local
522 if (!p_ccb) { in GAP_ConnWriteData()
527 if (p_ccb->con_state != GAP_CCB_STATE_CONNECTED) { in GAP_ConnWriteData()
532 if (msg->len > p_ccb->rem_mtu_size) { in GAP_ConnWriteData()
539 fixed_queue_enqueue(p_ccb->tx_queue, msg); in GAP_ConnWriteData()
541 if (!gap_try_write_queued_data(p_ccb)) return GAP_ERR_BAD_STATE; in GAP_ConnWriteData()
561 tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); in GAP_ConnReconfig() local
563 if (!p_ccb) return (GAP_ERR_BAD_HANDLE); in GAP_ConnReconfig()
565 p_ccb->cfg = *p_cfg; in GAP_ConnReconfig()
567 if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) in GAP_ConnReconfig()
568 L2CA_CONFIG_REQ(p_ccb->connection_id, p_cfg); in GAP_ConnReconfig()
596 tGAP_CCB* p_ccb; in GAP_ConnSetIdleTimeout() local
598 p_ccb = gap_find_ccb_by_handle(gap_handle); in GAP_ConnSetIdleTimeout()
599 if (p_ccb == NULL) return (GAP_ERR_BAD_HANDLE); in GAP_ConnSetIdleTimeout()
601 if (L2CA_SetIdleTimeout(p_ccb->connection_id, timeout, false)) in GAP_ConnSetIdleTimeout()
621 tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); in GAP_ConnGetRemoteAddr() local
625 if ((p_ccb) && (p_ccb->con_state > GAP_CCB_STATE_LISTENING)) { in GAP_ConnGetRemoteAddr()
626 DVLOG(1) << __func__ << " BDA: " << p_ccb->rem_dev_address; in GAP_ConnGetRemoteAddr()
627 return &p_ccb->rem_dev_address; in GAP_ConnGetRemoteAddr()
647 tGAP_CCB* p_ccb; in GAP_ConnGetRemMtuSize() local
649 p_ccb = gap_find_ccb_by_handle(gap_handle); in GAP_ConnGetRemMtuSize()
650 if (p_ccb == NULL) return (0); in GAP_ConnGetRemMtuSize()
652 return (p_ccb->rem_mtu_size); in GAP_ConnGetRemMtuSize()
668 tGAP_CCB* p_ccb; in GAP_ConnGetL2CAPCid() local
670 p_ccb = gap_find_ccb_by_handle(gap_handle); in GAP_ConnGetL2CAPCid()
671 if (p_ccb == NULL) return (0); in GAP_ConnGetL2CAPCid()
673 return (p_ccb->connection_id); in GAP_ConnGetL2CAPCid()
687 tGAP_CCB* p_ccb = gap_find_ccb_by_cid(l2cap_cid); in gap_tx_complete_ind() local
688 if (p_ccb == NULL) return; in gap_tx_complete_ind()
690 if ((p_ccb->con_state == GAP_CCB_STATE_CONNECTED) && (sdu_sent == 0xFFFF)) { in gap_tx_complete_ind()
692 p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_TX_EMPTY, nullptr); in gap_tx_complete_ind()
698 tGAP_CCB* p_ccb = gap_find_ccb_by_cid(l2cap_cid); in gap_credits_received_cb() local
699 if (!p_ccb) return; in gap_credits_received_cb()
703 p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_LE_COC_CREDITS, &data); in gap_credits_received_cb()
720 tGAP_CCB* p_ccb; in gap_connect_ind() local
723 for (xx = 0, p_ccb = conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; xx++, p_ccb++) { in gap_connect_ind()
724 if ((p_ccb->con_state == GAP_CCB_STATE_LISTENING) && (p_ccb->psm == psm) && in gap_connect_ind()
725 (!p_ccb->rem_addr_specified || (bd_addr == p_ccb->rem_dev_address))) in gap_connect_ind()
741 if (p_ccb->transport == BT_TRANSPORT_BR_EDR) in gap_connect_ind()
742 p_ccb->con_state = GAP_CCB_STATE_CFG_SETUP; in gap_connect_ind()
745 p_ccb->rem_dev_address = bd_addr; in gap_connect_ind()
746 p_ccb->connection_id = l2cap_cid; in gap_connect_ind()
749 if (p_ccb->transport == BT_TRANSPORT_BR_EDR) in gap_connect_ind()
751 &p_ccb->ertm_info); in gap_connect_ind()
753 if (p_ccb->transport == BT_TRANSPORT_LE) { in gap_connect_ind()
755 L2CAP_CONN_OK, &p_ccb->local_coc_cfg); in gap_connect_ind()
758 L2CA_GET_PEER_COC_CONFIG(l2cap_cid, &p_ccb->peer_coc_cfg); in gap_connect_ind()
759 p_ccb->rem_mtu_size = p_ccb->peer_coc_cfg.mtu; in gap_connect_ind()
762 p_ccb->con_flags |= GAP_CCB_FLAGS_HIS_CFG_DONE; in gap_connect_ind()
763 p_ccb->con_flags |= GAP_CCB_FLAGS_MY_CFG_DONE; in gap_connect_ind()
764 gap_checks_con_flags(p_ccb); in gap_connect_ind()
768 p_ccb->connection_id); in gap_connect_ind()
771 if (p_ccb->transport == BT_TRANSPORT_BR_EDR) in gap_connect_ind()
772 L2CA_CONFIG_REQ(l2cap_cid, &p_ccb->cfg); in gap_connect_ind()
785 static void gap_checks_con_flags(tGAP_CCB* p_ccb) { in gap_checks_con_flags() argument
786 DVLOG(1) << __func__ << " conn_flags:0x" << +p_ccb->con_flags; in gap_checks_con_flags()
788 if ((p_ccb->con_flags & GAP_CCB_FLAGS_CONN_DONE) == GAP_CCB_FLAGS_CONN_DONE) { in gap_checks_con_flags()
789 p_ccb->con_state = GAP_CCB_STATE_CONNECTED; in gap_checks_con_flags()
791 p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_OPENED, nullptr); in gap_checks_con_flags()
807 tGAP_CCB* p_ccb = (tGAP_CCB*)p_ref_data; in gap_sec_check_complete() local
811 p_ccb->con_state, p_ccb->con_flags, res); in gap_sec_check_complete()
812 if (p_ccb->con_state == GAP_CCB_STATE_IDLE) return; in gap_sec_check_complete()
815 p_ccb->con_flags |= GAP_CCB_FLAGS_SEC_DONE; in gap_sec_check_complete()
816 gap_checks_con_flags(p_ccb); in gap_sec_check_complete()
819 L2CA_DISCONNECT_REQ(p_ccb->connection_id); in gap_sec_check_complete()
835 tGAP_CCB* p_ccb; in gap_connect_cfm() local
838 p_ccb = gap_find_ccb_by_cid(l2cap_cid); in gap_connect_cfm()
839 if (p_ccb == NULL) return; in gap_connect_cfm()
842 if ((p_ccb->con_flags & GAP_CCB_FLAGS_SEC_DONE) == 0 && in gap_connect_cfm()
843 p_ccb->transport != BT_TRANSPORT_LE) { in gap_connect_cfm()
844 btm_sec_mx_access_request(p_ccb->rem_dev_address, p_ccb->psm, true, 0, 0, in gap_connect_cfm()
845 &gap_sec_check_complete, p_ccb); in gap_connect_cfm()
851 (p_ccb->con_state == GAP_CCB_STATE_CONN_SETUP)) { in gap_connect_cfm()
852 if (p_ccb->transport == BT_TRANSPORT_BR_EDR) { in gap_connect_cfm()
853 p_ccb->con_state = GAP_CCB_STATE_CFG_SETUP; in gap_connect_cfm()
856 L2CA_CONFIG_REQ(l2cap_cid, &p_ccb->cfg); in gap_connect_cfm()
859 if (p_ccb->transport == BT_TRANSPORT_LE) { in gap_connect_cfm()
861 L2CA_GET_PEER_COC_CONFIG(l2cap_cid, &p_ccb->peer_coc_cfg); in gap_connect_cfm()
862 p_ccb->rem_mtu_size = p_ccb->peer_coc_cfg.mtu; in gap_connect_cfm()
865 p_ccb->con_flags |= GAP_CCB_FLAGS_HIS_CFG_DONE; in gap_connect_cfm()
866 p_ccb->con_flags |= GAP_CCB_FLAGS_MY_CFG_DONE; in gap_connect_cfm()
867 p_ccb->con_flags |= GAP_CCB_FLAGS_SEC_DONE; in gap_connect_cfm()
868 gap_checks_con_flags(p_ccb); in gap_connect_cfm()
872 if (p_ccb->p_callback) in gap_connect_cfm()
873 (*p_ccb->p_callback)(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED, nullptr); in gap_connect_cfm()
875 gap_release_ccb(p_ccb); in gap_connect_cfm()
890 tGAP_CCB* p_ccb; in gap_config_ind() local
894 p_ccb = gap_find_ccb_by_cid(l2cap_cid); in gap_config_ind()
895 if (p_ccb == NULL) return; in gap_config_ind()
899 if (p_ccb->cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) { in gap_config_ind()
901 p_ccb->ertm_info.user_tx_buf_size - sizeof(BT_HDR) - L2CAP_MIN_OFFSET; in gap_config_ind()
906 p_ccb->rem_mtu_size = local_mtu_size; in gap_config_ind()
908 p_ccb->rem_mtu_size = p_cfg->mtu; in gap_config_ind()
918 p_ccb->con_flags |= GAP_CCB_FLAGS_HIS_CFG_DONE; in gap_config_ind()
920 gap_checks_con_flags(p_ccb); in gap_config_ind()
934 tGAP_CCB* p_ccb; in gap_config_cfm() local
937 p_ccb = gap_find_ccb_by_cid(l2cap_cid); in gap_config_cfm()
938 if (p_ccb == NULL) return; in gap_config_cfm()
941 p_ccb->con_flags |= GAP_CCB_FLAGS_MY_CFG_DONE; in gap_config_cfm()
943 if (p_ccb->cfg.fcr_present) in gap_config_cfm()
944 p_ccb->cfg.fcr.mode = p_cfg->fcr.mode; in gap_config_cfm()
946 p_ccb->cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; in gap_config_cfm()
948 gap_checks_con_flags(p_ccb); in gap_config_cfm()
950 p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED, nullptr); in gap_config_cfm()
951 gap_release_ccb(p_ccb); in gap_config_cfm()
966 tGAP_CCB* p_ccb; in gap_disconnect_ind() local
971 p_ccb = gap_find_ccb_by_cid(l2cap_cid); in gap_disconnect_ind()
972 if (p_ccb == NULL) return; in gap_disconnect_ind()
976 p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED, nullptr); in gap_disconnect_ind()
977 gap_release_ccb(p_ccb); in gap_disconnect_ind()
990 tGAP_CCB* p_ccb; in gap_data_ind() local
993 p_ccb = gap_find_ccb_by_cid(l2cap_cid); in gap_data_ind()
994 if (p_ccb == NULL) { in gap_data_ind()
999 if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) { in gap_data_ind()
1000 fixed_queue_enqueue(p_ccb->rx_queue, p_msg); in gap_data_ind()
1002 p_ccb->rx_queue_size += p_msg->len; in gap_data_ind()
1008 p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_DATA_AVAIL, nullptr); in gap_data_ind()
1026 tGAP_CCB* p_ccb = gap_find_ccb_by_cid(lcid); /* Find CCB based on CID */ in gap_congestion_ind() local
1027 if (!p_ccb) return; in gap_congestion_ind()
1029 p_ccb->is_congested = is_congested; in gap_congestion_ind()
1031 p_ccb->p_callback( in gap_congestion_ind()
1032 p_ccb->gap_handle, in gap_congestion_ind()
1036 gap_try_write_queued_data(p_ccb); in gap_congestion_ind()
1051 tGAP_CCB* p_ccb; in gap_find_ccb_by_cid() local
1054 for (xx = 0, p_ccb = conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; xx++, p_ccb++) { in gap_find_ccb_by_cid()
1055 if ((p_ccb->con_state != GAP_CCB_STATE_IDLE) && in gap_find_ccb_by_cid()
1056 (p_ccb->connection_id == cid)) in gap_find_ccb_by_cid()
1057 return (p_ccb); in gap_find_ccb_by_cid()
1075 tGAP_CCB* p_ccb; in gap_find_ccb_by_handle() local
1079 p_ccb = &conn.ccb_pool[handle]; in gap_find_ccb_by_handle()
1081 if (p_ccb->con_state != GAP_CCB_STATE_IDLE) return (p_ccb); in gap_find_ccb_by_handle()
1099 tGAP_CCB* p_ccb; in gap_allocate_ccb() local
1102 for (xx = 0, p_ccb = conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; xx++, p_ccb++) { in gap_allocate_ccb()
1103 if (p_ccb->con_state == GAP_CCB_STATE_IDLE) { in gap_allocate_ccb()
1104 memset(p_ccb, 0, sizeof(tGAP_CCB)); in gap_allocate_ccb()
1105 p_ccb->tx_queue = fixed_queue_new(SIZE_MAX); in gap_allocate_ccb()
1106 p_ccb->rx_queue = fixed_queue_new(SIZE_MAX); in gap_allocate_ccb()
1108 p_ccb->gap_handle = xx; in gap_allocate_ccb()
1109 p_ccb->rem_mtu_size = L2CAP_MTU_SIZE; in gap_allocate_ccb()
1111 return (p_ccb); in gap_allocate_ccb()
1128 static void gap_release_ccb(tGAP_CCB* p_ccb) { in gap_release_ccb() argument
1130 p_ccb->rx_queue_size = 0; in gap_release_ccb()
1132 while (!fixed_queue_is_empty(p_ccb->rx_queue)) in gap_release_ccb()
1133 osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue)); in gap_release_ccb()
1134 fixed_queue_free(p_ccb->rx_queue, NULL); in gap_release_ccb()
1135 p_ccb->rx_queue = NULL; in gap_release_ccb()
1137 while (!fixed_queue_is_empty(p_ccb->tx_queue)) in gap_release_ccb()
1138 osi_free(fixed_queue_try_dequeue(p_ccb->tx_queue)); in gap_release_ccb()
1139 fixed_queue_free(p_ccb->tx_queue, NULL); in gap_release_ccb()
1140 p_ccb->tx_queue = NULL; in gap_release_ccb()
1142 p_ccb->con_state = GAP_CCB_STATE_IDLE; in gap_release_ccb()
1148 (p_ccb_local->psm == p_ccb->psm)) { in gap_release_ccb()
1156 BTM_SecClrService(p_ccb->service_id); in gap_release_ccb()
1157 if (p_ccb->transport == BT_TRANSPORT_BR_EDR) L2CA_DEREGISTER(p_ccb->psm); in gap_release_ccb()
1158 if (p_ccb->transport == BT_TRANSPORT_LE) L2CA_DEREGISTER_COC(p_ccb->psm); in gap_release_ccb()