1 /******************************************************************************
2 *
3 * Copyright (C) 2009-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 /******************************************************************************
20 *
21 * This is the implementation file for the MCAP Data Channel Action
22 * Functions.
23 *
24 ******************************************************************************/
25 #include "bt_target.h"
26 #include "gki.h"
27 #include "mca_api.h"
28 #include "mca_int.h"
29
30 /*******************************************************************************
31 **
32 ** Function mca_dcb_report_cong
33 **
34 ** Description This function is called to report the congestion flag.
35 **
36 ** Returns void.
37 **
38 *******************************************************************************/
mca_dcb_report_cong(tMCA_DCB * p_dcb)39 void mca_dcb_report_cong (tMCA_DCB *p_dcb)
40 {
41 tMCA_CTRL evt_data;
42
43 evt_data.cong_chg.cong = p_dcb->cong;
44 evt_data.cong_chg.mdl = mca_dcb_to_hdl(p_dcb);
45 evt_data.cong_chg.mdl_id = p_dcb->mdl_id;
46 mca_ccb_report_event (p_dcb->p_ccb, MCA_CONG_CHG_EVT, &evt_data);
47 }
48
49 /*******************************************************************************
50 **
51 ** Function mca_dcb_tc_open
52 **
53 ** Description This function is called to report MCA_OPEN_IND_EVT or
54 ** MCA_OPEN_CFM_EVT event.
55 ** It also clears the congestion flag (dcb.cong).
56 **
57 ** Returns void.
58 **
59 *******************************************************************************/
mca_dcb_tc_open(tMCA_DCB * p_dcb,tMCA_DCB_EVT * p_data)60 void mca_dcb_tc_open (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
61 {
62 tMCA_CTRL evt_data;
63 tMCA_CCB *p_ccb = p_dcb->p_ccb;
64 UINT8 event = MCA_OPEN_IND_EVT;
65
66 if (p_data->open.param == MCA_INT)
67 event = MCA_OPEN_CFM_EVT;
68 p_dcb->cong = FALSE;
69 evt_data.open_cfm.mtu = p_data->open.peer_mtu;
70 evt_data.open_cfm.mdl_id = p_dcb->mdl_id;
71 evt_data.open_cfm.mdl = mca_dcb_to_hdl(p_dcb);
72 mca_ccb_event (p_ccb, MCA_CCB_DL_OPEN_EVT, NULL);
73 mca_ccb_report_event (p_ccb, event, &evt_data);
74 }
75
76 /*******************************************************************************
77 **
78 ** Function mca_dcb_cong
79 **
80 ** Description This function sets the congestion state for the DCB.
81 **
82 ** Returns void.
83 **
84 *******************************************************************************/
mca_dcb_cong(tMCA_DCB * p_dcb,tMCA_DCB_EVT * p_data)85 void mca_dcb_cong (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
86 {
87 p_dcb->cong = p_data->llcong;
88 mca_dcb_report_cong(p_dcb);
89 }
90
91 /*******************************************************************************
92 **
93 ** Function mca_dcb_free_data
94 **
95 ** Description This function frees the received message.
96 **
97 ** Returns void.
98 **
99 *******************************************************************************/
mca_dcb_free_data(tMCA_DCB * p_dcb,tMCA_DCB_EVT * p_data)100 void mca_dcb_free_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
101 {
102 GKI_freebuf (p_data);
103 }
104
105 /*******************************************************************************
106 **
107 ** Function mca_dcb_do_disconn
108 **
109 ** Description This function closes a data channel.
110 **
111 ** Returns void.
112 **
113 *******************************************************************************/
mca_dcb_do_disconn(tMCA_DCB * p_dcb,tMCA_DCB_EVT * p_data)114 void mca_dcb_do_disconn (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
115 {
116 tMCA_CLOSE close;
117 if ((p_dcb->lcid == 0) || (L2CA_DisconnectReq(p_dcb->lcid) == FALSE))
118 {
119 close.param = MCA_INT;
120 close.reason = L2CAP_DISC_OK;
121 close.lcid = 0;
122 mca_dcb_event(p_dcb, MCA_DCB_TC_CLOSE_EVT, (tMCA_DCB_EVT *) &close);
123 }
124 }
125
126 /*******************************************************************************
127 **
128 ** Function mca_dcb_snd_data
129 **
130 ** Description This function sends the data from application to the peer device.
131 **
132 ** Returns void.
133 **
134 *******************************************************************************/
mca_dcb_snd_data(tMCA_DCB * p_dcb,tMCA_DCB_EVT * p_data)135 void mca_dcb_snd_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
136 {
137 UINT8 status;
138
139 /* do not need to check cong, because API already checked the status */
140 status = L2CA_DataWrite (p_dcb->lcid, p_data->p_pkt);
141 if (status == L2CAP_DW_CONGESTED)
142 {
143 p_dcb->cong = TRUE;
144 mca_dcb_report_cong(p_dcb);
145 }
146 }
147
148 /*******************************************************************************
149 **
150 ** Function mca_dcb_hdl_data
151 **
152 ** Description This function reports the received data through the data
153 ** callback function.
154 **
155 ** Returns void.
156 **
157 *******************************************************************************/
mca_dcb_hdl_data(tMCA_DCB * p_dcb,tMCA_DCB_EVT * p_data)158 void mca_dcb_hdl_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
159 {
160 (*p_dcb->p_cs->p_data_cback) (mca_dcb_to_hdl(p_dcb), (BT_HDR *)p_data);
161 }
162
163