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