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 "bt_common.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)
46static char *bta_hl_mcap_evt_code(UINT8 evt_code);
47static char *bta_hl_dch_oper_code(tBTA_HL_DCH_OPER oper_code);
48static char *bta_hl_cback_evt_code(UINT8 evt_code);
49#endif
50static void bta_hl_sdp_cback(UINT8 sdp_op, UINT8 app_idx, UINT8 mcl_idx,
51                             UINT8 mdl_idx, UINT16 status);
52static void bta_hl_sdp_cback0(UINT16 status);
53static void bta_hl_sdp_cback1(UINT16 status);
54static void bta_hl_sdp_cback2(UINT16 status);
55static void bta_hl_sdp_cback3(UINT16 status);
56static void bta_hl_sdp_cback4(UINT16 status);
57static void bta_hl_sdp_cback5(UINT16 status);
58static void bta_hl_sdp_cback6(UINT16 status);
59
60
61static 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*******************************************************************************/
83void 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*******************************************************************************/
117void 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*******************************************************************************/
147void 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*******************************************************************************/
193void 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*******************************************************************************/
232void 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                    osi_free_and_reset((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*******************************************************************************/
298void 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    osi_free_and_reset((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*******************************************************************************/
327void 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*******************************************************************************/
369void 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    osi_free_and_reset((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*******************************************************************************/
410void 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        osi_free_and_reset((void **)&p_dcb->p_tx_pkt);
461
462    bta_hl_build_send_data_cfm(&evt_data,
463                               p_acb->app_handle,
464                               p_mcb->mcl_handle,
465                               p_dcb->mdl_handle,
466                               status);
467    p_acb->p_cback(BTA_HL_DCH_SEND_DATA_CFM_EVT,(tBTA_HL *) &evt_data );
468
469    if (close_dch)
470    {
471        bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_EVT, p_data);
472    }
473}
474
475
476/*******************************************************************************
477**
478** Function         bta_hl_dch_send_data
479**
480** Description      Action routine for processing api send data request
481**
482** Returns          void
483**
484*******************************************************************************/
485void bta_hl_dch_send_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
486                          tBTA_HL_DATA *p_data)
487{
488    tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
489    tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
490    tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
491    tBTA_HL             evt_data;
492    BOOLEAN             success = TRUE;
493
494#if (BTA_HL_DEBUG == TRUE)
495    APPL_TRACE_DEBUG("bta_hl_dch_send_data");
496#endif
497
498    if (!(p_dcb->cout_oper & BTA_HL_CO_GET_TX_DATA_MASK))
499    {
500        // p_dcb->chnl_cfg.fcs may be BTA_HL_MCA_USE_FCS (0x11) or BTA_HL_MCA_NO_FCS (0x10) or BTA_HL_DEFAULT_SOURCE_FCS (1)
501        BOOLEAN fcs_use = (BOOLEAN) (p_dcb->chnl_cfg.fcs & BTA_HL_MCA_FCS_USE_MASK);
502        if ((p_dcb->p_tx_pkt = bta_hl_get_buf(p_data->api_send_data.pkt_size, fcs_use)) != 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*******************************************************************************/
541void 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*******************************************************************************/
734void 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*******************************************************************************/
777void 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*******************************************************************************/
824void 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*******************************************************************************/
875void 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*******************************************************************************/
982void 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*******************************************************************************/
1103void 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*******************************************************************************/
1126void 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*******************************************************************************/
1171void 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*******************************************************************************/
1232void 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*******************************************************************************/
1306void 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*******************************************************************************/
1355void 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*******************************************************************************/
1394void 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*******************************************************************************/
1439void 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*******************************************************************************/
1545void 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*******************************************************************************/
1609void 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*******************************************************************************/
1657void 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******************************************************************************/
1681static 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                            strlcpy(p_hdp_rec->mdep_cfg[i].mdep_desp,
1797                                    sup_feature.list_elem[i].p_mdep_desp,
1798                                    BTA_HL_MDEP_DESP_LEN);
1799                        }
1800                        else
1801                        {
1802                            APPL_TRACE_ERROR("bta_hl_sdp_cback Incorrect Mdep[%d] Description (Null ptr)", i);
1803                        }
1804                    }
1805
1806                    sdp_parsing_ok = TRUE;
1807                }
1808                else
1809                {
1810                    APPL_TRACE_WARNING("HDP supported feature list fill failed");
1811                    break;
1812                }
1813            }
1814            else
1815            {
1816                APPL_TRACE_WARNING("HDP supported feature list not found");
1817                break;
1818            }
1819#if BTA_HL_DEBUG == TRUE
1820            APPL_TRACE_DEBUG("record=%d ctrl_psm=%0x data_psm=%x",
1821                              rec_cnt+1,
1822                              p_hdp_rec->ctrl_psm,
1823                              p_hdp_rec->data_psm );
1824            APPL_TRACE_DEBUG("srv_name=[%s]",(p_hdp_rec->srv_name[0] != '\0')? p_hdp_rec->srv_name:"NULL");
1825            APPL_TRACE_DEBUG("srv_desp=[%s]",(p_hdp_rec->srv_desp[0] != '\0')? p_hdp_rec->srv_desp:"NULL");
1826            for (i=0; i<sup_feature.num_elems; i++)
1827            {
1828                APPL_TRACE_DEBUG("index=0x%02x mdep_id=0x%04x data type=0x%04x mdep role=%s(0x%02x)",
1829                                  (i+1),
1830                                  p_hdp_rec->mdep_cfg[i].mdep_id,
1831                                  p_hdp_rec->mdep_cfg[i].data_type,
1832                                  (p_hdp_rec->mdep_cfg[i].mdep_role == BTA_HL_MDEP_ROLE_SOURCE)?"Src":"Snk",
1833                                  p_hdp_rec->mdep_cfg[i].mdep_role);
1834            }
1835            APPL_TRACE_DEBUG("provider_name=[%s]",(p_hdp_rec->provider_name[0] != '\0')? p_hdp_rec->provider_name:"NULL");
1836            APPL_TRACE_DEBUG("found MCAP sup procedure=%d",
1837                              p_cb->sdp.sdp_rec[rec_cnt].mcap_sup_proc );
1838#endif
1839            rec_cnt++;
1840            if (rec_cnt >= BTA_HL_NUM_SDP_RECS)
1841            {
1842                APPL_TRACE_WARNING("No more spaces for SDP recs max_rec_cnt=%d", BTA_HL_NUM_SDP_RECS);
1843                break;
1844            }
1845
1846
1847        } while (TRUE);
1848    }
1849
1850    osi_free_and_reset((void **)&p_cb->p_db);
1851
1852    if ( (status == SDP_SUCCESS || status == SDP_DB_FULL) &&
1853         p_cb->sdp.num_recs  &&
1854         sdp_parsing_ok)
1855    {
1856        result = TRUE;
1857    }
1858    else
1859    {
1860        APPL_TRACE_WARNING("SDP Failed sdp_status=%d num_recs=%d sdp_parsing_ok=%d ",
1861                            status, p_cb->sdp.num_recs,sdp_parsing_ok );
1862    }
1863
1864
1865    p_cb->sdp_oper = BTA_HL_SDP_OP_NONE;
1866
1867    switch (sdp_oper )
1868    {
1869        case BTA_HL_SDP_OP_CCH_INIT:
1870        case BTA_HL_SDP_OP_SDP_QUERY_NEW:
1871        case BTA_HL_SDP_OP_SDP_QUERY_CURRENT:
1872
1873            /* send result in event back to BTA */
1874            p_cch_buf = (tBTA_HL_CCH_SDP *)osi_malloc(sizeof(tBTA_HL_CCH_SDP));
1875            if (result) {
1876                if (sdp_oper == BTA_HL_SDP_OP_CCH_INIT) {
1877                    event = BTA_HL_CCH_SDP_OK_EVT;
1878                    if (p_cb->close_pending)
1879                        event = BTA_HL_CCH_SDP_FAIL_EVT;
1880                } else {
1881                    event = BTA_HL_SDP_QUERY_OK_EVT;
1882                }
1883            } else {
1884                if (sdp_oper == BTA_HL_SDP_OP_CCH_INIT)
1885                    event = BTA_HL_CCH_SDP_FAIL_EVT;
1886                else
1887                    event = BTA_HL_SDP_QUERY_FAIL_EVT;
1888            }
1889            p_cch_buf->hdr.event = event;
1890
1891            p_cch_buf->app_idx = app_idx;
1892            p_cch_buf->mcl_idx = mcl_idx;
1893            p_cch_buf->release_mcl_cb = FALSE;
1894            if (sdp_oper == BTA_HL_SDP_OP_SDP_QUERY_NEW)
1895                p_cch_buf->release_mcl_cb = TRUE;
1896
1897            bta_sys_sendmsg(p_cch_buf);
1898            break;
1899        case BTA_HL_SDP_OP_DCH_OPEN_INIT:
1900        case BTA_HL_SDP_OP_DCH_RECONNECT_INIT:
1901            p_dch_buf = (tBTA_HL_DCH_SDP *)osi_malloc(sizeof(tBTA_HL_DCH_SDP));
1902            p_dch_buf->hdr.event = BTA_HL_DCH_SDP_FAIL_EVT;
1903            p_dch_buf->app_idx = app_idx;
1904            p_dch_buf->mcl_idx = mcl_idx;
1905            p_dch_buf->mdl_idx = mdl_idx;
1906            p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1907            if (p_dcb->abort_oper & BTA_HL_ABORT_PENDING_MASK) {
1908                p_dcb->abort_oper &= ~BTA_HL_ABORT_PENDING_MASK;
1909                result = FALSE;
1910            }
1911            if (result) {
1912                if (sdp_oper == BTA_HL_SDP_OP_DCH_OPEN_INIT) {
1913                    if (p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID) {
1914                        p_dch_buf->hdr.event = BTA_HL_DCH_ECHO_TEST_EVT;
1915                    } else {
1916                        p_dch_buf->hdr.event = BTA_HL_DCH_OPEN_EVT;
1917                    }
1918                } else {
1919                    p_dch_buf->hdr.event = BTA_HL_DCH_RECONNECT_EVT;
1920                }
1921            }
1922            bta_sys_sendmsg(p_dch_buf);
1923            break;
1924        default:
1925            break;
1926    }
1927}
1928
1929
1930/******************************************************************************
1931**
1932** Function         bta_hl_sdp_cback0
1933**
1934** Description      This is the SDP callback function used by index = 0
1935**
1936** Returns          void.
1937**
1938******************************************************************************/
1939static void bta_hl_sdp_cback0(UINT16 status)
1940{
1941    bta_hl_sdp_cback(bta_hl_cb.scb[0].sdp_oper,
1942                     bta_hl_cb.scb[0].app_idx,
1943                     bta_hl_cb.scb[0].mcl_idx,
1944                     bta_hl_cb.scb[0].mdl_idx,
1945                     status);
1946    bta_hl_deallocate_spd_cback(0);
1947}
1948
1949/******************************************************************************
1950**
1951** Function         bta_hl_sdp_cback1
1952**
1953** Description      This is the SDP callback function used by index = 1
1954**
1955** Parameters       status  - status of the SDP callabck
1956**
1957** Returns          void.
1958**
1959******************************************************************************/
1960static void bta_hl_sdp_cback1(UINT16 status)
1961{
1962    bta_hl_sdp_cback(bta_hl_cb.scb[1].sdp_oper,
1963                     bta_hl_cb.scb[1].app_idx,
1964                     bta_hl_cb.scb[1].mcl_idx,
1965                     bta_hl_cb.scb[1].mdl_idx,
1966                     status);
1967    bta_hl_deallocate_spd_cback(1);
1968}
1969
1970/******************************************************************************
1971**
1972** Function         bta_hl_sdp_cback2
1973**
1974** Description      This is the SDP callback function used by index = 2
1975**
1976** Returns          void.
1977**
1978******************************************************************************/
1979static void bta_hl_sdp_cback2(UINT16 status)
1980{
1981    bta_hl_sdp_cback(bta_hl_cb.scb[2].sdp_oper,
1982                     bta_hl_cb.scb[2].app_idx,
1983                     bta_hl_cb.scb[2].mcl_idx,
1984                     bta_hl_cb.scb[2].mdl_idx,
1985                     status);
1986    bta_hl_deallocate_spd_cback(2);
1987}
1988
1989/******************************************************************************
1990**
1991** Function         bta_hl_sdp_cback3
1992**
1993** Description      This is the SDP callback function used by index = 3
1994**
1995** Returns          void.
1996**
1997******************************************************************************/
1998static void bta_hl_sdp_cback3(UINT16 status)
1999{
2000    bta_hl_sdp_cback(bta_hl_cb.scb[3].sdp_oper,
2001                     bta_hl_cb.scb[3].app_idx,
2002                     bta_hl_cb.scb[3].mcl_idx,
2003                     bta_hl_cb.scb[3].mdl_idx,
2004                     status);
2005    bta_hl_deallocate_spd_cback(3);
2006}
2007
2008/******************************************************************************
2009**
2010** Function         bta_hl_sdp_cback4
2011**
2012** Description      This is the SDP callback function used by index = 4
2013**
2014** Parameters       status  - status of the SDP callabck
2015**
2016** Returns          void.
2017**
2018******************************************************************************/
2019static void bta_hl_sdp_cback4(UINT16 status)
2020{
2021    bta_hl_sdp_cback(bta_hl_cb.scb[4].sdp_oper,
2022                     bta_hl_cb.scb[4].app_idx,
2023                     bta_hl_cb.scb[4].mcl_idx,
2024                     bta_hl_cb.scb[4].mdl_idx,
2025                     status);
2026    bta_hl_deallocate_spd_cback(4);
2027}
2028
2029/******************************************************************************
2030**
2031** Function         bta_hl_sdp_cback5
2032**
2033** Description      This is the SDP callback function used by index = 5
2034**
2035** Parameters       status  - status of the SDP callabck
2036**
2037** Returns          void.
2038**
2039******************************************************************************/
2040static void bta_hl_sdp_cback5(UINT16 status)
2041{
2042    bta_hl_sdp_cback(bta_hl_cb.scb[5].sdp_oper,
2043                     bta_hl_cb.scb[5].app_idx,
2044                     bta_hl_cb.scb[5].mcl_idx,
2045                     bta_hl_cb.scb[5].mdl_idx,
2046                     status);
2047    bta_hl_deallocate_spd_cback(5);
2048}
2049
2050/******************************************************************************
2051**
2052** Function         bta_hl_sdp_cback6
2053**
2054** Description      This is the SDP callback function used by index = 6
2055**
2056** Returns          void.
2057**
2058******************************************************************************/
2059static void bta_hl_sdp_cback6(UINT16 status)
2060{
2061    bta_hl_sdp_cback(bta_hl_cb.scb[6].sdp_oper,
2062                     bta_hl_cb.scb[6].app_idx,
2063                     bta_hl_cb.scb[6].mcl_idx,
2064                     bta_hl_cb.scb[6].mdl_idx,
2065                     status);
2066    bta_hl_deallocate_spd_cback(6);
2067}
2068
2069
2070/*******************************************************************************
2071**
2072** Function      bta_hl_deallocate_spd_cback
2073**
2074** Description   Deallocate a SDP control block
2075**
2076** Returns      BOOLEAN - TRUE found
2077**                        FALSE not found
2078**
2079*******************************************************************************/
2080void bta_hl_deallocate_spd_cback(UINT8 sdp_cback_idx)
2081{
2082    tBTA_HL_SDP_CB *p_spd_cb = &bta_hl_cb.scb[sdp_cback_idx];
2083
2084    memset(p_spd_cb, 0, sizeof(tBTA_HL_SDP_CB));
2085
2086#if BTA_HL_DEBUG == TRUE
2087    APPL_TRACE_DEBUG("bta_hl_deallocate_spd_cback index=%d", sdp_cback_idx);
2088#endif
2089
2090
2091}
2092
2093/*******************************************************************************
2094**
2095** Function      bta_hl_allocate_spd_cback
2096**
2097** Description   Finds a not in used SDP control block index
2098**
2099**
2100** Returns      BOOLEAN - TRUE found
2101**                        FALSE not found
2102**
2103*******************************************************************************/
2104tSDP_DISC_CMPL_CB *bta_hl_allocate_spd_cback(tBTA_HL_SDP_OPER sdp_oper, UINT8 app_idx, UINT8 mcl_idx,
2105                                             UINT8 mdl_idx,
2106                                             UINT8 *p_sdp_cback_idx)
2107{
2108    UINT8 i;
2109    tSDP_DISC_CMPL_CB *p_cbcak=NULL;
2110
2111
2112    for (i=0; i < BTA_HL_NUM_SDP_CBACKS ; i ++)
2113    {
2114        if (!bta_hl_cb.scb[i].in_use)
2115        {
2116            p_cbcak = bta_hl_sdp_cback_arr[i];
2117            bta_hl_cb.scb[i].in_use = TRUE;
2118            bta_hl_cb.scb[i].sdp_oper = sdp_oper;
2119            bta_hl_cb.scb[i].app_idx = app_idx;
2120            bta_hl_cb.scb[i].mcl_idx = mcl_idx;
2121            bta_hl_cb.scb[i].mdl_idx = mdl_idx;
2122            *p_sdp_cback_idx = i;
2123            break;
2124        }
2125    }
2126
2127    if (i == BTA_HL_NUM_SDP_CBACKS)
2128    {
2129        APPL_TRACE_WARNING("No scb is available to allocate")
2130    }
2131    else
2132    {
2133#if BTA_HL_DEBUG == TRUE
2134    APPL_TRACE_DEBUG("bta_hl_allocate_spd_cback cback_idx=%d ",i );
2135    APPL_TRACE_DEBUG("sdp_oper=%d, app_idx=%d, mcl_idx=%d,  mdl_idx=%d",
2136                      bta_hl_cb.scb[i].sdp_oper,
2137                      bta_hl_cb.scb[i].app_idx,
2138                      bta_hl_cb.scb[i].mcl_idx,
2139                      bta_hl_cb.scb[i].mdl_idx );
2140#endif
2141    }
2142    return p_cbcak;
2143}
2144
2145
2146/*******************************************************************************
2147**
2148** Function         bta_hl_init_sdp
2149**
2150** Description      Action routine for processing the SDP initiattion request
2151**
2152** Returns          void
2153**
2154*******************************************************************************/
2155tBTA_HL_STATUS bta_hl_init_sdp(tBTA_HL_SDP_OPER sdp_oper, UINT8 app_idx, UINT8 mcl_idx,
2156                               UINT8 mdl_idx)
2157{
2158    tBTA_HL_MCL_CB      *p_cb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2159    tSDP_UUID           uuid_list;
2160    UINT16              attr_list[BTA_HL_NUM_SRCH_ATTR];
2161    UINT16              num_attrs = BTA_HL_NUM_SRCH_ATTR;
2162    tBTA_HL_STATUS      status;
2163    UINT8               sdp_cback_idx;
2164#if BTA_HL_DEBUG == TRUE
2165    APPL_TRACE_DEBUG("bta_hl_init_sdp sdp_oper=%d app_idx=%d mcl_idx=%d, mdl_idx=%d",
2166                      sdp_oper, app_idx, mcl_idx, mdl_idx);
2167#endif
2168    if ((p_cb->sdp_cback = bta_hl_allocate_spd_cback(sdp_oper, app_idx, mcl_idx, mdl_idx, &sdp_cback_idx)) != NULL)
2169    {
2170        if (p_cb->p_db == NULL)
2171            (p_cb->p_db = (tSDP_DISCOVERY_DB *)osi_malloc(BTA_HL_DISC_SIZE));
2172        attr_list[0] = ATTR_ID_SERVICE_CLASS_ID_LIST;
2173        attr_list[1] = ATTR_ID_PROTOCOL_DESC_LIST;
2174        attr_list[2] = ATTR_ID_BT_PROFILE_DESC_LIST;
2175        attr_list[3] = ATTR_ID_ADDITION_PROTO_DESC_LISTS;
2176        attr_list[4] = ATTR_ID_SERVICE_NAME;
2177        attr_list[5] = ATTR_ID_SERVICE_DESCRIPTION;
2178        attr_list[6] = ATTR_ID_PROVIDER_NAME;
2179        attr_list[7] = ATTR_ID_HDP_SUP_FEAT_LIST;
2180        attr_list[8] = ATTR_ID_HDP_DATA_EXCH_SPEC;
2181        attr_list[9] = ATTR_ID_HDP_MCAP_SUP_PROC;
2182
2183        uuid_list.len = LEN_UUID_16;
2184        uuid_list.uu.uuid16 = UUID_SERVCLASS_HDP_PROFILE;
2185        SDP_InitDiscoveryDb(p_cb->p_db, BTA_HL_DISC_SIZE, 1, &uuid_list, num_attrs, attr_list);
2186
2187        if (!SDP_ServiceSearchAttributeRequest(p_cb->bd_addr, p_cb->p_db, p_cb->sdp_cback))
2188        {
2189            status = BTA_HL_STATUS_FAIL;
2190        } else {
2191            status = BTA_HL_STATUS_OK;
2192        }
2193    } else {
2194        status = BTA_HL_STATUS_SDP_NO_RESOURCE;
2195    }
2196
2197    if (status != BTA_HL_STATUS_OK) {
2198        osi_free_and_reset((void **)&p_cb->p_db);
2199        if (status != BTA_HL_STATUS_SDP_NO_RESOURCE)
2200            bta_hl_deallocate_spd_cback(sdp_cback_idx);
2201    }
2202
2203    return status;
2204}
2205
2206/*******************************************************************************
2207**
2208** Function         bta_hl_cch_sdp_init
2209**
2210** Description      Action routine for processing the CCH SDP init event
2211**
2212** Returns          void
2213**
2214*******************************************************************************/
2215void bta_hl_cch_sdp_init(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2216{
2217    tBTA_HL_MCL_CB      *p_cb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2218#if BTA_HL_DEBUG == TRUE
2219    APPL_TRACE_DEBUG("bta_hl_cch_init_sdp");
2220#endif
2221    if ( p_cb->sdp_oper == BTA_HL_SDP_OP_NONE)
2222    {
2223        p_cb->app_id = p_data->api_cch_open.app_id;
2224        p_cb->sdp_oper = BTA_HL_SDP_OP_CCH_INIT;
2225
2226        if (bta_hl_init_sdp( p_cb->sdp_oper, app_idx, mcl_idx, 0xFF) != BTA_HL_STATUS_OK)
2227        {
2228            p_cb->sdp_oper = BTA_HL_SDP_OP_NONE;
2229            bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_SDP_FAIL_EVT, p_data);
2230        }
2231    }
2232    else
2233    {
2234        APPL_TRACE_ERROR("SDP in use");
2235        bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_SDP_FAIL_EVT, p_data);
2236    }
2237}
2238
2239/*******************************************************************************
2240**
2241** Function         bta_hl_cch_mca_open
2242**
2243** Description      Action routine for processing the CCH open request
2244**
2245** Returns          void
2246**
2247*******************************************************************************/
2248void bta_hl_cch_mca_open(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2249{
2250    tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
2251    tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2252    UINT8               sdp_idx;
2253
2254#if BTA_HL_DEBUG == TRUE
2255    APPL_TRACE_DEBUG("bta_hl_cch_mca_open");
2256#endif
2257
2258    if (bta_hl_find_sdp_idx_using_ctrl_psm(&p_mcb->sdp, p_mcb->req_ctrl_psm, &sdp_idx))
2259    {
2260        p_mcb->ctrl_psm = p_mcb->sdp.sdp_rec[sdp_idx].ctrl_psm;
2261        p_mcb->data_psm = p_mcb->sdp.sdp_rec[sdp_idx].data_psm;
2262        if ( MCA_ConnectReq((tMCA_HANDLE) p_acb->app_handle,
2263                            p_mcb->bd_addr,
2264                            p_mcb->ctrl_psm ,
2265                            p_mcb->sec_mask) != MCA_SUCCESS)
2266        {
2267
2268            bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data);
2269        }
2270    }
2271    else
2272    {
2273        bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data);
2274    }
2275}
2276
2277/*******************************************************************************
2278**
2279** Function         bta_hl_cch_mca_close
2280**
2281** Description      Action routine for processing the CCH close request
2282**
2283** Returns          void
2284**
2285*******************************************************************************/
2286void bta_hl_cch_mca_close(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2287{
2288    tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2289
2290#if BTA_HL_DEBUG == TRUE
2291    APPL_TRACE_DEBUG("bta_hl_cch_mca_close mcl_handle=%d", p_mcb->mcl_handle);
2292#endif
2293    if (p_mcb->sdp_oper != BTA_HL_SDP_OP_CCH_INIT)
2294    {
2295        if(p_mcb->mcl_handle)
2296        {
2297            if ( MCA_DisconnectReq((tMCA_HANDLE) p_mcb->mcl_handle) != MCA_SUCCESS)
2298            {
2299                bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data);
2300            }
2301        }
2302        else
2303        {
2304            p_mcb->close_pending = TRUE;
2305            APPL_TRACE_DEBUG("No valid mcl_handle to stop the CCH setup now so wait until CCH is up then close it" );
2306        }
2307    }
2308    else
2309    {
2310        p_mcb->close_pending = TRUE;
2311        APPL_TRACE_DEBUG("can not stop the CCH setup becasue SDP is in progress so wait until it is done" );
2312    }
2313}
2314
2315/*******************************************************************************
2316**
2317** Function         bta_hl_cch_close_cmpl
2318**
2319** Description      Action routine for processing the CCH close complete event
2320**
2321** Returns          void
2322**
2323*******************************************************************************/
2324void bta_hl_cch_close_cmpl(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2325{
2326    tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
2327    tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2328
2329    tBTA_HL             evt_data;
2330    tBTA_HL_EVT         event;
2331    BOOLEAN             send_evt=TRUE;
2332#if BTA_HL_DEBUG == TRUE
2333    APPL_TRACE_DEBUG("bta_hl_cch_close_cmpl");
2334#endif
2335    bta_sys_conn_close(BTA_ID_HL, p_acb->app_id, p_mcb->bd_addr);
2336
2337    if (p_mcb->cch_oper == BTA_HL_CCH_OP_LOCAL_CLOSE && p_mcb->force_close_local_cch_opening)
2338    {
2339       p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_OPEN;
2340       APPL_TRACE_DEBUG("change cch_oper from BTA_HL_CCH_OP_LOCAL_CLOSE to BTA_HL_CCH_OP_LOCAL_OPEN");
2341    }
2342
2343    switch (p_mcb->cch_oper)
2344    {
2345        case BTA_HL_CCH_OP_LOCAL_OPEN:
2346            bta_hl_build_cch_open_cfm(&evt_data,p_mcb->app_id,p_acb->app_handle,
2347                                      p_mcb->mcl_handle,
2348                                      p_mcb->bd_addr,
2349                                      BTA_HL_STATUS_FAIL);
2350            event = BTA_HL_CCH_OPEN_CFM_EVT;
2351            break;
2352        case BTA_HL_CCH_OP_LOCAL_CLOSE:
2353            bta_hl_build_cch_close_cfm(&evt_data,  p_acb->app_handle,
2354                                       p_mcb->mcl_handle,
2355                                       BTA_HL_STATUS_OK);
2356            event = BTA_HL_CCH_CLOSE_CFM_EVT;
2357            break;
2358        case BTA_HL_CCH_OP_REMOTE_CLOSE:
2359            bta_hl_build_cch_close_ind(&evt_data,
2360                                       p_acb->app_handle,
2361                                       p_mcb->mcl_handle,
2362                                       p_mcb->intentional_close);
2363            event = BTA_HL_CCH_CLOSE_IND_EVT;
2364            break;
2365        default:
2366            send_evt=FALSE;
2367            break;
2368    }
2369
2370
2371    memset(p_mcb, 0 ,sizeof(tBTA_HL_MCL_CB));
2372
2373    if (send_evt)p_acb->p_cback(event,(tBTA_HL *) &evt_data );
2374
2375    bta_hl_check_deregistration(app_idx, p_data);
2376}
2377
2378/*******************************************************************************
2379**
2380** Function         bta_hl_cch_mca_disconnect
2381**
2382** Description      Action routine for processing the CCH disconnect indication
2383**
2384** Returns          void
2385**
2386*******************************************************************************/
2387void bta_hl_cch_mca_disconnect(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2388{
2389
2390    tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2391    tBTA_HL_MDL_CB      *p_dcb;
2392    UINT8              i;
2393#if BTA_HL_DEBUG == TRUE
2394    APPL_TRACE_DEBUG("bta_hl_cch_mca_disconnect");
2395#endif
2396
2397    p_mcb->intentional_close = FALSE;
2398    if (p_data->mca_evt.mca_data.disconnect_ind.reason == L2CAP_DISC_OK)
2399    {
2400        p_mcb->intentional_close = TRUE;
2401    }
2402
2403    for (i=0; i< BTA_HL_NUM_MDLS_PER_MCL; i++)
2404    {
2405        p_dcb= BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, i);
2406        if (p_dcb->in_use && (p_dcb->dch_state != BTA_HL_DCH_IDLE_ST))
2407        {
2408            if (p_mcb->cch_oper == BTA_HL_CCH_OP_LOCAL_CLOSE )
2409            {
2410                bta_hl_dch_sm_execute(app_idx, mcl_idx, i, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
2411            }
2412            else
2413            {
2414                bta_hl_dch_sm_execute(app_idx, mcl_idx, i, BTA_HL_MCA_CLOSE_IND_EVT, p_data);
2415            }
2416        }
2417    }
2418    bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data);
2419}
2420
2421/*******************************************************************************
2422**
2423** Function         bta_hl_cch_mca_disc_open
2424**
2425** Description      Action routine for disconnect the just opened Control channel
2426**
2427** Returns          void
2428**
2429*******************************************************************************/
2430void bta_hl_cch_mca_disc_open(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2431{
2432    tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2433
2434#if BTA_HL_DEBUG == TRUE
2435    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 );
2436#endif
2437
2438    p_mcb->close_pending = FALSE;
2439    p_mcb->mcl_handle = p_data->mca_evt.mcl_handle;
2440    bta_hl_cch_mca_close(app_idx, mcl_idx, p_data);
2441}
2442
2443/*******************************************************************************
2444**
2445** Function         bta_hl_cch_mca_rsp_tout
2446**
2447** Description      Action routine for processing the MCAP response timeout
2448**
2449** Returns          void
2450**
2451*******************************************************************************/
2452void bta_hl_cch_mca_rsp_tout(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2453{
2454
2455    tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2456#if BTA_HL_DEBUG == TRUE
2457    APPL_TRACE_DEBUG("bta_hl_cch_mca_rsp_tout");
2458#endif
2459
2460    p_mcb->rsp_tout = TRUE;
2461
2462    bta_hl_check_cch_close(app_idx,mcl_idx,p_data,TRUE);
2463}
2464
2465/*******************************************************************************
2466**
2467** Function         bta_hl_cch_mca_connect
2468**
2469** Description      Action routine for processing the CCH connect indication
2470**
2471** Returns          void
2472**
2473*******************************************************************************/
2474void bta_hl_cch_mca_connect(UINT8 app_idx, UINT8 mcl_idx,  tBTA_HL_DATA *p_data)
2475{
2476    tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
2477    tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2478    tBTA_HL             evt_data;
2479    tBTA_HL_EVT         event;
2480    BOOLEAN             send_event=TRUE;
2481
2482#if BTA_HL_DEBUG == TRUE
2483    APPL_TRACE_DEBUG("bta_hl_cch_mca_connect mcl_handle=%d ", p_data->mca_evt.mcl_handle);
2484#endif
2485
2486    p_mcb->mcl_handle = p_data->mca_evt.mcl_handle;
2487    bdcpy(p_mcb->bd_addr, p_data->mca_evt.mca_data.connect_ind.bd_addr);
2488    p_mcb->cch_mtu = p_data->mca_evt.mca_data.connect_ind.mtu;
2489
2490    bta_sys_conn_open(BTA_ID_HL, p_acb->app_id, p_mcb->bd_addr);
2491    switch (p_mcb->cch_oper)
2492    {
2493        case BTA_HL_CCH_OP_LOCAL_OPEN:
2494            bta_hl_build_cch_open_cfm(&evt_data, p_mcb->app_id,p_acb->app_handle,
2495                                      p_mcb->mcl_handle,
2496                                      p_mcb->bd_addr,
2497                                      BTA_HL_STATUS_OK);
2498            event = BTA_HL_CCH_OPEN_CFM_EVT;
2499            break;
2500        case BTA_HL_CCH_OP_REMOTE_OPEN:
2501            bta_hl_build_cch_open_ind(&evt_data, p_acb->app_handle,
2502                                      p_mcb->mcl_handle,
2503                                      p_mcb->bd_addr);
2504            event = BTA_HL_CCH_OPEN_IND_EVT;
2505            break;
2506        default:
2507            send_event = FALSE;
2508            break;
2509    }
2510
2511    p_mcb->cch_oper = BTA_HL_CCH_OP_NONE;
2512    if (send_event) p_acb->p_cback(event,(tBTA_HL *) &evt_data );
2513}
2514
2515/*******************************************************************************
2516**
2517** Function         bta_hl_mcap_ctrl_cback
2518**
2519** Description      MCAP control callback function for HL.
2520**
2521** Returns          void
2522**
2523*******************************************************************************/
2524void bta_hl_mcap_ctrl_cback (tMCA_HANDLE handle, tMCA_CL mcl, UINT8 event,
2525                             tMCA_CTRL *p_data)
2526{
2527    BOOLEAN send_event=TRUE;
2528    UINT16 mca_event;
2529
2530#if (BTA_HL_DEBUG == TRUE)
2531#if (BT_TRACE_VERBOSE == TRUE)
2532    APPL_TRACE_EVENT("bta_hl_mcap_ctrl_cback event[%s]",bta_hl_mcap_evt_code(event));
2533#else
2534    APPL_TRACE_EVENT("bta_hl_mcap_ctrl_cback event[0x%02x]", event);
2535#endif
2536#endif
2537
2538    switch (event)
2539    {
2540
2541        case MCA_CREATE_IND_EVT:
2542            mca_event = (UINT16) BTA_HL_MCA_CREATE_IND_EVT;
2543            break;
2544        case MCA_CREATE_CFM_EVT:
2545            mca_event = (UINT16) BTA_HL_MCA_CREATE_CFM_EVT;
2546            break;
2547        case MCA_RECONNECT_IND_EVT:
2548            mca_event = (UINT16) BTA_HL_MCA_RECONNECT_IND_EVT;
2549            break;
2550        case MCA_RECONNECT_CFM_EVT:
2551            mca_event = (UINT16) BTA_HL_MCA_RECONNECT_CFM_EVT;
2552            break;
2553        case MCA_ABORT_IND_EVT:
2554            mca_event = (UINT16) BTA_HL_MCA_ABORT_IND_EVT;
2555            break;
2556        case MCA_ABORT_CFM_EVT:
2557            mca_event = (UINT16) BTA_HL_MCA_ABORT_CFM_EVT;
2558            break;
2559        case MCA_DELETE_IND_EVT:
2560            mca_event = (UINT16) BTA_HL_MCA_DELETE_IND_EVT;
2561            break;
2562        case MCA_DELETE_CFM_EVT:
2563            mca_event = (UINT16) BTA_HL_MCA_DELETE_CFM_EVT;
2564            break;
2565        case MCA_CONNECT_IND_EVT:
2566            mca_event = (UINT16) BTA_HL_MCA_CONNECT_IND_EVT;
2567            break;
2568        case MCA_DISCONNECT_IND_EVT:
2569            mca_event = (UINT16) BTA_HL_MCA_DISCONNECT_IND_EVT;
2570            break;
2571        case MCA_OPEN_IND_EVT:
2572            mca_event = (UINT16) BTA_HL_MCA_OPEN_IND_EVT;
2573            break;
2574        case MCA_OPEN_CFM_EVT:
2575            mca_event = (UINT16) BTA_HL_MCA_OPEN_CFM_EVT;
2576            break;
2577        case MCA_CLOSE_IND_EVT:
2578            mca_event = (UINT16) BTA_HL_MCA_CLOSE_IND_EVT;
2579            break;
2580        case MCA_CLOSE_CFM_EVT:
2581            mca_event = (UINT16) BTA_HL_MCA_CLOSE_CFM_EVT;
2582            break;
2583        case MCA_CONG_CHG_EVT:
2584            mca_event = (UINT16) BTA_HL_MCA_CONG_CHG_EVT;
2585            break;
2586        case MCA_RSP_TOUT_IND_EVT:
2587            mca_event = (UINT16) BTA_HL_MCA_RSP_TOUT_IND_EVT;
2588            break;
2589        case MCA_ERROR_RSP_EVT:
2590
2591        default:
2592            send_event=FALSE;
2593            break;
2594    }
2595
2596    if (send_event) {
2597        tBTA_HL_MCA_EVT * p_msg =
2598            (tBTA_HL_MCA_EVT *)osi_malloc(sizeof(tBTA_HL_MCA_EVT));
2599        p_msg->hdr.event = mca_event;
2600        p_msg->app_handle = (tBTA_HL_APP_HANDLE) handle;
2601        p_msg->mcl_handle = (tBTA_HL_MCL_HANDLE) mcl;
2602        memcpy(&p_msg->mca_data, p_data, sizeof(tMCA_CTRL));
2603        bta_sys_sendmsg(p_msg);
2604    }
2605}
2606
2607/*******************************************************************************
2608**
2609** Function         bta_hl_mcap_data_cback
2610**
2611** Description      MCAP data callback function for HL.
2612**
2613** Returns          void
2614**
2615*******************************************************************************/
2616void bta_hl_mcap_data_cback (tMCA_DL mdl, BT_HDR *p_pkt)
2617{
2618    UINT8 app_idx, mcl_idx, mdl_idx;
2619    if (bta_hl_find_mdl_idx_using_handle ((tBTA_HL_MDL_HANDLE)mdl, &app_idx, &mcl_idx, &mdl_idx))
2620    {
2621        tBTA_HL_MCA_RCV_DATA_EVT *p_msg =
2622            (tBTA_HL_MCA_RCV_DATA_EVT *)osi_malloc(sizeof(tBTA_HL_MCA_RCV_DATA_EVT));
2623        p_msg->hdr.event = BTA_HL_MCA_RCV_DATA_EVT;
2624        p_msg->app_idx = app_idx;
2625        p_msg->mcl_idx = mcl_idx;
2626        p_msg->mdl_idx = mdl_idx;
2627        p_msg->p_pkt = p_pkt;
2628        bta_sys_sendmsg(p_msg);
2629    }
2630}
2631
2632/*****************************************************************************
2633**  Debug Functions
2634*****************************************************************************/
2635#if (BTA_HL_DEBUG == TRUE && BT_TRACE_VERBOSE == TRUE)
2636
2637/*******************************************************************************
2638**
2639** Function         bta_hl_mcap_evt_code
2640**
2641** Description      get the MCAP event string pointer
2642**
2643** Returns          char * - event string pointer
2644**
2645*******************************************************************************/
2646static char *bta_hl_mcap_evt_code(UINT8 evt_code)
2647{
2648
2649    switch (evt_code)
2650    {
2651
2652        case MCA_ERROR_RSP_EVT:
2653            return "MCA_ERROR_RSP_EVT";
2654        case MCA_CREATE_IND_EVT:
2655            return "MCA_CREATE_IND_EVT";
2656        case MCA_CREATE_CFM_EVT:
2657            return "MCA_CREATE_CFM_EVT";
2658        case MCA_RECONNECT_IND_EVT:
2659            return "MCA_RECONNECT_IND_EVT";
2660        case MCA_RECONNECT_CFM_EVT:
2661            return "MCA_RECONNECT_CFM_EVT";
2662        case MCA_ABORT_IND_EVT:
2663            return "MCA_ABORT_IND_EVT";
2664        case MCA_ABORT_CFM_EVT:
2665            return "MCA_ABORT_CFM_EVT";
2666        case MCA_DELETE_IND_EVT:
2667            return "MCA_DELETE_IND_EVT";
2668        case MCA_DELETE_CFM_EVT:
2669            return "MCA_DELETE_CFM_EVT";
2670
2671        case MCA_CONNECT_IND_EVT:
2672            return "MCA_CONNECT_IND_EVT";
2673        case MCA_DISCONNECT_IND_EVT:
2674            return "MCA_DISCONNECT_IND_EVT";
2675        case MCA_OPEN_IND_EVT:
2676            return "MCA_OPEN_IND_EVT";
2677        case MCA_OPEN_CFM_EVT:
2678            return "MCA_OPEN_CFM_EVT";
2679        case MCA_CLOSE_IND_EVT:
2680            return "MCA_CLOSE_IND_EVT";
2681        case MCA_CLOSE_CFM_EVT:
2682            return "MCA_CLOSE_CFM_EVT";
2683        case MCA_CONG_CHG_EVT:
2684            return "MCA_CONG_CHG_EVT";
2685        case MCA_RSP_TOUT_IND_EVT:
2686            return "MCA_RSP_TOUT_IND_EVT";
2687        default:
2688            return "Unknown MCAP event code";
2689    }
2690}
2691
2692
2693/*******************************************************************************
2694**
2695** Function         bta_hl_cback_evt_code
2696**
2697** Description      get the HDP event string pointer
2698**
2699** Returns          char * - event string pointer
2700**
2701*******************************************************************************/
2702static char *bta_hl_cback_evt_code(UINT8 evt_code)
2703{
2704
2705    switch (evt_code)
2706    {
2707
2708        case BTA_HL_CCH_OPEN_IND_EVT:
2709            return "BTA_HL_CCH_OPEN_IND_EVT";
2710        case BTA_HL_CCH_OPEN_CFM_EVT:
2711            return "BTA_HL_CCH_OPEN_CFM_EVT";
2712        case BTA_HL_CCH_CLOSE_IND_EVT:
2713            return "BTA_HL_CCH_CLOSE_IND_EVT";
2714        case     BTA_HL_CCH_CLOSE_CFM_EVT:
2715            return "BTA_HL_CCH_CLOSE_CFM_EVT";
2716        case BTA_HL_DCH_OPEN_IND_EVT:
2717            return "BTA_HL_DCH_OPEN_IND_EVT";
2718        case BTA_HL_DCH_OPEN_CFM_EVT:
2719            return "BTA_HL_DCH_OPEN_CFM_EVT";
2720        case BTA_HL_DCH_CLOSE_IND_EVT:
2721            return "BTA_HL_DCH_CLOSE_IND_EVT";
2722        case BTA_HL_DCH_CLOSE_CFM_EVT:
2723            return "BTA_HL_DCH_CLOSE_CFM_EVT";
2724        case BTA_HL_DCH_RCV_DATA_IND_EVT:
2725            return "BTA_HL_DCH_RCV_DATA_IND_EVT";
2726        case BTA_HL_REGISTER_CFM_EVT:
2727            return "BTA_HL_REGISTER_CFM_EVT";
2728        case BTA_HL_DEREGISTER_CFM_EVT:
2729            return "BTA_HL_DEREGISTER_CFM_EVT";
2730        case BTA_HL_DCH_RECONNECT_CFM_EVT:
2731            return "BTA_HL_DCH_RECONNECT_CFM_EVT";
2732        case BTA_HL_DCH_RECONNECT_IND_EVT:
2733            return "BTA_HL_DCH_RECONNECT_IND_EVT";
2734        case BTA_HL_DCH_ECHO_TEST_CFM_EVT:
2735            return "BTA_HL_DCH_ECHO_TEST_CFM_EVT";
2736        case BTA_HL_SDP_QUERY_CFM_EVT:
2737            return "BTA_HL_SDP_QUERY_CFM_EVT";
2738        case BTA_HL_CONG_CHG_IND_EVT:
2739            return "BTA_HL_CONG_CHG_IND_EVT";
2740        case BTA_HL_DCH_CREATE_IND_EVT:
2741            return "BTA_HL_DCH_CREATE_IND_EVT";
2742        case BTA_HL_DELETE_MDL_IND_EVT:
2743            return "BTA_HL_DELETE_MDL_IND_EVT";
2744        case BTA_HL_DELETE_MDL_CFM_EVT:
2745            return "BTA_HL_DELETE_MDL_CFM_EVT";
2746        case BTA_HL_DCH_ABORT_IND_EVT:
2747            return "BTA_HL_DCH_ABORT_IND_EVT";
2748        case BTA_HL_DCH_ABORT_CFM_EVT:
2749            return "BTA_HL_DCH_ABORT_CFM_EVT";
2750        default:
2751            return "Unknown HDP event code";
2752    }
2753}
2754
2755
2756
2757/*******************************************************************************
2758**
2759** Function         bta_hl_dch_oper_code
2760**
2761** Description      Get the DCH operation string
2762**
2763** Returns          char * - DCH operation string pointer
2764**
2765*******************************************************************************/
2766static char *bta_hl_dch_oper_code(tBTA_HL_DCH_OPER oper_code)
2767{
2768
2769    switch (oper_code)
2770    {
2771        case BTA_HL_DCH_OP_NONE:
2772            return "BTA_HL_DCH_OP_NONE";
2773        case BTA_HL_DCH_OP_REMOTE_CREATE:
2774            return "BTA_HL_DCH_OP_REMOTE_CREATE";
2775        case BTA_HL_DCH_OP_LOCAL_OPEN:
2776            return "BTA_HL_DCH_OP_LOCAL_OPEN";
2777        case BTA_HL_DCH_OP_REMOTE_OPEN:
2778            return "BTA_HL_DCH_OP_REMOTE_OPEN";
2779        case BTA_HL_DCH_OP_LOCAL_CLOSE:
2780            return "BTA_HL_DCH_OP_LOCAL_CLOSE";
2781        case BTA_HL_DCH_OP_REMOTE_CLOSE:
2782            return "BTA_HL_DCH_OP_REMOTE_CLOSE";
2783        case BTA_HL_DCH_OP_LOCAL_DELETE:
2784            return "BTA_HL_DCH_OP_LOCAL_DELETE";
2785        case BTA_HL_DCH_OP_REMOTE_DELETE:
2786            return "BTA_HL_DCH_OP_REMOTE_DELETE";
2787        case BTA_HL_DCH_OP_LOCAL_RECONNECT:
2788            return "BTA_HL_DCH_OP_LOCAL_RECONNECT";
2789        case BTA_HL_DCH_OP_REMOTE_RECONNECT:
2790            return "BTA_HL_DCH_OP_REMOTE_RECONNECT";
2791        case BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST:
2792            return "BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST";
2793        case BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT:
2794            return "BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT";
2795        default:
2796            return "Unknown DCH oper code";
2797    }
2798}
2799
2800
2801#endif  /* Debug Functions */
2802#endif /* HL_INCLUDED */
2803