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