1 /******************************************************************************
3 * Copyright (C) 2009-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This is the implementation file for the MCAP Data Channel Action
24 ******************************************************************************/
27 #include "bt_common.h"
28 #include "bt_target.h"
32 #include "osi/include/osi.h"
34 /*******************************************************************************
36 * Function mca_dcb_report_cong
38 * Description This function is called to report the congestion flag.
42 ******************************************************************************/
43 void mca_dcb_report_cong(tMCA_DCB* p_dcb) {
46 evt_data.cong_chg.cong = p_dcb->cong;
47 evt_data.cong_chg.mdl = mca_dcb_to_hdl(p_dcb);
48 evt_data.cong_chg.mdl_id = p_dcb->mdl_id;
49 mca_ccb_report_event(p_dcb->p_ccb, MCA_CONG_CHG_EVT, &evt_data);
52 /*******************************************************************************
54 * Function mca_dcb_tc_open
56 * Description This function is called to report MCA_OPEN_IND_EVT or
57 * MCA_OPEN_CFM_EVT event.
58 * It also clears the congestion flag (dcb.cong).
62 ******************************************************************************/
63 void mca_dcb_tc_open(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data) {
65 tMCA_CCB* p_ccb = p_dcb->p_ccb;
66 uint8_t event = MCA_OPEN_IND_EVT;
68 if (p_data->open.param == MCA_INT) event = MCA_OPEN_CFM_EVT;
70 evt_data.open_cfm.mtu = p_data->open.peer_mtu;
71 evt_data.open_cfm.mdl_id = p_dcb->mdl_id;
72 evt_data.open_cfm.mdl = mca_dcb_to_hdl(p_dcb);
73 mca_ccb_event(p_ccb, MCA_CCB_DL_OPEN_EVT, NULL);
74 mca_ccb_report_event(p_ccb, event, &evt_data);
77 /*******************************************************************************
79 * Function mca_dcb_cong
81 * Description This function sets the congestion state for the DCB.
85 ******************************************************************************/
86 void mca_dcb_cong(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data) {
87 p_dcb->cong = p_data->llcong;
88 mca_dcb_report_cong(p_dcb);
91 /*******************************************************************************
93 * Function mca_dcb_free_data
95 * Description This function frees the received message.
99 ******************************************************************************/
100 void mca_dcb_free_data(UNUSED_ATTR tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data) {
104 /*******************************************************************************
106 * Function mca_dcb_do_disconn
108 * Description This function closes a data channel.
112 ******************************************************************************/
113 void mca_dcb_do_disconn(tMCA_DCB* p_dcb, UNUSED_ATTR tMCA_DCB_EVT* p_data) {
114 if ((p_dcb->lcid == 0) || (L2CA_DisconnectReq(p_dcb->lcid) == false)) {
116 close.param = MCA_INT;
117 close.reason = L2CAP_DISC_OK;
119 tMCA_DCB_EVT mca_dcb_evt;
120 mca_dcb_evt.close = close;
121 mca_dcb_event(p_dcb, MCA_DCB_TC_CLOSE_EVT, &mca_dcb_evt);
125 /*******************************************************************************
127 * Function mca_dcb_snd_data
129 * Description Send the data from application to the peer device.
133 ******************************************************************************/
134 void mca_dcb_snd_data(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data) {
137 /* do not need to check cong, because API already checked the status */
138 status = L2CA_DataWrite(p_dcb->lcid, p_data->p_pkt);
139 if (status == L2CAP_DW_CONGESTED) {
141 mca_dcb_report_cong(p_dcb);
145 /*******************************************************************************
147 * Function mca_dcb_hdl_data
149 * Description This function reports the received data through the data
154 ******************************************************************************/
155 void mca_dcb_hdl_data(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data) {
156 (*p_dcb->p_cs->p_data_cback)(mca_dcb_to_hdl(p_dcb), (BT_HDR*)p_data);