1 /******************************************************************************
2  *
3  *  Copyright (C) 2003-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 (HL) action functions for
22  *  the state machine.
23  *
24  ******************************************************************************/
25 
26 #include <string.h>
27 
28 #include "bt_target.h"
29 #if defined(HL_INCLUDED) && (HL_INCLUDED == TRUE)
30 
31 #include "gki.h"
32 #include "sdp_api.h"
33 #include "bta_sys.h"
34 #include "port_api.h"
35 #include "sdp_api.h"
36 #include "bta_hl_api.h"
37 #include "bta_hl_int.h"
38 #include "utl.h"
39 #include "mca_defs.h"
40 #include "mca_api.h"
41 
42 /*****************************************************************************
43 **  Local Function prototypes
44 *****************************************************************************/
45 #if (BTA_HL_DEBUG == TRUE && BT_TRACE_VERBOSE == TRUE)
46 static char *bta_hl_mcap_evt_code(UINT8 evt_code);
47 static char *bta_hl_dch_oper_code(tBTA_HL_DCH_OPER oper_code);
48 static char *bta_hl_cback_evt_code(UINT8 evt_code);
49 #endif
50 static void bta_hl_sdp_cback(UINT8 sdp_op, UINT8 app_idx, UINT8 mcl_idx,
51                              UINT8 mdl_idx, UINT16 status);
52 static void bta_hl_sdp_cback0(UINT16 status);
53 static void bta_hl_sdp_cback1(UINT16 status);
54 static void bta_hl_sdp_cback2(UINT16 status);
55 static void bta_hl_sdp_cback3(UINT16 status);
56 static void bta_hl_sdp_cback4(UINT16 status);
57 static void bta_hl_sdp_cback5(UINT16 status);
58 static void bta_hl_sdp_cback6(UINT16 status);
59 
60 
61 static tSDP_DISC_CMPL_CB * const bta_hl_sdp_cback_arr[] =
62 {
63     bta_hl_sdp_cback0,
64     bta_hl_sdp_cback1,
65     bta_hl_sdp_cback2,
66     bta_hl_sdp_cback3,
67     bta_hl_sdp_cback4,
68     bta_hl_sdp_cback5,
69     bta_hl_sdp_cback6
70 };
71 
72 
73 
74 /*******************************************************************************
75 **
76 ** Function         bta_hl_dch_mca_cong_change
77 **
78 ** Description      Action routine for processing congestion change notification
79 **
80 ** Returns          void
81 **
82 *******************************************************************************/
bta_hl_dch_mca_cong_change(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)83 void bta_hl_dch_mca_cong_change(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
84                                 tBTA_HL_DATA *p_data)
85 {
86     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
87     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
88     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
89     tMCA_CONG_CHG       *p_cong_chg = &p_data->mca_evt.mca_data.cong_chg;
90     tBTA_HL             evt_data;
91 
92 #if (BTA_HL_DEBUG == TRUE)
93     APPL_TRACE_DEBUG("bta_hl_dch_mca_cong_change mdl_id=%d cong=%d",
94                       p_cong_chg->mdl_id,
95                       p_cong_chg->cong);
96 #endif
97     evt_data.dch_cong_ind.cong          =
98     p_dcb->cong                         = p_cong_chg->cong;
99     evt_data.dch_cong_ind.mdl_handle    = p_dcb->mdl_handle;
100     evt_data.dch_cong_ind.mcl_handle    = p_mcb->mcl_handle;
101     evt_data.dch_cong_ind.app_handle    = p_acb->app_handle;
102 
103     p_acb->p_cback(BTA_HL_CONG_CHG_IND_EVT ,(tBTA_HL *) &evt_data );
104 }
105 
106 
107 
108 /*******************************************************************************
109 **
110 ** Function         bta_hl_dch_echo_test
111 **
112 ** Description      Action routine for processing echo test request
113 **
114 ** Returns          void
115 **
116 *******************************************************************************/
bta_hl_dch_echo_test(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)117 void bta_hl_dch_echo_test(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
118                           tBTA_HL_DATA *p_data)
119 {
120     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
121     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
122     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
123     UNUSED(p_data);
124 
125 #if (BTA_HL_DEBUG == TRUE)
126     APPL_TRACE_DEBUG("bta_hl_dch_echo_test");
127 #endif
128 
129     p_dcb->echo_oper = BTA_HL_ECHO_OP_CI_GET_ECHO_DATA;
130     p_dcb->cout_oper |= BTA_HL_CO_GET_ECHO_DATA_MASK;
131 
132     bta_hl_co_get_echo_data(p_acb->app_id, p_mcb->mcl_handle,
133                             p_dcb->p_echo_tx_pkt->len,
134                             BTA_HL_GET_BUF_PTR(p_dcb->p_echo_tx_pkt),
135                             BTA_HL_CI_GET_ECHO_DATA_EVT);
136 
137 }
138 /*******************************************************************************
139 **
140 ** Function         bta_hl_dch_sdp_init
141 **
142 ** Description      Action routine for processing DCH SDP initiation
143 **
144 ** Returns          void
145 **
146 *******************************************************************************/
bta_hl_dch_sdp_init(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)147 void bta_hl_dch_sdp_init(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
148                          tBTA_HL_DATA *p_data)
149 {
150     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
151     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
152 
153 #if (BTA_HL_DEBUG == TRUE)
154     APPL_TRACE_DEBUG("bta_hl_dch_sdp_init");
155 #endif
156     if ( p_mcb->sdp_oper == BTA_HL_SDP_OP_NONE)
157     {
158         p_mcb->sdp_mdl_idx = mdl_idx;
159         if (p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_OPEN )
160         {
161             p_mcb->sdp_oper = BTA_HL_SDP_OP_DCH_OPEN_INIT;
162 
163         }
164         else
165         {
166             p_mcb->sdp_oper = BTA_HL_SDP_OP_DCH_RECONNECT_INIT;
167         }
168 
169         if (bta_hl_init_sdp(p_mcb->sdp_oper, app_idx, mcl_idx, mdl_idx) != BTA_HL_STATUS_OK)
170         {
171             APPL_TRACE_ERROR("SDP INIT failed");
172             p_mcb->sdp_oper = BTA_HL_SDP_OP_NONE;
173             bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_SDP_FAIL_EVT, p_data);
174         }
175     }
176     else
177     {
178         APPL_TRACE_ERROR("SDP in use");
179         bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_SDP_FAIL_EVT, p_data);
180     }
181 }
182 
183 
184 /*******************************************************************************
185 **
186 ** Function         bta_hl_dch_close_echo_test
187 **
188 ** Description      Action routine for processing the closing of echo test
189 **
190 ** Returns          void
191 **
192 *******************************************************************************/
bta_hl_dch_close_echo_test(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)193 void bta_hl_dch_close_echo_test(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
194                                 tBTA_HL_DATA *p_data)
195 {
196     tBTA_HL_MDL_CB          *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
197 
198 #if (BTA_HL_DEBUG == TRUE)
199     APPL_TRACE_DEBUG("bta_hl_dch_close_echo_test");
200 #endif
201 
202     switch (p_dcb->echo_oper)
203     {
204         case BTA_HL_ECHO_OP_DCH_CLOSE_CFM:
205         case BTA_HL_ECHO_OP_OPEN_IND:
206         case BTA_HL_ECHO_OP_ECHO_PKT:
207             p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST;
208             break;
209         case BTA_HL_ECHO_OP_MDL_CREATE_CFM:
210         case BTA_HL_ECHO_OP_DCH_OPEN_CFM:
211         case BTA_HL_ECHO_OP_LOOP_BACK:
212         default:
213             break;
214     }
215 
216     if (MCA_CloseReq((tMCA_DL) p_dcb->mdl_handle)!= MCA_SUCCESS)
217     {
218         bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
219     }
220 }
221 
222 
223 /*******************************************************************************
224 **
225 ** Function         bta_hl_dch_mca_rcv_data
226 **
227 ** Description      Action routine for processing the received data
228 **
229 ** Returns          void
230 **
231 *******************************************************************************/
bta_hl_dch_mca_rcv_data(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)232 void bta_hl_dch_mca_rcv_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
233                              tBTA_HL_DATA *p_data)
234 {
235     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
236     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
237     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
238 
239 #if (BTA_HL_DEBUG == TRUE)
240     APPL_TRACE_DEBUG("bta_hl_dch_mca_rcv_data");
241 #endif
242 
243     if (p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID)
244     {
245         switch ( p_dcb->echo_oper)
246         {
247             case  BTA_HL_ECHO_OP_ECHO_PKT:
248 
249                 if (MCA_WriteReq((tMCA_DL) p_dcb->mdl_handle, p_data->mca_rcv_data_evt.p_pkt) != MCA_SUCCESS)
250                 {
251                     utl_freebuf((void **) &p_data->mca_rcv_data_evt.p_pkt);
252                     bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_ECHO_TEST_EVT, p_data);
253                 }
254                 break;
255             case BTA_HL_ECHO_OP_LOOP_BACK:
256 
257                 p_dcb->p_echo_rx_pkt = p_data->mca_rcv_data_evt.p_pkt;
258                 p_dcb->echo_oper = BTA_HL_ECHO_OP_CI_PUT_ECHO_DATA;
259                 p_dcb->cout_oper |= BTA_HL_CO_PUT_ECHO_DATA_MASK;
260                 p_dcb->ci_put_echo_data_status = BTA_HL_STATUS_FAIL;
261 
262                 bta_hl_co_put_echo_data(p_acb->app_id, p_mcb->mcl_handle,
263                                         p_dcb->p_echo_rx_pkt->len,
264                                         BTA_HL_GET_BUF_PTR(p_dcb->p_echo_rx_pkt),
265                                         BTA_HL_CI_PUT_ECHO_DATA_EVT);
266                 break;
267             default:
268                 APPL_TRACE_ERROR("Unknonw echo_oper=%d",p_dcb->echo_oper);
269                 break;
270         }
271 
272     }
273     else
274     {
275         p_dcb->cout_oper |= BTA_HL_CO_PUT_RX_DATA_MASK;
276         p_dcb->p_rx_pkt = p_data->mca_rcv_data_evt.p_pkt;
277 
278         bta_hl_co_put_rx_data(p_acb->app_id, p_dcb->mdl_handle,
279                               p_dcb->p_rx_pkt->len,
280                               BTA_HL_GET_BUF_PTR(p_dcb->p_rx_pkt),
281                               BTA_HL_CI_PUT_RX_DATA_EVT);
282 
283 
284     }
285 }
286 
287 
288 /*******************************************************************************
289 **
290 ** Function         bta_hl_dch_ci_put_echo_data
291 **
292 ** Description      Action routine for processing the call-in of the
293 **                  put echo data event
294 **
295 ** Returns          void
296 **
297 *******************************************************************************/
bta_hl_dch_ci_put_echo_data(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)298 void bta_hl_dch_ci_put_echo_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
299                                  tBTA_HL_DATA *p_data)
300 {
301     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
302 
303 #if (BTA_HL_DEBUG == TRUE)
304     APPL_TRACE_DEBUG("bta_hl_dch_ci_put_echo_data");
305 #endif
306 
307     p_dcb->cout_oper &= ~BTA_HL_CO_PUT_ECHO_DATA_MASK;
308     utl_freebuf((void **) &p_dcb->p_echo_rx_pkt);
309     p_dcb->ci_put_echo_data_status = p_data->ci_get_put_echo_data.status;
310 
311     p_dcb->echo_oper = BTA_HL_ECHO_OP_DCH_CLOSE_CFM;
312     bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_ECHO_TEST_EVT, p_data);
313 }
314 
315 
316 
317 /*******************************************************************************
318 **
319 ** Function         bta_hl_dch_ci_get_echo_data
320 **
321 ** Description      Action routine for processing the call-in of the
322 **                  get echo data event
323 **
324 ** Returns          void
325 **
326 *******************************************************************************/
bta_hl_dch_ci_get_echo_data(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)327 void bta_hl_dch_ci_get_echo_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
328                                  tBTA_HL_DATA *p_data)
329 {
330     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
331     tBTA_HL_STATUS      status;
332 
333 #if (BTA_HL_DEBUG == TRUE)
334     APPL_TRACE_DEBUG("bta_hl_dch_ci_get_echo_data");
335 #endif
336 
337     p_dcb->cout_oper &= ~BTA_HL_CO_GET_ECHO_DATA_MASK;
338 
339     if (!p_dcb->abort_oper)
340     {
341         status = p_data->ci_get_put_echo_data.status;
342         if (status == BTA_HL_STATUS_OK)
343         {
344             p_dcb->echo_oper = BTA_HL_ECHO_OP_MDL_CREATE_CFM;
345             bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_OPEN_EVT, p_data);
346         }
347         else
348         {
349             bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
350         }
351     }
352     else
353     {
354         bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
355     }
356 
357 }
358 
359 /*******************************************************************************
360 **
361 ** Function         bta_hl_dch_ci_put_rx_data
362 **
363 ** Description      Action routine for processing the call-in of the
364 **                  put rx data event
365 **
366 ** Returns          void
367 **
368 *******************************************************************************/
bta_hl_dch_ci_put_rx_data(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)369 void bta_hl_dch_ci_put_rx_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
370                                tBTA_HL_DATA *p_data)
371 {
372     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
373     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
374     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
375     tBTA_HL             evt_data;
376 
377 #if (BTA_HL_DEBUG == TRUE)
378     APPL_TRACE_DEBUG("bta_hl_dch_ci_put_rx_data");
379 #endif
380 
381     p_dcb->cout_oper &= ~BTA_HL_CO_PUT_RX_DATA_MASK;
382     utl_freebuf((void **) &p_dcb->p_rx_pkt);
383     bta_hl_build_rcv_data_ind(&evt_data,
384                               p_acb->app_handle,
385                               p_mcb->mcl_handle,
386                               p_dcb->mdl_handle);
387     p_acb->p_cback(BTA_HL_DCH_RCV_DATA_IND_EVT,(tBTA_HL *) &evt_data );
388     if (p_dcb->close_pending)
389     {
390         if (!p_dcb->cout_oper)
391         {
392             bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_EVT, p_data);
393         }
394 
395     }
396 }
397 
398 
399 
400 /*******************************************************************************
401 **
402 ** Function         bta_hl_dch_ci_get_tx_data
403 **
404 ** Description      Action routine for processing the call-in of the
405 **                  get tx data event
406 **
407 ** Returns          void
408 **
409 *******************************************************************************/
bta_hl_dch_ci_get_tx_data(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)410 void bta_hl_dch_ci_get_tx_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
411                                tBTA_HL_DATA *p_data)
412 {
413     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
414     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
415     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
416     tMCA_RESULT         result;
417     tBTA_HL_STATUS      status = BTA_HL_STATUS_OK;
418     BOOLEAN             free_buf = FALSE;
419     BOOLEAN             close_dch = FALSE;
420     tBTA_HL             evt_data;
421 
422 
423 #if (BTA_HL_DEBUG == TRUE)
424     APPL_TRACE_DEBUG("bta_hl_dch_ci_get_tx_data");
425 #endif
426 
427     p_dcb->cout_oper &= ~BTA_HL_CO_GET_TX_DATA_MASK;
428 
429     if (p_dcb->close_pending)
430     {
431         status = BTA_HL_STATUS_FAIL;
432         free_buf = TRUE;
433 
434         if (!p_dcb->cout_oper)
435         {
436             close_dch = TRUE;
437         }
438     }
439     else
440     {
441         if ((result = MCA_WriteReq((tMCA_DL) p_dcb->mdl_handle, p_dcb->p_tx_pkt)) != MCA_SUCCESS)
442         {
443             if (result == MCA_BUSY)
444             {
445                 status = BTA_HL_STATUS_DCH_BUSY;
446             }
447             else
448             {
449                 status = BTA_HL_STATUS_FAIL;
450             }
451             free_buf = TRUE;
452         }
453         else
454         {
455             p_dcb->p_tx_pkt = NULL;
456         }
457     }
458 
459     if (free_buf)
460     {
461         utl_freebuf((void **) &p_dcb->p_tx_pkt);
462     }
463 
464     bta_hl_build_send_data_cfm(&evt_data,
465                                p_acb->app_handle,
466                                p_mcb->mcl_handle,
467                                p_dcb->mdl_handle,
468                                status);
469     p_acb->p_cback(BTA_HL_DCH_SEND_DATA_CFM_EVT,(tBTA_HL *) &evt_data );
470 
471     if (close_dch)
472     {
473         bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_EVT, p_data);
474     }
475 }
476 
477 
478 /*******************************************************************************
479 **
480 ** Function         bta_hl_dch_send_data
481 **
482 ** Description      Action routine for processing api send data request
483 **
484 ** Returns          void
485 **
486 *******************************************************************************/
bta_hl_dch_send_data(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)487 void bta_hl_dch_send_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
488                           tBTA_HL_DATA *p_data)
489 {
490     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
491     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
492     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
493     tBTA_HL             evt_data;
494     BOOLEAN             success = TRUE;
495 
496 #if (BTA_HL_DEBUG == TRUE)
497     APPL_TRACE_DEBUG("bta_hl_dch_send_data");
498 #endif
499 
500     if (!(p_dcb->cout_oper & BTA_HL_CO_GET_TX_DATA_MASK))
501     {
502         if ((p_dcb->p_tx_pkt = bta_hl_get_buf(p_data->api_send_data.pkt_size)) != NULL)
503         {
504             bta_hl_co_get_tx_data( p_acb->app_id,
505                                    p_dcb->mdl_handle,
506                                    p_data->api_send_data.pkt_size,
507                                    BTA_HL_GET_BUF_PTR(p_dcb->p_tx_pkt),
508                                    BTA_HL_CI_GET_TX_DATA_EVT);
509             p_dcb->cout_oper |= BTA_HL_CO_GET_TX_DATA_MASK;
510         }
511         else
512         {
513             success = FALSE;
514         }
515     }
516     else
517     {
518         success = FALSE;
519     }
520 
521     if (!success)
522     {
523         bta_hl_build_send_data_cfm(&evt_data,
524                                    p_acb->app_handle,
525                                    p_mcb->mcl_handle,
526                                    p_dcb->mdl_handle,
527                                    BTA_HL_STATUS_FAIL);
528         p_acb->p_cback(BTA_HL_DCH_SEND_DATA_CFM_EVT,(tBTA_HL *) &evt_data );
529     }
530 }
531 
532 /*******************************************************************************
533 **
534 ** Function         bta_hl_dch_close_cmpl
535 **
536 ** Description      Action routine for processing the close complete event
537 **
538 ** Returns          void
539 **
540 *******************************************************************************/
bta_hl_dch_close_cmpl(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)541 void bta_hl_dch_close_cmpl(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
542                            tBTA_HL_DATA *p_data)
543 {
544     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
545     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
546     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
547     tBTA_HL             evt_data;
548     tBTA_HL_EVT         event = 0;
549     BOOLEAN             send_evt=TRUE;
550     tBTA_HL_STATUS      status;
551 
552 #if (BTA_HL_DEBUG == TRUE)
553 #if (BT_TRACE_VERBOSE == TRUE)
554     APPL_TRACE_DEBUG("bta_hl_dch_close_cmpl dch oper=%s", bta_hl_dch_oper_code(p_dcb->dch_oper));
555 #else
556     APPL_TRACE_DEBUG("bta_hl_dch_close_cmpl dch oper=%d", p_dcb->dch_oper);
557 #endif
558 #endif
559 
560     switch (p_dcb->dch_oper)
561     {
562         case BTA_HL_DCH_OP_LOCAL_OPEN:
563         case BTA_HL_DCH_OP_LOCAL_RECONNECT:
564 
565             if (p_dcb->abort_oper & BTA_HL_ABORT_LOCAL_MASK)
566             {
567                 bta_hl_build_abort_cfm(&evt_data,
568                                        p_acb->app_handle,
569                                        p_mcb->mcl_handle,
570                                        BTA_HL_STATUS_OK);
571                 event = BTA_HL_DCH_ABORT_CFM_EVT;
572             }
573             else if (p_dcb->abort_oper & BTA_HL_ABORT_REMOTE_MASK )
574             {
575                 bta_hl_build_abort_ind(&evt_data,
576                                        p_acb->app_handle,
577                                        p_mcb->mcl_handle);
578                 event = BTA_HL_DCH_ABORT_IND_EVT;
579             }
580             else
581             {
582                 bta_hl_build_dch_open_cfm(&evt_data,
583                                           p_acb->app_handle,
584                                           p_mcb->mcl_handle,
585                                           BTA_HL_INVALID_MDL_HANDLE,
586                                           0,0,0,0,0, BTA_HL_STATUS_FAIL);
587                 event = BTA_HL_DCH_OPEN_CFM_EVT;
588                 if (p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_RECONNECT)
589                 {
590                     event = BTA_HL_DCH_RECONNECT_CFM_EVT;
591                 }
592             }
593             break;
594 
595         case BTA_HL_DCH_OP_LOCAL_CLOSE:
596         case BTA_HL_DCH_OP_REMOTE_DELETE:
597         case BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT:
598         case BTA_HL_DCH_OP_NONE:
599 
600             bta_hl_build_dch_close_cfm(&evt_data,
601                                        p_acb->app_handle,
602                                        p_mcb->mcl_handle,
603                                        p_dcb->mdl_handle,
604                                        BTA_HL_STATUS_OK);
605             event = BTA_HL_DCH_CLOSE_CFM_EVT;
606             break;
607 
608         case BTA_HL_DCH_OP_REMOTE_CLOSE:
609             bta_hl_build_dch_close_ind(&evt_data,
610                                        p_acb->app_handle,
611                                        p_mcb->mcl_handle,
612                                        p_dcb->mdl_handle,
613                                        p_dcb->intentional_close);
614             event = BTA_HL_DCH_CLOSE_IND_EVT;
615             break;
616 
617         case BTA_HL_DCH_OP_REMOTE_OPEN:
618 
619             if (p_dcb->abort_oper & BTA_HL_ABORT_LOCAL_MASK)
620             {
621                 bta_hl_build_abort_cfm(&evt_data,
622                                        p_acb->app_handle,
623                                        p_mcb->mcl_handle,
624                                        BTA_HL_STATUS_OK);
625                 event = BTA_HL_DCH_ABORT_CFM_EVT;
626             }
627             else if (p_dcb->abort_oper & BTA_HL_ABORT_REMOTE_MASK )
628             {
629                 bta_hl_build_abort_ind(&evt_data,
630                                        p_acb->app_handle,
631                                        p_mcb->mcl_handle);
632                 event = BTA_HL_DCH_ABORT_IND_EVT;
633             }
634             else
635             {
636                 bta_hl_build_dch_close_ind(&evt_data,
637                                            p_acb->app_handle,
638                                            p_mcb->mcl_handle,
639                                            p_dcb->mdl_handle,
640                                            p_dcb->intentional_close);
641                 event = BTA_HL_DCH_CLOSE_IND_EVT;
642             }
643             break;
644 
645         case BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST:
646             /* this is normal echo test close */
647         case BTA_HL_DCH_OP_REMOTE_CREATE:
648         case BTA_HL_DCH_OP_REMOTE_RECONNECT:
649             send_evt=FALSE;
650             break;
651 
652         default:
653 #if (BTA_HL_DEBUG == TRUE)
654 #if (BT_TRACE_VERBOSE == TRUE)
655             APPL_TRACE_ERROR("DCH operation not found oper=%s", bta_hl_dch_oper_code(p_dcb->dch_oper));
656 #else
657             APPL_TRACE_ERROR("DCH operation not found oper=%d", p_dcb->dch_oper);
658 #endif
659 #endif
660             send_evt=FALSE;
661             break;
662     }
663 
664     if ( p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID )
665     {
666         p_mcb->echo_test = FALSE;
667         send_evt=FALSE;
668 
669         if ( p_dcb->dch_oper != BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST)
670         {
671             switch (p_dcb->echo_oper)
672             {
673                 case BTA_HL_ECHO_OP_CI_GET_ECHO_DATA:
674                 case BTA_HL_ECHO_OP_SDP_INIT:
675                 case BTA_HL_ECHO_OP_MDL_CREATE_CFM:
676                 case BTA_HL_ECHO_OP_DCH_OPEN_CFM:
677                 case BTA_HL_ECHO_OP_LOOP_BACK:
678 
679                     status = BTA_HL_STATUS_FAIL;
680                     send_evt = TRUE;
681                     break;
682                 case BTA_HL_ECHO_OP_OPEN_IND:
683                 case BTA_HL_ECHO_OP_ECHO_PKT:
684                     break;
685                 default:
686                     APPL_TRACE_ERROR("Invalid echo_oper=%d", p_dcb->echo_oper);
687                     break;
688             }
689         }
690         else
691         {
692             status = p_dcb->ci_put_echo_data_status;
693             send_evt = TRUE;
694         }
695 
696         if (send_evt)
697         {
698             bta_hl_build_echo_test_cfm(&evt_data,
699                                        p_acb->app_handle,
700                                        p_mcb->mcl_handle,
701                                        status);
702             event = BTA_HL_DCH_ECHO_TEST_CFM_EVT;
703         }
704     }
705 
706     bta_hl_clean_mdl_cb(app_idx, mcl_idx, mdl_idx);
707 
708     if (send_evt)
709     {
710         if (p_acb->p_cback)
711         {
712 #if (BTA_HL_DEBUG == TRUE)
713 #if (BT_TRACE_VERBOSE == TRUE)
714             APPL_TRACE_DEBUG("Send Event: %s",  bta_hl_cback_evt_code(event));
715 #else
716             APPL_TRACE_DEBUG("Send Event: 0x%02x", event);
717 #endif
718 #endif
719             p_acb->p_cback(event,(tBTA_HL *) &evt_data );
720         }
721     }
722     /* check cch close is in progress or not */
723     bta_hl_check_cch_close(app_idx, mcl_idx, p_data, FALSE);
724 }
725 /*******************************************************************************
726 **
727 ** Function         bta_hl_dch_mca_close_ind
728 **
729 ** Description      Action routine for processing the close indication
730 **
731 ** Returns          void
732 **
733 *******************************************************************************/
bta_hl_dch_mca_close_ind(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)734 void bta_hl_dch_mca_close_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
735                               tBTA_HL_DATA *p_data)
736 {
737     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
738 
739 #if (BTA_HL_DEBUG == TRUE)
740 #if (BT_TRACE_VERBOSE == TRUE)
741     APPL_TRACE_DEBUG("bta_hl_dch_mca_close_ind dch oper=%s", bta_hl_dch_oper_code(p_dcb->dch_oper));
742 #else
743     APPL_TRACE_DEBUG("bta_hl_dch_mca_close_ind dch oper=%d", p_dcb->dch_oper);
744 #endif
745 #endif
746 
747     p_dcb->intentional_close = FALSE;
748     if (p_data->mca_evt.mca_data.close_ind.reason == L2CAP_DISC_OK)
749     {
750         p_dcb->intentional_close = TRUE;
751     }
752 
753     if (!p_dcb->cout_oper)
754     {
755         if ((p_dcb->dch_oper != BTA_HL_DCH_OP_REMOTE_OPEN) &&
756             (p_dcb->dch_oper != BTA_HL_DCH_OP_REMOTE_RECONNECT))
757         {
758             p_dcb->dch_oper = BTA_HL_DCH_OP_REMOTE_CLOSE;
759         }
760         bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
761     }
762     else
763     {
764         p_dcb->close_pending = TRUE;
765     }
766 }
767 
768 /*******************************************************************************
769 **
770 ** Function         bta_hl_dch_mca_close_cfm
771 **
772 ** Description      Action routine for processing the close confirmation
773 **
774 ** Returns          void
775 **
776 *******************************************************************************/
bta_hl_dch_mca_close_cfm(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)777 void bta_hl_dch_mca_close_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
778                               tBTA_HL_DATA *p_data)
779 {
780     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
781 
782 
783 #if (BTA_HL_DEBUG == TRUE)
784 #if (BT_TRACE_VERBOSE == TRUE)
785     APPL_TRACE_DEBUG("bta_hl_dch_mca_close_cfm dch_oper=%s", bta_hl_dch_oper_code(p_dcb->dch_oper) );
786 #else
787     APPL_TRACE_DEBUG("bta_hl_dch_mca_close_cfm dch_oper=%d", p_dcb->dch_oper);
788 #endif
789 #endif
790 
791     switch (p_dcb->dch_oper)
792     {
793         case BTA_HL_DCH_OP_LOCAL_CLOSE:
794         case BTA_HL_DCH_OP_LOCAL_OPEN:
795         case BTA_HL_DCH_OP_LOCAL_RECONNECT:
796         case BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST:
797         case BTA_HL_DCH_OP_REMOTE_DELETE:
798         case BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT:
799         case BTA_HL_DCH_OP_NONE:
800             bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
801             break;
802         default:
803 #if (BTA_HL_DEBUG == TRUE)
804 #if (BT_TRACE_VERBOSE == TRUE)
805             APPL_TRACE_ERROR("Invalid dch_oper=%s for close cfm", bta_hl_dch_oper_code(p_dcb->dch_oper) );
806 #else
807             APPL_TRACE_ERROR("Invalid dch_oper=%d for close cfm", p_dcb->dch_oper);
808 #endif
809 #endif
810             break;
811     }
812 
813 }
814 
815 /*******************************************************************************
816 **
817 ** Function         bta_hl_dch_mca_close
818 **
819 ** Description      Action routine for processing the DCH close request
820 **
821 ** Returns          void
822 **
823 *******************************************************************************/
bta_hl_dch_mca_close(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)824 void bta_hl_dch_mca_close(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
825                           tBTA_HL_DATA *p_data)
826 {
827     tBTA_HL_APP_CB          *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
828     tBTA_HL_MCL_CB          *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
829     tBTA_HL_MDL_CB          *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
830     tBTA_HL_STATUS          status = BTA_HL_STATUS_OK;
831     tBTA_HL                 evt_data;
832 
833 #if (BTA_HL_DEBUG == TRUE)
834     APPL_TRACE_DEBUG("bta_hl_dch_mca_close");
835 #endif
836     if (!p_dcb->cout_oper)
837     {
838         p_dcb->close_pending = FALSE;
839         if (MCA_CloseReq((tMCA_DL)p_dcb->mdl_handle)== MCA_SUCCESS)
840         {
841             p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_CLOSE;
842         }
843         else
844         {
845             status = BTA_HL_STATUS_FAIL;
846         }
847 
848         if ((status != BTA_HL_STATUS_OK) &&
849             (p_mcb->cch_close_dch_oper != BTA_HL_CCH_CLOSE_OP_DCH_CLOSE))
850         {
851             bta_hl_build_dch_close_cfm(&evt_data,
852                                        p_acb->app_handle,
853                                        p_mcb->mcl_handle,
854                                        p_data->api_dch_close.mdl_handle,
855                                        status);
856             p_acb->p_cback(BTA_HL_DCH_CLOSE_CFM_EVT,(tBTA_HL *) &evt_data );
857         }
858     }
859     else
860     {
861         p_dcb->close_pending = TRUE;
862     }
863 }
864 
865 
866 /*******************************************************************************
867 **
868 ** Function         bta_hl_dch_mca_open_ind
869 **
870 ** Description      Action routine for processing the open indication
871 **
872 ** Returns          void
873 **
874 *******************************************************************************/
bta_hl_dch_mca_open_ind(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)875 void bta_hl_dch_mca_open_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
876                              tBTA_HL_DATA *p_data)
877 {
878     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
879     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
880     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
881     tMCA_DL_OPEN        *p_open_ind = &p_data->mca_evt.mca_data.open_ind;
882     tBTA_HL             evt_data;
883     tBTA_HL_EVT         event;
884     UINT8               old_dch_oper = BTA_HL_DCH_OP_NONE;
885     BOOLEAN             send_event = FALSE;
886 
887 
888 #if (BTA_HL_DEBUG == TRUE)
889     APPL_TRACE_DEBUG("bta_hl_dch_mca_open_ind");
890 #endif
891     if ((p_dcb->dch_oper == BTA_HL_DCH_OP_REMOTE_OPEN) ||
892         (p_dcb->dch_oper == BTA_HL_DCH_OP_REMOTE_RECONNECT)    )
893     {
894         p_dcb->mdl_handle = (tBTA_HL_MDL_HANDLE) p_open_ind->mdl;
895         p_dcb->mtu        = p_open_ind->mtu;
896 
897         evt_data.dch_open_ind.mdl_handle = p_dcb->mdl_handle;
898         evt_data.dch_open_ind.mcl_handle = p_mcb->mcl_handle;
899         evt_data.dch_open_ind.app_handle = p_acb->app_handle;
900 
901         evt_data.dch_open_ind.local_mdep_id = p_dcb->local_mdep_id;
902         evt_data.dch_open_ind.mdl_id = p_dcb->mdl_id;
903         evt_data.dch_open_ind.mtu = p_dcb->mtu;
904 
905         if ( p_dcb->chnl_cfg.fcr_opt.mode == L2CAP_FCR_ERTM_MODE )
906         {
907             evt_data.dch_open_ind.dch_mode = BTA_HL_DCH_MODE_RELIABLE;
908             if (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx))
909             {
910                 p_dcb->is_the_first_reliable = TRUE;
911             }
912         }
913         else
914         {
915             evt_data.dch_open_ind.dch_mode = BTA_HL_DCH_MODE_STREAMING;
916         }
917         evt_data.dch_open_ind.first_reliable = p_dcb->is_the_first_reliable ;
918 
919         old_dch_oper = p_dcb->dch_oper;
920         p_dcb->dch_oper = BTA_HL_DCH_OP_NONE;
921 
922 
923     }
924 
925     switch (old_dch_oper)
926     {
927         case BTA_HL_DCH_OP_REMOTE_OPEN:
928 
929             p_dcb->dch_mode = evt_data.dch_open_ind.dch_mode;
930             if (p_dcb->local_mdep_id != BTA_HL_ECHO_TEST_MDEP_ID)
931             {
932                 bta_hl_save_mdl_cfg(app_idx, mcl_idx,mdl_idx);
933                 event= BTA_HL_DCH_OPEN_IND_EVT;
934                 send_event= TRUE;
935             }
936             else
937             {
938                 p_dcb->echo_oper = BTA_HL_ECHO_OP_ECHO_PKT;
939             }
940 
941             break;
942 
943         case BTA_HL_DCH_OP_REMOTE_RECONNECT:
944 
945             if (bta_hl_validate_chan_cfg(app_idx, mcl_idx, mdl_idx))
946             {
947                 bta_hl_save_mdl_cfg(app_idx, mcl_idx,mdl_idx);
948                 event= BTA_HL_DCH_RECONNECT_IND_EVT;
949                 send_event= TRUE;
950             }
951             else
952             {
953                 if (MCA_CloseReq((tMCA_DL) p_dcb->mdl_handle) == MCA_SUCCESS)
954                 {
955                     p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT;
956                 }
957                 else
958                 {
959                     APPL_TRACE_ERROR("Unabel to close DCH for reconnect cfg mismatch");
960                 }
961             }
962             break;
963         default:
964             break;
965     }
966 
967     if (send_event)
968     {
969         p_acb->p_cback(event ,(tBTA_HL *) &evt_data );
970     }
971 }
972 
973 /*******************************************************************************
974 **
975 ** Function         bta_hl_dch_mca_open_cfm
976 **
977 ** Description      Action routine for processing the open confirmation
978 **
979 ** Returns          void
980 **
981 *******************************************************************************/
bta_hl_dch_mca_open_cfm(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)982 void bta_hl_dch_mca_open_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
983                              tBTA_HL_DATA *p_data)
984 {
985     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
986     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
987     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
988     tMCA_DL_OPEN        *p_open_cfm = &p_data->mca_evt.mca_data.open_cfm;
989     tBTA_HL             evt_data;
990     tBTA_HL_EVT         event;
991     UINT8               old_dch_oper = BTA_HL_DCH_OP_NONE;
992     tBTA_HL_DCH_MODE    dch_mode = BTA_HL_DCH_MODE_STREAMING;
993     BOOLEAN             send_event = FALSE;
994 
995 
996 #if (BTA_HL_DEBUG == TRUE)
997     APPL_TRACE_DEBUG("bta_hl_dch_mca_open_cfm");
998 #endif
999     if ((p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_OPEN) ||
1000         (p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_RECONNECT))
1001     {
1002         p_dcb->mdl_handle = (tBTA_HL_MDL_HANDLE) p_open_cfm->mdl;
1003         p_dcb->mtu        = p_open_cfm->mtu;
1004 
1005         /*todo verify dch_mode, mtu and fcs for reconnect */
1006         if ( p_dcb->chnl_cfg.fcr_opt.mode == L2CAP_FCR_ERTM_MODE )
1007         {
1008             dch_mode = BTA_HL_DCH_MODE_RELIABLE;
1009         }
1010 
1011         if (p_dcb->local_mdep_id != BTA_HL_ECHO_TEST_MDEP_ID)
1012         {
1013             if (dch_mode == BTA_HL_DCH_MODE_RELIABLE )
1014             {
1015                 if (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx))
1016                 {
1017                     p_dcb->is_the_first_reliable = TRUE;
1018                 }
1019             }
1020         }
1021 
1022         bta_hl_build_dch_open_cfm(&evt_data, p_acb->app_handle,
1023                                   p_mcb->mcl_handle,
1024                                   p_dcb->mdl_handle,
1025                                   p_dcb->local_mdep_id,
1026                                   p_dcb->mdl_id, dch_mode,
1027                                   p_dcb->is_the_first_reliable,
1028                                   p_dcb->mtu,
1029                                   BTA_HL_STATUS_OK);
1030 
1031         old_dch_oper = p_dcb->dch_oper;
1032         p_dcb->dch_oper = BTA_HL_DCH_OP_NONE;
1033     }
1034     else
1035     {
1036         APPL_TRACE_ERROR("Error dch oper =%d",  p_dcb->dch_oper);
1037         return;
1038     }
1039 
1040     switch (old_dch_oper)
1041     {
1042         case BTA_HL_DCH_OP_LOCAL_OPEN:
1043 
1044             p_dcb->dch_mode = dch_mode;
1045             if (p_dcb->local_mdep_id != BTA_HL_ECHO_TEST_MDEP_ID)
1046             {
1047                 bta_hl_save_mdl_cfg(app_idx, mcl_idx, mdl_idx);
1048                 event= BTA_HL_DCH_OPEN_CFM_EVT;
1049                 send_event= TRUE;
1050             }
1051             else
1052             {
1053                 p_dcb->echo_oper = BTA_HL_ECHO_OP_LOOP_BACK;
1054                 if (MCA_WriteReq((tMCA_DL) p_dcb->mdl_handle, p_dcb->p_echo_tx_pkt)!= MCA_SUCCESS)
1055                 {
1056                     bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_ECHO_TEST_EVT, p_data);
1057                 }
1058                 else
1059                 {
1060                     p_dcb->p_echo_tx_pkt = NULL;
1061                 }
1062             }
1063             break;
1064 
1065         case BTA_HL_DCH_OP_LOCAL_RECONNECT:
1066 
1067             if (bta_hl_validate_chan_cfg(app_idx, mcl_idx, mdl_idx))
1068             {
1069                 bta_hl_save_mdl_cfg(app_idx, mcl_idx,mdl_idx);
1070                 event= BTA_HL_DCH_RECONNECT_CFM_EVT;
1071                 send_event= TRUE;
1072             }
1073             else
1074             {
1075                 if (MCA_CloseReq((tMCA_DL) p_dcb->mdl_handle) == MCA_SUCCESS)
1076                 {
1077                     p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT;
1078                 }
1079                 else
1080                 {
1081                     APPL_TRACE_ERROR("Unabel to close DCH for reconnect cfg mismatch");
1082                 }
1083             }
1084             break;
1085         default:
1086             break;
1087     }
1088 
1089     if (send_event)
1090         p_acb->p_cback(event ,(tBTA_HL *) &evt_data );
1091 }
1092 
1093 
1094 /*******************************************************************************
1095 **
1096 ** Function         bta_hl_dch_mca_abort_ind
1097 **
1098 ** Description      Action routine for processing the abort indication
1099 **
1100 ** Returns          void
1101 **
1102 *******************************************************************************/
bta_hl_dch_mca_abort_ind(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)1103 void bta_hl_dch_mca_abort_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
1104                               tBTA_HL_DATA *p_data)
1105 {
1106     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1107 
1108 
1109 #if (BTA_HL_DEBUG == TRUE)
1110     APPL_TRACE_DEBUG("bta_hl_dch_mca_abort_ind");
1111 #endif
1112 
1113     p_dcb->abort_oper |= BTA_HL_ABORT_REMOTE_MASK;
1114     bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1115 }
1116 
1117 /*******************************************************************************
1118 **
1119 ** Function         bta_hl_dch_mca_abort_cfm
1120 **
1121 ** Description      Action routine for processing the abort confirmation
1122 **
1123 ** Returns          void
1124 **
1125 *******************************************************************************/
bta_hl_dch_mca_abort_cfm(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)1126 void bta_hl_dch_mca_abort_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
1127                               tBTA_HL_DATA *p_data)
1128 {
1129     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
1130     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1131     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1132     tBTA_HL             evt_data;
1133 
1134 #if (BTA_HL_DEBUG == TRUE)
1135     APPL_TRACE_DEBUG("bta_hl_dch_mca_abort_cfm");
1136 #endif
1137 
1138     if (p_dcb->abort_oper)
1139     {
1140         if (p_data->mca_evt.mca_data.abort_cfm.rsp_code != MCA_RSP_SUCCESS )
1141         {
1142             if (p_dcb->abort_oper & BTA_HL_ABORT_LOCAL_MASK)
1143             {
1144                 bta_hl_build_abort_cfm(&evt_data,
1145                                        p_acb->app_handle,
1146                                        p_mcb->mcl_handle,
1147                                        BTA_HL_STATUS_FAIL);
1148                 p_acb->p_cback(BTA_HL_DCH_ABORT_CFM_EVT ,(tBTA_HL *) &evt_data );
1149             }
1150         }
1151         else
1152         {
1153             bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1154         }
1155     }
1156     else
1157     {
1158         APPL_TRACE_ERROR("Not expecting Abort CFM ");
1159     }
1160 }
1161 
1162 /*******************************************************************************
1163 **
1164 ** Function         bta_hl_dch_mca_abort
1165 **
1166 ** Description      Action routine for processing the abort request
1167 **
1168 ** Returns          void
1169 **
1170 *******************************************************************************/
bta_hl_dch_mca_abort(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)1171 void bta_hl_dch_mca_abort(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
1172                           tBTA_HL_DATA *p_data)
1173 {
1174     tBTA_HL_APP_CB          *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
1175     tBTA_HL_MCL_CB          *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1176     tBTA_HL_MDL_CB          *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1177     tMCA_RESULT             mca_result;
1178     tBTA_HL                 evt_data;
1179 
1180     if (((p_mcb->sdp_oper == BTA_HL_SDP_OP_DCH_OPEN_INIT) ||
1181          (p_mcb->sdp_oper == BTA_HL_SDP_OP_DCH_RECONNECT_INIT)) &&
1182         (p_mcb->sdp_mdl_idx == mdl_idx) )
1183     {
1184         p_dcb->abort_oper |= BTA_HL_ABORT_PENDING_MASK;
1185         return;
1186     }
1187     else if (p_dcb->echo_oper == BTA_HL_ECHO_OP_CI_GET_ECHO_DATA)
1188     {
1189         p_dcb->abort_oper |= BTA_HL_ABORT_PENDING_MASK;
1190         return;
1191     }
1192 
1193     p_dcb->abort_oper &= ~BTA_HL_ABORT_PENDING_MASK;
1194 
1195     if ((mca_result = MCA_Abort((tMCA_CL) p_mcb->mcl_handle))!= MCA_SUCCESS)
1196     {
1197         if (mca_result == MCA_NO_RESOURCES)
1198         {
1199             p_dcb->abort_oper |= BTA_HL_ABORT_PENDING_MASK;
1200         }
1201         else
1202         {
1203             if (p_dcb->abort_oper & BTA_HL_ABORT_LOCAL_MASK)
1204             {
1205                 bta_hl_build_abort_cfm(&evt_data,
1206                                        p_acb->app_handle,
1207                                        p_mcb->mcl_handle,
1208                                        BTA_HL_STATUS_FAIL);
1209                 p_acb->p_cback(BTA_HL_DCH_ABORT_CFM_EVT ,(tBTA_HL *) &evt_data );
1210             }
1211             bta_hl_check_cch_close(app_idx, mcl_idx, p_data, FALSE);
1212         }
1213 
1214 
1215     }
1216 
1217 #if (BTA_HL_DEBUG == TRUE)
1218     APPL_TRACE_DEBUG("bta_hl_dch_mca_abort abort_oper=0x%x", p_dcb->abort_oper);
1219 #endif
1220 
1221 }
1222 
1223 /*******************************************************************************
1224 **
1225 ** Function         bta_hl_dch_mca_reconnect_ind
1226 **
1227 ** Description      Action routine for processing the reconnect indication
1228 **
1229 ** Returns          void
1230 **
1231 *******************************************************************************/
bta_hl_dch_mca_reconnect_ind(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)1232 void bta_hl_dch_mca_reconnect_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
1233                                   tBTA_HL_DATA *p_data)
1234 {
1235     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1236     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1237     tBTA_HL_MDL_CFG     *p_mdl_cfg;
1238     tMCA_EVT_HDR        *p_reconnect_ind = &p_data->mca_evt.mca_data.reconnect_ind;
1239     UINT8               mdl_cfg_idx, in_use_mdl_idx, mdep_cfg_idx;
1240     UINT8               rsp_code = MCA_RSP_SUCCESS;
1241 
1242 
1243 #if (BTA_HL_DEBUG == TRUE)
1244     APPL_TRACE_DEBUG("bta_hl_dch_mca_reconnect_ind mdl_id=%d", p_reconnect_ind->mdl_id);
1245 #endif
1246 
1247     if (bta_hl_find_mdl_cfg_idx(app_idx, mcl_idx, p_reconnect_ind->mdl_id, &mdl_cfg_idx))
1248     {
1249         if (!bta_hl_find_mdl_idx(app_idx,mcl_idx,p_reconnect_ind->mdl_id, &in_use_mdl_idx) )
1250         {
1251             p_mdl_cfg =  BTA_HL_GET_MDL_CFG_PTR(app_idx, mdl_cfg_idx);
1252 
1253             if (bta_hl_find_mdep_cfg_idx(app_idx, p_mdl_cfg->local_mdep_id, &mdep_cfg_idx))
1254             {
1255                 p_dcb->in_use               = TRUE;
1256                 p_dcb->dch_oper             = BTA_HL_DCH_OP_REMOTE_RECONNECT;
1257                 p_dcb->sec_mask             = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
1258                 p_dcb->peer_mdep_id             = 0xFF;
1259                 p_dcb->local_mdep_id        = p_mdl_cfg->local_mdep_id  ;
1260                 p_dcb->local_mdep_cfg_idx   = mdep_cfg_idx;
1261                 p_dcb->local_cfg            = BTA_HL_DCH_CFG_UNKNOWN;
1262                 p_dcb->mdl_id               = p_reconnect_ind->mdl_id;
1263                 p_dcb->mdl_cfg_idx_included = TRUE;
1264                 p_dcb->mdl_cfg_idx          = mdl_cfg_idx;
1265                 p_dcb->dch_mode             = p_mdl_cfg->dch_mode;
1266                 bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx,
1267                                            &p_dcb->max_rx_apdu_size,
1268                                            &p_dcb->max_tx_apdu_size);
1269                 bta_hl_set_dch_chan_cfg(app_idx, mcl_idx, mdl_idx, p_data);
1270             }
1271             else
1272             {
1273                 rsp_code = MCA_RSP_BAD_MDL;
1274             }
1275         }
1276         else
1277         {
1278             rsp_code = MCA_RSP_BAD_MDL;
1279         }
1280     }
1281     else
1282     {
1283         rsp_code = MCA_RSP_BAD_MDL;
1284     }
1285 
1286     if (MCA_ReconnectMdlRsp((tMCA_CL) p_mcb->mcl_handle,
1287                             p_dcb->local_mdep_id,
1288                             p_dcb->mdl_id,
1289                             rsp_code,
1290                             &p_dcb->chnl_cfg)!= MCA_SUCCESS)
1291     {
1292         MCA_Abort((tMCA_CL) p_mcb->mcl_handle);
1293         bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1294     }
1295 }
1296 
1297 /*******************************************************************************
1298 **
1299 ** Function         bta_hl_dch_mca_reconnect_cfm
1300 **
1301 ** Description      Action routine for processing the reconenct confirmation
1302 **
1303 ** Returns          void
1304 **
1305 *******************************************************************************/
bta_hl_dch_mca_reconnect_cfm(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)1306 void bta_hl_dch_mca_reconnect_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
1307                                   tBTA_HL_DATA *p_data)
1308 {
1309     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1310     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1311     tMCA_RSP_EVT        *p_reconnect_cfm = &p_data->mca_evt.mca_data.reconnect_cfm;
1312 
1313 
1314 #if (BTA_HL_DEBUG == TRUE)
1315     APPL_TRACE_DEBUG("bta_hl_dch_mca_reconnect_cfm");
1316 #endif
1317     if (p_dcb->abort_oper & BTA_HL_ABORT_PENDING_MASK)
1318     {
1319         p_dcb->abort_oper &= ~BTA_HL_ABORT_PENDING_MASK;
1320         bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ABORT_EVT, p_data);
1321         return;
1322     }
1323 
1324 
1325     if (p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_RECONNECT)
1326     {
1327         if (p_reconnect_cfm->rsp_code == MCA_RSP_SUCCESS)
1328         {
1329 
1330             bta_hl_set_dch_chan_cfg(app_idx, mcl_idx, mdl_idx, p_data);
1331 
1332             if (MCA_DataChnlCfg((tMCA_CL) p_mcb->mcl_handle, &p_dcb->chnl_cfg)!= MCA_SUCCESS)
1333             {
1334                 /* should be able to abort so no checking of the return code */
1335                 MCA_Abort((tMCA_CL) p_mcb->mcl_handle);
1336                 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1337             }
1338         }
1339         else
1340         {
1341             bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1342         }
1343     }
1344 }
1345 
1346 /*******************************************************************************
1347 **
1348 ** Function         bta_hl_dch_mca_reconnect
1349 **
1350 ** Description      Action routine for processing the reconnect request
1351 **
1352 ** Returns          void
1353 **
1354 *******************************************************************************/
bta_hl_dch_mca_reconnect(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)1355 void bta_hl_dch_mca_reconnect(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
1356                               tBTA_HL_DATA *p_data)
1357 {
1358     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1359     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1360     tMCA_CHNL_CFG       *p_chnl_cfg=NULL;
1361     UINT8               sdp_idx;
1362 
1363 #if (BTA_HL_DEBUG == TRUE)
1364     APPL_TRACE_DEBUG("bta_hl_dch_mca_reconnect");
1365 #endif
1366     if (bta_hl_find_sdp_idx_using_ctrl_psm(&p_mcb->sdp, p_mcb->ctrl_psm, &sdp_idx))
1367     {
1368         p_mcb->data_psm = p_mcb->sdp.sdp_rec[sdp_idx].data_psm;
1369         if ( MCA_ReconnectMdl((tMCA_CL) p_mcb->mcl_handle,
1370                               p_dcb->local_mdep_id,
1371                               p_mcb->data_psm,
1372                               p_dcb->mdl_id,
1373                               p_chnl_cfg ) != MCA_SUCCESS)
1374         {
1375             bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1376         }
1377     }
1378     else
1379     {
1380         bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1381     }
1382 }
1383 
1384 
1385 /*******************************************************************************
1386 **
1387 ** Function         bta_hl_dch_create_rsp
1388 **
1389 ** Description      Action routine for processing BTA_HL_API_DCH_CREATE_RSP_EVT
1390 **
1391 ** Returns          void
1392 **
1393 *******************************************************************************/
bta_hl_dch_create_rsp(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)1394 void bta_hl_dch_create_rsp(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
1395                            tBTA_HL_DATA *p_data)
1396 {
1397     tBTA_HL_MCL_CB              *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1398     tBTA_HL_MDL_CB              *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1399     tBTA_HL_API_DCH_CREATE_RSP  *p_create_rsp = &p_data->api_dch_create_rsp;
1400     UINT8                       mca_rsp_code = MCA_RSP_SUCCESS;
1401 
1402 #if (BTA_HL_DEBUG == TRUE)
1403     APPL_TRACE_DEBUG("bta_hl_dch_create_rsp");
1404 #endif
1405     if (p_create_rsp->rsp_code == BTA_HL_DCH_CREATE_RSP_SUCCESS)
1406     {
1407         p_dcb->dch_oper             = BTA_HL_DCH_OP_REMOTE_OPEN;
1408         p_dcb->local_cfg            = p_create_rsp->cfg_rsp;
1409 
1410 
1411 
1412         bta_hl_set_dch_chan_cfg(app_idx, mcl_idx, mdl_idx, p_data);
1413     }
1414     else
1415     {
1416         mca_rsp_code = MCA_RSP_CFG_REJ;
1417     }
1418 
1419     if (MCA_CreateMdlRsp((tMCA_CL) p_mcb->mcl_handle,
1420                          p_dcb->local_mdep_id,
1421                          p_dcb->mdl_id,
1422                          p_dcb->local_cfg,
1423                          mca_rsp_code,
1424                          &p_dcb->chnl_cfg)!= MCA_SUCCESS)
1425     {
1426         bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1427     }
1428 }
1429 
1430 /*******************************************************************************
1431 **
1432 ** Function         bta_hl_dch_mca_create_ind
1433 **
1434 ** Description      Action routine for processing
1435 **
1436 ** Returns          void
1437 **
1438 *******************************************************************************/
bta_hl_dch_mca_create_ind(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)1439 void bta_hl_dch_mca_create_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
1440                                tBTA_HL_DATA *p_data)
1441 {
1442     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
1443     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1444     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1445     tMCA_CREATE_IND     *p_create_ind = &p_data->mca_evt.mca_data.create_ind;
1446     UINT8               mdep_cfg_idx;
1447     UINT8               cfg_rsp;
1448     UINT8               rsp_code = MCA_RSP_SUCCESS;
1449     BOOLEAN             send_create_ind_evt = FALSE;
1450     tBTA_HL             evt_data;
1451     tBTA_HL_ECHO_CFG    *p_echo_cfg;
1452 
1453 #if (BTA_HL_DEBUG == TRUE)
1454     APPL_TRACE_DEBUG("bta_hl_dch_mca_create_ind");
1455 #endif
1456 
1457     if (bta_hl_find_mdep_cfg_idx(app_idx, p_create_ind->dep_id, &mdep_cfg_idx))
1458     {
1459         if (p_create_ind->dep_id == BTA_HL_ECHO_TEST_MDEP_ID )
1460         {
1461             if (bta_hl_find_echo_cfg_rsp(app_idx, mcl_idx, mdep_cfg_idx,p_create_ind->cfg, &cfg_rsp ))
1462             {
1463                 p_dcb->in_use               = TRUE;
1464                 p_dcb->dch_oper             = BTA_HL_DCH_OP_REMOTE_OPEN;
1465                 p_dcb->local_mdep_id        = p_create_ind->dep_id  ;
1466                 p_dcb->local_mdep_cfg_idx   = mdep_cfg_idx;
1467                 p_dcb->local_cfg            = cfg_rsp;
1468                 p_dcb->remote_cfg           = p_create_ind->cfg ;
1469                 p_dcb->mdl_id               = p_create_ind->mdl_id;
1470                 p_dcb->mdl_cfg_idx_included = FALSE;
1471                 p_echo_cfg                      = BTA_HL_GET_ECHO_CFG_PTR(app_idx);
1472                 p_dcb->max_rx_apdu_size         = p_echo_cfg->max_rx_apdu_size;
1473                 p_dcb->max_tx_apdu_size         = p_echo_cfg->max_tx_apdu_size;
1474 
1475                 bta_hl_set_dch_chan_cfg(app_idx, mcl_idx, mdl_idx, p_data);
1476             }
1477             else
1478             {
1479                 rsp_code = MCA_RSP_CFG_REJ;
1480             }
1481         }
1482         else
1483 
1484         {
1485             p_dcb->in_use               = TRUE;
1486             p_dcb->dch_oper             = BTA_HL_DCH_OP_REMOTE_CREATE;
1487             p_dcb->local_mdep_id        = p_create_ind->dep_id  ;
1488             p_dcb->local_mdep_cfg_idx   = mdep_cfg_idx;
1489             p_dcb->local_cfg            = BTA_HL_DCH_CFG_UNKNOWN;
1490             p_dcb->remote_cfg           = p_create_ind->cfg;
1491             p_dcb->mdl_id               = p_create_ind->mdl_id;
1492             p_dcb->mdl_cfg_idx_included = FALSE;
1493             bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx,
1494                                        &p_dcb->max_rx_apdu_size,
1495                                        &p_dcb->max_tx_apdu_size);
1496             send_create_ind_evt = TRUE;
1497         }
1498     }
1499     else
1500     {
1501         rsp_code = MCA_RSP_BAD_MDEP;
1502     }
1503 
1504     if (send_create_ind_evt)
1505     {
1506         evt_data.dch_create_ind.mcl_handle =  p_mcb->mcl_handle;
1507         evt_data.dch_create_ind.app_handle =  p_acb->app_handle;
1508         evt_data.dch_create_ind.local_mdep_id = p_dcb->local_mdep_id;
1509         evt_data.dch_create_ind.mdl_id = p_dcb->mdl_id;
1510         evt_data.dch_create_ind.cfg = p_dcb->remote_cfg;
1511         bdcpy(evt_data.dch_create_ind.bd_addr, p_mcb->bd_addr);
1512         p_acb->p_cback(BTA_HL_DCH_CREATE_IND_EVT,(tBTA_HL *) &evt_data );
1513     }
1514     else
1515     {
1516         if (MCA_CreateMdlRsp((tMCA_CL) p_mcb->mcl_handle,
1517                              p_dcb->local_mdep_id,
1518                              p_dcb->mdl_id,
1519                              p_dcb->local_cfg,
1520                              rsp_code,
1521                              &p_dcb->chnl_cfg)!= MCA_SUCCESS)
1522         {
1523             bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1524         }
1525         else
1526         {
1527             if (p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID)
1528             {
1529                 p_mcb->echo_test = TRUE;
1530                 p_dcb->echo_oper = BTA_HL_ECHO_OP_OPEN_IND;
1531             }
1532         }
1533     }
1534 }
1535 
1536 /*******************************************************************************
1537 **
1538 ** Function         bta_hl_dch_mca_create_cfm
1539 **
1540 ** Description      Action routine for processing
1541 **
1542 ** Returns          void
1543 **
1544 *******************************************************************************/
bta_hl_dch_mca_create_cfm(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)1545 void bta_hl_dch_mca_create_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
1546                                tBTA_HL_DATA *p_data)
1547 {
1548     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1549     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1550     tMCA_CREATE_CFM     *p_create_cfm = &p_data->mca_evt.mca_data.create_cfm;
1551 
1552 #if (BTA_HL_DEBUG == TRUE)
1553     APPL_TRACE_DEBUG("bta_hl_dch_mca_create_cfm");
1554 #endif
1555 
1556     if (p_dcb->abort_oper & BTA_HL_ABORT_PENDING_MASK)
1557     {
1558         p_dcb->abort_oper &= ~BTA_HL_ABORT_PENDING_MASK;
1559         bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ABORT_EVT, p_data);
1560         return;
1561     }
1562 
1563     if (p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_OPEN)
1564     {
1565         if (p_create_cfm->rsp_code == MCA_RSP_SUCCESS)
1566         {
1567             if (bta_hl_validate_cfg(app_idx, mcl_idx, mdl_idx, p_create_cfm->cfg ))
1568             {
1569                 bta_hl_set_dch_chan_cfg(app_idx, mcl_idx, mdl_idx, p_data);
1570 
1571                 if (MCA_DataChnlCfg((tMCA_CL) p_mcb->mcl_handle, &p_dcb->chnl_cfg)!= MCA_SUCCESS)
1572                 {
1573                     /* this should not happen */
1574                     APPL_TRACE_ERROR("Unable to create data channel");
1575                     MCA_Abort((tMCA_CL) p_mcb->mcl_handle);
1576                     bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1577                 }
1578                 else
1579                 {
1580                     if (p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID)
1581                     {
1582                         p_dcb->echo_oper = BTA_HL_ECHO_OP_DCH_OPEN_CFM;
1583                     }
1584                 }
1585             }
1586             else
1587             {
1588                 MCA_Abort((tMCA_CL) p_mcb->mcl_handle);
1589                 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1590             }
1591         }
1592         else
1593         {
1594             APPL_TRACE_ERROR("MCA Create- failed");
1595             bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1596         }
1597     }
1598 }
1599 
1600 /*******************************************************************************
1601 **
1602 ** Function         bta_hl_dch_mca_create
1603 **
1604 ** Description      Action routine for processing the MDL create request
1605 **
1606 ** Returns          void
1607 **
1608 *******************************************************************************/
bta_hl_dch_mca_create(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)1609 void bta_hl_dch_mca_create(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
1610                            tBTA_HL_DATA *p_data)
1611 {
1612     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1613     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1614     tMCA_RESULT         result;
1615     UINT8               sdp_idx;
1616 
1617 #if BTA_HL_DEBUG == TRUE
1618     APPL_TRACE_DEBUG("bta_hl_dch_mca_create");
1619 #endif
1620 
1621     if (bta_hl_find_sdp_idx_using_ctrl_psm(&p_mcb->sdp, p_mcb->ctrl_psm, &sdp_idx) &&
1622         bta_hl_validate_peer_cfg(app_idx, mcl_idx, mdl_idx,
1623                                  p_dcb->peer_mdep_id,
1624                                  p_dcb->peer_mdep_role,
1625                                  sdp_idx))
1626     {
1627 
1628         p_mcb->data_psm = p_mcb->sdp.sdp_rec[sdp_idx].data_psm;
1629         if ( (result = MCA_CreateMdl((tMCA_CL) p_mcb->mcl_handle,
1630                                      p_dcb->local_mdep_id,
1631                                      p_mcb->data_psm,
1632                                      p_dcb->mdl_id,
1633                                      p_dcb->peer_mdep_id,
1634                                      p_dcb->local_cfg,
1635                                      NULL )) != MCA_SUCCESS)
1636         {
1637             APPL_TRACE_ERROR("MCA_CreateMdl FAIL mca_result=%d", result);
1638             bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1639         }
1640     }
1641     else
1642     {
1643         APPL_TRACE_ERROR("MCA Create- SDP idx or peer MDEP cfg not found");
1644         bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1645     }
1646 }
1647 
1648 /*******************************************************************************
1649 **
1650 ** Function         bta_hl_dch_sdp_fail
1651 **
1652 ** Description      Action routine for processing the SDP failed event
1653 **
1654 ** Returns          void
1655 **
1656 *******************************************************************************/
bta_hl_dch_sdp_fail(UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,tBTA_HL_DATA * p_data)1657 void bta_hl_dch_sdp_fail(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
1658                          tBTA_HL_DATA *p_data)
1659 {
1660 
1661 #if (BTA_HL_DEBUG == TRUE)
1662     APPL_TRACE_DEBUG("bta_hl_dch_sdp_fail");
1663 #endif
1664     bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
1665 }
1666 
1667 /******************************************************************************
1668 **
1669 ** Function         bta_hl_sdp_cback
1670 **
1671 ** Description      This is the SDP callback function used by HL.
1672 **                  This function will be executed by SDP when the service
1673 **                  search is completed.  If the search is successful, it
1674 **                  finds the first record in the database that matches the
1675 **                  UUID of the search.  Then retrieves the scn from the
1676 **                  record.
1677 **
1678 ** Returns          void.
1679 **
1680 ******************************************************************************/
bta_hl_sdp_cback(UINT8 sdp_oper,UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,UINT16 status)1681 static void bta_hl_sdp_cback(UINT8 sdp_oper, UINT8 app_idx, UINT8 mcl_idx,
1682                              UINT8 mdl_idx, UINT16 status)
1683 {
1684     tBTA_HL_MCL_CB                  *p_cb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1685     tBTA_HL_SDP_REC                 *p_hdp_rec;
1686     tBTA_HL_CCH_SDP                 *p_cch_buf;
1687     tBTA_HL_DCH_SDP                 *p_dch_buf;
1688     tSDP_DISC_REC                   *p_rec = NULL;
1689     tSDP_PROTOCOL_ELEM              pe;
1690     tSDP_DISC_ATTR                  *p_attr;
1691     UINT8                           i, rec_cnt;
1692     tBTA_HL_SUP_FEATURE_LIST_ELEM   sup_feature;
1693     BOOLEAN                         sdp_parsing_ok =FALSE, result=FALSE;
1694     UINT16                          event;
1695     tBTA_HL_MDL_CB                  *p_dcb;
1696     UINT16                          service_uuid;
1697     UINT16                          name_len;
1698 
1699 #if BTA_HL_DEBUG == TRUE
1700     APPL_TRACE_DEBUG("bta_hl_sdp_cback status:%d sdp_oper=%d app_idx=%d, mcl_idx=%d,   mdl_idx=%d",
1701                       status, sdp_oper, app_idx, mcl_idx, mdl_idx);
1702 #endif
1703 
1704     rec_cnt = 0;
1705     service_uuid = bta_hl_get_service_uuids(sdp_oper, app_idx, mcl_idx, mdl_idx);
1706 
1707     if (status == SDP_SUCCESS || status == SDP_DB_FULL)
1708     {
1709         memset(&p_cb->sdp,0, sizeof(tBTA_HL_SDP));
1710         do
1711         {
1712             if (bta_hl_find_service_in_db(app_idx, mcl_idx, service_uuid, &p_rec))
1713             {
1714                 p_hdp_rec = &p_cb->sdp.sdp_rec[rec_cnt];
1715                 p_cb->sdp.num_recs = rec_cnt+1;
1716             }
1717             else
1718             {
1719                 break;
1720             }
1721 
1722             if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_L2CAP, &pe))
1723             {
1724                 p_hdp_rec->ctrl_psm  = (UINT16) pe.params[0];
1725             }
1726             else
1727             {
1728                 APPL_TRACE_WARNING("Control PSM not found");
1729                 break;
1730             }
1731             if (SDP_FindAddProtoListsElemInRec(p_rec, UUID_PROTOCOL_L2CAP, &pe))
1732             {
1733                 p_hdp_rec->data_psm = (UINT16) pe.params[0];
1734             }
1735             else
1736             {
1737                 APPL_TRACE_WARNING("Data PSM not found");
1738                 break;
1739             }
1740 
1741             p_hdp_rec->srv_name[0]= '\0';
1742             if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
1743             {
1744                 if (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) < BT_MAX_SERVICE_NAME_LEN)
1745                     name_len = (UINT16)SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
1746                 else
1747                     name_len = BT_MAX_SERVICE_NAME_LEN;
1748                 memcpy(p_hdp_rec->srv_name, p_attr->attr_value.v.array, name_len);
1749             }
1750 
1751             p_hdp_rec->srv_desp[0]= '\0';
1752             if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_DESCRIPTION)) != NULL)
1753             {
1754                 if (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) < BT_MAX_SERVICE_NAME_LEN)
1755                     name_len = (UINT16)SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
1756                 else
1757                     name_len = BT_MAX_SERVICE_NAME_LEN;
1758                 memcpy(p_hdp_rec->srv_desp, p_attr->attr_value.v.array, name_len);
1759             }
1760 
1761 
1762             p_hdp_rec->provider_name[0]= '\0';
1763             if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_PROVIDER_NAME)) != NULL)
1764             {
1765                 if (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) < BT_MAX_SERVICE_NAME_LEN)
1766                     name_len = (UINT16)SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
1767                 else
1768                     name_len = BT_MAX_SERVICE_NAME_LEN;
1769                 memcpy(p_hdp_rec->provider_name, p_attr->attr_value.v.array, name_len);
1770             }
1771 
1772             if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HDP_MCAP_SUP_PROC))!=NULL)
1773             {
1774                 p_hdp_rec->mcap_sup_proc = p_attr->attr_value.v.u8;
1775             }
1776             else
1777             {
1778                 APPL_TRACE_WARNING("MCAP SUP PROC not found");
1779                 break;
1780             }
1781 
1782             if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HDP_SUP_FEAT_LIST ))!=NULL)
1783             {
1784                 if (bta_hl_fill_sup_feature_list (p_attr, &sup_feature))
1785                 {
1786                     p_hdp_rec->num_mdeps = (UINT8) sup_feature.num_elems;
1787                     APPL_TRACE_WARNING("bta_hl_sdp_cback num_mdeps %d",sup_feature.num_elems);
1788                     for (i=0; i<sup_feature.num_elems; i++)
1789                     {
1790                         p_hdp_rec->mdep_cfg[i].data_type = sup_feature.list_elem[i].data_type;
1791                         p_hdp_rec->mdep_cfg[i].mdep_id = sup_feature.list_elem[i].mdep_id;
1792                         p_hdp_rec->mdep_cfg[i].mdep_role = sup_feature.list_elem[i].mdep_role;
1793                         /* Check MDEP Description pointer to prevent crash due to null pointer */
1794                         if (sup_feature.list_elem[i].p_mdep_desp != NULL)
1795                         {
1796                             BCM_STRNCPY_S(p_hdp_rec->mdep_cfg[i].mdep_desp,
1797                                     sizeof(p_hdp_rec->mdep_cfg[i].mdep_desp),
1798                                     sup_feature.list_elem[i].p_mdep_desp,
1799                                     BTA_HL_MDEP_DESP_LEN);
1800                         }
1801                         else
1802                         {
1803                             APPL_TRACE_ERROR("bta_hl_sdp_cback Incorrect Mdep[%d] Description (Null ptr)", i);
1804                         }
1805                     }
1806 
1807                     sdp_parsing_ok = TRUE;
1808                 }
1809                 else
1810                 {
1811                     APPL_TRACE_WARNING("HDP supported feature list fill failed");
1812                     break;
1813                 }
1814             }
1815             else
1816             {
1817                 APPL_TRACE_WARNING("HDP supported feature list not found");
1818                 break;
1819             }
1820 #if BTA_HL_DEBUG == TRUE
1821             APPL_TRACE_DEBUG("record=%d ctrl_psm=%0x data_psm=%x",
1822                               rec_cnt+1,
1823                               p_hdp_rec->ctrl_psm,
1824                               p_hdp_rec->data_psm );
1825             APPL_TRACE_DEBUG("srv_name=[%s]",(p_hdp_rec->srv_name[0] != '\0')? p_hdp_rec->srv_name:"NULL");
1826             APPL_TRACE_DEBUG("srv_desp=[%s]",(p_hdp_rec->srv_desp[0] != '\0')? p_hdp_rec->srv_desp:"NULL");
1827             for (i=0; i<sup_feature.num_elems; i++)
1828             {
1829                 APPL_TRACE_DEBUG("index=0x%02x mdep_id=0x%04x data type=0x%04x mdep role=%s(0x%02x)",
1830                                   (i+1),
1831                                   p_hdp_rec->mdep_cfg[i].mdep_id,
1832                                   p_hdp_rec->mdep_cfg[i].data_type,
1833                                   (p_hdp_rec->mdep_cfg[i].mdep_role == BTA_HL_MDEP_ROLE_SOURCE)?"Src":"Snk",
1834                                   p_hdp_rec->mdep_cfg[i].mdep_role);
1835             }
1836             APPL_TRACE_DEBUG("provider_name=[%s]",(p_hdp_rec->provider_name[0] != '\0')? p_hdp_rec->provider_name:"NULL");
1837             APPL_TRACE_DEBUG("found MCAP sup procedure=%d",
1838                               p_cb->sdp.sdp_rec[rec_cnt].mcap_sup_proc );
1839 #endif
1840             rec_cnt++;
1841             if (rec_cnt >= BTA_HL_NUM_SDP_RECS)
1842             {
1843                 APPL_TRACE_WARNING("No more spaces for SDP recs max_rec_cnt=%d", BTA_HL_NUM_SDP_RECS);
1844                 break;
1845             }
1846 
1847 
1848         } while (TRUE);
1849     }
1850 
1851 
1852     utl_freebuf((void **)&p_cb->p_db);
1853 
1854     if ( (status == SDP_SUCCESS || status == SDP_DB_FULL) &&
1855          p_cb->sdp.num_recs  &&
1856          sdp_parsing_ok)
1857     {
1858         result = TRUE;
1859     }
1860     else
1861     {
1862         APPL_TRACE_WARNING("SDP Failed sdp_status=%d num_recs=%d sdp_parsing_ok=%d ",
1863                             status, p_cb->sdp.num_recs,sdp_parsing_ok );
1864     }
1865 
1866 
1867     p_cb->sdp_oper = BTA_HL_SDP_OP_NONE;
1868 
1869     switch (sdp_oper )
1870     {
1871         case BTA_HL_SDP_OP_CCH_INIT:
1872         case BTA_HL_SDP_OP_SDP_QUERY_NEW:
1873         case BTA_HL_SDP_OP_SDP_QUERY_CURRENT:
1874 
1875             /* send result in event back to BTA */
1876             if ((p_cch_buf = (tBTA_HL_CCH_SDP *) GKI_getbuf(sizeof(tBTA_HL_CCH_SDP))) != NULL)
1877             {
1878                 if (result)
1879                 {
1880                     if (sdp_oper == BTA_HL_SDP_OP_CCH_INIT)
1881                     {
1882                         event = BTA_HL_CCH_SDP_OK_EVT;
1883                         if (p_cb->close_pending)
1884                         {
1885                             event = BTA_HL_CCH_SDP_FAIL_EVT;
1886                         }
1887                     }
1888                     else
1889                     {
1890                         event = BTA_HL_SDP_QUERY_OK_EVT;
1891                     }
1892                 }
1893                 else
1894                 {
1895                     if (sdp_oper == BTA_HL_SDP_OP_CCH_INIT)
1896                     {
1897                         event = BTA_HL_CCH_SDP_FAIL_EVT;
1898                     }
1899                     else
1900                     {
1901                         event = BTA_HL_SDP_QUERY_FAIL_EVT;
1902                     }
1903                 }
1904                 p_cch_buf->hdr.event = event;
1905 
1906                 p_cch_buf->app_idx = app_idx;
1907                 p_cch_buf->mcl_idx = mcl_idx;
1908                 p_cch_buf->release_mcl_cb = FALSE;
1909                 if (sdp_oper == BTA_HL_SDP_OP_SDP_QUERY_NEW)
1910                 {
1911                     p_cch_buf->release_mcl_cb = TRUE;
1912                 }
1913 
1914                 bta_sys_sendmsg(p_cch_buf);
1915             }
1916             break;
1917         case BTA_HL_SDP_OP_DCH_OPEN_INIT:
1918         case BTA_HL_SDP_OP_DCH_RECONNECT_INIT:
1919             if ((p_dch_buf = (tBTA_HL_DCH_SDP *) GKI_getbuf(sizeof(tBTA_HL_DCH_SDP))) != NULL)
1920             {
1921                 p_dch_buf->hdr.event = BTA_HL_DCH_SDP_FAIL_EVT;
1922                 p_dch_buf->app_idx = app_idx;
1923                 p_dch_buf->mcl_idx = mcl_idx;
1924                 p_dch_buf->mdl_idx = mdl_idx;
1925                 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1926                 if (p_dcb->abort_oper & BTA_HL_ABORT_PENDING_MASK)
1927                 {
1928                     p_dcb->abort_oper &= ~BTA_HL_ABORT_PENDING_MASK;
1929                     result = FALSE;
1930                 }
1931                 if (result)
1932                 {
1933                     if (sdp_oper == BTA_HL_SDP_OP_DCH_OPEN_INIT)
1934                     {
1935                         if (p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID )
1936                         {
1937                             p_dch_buf->hdr.event = BTA_HL_DCH_ECHO_TEST_EVT;
1938                         }
1939                         else
1940                         {
1941                             p_dch_buf->hdr.event = BTA_HL_DCH_OPEN_EVT;
1942                         }
1943                     }
1944                     else
1945                     {
1946                         p_dch_buf->hdr.event = BTA_HL_DCH_RECONNECT_EVT;
1947                     }
1948                 }
1949                 bta_sys_sendmsg(p_dch_buf);
1950             }
1951             break;
1952         default:
1953             break;
1954     }
1955 }
1956 
1957 
1958 /******************************************************************************
1959 **
1960 ** Function         bta_hl_sdp_cback0
1961 **
1962 ** Description      This is the SDP callback function used by index = 0
1963 **
1964 ** Returns          void.
1965 **
1966 ******************************************************************************/
bta_hl_sdp_cback0(UINT16 status)1967 static void bta_hl_sdp_cback0(UINT16 status)
1968 {
1969     bta_hl_sdp_cback(bta_hl_cb.scb[0].sdp_oper,
1970                      bta_hl_cb.scb[0].app_idx,
1971                      bta_hl_cb.scb[0].mcl_idx,
1972                      bta_hl_cb.scb[0].mdl_idx,
1973                      status);
1974     bta_hl_deallocate_spd_cback(0);
1975 }
1976 
1977 /******************************************************************************
1978 **
1979 ** Function         bta_hl_sdp_cback1
1980 **
1981 ** Description      This is the SDP callback function used by index = 1
1982 **
1983 ** Parameters       status  - status of the SDP callabck
1984 **
1985 ** Returns          void.
1986 **
1987 ******************************************************************************/
bta_hl_sdp_cback1(UINT16 status)1988 static void bta_hl_sdp_cback1(UINT16 status)
1989 {
1990     bta_hl_sdp_cback(bta_hl_cb.scb[1].sdp_oper,
1991                      bta_hl_cb.scb[1].app_idx,
1992                      bta_hl_cb.scb[1].mcl_idx,
1993                      bta_hl_cb.scb[1].mdl_idx,
1994                      status);
1995     bta_hl_deallocate_spd_cback(1);
1996 }
1997 
1998 /******************************************************************************
1999 **
2000 ** Function         bta_hl_sdp_cback2
2001 **
2002 ** Description      This is the SDP callback function used by index = 2
2003 **
2004 ** Returns          void.
2005 **
2006 ******************************************************************************/
bta_hl_sdp_cback2(UINT16 status)2007 static void bta_hl_sdp_cback2(UINT16 status)
2008 {
2009     bta_hl_sdp_cback(bta_hl_cb.scb[2].sdp_oper,
2010                      bta_hl_cb.scb[2].app_idx,
2011                      bta_hl_cb.scb[2].mcl_idx,
2012                      bta_hl_cb.scb[2].mdl_idx,
2013                      status);
2014     bta_hl_deallocate_spd_cback(2);
2015 }
2016 
2017 /******************************************************************************
2018 **
2019 ** Function         bta_hl_sdp_cback3
2020 **
2021 ** Description      This is the SDP callback function used by index = 3
2022 **
2023 ** Returns          void.
2024 **
2025 ******************************************************************************/
bta_hl_sdp_cback3(UINT16 status)2026 static void bta_hl_sdp_cback3(UINT16 status)
2027 {
2028     bta_hl_sdp_cback(bta_hl_cb.scb[3].sdp_oper,
2029                      bta_hl_cb.scb[3].app_idx,
2030                      bta_hl_cb.scb[3].mcl_idx,
2031                      bta_hl_cb.scb[3].mdl_idx,
2032                      status);
2033     bta_hl_deallocate_spd_cback(3);
2034 }
2035 
2036 /******************************************************************************
2037 **
2038 ** Function         bta_hl_sdp_cback4
2039 **
2040 ** Description      This is the SDP callback function used by index = 4
2041 **
2042 ** Parameters       status  - status of the SDP callabck
2043 **
2044 ** Returns          void.
2045 **
2046 ******************************************************************************/
bta_hl_sdp_cback4(UINT16 status)2047 static void bta_hl_sdp_cback4(UINT16 status)
2048 {
2049     bta_hl_sdp_cback(bta_hl_cb.scb[4].sdp_oper,
2050                      bta_hl_cb.scb[4].app_idx,
2051                      bta_hl_cb.scb[4].mcl_idx,
2052                      bta_hl_cb.scb[4].mdl_idx,
2053                      status);
2054     bta_hl_deallocate_spd_cback(4);
2055 }
2056 
2057 /******************************************************************************
2058 **
2059 ** Function         bta_hl_sdp_cback5
2060 **
2061 ** Description      This is the SDP callback function used by index = 5
2062 **
2063 ** Parameters       status  - status of the SDP callabck
2064 **
2065 ** Returns          void.
2066 **
2067 ******************************************************************************/
bta_hl_sdp_cback5(UINT16 status)2068 static void bta_hl_sdp_cback5(UINT16 status)
2069 {
2070     bta_hl_sdp_cback(bta_hl_cb.scb[5].sdp_oper,
2071                      bta_hl_cb.scb[5].app_idx,
2072                      bta_hl_cb.scb[5].mcl_idx,
2073                      bta_hl_cb.scb[5].mdl_idx,
2074                      status);
2075     bta_hl_deallocate_spd_cback(5);
2076 }
2077 
2078 /******************************************************************************
2079 **
2080 ** Function         bta_hl_sdp_cback6
2081 **
2082 ** Description      This is the SDP callback function used by index = 6
2083 **
2084 ** Returns          void.
2085 **
2086 ******************************************************************************/
bta_hl_sdp_cback6(UINT16 status)2087 static void bta_hl_sdp_cback6(UINT16 status)
2088 {
2089     bta_hl_sdp_cback(bta_hl_cb.scb[6].sdp_oper,
2090                      bta_hl_cb.scb[6].app_idx,
2091                      bta_hl_cb.scb[6].mcl_idx,
2092                      bta_hl_cb.scb[6].mdl_idx,
2093                      status);
2094     bta_hl_deallocate_spd_cback(6);
2095 }
2096 
2097 
2098 /*******************************************************************************
2099 **
2100 ** Function      bta_hl_deallocate_spd_cback
2101 **
2102 ** Description   Deallocate a SDP control block
2103 **
2104 ** Returns      BOOLEAN - TRUE found
2105 **                        FALSE not found
2106 **
2107 *******************************************************************************/
bta_hl_deallocate_spd_cback(UINT8 sdp_cback_idx)2108 void bta_hl_deallocate_spd_cback(UINT8 sdp_cback_idx)
2109 {
2110     tBTA_HL_SDP_CB *p_spd_cb = &bta_hl_cb.scb[sdp_cback_idx];
2111 
2112     memset(p_spd_cb, 0, sizeof(tBTA_HL_SDP_CB));
2113 
2114 #if BTA_HL_DEBUG == TRUE
2115     APPL_TRACE_DEBUG("bta_hl_deallocate_spd_cback index=%d", sdp_cback_idx);
2116 #endif
2117 
2118 
2119 }
2120 
2121 /*******************************************************************************
2122 **
2123 ** Function      bta_hl_allocate_spd_cback
2124 **
2125 ** Description   Finds a not in used SDP control block index
2126 **
2127 **
2128 ** Returns      BOOLEAN - TRUE found
2129 **                        FALSE not found
2130 **
2131 *******************************************************************************/
bta_hl_allocate_spd_cback(tBTA_HL_SDP_OPER sdp_oper,UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx,UINT8 * p_sdp_cback_idx)2132 tSDP_DISC_CMPL_CB *bta_hl_allocate_spd_cback(tBTA_HL_SDP_OPER sdp_oper, UINT8 app_idx, UINT8 mcl_idx,
2133                                              UINT8 mdl_idx,
2134                                              UINT8 *p_sdp_cback_idx)
2135 {
2136     UINT8 i;
2137     tSDP_DISC_CMPL_CB *p_cbcak=NULL;
2138 
2139 
2140     for (i=0; i < BTA_HL_NUM_SDP_CBACKS ; i ++)
2141     {
2142         if (!bta_hl_cb.scb[i].in_use)
2143         {
2144             p_cbcak = bta_hl_sdp_cback_arr[i];
2145             bta_hl_cb.scb[i].in_use = TRUE;
2146             bta_hl_cb.scb[i].sdp_oper = sdp_oper;
2147             bta_hl_cb.scb[i].app_idx = app_idx;
2148             bta_hl_cb.scb[i].mcl_idx = mcl_idx;
2149             bta_hl_cb.scb[i].mdl_idx = mdl_idx;
2150             *p_sdp_cback_idx = i;
2151             break;
2152         }
2153     }
2154 
2155     if (i == BTA_HL_NUM_SDP_CBACKS)
2156     {
2157         APPL_TRACE_WARNING("No scb is available to allocate")
2158     }
2159     else
2160     {
2161 #if BTA_HL_DEBUG == TRUE
2162     APPL_TRACE_DEBUG("bta_hl_allocate_spd_cback cback_idx=%d ",i );
2163     APPL_TRACE_DEBUG("sdp_oper=%d, app_idx=%d, mcl_idx=%d,  mdl_idx=%d",
2164                       bta_hl_cb.scb[i].sdp_oper,
2165                       bta_hl_cb.scb[i].app_idx,
2166                       bta_hl_cb.scb[i].mcl_idx,
2167                       bta_hl_cb.scb[i].mdl_idx );
2168 #endif
2169     }
2170     return p_cbcak;
2171 }
2172 
2173 
2174 /*******************************************************************************
2175 **
2176 ** Function         bta_hl_init_sdp
2177 **
2178 ** Description      Action routine for processing the SDP initiattion request
2179 **
2180 ** Returns          void
2181 **
2182 *******************************************************************************/
bta_hl_init_sdp(tBTA_HL_SDP_OPER sdp_oper,UINT8 app_idx,UINT8 mcl_idx,UINT8 mdl_idx)2183 tBTA_HL_STATUS bta_hl_init_sdp(tBTA_HL_SDP_OPER sdp_oper, UINT8 app_idx, UINT8 mcl_idx,
2184                                UINT8 mdl_idx)
2185 {
2186     tBTA_HL_MCL_CB      *p_cb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2187     tSDP_UUID           uuid_list;
2188     UINT16              attr_list[BTA_HL_NUM_SRCH_ATTR];
2189     UINT16              num_attrs = BTA_HL_NUM_SRCH_ATTR;
2190     tBTA_HL_STATUS      status;
2191     UINT8               sdp_cback_idx;
2192 #if BTA_HL_DEBUG == TRUE
2193     APPL_TRACE_DEBUG("bta_hl_init_sdp sdp_oper=%d app_idx=%d mcl_idx=%d, mdl_idx=%d",
2194                       sdp_oper, app_idx, mcl_idx, mdl_idx);
2195 #endif
2196     if ((p_cb->sdp_cback = bta_hl_allocate_spd_cback(sdp_oper, app_idx, mcl_idx, mdl_idx, &sdp_cback_idx)) != NULL)
2197     {
2198         if ( p_cb->p_db ||
2199              (!p_cb->p_db &&
2200               (p_cb->p_db = (tSDP_DISCOVERY_DB *) GKI_getbuf(BTA_HL_DISC_SIZE)) != NULL))
2201         {
2202             attr_list[0] = ATTR_ID_SERVICE_CLASS_ID_LIST;
2203             attr_list[1] = ATTR_ID_PROTOCOL_DESC_LIST;
2204             attr_list[2] = ATTR_ID_BT_PROFILE_DESC_LIST;
2205             attr_list[3] = ATTR_ID_ADDITION_PROTO_DESC_LISTS;
2206             attr_list[4] = ATTR_ID_SERVICE_NAME;
2207             attr_list[5] = ATTR_ID_SERVICE_DESCRIPTION;
2208             attr_list[6] = ATTR_ID_PROVIDER_NAME;
2209             attr_list[7] = ATTR_ID_HDP_SUP_FEAT_LIST;
2210             attr_list[8] = ATTR_ID_HDP_DATA_EXCH_SPEC;
2211             attr_list[9] = ATTR_ID_HDP_MCAP_SUP_PROC;
2212 
2213 
2214             uuid_list.len = LEN_UUID_16;
2215             uuid_list.uu.uuid16 = UUID_SERVCLASS_HDP_PROFILE;
2216             SDP_InitDiscoveryDb(p_cb->p_db, BTA_HL_DISC_SIZE, 1, &uuid_list, num_attrs, attr_list);
2217 
2218             if (!SDP_ServiceSearchAttributeRequest(p_cb->bd_addr, p_cb->p_db, p_cb->sdp_cback))
2219             {
2220                 status = BTA_HL_STATUS_FAIL;
2221             }
2222             else
2223             {
2224                 status = BTA_HL_STATUS_OK;
2225             }
2226         }
2227         else    /* No services available */
2228         {
2229             status = BTA_HL_STATUS_NO_RESOURCE;
2230         }
2231     }
2232     else
2233     {
2234         status = BTA_HL_STATUS_SDP_NO_RESOURCE;
2235     }
2236 
2237     if (status != BTA_HL_STATUS_OK)
2238     {
2239         utl_freebuf((void **)&p_cb->p_db);
2240         if (status != BTA_HL_STATUS_SDP_NO_RESOURCE )
2241         {
2242             bta_hl_deallocate_spd_cback(sdp_cback_idx);
2243         }
2244     }
2245 
2246     return status;
2247 }
2248 
2249 /*******************************************************************************
2250 **
2251 ** Function         bta_hl_cch_sdp_init
2252 **
2253 ** Description      Action routine for processing the CCH SDP init event
2254 **
2255 ** Returns          void
2256 **
2257 *******************************************************************************/
bta_hl_cch_sdp_init(UINT8 app_idx,UINT8 mcl_idx,tBTA_HL_DATA * p_data)2258 void bta_hl_cch_sdp_init(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2259 {
2260     tBTA_HL_MCL_CB      *p_cb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2261 #if BTA_HL_DEBUG == TRUE
2262     APPL_TRACE_DEBUG("bta_hl_cch_init_sdp");
2263 #endif
2264     if ( p_cb->sdp_oper == BTA_HL_SDP_OP_NONE)
2265     {
2266         p_cb->app_id = p_data->api_cch_open.app_id;
2267         p_cb->sdp_oper = BTA_HL_SDP_OP_CCH_INIT;
2268 
2269         if (bta_hl_init_sdp( p_cb->sdp_oper, app_idx, mcl_idx, 0xFF) != BTA_HL_STATUS_OK)
2270         {
2271             p_cb->sdp_oper = BTA_HL_SDP_OP_NONE;
2272             bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_SDP_FAIL_EVT, p_data);
2273         }
2274     }
2275     else
2276     {
2277         APPL_TRACE_ERROR("SDP in use");
2278         bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_SDP_FAIL_EVT, p_data);
2279     }
2280 }
2281 
2282 /*******************************************************************************
2283 **
2284 ** Function         bta_hl_cch_mca_open
2285 **
2286 ** Description      Action routine for processing the CCH open request
2287 **
2288 ** Returns          void
2289 **
2290 *******************************************************************************/
bta_hl_cch_mca_open(UINT8 app_idx,UINT8 mcl_idx,tBTA_HL_DATA * p_data)2291 void bta_hl_cch_mca_open(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2292 {
2293     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
2294     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2295     UINT8               sdp_idx;
2296 
2297 #if BTA_HL_DEBUG == TRUE
2298     APPL_TRACE_DEBUG("bta_hl_cch_mca_open");
2299 #endif
2300 
2301     if (bta_hl_find_sdp_idx_using_ctrl_psm(&p_mcb->sdp, p_mcb->req_ctrl_psm, &sdp_idx))
2302     {
2303         p_mcb->ctrl_psm = p_mcb->sdp.sdp_rec[sdp_idx].ctrl_psm;
2304         p_mcb->data_psm = p_mcb->sdp.sdp_rec[sdp_idx].data_psm;
2305         if ( MCA_ConnectReq((tMCA_HANDLE) p_acb->app_handle,
2306                             p_mcb->bd_addr,
2307                             p_mcb->ctrl_psm ,
2308                             p_mcb->sec_mask) != MCA_SUCCESS)
2309         {
2310 
2311             bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data);
2312         }
2313     }
2314     else
2315     {
2316         bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data);
2317     }
2318 }
2319 
2320 /*******************************************************************************
2321 **
2322 ** Function         bta_hl_cch_mca_close
2323 **
2324 ** Description      Action routine for processing the CCH close request
2325 **
2326 ** Returns          void
2327 **
2328 *******************************************************************************/
bta_hl_cch_mca_close(UINT8 app_idx,UINT8 mcl_idx,tBTA_HL_DATA * p_data)2329 void bta_hl_cch_mca_close(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2330 {
2331     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2332 
2333 #if BTA_HL_DEBUG == TRUE
2334     APPL_TRACE_DEBUG("bta_hl_cch_mca_close mcl_handle=%d", p_mcb->mcl_handle);
2335 #endif
2336     if (p_mcb->sdp_oper != BTA_HL_SDP_OP_CCH_INIT)
2337     {
2338         if(p_mcb->mcl_handle)
2339         {
2340             if ( MCA_DisconnectReq((tMCA_HANDLE) p_mcb->mcl_handle) != MCA_SUCCESS)
2341             {
2342                 bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data);
2343             }
2344         }
2345         else
2346         {
2347             p_mcb->close_pending = TRUE;
2348             APPL_TRACE_DEBUG("No valid mcl_handle to stop the CCH setup now so wait until CCH is up then close it" );
2349         }
2350     }
2351     else
2352     {
2353         p_mcb->close_pending = TRUE;
2354         APPL_TRACE_DEBUG("can not stop the CCH setup becasue SDP is in progress so wait until it is done" );
2355     }
2356 }
2357 
2358 /*******************************************************************************
2359 **
2360 ** Function         bta_hl_cch_close_cmpl
2361 **
2362 ** Description      Action routine for processing the CCH close complete event
2363 **
2364 ** Returns          void
2365 **
2366 *******************************************************************************/
bta_hl_cch_close_cmpl(UINT8 app_idx,UINT8 mcl_idx,tBTA_HL_DATA * p_data)2367 void bta_hl_cch_close_cmpl(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2368 {
2369     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
2370     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2371 
2372     tBTA_HL             evt_data;
2373     tBTA_HL_EVT         event;
2374     BOOLEAN             send_evt=TRUE;
2375 #if BTA_HL_DEBUG == TRUE
2376     APPL_TRACE_DEBUG("bta_hl_cch_close_cmpl");
2377 #endif
2378     bta_sys_conn_close(BTA_ID_HL, p_acb->app_id, p_mcb->bd_addr);
2379 
2380     if (p_mcb->cch_oper == BTA_HL_CCH_OP_LOCAL_CLOSE && p_mcb->force_close_local_cch_opening)
2381     {
2382        p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_OPEN;
2383        APPL_TRACE_DEBUG("change cch_oper from BTA_HL_CCH_OP_LOCAL_CLOSE to BTA_HL_CCH_OP_LOCAL_OPEN");
2384     }
2385 
2386     switch (p_mcb->cch_oper)
2387     {
2388         case BTA_HL_CCH_OP_LOCAL_OPEN:
2389             bta_hl_build_cch_open_cfm(&evt_data,p_mcb->app_id,p_acb->app_handle,
2390                                       p_mcb->mcl_handle,
2391                                       p_mcb->bd_addr,
2392                                       BTA_HL_STATUS_FAIL);
2393             event = BTA_HL_CCH_OPEN_CFM_EVT;
2394             break;
2395         case BTA_HL_CCH_OP_LOCAL_CLOSE:
2396             bta_hl_build_cch_close_cfm(&evt_data,  p_acb->app_handle,
2397                                        p_mcb->mcl_handle,
2398                                        BTA_HL_STATUS_OK);
2399             event = BTA_HL_CCH_CLOSE_CFM_EVT;
2400             break;
2401         case BTA_HL_CCH_OP_REMOTE_CLOSE:
2402             bta_hl_build_cch_close_ind(&evt_data,
2403                                        p_acb->app_handle,
2404                                        p_mcb->mcl_handle,
2405                                        p_mcb->intentional_close);
2406             event = BTA_HL_CCH_CLOSE_IND_EVT;
2407             break;
2408         default:
2409             send_evt=FALSE;
2410             break;
2411     }
2412 
2413 
2414     memset(p_mcb, 0 ,sizeof(tBTA_HL_MCL_CB));
2415 
2416     if (send_evt)p_acb->p_cback(event,(tBTA_HL *) &evt_data );
2417 
2418     bta_hl_check_deregistration(app_idx, p_data);
2419 }
2420 
2421 /*******************************************************************************
2422 **
2423 ** Function         bta_hl_cch_mca_disconnect
2424 **
2425 ** Description      Action routine for processing the CCH disconnect indication
2426 **
2427 ** Returns          void
2428 **
2429 *******************************************************************************/
bta_hl_cch_mca_disconnect(UINT8 app_idx,UINT8 mcl_idx,tBTA_HL_DATA * p_data)2430 void bta_hl_cch_mca_disconnect(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2431 {
2432 
2433     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2434     tBTA_HL_MDL_CB      *p_dcb;
2435     UINT8              i;
2436 #if BTA_HL_DEBUG == TRUE
2437     APPL_TRACE_DEBUG("bta_hl_cch_mca_disconnect");
2438 #endif
2439 
2440     p_mcb->intentional_close = FALSE;
2441     if (p_data->mca_evt.mca_data.disconnect_ind.reason == L2CAP_DISC_OK)
2442     {
2443         p_mcb->intentional_close = TRUE;
2444     }
2445 
2446     for (i=0; i< BTA_HL_NUM_MDLS_PER_MCL; i++)
2447     {
2448         p_dcb= BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, i);
2449         if (p_dcb->in_use && (p_dcb->dch_state != BTA_HL_DCH_IDLE_ST))
2450         {
2451             if (p_mcb->cch_oper == BTA_HL_CCH_OP_LOCAL_CLOSE )
2452             {
2453                 bta_hl_dch_sm_execute(app_idx, mcl_idx, i, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
2454             }
2455             else
2456             {
2457                 bta_hl_dch_sm_execute(app_idx, mcl_idx, i, BTA_HL_MCA_CLOSE_IND_EVT, p_data);
2458             }
2459         }
2460     }
2461     bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data);
2462 }
2463 
2464 /*******************************************************************************
2465 **
2466 ** Function         bta_hl_cch_mca_disc_open
2467 **
2468 ** Description      Action routine for disconnect the just opened Control channel
2469 **
2470 ** Returns          void
2471 **
2472 *******************************************************************************/
bta_hl_cch_mca_disc_open(UINT8 app_idx,UINT8 mcl_idx,tBTA_HL_DATA * p_data)2473 void bta_hl_cch_mca_disc_open(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2474 {
2475     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2476 
2477 #if BTA_HL_DEBUG == TRUE
2478     APPL_TRACE_DEBUG("bta_hl_cch_mca_disc_open mcl_handle=0x%x close_pending=%d", p_data->mca_evt.mcl_handle, p_mcb->close_pending );
2479 #endif
2480 
2481     p_mcb->close_pending = FALSE;
2482     p_mcb->mcl_handle = p_data->mca_evt.mcl_handle;
2483     bta_hl_cch_mca_close(app_idx, mcl_idx, p_data);
2484 }
2485 
2486 /*******************************************************************************
2487 **
2488 ** Function         bta_hl_cch_mca_rsp_tout
2489 **
2490 ** Description      Action routine for processing the MCAP response timeout
2491 **
2492 ** Returns          void
2493 **
2494 *******************************************************************************/
bta_hl_cch_mca_rsp_tout(UINT8 app_idx,UINT8 mcl_idx,tBTA_HL_DATA * p_data)2495 void bta_hl_cch_mca_rsp_tout(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2496 {
2497 
2498     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2499 #if BTA_HL_DEBUG == TRUE
2500     APPL_TRACE_DEBUG("bta_hl_cch_mca_rsp_tout");
2501 #endif
2502 
2503     p_mcb->rsp_tout = TRUE;
2504 
2505     bta_hl_check_cch_close(app_idx,mcl_idx,p_data,TRUE);
2506 }
2507 
2508 /*******************************************************************************
2509 **
2510 ** Function         bta_hl_cch_mca_connect
2511 **
2512 ** Description      Action routine for processing the CCH connect indication
2513 **
2514 ** Returns          void
2515 **
2516 *******************************************************************************/
bta_hl_cch_mca_connect(UINT8 app_idx,UINT8 mcl_idx,tBTA_HL_DATA * p_data)2517 void bta_hl_cch_mca_connect(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2518 {
2519     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
2520     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2521     tBTA_HL             evt_data;
2522     tBTA_HL_EVT         event;
2523     BOOLEAN             send_event=TRUE;
2524 
2525 #if BTA_HL_DEBUG == TRUE
2526     APPL_TRACE_DEBUG("bta_hl_cch_mca_connect mcl_handle=%d ", p_data->mca_evt.mcl_handle);
2527 #endif
2528 
2529     p_mcb->mcl_handle = p_data->mca_evt.mcl_handle;
2530     bdcpy(p_mcb->bd_addr, p_data->mca_evt.mca_data.connect_ind.bd_addr);
2531     p_mcb->cch_mtu = p_data->mca_evt.mca_data.connect_ind.mtu;
2532 
2533     bta_sys_conn_open(BTA_ID_HL, p_acb->app_id, p_mcb->bd_addr);
2534     switch (p_mcb->cch_oper)
2535     {
2536         case BTA_HL_CCH_OP_LOCAL_OPEN:
2537             bta_hl_build_cch_open_cfm(&evt_data, p_mcb->app_id,p_acb->app_handle,
2538                                       p_mcb->mcl_handle,
2539                                       p_mcb->bd_addr,
2540                                       BTA_HL_STATUS_OK);
2541             event = BTA_HL_CCH_OPEN_CFM_EVT;
2542             break;
2543         case BTA_HL_CCH_OP_REMOTE_OPEN:
2544             bta_hl_build_cch_open_ind(&evt_data, p_acb->app_handle,
2545                                       p_mcb->mcl_handle,
2546                                       p_mcb->bd_addr);
2547             event = BTA_HL_CCH_OPEN_IND_EVT;
2548             break;
2549         default:
2550             send_event = FALSE;
2551             break;
2552     }
2553 
2554     p_mcb->cch_oper = BTA_HL_CCH_OP_NONE;
2555     if (send_event) p_acb->p_cback(event,(tBTA_HL *) &evt_data );
2556 }
2557 
2558 /*******************************************************************************
2559 **
2560 ** Function         bta_hl_mcap_ctrl_cback
2561 **
2562 ** Description      MCAP control callback function for HL.
2563 **
2564 ** Returns          void
2565 **
2566 *******************************************************************************/
bta_hl_mcap_ctrl_cback(tMCA_HANDLE handle,tMCA_CL mcl,UINT8 event,tMCA_CTRL * p_data)2567 void bta_hl_mcap_ctrl_cback (tMCA_HANDLE handle, tMCA_CL mcl, UINT8 event,
2568                              tMCA_CTRL *p_data)
2569 {
2570     tBTA_HL_MCA_EVT * p_msg;
2571     BOOLEAN send_event=TRUE;
2572     UINT16 mca_event;
2573 
2574 #if (BTA_HL_DEBUG == TRUE)
2575 #if (BT_TRACE_VERBOSE == TRUE)
2576     APPL_TRACE_EVENT("bta_hl_mcap_ctrl_cback event[%s]",bta_hl_mcap_evt_code(event));
2577 #else
2578     APPL_TRACE_EVENT("bta_hl_mcap_ctrl_cback event[0x%02x]", event);
2579 #endif
2580 #endif
2581 
2582     switch (event)
2583     {
2584 
2585         case MCA_CREATE_IND_EVT:
2586             mca_event = (UINT16) BTA_HL_MCA_CREATE_IND_EVT;
2587             break;
2588         case MCA_CREATE_CFM_EVT:
2589             mca_event = (UINT16) BTA_HL_MCA_CREATE_CFM_EVT;
2590             break;
2591         case MCA_RECONNECT_IND_EVT:
2592             mca_event = (UINT16) BTA_HL_MCA_RECONNECT_IND_EVT;
2593             break;
2594         case MCA_RECONNECT_CFM_EVT:
2595             mca_event = (UINT16) BTA_HL_MCA_RECONNECT_CFM_EVT;
2596             break;
2597         case MCA_ABORT_IND_EVT:
2598             mca_event = (UINT16) BTA_HL_MCA_ABORT_IND_EVT;
2599             break;
2600         case MCA_ABORT_CFM_EVT:
2601             mca_event = (UINT16) BTA_HL_MCA_ABORT_CFM_EVT;
2602             break;
2603         case MCA_DELETE_IND_EVT:
2604             mca_event = (UINT16) BTA_HL_MCA_DELETE_IND_EVT;
2605             break;
2606         case MCA_DELETE_CFM_EVT:
2607             mca_event = (UINT16) BTA_HL_MCA_DELETE_CFM_EVT;
2608             break;
2609         case MCA_CONNECT_IND_EVT:
2610             mca_event = (UINT16) BTA_HL_MCA_CONNECT_IND_EVT;
2611             break;
2612         case MCA_DISCONNECT_IND_EVT:
2613             mca_event = (UINT16) BTA_HL_MCA_DISCONNECT_IND_EVT;
2614             break;
2615         case MCA_OPEN_IND_EVT:
2616             mca_event = (UINT16) BTA_HL_MCA_OPEN_IND_EVT;
2617             break;
2618         case MCA_OPEN_CFM_EVT:
2619             mca_event = (UINT16) BTA_HL_MCA_OPEN_CFM_EVT;
2620             break;
2621         case MCA_CLOSE_IND_EVT:
2622             mca_event = (UINT16) BTA_HL_MCA_CLOSE_IND_EVT;
2623             break;
2624         case MCA_CLOSE_CFM_EVT:
2625             mca_event = (UINT16) BTA_HL_MCA_CLOSE_CFM_EVT;
2626             break;
2627         case MCA_CONG_CHG_EVT:
2628             mca_event = (UINT16) BTA_HL_MCA_CONG_CHG_EVT;
2629             break;
2630         case MCA_RSP_TOUT_IND_EVT:
2631             mca_event = (UINT16) BTA_HL_MCA_RSP_TOUT_IND_EVT;
2632             break;
2633         case MCA_ERROR_RSP_EVT:
2634 
2635         default:
2636             send_event=FALSE;
2637             break;
2638     }
2639 
2640     if (send_event && ((p_msg = (tBTA_HL_MCA_EVT *)GKI_getbuf(sizeof(tBTA_HL_MCA_EVT))) != NULL))
2641     {
2642         p_msg->hdr.event = mca_event;
2643         p_msg->app_handle = (tBTA_HL_APP_HANDLE) handle;
2644         p_msg->mcl_handle = (tBTA_HL_MCL_HANDLE) mcl;
2645         memcpy (&p_msg->mca_data, p_data, sizeof(tMCA_CTRL));
2646         bta_sys_sendmsg(p_msg);
2647     }
2648 }
2649 
2650 /*******************************************************************************
2651 **
2652 ** Function         bta_hl_mcap_data_cback
2653 **
2654 ** Description      MCAP data callback function for HL.
2655 **
2656 ** Returns          void
2657 **
2658 *******************************************************************************/
bta_hl_mcap_data_cback(tMCA_DL mdl,BT_HDR * p_pkt)2659 void bta_hl_mcap_data_cback (tMCA_DL mdl, BT_HDR *p_pkt)
2660 {
2661     tBTA_HL_MCA_RCV_DATA_EVT *p_msg;
2662 
2663     UINT8 app_idx, mcl_idx, mdl_idx;
2664     if (bta_hl_find_mdl_idx_using_handle ((tBTA_HL_MDL_HANDLE)mdl, &app_idx, &mcl_idx, &mdl_idx))
2665     {
2666         if ((p_msg = (tBTA_HL_MCA_RCV_DATA_EVT *)GKI_getbuf(sizeof(tBTA_HL_MCA_RCV_DATA_EVT))) != NULL)
2667         {
2668             p_msg->hdr.event = BTA_HL_MCA_RCV_DATA_EVT;
2669             p_msg->app_idx = app_idx;
2670             p_msg->mcl_idx = mcl_idx;
2671             p_msg->mdl_idx = mdl_idx;
2672             p_msg->p_pkt = p_pkt;
2673             bta_sys_sendmsg(p_msg);
2674         }
2675     }
2676 }
2677 /*****************************************************************************
2678 **  Debug Functions
2679 *****************************************************************************/
2680 #if (BTA_HL_DEBUG == TRUE && BT_TRACE_VERBOSE == TRUE)
2681 
2682 /*******************************************************************************
2683 **
2684 ** Function         bta_hl_mcap_evt_code
2685 **
2686 ** Description      get the MCAP event string pointer
2687 **
2688 ** Returns          char * - event string pointer
2689 **
2690 *******************************************************************************/
bta_hl_mcap_evt_code(UINT8 evt_code)2691 static char *bta_hl_mcap_evt_code(UINT8 evt_code)
2692 {
2693 
2694     switch (evt_code)
2695     {
2696 
2697         case MCA_ERROR_RSP_EVT:
2698             return "MCA_ERROR_RSP_EVT";
2699         case MCA_CREATE_IND_EVT:
2700             return "MCA_CREATE_IND_EVT";
2701         case MCA_CREATE_CFM_EVT:
2702             return "MCA_CREATE_CFM_EVT";
2703         case MCA_RECONNECT_IND_EVT:
2704             return "MCA_RECONNECT_IND_EVT";
2705         case MCA_RECONNECT_CFM_EVT:
2706             return "MCA_RECONNECT_CFM_EVT";
2707         case MCA_ABORT_IND_EVT:
2708             return "MCA_ABORT_IND_EVT";
2709         case MCA_ABORT_CFM_EVT:
2710             return "MCA_ABORT_CFM_EVT";
2711         case MCA_DELETE_IND_EVT:
2712             return "MCA_DELETE_IND_EVT";
2713         case MCA_DELETE_CFM_EVT:
2714             return "MCA_DELETE_CFM_EVT";
2715 
2716         case MCA_CONNECT_IND_EVT:
2717             return "MCA_CONNECT_IND_EVT";
2718         case MCA_DISCONNECT_IND_EVT:
2719             return "MCA_DISCONNECT_IND_EVT";
2720         case MCA_OPEN_IND_EVT:
2721             return "MCA_OPEN_IND_EVT";
2722         case MCA_OPEN_CFM_EVT:
2723             return "MCA_OPEN_CFM_EVT";
2724         case MCA_CLOSE_IND_EVT:
2725             return "MCA_CLOSE_IND_EVT";
2726         case MCA_CLOSE_CFM_EVT:
2727             return "MCA_CLOSE_CFM_EVT";
2728         case MCA_CONG_CHG_EVT:
2729             return "MCA_CONG_CHG_EVT";
2730         case MCA_RSP_TOUT_IND_EVT:
2731             return "MCA_RSP_TOUT_IND_EVT";
2732         default:
2733             return "Unknown MCAP event code";
2734     }
2735 }
2736 
2737 
2738 /*******************************************************************************
2739 **
2740 ** Function         bta_hl_cback_evt_code
2741 **
2742 ** Description      get the HDP event string pointer
2743 **
2744 ** Returns          char * - event string pointer
2745 **
2746 *******************************************************************************/
bta_hl_cback_evt_code(UINT8 evt_code)2747 static char *bta_hl_cback_evt_code(UINT8 evt_code)
2748 {
2749 
2750     switch (evt_code)
2751     {
2752 
2753         case BTA_HL_CCH_OPEN_IND_EVT:
2754             return "BTA_HL_CCH_OPEN_IND_EVT";
2755         case BTA_HL_CCH_OPEN_CFM_EVT:
2756             return "BTA_HL_CCH_OPEN_CFM_EVT";
2757         case BTA_HL_CCH_CLOSE_IND_EVT:
2758             return "BTA_HL_CCH_CLOSE_IND_EVT";
2759         case     BTA_HL_CCH_CLOSE_CFM_EVT:
2760             return "BTA_HL_CCH_CLOSE_CFM_EVT";
2761         case BTA_HL_DCH_OPEN_IND_EVT:
2762             return "BTA_HL_DCH_OPEN_IND_EVT";
2763         case BTA_HL_DCH_OPEN_CFM_EVT:
2764             return "BTA_HL_DCH_OPEN_CFM_EVT";
2765         case BTA_HL_DCH_CLOSE_IND_EVT:
2766             return "BTA_HL_DCH_CLOSE_IND_EVT";
2767         case BTA_HL_DCH_CLOSE_CFM_EVT:
2768             return "BTA_HL_DCH_CLOSE_CFM_EVT";
2769         case BTA_HL_DCH_RCV_DATA_IND_EVT:
2770             return "BTA_HL_DCH_RCV_DATA_IND_EVT";
2771         case BTA_HL_REGISTER_CFM_EVT:
2772             return "BTA_HL_REGISTER_CFM_EVT";
2773         case BTA_HL_DEREGISTER_CFM_EVT:
2774             return "BTA_HL_DEREGISTER_CFM_EVT";
2775         case BTA_HL_DCH_RECONNECT_CFM_EVT:
2776             return "BTA_HL_DCH_RECONNECT_CFM_EVT";
2777         case BTA_HL_DCH_RECONNECT_IND_EVT:
2778             return "BTA_HL_DCH_RECONNECT_IND_EVT";
2779         case BTA_HL_DCH_ECHO_TEST_CFM_EVT:
2780             return "BTA_HL_DCH_ECHO_TEST_CFM_EVT";
2781         case BTA_HL_SDP_QUERY_CFM_EVT:
2782             return "BTA_HL_SDP_QUERY_CFM_EVT";
2783         case BTA_HL_CONG_CHG_IND_EVT:
2784             return "BTA_HL_CONG_CHG_IND_EVT";
2785         case BTA_HL_DCH_CREATE_IND_EVT:
2786             return "BTA_HL_DCH_CREATE_IND_EVT";
2787         case BTA_HL_DELETE_MDL_IND_EVT:
2788             return "BTA_HL_DELETE_MDL_IND_EVT";
2789         case BTA_HL_DELETE_MDL_CFM_EVT:
2790             return "BTA_HL_DELETE_MDL_CFM_EVT";
2791         case BTA_HL_DCH_ABORT_IND_EVT:
2792             return "BTA_HL_DCH_ABORT_IND_EVT";
2793         case BTA_HL_DCH_ABORT_CFM_EVT:
2794             return "BTA_HL_DCH_ABORT_CFM_EVT";
2795         default:
2796             return "Unknown HDP event code";
2797     }
2798 }
2799 
2800 
2801 
2802 /*******************************************************************************
2803 **
2804 ** Function         bta_hl_dch_oper_code
2805 **
2806 ** Description      Get the DCH operation string
2807 **
2808 ** Returns          char * - DCH operation string pointer
2809 **
2810 *******************************************************************************/
bta_hl_dch_oper_code(tBTA_HL_DCH_OPER oper_code)2811 static char *bta_hl_dch_oper_code(tBTA_HL_DCH_OPER oper_code)
2812 {
2813 
2814     switch (oper_code)
2815     {
2816         case BTA_HL_DCH_OP_NONE:
2817             return "BTA_HL_DCH_OP_NONE";
2818         case BTA_HL_DCH_OP_REMOTE_CREATE:
2819             return "BTA_HL_DCH_OP_REMOTE_CREATE";
2820         case BTA_HL_DCH_OP_LOCAL_OPEN:
2821             return "BTA_HL_DCH_OP_LOCAL_OPEN";
2822         case BTA_HL_DCH_OP_REMOTE_OPEN:
2823             return "BTA_HL_DCH_OP_REMOTE_OPEN";
2824         case BTA_HL_DCH_OP_LOCAL_CLOSE:
2825             return "BTA_HL_DCH_OP_LOCAL_CLOSE";
2826         case BTA_HL_DCH_OP_REMOTE_CLOSE:
2827             return "BTA_HL_DCH_OP_REMOTE_CLOSE";
2828         case BTA_HL_DCH_OP_LOCAL_DELETE:
2829             return "BTA_HL_DCH_OP_LOCAL_DELETE";
2830         case BTA_HL_DCH_OP_REMOTE_DELETE:
2831             return "BTA_HL_DCH_OP_REMOTE_DELETE";
2832         case BTA_HL_DCH_OP_LOCAL_RECONNECT:
2833             return "BTA_HL_DCH_OP_LOCAL_RECONNECT";
2834         case BTA_HL_DCH_OP_REMOTE_RECONNECT:
2835             return "BTA_HL_DCH_OP_REMOTE_RECONNECT";
2836         case BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST:
2837             return "BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST";
2838         case BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT:
2839             return "BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT";
2840         default:
2841             return "Unknown DCH oper code";
2842     }
2843 }
2844 
2845 
2846 #endif  /* Debug Functions */
2847 #endif /* HL_INCLUDED */
2848