1 /******************************************************************************
2 *
3 * Copyright 1998-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 file contains the HeaLth device profile main functions and state
22 * machine.
23 *
24 ******************************************************************************/
25 #include <string.h>
26
27 #include "bt_target.h"
28 #if (HL_INCLUDED == TRUE)
29
30 #include "bt_common.h"
31 #include "bta_hl_api.h"
32 #include "bta_hl_int.h"
33 #include "l2c_api.h"
34 #include "mca_defs.h"
35 #include "osi/include/osi.h"
36 #include "utl.h"
37
38 #if (BTA_HL_DEBUG == TRUE)
39 static const char* bta_hl_cch_state_code(tBTA_HL_CCH_STATE state_code);
40 static const char* bta_hl_dch_state_code(tBTA_HL_DCH_STATE state_code);
41 #endif
42
43 extern uint16_t L2CA_AllocateRandomPsm(void);
44 extern uint16_t L2CA_AllocatePsm(void);
45 /*****************************************************************************
46 * DCH State Table
47 ****************************************************************************/
48 /*****************************************************************************
49 * Constants and types
50 ****************************************************************************/
51 /* state machine action enumeration list for DCH */
52 /* The order of this enumeration must be the same as bta_hl_dch_act_tbl[] */
53 enum {
54 BTA_HL_DCH_MCA_CREATE,
55 BTA_HL_DCH_MCA_CREATE_CFM,
56 BTA_HL_DCH_MCA_CREATE_IND,
57 BTA_HL_DCH_MCA_OPEN_CFM,
58 BTA_HL_DCH_MCA_OPEN_IND,
59 BTA_HL_DCH_MCA_CLOSE,
60 BTA_HL_DCH_MCA_CLOSE_CFM,
61 BTA_HL_DCH_MCA_CLOSE_IND,
62 BTA_HL_DCH_CLOSE_CMPL,
63 BTA_HL_DCH_MCA_RCV_DATA,
64
65 BTA_HL_DCH_SDP_INIT,
66 BTA_HL_DCH_MCA_RECONNECT,
67 BTA_HL_DCH_MCA_RECONNECT_IND,
68 BTA_HL_DCH_MCA_RECONNECT_CFM,
69 BTA_HL_DCH_CLOSE_ECHO_TEST,
70 BTA_HL_DCH_CREATE_RSP,
71 BTA_HL_DCH_MCA_ABORT,
72 BTA_HL_DCH_MCA_ABORT_IND,
73 BTA_HL_DCH_MCA_ABORT_CFM,
74 BTA_HL_DCH_MCA_CONG_CHANGE,
75
76 BTA_HL_DCH_SDP_FAIL,
77 BTA_HL_DCH_SEND_DATA,
78 BTA_HL_DCH_CI_GET_TX_DATA,
79 BTA_HL_DCH_CI_PUT_RX_DATA,
80 BTA_HL_DCH_CI_GET_ECHO_DATA,
81 BTA_HL_DCH_ECHO_TEST,
82 BTA_HL_DCH_CI_PUT_ECHO_DATA,
83 BTA_HL_DCH_IGNORE
84 };
85
86 typedef void (*tBTA_HL_DCH_ACTION)(uint8_t app_idx, uint8_t mcl_idx,
87 uint8_t mdl_idx, tBTA_HL_DATA* p_data);
88
89 static const tBTA_HL_DCH_ACTION bta_hl_dch_action[] = {
90 bta_hl_dch_mca_create, bta_hl_dch_mca_create_cfm,
91 bta_hl_dch_mca_create_ind, bta_hl_dch_mca_open_cfm,
92 bta_hl_dch_mca_open_ind, bta_hl_dch_mca_close,
93 bta_hl_dch_mca_close_cfm, bta_hl_dch_mca_close_ind,
94 bta_hl_dch_close_cmpl, bta_hl_dch_mca_rcv_data,
95
96 bta_hl_dch_sdp_init, bta_hl_dch_mca_reconnect,
97 bta_hl_dch_mca_reconnect_ind, bta_hl_dch_mca_reconnect_cfm,
98 bta_hl_dch_close_echo_test, bta_hl_dch_create_rsp,
99 bta_hl_dch_mca_abort, bta_hl_dch_mca_abort_ind,
100 bta_hl_dch_mca_abort_cfm, bta_hl_dch_mca_cong_change,
101
102 bta_hl_dch_sdp_fail, bta_hl_dch_send_data,
103 bta_hl_dch_ci_get_tx_data, bta_hl_dch_ci_put_rx_data,
104 bta_hl_dch_ci_get_echo_data, bta_hl_dch_echo_test,
105 bta_hl_dch_ci_put_echo_data,
106 };
107
108 /* state table information */
109 #define BTA_HL_DCH_ACTIONS 1 /* number of actions */
110 #define BTA_HL_DCH_ACTION_COL 0 /* position of action */
111 #define BTA_HL_DCH_NEXT_STATE 1 /* position of next state */
112 #define BTA_HL_DCH_NUM_COLS 2 /* number of columns in state tables */
113
114 /* state table for idle state */
115 static const uint8_t bta_hl_dch_st_idle[][BTA_HL_DCH_NUM_COLS] = {
116 /* Event Action 1 Next
117 state */
118 /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_SDP_INIT,
119 BTA_HL_DCH_OPENING_ST},
120 /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_MCA_CREATE,
121 BTA_HL_DCH_OPENING_ST},
122 /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_MCA_CREATE_IND,
123 BTA_HL_DCH_OPENING_ST},
124 /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
125 /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
126
127 /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
128 /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
129 /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
130 /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
131 /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
132
133 /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
134 /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
135 /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_MCA_RECONNECT,
136 BTA_HL_DCH_OPENING_ST},
137 /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
138 /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_MCA_RECONNECT_IND,
139 BTA_HL_DCH_OPENING_ST},
140
141 /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
142 /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
143 /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
144 /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
145 /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
146
147 /* BTA_HL_MCA_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
148 /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
149 /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
150 /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
151 /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
152 /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_ECHO_TEST,
153 BTA_HL_DCH_OPENING_ST},
154 /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}};
155
156 /* state table for opening state */
157 static const uint8_t bta_hl_dch_st_opening[][BTA_HL_DCH_NUM_COLS] = {
158 /* Event Action 1 Next
159 state */
160 /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_SDP_INIT,
161 BTA_HL_DCH_OPENING_ST},
162 /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_MCA_CREATE,
163 BTA_HL_DCH_OPENING_ST},
164 /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST},
165 /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_MCA_CREATE_CFM,
166 BTA_HL_DCH_OPENING_ST},
167 /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_MCA_OPEN_IND,
168 BTA_HL_DCH_OPEN_ST},
169 /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_MCA_OPEN_CFM,
170 BTA_HL_DCH_OPEN_ST},
171 /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST},
172 /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_MCA_CLOSE_IND,
173 BTA_HL_DCH_CLOSING_ST},
174 /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM,
175 BTA_HL_DCH_CLOSING_ST},
176 /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
177
178 /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
179 /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST},
180 /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_MCA_RECONNECT,
181 BTA_HL_DCH_OPENING_ST},
182 /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_SDP_FAIL,
183 BTA_HL_DCH_CLOSING_ST},
184 /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST},
185 /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_MCA_RECONNECT_CFM,
186 BTA_HL_DCH_OPENING_ST},
187 /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE,
188 BTA_HL_DCH_OPENING_ST},
189 /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_CREATE_RSP,
190 BTA_HL_DCH_OPENING_ST},
191 /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_MCA_ABORT, BTA_HL_DCH_OPENING_ST},
192 /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_MCA_ABORT_IND,
193 BTA_HL_DCH_OPENING_ST},
194
195 /* BTA_HL_MCA_ABORT_CFM_EVT */ {BTA_HL_DCH_MCA_ABORT_CFM,
196 BTA_HL_DCH_OPENING_ST},
197 /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST},
198 /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST},
199 /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST},
200 /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA,
201 BTA_HL_DCH_OPENING_ST},
202 /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_ECHO_TEST,
203 BTA_HL_DCH_OPENING_ST},
204 /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE,
205 BTA_HL_DCH_OPENING_ST}};
206
207 /* state table for open state */
208 static const uint8_t bta_hl_dch_st_open[][BTA_HL_DCH_NUM_COLS] = {
209 /* Event Action 1 Next
210 state */
211 /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
212 /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
213 /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
214 /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
215 /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
216 /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
217 /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_MCA_CLOSE,
218 BTA_HL_DCH_CLOSING_ST},
219 /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_MCA_CLOSE_IND,
220 BTA_HL_DCH_CLOSING_ST},
221 /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM,
222 BTA_HL_DCH_CLOSING_ST},
223 /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_SEND_DATA, BTA_HL_DCH_OPEN_ST},
224
225 /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_MCA_RCV_DATA,
226 BTA_HL_DCH_OPEN_ST},
227 /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST},
228 /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
229 /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
230 /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
231 /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
232 /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_CLOSE_ECHO_TEST,
233 BTA_HL_DCH_CLOSING_ST},
234 /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
235 /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
236 /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
237
238 /* BTA_HL_DCH_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
239 /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_MCA_CONG_CHANGE,
240 BTA_HL_DCH_OPEN_ST},
241 /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_CI_GET_TX_DATA,
242 BTA_HL_DCH_OPEN_ST},
243 /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_CI_PUT_RX_DATA,
244 BTA_HL_DCH_OPEN_ST},
245 /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA,
246 BTA_HL_DCH_OPEN_ST},
247 /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST},
248 /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_PUT_ECHO_DATA,
249 BTA_HL_DCH_OPEN_ST}};
250
251 /* state table for closing state */
252 static const uint8_t bta_hl_dch_st_closing[][BTA_HL_DCH_NUM_COLS] = {
253 /* Event Action 1 Next state */
254 /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
255 /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
256 /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
257 /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
258 /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
259 /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
260 /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_MCA_CLOSE,
261 BTA_HL_DCH_CLOSING_ST},
262 /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
263 /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM,
264 BTA_HL_DCH_CLOSING_ST},
265 /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
266
267 /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
268 /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST},
269 /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
270 /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
271 /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE,
272 BTA_HL_DCH_CLOSING_ST},
273 /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE,
274 BTA_HL_DCH_CLOSING_ST},
275 /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE,
276 BTA_HL_DCH_CLOSING_ST},
277 /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE,
278 BTA_HL_DCH_CLOSING_ST},
279 /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
280 /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
281
282 /* BTA_HL_DCH_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
283 /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
284 /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_CI_GET_TX_DATA,
285 BTA_HL_DCH_CLOSING_ST},
286 /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_CI_PUT_RX_DATA,
287 BTA_HL_DCH_CLOSING_ST},
288 /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA,
289 BTA_HL_DCH_CLOSING_ST},
290 /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST},
291 /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_PUT_ECHO_DATA,
292 BTA_HL_DCH_CLOSING_ST}};
293
294 /* type for state table */
295 typedef const uint8_t (*tBTA_HL_DCH_ST_TBL)[BTA_HL_DCH_NUM_COLS];
296
297 /* state table */
298 const tBTA_HL_DCH_ST_TBL bta_hl_dch_st_tbl[] = {
299 bta_hl_dch_st_idle, bta_hl_dch_st_opening, bta_hl_dch_st_open,
300 bta_hl_dch_st_closing};
301
302 /*****************************************************************************
303 * CCH State Table
304 ****************************************************************************/
305 /*****************************************************************************
306 * Constants and types
307 ****************************************************************************/
308 /* state machine action enumeration list for CCH */
309 enum {
310 BTA_HL_CCH_SDP_INIT,
311 BTA_HL_CCH_MCA_OPEN,
312 BTA_HL_CCH_MCA_CLOSE,
313 BTA_HL_CCH_CLOSE_CMPL,
314 BTA_HL_CCH_MCA_CONNECT,
315 BTA_HL_CCH_MCA_DISCONNECT,
316 BTA_HL_CCH_MCA_RSP_TOUT,
317 BTA_HL_CCH_MCA_DISC_OPEN,
318 BTA_HL_CCH_IGNORE
319 };
320
321 /* type for action functions */
322 typedef void (*tBTA_HL_CCH_ACTION)(uint8_t app_idx, uint8_t mcl_idx,
323 tBTA_HL_DATA* p_data);
324
325 /* action function list for MAS */
326 const tBTA_HL_CCH_ACTION bta_hl_cch_action[] = {
327 bta_hl_cch_sdp_init, bta_hl_cch_mca_open, bta_hl_cch_mca_close,
328 bta_hl_cch_close_cmpl, bta_hl_cch_mca_connect, bta_hl_cch_mca_disconnect,
329 bta_hl_cch_mca_rsp_tout, bta_hl_cch_mca_disc_open};
330
331 /* state table information */
332 #define BTA_HL_CCH_ACTIONS 1 /* number of actions */
333 #define BTA_HL_CCH_NEXT_STATE 1 /* position of next state */
334 #define BTA_HL_CCH_NUM_COLS 2 /* number of columns in state tables */
335
336 /* state table for MAS idle state */
337 static const uint8_t bta_hl_cch_st_idle[][BTA_HL_CCH_NUM_COLS] = {
338 /* Event Action 1 Next state */
339 /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_SDP_INIT,
340 BTA_HL_CCH_OPENING_ST},
341 /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST},
342 /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST},
343 /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_CONNECT,
344 BTA_HL_CCH_OPEN_ST},
345 /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST},
346 /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST},
347 /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST},
348 /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE,
349 BTA_HL_CCH_IDLE_ST}};
350
351 /* state table for obex/rfcomm connection state */
352 static const uint8_t bta_hl_cch_st_opening[][BTA_HL_CCH_NUM_COLS] = {
353 /* Event Action 1 Next state */
354 /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE,
355 BTA_HL_CCH_OPENING_ST},
356 /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_MCA_OPEN,
357 BTA_HL_CCH_OPENING_ST},
358 /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_CLOSE_CMPL,
359 BTA_HL_CCH_IDLE_ST},
360 /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_CONNECT,
361 BTA_HL_CCH_OPEN_ST},
362 /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT,
363 BTA_HL_CCH_CLOSING_ST},
364 /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE,
365 BTA_HL_CCH_CLOSING_ST},
366 /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_CLOSE_CMPL,
367 BTA_HL_CCH_IDLE_ST},
368 /* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_MCA_RSP_TOUT,
369 BTA_HL_CCH_CLOSING_ST}};
370
371 /* state table for open state */
372 static const uint8_t bta_hl_cch_st_open[][BTA_HL_CCH_NUM_COLS] = {
373 /* Event Action 1 Next state */
374 /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST},
375 /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST},
376 /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST},
377 /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST},
378 /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT,
379 BTA_HL_CCH_CLOSING_ST},
380 /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE,
381 BTA_HL_CCH_CLOSING_ST},
382 /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST},
383 /* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_MCA_RSP_TOUT,
384 BTA_HL_CCH_CLOSING_ST}};
385
386 /* state table for closing state */
387 static const uint8_t bta_hl_cch_st_closing[][BTA_HL_CCH_NUM_COLS] = {
388 /* Event Action 1 Next state */
389 /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE,
390 BTA_HL_CCH_CLOSING_ST},
391 /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_CLOSE_CMPL,
392 BTA_HL_CCH_IDLE_ST},
393 /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_CLOSE_CMPL,
394 BTA_HL_CCH_IDLE_ST},
395 /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISC_OPEN,
396 BTA_HL_CCH_CLOSING_ST},
397 /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT,
398 BTA_HL_CCH_CLOSING_ST},
399 /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE,
400 BTA_HL_CCH_CLOSING_ST},
401 /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_CLOSE_CMPL,
402 BTA_HL_CCH_IDLE_ST},
403 /* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_IGNORE,
404 BTA_HL_CCH_CLOSING_ST}};
405
406 /* type for state table CCH */
407 typedef const uint8_t (*tBTA_HL_CCH_ST_TBL)[BTA_HL_CCH_NUM_COLS];
408
409 /* MAS state table */
410 const tBTA_HL_CCH_ST_TBL bta_hl_cch_st_tbl[] = {
411 bta_hl_cch_st_idle, bta_hl_cch_st_opening, bta_hl_cch_st_open,
412 bta_hl_cch_st_closing};
413
414 /*****************************************************************************
415 * Global data
416 ****************************************************************************/
417
418 /* HL control block */
419 tBTA_HL_CB bta_hl_cb;
420
421 /*******************************************************************************
422 *
423 * Function bta_hl_cch_sm_execute
424 *
425 * Description State machine event handling function for CCH
426 *
427 * Returns void
428 *
429 ******************************************************************************/
bta_hl_cch_sm_execute(uint8_t app_idx,uint8_t mcl_idx,uint16_t event,tBTA_HL_DATA * p_data)430 void bta_hl_cch_sm_execute(uint8_t app_idx, uint8_t mcl_idx, uint16_t event,
431 tBTA_HL_DATA* p_data) {
432 tBTA_HL_CCH_ST_TBL state_table;
433 uint8_t action;
434 int i;
435 tBTA_HL_MCL_CB* p_cb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
436
437 #if (BTA_HL_DEBUG == TRUE)
438 tBTA_HL_CCH_STATE in_state = p_cb->cch_state;
439 uint16_t cur_evt = event;
440 APPL_TRACE_DEBUG("HDP CCH Event Handler: State 0x%02x [%s], Event [%s]",
441 in_state, bta_hl_cch_state_code(in_state),
442 bta_hl_evt_code(cur_evt));
443 #endif
444
445 /* look up the state table for the current state */
446 state_table = bta_hl_cch_st_tbl[p_cb->cch_state];
447
448 event &= 0x00FF;
449
450 /* set next state */
451 p_cb->cch_state = state_table[event][BTA_HL_CCH_NEXT_STATE];
452
453 for (i = 0; i < BTA_HL_CCH_ACTIONS; i++) {
454 action = state_table[event][i];
455 if (action != BTA_HL_CCH_IGNORE) {
456 (*bta_hl_cch_action[action])(app_idx, mcl_idx, p_data);
457 } else {
458 /* discard HDP data */
459 bta_hl_discard_data(p_data->hdr.event, p_data);
460 break;
461 }
462 }
463 #if (BTA_HL_DEBUG == TRUE)
464 if (in_state != p_cb->cch_state) {
465 APPL_TRACE_DEBUG("HL CCH State Change: [%s] -> [%s] after [%s]",
466 bta_hl_cch_state_code(in_state),
467 bta_hl_cch_state_code(p_cb->cch_state),
468 bta_hl_evt_code(cur_evt));
469 }
470 #endif
471 }
472
473 /*******************************************************************************
474 *
475 * Function bta_hl_dch_sm_execute
476 *
477 * Description State machine event handling function for DCH
478 *
479 * Returns void
480 *
481 ******************************************************************************/
bta_hl_dch_sm_execute(uint8_t app_idx,uint8_t mcl_idx,uint8_t mdl_idx,uint16_t event,tBTA_HL_DATA * p_data)482 void bta_hl_dch_sm_execute(uint8_t app_idx, uint8_t mcl_idx, uint8_t mdl_idx,
483 uint16_t event, tBTA_HL_DATA* p_data) {
484 tBTA_HL_DCH_ST_TBL state_table;
485 uint8_t action;
486 int i;
487 tBTA_HL_MDL_CB* p_cb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
488
489 #if (BTA_HL_DEBUG == TRUE)
490 tBTA_HL_DCH_STATE in_state = p_cb->dch_state;
491 uint16_t cur_evt = event;
492 APPL_TRACE_DEBUG("HDP DCH Event Handler: State 0x%02x [%s], Event [%s]",
493 in_state, bta_hl_dch_state_code(in_state),
494 bta_hl_evt_code(cur_evt));
495 #endif
496
497 /* look up the state table for the current state */
498 state_table = bta_hl_dch_st_tbl[p_cb->dch_state];
499 event -= BTA_HL_DCH_EVT_MIN;
500
501 /* set next state */
502 p_cb->dch_state = state_table[event][BTA_HL_DCH_NEXT_STATE];
503
504 for (i = 0; i < BTA_HL_DCH_ACTIONS; i++) {
505 action = state_table[event][i];
506 if (action != BTA_HL_DCH_IGNORE) {
507 (*bta_hl_dch_action[action])(app_idx, mcl_idx, mdl_idx, p_data);
508 } else {
509 /* discard mas data */
510 bta_hl_discard_data(p_data->hdr.event, p_data);
511 break;
512 }
513 }
514
515 #if (BTA_HL_DEBUG == TRUE)
516 if (in_state != p_cb->dch_state) {
517 APPL_TRACE_DEBUG("HL DCH State Change: [%s] -> [%s] after [%s]",
518 bta_hl_dch_state_code(in_state),
519 bta_hl_dch_state_code(p_cb->dch_state),
520 bta_hl_evt_code(cur_evt));
521 }
522 #endif
523 }
524 /*******************************************************************************
525 *
526 * Function bta_hl_api_enable
527 *
528 * Description Process the API enable request to enable the HL subsystem
529 *
530 * Returns void
531 *
532 ******************************************************************************/
bta_hl_api_enable(tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)533 static void bta_hl_api_enable(tBTA_HL_CB* p_cb, tBTA_HL_DATA* p_data) {
534 tBTA_HL_CTRL evt_data;
535
536 /* If already enabled then reject this request */
537 if (p_cb->enable) {
538 APPL_TRACE_ERROR("HL is already enabled");
539 evt_data.enable_cfm.status = BTA_HL_STATUS_FAIL;
540 if (p_data->api_enable.p_cback)
541 p_data->api_enable.p_cback(BTA_HL_CTRL_ENABLE_CFM_EVT,
542 (tBTA_HL_CTRL*)&evt_data);
543 return;
544 }
545
546 /* Done with checking. now perform the enable oepration*/
547 /* initialize control block */
548 memset(p_cb, 0, sizeof(tBTA_HL_CB));
549 p_cb->enable = true;
550 p_cb->p_ctrl_cback = p_data->api_enable.p_cback;
551 evt_data.enable_cfm.status = BTA_HL_STATUS_OK;
552 if (p_data->api_enable.p_cback)
553 p_data->api_enable.p_cback(BTA_HL_CTRL_ENABLE_CFM_EVT,
554 (tBTA_HL_CTRL*)&evt_data);
555 }
556 /*******************************************************************************
557 *
558 * Function bta_hl_api_disable
559 *
560 * Description Process the API disable request to disable the HL subsystem
561 *
562 * Returns void
563 *
564 ******************************************************************************/
bta_hl_api_disable(tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)565 static void bta_hl_api_disable(tBTA_HL_CB* p_cb, tBTA_HL_DATA* p_data) {
566 tBTA_HL_CTRL evt_data;
567 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
568
569 if (p_cb->enable) {
570 p_cb->disabling = true;
571 bta_hl_check_disable(p_data);
572 } else {
573 status = BTA_HL_STATUS_FAIL;
574 evt_data.disable_cfm.status = status;
575 if (p_cb->p_ctrl_cback)
576 p_cb->p_ctrl_cback(BTA_HL_CTRL_DISABLE_CFM_EVT, (tBTA_HL_CTRL*)&evt_data);
577 }
578
579 #if (BTA_HL_DEBUG == TRUE)
580 if (status != BTA_HL_STATUS_OK) {
581 APPL_TRACE_DEBUG("bta_hl_api_disable status =%s",
582 bta_hl_status_code(status));
583 }
584 #endif
585 }
586
587 /*******************************************************************************
588 *
589 * Function bta_hl_api_update
590 *
591 * Description Process the API registration request to register an HDP
592 * application
593 *
594 * Returns void
595 *
596 ******************************************************************************/
bta_hl_api_update(tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)597 static void bta_hl_api_update(tBTA_HL_CB* p_cb, tBTA_HL_DATA* p_data) {
598 tBTA_HL evt_data;
599 tBTA_HL_APP_CB* p_acb = BTA_HL_GET_APP_CB_PTR(0);
600 tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL;
601
602 APPL_TRACE_DEBUG("bta_hl_api_update");
603 if (p_cb->enable) {
604 status = bta_hl_app_update(p_data->api_update.app_id,
605 p_data->api_update.is_register);
606 if (!p_data->api_update.is_register) {
607 APPL_TRACE_DEBUG("Deregister");
608 memset(&evt_data, 0, sizeof(tBTA_HL));
609 evt_data.dereg_cfm.status = status;
610 evt_data.dereg_cfm.app_id = p_data->api_update.app_id;
611 if (status == BTA_HL_STATUS_OK)
612 evt_data.dereg_cfm.app_handle = p_acb->app_handle;
613 if (p_acb->p_cback) {
614 p_acb->p_cback(BTA_HL_DEREGISTER_CFM_EVT, (tBTA_HL*)&evt_data);
615 }
616 return;
617 }
618 }
619
620 if (status != BTA_HL_STATUS_OK) {
621 if ((status != BTA_HL_STATUS_DUPLICATE_APP_ID) &&
622 (status != BTA_HL_STATUS_NO_RESOURCE)) {
623 if (p_acb) memset(p_acb, 0, sizeof(tBTA_HL_APP_CB));
624 }
625 }
626 #if (BTA_HL_DEBUG == TRUE)
627 if (status != BTA_HL_STATUS_OK) {
628 APPL_TRACE_DEBUG("bta_hl_api_register status =%s",
629 bta_hl_status_code(status));
630 }
631 #endif
632
633 memset(&evt_data, 0, sizeof(tBTA_HL));
634 evt_data.reg_cfm.status = status;
635 evt_data.reg_cfm.app_id = p_data->api_update.app_id;
636 if (status == BTA_HL_STATUS_OK)
637 evt_data.reg_cfm.app_handle = p_acb->app_handle;
638 if (p_data->api_reg.p_cback) {
639 p_data->api_reg.p_cback(BTA_HL_REGISTER_CFM_EVT, (tBTA_HL*)&evt_data);
640 }
641
642 if (status == BTA_HL_STATUS_OK) {
643 evt_data.sdp_info_ind.app_handle = p_acb->app_handle;
644 evt_data.sdp_info_ind.ctrl_psm = p_acb->ctrl_psm;
645 evt_data.sdp_info_ind.data_psm = p_acb->data_psm;
646 evt_data.sdp_info_ind.data_x_spec = BTA_HL_SDP_IEEE_11073_20601;
647 evt_data.sdp_info_ind.mcap_sup_procs = BTA_HL_MCAP_SUP_PROC_MASK;
648
649 if (p_data->api_reg.p_cback) {
650 p_data->api_reg.p_cback(BTA_HL_SDP_INFO_IND_EVT, (tBTA_HL*)&evt_data);
651 }
652 }
653 }
654
655 /*******************************************************************************
656 *
657 * Function bta_hl_api_register
658 *
659 * Description Process the API registration request to register an HDP
660 * application
661 *
662 * Returns void
663 *
664 ******************************************************************************/
bta_hl_api_register(tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)665 static void bta_hl_api_register(tBTA_HL_CB* p_cb, tBTA_HL_DATA* p_data) {
666 tBTA_HL evt_data;
667 uint8_t app_idx;
668 tBTA_HL_APP_CB* p_acb = NULL;
669 tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL;
670
671 if (p_cb->enable) {
672 if (!bta_hl_is_a_duplicate_id(p_data->api_reg.app_id)) {
673 if (bta_hl_find_avail_app_idx(&app_idx)) {
674 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
675 p_acb->in_use = true;
676 p_acb->app_id = p_data->api_reg.app_id;
677 p_acb->p_cback = p_data->api_reg.p_cback;
678 p_acb->sec_mask = p_data->api_reg.sec_mask;
679 p_acb->dev_type = p_data->api_reg.dev_type;
680 strlcpy(p_acb->srv_name, p_data->api_reg.srv_name,
681 sizeof(p_acb->srv_name));
682 strlcpy(p_acb->srv_desp, p_data->api_reg.srv_desp,
683 sizeof(p_acb->srv_desp));
684 strlcpy(p_acb->provider_name, p_data->api_reg.provider_name,
685 sizeof(p_acb->provider_name));
686 bta_hl_cb.p_alloc_psm = L2CA_AllocatePSM;
687 p_acb->ctrl_psm = bta_hl_cb.p_alloc_psm();
688 p_acb->data_psm = bta_hl_cb.p_alloc_psm();
689 p_acb->p_mcap_cback = bta_hl_mcap_ctrl_cback;
690 status = bta_hl_app_registration(app_idx);
691 } else {
692 status = BTA_HL_STATUS_NO_RESOURCE;
693 }
694 } else {
695 status = BTA_HL_STATUS_DUPLICATE_APP_ID;
696 }
697 }
698
699 if (status != BTA_HL_STATUS_OK) {
700 if ((status != BTA_HL_STATUS_DUPLICATE_APP_ID) &&
701 (status != BTA_HL_STATUS_NO_RESOURCE)) {
702 if (p_acb) memset(p_acb, 0, sizeof(tBTA_HL_APP_CB));
703 }
704 }
705 #if (BTA_HL_DEBUG == TRUE)
706 if (status != BTA_HL_STATUS_OK) {
707 APPL_TRACE_DEBUG("bta_hl_api_register status =%s",
708 bta_hl_status_code(status));
709 }
710 #endif
711
712 memset(&evt_data, 0, sizeof(tBTA_HL));
713 evt_data.reg_cfm.status = status;
714 evt_data.reg_cfm.app_id = p_data->api_reg.app_id;
715 if (status == BTA_HL_STATUS_OK)
716 evt_data.reg_cfm.app_handle = p_acb->app_handle;
717 if (p_data->api_reg.p_cback) {
718 p_data->api_reg.p_cback(BTA_HL_REGISTER_CFM_EVT, (tBTA_HL*)&evt_data);
719 }
720
721 if (status == BTA_HL_STATUS_OK) {
722 evt_data.sdp_info_ind.app_handle = p_acb->app_handle;
723 evt_data.sdp_info_ind.ctrl_psm = p_acb->ctrl_psm;
724 evt_data.sdp_info_ind.data_psm = p_acb->data_psm;
725 evt_data.sdp_info_ind.data_x_spec = BTA_HL_SDP_IEEE_11073_20601;
726 evt_data.sdp_info_ind.mcap_sup_procs = BTA_HL_MCAP_SUP_PROC_MASK;
727
728 if (p_data->api_reg.p_cback) {
729 p_data->api_reg.p_cback(BTA_HL_SDP_INFO_IND_EVT, (tBTA_HL*)&evt_data);
730 }
731 }
732 }
733
734 /*******************************************************************************
735 *
736 * Function bta_hl_api_deregister
737 *
738 * Description Process the API de-registration request
739 *
740 * Returns void
741 *
742 ******************************************************************************/
bta_hl_api_deregister(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)743 static void bta_hl_api_deregister(UNUSED_ATTR tBTA_HL_CB* p_cb,
744 tBTA_HL_DATA* p_data) {
745 uint8_t app_idx;
746 tBTA_HL_APP_CB* p_acb;
747
748 if (bta_hl_find_app_idx_using_handle(p_data->api_dereg.app_handle,
749 &app_idx)) {
750 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
751 p_acb->deregistering = true;
752 bta_hl_check_deregistration(app_idx, p_data);
753 } else {
754 APPL_TRACE_ERROR("Invalid app_handle=%d", p_data->api_dereg.app_handle);
755 }
756 }
757
758 /*******************************************************************************
759 *
760 * Function bta_hl_api_cch_open
761 *
762 * Description Process the API CCH open request
763 *
764 * Returns void
765 *
766 ******************************************************************************/
bta_hl_api_cch_open(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)767 static void bta_hl_api_cch_open(UNUSED_ATTR tBTA_HL_CB* p_cb,
768 tBTA_HL_DATA* p_data) {
769 tBTA_HL evt_data;
770 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
771 uint8_t app_idx, mcl_idx;
772 tBTA_HL_APP_CB* p_acb;
773 tBTA_HL_MCL_CB* p_mcb;
774
775 if (bta_hl_find_app_idx_using_handle(p_data->api_cch_open.app_handle,
776 &app_idx)) {
777 if (!bta_hl_find_mcl_idx(app_idx, p_data->api_cch_open.bd_addr, &mcl_idx)) {
778 if (bta_hl_find_avail_mcl_idx(app_idx, &mcl_idx)) {
779 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
780 p_mcb->in_use = true;
781 p_mcb->req_ctrl_psm = p_data->api_cch_open.ctrl_psm;
782 p_mcb->sec_mask = p_data->api_cch_open.sec_mask;
783 p_mcb->bd_addr = p_data->api_cch_open.bd_addr;
784 p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_OPEN;
785 } else {
786 status = BTA_HL_STATUS_NO_RESOURCE;
787 }
788 } else {
789 /* Only one MCL per BD_ADDR */
790 status = BTA_HL_STATUS_DUPLICATE_CCH_OPEN;
791 APPL_TRACE_DEBUG("bta_hl_api_cch_open: CCH already open: status =%d",
792 status)
793 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
794 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
795 if (p_acb->p_cback) {
796 bta_hl_build_cch_open_cfm(&evt_data, p_data->api_cch_open.app_id,
797 p_data->api_cch_open.app_handle,
798 p_mcb->mcl_handle,
799 p_data->api_cch_open.bd_addr, status);
800 p_acb->p_cback(BTA_HL_CCH_OPEN_CFM_EVT, (tBTA_HL*)&evt_data);
801 } else {
802 APPL_TRACE_ERROR("bta_hl_api_cch_open Null Callback");
803 }
804 return;
805 }
806 } else {
807 status = BTA_HL_STATUS_INVALID_APP_HANDLE;
808 }
809 #if (BTA_HL_DEBUG == TRUE)
810 if (status != BTA_HL_STATUS_OK) {
811 APPL_TRACE_DEBUG("bta_hl_api_cch_open status =%s",
812 bta_hl_status_code(status));
813 }
814 #endif
815 switch (status) {
816 case BTA_HL_STATUS_OK:
817 bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_OPEN_EVT, p_data);
818 break;
819 case BTA_HL_STATUS_NO_RESOURCE:
820 case BTA_HL_STATUS_FAIL:
821
822 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
823 if (p_acb->p_cback) {
824 bta_hl_build_cch_open_cfm(&evt_data, p_data->api_cch_open.app_id,
825 p_data->api_cch_open.app_handle, 0,
826 p_data->api_cch_open.bd_addr, status);
827 p_acb->p_cback(BTA_HL_CCH_OPEN_CFM_EVT, (tBTA_HL*)&evt_data);
828 } else {
829 APPL_TRACE_ERROR("bta_hl_api_cch_open Null Callback");
830 }
831 break;
832 default:
833 APPL_TRACE_ERROR("status code=%d", status);
834 break;
835 }
836 }
837
838 /*******************************************************************************
839 *
840 * Function bta_hl_api_cch_close
841 *
842 * Description Process the API CCH close request
843 *
844 * Returns void
845 *
846 ******************************************************************************/
bta_hl_api_cch_close(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)847 static void bta_hl_api_cch_close(UNUSED_ATTR tBTA_HL_CB* p_cb,
848 tBTA_HL_DATA* p_data) {
849 tBTA_HL evt_data;
850 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
851 uint8_t app_idx, mcl_idx;
852 tBTA_HL_APP_CB* p_acb;
853 tBTA_HL_MCL_CB* p_mcb;
854
855 if (bta_hl_find_mcl_idx_using_handle(p_data->api_cch_close.mcl_handle,
856 &app_idx, &mcl_idx)) {
857 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
858 p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_CLOSE;
859 } else {
860 status = BTA_HL_STATUS_INVALID_MCL_HANDLE;
861 }
862 #if (BTA_HL_DEBUG == TRUE)
863 if (status != BTA_HL_STATUS_OK) {
864 APPL_TRACE_DEBUG("bta_hl_api_cch_close status =%s",
865 bta_hl_status_code(status));
866 }
867 #endif
868 switch (status) {
869 case BTA_HL_STATUS_OK:
870 bta_hl_check_cch_close(app_idx, mcl_idx, p_data, true);
871 break;
872
873 case BTA_HL_STATUS_INVALID_MCL_HANDLE:
874 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
875 if (p_acb->p_cback) {
876 bta_hl_build_cch_close_cfm(&evt_data, p_acb->app_handle,
877 p_data->api_cch_close.mcl_handle, status);
878 p_acb->p_cback(BTA_HL_CCH_CLOSE_CFM_EVT, (tBTA_HL*)&evt_data);
879 } else {
880 APPL_TRACE_ERROR("bta_hl_api_cch_close Null Callback");
881 }
882 break;
883 default:
884 APPL_TRACE_ERROR("status code=%d", status);
885 break;
886 }
887 }
888
889 /*******************************************************************************
890 *
891 * Function bta_hl_api_dch_open
892 *
893 * Description Process the API DCH open request
894 *
895 * Returns void
896 *
897 ******************************************************************************/
bta_hl_api_dch_open(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)898 static void bta_hl_api_dch_open(UNUSED_ATTR tBTA_HL_CB* p_cb,
899 tBTA_HL_DATA* p_data) {
900 tBTA_HL evt_data;
901 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
902 uint8_t app_idx, mcl_idx, mdl_idx;
903 tBTA_HL_APP_CB* p_acb;
904 tBTA_HL_MCL_CB* p_mcb = NULL;
905 tBTA_HL_MDL_CB* p_dcb;
906 tBTA_HL_MDEP_CFG* p_mdep_cfg;
907 uint8_t mdep_cfg_idx;
908
909 if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_open.mcl_handle,
910 &app_idx, &mcl_idx)) {
911 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
912 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
913
914 APPL_TRACE_DEBUG(
915 "bta_hl_api_dch_open: app_ix=%d, mcl_idx=%d, cch_state=%d, "
916 "mcl_handle=%d",
917 app_idx, mcl_idx, p_mcb->cch_state, p_data->api_dch_open.mcl_handle);
918 if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) {
919 if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) {
920 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
921
922 if (bta_hl_find_mdep_cfg_idx(
923 app_idx, p_data->api_dch_open.local_mdep_id, &mdep_cfg_idx)) {
924 if (mdep_cfg_idx &&
925 (p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.mdep_role ==
926 BTA_HL_MDEP_ROLE_SINK)) {
927 p_data->api_dch_open.local_cfg = BTA_HL_DCH_CFG_NO_PREF;
928 }
929
930 status = bta_hl_chk_local_cfg(app_idx, mcl_idx, mdep_cfg_idx,
931 p_data->api_dch_open.local_cfg);
932 if (status == BTA_HL_STATUS_OK) {
933 if (p_data->api_dch_open.local_mdep_id !=
934 BTA_HL_ECHO_TEST_MDEP_ID) {
935 if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx,
936 p_data->api_dch_open.ctrl_psm)) {
937 p_mdep_cfg = BTA_HL_GET_MDEP_CFG_PTR(app_idx, mdep_cfg_idx);
938 p_dcb->in_use = true;
939 p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_OPEN;
940 p_dcb->sec_mask = p_data->api_dch_open.sec_mask;
941 p_dcb->local_mdep_id = p_data->api_dch_open.local_mdep_id;
942 p_dcb->peer_mdep_id = p_data->api_dch_open.peer_mdep_id;
943
944 if (p_mdep_cfg->mdep_role == BTA_HL_MDEP_ROLE_SINK) {
945 p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE;
946 } else {
947 p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SINK;
948 }
949
950 p_dcb->local_mdep_cfg_idx = mdep_cfg_idx;
951 p_dcb->local_cfg = p_data->api_dch_open.local_cfg;
952
953 bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx,
954 &p_dcb->max_rx_apdu_size,
955 &p_dcb->max_tx_apdu_size);
956 p_dcb->mdl_id =
957 bta_hl_allocate_mdl_id(app_idx, mcl_idx, mdl_idx);
958 p_dcb->mdl_cfg_idx_included = false;
959 } else {
960 status = BTA_HL_STATUS_INVALID_CTRL_PSM;
961 }
962
963 } else {
964 status = BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID;
965 }
966 }
967 } else {
968 status = BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID;
969 }
970 } else {
971 status = BTA_HL_STATUS_NO_RESOURCE;
972 }
973 } else {
974 status = BTA_HL_STATUS_NO_CCH;
975 }
976 } else {
977 status = BTA_HL_STATUS_INVALID_MCL_HANDLE;
978 }
979
980 #if (BTA_HL_DEBUG == TRUE)
981 if (status != BTA_HL_STATUS_OK) {
982 APPL_TRACE_DEBUG("bta_hl_api_dch_open status =%s",
983 bta_hl_status_code(status));
984 }
985 #endif
986 switch (status) {
987 case BTA_HL_STATUS_OK:
988 if (p_mcb->sdp.num_recs) {
989 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_OPEN_EVT,
990 p_data);
991 } else {
992 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx,
993 BTA_HL_DCH_SDP_INIT_EVT, p_data);
994 }
995 break;
996 case BTA_HL_STATUS_INVALID_DCH_CFG:
997 case BTA_HL_STATUS_NO_FIRST_RELIABLE:
998 case BTA_HL_STATUS_NO_CCH:
999 case BTA_HL_STATUS_NO_RESOURCE:
1000 case BTA_HL_STATUS_FAIL:
1001 case BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID:
1002 case BTA_HL_STATUS_INVALID_CTRL_PSM:
1003 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1004 if (p_acb->p_cback) {
1005 bta_hl_build_dch_open_cfm(
1006 &evt_data, p_acb->app_handle, p_data->api_dch_open.mcl_handle,
1007 BTA_HL_INVALID_MDL_HANDLE, 0, 0, 0, 0, 0, status);
1008 p_acb->p_cback(BTA_HL_DCH_OPEN_CFM_EVT, (tBTA_HL*)&evt_data);
1009 } else {
1010 APPL_TRACE_ERROR("bta_hl_api_dch_open Null Callback");
1011 }
1012
1013 break;
1014 default:
1015 APPL_TRACE_ERROR("Status code=%d", status);
1016 break;
1017 }
1018 }
1019 /*******************************************************************************
1020 *
1021 * Function bta_hl_api_dch_close
1022 *
1023 * Description Process the API DCH close request
1024 *
1025 * Returns void
1026 *
1027 ******************************************************************************/
bta_hl_api_dch_close(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)1028 static void bta_hl_api_dch_close(UNUSED_ATTR tBTA_HL_CB* p_cb,
1029 tBTA_HL_DATA* p_data) {
1030 tBTA_HL evt_data;
1031 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
1032 uint8_t app_idx, mcl_idx, mdl_idx;
1033 tBTA_HL_APP_CB* p_acb;
1034 tBTA_HL_MCL_CB* p_mcb;
1035 tBTA_HL_MDL_CB* p_dcb;
1036
1037 if (bta_hl_find_mdl_idx_using_handle(p_data->api_dch_close.mdl_handle,
1038 &app_idx, &mcl_idx, &mdl_idx)) {
1039 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1040 if (p_dcb->dch_state != BTA_HL_DCH_OPEN_ST) {
1041 status = BTA_HL_STATUS_FAIL;
1042 }
1043 } else {
1044 status = BTA_HL_STATUS_INVALID_MDL_HANDLE;
1045 }
1046
1047 #if (BTA_HL_DEBUG == TRUE)
1048 if (status != BTA_HL_STATUS_OK) {
1049 APPL_TRACE_DEBUG("bta_hl_api_dch_close status =%s",
1050 bta_hl_status_code(status));
1051 }
1052 #endif
1053
1054 switch (status) {
1055 case BTA_HL_STATUS_OK:
1056 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_EVT,
1057 p_data);
1058 break;
1059 case BTA_HL_STATUS_FAIL:
1060 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1061 if (p_acb->p_cback) {
1062 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1063 bta_hl_build_dch_close_cfm(&evt_data, p_acb->app_handle,
1064 p_mcb->mcl_handle,
1065 p_data->api_dch_close.mdl_handle, status);
1066
1067 p_acb->p_cback(BTA_HL_DCH_CLOSE_CFM_EVT, (tBTA_HL*)&evt_data);
1068 } else {
1069 APPL_TRACE_ERROR("bta_hl_api_dch_close Null Callback");
1070 }
1071 break;
1072 default:
1073 APPL_TRACE_ERROR("Status code=%d", status);
1074 break;
1075 }
1076 }
1077
1078 /*******************************************************************************
1079 *
1080 * Function bta_hl_api_dch_reconnect
1081 *
1082 * Description Process the API DCH reconnect request
1083 *
1084 * Returns void
1085 *
1086 ******************************************************************************/
bta_hl_api_dch_reconnect(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)1087 static void bta_hl_api_dch_reconnect(UNUSED_ATTR tBTA_HL_CB* p_cb,
1088 tBTA_HL_DATA* p_data) {
1089 tBTA_HL evt_data;
1090 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
1091 uint8_t app_idx, mcl_idx, mdl_idx;
1092 tBTA_HL_APP_CB* p_acb;
1093 tBTA_HL_MCL_CB* p_mcb = NULL;
1094 tBTA_HL_MDL_CB* p_dcb;
1095 uint8_t mdep_cfg_idx;
1096 uint8_t mdl_cfg_idx;
1097 tBTA_HL_MDEP_CFG* p_mdep_cfg;
1098
1099 if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_reconnect.mcl_handle,
1100 &app_idx, &mcl_idx)) {
1101 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1102 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1103 if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) {
1104 if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) {
1105 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1106 if (bta_hl_validate_reconnect_params(app_idx, mcl_idx,
1107 &(p_data->api_dch_reconnect),
1108 &mdep_cfg_idx, &mdl_cfg_idx)) {
1109 if (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx) &&
1110 (p_acb->mdl_cfg[mdl_cfg_idx].dch_mode !=
1111 BTA_HL_DCH_MODE_RELIABLE)) {
1112 status = BTA_HL_STATUS_NO_FIRST_RELIABLE;
1113 } else {
1114 if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx,
1115 p_data->api_dch_open.ctrl_psm)) {
1116 p_dcb->in_use = true;
1117 p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_RECONNECT;
1118 p_dcb->sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
1119 p_dcb->local_mdep_id = p_acb->mdl_cfg[mdl_cfg_idx].local_mdep_id;
1120 p_dcb->local_mdep_cfg_idx = mdep_cfg_idx;
1121 p_dcb->local_cfg = BTA_HL_DCH_CFG_UNKNOWN;
1122 p_dcb->mdl_id = p_data->api_dch_reconnect.mdl_id;
1123 p_dcb->mdl_cfg_idx_included = true;
1124 p_dcb->mdl_cfg_idx = mdl_cfg_idx;
1125 p_dcb->dch_mode = p_acb->mdl_cfg[mdl_cfg_idx].dch_mode;
1126
1127 p_mdep_cfg = BTA_HL_GET_MDEP_CFG_PTR(app_idx, mdep_cfg_idx);
1128
1129 if (p_mdep_cfg->mdep_role == BTA_HL_MDEP_ROLE_SINK) {
1130 p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE;
1131 APPL_TRACE_DEBUG("peer mdep role = SOURCE ");
1132 } else {
1133 p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SINK;
1134 APPL_TRACE_DEBUG("peer mdep role = SINK ");
1135 }
1136
1137 bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx,
1138 &p_dcb->max_rx_apdu_size,
1139 &p_dcb->max_tx_apdu_size);
1140 } else {
1141 status = BTA_HL_STATUS_INVALID_CTRL_PSM;
1142 }
1143 }
1144 } else {
1145 status = BTA_HL_STATUS_INVALID_RECONNECT_CFG;
1146 }
1147 } else {
1148 status = BTA_HL_STATUS_NO_RESOURCE;
1149 }
1150 } else {
1151 status = BTA_HL_STATUS_NO_CCH;
1152 }
1153 } else {
1154 status = BTA_HL_STATUS_INVALID_MCL_HANDLE;
1155 }
1156
1157 #if (BTA_HL_DEBUG == TRUE)
1158 if (status != BTA_HL_STATUS_OK) {
1159 APPL_TRACE_DEBUG("bta_hl_api_dch_reconnect status=%s",
1160 bta_hl_status_code(status));
1161 }
1162 #endif
1163
1164 switch (status) {
1165 case BTA_HL_STATUS_OK:
1166 if (p_mcb->sdp.num_recs) {
1167 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx,
1168 BTA_HL_DCH_RECONNECT_EVT, p_data);
1169 } else {
1170 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx,
1171 BTA_HL_DCH_SDP_INIT_EVT, p_data);
1172 }
1173 break;
1174 case BTA_HL_STATUS_INVALID_RECONNECT_CFG:
1175 case BTA_HL_STATUS_NO_FIRST_RELIABLE:
1176 case BTA_HL_STATUS_NO_CCH:
1177 case BTA_HL_STATUS_NO_RESOURCE:
1178 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1179 if (p_acb->p_cback) {
1180 bta_hl_build_dch_open_cfm(
1181 &evt_data, p_acb->app_handle, p_data->api_dch_reconnect.mcl_handle,
1182 BTA_HL_INVALID_MDL_HANDLE, 0, p_data->api_dch_reconnect.mdl_id, 0,
1183 0, 0, status);
1184 p_acb->p_cback(BTA_HL_DCH_RECONNECT_CFM_EVT, (tBTA_HL*)&evt_data);
1185 } else {
1186 APPL_TRACE_ERROR("bta_hl_api_dch_reconnect Null Callback");
1187 }
1188 break;
1189 default:
1190 APPL_TRACE_ERROR("Status code=%d", status);
1191 break;
1192 }
1193 }
1194
1195 /*******************************************************************************
1196 *
1197 * Function bta_hl_api_dch_echo_test
1198 *
1199 * Description Process the API Echo test request
1200 *
1201 * Returns void
1202 *
1203 ******************************************************************************/
bta_hl_api_dch_echo_test(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)1204 static void bta_hl_api_dch_echo_test(UNUSED_ATTR tBTA_HL_CB* p_cb,
1205 tBTA_HL_DATA* p_data) {
1206 tBTA_HL evt_data;
1207 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
1208 uint8_t app_idx, mcl_idx, mdl_idx;
1209 tBTA_HL_APP_CB* p_acb;
1210 tBTA_HL_MCL_CB* p_mcb = NULL;
1211 tBTA_HL_MDL_CB* p_dcb;
1212 tBTA_HL_ECHO_CFG* p_echo_cfg;
1213
1214 if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_echo_test.mcl_handle,
1215 &app_idx, &mcl_idx)) {
1216 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1217 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1218 if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) {
1219 if (!p_mcb->echo_test) {
1220 if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) {
1221 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1222
1223 if ((p_data->api_dch_echo_test.local_cfg ==
1224 BTA_HL_DCH_CFG_RELIABLE) ||
1225 (p_data->api_dch_echo_test.local_cfg ==
1226 BTA_HL_DCH_CFG_STREAMING)) {
1227 bool fcs_use =
1228 (bool)(p_dcb->chnl_cfg.fcs & BTA_HL_MCA_FCS_USE_MASK);
1229 p_dcb->p_echo_tx_pkt =
1230 bta_hl_get_buf(p_data->api_dch_echo_test.pkt_size, fcs_use);
1231 if (p_dcb->p_echo_tx_pkt != NULL) {
1232 if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx,
1233 p_data->api_dch_open.ctrl_psm)) {
1234 p_dcb->in_use = true;
1235 p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_OPEN;
1236 p_dcb->sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
1237 p_dcb->local_mdep_cfg_idx = BTA_HL_ECHO_TEST_MDEP_CFG_IDX;
1238 p_dcb->local_cfg = p_data->api_dch_echo_test.local_cfg;
1239 p_dcb->local_mdep_id = BTA_HL_ECHO_TEST_MDEP_ID;
1240 p_dcb->peer_mdep_id = BTA_HL_ECHO_TEST_MDEP_ID;
1241 p_dcb->mdl_id =
1242 bta_hl_allocate_mdl_id(app_idx, mcl_idx, mdl_idx);
1243 p_dcb->mdl_cfg_idx_included = false;
1244 p_echo_cfg = BTA_HL_GET_ECHO_CFG_PTR(app_idx);
1245 p_dcb->max_rx_apdu_size = p_echo_cfg->max_rx_apdu_size;
1246 p_dcb->max_tx_apdu_size = p_echo_cfg->max_tx_apdu_size;
1247 p_mcb->echo_test = true;
1248 p_mcb->echo_mdl_idx = mdl_idx;
1249 } else {
1250 status = BTA_HL_STATUS_INVALID_CTRL_PSM;
1251 }
1252 } else {
1253 status = BTA_HL_STATUS_NO_RESOURCE;
1254 }
1255 } else {
1256 status = BTA_HL_STATUS_INVALID_DCH_CFG;
1257 }
1258 } else {
1259 status = BTA_HL_STATUS_NO_RESOURCE;
1260 }
1261 } else {
1262 status = BTA_HL_STATUS_ECHO_TEST_BUSY;
1263 }
1264 } else {
1265 status = BTA_HL_STATUS_NO_CCH;
1266 }
1267 } else {
1268 status = BTA_HL_STATUS_NO_MCL;
1269 }
1270
1271 #if (BTA_HL_DEBUG == TRUE)
1272 if (status != BTA_HL_STATUS_OK) {
1273 APPL_TRACE_DEBUG("bta_hl_api_dch_echo_test status=%s",
1274 bta_hl_status_code(status));
1275 }
1276 #endif
1277
1278 switch (status) {
1279 case BTA_HL_STATUS_OK:
1280 if (p_mcb->sdp.num_recs) {
1281 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx,
1282 BTA_HL_DCH_ECHO_TEST_EVT, p_data);
1283 } else {
1284 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx,
1285 BTA_HL_DCH_SDP_INIT_EVT, p_data);
1286 }
1287 break;
1288 case BTA_HL_STATUS_ECHO_TEST_BUSY:
1289 case BTA_HL_STATUS_NO_RESOURCE:
1290 case BTA_HL_STATUS_INVALID_DCH_CFG:
1291 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1292 if (p_acb->p_cback) {
1293 bta_hl_build_echo_test_cfm(&evt_data, p_acb->app_handle,
1294 p_mcb->mcl_handle, status);
1295 p_acb->p_cback(BTA_HL_DCH_ECHO_TEST_CFM_EVT, (tBTA_HL*)&evt_data);
1296 } else {
1297 APPL_TRACE_ERROR("bta_hl_api_dch_echo_test Null Callback");
1298 }
1299 break;
1300
1301 default:
1302 APPL_TRACE_ERROR("Status code=%s", status);
1303 break;
1304 }
1305 }
1306
1307 /*******************************************************************************
1308 *
1309 * Function bta_hl_api_sdp_query
1310 *
1311 * Description Process the API SDP query request
1312 *
1313 * Returns void
1314 *
1315 ******************************************************************************/
bta_hl_api_sdp_query(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)1316 static void bta_hl_api_sdp_query(UNUSED_ATTR tBTA_HL_CB* p_cb,
1317 tBTA_HL_DATA* p_data) {
1318 tBTA_HL evt_data;
1319 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
1320 uint8_t app_idx, mcl_idx;
1321 tBTA_HL_APP_CB* p_acb;
1322 tBTA_HL_MCL_CB* p_mcb;
1323
1324 if (bta_hl_find_app_idx_using_handle(p_data->api_sdp_query.app_handle,
1325 &app_idx)) {
1326 if (!bta_hl_find_mcl_idx(app_idx, p_data->api_sdp_query.bd_addr,
1327 &mcl_idx)) {
1328 if (bta_hl_find_avail_mcl_idx(app_idx, &mcl_idx)) {
1329 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1330 p_mcb->in_use = true;
1331 p_mcb->bd_addr = p_data->api_sdp_query.bd_addr;
1332 APPL_TRACE_DEBUG(
1333 "bta_hl_api_sdp_query p_mcb->app_id %d app_idx %d mcl_idx %d",
1334 p_mcb->app_id, app_idx, mcl_idx);
1335 p_mcb->app_id = p_data->api_sdp_query.app_id;
1336 p_mcb->sdp_oper = BTA_HL_SDP_OP_SDP_QUERY_NEW;
1337 } else {
1338 status = BTA_HL_STATUS_NO_RESOURCE;
1339 }
1340 } else {
1341 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1342 p_mcb->app_id = p_data->api_sdp_query.app_id;
1343 if (p_mcb->sdp_oper != BTA_HL_SDP_OP_NONE) {
1344 status = BTA_HL_STATUS_SDP_NO_RESOURCE;
1345 } else {
1346 p_mcb->sdp_oper = BTA_HL_SDP_OP_SDP_QUERY_CURRENT;
1347 }
1348 }
1349 } else {
1350 status = BTA_HL_STATUS_INVALID_APP_HANDLE;
1351 }
1352
1353 if (status == BTA_HL_STATUS_OK) {
1354 status = bta_hl_init_sdp(p_mcb->sdp_oper, app_idx, mcl_idx, 0xFF);
1355 if ((status != BTA_HL_STATUS_OK) &&
1356 (p_mcb->sdp_oper == BTA_HL_SDP_OP_SDP_QUERY_NEW)) {
1357 memset(p_mcb, 0, sizeof(tBTA_HL_MCL_CB));
1358 }
1359 }
1360 #if (BTA_HL_DEBUG == TRUE)
1361 if (status != BTA_HL_STATUS_OK) {
1362 APPL_TRACE_DEBUG("bta_hl_api_sdp_query status=%s",
1363 bta_hl_status_code(status));
1364 }
1365 #endif
1366 switch (status) {
1367 case BTA_HL_STATUS_NO_RESOURCE:
1368 case BTA_HL_STATUS_FAIL:
1369 case BTA_HL_STATUS_SDP_NO_RESOURCE:
1370 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1371 if (p_acb->p_cback) {
1372 bta_hl_build_sdp_query_cfm(&evt_data, p_data->api_sdp_query.app_id,
1373 p_data->api_sdp_query.app_handle,
1374 p_data->api_sdp_query.bd_addr, NULL, status);
1375 p_acb->p_cback(BTA_HL_SDP_QUERY_CFM_EVT, (tBTA_HL*)&evt_data);
1376 } else {
1377 APPL_TRACE_ERROR("bta_hl_api_sdp_query Null Callback");
1378 }
1379 break;
1380 case BTA_HL_STATUS_OK:
1381 break;
1382 default:
1383 APPL_TRACE_ERROR("Status code=%d", status);
1384 break;
1385 }
1386 }
1387
1388 /*******************************************************************************
1389 *
1390 * Function bta_hl_sdp_query_results
1391 *
1392 * Description Process the SDP query results
1393 *
1394 * Returns void
1395 *
1396 ******************************************************************************/
bta_hl_sdp_query_results(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)1397 static void bta_hl_sdp_query_results(UNUSED_ATTR tBTA_HL_CB* p_cb,
1398 tBTA_HL_DATA* p_data) {
1399 tBTA_HL evt_data;
1400 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
1401 uint8_t app_idx = p_data->cch_sdp.app_idx;
1402 uint8_t mcl_idx = p_data->cch_sdp.mcl_idx;
1403 tBTA_HL_APP_CB* p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1404 tBTA_HL_MCL_CB* p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1405 tBTA_HL_SDP* p_sdp = NULL;
1406 uint16_t event;
1407
1408 event = p_data->hdr.event;
1409
1410 if (event == BTA_HL_SDP_QUERY_OK_EVT) {
1411 // this is freed in btif_hl_proc_sdp_query_cfm
1412 p_sdp = (tBTA_HL_SDP*)osi_malloc(sizeof(tBTA_HL_SDP));
1413 memcpy(p_sdp, &p_mcb->sdp, sizeof(tBTA_HL_SDP));
1414 } else {
1415 status = BTA_HL_STATUS_SDP_FAIL;
1416 }
1417
1418 #if (BTA_HL_DEBUG == TRUE)
1419 if (status != BTA_HL_STATUS_OK) {
1420 APPL_TRACE_DEBUG("bta_hl_sdp_query_results status=%s",
1421 bta_hl_status_code(status));
1422 }
1423 #endif
1424
1425 APPL_TRACE_DEBUG(
1426 "bta_hl_sdp_query_results p_mcb->app_id %d app_idx %d mcl_idx %d",
1427 p_mcb->app_id, app_idx, mcl_idx);
1428 bta_hl_build_sdp_query_cfm(&evt_data, p_mcb->app_id, p_acb->app_handle,
1429 p_mcb->bd_addr, p_sdp, status);
1430 p_acb->p_cback(BTA_HL_SDP_QUERY_CFM_EVT, (tBTA_HL*)&evt_data);
1431
1432 if (p_data->cch_sdp.release_mcl_cb) {
1433 memset(p_mcb, 0, sizeof(tBTA_HL_MCL_CB));
1434 } else {
1435 if (p_mcb->close_pending)
1436 bta_hl_check_cch_close(app_idx, mcl_idx, p_data, true);
1437
1438 if (!p_mcb->ctrl_psm) {
1439 /* Control channel acceptor: do not store the SDP records */
1440 memset(&p_mcb->sdp, 0, sizeof(tBTA_HL_SDP));
1441 }
1442 }
1443 }
1444
1445 /*******************************************************************************
1446 *
1447 * Function bta_hl_api_delete_mdl
1448 *
1449 * Description Process the API DELETE MDL request
1450 *
1451 * Returns void
1452 *
1453 ******************************************************************************/
bta_hl_api_delete_mdl(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)1454 static void bta_hl_api_delete_mdl(UNUSED_ATTR tBTA_HL_CB* p_cb,
1455 tBTA_HL_DATA* p_data) {
1456 tBTA_HL evt_data;
1457 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
1458 uint8_t app_idx, mcl_idx;
1459 tBTA_HL_APP_CB* p_acb;
1460 tBTA_HL_MCL_CB* p_mcb;
1461
1462 if (bta_hl_find_mcl_idx_using_handle(p_data->api_delete_mdl.mcl_handle,
1463 &app_idx, &mcl_idx)) {
1464 if (bta_hl_is_mdl_value_valid(p_data->api_delete_mdl.mdl_id)) {
1465 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1466 if (bta_hl_is_mdl_exsit_in_mcl(app_idx, p_mcb->bd_addr,
1467 p_data->api_delete_mdl.mdl_id)) {
1468 p_mcb->delete_mdl.mcl_handle = p_data->api_delete_mdl.mcl_handle;
1469 p_mcb->delete_mdl.mdl_id = p_data->api_delete_mdl.mdl_id;
1470 p_mcb->delete_mdl.delete_req_pending = true;
1471
1472 if (MCA_Delete((tMCA_CL)p_mcb->mcl_handle,
1473 p_data->api_delete_mdl.mdl_id) != MCA_SUCCESS) {
1474 status = BTA_HL_STATUS_FAIL;
1475 memset(&p_mcb->delete_mdl, 0, sizeof(tBTA_HL_DELETE_MDL));
1476 }
1477 } else {
1478 status = BTA_HL_STATUS_NO_MDL_ID_FOUND;
1479 }
1480 } else {
1481 status = BTA_HL_STATUS_INVALID_MDL_ID;
1482 }
1483 } else {
1484 status = BTA_HL_STATUS_INVALID_MCL_HANDLE;
1485 }
1486
1487 #if (BTA_HL_DEBUG == TRUE)
1488 if (status != BTA_HL_STATUS_OK) {
1489 APPL_TRACE_DEBUG("bta_hl_api_delete_mdl status=%s",
1490 bta_hl_status_code(status));
1491 }
1492 #endif
1493 switch (status) {
1494 case BTA_HL_STATUS_OK:
1495 break;
1496 case BTA_HL_STATUS_FAIL:
1497 case BTA_HL_STATUS_NO_MDL_ID_FOUND:
1498 case BTA_HL_STATUS_INVALID_MDL_ID:
1499 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1500 if (p_acb->p_cback) {
1501 bta_hl_build_delete_mdl_cfm(&evt_data, p_acb->app_handle,
1502 p_data->api_delete_mdl.mcl_handle,
1503 p_data->api_delete_mdl.mdl_id, status);
1504 p_acb->p_cback(BTA_HL_DELETE_MDL_CFM_EVT, (tBTA_HL*)&evt_data);
1505 } else {
1506 APPL_TRACE_ERROR("bta_hl_api_delete_mdl Null Callback");
1507 }
1508 break;
1509 default:
1510 APPL_TRACE_ERROR("status code =%d", status);
1511 break;
1512 }
1513 }
1514
1515 /*******************************************************************************
1516 *
1517 * Function bta_hl_mca_delete_mdl_cfm
1518 *
1519 * Description Process the DELETE MDL confirmation event
1520 *
1521 * Returns void
1522 *
1523 ******************************************************************************/
bta_hl_mca_delete_mdl_cfm(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)1524 static void bta_hl_mca_delete_mdl_cfm(UNUSED_ATTR tBTA_HL_CB* p_cb,
1525 tBTA_HL_DATA* p_data) {
1526 tBTA_HL evt_data;
1527 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
1528 uint8_t app_idx, mcl_idx;
1529 tMCA_RSP_EVT* p_delete_cfm = &p_data->mca_evt.mca_data.delete_cfm;
1530 tBTA_HL_MCL_CB* p_mcb;
1531 bool send_cfm_evt = true;
1532 tBTA_HL_APP_CB* p_acb;
1533
1534 if (bta_hl_find_mcl_idx_using_handle(p_data->mca_evt.mcl_handle, &app_idx,
1535 &mcl_idx)) {
1536 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1537 if (p_mcb->delete_mdl.delete_req_pending) {
1538 if (p_delete_cfm->rsp_code == MCA_RSP_SUCCESS) {
1539 if (!bta_hl_delete_mdl_cfg(app_idx, p_mcb->bd_addr,
1540 p_delete_cfm->mdl_id)) {
1541 status = BTA_HL_STATUS_FAIL;
1542 }
1543 } else {
1544 status = BTA_HL_STATUS_FAIL;
1545 }
1546
1547 memset(&p_mcb->delete_mdl, 0, sizeof(tBTA_HL_DELETE_MDL));
1548 } else {
1549 send_cfm_evt = false;
1550 }
1551 } else {
1552 send_cfm_evt = false;
1553 }
1554
1555 #if (BTA_HL_DEBUG == TRUE)
1556 if (status != BTA_HL_STATUS_OK) {
1557 APPL_TRACE_DEBUG("bta_hl_api_delete_mdl status=%s",
1558 bta_hl_status_code(status));
1559 }
1560 #endif
1561
1562 if (send_cfm_evt) {
1563 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1564 if (p_acb->p_cback) {
1565 bta_hl_build_delete_mdl_cfm(&evt_data, p_acb->app_handle,
1566 p_mcb->mcl_handle, p_delete_cfm->mdl_id,
1567 status);
1568
1569 p_acb->p_cback(BTA_HL_DELETE_MDL_CFM_EVT, (tBTA_HL*)&evt_data);
1570 } else {
1571 APPL_TRACE_ERROR("bta_hl_mca_delete_mdl_cfm Null Callback");
1572 }
1573 }
1574 }
1575
1576 /*******************************************************************************
1577 *
1578 * Function bta_hl_mca_delete_mdl_ind
1579 *
1580 * Description Process the DELETE MDL indication event
1581 *
1582 * Returns void
1583 *
1584 ******************************************************************************/
bta_hl_mca_delete_mdl_ind(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)1585 static void bta_hl_mca_delete_mdl_ind(UNUSED_ATTR tBTA_HL_CB* p_cb,
1586 tBTA_HL_DATA* p_data) {
1587 tBTA_HL evt_data;
1588 uint8_t app_idx, mcl_idx, mdl_idx;
1589 tMCA_EVT_HDR* p_delete_ind = &p_data->mca_evt.mca_data.delete_ind;
1590 tBTA_HL_MCL_CB* p_mcb;
1591 tBTA_HL_MDL_CB* p_dcb;
1592 bool send_ind_evt = false;
1593 tBTA_HL_APP_CB* p_acb;
1594
1595 if (bta_hl_find_mcl_idx_using_handle(p_data->mca_evt.mcl_handle, &app_idx,
1596 &mcl_idx)) {
1597 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1598
1599 if (bta_hl_find_mdl_idx(app_idx, mcl_idx, p_delete_ind->mdl_id, &mdl_idx)) {
1600 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1601 p_dcb->dch_oper = BTA_HL_DCH_OP_REMOTE_DELETE;
1602 }
1603 if (bta_hl_delete_mdl_cfg(app_idx, p_mcb->bd_addr, p_delete_ind->mdl_id)) {
1604 send_ind_evt = true;
1605 }
1606 }
1607
1608 #if (BTA_HL_DEBUG == TRUE)
1609 if (!send_ind_evt) {
1610 APPL_TRACE_DEBUG("bta_hl_mca_delete_mdl_ind is_send_ind_evt =%d",
1611 send_ind_evt);
1612 }
1613 #endif
1614
1615 if (send_ind_evt) {
1616 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1617 if (p_acb->p_cback) {
1618 evt_data.delete_mdl_ind.mcl_handle = p_mcb->mcl_handle;
1619 evt_data.delete_mdl_ind.app_handle = p_acb->app_handle;
1620 evt_data.delete_mdl_ind.mdl_id = p_delete_ind->mdl_id;
1621 p_acb->p_cback(BTA_HL_DELETE_MDL_IND_EVT, (tBTA_HL*)&evt_data);
1622 } else {
1623 APPL_TRACE_ERROR("bta_hl_mca_delete_mdl_ind Null Callback");
1624 }
1625 }
1626 }
1627
1628 /*******************************************************************************
1629 *
1630 * Function bta_hl_api_dch_abort
1631 *
1632 * Description Process the API DCH abort request
1633 *
1634 * Returns void
1635 *
1636 ******************************************************************************/
bta_hl_api_dch_abort(UNUSED_ATTR tBTA_HL_CB * p_cb,tBTA_HL_DATA * p_data)1637 static void bta_hl_api_dch_abort(UNUSED_ATTR tBTA_HL_CB* p_cb,
1638 tBTA_HL_DATA* p_data) {
1639 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
1640 uint8_t app_idx, mcl_idx, mdl_idx;
1641 tBTA_HL_APP_CB* p_acb;
1642 tBTA_HL_MCL_CB* p_mcb;
1643 tBTA_HL_MDL_CB* p_dcb;
1644 tBTA_HL evt_data;
1645
1646 if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_abort.mcl_handle,
1647 &app_idx, &mcl_idx)) {
1648 if (!bta_hl_find_dch_setup_mdl_idx(app_idx, mcl_idx, &mdl_idx)) {
1649 status = BTA_HL_STATUS_NO_MDL_ID_FOUND;
1650 } else {
1651 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1652 if (p_dcb->abort_oper) {
1653 /* abort already in progress*/
1654 status = BTA_HL_STATUS_FAIL;
1655 } else {
1656 p_dcb->abort_oper = BTA_HL_ABORT_LOCAL_MASK;
1657 }
1658 }
1659 } else {
1660 status = BTA_HL_STATUS_INVALID_MCL_HANDLE;
1661 }
1662
1663 #if (BTA_HL_DEBUG == TRUE)
1664 if (status != BTA_HL_STATUS_OK) {
1665 APPL_TRACE_DEBUG("bta_hl_api_dch_abort status=%s",
1666 bta_hl_status_code(status));
1667 }
1668 #endif
1669 switch (status) {
1670 case BTA_HL_STATUS_OK:
1671
1672 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ABORT_EVT,
1673 p_data);
1674 break;
1675 case BTA_HL_STATUS_NO_MDL_ID_FOUND:
1676 case BTA_HL_STATUS_FAIL:
1677
1678 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1679 if (p_acb->p_cback) {
1680 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1681 bta_hl_build_abort_cfm(&evt_data,
1682
1683 p_acb->app_handle, p_mcb->mcl_handle,
1684 BTA_HL_STATUS_FAIL);
1685 p_acb->p_cback(BTA_HL_DCH_ABORT_CFM_EVT, (tBTA_HL*)&evt_data);
1686 } else {
1687 APPL_TRACE_ERROR("bta_hl_api_dch_abort Null Callback");
1688 }
1689 break;
1690 default:
1691 APPL_TRACE_ERROR("Status code=%d", status);
1692 break;
1693 }
1694 }
1695
1696 /*******************************************************************************
1697 *
1698 * Function bta_hl_hdl_event
1699 *
1700 * Description HL main event handling function.
1701 *
1702 * Returns void
1703 *
1704 ******************************************************************************/
bta_hl_hdl_event(BT_HDR * p_msg)1705 bool bta_hl_hdl_event(BT_HDR* p_msg) {
1706 uint8_t app_idx, mcl_idx, mdl_idx;
1707 bool success = true;
1708
1709 #if (BTA_HL_DEBUG == TRUE)
1710 APPL_TRACE_DEBUG("BTA HL Event Handler: Event [%s]",
1711 bta_hl_evt_code(p_msg->event));
1712 #endif
1713
1714 switch (p_msg->event) {
1715 case BTA_HL_API_ENABLE_EVT:
1716 bta_hl_api_enable(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1717 break;
1718 case BTA_HL_API_DISABLE_EVT:
1719 bta_hl_api_disable(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1720 break;
1721 case BTA_HL_API_UPDATE_EVT:
1722 bta_hl_api_update(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1723 break;
1724 case BTA_HL_API_REGISTER_EVT:
1725 bta_hl_api_register(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1726 break;
1727 case BTA_HL_API_DEREGISTER_EVT:
1728 bta_hl_api_deregister(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1729 break;
1730 case BTA_HL_API_CCH_OPEN_EVT:
1731 bta_hl_api_cch_open(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1732 break;
1733 case BTA_HL_API_CCH_CLOSE_EVT:
1734 bta_hl_api_cch_close(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1735 break;
1736 case BTA_HL_API_DCH_OPEN_EVT:
1737 bta_hl_api_dch_open(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1738 break;
1739 case BTA_HL_API_DCH_CLOSE_EVT:
1740 bta_hl_api_dch_close(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1741 break;
1742 case BTA_HL_API_DELETE_MDL_EVT:
1743 bta_hl_api_delete_mdl(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1744 break;
1745 case BTA_HL_API_DCH_RECONNECT_EVT:
1746 bta_hl_api_dch_reconnect(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1747 break;
1748
1749 case BTA_HL_API_DCH_ECHO_TEST_EVT:
1750 bta_hl_api_dch_echo_test(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1751 break;
1752
1753 case BTA_HL_API_SDP_QUERY_EVT:
1754 bta_hl_api_sdp_query(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1755 break;
1756
1757 case BTA_HL_MCA_DELETE_CFM_EVT:
1758 bta_hl_mca_delete_mdl_cfm(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1759 break;
1760
1761 case BTA_HL_MCA_DELETE_IND_EVT:
1762 bta_hl_mca_delete_mdl_ind(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1763 break;
1764
1765 case BTA_HL_SDP_QUERY_OK_EVT:
1766 case BTA_HL_SDP_QUERY_FAIL_EVT:
1767 bta_hl_sdp_query_results(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1768 break;
1769 case BTA_HL_API_DCH_ABORT_EVT:
1770 bta_hl_api_dch_abort(&bta_hl_cb, (tBTA_HL_DATA*)p_msg);
1771 break;
1772
1773 default:
1774 if (p_msg->event < BTA_HL_DCH_EVT_MIN) {
1775 if (bta_hl_find_cch_cb_indexes((tBTA_HL_DATA*)p_msg, &app_idx,
1776 &mcl_idx)) {
1777 bta_hl_cch_sm_execute(app_idx, mcl_idx, p_msg->event,
1778 (tBTA_HL_DATA*)p_msg);
1779 } else {
1780 #if (BTA_HL_DEBUG == TRUE)
1781 APPL_TRACE_ERROR(
1782 "unable to find control block indexes for CCH: [event=%s]",
1783 bta_hl_evt_code(p_msg->event));
1784 #else
1785 APPL_TRACE_ERROR(
1786 "unable to find control block indexes for CCH: [event=%d]",
1787 p_msg->event);
1788 #endif
1789 success = false;
1790 }
1791 } else {
1792 if (bta_hl_find_dch_cb_indexes((tBTA_HL_DATA*)p_msg, &app_idx, &mcl_idx,
1793 &mdl_idx)) {
1794 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, p_msg->event,
1795 (tBTA_HL_DATA*)p_msg);
1796 } else {
1797 #if (BTA_HL_DEBUG == TRUE)
1798 APPL_TRACE_ERROR(
1799 "unable to find control block indexes for DCH : [event=%s]",
1800 bta_hl_evt_code(p_msg->event));
1801 #else
1802 APPL_TRACE_ERROR(
1803 "unable to find control block indexes for DCH: [event=%d]",
1804 p_msg->event);
1805 #endif
1806 success = false;
1807 }
1808 }
1809
1810 break;
1811 }
1812
1813 return (success);
1814 }
1815
1816 /*****************************************************************************
1817 * Debug Functions
1818 ****************************************************************************/
1819 #if (BTA_HL_DEBUG == TRUE)
1820
1821 /*******************************************************************************
1822 *
1823 * Function bta_hl_cch_state_code
1824 *
1825 * Description Map CCH state code to the corresponding state string
1826 *
1827 * Returns string pointer for the associated state name
1828 *
1829 ******************************************************************************/
bta_hl_cch_state_code(tBTA_HL_CCH_STATE state_code)1830 static const char* bta_hl_cch_state_code(tBTA_HL_CCH_STATE state_code) {
1831 switch (state_code) {
1832 case BTA_HL_CCH_IDLE_ST:
1833 return "BTA_HL_CCH_IDLE_ST";
1834 case BTA_HL_CCH_OPENING_ST:
1835 return "BTA_HL_CCH_OPENING_ST";
1836 case BTA_HL_CCH_OPEN_ST:
1837 return "BTA_HL_CCH_OPEN_ST";
1838 case BTA_HL_CCH_CLOSING_ST:
1839 return "BTA_HL_CCH_CLOSING_ST";
1840 default:
1841 return "Unknown CCH state code";
1842 }
1843 }
1844
1845 /*******************************************************************************
1846 *
1847 * Function bta_hl_dch_state_code
1848 *
1849 * Description Map DCH state code to the corresponding state string
1850 *
1851 * Returns string pointer for the associated state name
1852 *
1853 ******************************************************************************/
bta_hl_dch_state_code(tBTA_HL_DCH_STATE state_code)1854 static const char* bta_hl_dch_state_code(tBTA_HL_DCH_STATE state_code) {
1855 switch (state_code) {
1856 case BTA_HL_DCH_IDLE_ST:
1857 return "BTA_HL_DCH_IDLE_ST";
1858 case BTA_HL_DCH_OPENING_ST:
1859 return "BTA_HL_DCH_OPENING_ST";
1860 case BTA_HL_DCH_OPEN_ST:
1861 return "BTA_HL_DCH_OPEN_ST";
1862 case BTA_HL_DCH_CLOSING_ST:
1863 return "BTA_HL_DCH_CLOSING_ST";
1864 default:
1865 return "Unknown DCH state code";
1866 }
1867 }
1868 #endif /* Debug Functions */
1869 #endif /* HL_INCLUDED */
1870