diff options
author | Andre Eisenbach <andre@broadcom.com> | 2012-02-22 13:18:21 -0800 |
---|---|---|
committer | Matthew Xie <mattx@google.com> | 2012-07-14 11:19:11 -0700 |
commit | e448862a47c08eb23185aaed574b39264f5005fc (patch) | |
tree | 2bc6246e3091315e77224fd798ea2fe8074ef972 /bta/hl | |
parent | a2ca4b83ab8bbbfd8d5f6693e927ed4b82094624 (diff) | |
download | external_bluetooth_bluedroid-e448862a47c08eb23185aaed574b39264f5005fc.zip external_bluetooth_bluedroid-e448862a47c08eb23185aaed574b39264f5005fc.tar.gz external_bluetooth_bluedroid-e448862a47c08eb23185aaed574b39264f5005fc.tar.bz2 |
Initial Bluedroid stack commit
Diffstat (limited to 'bta/hl')
-rw-r--r-- | bta/hl/bta_hl_act.c | 2794 | ||||
-rw-r--r-- | bta/hl/bta_hl_api.c | 472 | ||||
-rw-r--r-- | bta/hl/bta_hl_ci.c | 158 | ||||
-rw-r--r-- | bta/hl/bta_hl_int.h | 845 | ||||
-rw-r--r-- | bta/hl/bta_hl_main.c | 1907 | ||||
-rw-r--r-- | bta/hl/bta_hl_sdp.c | 429 | ||||
-rw-r--r-- | bta/hl/bta_hl_utils.c | 3324 |
7 files changed, 9929 insertions, 0 deletions
diff --git a/bta/hl/bta_hl_act.c b/bta/hl/bta_hl_act.c new file mode 100644 index 0000000..cc14721 --- /dev/null +++ b/bta/hl/bta_hl_act.c @@ -0,0 +1,2794 @@ +/***************************************************************************** +** +** Name: bta_hl_act.c +** +** Description: This file contains the HeaLth device profile (HL) action +** functions for the state machine. +** +** Copyright (c) 2003-2011, Broadcom Corp., All Rights Reserved. +** Broadcom Bluetooth Core. Proprietary and confidential. +** +*****************************************************************************/ + +#include <string.h> + +#include "bt_target.h" +#if defined(HL_INCLUDED) && (HL_INCLUDED == TRUE) + +#include "gki.h" +#include "sdp_api.h" +#include "bta_sys.h" +#include "port_api.h" +#include "sdp_api.h" +#include "bta_hl_api.h" +#include "bta_hl_int.h" +#include "utl.h" +#include "bd.h" +#include "mca_defs.h" +#include "mca_api.h" + +/***************************************************************************** +** Local Function prototypes +*****************************************************************************/ +#if (BTA_HL_DEBUG == TRUE && BT_TRACE_VERBOSE == TRUE) +static char *bta_hl_mcap_evt_code(UINT8 evt_code); +static char *bta_hl_dch_oper_code(tBTA_HL_DCH_OPER oper_code); +static char *bta_hl_cback_evt_code(UINT8 evt_code); +#endif +static void bta_hl_sdp_cback(UINT8 sdp_op, UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdl_idx, UINT16 status); +static void bta_hl_sdp_cback0(UINT16 status); +static void bta_hl_sdp_cback1(UINT16 status); +static void bta_hl_sdp_cback2(UINT16 status); +static void bta_hl_sdp_cback3(UINT16 status); +static void bta_hl_sdp_cback4(UINT16 status); +static void bta_hl_sdp_cback5(UINT16 status); +static void bta_hl_sdp_cback6(UINT16 status); + + +static tSDP_DISC_CMPL_CB * const bta_hl_sdp_cback_arr[] = { + bta_hl_sdp_cback0, + bta_hl_sdp_cback1, + bta_hl_sdp_cback2, + bta_hl_sdp_cback3, + bta_hl_sdp_cback4, + bta_hl_sdp_cback5, + bta_hl_sdp_cback6 +}; + + + +/******************************************************************************* +** +** Function bta_hl_dch_mca_cong_change +** +** Description Action routine for processing congestion change notification +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_cong_change(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tMCA_CONG_CHG *p_cong_chg = &p_data->mca_evt.mca_data.cong_chg; + tBTA_HL evt_data; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG2("bta_hl_dch_mca_cong_change mdl_id=%d cong=%d", + p_cong_chg->mdl_id, + p_cong_chg->cong); +#endif + evt_data.dch_cong_ind.cong = + p_dcb->cong = p_cong_chg->cong; + evt_data.dch_cong_ind.mdl_handle = p_dcb->mdl_handle; + evt_data.dch_cong_ind.mcl_handle = p_mcb->mcl_handle; + evt_data.dch_cong_ind.app_handle = p_acb->app_handle; + + p_acb->p_cback(BTA_HL_CONG_CHG_IND_EVT ,(tBTA_HL *) &evt_data ); +} + + + +/******************************************************************************* +** +** Function bta_hl_dch_echo_test +** +** Description Action routine for processing echo test request +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_echo_test(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_echo_test"); +#endif + + p_dcb->echo_oper = BTA_HL_ECHO_OP_CI_GET_ECHO_DATA; + p_dcb->cout_oper |= BTA_HL_CO_GET_ECHO_DATA_MASK; + + bta_hl_co_get_echo_data(p_acb->app_id, p_mcb->mcl_handle, + p_dcb->p_echo_tx_pkt->len, + BTA_HL_GET_BUF_PTR(p_dcb->p_echo_tx_pkt), + BTA_HL_CI_GET_ECHO_DATA_EVT); + +} +/******************************************************************************* +** +** Function bta_hl_dch_sdp_init +** +** Description Action routine for processing DCH SDP initiation +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_sdp_init(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_sdp_init"); +#endif + if ( p_mcb->sdp_oper == BTA_HL_SDP_OP_NONE) + { + p_mcb->sdp_mdl_idx = mdl_idx; + if (p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_OPEN ) + { + p_mcb->sdp_oper = BTA_HL_SDP_OP_DCH_OPEN_INIT; + + } + else + { + p_mcb->sdp_oper = BTA_HL_SDP_OP_DCH_RECONNECT_INIT; + } + + if (bta_hl_init_sdp(p_mcb->sdp_oper, app_idx, mcl_idx, mdl_idx) != BTA_HL_STATUS_OK) + { + APPL_TRACE_ERROR0("SDP INIT failed"); + p_mcb->sdp_oper = BTA_HL_SDP_OP_NONE; + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_SDP_FAIL_EVT, p_data); + } + } + else + { + APPL_TRACE_ERROR0("SDP in use"); + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_SDP_FAIL_EVT, p_data); + } +} + + +/******************************************************************************* +** +** Function bta_hl_dch_close_echo_test +** +** Description Action routine for processing the closing of echo test +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_close_echo_test(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_close_echo_test"); +#endif + + switch (p_dcb->echo_oper) + { + case BTA_HL_ECHO_OP_DCH_CLOSE_CFM: + case BTA_HL_ECHO_OP_OPEN_IND: + case BTA_HL_ECHO_OP_ECHO_PKT: + p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST; + break; + case BTA_HL_ECHO_OP_MDL_CREATE_CFM: + case BTA_HL_ECHO_OP_DCH_OPEN_CFM: + case BTA_HL_ECHO_OP_LOOP_BACK: + default: + break; + } + + if (MCA_CloseReq((tMCA_DL) p_dcb->mdl_handle)!= MCA_SUCCESS) + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } +} + + +/******************************************************************************* +** +** Function bta_hl_dch_mca_rcv_data +** +** Description Action routine for processing the received data +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_rcv_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_mca_rcv_data"); +#endif + + if (p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID) + { + switch ( p_dcb->echo_oper) + { + case BTA_HL_ECHO_OP_ECHO_PKT: + + if (MCA_WriteReq((tMCA_DL) p_dcb->mdl_handle, p_data->mca_rcv_data_evt.p_pkt) != MCA_SUCCESS) + { + utl_freebuf((void **) &p_data->mca_rcv_data_evt.p_pkt); + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_ECHO_TEST_EVT, p_data); + } + break; + case BTA_HL_ECHO_OP_LOOP_BACK: + + p_dcb->p_echo_rx_pkt = p_data->mca_rcv_data_evt.p_pkt; + p_dcb->echo_oper = BTA_HL_ECHO_OP_CI_PUT_ECHO_DATA; + p_dcb->cout_oper |= BTA_HL_CO_PUT_ECHO_DATA_MASK; + p_dcb->ci_put_echo_data_status = BTA_HL_STATUS_FAIL; + + bta_hl_co_put_echo_data(p_acb->app_id, p_mcb->mcl_handle, + p_dcb->p_echo_rx_pkt->len, + BTA_HL_GET_BUF_PTR(p_dcb->p_echo_rx_pkt), + BTA_HL_CI_PUT_ECHO_DATA_EVT); + break; + default: + APPL_TRACE_ERROR1("Unknonw echo_oper=%d",p_dcb->echo_oper); + break; + } + + } + else + { + p_dcb->cout_oper |= BTA_HL_CO_PUT_RX_DATA_MASK; + p_dcb->p_rx_pkt = p_data->mca_rcv_data_evt.p_pkt; + + bta_hl_co_put_rx_data(p_acb->app_id, p_dcb->mdl_handle, + p_dcb->p_rx_pkt->len, + BTA_HL_GET_BUF_PTR(p_dcb->p_rx_pkt), + BTA_HL_CI_PUT_RX_DATA_EVT); + + + } +} + + +/******************************************************************************* +** +** Function bta_hl_dch_ci_put_echo_data +** +** Description Action routine for processing the call-in of the +** put echo data event +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_ci_put_echo_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_ci_put_echo_data"); +#endif + + p_dcb->cout_oper &= ~BTA_HL_CO_PUT_ECHO_DATA_MASK; + utl_freebuf((void **) &p_dcb->p_echo_rx_pkt); + p_dcb->ci_put_echo_data_status = p_data->ci_get_put_echo_data.status; + + p_dcb->echo_oper = BTA_HL_ECHO_OP_DCH_CLOSE_CFM; + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_ECHO_TEST_EVT, p_data); +} + + + +/******************************************************************************* +** +** Function bta_hl_dch_ci_get_echo_data +** +** Description Action routine for processing the call-in of the +** get echo data event +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_ci_get_echo_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tBTA_HL_STATUS status; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_ci_get_echo_data"); +#endif + + p_dcb->cout_oper &= ~BTA_HL_CO_GET_ECHO_DATA_MASK; + + if (!p_dcb->abort_oper) + { + status = p_data->ci_get_put_echo_data.status; + if (status == BTA_HL_STATUS_OK) + { + p_dcb->echo_oper = BTA_HL_ECHO_OP_MDL_CREATE_CFM; + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_OPEN_EVT, p_data); + } + else + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + } + else + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + +} + +/******************************************************************************* +** +** Function bta_hl_dch_ci_put_rx_data +** +** Description Action routine for processing the call-in of the +** put rx data event +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_ci_put_rx_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tBTA_HL evt_data; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_ci_put_rx_data"); +#endif + + p_dcb->cout_oper &= ~BTA_HL_CO_PUT_RX_DATA_MASK; + utl_freebuf((void **) &p_dcb->p_rx_pkt); + bta_hl_build_rcv_data_ind(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + p_dcb->mdl_handle); + p_acb->p_cback(BTA_HL_DCH_RCV_DATA_IND_EVT,(tBTA_HL *) &evt_data ); + if (p_dcb->close_pending) + { + if (!p_dcb->cout_oper) + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_EVT, p_data); + } + + } +} + + + +/******************************************************************************* +** +** Function bta_hl_dch_ci_get_tx_data +** +** Description Action routine for processing the call-in of the +** get tx data event +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_ci_get_tx_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tMCA_RESULT result; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + BOOLEAN free_buf = FALSE; + BOOLEAN close_dch = FALSE; + tBTA_HL evt_data; + + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_ci_get_tx_data"); +#endif + + p_dcb->cout_oper &= ~BTA_HL_CO_GET_TX_DATA_MASK; + + if (p_dcb->close_pending) + { + status = BTA_HL_STATUS_FAIL; + free_buf = TRUE; + + if (!p_dcb->cout_oper) + { + close_dch = TRUE; + } + } + else + { + if ((result = MCA_WriteReq((tMCA_DL) p_dcb->mdl_handle, p_dcb->p_tx_pkt)) != MCA_SUCCESS) + { + if (result == MCA_BUSY) + { + status = BTA_HL_STATUS_DCH_BUSY; + } + else + { + status = BTA_HL_STATUS_FAIL; + } + free_buf = TRUE; + } + else + { + p_dcb->p_tx_pkt = NULL; + } + } + + if (free_buf) + { + utl_freebuf((void **) &p_dcb->p_tx_pkt); + } + + bta_hl_build_send_data_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + p_dcb->mdl_handle, + status); + p_acb->p_cback(BTA_HL_DCH_SEND_DATA_CFM_EVT,(tBTA_HL *) &evt_data ); + + if (close_dch) + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_EVT, p_data); + } +} + + +/******************************************************************************* +** +** Function bta_hl_dch_send_data +** +** Description Action routine for processing api send data request +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_send_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tBTA_HL evt_data; + BOOLEAN success = TRUE; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_send_data"); +#endif + + if (!(p_dcb->cout_oper & BTA_HL_CO_GET_TX_DATA_MASK)) + { + if ((p_dcb->p_tx_pkt = bta_hl_get_buf(p_data->api_send_data.pkt_size)) != NULL) + { + bta_hl_co_get_tx_data( p_acb->app_id, + p_dcb->mdl_handle, + p_data->api_send_data.pkt_size, + BTA_HL_GET_BUF_PTR(p_dcb->p_tx_pkt), + BTA_HL_CI_GET_TX_DATA_EVT); + p_dcb->cout_oper |= BTA_HL_CO_GET_TX_DATA_MASK; + } + else + { + success = FALSE; + } + } + else + { + success = FALSE; + } + + if (!success) + { + bta_hl_build_send_data_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + p_dcb->mdl_handle, + BTA_HL_STATUS_FAIL); + p_acb->p_cback(BTA_HL_DCH_SEND_DATA_CFM_EVT,(tBTA_HL *) &evt_data ); + } +} + +/******************************************************************************* +** +** Function bta_hl_dch_close_cmpl +** +** Description Action routine for processing the close complete event +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_close_cmpl(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tBTA_HL evt_data; + tBTA_HL_EVT event; + BOOLEAN send_evt=TRUE; + tBTA_HL_STATUS status; + +#if (BTA_HL_DEBUG == TRUE) +#if (BT_TRACE_VERBOSE == TRUE) + APPL_TRACE_DEBUG1("bta_hl_dch_close_cmpl dch oper=%s", bta_hl_dch_oper_code(p_dcb->dch_oper)); +#else + APPL_TRACE_DEBUG1("bta_hl_dch_close_cmpl dch oper=%d", p_dcb->dch_oper); +#endif +#endif + + switch (p_dcb->dch_oper) + { + case BTA_HL_DCH_OP_LOCAL_OPEN: + case BTA_HL_DCH_OP_LOCAL_RECONNECT: + + if (p_dcb->abort_oper & BTA_HL_ABORT_LOCAL_MASK) + { + bta_hl_build_abort_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + BTA_HL_STATUS_OK); + event = BTA_HL_DCH_ABORT_CFM_EVT; + } + else if (p_dcb->abort_oper & BTA_HL_ABORT_REMOTE_MASK ) + { + bta_hl_build_abort_ind(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle); + event = BTA_HL_DCH_ABORT_IND_EVT; + } + else + { + bta_hl_build_dch_open_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + BTA_HL_INVALID_MDL_HANDLE, + 0,0,0,0,0, BTA_HL_STATUS_FAIL); + event = BTA_HL_DCH_OPEN_CFM_EVT; + if (p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_RECONNECT) + { + event = BTA_HL_DCH_RECONNECT_CFM_EVT; + } + } + break; + + case BTA_HL_DCH_OP_LOCAL_CLOSE: + case BTA_HL_DCH_OP_REMOTE_DELETE: + case BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT: + case BTA_HL_DCH_OP_NONE: + + bta_hl_build_dch_close_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + p_dcb->mdl_handle, + BTA_HL_STATUS_OK); + event = BTA_HL_DCH_CLOSE_CFM_EVT; + break; + + case BTA_HL_DCH_OP_REMOTE_CLOSE: + bta_hl_build_dch_close_ind(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + p_dcb->mdl_handle, + p_dcb->intentional_close); + event = BTA_HL_DCH_CLOSE_IND_EVT; + break; + + case BTA_HL_DCH_OP_REMOTE_OPEN: + + if (p_dcb->abort_oper & BTA_HL_ABORT_LOCAL_MASK) + { + bta_hl_build_abort_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + BTA_HL_STATUS_OK); + event = BTA_HL_DCH_ABORT_CFM_EVT; + } + else if (p_dcb->abort_oper & BTA_HL_ABORT_REMOTE_MASK ) + { + bta_hl_build_abort_ind(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle); + event = BTA_HL_DCH_ABORT_IND_EVT; + } + else + { + bta_hl_build_dch_close_ind(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + p_dcb->mdl_handle, + p_dcb->intentional_close); + event = BTA_HL_DCH_CLOSE_IND_EVT; + } + break; + + case BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST: + /* this is normal echo test close */ + case BTA_HL_DCH_OP_REMOTE_CREATE: + case BTA_HL_DCH_OP_REMOTE_RECONNECT: + send_evt=FALSE; + break; + + default: +#if (BTA_HL_DEBUG == TRUE) +#if (BT_TRACE_VERBOSE == TRUE) + APPL_TRACE_ERROR1("DCH operation not found oper=%s", bta_hl_dch_oper_code(p_dcb->dch_oper)); +#else + APPL_TRACE_ERROR1("DCH operation not found oper=%d", p_dcb->dch_oper); +#endif +#endif + send_evt=FALSE; + break; + } + + if ( p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID ) + { + p_mcb->echo_test = FALSE; + send_evt=FALSE; + + if ( p_dcb->dch_oper != BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST) + { + switch (p_dcb->echo_oper) + { + case BTA_HL_ECHO_OP_CI_GET_ECHO_DATA: + case BTA_HL_ECHO_OP_SDP_INIT: + case BTA_HL_ECHO_OP_MDL_CREATE_CFM: + case BTA_HL_ECHO_OP_DCH_OPEN_CFM: + case BTA_HL_ECHO_OP_LOOP_BACK: + + status = BTA_HL_STATUS_FAIL; + send_evt = TRUE; + break; + case BTA_HL_ECHO_OP_OPEN_IND: + case BTA_HL_ECHO_OP_ECHO_PKT: + break; + default: + APPL_TRACE_ERROR1("Invalid echo_oper=%d", p_dcb->echo_oper); + break; + } + } + else + { + status = p_dcb->ci_put_echo_data_status; + send_evt = TRUE; + } + + if (send_evt) + { + bta_hl_build_echo_test_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + status); + event = BTA_HL_DCH_ECHO_TEST_CFM_EVT; + } + } + + bta_hl_clean_mdl_cb(app_idx, mcl_idx, mdl_idx); + + if (send_evt) + { + if (p_acb->p_cback) + { +#if (BTA_HL_DEBUG == TRUE) +#if (BT_TRACE_VERBOSE == TRUE) + APPL_TRACE_DEBUG1("Send Event: %s", bta_hl_cback_evt_code(event)); +#else + APPL_TRACE_DEBUG1("Send Event: 0x%02x", event); +#endif +#endif + p_acb->p_cback(event,(tBTA_HL *) &evt_data ); + } + } + /* check cch close is in progress or not */ + bta_hl_check_cch_close(app_idx, mcl_idx, p_data, FALSE); +} +/******************************************************************************* +** +** Function bta_hl_dch_mca_close_ind +** +** Description Action routine for processing the close indication +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_close_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + +#if (BTA_HL_DEBUG == TRUE) +#if (BT_TRACE_VERBOSE == TRUE) + APPL_TRACE_DEBUG1("bta_hl_dch_mca_close_ind dch oper=%s", bta_hl_dch_oper_code(p_dcb->dch_oper)); +#else + APPL_TRACE_DEBUG1("bta_hl_dch_mca_close_ind dch oper=%d", p_dcb->dch_oper); +#endif +#endif + + p_dcb->intentional_close = FALSE; + if (p_data->mca_evt.mca_data.close_ind.reason == L2CAP_DISC_OK) + { + p_dcb->intentional_close = TRUE; + } + + if (!p_dcb->cout_oper) + { + if ((p_dcb->dch_oper != BTA_HL_DCH_OP_REMOTE_OPEN) && + (p_dcb->dch_oper != BTA_HL_DCH_OP_REMOTE_RECONNECT)) + { + p_dcb->dch_oper = BTA_HL_DCH_OP_REMOTE_CLOSE; + } + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + else + { + p_dcb->close_pending = TRUE; + } +} + +/******************************************************************************* +** +** Function bta_hl_dch_mca_close_cfm +** +** Description Action routine for processing the close confirmation +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_close_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + + +#if (BTA_HL_DEBUG == TRUE) +#if (BT_TRACE_VERBOSE == TRUE) + APPL_TRACE_DEBUG1("bta_hl_dch_mca_close_cfm dch_oper=%s", bta_hl_dch_oper_code(p_dcb->dch_oper) ); +#else + APPL_TRACE_DEBUG1("bta_hl_dch_mca_close_cfm dch_oper=%d", p_dcb->dch_oper); +#endif +#endif + + switch (p_dcb->dch_oper) + { + case BTA_HL_DCH_OP_LOCAL_CLOSE: + case BTA_HL_DCH_OP_LOCAL_OPEN: + case BTA_HL_DCH_OP_LOCAL_RECONNECT: + case BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST: + case BTA_HL_DCH_OP_REMOTE_DELETE: + case BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT: + case BTA_HL_DCH_OP_NONE: + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + break; + default: +#if (BTA_HL_DEBUG == TRUE) +#if (BT_TRACE_VERBOSE == TRUE) + APPL_TRACE_ERROR1("Invalid dch_oper=%s for close cfm", bta_hl_dch_oper_code(p_dcb->dch_oper) ); +#else + APPL_TRACE_ERROR1("Invalid dch_oper=%d for close cfm", p_dcb->dch_oper); +#endif +#endif + break; + } + +} + +/******************************************************************************* +** +** Function bta_hl_dch_mca_close +** +** Description Action routine for processing the DCH close request +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_close(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + tBTA_HL evt_data; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_mca_close"); +#endif + if (!p_dcb->cout_oper) + { + p_dcb->close_pending = FALSE; + if (MCA_CloseReq((tMCA_DL)p_dcb->mdl_handle)== MCA_SUCCESS) + { + p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_CLOSE; + } + else + { + status = BTA_HL_STATUS_FAIL; + } + + if ((status != BTA_HL_STATUS_OK) && + (p_mcb->cch_close_dch_oper != BTA_HL_CCH_CLOSE_OP_DCH_CLOSE)) + { + bta_hl_build_dch_close_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + p_data->api_dch_close.mdl_handle, + status); + p_acb->p_cback(BTA_HL_DCH_CLOSE_CFM_EVT,(tBTA_HL *) &evt_data ); + } + } + else + { + p_dcb->close_pending = TRUE; + } +} + + +/******************************************************************************* +** +** Function bta_hl_dch_mca_open_ind +** +** Description Action routine for processing the open indication +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_open_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tMCA_DL_OPEN *p_open_ind = &p_data->mca_evt.mca_data.open_ind; + tBTA_HL evt_data; + tBTA_HL_EVT event; + UINT8 old_dch_oper; + BOOLEAN send_event = FALSE; + + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_mca_open_ind"); +#endif + if ((p_dcb->dch_oper == BTA_HL_DCH_OP_REMOTE_OPEN) || + (p_dcb->dch_oper == BTA_HL_DCH_OP_REMOTE_RECONNECT) ) + { + p_dcb->mdl_handle = (tBTA_HL_MDL_HANDLE) p_open_ind->mdl; + p_dcb->mtu = p_open_ind->mtu; + + evt_data.dch_open_ind.mdl_handle = p_dcb->mdl_handle; + evt_data.dch_open_ind.mcl_handle = p_mcb->mcl_handle; + evt_data.dch_open_ind.app_handle = p_acb->app_handle; + + evt_data.dch_open_ind.local_mdep_id = p_dcb->local_mdep_id; + evt_data.dch_open_ind.mdl_id = p_dcb->mdl_id; + evt_data.dch_open_ind.mtu = p_dcb->mtu; + + if ( p_dcb->chnl_cfg.fcr_opt.mode == L2CAP_FCR_ERTM_MODE ) + { + evt_data.dch_open_ind.dch_mode = BTA_HL_DCH_MODE_RELIABLE; + if (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx)) + { + p_dcb->is_the_first_reliable = TRUE; + } + } + else + { + evt_data.dch_open_ind.dch_mode = BTA_HL_DCH_MODE_STREAMING; + } + evt_data.dch_open_ind.first_reliable = p_dcb->is_the_first_reliable ; + + old_dch_oper = p_dcb->dch_oper; + p_dcb->dch_oper = BTA_HL_DCH_OP_NONE; + + + } + + switch (old_dch_oper) + { + case BTA_HL_DCH_OP_REMOTE_OPEN: + + p_dcb->dch_mode = evt_data.dch_open_ind.dch_mode; + if (p_dcb->local_mdep_id != BTA_HL_ECHO_TEST_MDEP_ID) + { + bta_hl_save_mdl_cfg(app_idx, mcl_idx,mdl_idx); + event= BTA_HL_DCH_OPEN_IND_EVT; + send_event= TRUE; + } + else + { + p_dcb->echo_oper = BTA_HL_ECHO_OP_ECHO_PKT; + } + + break; + + case BTA_HL_DCH_OP_REMOTE_RECONNECT: + + if (bta_hl_validate_chan_cfg(app_idx, mcl_idx, mdl_idx)) + { + bta_hl_save_mdl_cfg(app_idx, mcl_idx,mdl_idx); + event= BTA_HL_DCH_RECONNECT_IND_EVT; + send_event= TRUE; + } + else + { + if (MCA_CloseReq((tMCA_DL) p_dcb->mdl_handle) == MCA_SUCCESS) + { + p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT; + } + else + { + APPL_TRACE_ERROR0("Unabel to close DCH for reconnect cfg mismatch"); + } + } + break; + default: + break; + } + + if (send_event) + { + p_acb->p_cback(event ,(tBTA_HL *) &evt_data ); + } +} + +/******************************************************************************* +** +** Function bta_hl_dch_mca_open_cfm +** +** Description Action routine for processing the open confirmation +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_open_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tMCA_DL_OPEN *p_open_cfm = &p_data->mca_evt.mca_data.open_cfm; + tBTA_HL evt_data; + tBTA_HL_EVT event; + UINT8 old_dch_oper; + tBTA_HL_DCH_MODE dch_mode; + BOOLEAN send_event = FALSE; + + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_mca_open_cfm"); +#endif + if ((p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_OPEN) || + (p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_RECONNECT)) + { + p_dcb->mdl_handle = (tBTA_HL_MDL_HANDLE) p_open_cfm->mdl; + p_dcb->mtu = p_open_cfm->mtu; + + /*todo verify dch_mode, mtu and fcs for reconnect */ + if ( p_dcb->chnl_cfg.fcr_opt.mode == L2CAP_FCR_ERTM_MODE ) + { + dch_mode = BTA_HL_DCH_MODE_RELIABLE; + } + else + { + dch_mode = BTA_HL_DCH_MODE_STREAMING; + } + + if (p_dcb->local_mdep_id != BTA_HL_ECHO_TEST_MDEP_ID) + { + if (dch_mode == BTA_HL_DCH_MODE_RELIABLE ) + { + if (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx)) + { + p_dcb->is_the_first_reliable = TRUE; + } + } + } + + bta_hl_build_dch_open_cfm(&evt_data, p_acb->app_handle, + p_mcb->mcl_handle, + p_dcb->mdl_handle, + p_dcb->local_mdep_id, + p_dcb->mdl_id, dch_mode, + p_dcb->is_the_first_reliable, + p_dcb->mtu, + BTA_HL_STATUS_OK); + + old_dch_oper = p_dcb->dch_oper; + p_dcb->dch_oper = BTA_HL_DCH_OP_NONE; + } + + switch (old_dch_oper) + { + case BTA_HL_DCH_OP_LOCAL_OPEN: + + p_dcb->dch_mode = dch_mode; + if (p_dcb->local_mdep_id != BTA_HL_ECHO_TEST_MDEP_ID) + { + bta_hl_save_mdl_cfg(app_idx, mcl_idx, mdl_idx); + event= BTA_HL_DCH_OPEN_CFM_EVT; + send_event= TRUE; + } + else + { + p_dcb->echo_oper = BTA_HL_ECHO_OP_LOOP_BACK; + if (MCA_WriteReq((tMCA_DL) p_dcb->mdl_handle, p_dcb->p_echo_tx_pkt)!= MCA_SUCCESS) + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_ECHO_TEST_EVT, p_data); + } + else + { + p_dcb->p_echo_tx_pkt = NULL; + } + } + break; + + case BTA_HL_DCH_OP_LOCAL_RECONNECT: + + if (bta_hl_validate_chan_cfg(app_idx, mcl_idx, mdl_idx)) + { + bta_hl_save_mdl_cfg(app_idx, mcl_idx,mdl_idx); + event= BTA_HL_DCH_RECONNECT_CFM_EVT; + send_event= TRUE; + } + else + { + if (MCA_CloseReq((tMCA_DL) p_dcb->mdl_handle) == MCA_SUCCESS) + { + p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT; + } + else + { + APPL_TRACE_ERROR0("Unabel to close DCH for reconnect cfg mismatch"); + } + } + break; + default: + break; + } + + if (send_event) + p_acb->p_cback(event ,(tBTA_HL *) &evt_data ); +} + + +/******************************************************************************* +** +** Function bta_hl_dch_mca_abort_ind +** +** Description Action routine for processing the abort indication +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_abort_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_mca_abort_ind"); +#endif + + p_dcb->abort_oper |= BTA_HL_ABORT_REMOTE_MASK; + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); +} + +/******************************************************************************* +** +** Function bta_hl_dch_mca_abort_cfm +** +** Description Action routine for processing the abort confirmation +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_abort_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tBTA_HL evt_data; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_mca_abort_cfm"); +#endif + + if (p_dcb->abort_oper) + { + if (p_data->mca_evt.mca_data.abort_cfm.rsp_code != MCA_RSP_SUCCESS ) + { + if (p_dcb->abort_oper & BTA_HL_ABORT_LOCAL_MASK) + { + bta_hl_build_abort_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + BTA_HL_STATUS_FAIL); + p_acb->p_cback(BTA_HL_DCH_ABORT_CFM_EVT ,(tBTA_HL *) &evt_data ); + } + } + else + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + } + else + { + APPL_TRACE_ERROR0("Not expecting Abort CFM "); + } +} + +/******************************************************************************* +** +** Function bta_hl_dch_mca_abort +** +** Description Action routine for processing the abort request +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_abort(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tMCA_RESULT mca_result; + tBTA_HL evt_data; + + if (((p_mcb->sdp_oper == BTA_HL_SDP_OP_DCH_OPEN_INIT) || + (p_mcb->sdp_oper == BTA_HL_SDP_OP_DCH_RECONNECT_INIT)) && + (p_mcb->sdp_mdl_idx == mdl_idx) ) + { + p_dcb->abort_oper |= BTA_HL_ABORT_PENDING_MASK; + return; + } + else if (p_dcb->echo_oper == BTA_HL_ECHO_OP_CI_GET_ECHO_DATA) + { + p_dcb->abort_oper |= BTA_HL_ABORT_PENDING_MASK; + return; + } + + p_dcb->abort_oper &= ~BTA_HL_ABORT_PENDING_MASK; + + if ((mca_result = MCA_Abort((tMCA_CL) p_mcb->mcl_handle))!= MCA_SUCCESS) + { + if (mca_result == MCA_NO_RESOURCES) + { + p_dcb->abort_oper |= BTA_HL_ABORT_PENDING_MASK; + } + else + { + if (p_dcb->abort_oper & BTA_HL_ABORT_LOCAL_MASK) + { + bta_hl_build_abort_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + BTA_HL_STATUS_FAIL); + p_acb->p_cback(BTA_HL_DCH_ABORT_CFM_EVT ,(tBTA_HL *) &evt_data ); + } + bta_hl_check_cch_close(app_idx, mcl_idx, p_data, FALSE); + } + + + } + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG1("bta_hl_dch_mca_abort abort_oper=0x%x", p_dcb->abort_oper); +#endif + +} + +/******************************************************************************* +** +** Function bta_hl_dch_mca_reconnect_ind +** +** Description Action routine for processing the reconnect indication +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_reconnect_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tBTA_HL_MDL_CFG *p_mdl_cfg; + tMCA_EVT_HDR *p_reconnect_ind = &p_data->mca_evt.mca_data.reconnect_ind; + UINT8 mdl_cfg_idx, in_use_mdl_idx, mdep_cfg_idx; + UINT8 rsp_code = MCA_RSP_SUCCESS; + + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG1("bta_hl_dch_mca_reconnect_ind mdl_id=%d", p_reconnect_ind->mdl_id); +#endif + + if (bta_hl_find_mdl_cfg_idx(app_idx, mcl_idx, p_reconnect_ind->mdl_id, &mdl_cfg_idx)) + { + if (!bta_hl_find_mdl_idx(app_idx,mcl_idx,p_reconnect_ind->mdl_id, &in_use_mdl_idx) ) + { + p_mdl_cfg = BTA_HL_GET_MDL_CFG_PTR(app_idx, mdl_cfg_idx); + + if (bta_hl_find_mdep_cfg_idx(app_idx, p_mdl_cfg->local_mdep_id, &mdep_cfg_idx)) + { + p_dcb->in_use = TRUE; + p_dcb->dch_oper = BTA_HL_DCH_OP_REMOTE_RECONNECT; + p_dcb->sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); + p_dcb->peer_mdep_id = 0xFF; + p_dcb->local_mdep_id = p_mdl_cfg->local_mdep_id ; + p_dcb->local_mdep_cfg_idx = mdep_cfg_idx; + p_dcb->local_cfg = BTA_HL_DCH_CFG_UNKNOWN; + p_dcb->mdl_id = p_reconnect_ind->mdl_id; + p_dcb->mdl_cfg_idx_included = TRUE; + p_dcb->mdl_cfg_idx = mdl_cfg_idx; + p_dcb->dch_mode = p_mdl_cfg->dch_mode; + bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx, + &p_dcb->max_rx_apdu_size, + &p_dcb->max_tx_apdu_size); + bta_hl_set_dch_chan_cfg(app_idx, mcl_idx, mdl_idx, p_data); + } + else + { + rsp_code = MCA_RSP_BAD_MDL; + } + } + else + { + rsp_code = MCA_RSP_BAD_MDL; + } + } + else + { + rsp_code = MCA_RSP_BAD_MDL; + } + + if (MCA_ReconnectMdlRsp((tMCA_CL) p_mcb->mcl_handle, + p_dcb->local_mdep_id, + p_dcb->mdl_id, + rsp_code, + &p_dcb->chnl_cfg)!= MCA_SUCCESS) + { + MCA_Abort((tMCA_CL) p_mcb->mcl_handle); + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } +} + +/******************************************************************************* +** +** Function bta_hl_dch_mca_reconnect_cfm +** +** Description Action routine for processing the reconenct confirmation +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_reconnect_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tMCA_RSP_EVT *p_reconnect_cfm = &p_data->mca_evt.mca_data.reconnect_cfm; + + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_mca_reconnect_cfm"); +#endif + if (p_dcb->abort_oper & BTA_HL_ABORT_PENDING_MASK) + { + p_dcb->abort_oper &= ~BTA_HL_ABORT_PENDING_MASK; + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ABORT_EVT, p_data); + return; + } + + + if (p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_RECONNECT) + { + if (p_reconnect_cfm->rsp_code == MCA_RSP_SUCCESS) + { + + bta_hl_set_dch_chan_cfg(app_idx, mcl_idx, mdl_idx, p_data); + + if (MCA_DataChnlCfg((tMCA_CL) p_mcb->mcl_handle, &p_dcb->chnl_cfg)!= MCA_SUCCESS) + { + /* should be able to abort so no checking of the return code */ + MCA_Abort((tMCA_CL) p_mcb->mcl_handle); + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + } + else + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + } +} + +/******************************************************************************* +** +** Function bta_hl_dch_mca_reconnect +** +** Description Action routine for processing the reconnect request +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_reconnect(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tMCA_CHNL_CFG *p_chnl_cfg=NULL; + UINT8 sdp_idx; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_mca_reconnect"); +#endif + if (bta_hl_find_sdp_idx_using_ctrl_psm(&p_mcb->sdp, p_mcb->ctrl_psm, &sdp_idx)) + { + p_mcb->data_psm = p_mcb->sdp.sdp_rec[sdp_idx].data_psm; + if ( MCA_ReconnectMdl((tMCA_CL) p_mcb->mcl_handle, + p_dcb->local_mdep_id, + p_mcb->data_psm, + p_dcb->mdl_id, + p_chnl_cfg ) != MCA_SUCCESS) + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + } + else + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } +} + + +/******************************************************************************* +** +** Function bta_hl_dch_create_rsp +** +** Description Action routine for processing BTA_HL_API_DCH_CREATE_RSP_EVT +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_create_rsp(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tBTA_HL_API_DCH_CREATE_RSP *p_create_rsp = &p_data->api_dch_create_rsp; + UINT8 mca_rsp_code = MCA_RSP_SUCCESS; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_create_rsp"); +#endif + if (p_create_rsp->rsp_code == BTA_HL_DCH_CREATE_RSP_SUCCESS) + { + p_dcb->dch_oper = BTA_HL_DCH_OP_REMOTE_OPEN; + p_dcb->local_cfg = p_create_rsp->cfg_rsp; + + + + bta_hl_set_dch_chan_cfg(app_idx, mcl_idx, mdl_idx, p_data); + } + else + { + mca_rsp_code = MCA_RSP_CFG_REJ; + } + + if (MCA_CreateMdlRsp((tMCA_CL) p_mcb->mcl_handle, + p_dcb->local_mdep_id, + p_dcb->mdl_id, + p_dcb->local_cfg, + mca_rsp_code, + &p_dcb->chnl_cfg)!= MCA_SUCCESS) + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } +} + +/******************************************************************************* +** +** Function bta_hl_dch_mca_create_ind +** +** Description Action routine for processing +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_create_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tMCA_CREATE_IND *p_create_ind = &p_data->mca_evt.mca_data.create_ind; + UINT8 mdep_cfg_idx; + UINT8 cfg_rsp; + UINT8 rsp_code = MCA_RSP_SUCCESS; + BOOLEAN send_create_ind_evt = FALSE; + tBTA_HL evt_data; + tBTA_HL_ECHO_CFG *p_echo_cfg; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_mca_create_ind"); +#endif + + if (bta_hl_find_mdep_cfg_idx(app_idx, p_create_ind->dep_id, &mdep_cfg_idx)) + { + if (p_create_ind->dep_id == BTA_HL_ECHO_TEST_MDEP_ID ) + { + if (bta_hl_find_echo_cfg_rsp(app_idx, mcl_idx, mdep_cfg_idx,p_create_ind->cfg, &cfg_rsp )) + { + p_dcb->in_use = TRUE; + p_dcb->dch_oper = BTA_HL_DCH_OP_REMOTE_OPEN; + p_dcb->local_mdep_id = p_create_ind->dep_id ; + p_dcb->local_mdep_cfg_idx = mdep_cfg_idx; + p_dcb->local_cfg = cfg_rsp; + p_dcb->remote_cfg = p_create_ind->cfg ; + p_dcb->mdl_id = p_create_ind->mdl_id; + p_dcb->mdl_cfg_idx_included = FALSE; + p_echo_cfg = BTA_HL_GET_ECHO_CFG_PTR(app_idx); + p_dcb->max_rx_apdu_size = p_echo_cfg->max_rx_apdu_size; + p_dcb->max_tx_apdu_size = p_echo_cfg->max_tx_apdu_size; + + bta_hl_set_dch_chan_cfg(app_idx, mcl_idx, mdl_idx, p_data); + } + else + { + rsp_code = MCA_RSP_CFG_REJ; + } + } + else + + { + p_dcb->in_use = TRUE; + p_dcb->dch_oper = BTA_HL_DCH_OP_REMOTE_CREATE; + p_dcb->local_mdep_id = p_create_ind->dep_id ; + p_dcb->local_mdep_cfg_idx = mdep_cfg_idx; + p_dcb->local_cfg = BTA_HL_DCH_CFG_UNKNOWN; + p_dcb->remote_cfg = p_create_ind->cfg; + p_dcb->mdl_id = p_create_ind->mdl_id; + p_dcb->mdl_cfg_idx_included = FALSE; + bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx, + &p_dcb->max_rx_apdu_size, + &p_dcb->max_tx_apdu_size); + send_create_ind_evt = TRUE; + } + } + else + { + rsp_code = MCA_RSP_BAD_MDEP; + } + + if (send_create_ind_evt) + { + evt_data.dch_create_ind.mcl_handle = p_mcb->mcl_handle; + evt_data.dch_create_ind.app_handle = p_acb->app_handle; + evt_data.dch_create_ind.local_mdep_id = p_dcb->local_mdep_id; + evt_data.dch_create_ind.mdl_id = p_dcb->mdl_id; + evt_data.dch_create_ind.cfg = p_dcb->remote_cfg; + p_acb->p_cback(BTA_HL_DCH_CREATE_IND_EVT,(tBTA_HL *) &evt_data ); + } + else + { + if (MCA_CreateMdlRsp((tMCA_CL) p_mcb->mcl_handle, + p_dcb->local_mdep_id, + p_dcb->mdl_id, + p_dcb->local_cfg, + rsp_code, + &p_dcb->chnl_cfg)!= MCA_SUCCESS) + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + else + { + if (p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID) + { + p_mcb->echo_test = TRUE; + p_dcb->echo_oper = BTA_HL_ECHO_OP_OPEN_IND; + } + } + } +} + +/******************************************************************************* +** +** Function bta_hl_dch_mca_create_cfm +** +** Description Action routine for processing +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_create_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tMCA_CREATE_CFM *p_create_cfm = &p_data->mca_evt.mca_data.create_cfm; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_mca_create_cfm"); +#endif + + if (p_dcb->abort_oper & BTA_HL_ABORT_PENDING_MASK) + { + p_dcb->abort_oper &= ~BTA_HL_ABORT_PENDING_MASK; + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ABORT_EVT, p_data); + return; + } + + if (p_dcb->dch_oper == BTA_HL_DCH_OP_LOCAL_OPEN) + { + if (p_create_cfm->rsp_code == MCA_RSP_SUCCESS) + { + if (bta_hl_validate_cfg(app_idx, mcl_idx, mdl_idx, p_create_cfm->cfg )) + { + bta_hl_set_dch_chan_cfg(app_idx, mcl_idx, mdl_idx, p_data); + + if (MCA_DataChnlCfg((tMCA_CL) p_mcb->mcl_handle, &p_dcb->chnl_cfg)!= MCA_SUCCESS) + { + /* this should not happen */ + APPL_TRACE_ERROR0("Unable to create data channel"); + MCA_Abort((tMCA_CL) p_mcb->mcl_handle); + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + else + { + if (p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID) + { + p_dcb->echo_oper = BTA_HL_ECHO_OP_DCH_OPEN_CFM; + } + } + } + else + { + MCA_Abort((tMCA_CL) p_mcb->mcl_handle); + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + } + else + { + APPL_TRACE_ERROR0("MCA Create- failed"); + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + } +} + +/******************************************************************************* +** +** Function bta_hl_dch_mca_create +** +** Description Action routine for processing the MDL create request +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_mca_create(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tMCA_RESULT result; + UINT8 sdp_idx; + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG0("bta_hl_dch_mca_create"); +#endif + + if (bta_hl_find_sdp_idx_using_ctrl_psm(&p_mcb->sdp, p_mcb->ctrl_psm, &sdp_idx) && + bta_hl_validate_peer_cfg(app_idx, mcl_idx, mdl_idx, + p_dcb->peer_mdep_id, + p_dcb->peer_mdep_role, + sdp_idx)) + { + + p_mcb->data_psm = p_mcb->sdp.sdp_rec[sdp_idx].data_psm; + if ( (result = MCA_CreateMdl((tMCA_CL) p_mcb->mcl_handle, + p_dcb->local_mdep_id, + p_mcb->data_psm, + p_dcb->mdl_id, + p_dcb->peer_mdep_id, + p_dcb->local_cfg, + NULL )) != MCA_SUCCESS) + { + APPL_TRACE_ERROR1("MCA_CreateMdl FAIL mca_result=%d", result); + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + } + else + { + APPL_TRACE_ERROR0("MCA Create- SDP idx or peer MDEP cfg not found"); + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } +} + +/******************************************************************************* +** +** Function bta_hl_dch_sdp_fail +** +** Description Action routine for processing the SDP failed event +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_sdp_fail(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data) +{ + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_dch_sdp_fail"); +#endif + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); +} + +/****************************************************************************** +** +** Function bta_hl_sdp_cback +** +** Description This is the SDP callback function used by HL. +** This function will be executed by SDP when the service +** search is completed. If the search is successful, it +** finds the first record in the database that matches the +** UUID of the search. Then retrieves the scn from the +** record. +** +** Returns void. +** +******************************************************************************/ +static void bta_hl_sdp_cback(UINT8 sdp_oper, UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdl_idx, UINT16 status) +{ + tBTA_HL_MCL_CB *p_cb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_SDP_REC *p_hdp_rec; + tBTA_HL_CCH_SDP *p_cch_buf; + tBTA_HL_DCH_SDP *p_dch_buf; + tSDP_DISC_REC *p_rec = NULL; + tSDP_PROTOCOL_ELEM pe; + tSDP_DISC_ATTR *p_attr; + UINT8 i, rec_cnt; + tBTA_HL_SUP_FEATURE_LIST_ELEM sup_feature; + BOOLEAN sdp_parsing_ok =FALSE, result=FALSE; + UINT16 event; + tBTA_HL_MDL_CB *p_dcb; + UINT16 service_uuid; + UINT16 name_len; + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG5("bta_hl_sdp_cback status:%d sdp_oper=%d app_idx=%d, mcl_idx=%d, mdl_idx=%d", + status, sdp_oper, app_idx, mcl_idx, mdl_idx); +#endif + + rec_cnt = 0; + service_uuid = bta_hl_get_service_uuids(sdp_oper, app_idx, mcl_idx, mdl_idx); + + if (status == SDP_SUCCESS || status == SDP_DB_FULL) + { + memset(&p_cb->sdp,0, sizeof(tBTA_HL_SDP)); + do + { + if (bta_hl_find_service_in_db(app_idx, mcl_idx, service_uuid, &p_rec)) + { + p_hdp_rec = &p_cb->sdp.sdp_rec[rec_cnt]; + p_cb->sdp.num_recs = rec_cnt+1; + } + else + { + break; + } + + if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_L2CAP, &pe)) + { + p_hdp_rec->ctrl_psm = (UINT16) pe.params[0]; + } + else + { + APPL_TRACE_WARNING0("Control PSM not found"); + break; + } + if (SDP_FindAddProtoListsElemInRec(p_rec, UUID_PROTOCOL_L2CAP, &pe)) + { + p_hdp_rec->data_psm = (UINT16) pe.params[0]; + } + else + { + APPL_TRACE_WARNING0("Data PSM not found"); + break; + } + + p_hdp_rec->srv_name[0]= '\0'; + if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) + { + if (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) < BT_MAX_SERVICE_NAME_LEN) + name_len = (UINT16)SDP_DISC_ATTR_LEN(p_attr->attr_len_type); + else + name_len = BT_MAX_SERVICE_NAME_LEN; + memcpy(p_hdp_rec->srv_name, p_attr->attr_value.v.array, name_len); + } + + p_hdp_rec->srv_desp[0]= '\0'; + if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_DESCRIPTION)) != NULL) + { + if (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) < BT_MAX_SERVICE_NAME_LEN) + name_len = (UINT16)SDP_DISC_ATTR_LEN(p_attr->attr_len_type); + else + name_len = BT_MAX_SERVICE_NAME_LEN; + memcpy(p_hdp_rec->srv_desp, p_attr->attr_value.v.array, name_len); + } + + + p_hdp_rec->provider_name[0]= '\0'; + if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_PROVIDER_NAME)) != NULL) + { + if (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) < BT_MAX_SERVICE_NAME_LEN) + name_len = (UINT16)SDP_DISC_ATTR_LEN(p_attr->attr_len_type); + else + name_len = BT_MAX_SERVICE_NAME_LEN; + memcpy(p_hdp_rec->provider_name, p_attr->attr_value.v.array, name_len); + } + + if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HDP_MCAP_SUP_PROC))!=NULL) + { + p_hdp_rec->mcap_sup_proc = p_attr->attr_value.v.u8; + } + else + { + APPL_TRACE_WARNING0("MCAP SUP PROC not found"); + break; + } + + if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HDP_SUP_FEAT_LIST ))!=NULL) + { + if (bta_hl_fill_sup_feature_list (p_attr, &sup_feature)) + { + p_hdp_rec->num_mdeps = (UINT8) sup_feature.num_elems; + for (i=0; i<sup_feature.num_elems; i++) + { + p_hdp_rec->mdep_cfg[i].data_type = sup_feature.list_elem[i].data_type; + p_hdp_rec->mdep_cfg[i].mdep_id = sup_feature.list_elem[i].mdep_id; + p_hdp_rec->mdep_cfg[i].mdep_role = sup_feature.list_elem[i].mdep_role; + /* Check MDEP Description pointer to prevent crash due to null pointer */ + if (sup_feature.list_elem[i].p_mdep_desp != NULL) + { + BCM_STRNCPY_S(p_hdp_rec->mdep_cfg[i].mdep_desp, + sizeof(p_hdp_rec->mdep_cfg[i].mdep_desp), + sup_feature.list_elem[i].p_mdep_desp, + BTA_HL_MDEP_DESP_LEN); + } + else + { + APPL_TRACE_ERROR1("bta_hl_sdp_cback Incorrect Mdep[%d] Description (Null ptr)", i); + } + } + + sdp_parsing_ok = TRUE; + } + else + { + APPL_TRACE_WARNING0("HDP supported feature list fill failed"); + break; + } + } + else + { + APPL_TRACE_WARNING0("HDP supported feature list not found"); + break; + } +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG3("record=%d ctrl_psm=%0x data_psm=%x", + rec_cnt+1, + p_hdp_rec->ctrl_psm, + p_hdp_rec->data_psm ); + APPL_TRACE_DEBUG1("srv_name=[%s]",(p_hdp_rec->srv_name[0] != '\0')? p_hdp_rec->srv_name:"NULL"); + APPL_TRACE_DEBUG1("srv_desp=[%s]",(p_hdp_rec->srv_desp[0] != '\0')? p_hdp_rec->srv_desp:"NULL"); + for (i=0; i<sup_feature.num_elems; i++) + { + APPL_TRACE_DEBUG5("index=0x%02x mdep_id=0x%04x data type=0x%04x mdep role=%s(0x%02x)", + (i+1), + p_hdp_rec->mdep_cfg[i].mdep_id, + p_hdp_rec->mdep_cfg[i].data_type, + (p_hdp_rec->mdep_cfg[i].mdep_role == BTA_HL_MDEP_ROLE_SOURCE)?"Src":"Snk", + p_hdp_rec->mdep_cfg[i].mdep_role); + } + APPL_TRACE_DEBUG1("provider_name=[%s]",(p_hdp_rec->provider_name[0] != '\0')? p_hdp_rec->provider_name:"NULL"); + APPL_TRACE_DEBUG1("found MCAP sup procedure=%d", + p_cb->sdp.sdp_rec[rec_cnt].mcap_sup_proc ); +#endif + rec_cnt++; + if (rec_cnt >= BTA_HL_NUM_SDP_RECS) + { + APPL_TRACE_WARNING1("No more spaces for SDP recs max_rec_cnt=%d", BTA_HL_NUM_SDP_RECS); + break; + } + + + } while (TRUE); + } + + + utl_freebuf((void **)&p_cb->p_db); + + if ( (status == SDP_SUCCESS || status == SDP_DB_FULL) && + p_cb->sdp.num_recs && + sdp_parsing_ok) + { + result = TRUE; + } + else + { + APPL_TRACE_WARNING3("SDP Failed sdp_status=%d num_recs=%d sdp_parsing_ok=%d ", + status, p_cb->sdp.num_recs,sdp_parsing_ok ); + } + + + p_cb->sdp_oper = BTA_HL_SDP_OP_NONE; + + switch (sdp_oper ) + { + case BTA_HL_SDP_OP_CCH_INIT: + case BTA_HL_SDP_OP_SDP_QUERY_NEW: + case BTA_HL_SDP_OP_SDP_QUERY_CURRENT: + + /* send result in event back to BTA */ + if ((p_cch_buf = (tBTA_HL_CCH_SDP *) GKI_getbuf(sizeof(tBTA_HL_CCH_SDP))) != NULL) + { + if (result) + { + if (sdp_oper == BTA_HL_SDP_OP_CCH_INIT) + { + event = BTA_HL_CCH_SDP_OK_EVT; + if (p_cb->close_pending) + { + event = BTA_HL_CCH_SDP_FAIL_EVT; + } + } + else + { + event = BTA_HL_SDP_QUERY_OK_EVT; + } + } + else + { + if (sdp_oper == BTA_HL_SDP_OP_CCH_INIT) + { + event = BTA_HL_CCH_SDP_FAIL_EVT; + } + else + { + event = BTA_HL_SDP_QUERY_FAIL_EVT; + } + } + p_cch_buf->hdr.event = event; + + p_cch_buf->app_idx = app_idx; + p_cch_buf->mcl_idx = mcl_idx; + p_cch_buf->release_mcl_cb = FALSE; + if (sdp_oper == BTA_HL_SDP_OP_SDP_QUERY_NEW) + { + p_cch_buf->release_mcl_cb = TRUE; + } + + bta_sys_sendmsg(p_cch_buf); + } + break; + case BTA_HL_SDP_OP_DCH_OPEN_INIT: + case BTA_HL_SDP_OP_DCH_RECONNECT_INIT: + if ((p_dch_buf = (tBTA_HL_DCH_SDP *) GKI_getbuf(sizeof(tBTA_HL_DCH_SDP))) != NULL) + { + p_dch_buf->hdr.event = BTA_HL_DCH_SDP_FAIL_EVT; + p_dch_buf->app_idx = app_idx; + p_dch_buf->mcl_idx = mcl_idx; + p_dch_buf->mdl_idx = mdl_idx; + p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + if (p_dcb->abort_oper & BTA_HL_ABORT_PENDING_MASK) + { + p_dcb->abort_oper &= ~BTA_HL_ABORT_PENDING_MASK; + result = FALSE; + } + if (result) + { + if (sdp_oper == BTA_HL_SDP_OP_DCH_OPEN_INIT) + { + if (p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID ) + { + p_dch_buf->hdr.event = BTA_HL_DCH_ECHO_TEST_EVT; + } + else + { + p_dch_buf->hdr.event = BTA_HL_DCH_OPEN_EVT; + } + } + else + { + p_dch_buf->hdr.event = BTA_HL_DCH_RECONNECT_EVT; + } + } + bta_sys_sendmsg(p_dch_buf); + } + break; + default: + break; + } +} + + +/****************************************************************************** +** +** Function bta_hl_sdp_cback0 +** +** Description This is the SDP callback function used by index = 0 +** +** Returns void. +** +******************************************************************************/ +static void bta_hl_sdp_cback0(UINT16 status) +{ + bta_hl_sdp_cback(bta_hl_cb.scb[0].sdp_oper, + bta_hl_cb.scb[0].app_idx, + bta_hl_cb.scb[0].mcl_idx, + bta_hl_cb.scb[0].mdl_idx, + status); + bta_hl_deallocate_spd_cback(0); +} + +/****************************************************************************** +** +** Function bta_hl_sdp_cback1 +** +** Description This is the SDP callback function used by index = 1 +** +** Parameters status - status of the SDP callabck +** +** Returns void. +** +******************************************************************************/ +static void bta_hl_sdp_cback1(UINT16 status) +{ + bta_hl_sdp_cback(bta_hl_cb.scb[1].sdp_oper, + bta_hl_cb.scb[1].app_idx, + bta_hl_cb.scb[1].mcl_idx, + bta_hl_cb.scb[1].mdl_idx, + status); + bta_hl_deallocate_spd_cback(1); +} + +/****************************************************************************** +** +** Function bta_hl_sdp_cback2 +** +** Description This is the SDP callback function used by index = 2 +** +** Returns void. +** +******************************************************************************/ +static void bta_hl_sdp_cback2(UINT16 status) +{ + bta_hl_sdp_cback(bta_hl_cb.scb[2].sdp_oper, + bta_hl_cb.scb[2].app_idx, + bta_hl_cb.scb[2].mcl_idx, + bta_hl_cb.scb[2].mdl_idx, + status); + bta_hl_deallocate_spd_cback(2); +} + +/****************************************************************************** +** +** Function bta_hl_sdp_cback3 +** +** Description This is the SDP callback function used by index = 3 +** +** Returns void. +** +******************************************************************************/ +static void bta_hl_sdp_cback3(UINT16 status) +{ + bta_hl_sdp_cback(bta_hl_cb.scb[3].sdp_oper, + bta_hl_cb.scb[3].app_idx, + bta_hl_cb.scb[3].mcl_idx, + bta_hl_cb.scb[3].mdl_idx, + status); + bta_hl_deallocate_spd_cback(3); +} + +/****************************************************************************** +** +** Function bta_hl_sdp_cback4 +** +** Description This is the SDP callback function used by index = 4 +** +** Parameters status - status of the SDP callabck +** +** Returns void. +** +******************************************************************************/ +static void bta_hl_sdp_cback4(UINT16 status) +{ + bta_hl_sdp_cback(bta_hl_cb.scb[4].sdp_oper, + bta_hl_cb.scb[4].app_idx, + bta_hl_cb.scb[4].mcl_idx, + bta_hl_cb.scb[4].mdl_idx, + status); + bta_hl_deallocate_spd_cback(4); +} + +/****************************************************************************** +** +** Function bta_hl_sdp_cback5 +** +** Description This is the SDP callback function used by index = 5 +** +** Parameters status - status of the SDP callabck +** +** Returns void. +** +******************************************************************************/ +static void bta_hl_sdp_cback5(UINT16 status) +{ + bta_hl_sdp_cback(bta_hl_cb.scb[5].sdp_oper, + bta_hl_cb.scb[5].app_idx, + bta_hl_cb.scb[5].mcl_idx, + bta_hl_cb.scb[5].mdl_idx, + status); + bta_hl_deallocate_spd_cback(5); +} + +/****************************************************************************** +** +** Function bta_hl_sdp_cback6 +** +** Description This is the SDP callback function used by index = 6 +** +** Returns void. +** +******************************************************************************/ +static void bta_hl_sdp_cback6(UINT16 status) +{ + bta_hl_sdp_cback(bta_hl_cb.scb[6].sdp_oper, + bta_hl_cb.scb[6].app_idx, + bta_hl_cb.scb[6].mcl_idx, + bta_hl_cb.scb[6].mdl_idx, + status); + bta_hl_deallocate_spd_cback(6); +} + + +/******************************************************************************* +** +** Function bta_hl_deallocate_spd_cback +** +** Description Deallocate a SDP control block +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +void bta_hl_deallocate_spd_cback(UINT8 sdp_cback_idx) +{ + tBTA_HL_SDP_CB *p_spd_cb = &bta_hl_cb.scb[sdp_cback_idx]; + + memset(p_spd_cb, 0, sizeof(tBTA_HL_SDP_CB)); + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("bta_hl_deallocate_spd_cback index=%d", sdp_cback_idx); +#endif + + +} + +/******************************************************************************* +** +** Function bta_hl_allocate_spd_cback +** +** Description Finds a not in used SDP control block index +** +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +tSDP_DISC_CMPL_CB *bta_hl_allocate_spd_cback(tBTA_HL_SDP_OPER sdp_oper, UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdl_idx, + UINT8 *p_sdp_cback_idx) +{ + UINT8 i; + tSDP_DISC_CMPL_CB *p_cbcak=NULL; + + + for (i=0; i < BTA_HL_NUM_SDP_CBACKS ; i ++) + { + if (!bta_hl_cb.scb[i].in_use) + { + p_cbcak = bta_hl_sdp_cback_arr[i]; + bta_hl_cb.scb[i].in_use = TRUE; + bta_hl_cb.scb[i].sdp_oper = sdp_oper; + bta_hl_cb.scb[i].app_idx = app_idx; + bta_hl_cb.scb[i].mcl_idx = mcl_idx; + bta_hl_cb.scb[i].mdl_idx = mdl_idx; + *p_sdp_cback_idx = i; + break; + } + } + + if (i == BTA_HL_NUM_SDP_CBACKS) + { + APPL_TRACE_WARNING0("No scb is available to allocate") + } + else + { +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("bta_hl_allocate_spd_cback cback_idx=%d ",i ); + APPL_TRACE_DEBUG4("sdp_oper=%d, app_idx=%d, mcl_idx=%d, mdl_idx=%d", + bta_hl_cb.scb[i].sdp_oper, + bta_hl_cb.scb[i].app_idx, + bta_hl_cb.scb[i].mcl_idx, + bta_hl_cb.scb[i].mdl_idx ); +#endif + } + return p_cbcak; +} + + +/******************************************************************************* +** +** Function bta_hl_init_sdp +** +** Description Action routine for processing the SDP initiattion request +** +** Returns void +** +*******************************************************************************/ +tBTA_HL_STATUS bta_hl_init_sdp(tBTA_HL_SDP_OPER sdp_oper, UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdl_idx) +{ + tBTA_HL_MCL_CB *p_cb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tSDP_UUID uuid_list; + UINT16 attr_list[BTA_HL_NUM_SRCH_ATTR]; + UINT16 num_attrs = BTA_HL_NUM_SRCH_ATTR; + tBTA_HL_STATUS status; + UINT8 sdp_cback_idx; +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG4("bta_hl_init_sdp sdp_oper=%d app_idx=%d mcl_idx=%d, mdl_idx=%d", + sdp_oper, app_idx, mcl_idx, mdl_idx); +#endif + if ((p_cb->sdp_cback = bta_hl_allocate_spd_cback(sdp_oper, app_idx, mcl_idx, mdl_idx, &sdp_cback_idx)) != NULL) + { + if ( p_cb->p_db || + (!p_cb->p_db && + (p_cb->p_db = (tSDP_DISCOVERY_DB *) GKI_getbuf(BTA_HL_DISC_SIZE)) != NULL)) + { + attr_list[0] = ATTR_ID_SERVICE_CLASS_ID_LIST; + attr_list[1] = ATTR_ID_PROTOCOL_DESC_LIST; + attr_list[2] = ATTR_ID_BT_PROFILE_DESC_LIST; + attr_list[3] = ATTR_ID_ADDITION_PROTO_DESC_LISTS; + attr_list[4] = ATTR_ID_SERVICE_NAME; + attr_list[5] = ATTR_ID_SERVICE_DESCRIPTION; + attr_list[6] = ATTR_ID_PROVIDER_NAME; + attr_list[7] = ATTR_ID_HDP_SUP_FEAT_LIST; + attr_list[8] = ATTR_ID_HDP_DATA_EXCH_SPEC; + attr_list[9] = ATTR_ID_HDP_MCAP_SUP_PROC; + + + uuid_list.len = LEN_UUID_16; + uuid_list.uu.uuid16 = UUID_SERVCLASS_HDP_PROFILE; + + SDP_InitDiscoveryDb(p_cb->p_db, BTA_HL_DISC_SIZE, 1, &uuid_list, num_attrs, attr_list); + + if (!SDP_ServiceSearchAttributeRequest(p_cb->bd_addr, p_cb->p_db, p_cb->sdp_cback)) + { + status = BTA_HL_STATUS_FAIL; + } + else + { + status = BTA_HL_STATUS_OK; + } + } + else /* No services available */ + { + status = BTA_HL_STATUS_NO_RESOURCE; + } + } + else + { + status = BTA_HL_STATUS_SDP_NO_RESOURCE; + } + + if (status != BTA_HL_STATUS_OK) + { + utl_freebuf((void **)&p_cb->p_db); + if (status != BTA_HL_STATUS_SDP_NO_RESOURCE ) + { + bta_hl_deallocate_spd_cback(sdp_cback_idx); + } + } + + return status; +} + +/******************************************************************************* +** +** Function bta_hl_cch_sdp_init +** +** Description Action routine for processing the CCH SDP init event +** +** Returns void +** +*******************************************************************************/ +void bta_hl_cch_sdp_init(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data) +{ + tBTA_HL_MCL_CB *p_cb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG0("bta_hl_cch_init_sdp"); +#endif + if ( p_cb->sdp_oper == BTA_HL_SDP_OP_NONE) + { + p_cb->sdp_oper = BTA_HL_SDP_OP_CCH_INIT; + + if (bta_hl_init_sdp( p_cb->sdp_oper, app_idx, mcl_idx, 0xFF) != BTA_HL_STATUS_OK) + { + p_cb->sdp_oper = BTA_HL_SDP_OP_NONE; + bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_SDP_FAIL_EVT, p_data); + } + } + else + { + APPL_TRACE_ERROR0("SDP in use"); + bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_SDP_FAIL_EVT, p_data); + } +} + +/******************************************************************************* +** +** Function bta_hl_cch_mca_open +** +** Description Action routine for processing the CCH open request +** +** Returns void +** +*******************************************************************************/ +void bta_hl_cch_mca_open(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + UINT8 sdp_idx; + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG0("bta_hl_cch_mca_open"); +#endif + + if (bta_hl_find_sdp_idx_using_ctrl_psm(&p_mcb->sdp, p_mcb->req_ctrl_psm, &sdp_idx)) + { + p_mcb->ctrl_psm = p_mcb->sdp.sdp_rec[sdp_idx].ctrl_psm; + p_mcb->data_psm = p_mcb->sdp.sdp_rec[sdp_idx].data_psm; + if ( MCA_ConnectReq((tMCA_HANDLE) p_acb->app_handle, + p_mcb->bd_addr, + p_mcb->ctrl_psm , + p_mcb->sec_mask) != MCA_SUCCESS) + { + + bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data); + } + } + else + { + bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data); + } +} + +/******************************************************************************* +** +** Function bta_hl_cch_mca_close +** +** Description Action routine for processing the CCH close request +** +** Returns void +** +*******************************************************************************/ +void bta_hl_cch_mca_close(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG0("bta_hl_cch_mca_close"); +#endif + if (p_mcb->sdp_oper != BTA_HL_SDP_OP_CCH_INIT) + { + if ( MCA_DisconnectReq((tMCA_HANDLE) p_acb->app_handle) != MCA_SUCCESS) + { + bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data); + } + } + else + { + p_mcb->close_pending = TRUE; + } +} + +/******************************************************************************* +** +** Function bta_hl_cch_close_cmpl +** +** Description Action routine for processing the CCH close complete event +** +** Returns void +** +*******************************************************************************/ +void bta_hl_cch_close_cmpl(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + + tBTA_HL evt_data; + tBTA_HL_EVT event; + BOOLEAN send_evt=TRUE; +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG0("bta_hl_cch_close_cmpl"); +#endif + bta_sys_conn_close(BTA_ID_HL, p_acb->app_id, p_mcb->bd_addr); + + switch (p_mcb->cch_oper) + { + case BTA_HL_CCH_OP_LOCAL_OPEN: + bta_hl_build_cch_open_cfm(&evt_data, p_acb->app_handle, + p_mcb->mcl_handle, + p_mcb->bd_addr, + BTA_HL_STATUS_FAIL); + event = BTA_HL_CCH_OPEN_CFM_EVT; + break; + case BTA_HL_CCH_OP_LOCAL_CLOSE: + bta_hl_build_cch_close_cfm(&evt_data, p_acb->app_handle, + p_mcb->mcl_handle, + BTA_HL_STATUS_OK); + event = BTA_HL_CCH_CLOSE_CFM_EVT; + break; + case BTA_HL_CCH_OP_REMOTE_CLOSE: + bta_hl_build_cch_close_ind(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + p_mcb->intentional_close); + event = BTA_HL_CCH_CLOSE_IND_EVT; + break; + default: + send_evt=FALSE; + break; + } + + + memset(p_mcb, 0 ,sizeof(tBTA_HL_MCL_CB)); + + if (send_evt)p_acb->p_cback(event,(tBTA_HL *) &evt_data ); + + bta_hl_check_deregistration(app_idx, p_data); +} + +/******************************************************************************* +** +** Function bta_hl_cch_mca_disconnect +** +** Description Action routine for processing the CCH disconnect indication +** +** Returns void +** +*******************************************************************************/ +void bta_hl_cch_mca_disconnect(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data) +{ + + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb; + UINT8 i; +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG0("bta_hl_cch_mca_disconnect"); +#endif + + p_mcb->intentional_close = FALSE; + if (p_data->mca_evt.mca_data.disconnect_ind.reason == L2CAP_DISC_OK) + { + p_mcb->intentional_close = TRUE; + } + + for (i=0; i< BTA_HL_NUM_MDLS_PER_MCL; i++) + { + p_dcb= BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, i); + if (p_dcb->in_use && (p_dcb->dch_state != BTA_HL_DCH_IDLE_ST)) + { + if (p_mcb->cch_oper == BTA_HL_CCH_OP_LOCAL_CLOSE ) + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, i, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + else + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, i, BTA_HL_MCA_CLOSE_IND_EVT, p_data); + } + } + } + bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_CMPL_EVT, p_data); +} + +/******************************************************************************* +** +** Function bta_hl_cch_mca_rsp_tout +** +** Description Action routine for processing the MCAP response timeout +** +** Returns void +** +*******************************************************************************/ +void bta_hl_cch_mca_rsp_tout(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data) +{ + + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG0("bta_hl_cch_mca_rsp_tout"); +#endif + + p_mcb->rsp_tout = TRUE; + + bta_hl_check_cch_close(app_idx,mcl_idx,p_data,TRUE); +} +/******************************************************************************* +** +** Function bta_hl_cch_mca_connect +** +** Description Action routine for processing the CCH connect indication +** +** Returns void +** +*******************************************************************************/ +void bta_hl_cch_mca_connect(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL evt_data; + tBTA_HL_EVT event; + BOOLEAN send_event=TRUE; + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG0("bta_hl_cch_mca_connect"); +#endif + + p_mcb->mcl_handle = p_data->mca_evt.mcl_handle; + bdcpy(p_mcb->bd_addr, p_data->mca_evt.mca_data.connect_ind.bd_addr); + p_mcb->cch_mtu = p_data->mca_evt.mca_data.connect_ind.mtu; + + bta_sys_conn_open(BTA_ID_HL, p_acb->app_id, p_mcb->bd_addr); + switch (p_mcb->cch_oper) + { + case BTA_HL_CCH_OP_LOCAL_OPEN: + bta_hl_build_cch_open_cfm(&evt_data, p_acb->app_handle, + p_mcb->mcl_handle, + p_mcb->bd_addr, + BTA_HL_STATUS_OK); + event = BTA_HL_CCH_OPEN_CFM_EVT; + break; + case BTA_HL_CCH_OP_REMOTE_OPEN: + bta_hl_build_cch_open_ind(&evt_data, p_acb->app_handle, + p_mcb->mcl_handle, + p_mcb->bd_addr); + event = BTA_HL_CCH_OPEN_IND_EVT; + break; + default: + send_event = FALSE; + break; + } + + p_mcb->cch_oper = BTA_HL_CCH_OP_NONE; + if (send_event) p_acb->p_cback(event,(tBTA_HL *) &evt_data ); +} + +/******************************************************************************* +** +** Function bta_hl_mcap_ctrl_cback +** +** Description MCAP control callback function for HL. +** +** Returns void +** +*******************************************************************************/ +void bta_hl_mcap_ctrl_cback (tMCA_HANDLE handle, tMCA_CL mcl, UINT8 event, + tMCA_CTRL *p_data) +{ + tBTA_HL_MCA_EVT * p_msg; + BOOLEAN send_event=TRUE; + UINT16 mca_event; + +#if (BTA_HL_DEBUG == TRUE) +#if (BT_TRACE_VERBOSE == TRUE) + APPL_TRACE_EVENT1("bta_hl_mcap_ctrl_cback event[%s]",bta_hl_mcap_evt_code(event)); +#else + APPL_TRACE_EVENT1("bta_hl_mcap_ctrl_cback event[0x%02x]", event); +#endif +#endif + + switch (event) + { + + case MCA_CREATE_IND_EVT: + mca_event = (UINT16) BTA_HL_MCA_CREATE_IND_EVT; + break; + case MCA_CREATE_CFM_EVT: + mca_event = (UINT16) BTA_HL_MCA_CREATE_CFM_EVT; + break; + case MCA_RECONNECT_IND_EVT: + mca_event = (UINT16) BTA_HL_MCA_RECONNECT_IND_EVT; + break; + case MCA_RECONNECT_CFM_EVT: + mca_event = (UINT16) BTA_HL_MCA_RECONNECT_CFM_EVT; + break; + case MCA_ABORT_IND_EVT: + mca_event = (UINT16) BTA_HL_MCA_ABORT_IND_EVT; + break; + case MCA_ABORT_CFM_EVT: + mca_event = (UINT16) BTA_HL_MCA_ABORT_CFM_EVT; + break; + case MCA_DELETE_IND_EVT: + mca_event = (UINT16) BTA_HL_MCA_DELETE_IND_EVT; + break; + case MCA_DELETE_CFM_EVT: + mca_event = (UINT16) BTA_HL_MCA_DELETE_CFM_EVT; + break; + case MCA_CONNECT_IND_EVT: + mca_event = (UINT16) BTA_HL_MCA_CONNECT_IND_EVT; + break; + case MCA_DISCONNECT_IND_EVT: + mca_event = (UINT16) BTA_HL_MCA_DISCONNECT_IND_EVT; + break; + case MCA_OPEN_IND_EVT: + mca_event = (UINT16) BTA_HL_MCA_OPEN_IND_EVT; + break; + case MCA_OPEN_CFM_EVT: + mca_event = (UINT16) BTA_HL_MCA_OPEN_CFM_EVT; + break; + case MCA_CLOSE_IND_EVT: + mca_event = (UINT16) BTA_HL_MCA_CLOSE_IND_EVT; + break; + case MCA_CLOSE_CFM_EVT: + mca_event = (UINT16) BTA_HL_MCA_CLOSE_CFM_EVT; + break; + case MCA_CONG_CHG_EVT: + mca_event = (UINT16) BTA_HL_MCA_CONG_CHG_EVT; + break; + case MCA_RSP_TOUT_IND_EVT: + mca_event = (UINT16) BTA_HL_MCA_RSP_TOUT_IND_EVT; + break; + case MCA_ERROR_RSP_EVT: + + default: + send_event=FALSE; + break; + } + + if ((p_msg = (tBTA_HL_MCA_EVT *)GKI_getbuf(sizeof(tBTA_HL_MCA_EVT))) != NULL) + { + p_msg->hdr.event = mca_event; + p_msg->app_handle = (tBTA_HL_APP_HANDLE) handle; + p_msg->mcl_handle = (tBTA_HL_MCL_HANDLE) mcl; + memcpy (&p_msg->mca_data, p_data, sizeof(tMCA_CTRL)); + bta_sys_sendmsg(p_msg); + } +} + + +/******************************************************************************* +** +** Function bta_hl_mcap_data_cback +** +** Description MCAP data callback function for HL. +** +** Returns void +** +*******************************************************************************/ +void bta_hl_mcap_data_cback (tMCA_DL mdl, BT_HDR *p_pkt) +{ + tBTA_HL_MCA_RCV_DATA_EVT *p_msg; + + UINT8 app_idx, mcl_idx, mdl_idx; + if (bta_hl_find_mdl_idx_using_handle ((tBTA_HL_MDL_HANDLE)mdl, &app_idx, &mcl_idx, &mdl_idx)) + { + if ((p_msg = (tBTA_HL_MCA_RCV_DATA_EVT *)GKI_getbuf(sizeof(tBTA_HL_MCA_RCV_DATA_EVT))) != NULL) + { + p_msg->hdr.event = BTA_HL_MCA_RCV_DATA_EVT; + p_msg->app_idx = app_idx; + p_msg->mcl_idx = mcl_idx; + p_msg->mdl_idx = mdl_idx; + p_msg->p_pkt = p_pkt; + bta_sys_sendmsg(p_msg); + } + } +} +/***************************************************************************** +** Debug Functions +*****************************************************************************/ +#if (BTA_HL_DEBUG == TRUE && BT_TRACE_VERBOSE == TRUE) + +/******************************************************************************* +** +** Function bta_hl_mcap_evt_code +** +** Description get the MCAP event string pointer +** +** Returns char * - event string pointer +** +*******************************************************************************/ +static char *bta_hl_mcap_evt_code(UINT8 evt_code) +{ + + switch (evt_code) + { + + case MCA_ERROR_RSP_EVT: + return "MCA_ERROR_RSP_EVT"; + case MCA_CREATE_IND_EVT: + return "MCA_CREATE_IND_EVT"; + case MCA_CREATE_CFM_EVT: + return "MCA_CREATE_CFM_EVT"; + case MCA_RECONNECT_IND_EVT: + return "MCA_RECONNECT_IND_EVT"; + case MCA_RECONNECT_CFM_EVT: + return "MCA_RECONNECT_CFM_EVT"; + case MCA_ABORT_IND_EVT: + return "MCA_ABORT_IND_EVT"; + case MCA_ABORT_CFM_EVT: + return "MCA_ABORT_CFM_EVT"; + case MCA_DELETE_IND_EVT: + return "MCA_DELETE_IND_EVT"; + case MCA_DELETE_CFM_EVT: + return "MCA_DELETE_CFM_EVT"; + + case MCA_CONNECT_IND_EVT: + return "MCA_CONNECT_IND_EVT"; + case MCA_DISCONNECT_IND_EVT: + return "MCA_DISCONNECT_IND_EVT"; + case MCA_OPEN_IND_EVT: + return "MCA_OPEN_IND_EVT"; + case MCA_OPEN_CFM_EVT: + return "MCA_OPEN_CFM_EVT"; + case MCA_CLOSE_IND_EVT: + return "MCA_CLOSE_IND_EVT"; + case MCA_CLOSE_CFM_EVT: + return "MCA_CLOSE_CFM_EVT"; + case MCA_CONG_CHG_EVT: + return "MCA_CONG_CHG_EVT"; + case MCA_RSP_TOUT_IND_EVT: + return "MCA_RSP_TOUT_IND_EVT"; + default: + return "Unknown MCAP event code"; + } +} + + +/******************************************************************************* +** +** Function bta_hl_cback_evt_code +** +** Description get the HDP event string pointer +** +** Returns char * - event string pointer +** +*******************************************************************************/ +static char *bta_hl_cback_evt_code(UINT8 evt_code) +{ + + switch (evt_code) + { + + case BTA_HL_CCH_OPEN_IND_EVT: + return "BTA_HL_CCH_OPEN_IND_EVT"; + case BTA_HL_CCH_OPEN_CFM_EVT: + return "BTA_HL_CCH_OPEN_CFM_EVT"; + case BTA_HL_CCH_CLOSE_IND_EVT: + return "BTA_HL_CCH_CLOSE_IND_EVT"; + case BTA_HL_CCH_CLOSE_CFM_EVT: + return "BTA_HL_CCH_CLOSE_CFM_EVT"; + case BTA_HL_DCH_OPEN_IND_EVT: + return "BTA_HL_DCH_OPEN_IND_EVT"; + case BTA_HL_DCH_OPEN_CFM_EVT: + return "BTA_HL_DCH_OPEN_CFM_EVT"; + case BTA_HL_DCH_CLOSE_IND_EVT: + return "BTA_HL_DCH_CLOSE_IND_EVT"; + case BTA_HL_DCH_CLOSE_CFM_EVT: + return "BTA_HL_DCH_CLOSE_CFM_EVT"; + case BTA_HL_DCH_RCV_DATA_IND_EVT: + return "BTA_HL_DCH_RCV_DATA_IND_EVT"; + case BTA_HL_REGISTER_CFM_EVT: + return "BTA_HL_REGISTER_CFM_EVT"; + case BTA_HL_DEREGISTER_CFM_EVT: + return "BTA_HL_DEREGISTER_CFM_EVT"; + case BTA_HL_DCH_RECONNECT_CFM_EVT: + return "BTA_HL_DCH_RECONNECT_CFM_EVT"; + case BTA_HL_DCH_RECONNECT_IND_EVT: + return "BTA_HL_DCH_RECONNECT_IND_EVT"; + case BTA_HL_DCH_ECHO_TEST_CFM_EVT: + return "BTA_HL_DCH_ECHO_TEST_CFM_EVT"; + case BTA_HL_SDP_QUERY_CFM_EVT: + return "BTA_HL_SDP_QUERY_CFM_EVT"; + case BTA_HL_CONG_CHG_IND_EVT: + return "BTA_HL_CONG_CHG_IND_EVT"; + case BTA_HL_DCH_CREATE_IND_EVT: + return "BTA_HL_DCH_CREATE_IND_EVT"; + case BTA_HL_DELETE_MDL_IND_EVT: + return "BTA_HL_DELETE_MDL_IND_EVT"; + case BTA_HL_DELETE_MDL_CFM_EVT: + return "BTA_HL_DELETE_MDL_CFM_EVT"; + case BTA_HL_DCH_ABORT_IND_EVT: + return "BTA_HL_DCH_ABORT_IND_EVT"; + case BTA_HL_DCH_ABORT_CFM_EVT: + return "BTA_HL_DCH_ABORT_CFM_EVT"; + default: + return "Unknown HDP event code"; + } +} + + + +/******************************************************************************* +** +** Function bta_hl_dch_oper_code +** +** Description Get the DCH operation string +** +** Returns char * - DCH operation string pointer +** +*******************************************************************************/ +static char *bta_hl_dch_oper_code(tBTA_HL_DCH_OPER oper_code) +{ + + switch (oper_code) + { + case BTA_HL_DCH_OP_NONE: + return "BTA_HL_DCH_OP_NONE"; + case BTA_HL_DCH_OP_REMOTE_CREATE: + return "BTA_HL_DCH_OP_REMOTE_CREATE"; + case BTA_HL_DCH_OP_LOCAL_OPEN: + return "BTA_HL_DCH_OP_LOCAL_OPEN"; + case BTA_HL_DCH_OP_REMOTE_OPEN: + return "BTA_HL_DCH_OP_REMOTE_OPEN"; + case BTA_HL_DCH_OP_LOCAL_CLOSE: + return "BTA_HL_DCH_OP_LOCAL_CLOSE"; + case BTA_HL_DCH_OP_REMOTE_CLOSE: + return "BTA_HL_DCH_OP_REMOTE_CLOSE"; + case BTA_HL_DCH_OP_LOCAL_DELETE: + return "BTA_HL_DCH_OP_LOCAL_DELETE"; + case BTA_HL_DCH_OP_REMOTE_DELETE: + return "BTA_HL_DCH_OP_REMOTE_DELETE"; + case BTA_HL_DCH_OP_LOCAL_RECONNECT: + return "BTA_HL_DCH_OP_LOCAL_RECONNECT"; + case BTA_HL_DCH_OP_REMOTE_RECONNECT: + return "BTA_HL_DCH_OP_REMOTE_RECONNECT"; + case BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST: + return "BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST"; + case BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT: + return "BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT"; + default: + return "Unknown DCH oper code"; + } +} + + +#endif /* Debug Functions */ +#endif /* HL_INCLUDED */ diff --git a/bta/hl/bta_hl_api.c b/bta/hl/bta_hl_api.c new file mode 100644 index 0000000..65ab7bd --- /dev/null +++ b/bta/hl/bta_hl_api.c @@ -0,0 +1,472 @@ +/***************************************************************************** +** +** Name: bta_hl_api.c +** +** Description: This is the implementation of the API for the HeaLth +** device profile (HL) subsystem of BTA, Broadcom Corp's Bluetooth +** application layer for mobile phones. +** +** Copyright (c) 2009-2011 Broadcom Corp., All Rights Reserved. +** Broadcom Bluetooth Core. Proprietary and confidential. +** +*****************************************************************************/ + +#include <string.h> + +#include "bt_target.h" +#if defined(HL_INCLUDED) && (HL_INCLUDED == TRUE) + +#include "gki.h" +#include "bd.h" +#include "bta_hl_api.h" +#include "bta_hl_int.h" + +/***************************************************************************** +** Constants +*****************************************************************************/ + +static const tBTA_SYS_REG bta_hl_reg = +{ + bta_hl_hdl_event, + BTA_HlDisable +}; + +/******************************************************************************* +** +** Function BTA_HlEnable +** +** Description Enable the HL subsystems. This function must be +** called before any other functions in the HL API are called. +** When the enable operation is completed the callback function +** will be called with an BTA_HL_CTRL_ENABLE_CFM_EVT event. +** +** Parameters p_cback - HL event call back function +** +** Returns void +** +*******************************************************************************/ +void BTA_HlEnable(tBTA_HL_CTRL_CBACK *p_ctrl_cback) +{ + tBTA_HL_API_ENABLE *p_buf; + + /* register with BTA system manager */ + GKI_sched_lock(); + bta_sys_register(BTA_ID_HL, &bta_hl_reg); + GKI_sched_unlock(); + + if ((p_buf = (tBTA_HL_API_ENABLE *)GKI_getbuf(sizeof(tBTA_HL_API_ENABLE))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_ENABLE_EVT; + p_buf->p_cback = p_ctrl_cback; + bta_sys_sendmsg(p_buf); + } +} + +/******************************************************************************* +** +** Function BTA_HlDisable +** +** Description Disable the HL subsystem. +** +** Returns void +** +*******************************************************************************/ +void BTA_HlDisable(void) +{ + BT_HDR *p_buf; + + bta_sys_deregister(BTA_ID_HL); + if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR))) != NULL) + { + p_buf->event = BTA_HL_API_DISABLE_EVT; + bta_sys_sendmsg(p_buf); + } +} + +/******************************************************************************* +** +** Function BTA_HlRegister +** +** Description Register an HDP application +** +** Parameters app_id - Application ID +** p_reg_param - non-platform related parameters for the +** HDP application +** p_cback - HL event callback fucntion +** +** Returns void +** +*******************************************************************************/ +void BTA_HlRegister(UINT8 app_id, + tBTA_HL_REG_PARAM *p_reg_param, + tBTA_HL_CBACK *p_cback) +{ + tBTA_HL_API_REGISTER *p_buf; + + if ((p_buf = (tBTA_HL_API_REGISTER *)GKI_getbuf((UINT16)sizeof(tBTA_HL_API_REGISTER))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_REGISTER_EVT; + p_buf->app_id = app_id; + p_buf->sec_mask = (p_reg_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); + p_buf->p_cback = p_cback; + if (p_reg_param->p_srv_name) + { + BCM_STRNCPY_S(p_buf->srv_name, sizeof(p_buf->srv_name), + p_reg_param->p_srv_name, BTA_SERVICE_NAME_LEN); + p_buf->srv_name[BTA_SERVICE_NAME_LEN] = '\0'; + } + else + p_buf->srv_name[0]= '\0'; + + if (p_reg_param->p_srv_desp) + { + BCM_STRNCPY_S(p_buf->srv_desp, sizeof(p_buf->srv_desp), + p_reg_param->p_srv_desp, BTA_SERVICE_DESP_LEN); + p_buf->srv_desp[BTA_SERVICE_DESP_LEN]= '\0'; + } + else + p_buf->srv_desp[0]= '\0'; + + if (p_reg_param->p_provider_name) + { + BCM_STRNCPY_S(p_buf->provider_name, sizeof(p_buf->provider_name), + p_reg_param->p_provider_name, BTA_PROVIDER_NAME_LEN); + p_buf->provider_name[BTA_PROVIDER_NAME_LEN]= '\0'; + } + else + p_buf->provider_name[0]= '\0'; + + bta_sys_sendmsg(p_buf); + } +} + +/******************************************************************************* +** +** Function BTA_HlDeregister +** +** Description Deregister an HDP application +** +** Parameters app_handle - Application handle +** +** Returns void +** +*******************************************************************************/ +void BTA_HlDeregister(tBTA_HL_APP_HANDLE app_handle) +{ + tBTA_HL_API_DEREGISTER *p_buf; + + if ((p_buf = (tBTA_HL_API_DEREGISTER *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DEREGISTER)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_DEREGISTER_EVT; + p_buf->app_handle = app_handle; + bta_sys_sendmsg(p_buf); + } +} +/******************************************************************************* +** +** Function BTA_HlCchOpen +** +** Description Open a Control channel connection with the specified BD address +** +** Parameters app_handle - Application Handle +** p_open_param - parameters for opening a control channel +** +** Returns void +** +** Note: The control PSM value is used to select which +** HDP insatnce should be used in case the peer device support +** multiple HDP instances. Also, if the control PSM value is zero +** then the first HDP instance is used for the control channel setup +*******************************************************************************/ +void BTA_HlCchOpen(tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_CCH_OPEN_PARAM *p_open_param) +{ + tBTA_HL_API_CCH_OPEN *p_buf; + + if ((p_buf = (tBTA_HL_API_CCH_OPEN *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_CCH_OPEN)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_CCH_OPEN_EVT; + p_buf->app_handle = app_handle; + p_buf->sec_mask = (p_open_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); + bdcpy(p_buf->bd_addr, p_open_param->bd_addr); + p_buf->ctrl_psm = p_open_param->ctrl_psm; + bta_sys_sendmsg(p_buf); + } +} + +/******************************************************************************* +** +** Function BTA_HlCchClose +** +** Description Close a Control channel connection with the specified MCL +** handle +** +** Parameters mcl_handle - MCL handle +** +** Returns void +** +*******************************************************************************/ +void BTA_HlCchClose(tBTA_HL_MCL_HANDLE mcl_handle) +{ + tBTA_HL_API_CCH_CLOSE *p_buf; + + if ((p_buf = (tBTA_HL_API_CCH_CLOSE *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_CCH_CLOSE)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_CCH_CLOSE_EVT; + p_buf->mcl_handle = mcl_handle; + bta_sys_sendmsg(p_buf); + } +} + +/******************************************************************************* +** +** Function BTA_HlDchOpen +** +** Description Open a data channel connection with the specified DCH parameters +** +** Parameters mcl_handle - MCL handle +** p_open_param - parameters for opening a data channel +** +** Returns void +** +*******************************************************************************/ +void BTA_HlDchOpen(tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_DCH_OPEN_PARAM *p_open_param) +{ + tBTA_HL_API_DCH_OPEN *p_buf; + + if ((p_buf = (tBTA_HL_API_DCH_OPEN *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_OPEN)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_DCH_OPEN_EVT; + p_buf->mcl_handle = mcl_handle; + p_buf->ctrl_psm = p_open_param->ctrl_psm; + p_buf->local_mdep_id = p_open_param->local_mdep_id; + p_buf->peer_mdep_id = p_open_param->peer_mdep_id; + p_buf->local_cfg = p_open_param->local_cfg; + p_buf->sec_mask = (p_open_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); + bta_sys_sendmsg(p_buf); + } +} + +/******************************************************************************* +** +** Function BTA_HlDchReconnect +** +** Description Reconnect a data channel with the specified MDL_ID +** +** Parameters mcl_handle - MCL handle +*8 p_recon_param - parameters for reconnecting a data channel +** +** Returns void +** +*******************************************************************************/ +void BTA_HlDchReconnect(tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_DCH_RECONNECT_PARAM *p_recon_param) +{ + tBTA_HL_API_DCH_RECONNECT *p_buf; + + if ((p_buf = (tBTA_HL_API_DCH_RECONNECT *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_RECONNECT)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_DCH_RECONNECT_EVT; + p_buf->mcl_handle = mcl_handle; + p_buf->ctrl_psm = p_recon_param->ctrl_psm; + p_buf->mdl_id = p_recon_param->mdl_id; + bta_sys_sendmsg(p_buf); + } +} + +/******************************************************************************* +** +** Function BTA_HlDchClose +** +** Description Close a data channel with the specified MDL handle +** +** Parameters mdl_handle - MDL handle +** +** Returns void +** +*******************************************************************************/ +void BTA_HlDchClose(tBTA_HL_MDL_HANDLE mdl_handle) +{ + tBTA_HL_API_DCH_CLOSE *p_buf; + + if ((p_buf = (tBTA_HL_API_DCH_CLOSE *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_CLOSE)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_DCH_CLOSE_EVT; + p_buf->mdl_handle = mdl_handle; + bta_sys_sendmsg(p_buf); + } +} + +/******************************************************************************* +** +** Function BTA_HlDchAbort +** +** Description Abort the current data channel setup with the specified MCL +** handle +** +** Parameters mcl_handle - MCL handle +** +** +** Returns void +** +*******************************************************************************/ +void BTA_HlDchAbort(tBTA_HL_MCL_HANDLE mcl_handle) +{ + tBTA_HL_API_DCH_ABORT *p_buf; + + if ((p_buf = (tBTA_HL_API_DCH_ABORT *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_ABORT)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_DCH_ABORT_EVT; + p_buf->mcl_handle = mcl_handle; + bta_sys_sendmsg(p_buf); + } +} + +/******************************************************************************* +** +** Function BTA_HlSendData +** +** Description Send an APDU to the peer device +** +** Parameters mdl_handle - MDL handle +** pkt_size - size of the data packet to be sent +** +** Returns void +** +*******************************************************************************/ +void BTA_HlSendData(tBTA_HL_MDL_HANDLE mdl_handle, + UINT16 pkt_size) +{ + tBTA_HL_API_SEND_DATA *p_buf = NULL; + + if ((p_buf = (tBTA_HL_API_SEND_DATA *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_SEND_DATA)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_SEND_DATA_EVT; + p_buf->mdl_handle = mdl_handle; + p_buf->pkt_size = pkt_size; + bta_sys_sendmsg(p_buf); + } + +} + +/******************************************************************************* +** +** Function BTA_HlDeleteMdl +** +** Description Delete the specified MDL_ID within the specified MCL handle +** +** Parameters mcl_handle - MCL handle +** mdl_id - MDL ID +** +** Returns void +** +** note: If mdl_id = 0xFFFF then this means to delete all MDLs +** and this value can only be used with DeleteMdl request only +** not other requests +** +*******************************************************************************/ +void BTA_HlDeleteMdl(tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_ID mdl_id ) +{ + tBTA_HL_API_DELETE_MDL *p_buf; + + if ((p_buf = (tBTA_HL_API_DELETE_MDL *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DELETE_MDL)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_DELETE_MDL_EVT; + p_buf->mcl_handle = mcl_handle; + p_buf->mdl_id = mdl_id; + bta_sys_sendmsg(p_buf); + } +} + +/******************************************************************************* +** +** Function BTA_HlDchEchoTest +** +** Description Initiate an echo test with the specified MCL handle +** +** Parameters mcl_handle - MCL handle +*8 p_echo_test_param - parameters for echo testing +** +** Returns void +** +*******************************************************************************/ +void BTA_HlDchEchoTest( tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_DCH_ECHO_TEST_PARAM *p_echo_test_param) +{ + tBTA_HL_API_DCH_ECHO_TEST *p_buf; + + if ((p_buf = (tBTA_HL_API_DCH_ECHO_TEST *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_ECHO_TEST)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_DCH_ECHO_TEST_EVT; + p_buf->mcl_handle = mcl_handle; + p_buf->ctrl_psm = p_echo_test_param->ctrl_psm; + p_buf->local_cfg = p_echo_test_param->local_cfg; + p_buf->pkt_size = p_echo_test_param->pkt_size; + bta_sys_sendmsg(p_buf); + } +} + + +/******************************************************************************* +** +** Function BTA_HlSdpQuery +** +** Description SDP query request for the specified BD address +** +** Parameters app_handle - application handle +** bd_addr - BD address +** +** Returns void +** +*******************************************************************************/ +void BTA_HlSdpQuery(tBTA_HL_APP_HANDLE app_handle, + BD_ADDR bd_addr) +{ + tBTA_HL_API_SDP_QUERY *p_buf; + + if ((p_buf = (tBTA_HL_API_SDP_QUERY *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_SDP_QUERY)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_SDP_QUERY_EVT; + p_buf->app_handle = app_handle; + bdcpy(p_buf->bd_addr, bd_addr); + bta_sys_sendmsg(p_buf); + } +} + + +/******************************************************************************* +** +** Function BTA_HlDchCreateMdlRsp +** +** Description Set the Response and configuration values for the Create MDL +** request +** +** Parameters mcl_handle - MCL handle +** p_rsp_param - parameters specified whether the request should +** be accepted or not and if it should be accepted +** then it also specified the configuration response +** value +** +** Returns void +** +*******************************************************************************/ +void BTA_HlDchCreateRsp(tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_DCH_CREATE_RSP_PARAM *p_rsp_param) +{ + tBTA_HL_API_DCH_CREATE_RSP *p_buf; + + if ((p_buf = (tBTA_HL_API_DCH_CREATE_RSP *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_CREATE_RSP)))) != NULL) + { + p_buf->hdr.event = BTA_HL_API_DCH_CREATE_RSP_EVT; + p_buf->mcl_handle = mcl_handle; + p_buf->mdl_id = p_rsp_param->mdl_id; + p_buf->local_mdep_id = p_rsp_param->local_mdep_id; + p_buf->rsp_code = p_rsp_param->rsp_code; + p_buf->cfg_rsp = p_rsp_param->cfg_rsp; + bta_sys_sendmsg(p_buf); + } +} + +#endif /* HL_INCLUDED */ diff --git a/bta/hl/bta_hl_ci.c b/bta/hl/bta_hl_ci.c new file mode 100644 index 0000000..aab858f --- /dev/null +++ b/bta/hl/bta_hl_ci.c @@ -0,0 +1,158 @@ +/***************************************************************************** +** +** Name: bta_hl_ci.c +** +** Description: This is the implementation file for the HeaLth device profile +** (HL) subsystem call-in functions. +** +** Copyright (c) 2009, Broadcom Corp., All Rights Reserved. +** Broadcom Bluetooth Core. Proprietary and confidential. +** +*****************************************************************************/ +#include "bta_api.h" +#include "btm_api.h" +#include "bta_sys.h" +#include "bta_hl_api.h" +#include "bta_hl_co.h" +#include "bta_hl_int.h" + +/******************************************************************************* +** +** Function bta_hl_ci_get_tx_data +** +** Description This function is called in response to the +** bta_hl_co_get_tx_data call-out function. +** +** Parameters mdl_handle -MDL handle +** status - BTA_MA_STATUS_OK if operation is successful +** BTA_MA_STATUS_FAIL if any errors have occurred. +** evt - evt from the call-out function +** +** Returns void +** +*******************************************************************************/ +BTA_API extern void bta_hl_ci_get_tx_data( tBTA_HL_MDL_HANDLE mdl_handle, + tBTA_HL_STATUS status, + UINT16 evt ) +{ + tBTA_HL_CI_GET_PUT_DATA *p_evt; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG3("bta_hl_ci_get_tx_data mdl_handle=%d status=%d evt=%d\n", + mdl_handle, status, evt); +#endif + + if ((p_evt = (tBTA_HL_CI_GET_PUT_DATA *)GKI_getbuf(sizeof(tBTA_HL_CI_GET_PUT_DATA))) != NULL) + { + p_evt->hdr.event = evt; + p_evt->mdl_handle = mdl_handle; + p_evt->status = status; + bta_sys_sendmsg(p_evt); + } +} + +/******************************************************************************* +** +** Function bta_hl_ci_put_rx_data +** +** Description This function is called in response to the +** bta_hl_co_put_rx_data call-out function. +** +** Parameters mdl_handle -MDL handle +** status - BTA_MA_STATUS_OK if operation is successful +** BTA_MA_STATUS_FAIL if any errors have occurred. +** evt - evt from the call-out function +** +** Returns void +** +*******************************************************************************/ +BTA_API extern void bta_hl_ci_put_rx_data( tBTA_HL_MDL_HANDLE mdl_handle, + tBTA_HL_STATUS status, + UINT16 evt ) +{ + tBTA_HL_CI_GET_PUT_DATA *p_evt; +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG3("bta_hl_ci_put_rx_data mdl_handle=%d status=%d evt=%d\n", + mdl_handle, status, evt); +#endif + + if ((p_evt = (tBTA_HL_CI_GET_PUT_DATA *)GKI_getbuf(sizeof(tBTA_HL_CI_GET_PUT_DATA))) != NULL) + { + p_evt->hdr.event = evt; + p_evt->mdl_handle = mdl_handle; + p_evt->status = status; + bta_sys_sendmsg(p_evt); + } +} + + +/******************************************************************************* +** +** Function bta_hl_ci_get_echo_data +** +** Description This function is called in response to the +** bta_hl_co_get_echo_data call-out function. +** +** Parameters mcl_handle -MCL handle +** status - BTA_MA_STATUS_OK if operation is successful +** BTA_MA_STATUS_FAIL if any errors have occurred. +** evt - evt from the call-out function +** +** Returns void +** +*******************************************************************************/ +BTA_API extern void bta_hl_ci_get_echo_data( tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_STATUS status, + UINT16 evt ) +{ + tBTA_HL_CI_ECHO_DATA *p_evt; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG3("bta_hl_ci_get_echo_data mcl_handle=%d status=%d evt=%d\n", + mcl_handle, status, evt); +#endif + + if ((p_evt = (tBTA_HL_CI_ECHO_DATA *)GKI_getbuf(sizeof(tBTA_HL_CI_ECHO_DATA))) != NULL) + { + p_evt->hdr.event = evt; + p_evt->mcl_handle = mcl_handle; + p_evt->status = status; + bta_sys_sendmsg(p_evt); + } +} + +/******************************************************************************* +** +** Function bta_hl_ci_put_echo_data +** +** Description This function is called in response to the +** bta_hl_co_put_echo_data call-out function. +** +** Parameters mcl_handle -MCL handle +** status - BTA_MA_STATUS_OK if operation is successful +** BTA_MA_STATUS_FAIL if any errors have occurred. +** evt - evt from the call-out function +** +** Returns void +** +*******************************************************************************/ +BTA_API extern void bta_hl_ci_put_echo_data( tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_STATUS status, + UINT16 evt ) +{ + tBTA_HL_CI_ECHO_DATA *p_evt; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG3("bta_hl_ci_put_echo_data mcl_handle=%d status=%d evt=%d\n", + mcl_handle, status, evt); +#endif + + if ((p_evt = (tBTA_HL_CI_ECHO_DATA *)GKI_getbuf(sizeof(tBTA_HL_CI_ECHO_DATA))) != NULL) + { + p_evt->hdr.event = evt; + p_evt->mcl_handle = mcl_handle; + p_evt->status = status; + bta_sys_sendmsg(p_evt); + } +} + diff --git a/bta/hl/bta_hl_int.h b/bta/hl/bta_hl_int.h new file mode 100644 index 0000000..03805d4 --- /dev/null +++ b/bta/hl/bta_hl_int.h @@ -0,0 +1,845 @@ +/***************************************************************************** +** +** Name: bta_hl_int.h +** +** Description: This is the private file for the message access +** equipment (MSE) subsystem. +** +** Copyright (c) 1998-2009, Broadcom Corp., All Rights Reserved. +** Broadcom Bluetooth Core. Proprietary and confidential. +** +*****************************************************************************/ +#ifndef BTA_HL_INT_H +#define BTA_HL_INT_H + +#include "bt_target.h" +#include "bta_sys.h" +#include "obx_api.h" +#include "bta_hl_api.h" +#include "bta_hl_co.h" +#include "l2cdefs.h" + + +typedef UINT16 (tBTA_HL_ALLOCATE_PSM) (void); + +/***************************************************************************** +** Constants and data types +*****************************************************************************/ + +#ifndef BTA_HL_DISC_SIZE +#define BTA_HL_DISC_SIZE 1600 +#endif +#define BTA_HL_NUM_SRCH_ATTR 10 +#define BTA_HL_MIN_SDP_MDEP_LEN 7 + +/* L2CAP defualt parameters */ +#define BTA_HL_L2C_TX_WIN_SIZE 10 +#define BTA_HL_L2C_MAX_TRANSMIT 32 +#define BTA_HL_L2C_RTRANS_TOUT 2000 +#define BTA_HL_L2C_MON_TOUT 12000 +#define BTA_HL_L2C_MPS 1017 +#define BTA_HL_L2C_USER_RX_POOL_ID L2CAP_DEFAULT_ERM_POOL_ID +#define BTA_HL_L2C_USER_TX_POOL_ID L2CAP_DEFAULT_ERM_POOL_ID /* todo this should be based on data type */ +#define BTA_HL_L2C_FCR_RX_POOL_ID L2CAP_DEFAULT_ERM_POOL_ID +#define BTA_HL_L2C_FCR_TX_POOL_ID L2CAP_DEFAULT_ERM_POOL_ID + +/* L2CAP FCS setting*/ +#define BTA_HL_MCA_USE_FCS MCA_FCS_USE +#define BTA_HL_MCA_NO_FCS MCA_FCS_BYPASS +#define BTA_HL_L2C_USE_FCS 1 +#define BTA_HL_L2C_NO_FCS 0 +#define BTA_HL_DEFAULT_SOURCE_FCS BTA_HL_L2C_USE_FCS + +/* SDP Operations */ +#define BTA_HL_SDP_OP_NONE 0 +#define BTA_HL_SDP_OP_CCH_INIT 1 +#define BTA_HL_SDP_OP_DCH_OPEN_INIT 2 +#define BTA_HL_SDP_OP_DCH_RECONNECT_INIT 3 +#define BTA_HL_SDP_OP_SDP_QUERY_NEW 4 +#define BTA_HL_SDP_OP_SDP_QUERY_CURRENT 5 + +typedef UINT8 tBTA_HL_SDP_OPER; + +/* CCH Operations */ +#define BTA_HL_CCH_OP_NONE 0 +#define BTA_HL_CCH_OP_LOCAL_OPEN 1 +#define BTA_HL_CCH_OP_REMOTE_OPEN 2 +#define BTA_HL_CCH_OP_LOCAL_CLOSE 3 +#define BTA_HL_CCH_OP_REMOTE_CLOSE 4 + +typedef UINT8 tBTA_HL_CCH_OPER; + +/* Pending DCH close operations when closing a CCH */ +#define BTA_HL_CCH_CLOSE_OP_DCH_NONE 0 +#define BTA_HL_CCH_CLOSE_OP_DCH_ABORT 1 +#define BTA_HL_CCH_CLOSE_OP_DCH_CLOSE 2 +typedef UINT8 tBTA_HL_CCH_CLOSE_DCH_OPER; + +/* DCH Operations */ +#define BTA_HL_DCH_OP_NONE 0 +#define BTA_HL_DCH_OP_REMOTE_CREATE 1 +#define BTA_HL_DCH_OP_LOCAL_OPEN 2 +#define BTA_HL_DCH_OP_REMOTE_OPEN 3 +#define BTA_HL_DCH_OP_LOCAL_CLOSE 4 +#define BTA_HL_DCH_OP_REMOTE_CLOSE 5 +#define BTA_HL_DCH_OP_LOCAL_DELETE 6 +#define BTA_HL_DCH_OP_REMOTE_DELETE 7 +#define BTA_HL_DCH_OP_LOCAL_RECONNECT 8 +#define BTA_HL_DCH_OP_REMOTE_RECONNECT 9 +#define BTA_HL_DCH_OP_LOCAL_CLOSE_ECHO_TEST 10 +#define BTA_HL_DCH_OP_LOCAL_CLOSE_RECONNECT 11 + +typedef UINT8 tBTA_HL_DCH_OPER; + +/* Echo test Operations */ +#define BTA_HL_ECHO_OP_NONE 0 +#define BTA_HL_ECHO_OP_CI_GET_ECHO_DATA 1 +#define BTA_HL_ECHO_OP_SDP_INIT 2 +#define BTA_HL_ECHO_OP_MDL_CREATE_CFM 3 +#define BTA_HL_ECHO_OP_DCH_OPEN_CFM 4 +#define BTA_HL_ECHO_OP_LOOP_BACK 5 +#define BTA_HL_ECHO_OP_CI_PUT_ECHO_DATA 6 +#define BTA_HL_ECHO_OP_DCH_CLOSE_CFM 7 +#define BTA_HL_ECHO_OP_OPEN_IND 8 +#define BTA_HL_ECHO_OP_ECHO_PKT 9 + +typedef UINT8 tBTA_HL_ECHO_OPER; + +/* abort status mask for abort_oper */ + +#define BTA_HL_ABORT_NONE_MASK 0x00 +#define BTA_HL_ABORT_PENDING_MASK 0x01 +#define BTA_HL_ABORT_LOCAL_MASK 0x10 +#define BTA_HL_ABORT_REMOTE_MASK 0x20 +#define BTA_HL_ABORT_CCH_CLOSE_MASK 0x40 + +/* call out mask for cout_oper */ +#define BTA_HL_CO_NONE_MASK 0x00 +#define BTA_HL_CO_GET_TX_DATA_MASK 0x01 +#define BTA_HL_CO_PUT_RX_DATA_MASK 0x02 +#define BTA_HL_CO_GET_ECHO_DATA_MASK 0x04 +#define BTA_HL_CO_PUT_ECHO_DATA_MASK 0x08 + +typedef struct +{ + UINT16 mtu; + UINT8 fcs; /* '0' No FCS, otherwise '1' */ +} tBTA_HL_L2CAP_CFG_INFO; + + +/* State Machine Events */ +enum +{ + /* these events are handled by the state machine */ + BTA_HL_CCH_OPEN_EVT = BTA_SYS_EVT_START(BTA_ID_HL), + BTA_HL_CCH_SDP_OK_EVT, + BTA_HL_CCH_SDP_FAIL_EVT, + BTA_HL_MCA_CONNECT_IND_EVT, + BTA_HL_MCA_DISCONNECT_IND_EVT, + BTA_HL_CCH_CLOSE_EVT, + BTA_HL_CCH_CLOSE_CMPL_EVT, + BTA_HL_MCA_RSP_TOUT_IND_EVT, + /* DCH EVENT */ + BTA_HL_DCH_SDP_INIT_EVT, + BTA_HL_DCH_OPEN_EVT, + BTA_HL_MCA_CREATE_IND_EVT, + BTA_HL_MCA_CREATE_CFM_EVT, + BTA_HL_MCA_OPEN_IND_EVT, + + BTA_HL_MCA_OPEN_CFM_EVT, + BTA_HL_DCH_CLOSE_EVT, + BTA_HL_MCA_CLOSE_IND_EVT, + BTA_HL_MCA_CLOSE_CFM_EVT, + BTA_HL_API_SEND_DATA_EVT, + + BTA_HL_MCA_RCV_DATA_EVT, + BTA_HL_DCH_CLOSE_CMPL_EVT, + BTA_HL_DCH_RECONNECT_EVT, + BTA_HL_DCH_SDP_FAIL_EVT, + BTA_HL_MCA_RECONNECT_IND_EVT, + + BTA_HL_MCA_RECONNECT_CFM_EVT, + BTA_HL_DCH_CLOSE_ECHO_TEST_EVT, + BTA_HL_API_DCH_CREATE_RSP_EVT, + BTA_HL_DCH_ABORT_EVT, + BTA_HL_MCA_ABORT_IND_EVT, + + BTA_HL_MCA_ABORT_CFM_EVT, + BTA_HL_MCA_CONG_CHG_EVT, + BTA_HL_CI_GET_TX_DATA_EVT, + BTA_HL_CI_PUT_RX_DATA_EVT, + BTA_HL_CI_GET_ECHO_DATA_EVT, + BTA_HL_DCH_ECHO_TEST_EVT, + BTA_HL_CI_PUT_ECHO_DATA_EVT, + + /* these events are handled outside the state machine */ + BTA_HL_API_ENABLE_EVT, + BTA_HL_API_DISABLE_EVT, + BTA_HL_API_REGISTER_EVT, + BTA_HL_API_DEREGISTER_EVT, + BTA_HL_API_CCH_OPEN_EVT, + BTA_HL_API_CCH_CLOSE_EVT, + BTA_HL_API_DCH_OPEN_EVT, + BTA_HL_API_DCH_RECONNECT_EVT, + BTA_HL_API_DCH_CLOSE_EVT, + BTA_HL_API_DELETE_MDL_EVT, + BTA_HL_API_DCH_ABORT_EVT, + + BTA_HL_API_DCH_ECHO_TEST_EVT, + BTA_HL_API_SDP_QUERY_EVT, + BTA_HL_SDP_QUERY_OK_EVT, + BTA_HL_SDP_QUERY_FAIL_EVT, + BTA_HL_MCA_DELETE_IND_EVT, + BTA_HL_MCA_DELETE_CFM_EVT +}; +typedef UINT16 tBTA_HL_INT_EVT; + +#define BTA_HL_DCH_EVT_MIN BTA_HL_DCH_SDP_INIT_EVT +#define BTA_HL_DCH_EVT_MAX 0xFFFF + + +/* state machine states */ +enum +{ + BTA_HL_CCH_IDLE_ST = 0, /* Idle */ + BTA_HL_CCH_OPENING_ST, /* Opening a connection*/ + BTA_HL_CCH_OPEN_ST, /* Connection is open */ + BTA_HL_CCH_CLOSING_ST /* Closing is in progress */ +}; +typedef UINT8 tBTA_HL_CCH_STATE; + +enum +{ + BTA_HL_DCH_IDLE_ST = 0, /* Idle */ + BTA_HL_DCH_OPENING_ST, /* Opening a connection*/ + BTA_HL_DCH_OPEN_ST, /* Connection is open */ + BTA_HL_DCH_CLOSING_ST /* Closing is in progress */ +}; +typedef UINT8 tBTA_HL_DCH_STATE; + + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_CTRL_CBACK *p_cback; /* pointer to control callback function */ +} tBTA_HL_API_ENABLE; + +typedef struct +{ + BT_HDR hdr; + UINT8 app_id; + tBTA_HL_CBACK *p_cback; /* pointer to application callback function */ + tBTA_HL_DEVICE_TYPE dev_type; /* sink, source or dual roles */ + tBTA_SEC sec_mask; /* security mask for accepting conenction*/ + char srv_name[BTA_SERVICE_NAME_LEN +1]; /* service name to be used in the SDP; null terminated*/ + char srv_desp[BTA_SERVICE_DESP_LEN +1]; /* service description to be used in the SDP; null terminated */ + char provider_name[BTA_PROVIDER_NAME_LEN +1]; /* provide name to be used in the SDP; null terminated */ +} tBTA_HL_API_REGISTER; + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_APP_HANDLE app_handle; +} tBTA_HL_API_DEREGISTER; + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_APP_HANDLE app_handle; + UINT16 ctrl_psm; + BD_ADDR bd_addr; /* Address of peer device */ + tBTA_SEC sec_mask; /* security mask for initiating connection*/ +} tBTA_HL_API_CCH_OPEN; + + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_MCL_HANDLE mcl_handle; +} tBTA_HL_API_CCH_CLOSE; + + + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_MCL_HANDLE mcl_handle; + UINT16 ctrl_psm; + tBTA_HL_MDEP_ID local_mdep_id; /* local MDEP ID */ + tBTA_HL_MDEP_ID peer_mdep_id; /* peer mdep id */ + tBTA_HL_DCH_CFG local_cfg; + tBTA_SEC sec_mask; /* security mask for initiating connection*/ +} tBTA_HL_API_DCH_OPEN; + + +typedef struct +{ + BT_HDR hdr; + + tBTA_HL_MCL_HANDLE mcl_handle; + UINT16 ctrl_psm; + tBTA_HL_MDL_ID mdl_id; +} tBTA_HL_API_DCH_RECONNECT; + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_MDL_HANDLE mdl_handle; +} tBTA_HL_API_DCH_CLOSE; + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_MCL_HANDLE mcl_handle; + tBTA_HL_MDL_ID mdl_id; +} tBTA_HL_API_DELETE_MDL; + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_MCL_HANDLE mcl_handle; +} tBTA_HL_API_DCH_ABORT; + + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_MDL_HANDLE mdl_handle; + UINT16 pkt_size; +} tBTA_HL_API_SEND_DATA; + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_MCL_HANDLE mcl_handle; + UINT16 ctrl_psm; + UINT16 pkt_size; + tBTA_HL_DCH_CFG local_cfg; +} tBTA_HL_API_DCH_ECHO_TEST; + +typedef struct +{ + BT_HDR hdr; + UINT8 app_idx; + UINT8 mcl_idx; + BOOLEAN release_mcl_cb; +}tBTA_HL_CCH_SDP; + + +/* MCA callback event parameters. */ +typedef struct +{ + BT_HDR hdr; + tBTA_HL_APP_HANDLE app_handle; + tBTA_HL_MCL_HANDLE mcl_handle; + tMCA_CTRL mca_data; +} tBTA_HL_MCA_EVT; + + +/* MCA callback event parameters. */ +typedef struct +{ + BT_HDR hdr; + UINT8 app_idx; + UINT8 mcl_idx; + UINT8 mdl_idx; + BT_HDR *p_pkt; +} tBTA_HL_MCA_RCV_DATA_EVT; + + +typedef struct +{ + BT_HDR hdr; + UINT8 app_idx; + UINT8 mcl_idx; + UINT8 mdl_idx; +}tBTA_HL_DCH_SDP; + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_APP_HANDLE app_handle; + BD_ADDR bd_addr; /* Address of peer device */ +} tBTA_HL_API_SDP_QUERY; + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_MCL_HANDLE mcl_handle; + tBTA_HL_MDL_ID mdl_id; + tBTA_HL_MDEP_ID local_mdep_id; + tBTA_HL_DCH_CREATE_RSP rsp_code; + tBTA_HL_DCH_CFG cfg_rsp; +} tBTA_HL_API_DCH_CREATE_RSP; + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_MDL_HANDLE mdl_handle; + tBTA_HL_STATUS status; +} tBTA_HL_CI_GET_PUT_DATA; + +typedef struct +{ + BT_HDR hdr; + tBTA_HL_MCL_HANDLE mcl_handle; + tBTA_HL_STATUS status; +} tBTA_HL_CI_ECHO_DATA; + +/* union of all state machine event data types */ +typedef union +{ + BT_HDR hdr; + tBTA_HL_API_ENABLE api_enable; /* data for BTA_MSE_API_ENABLE_EVT */ + tBTA_HL_API_REGISTER api_reg; + tBTA_HL_API_DEREGISTER api_dereg; + tBTA_HL_API_CCH_OPEN api_cch_open; + tBTA_HL_API_CCH_CLOSE api_cch_close; + tBTA_HL_API_DCH_CREATE_RSP api_dch_create_rsp; + tBTA_HL_API_DCH_OPEN api_dch_open; + tBTA_HL_API_DCH_RECONNECT api_dch_reconnect; + tBTA_HL_API_DCH_CLOSE api_dch_close; + tBTA_HL_API_DELETE_MDL api_delete_mdl; + tBTA_HL_API_DCH_ABORT api_dch_abort; + tBTA_HL_API_SEND_DATA api_send_data; + tBTA_HL_API_DCH_ECHO_TEST api_dch_echo_test; + tBTA_HL_API_SDP_QUERY api_sdp_query; + + tBTA_HL_CCH_SDP cch_sdp; + tBTA_HL_MCA_EVT mca_evt; + tBTA_HL_MCA_RCV_DATA_EVT mca_rcv_data_evt; + tBTA_HL_DCH_SDP dch_sdp; /* for DCH_OPEN_EVT and DCH_RECONNECT_EVT */ + tBTA_HL_CI_GET_PUT_DATA ci_get_put_data; + tBTA_HL_CI_ECHO_DATA ci_get_put_echo_data; +} tBTA_HL_DATA; + + +typedef struct +{ + BOOLEAN in_use; + UINT16 mdl_id; + tBTA_HL_MDL_HANDLE mdl_handle; + tBTA_HL_DCH_OPER dch_oper; + BOOLEAN intentional_close; + tBTA_HL_DCH_STATE dch_state; + UINT8 abort_oper; + UINT16 req_data_psm; + UINT16 max_rx_apdu_size; + UINT16 max_tx_apdu_size; + BT_HDR *p_tx_pkt; + BT_HDR *p_rx_pkt; + tBTA_HL_MDEP_ID local_mdep_id; + UINT8 local_mdep_cfg_idx; + tBTA_HL_DCH_CFG local_cfg; + tBTA_HL_DCH_CFG remote_cfg; + tBTA_HL_MDEP_ID peer_mdep_id; + UINT16 peer_data_type; + tBTA_HL_MDEP_ROLE peer_mdep_role; + tBTA_HL_DCH_MODE dch_mode; + tBTA_SEC sec_mask; + BOOLEAN is_the_first_reliable; + BOOLEAN delete_mdl; + UINT16 mtu; + tMCA_CHNL_CFG chnl_cfg; + BOOLEAN mdl_cfg_idx_included; + UINT8 mdl_cfg_idx; + UINT8 echo_oper; + BOOLEAN cong; + BOOLEAN close_pending; + UINT8 cout_oper; + BT_HDR *p_echo_tx_pkt; + BT_HDR *p_echo_rx_pkt; + tBTA_HL_STATUS ci_put_echo_data_status; +}tBTA_HL_MDL_CB; + +typedef struct +{ + tBTA_HL_MDL_CB mdl[BTA_HL_NUM_MDLS_PER_MCL]; + tBTA_HL_DELETE_MDL delete_mdl; + BOOLEAN in_use; + tBTA_HL_CCH_STATE cch_state; + UINT16 req_ctrl_psm; + UINT16 ctrl_psm; + UINT16 data_psm; + BD_ADDR bd_addr; + UINT16 cch_mtu; + UINT16 sec_mask; + tBTA_HL_MCL_HANDLE mcl_handle; + tSDP_DISCOVERY_DB *p_db; /* pointer to discovery database */ + tSDP_DISC_CMPL_CB *sdp_cback; + tBTA_HL_SDP_OPER sdp_oper; + BOOLEAN close_pending; + UINT8 sdp_mdl_idx; + tBTA_HL_SDP sdp; + UINT8 cch_oper; + BOOLEAN intentional_close; + BOOLEAN rsp_tout; + UINT8 timer_oper; + BOOLEAN echo_test; + UINT8 echo_mdl_idx; + UINT8 cch_close_dch_oper; +}tBTA_HL_MCL_CB; + +typedef struct +{ + tBTA_HL_MCL_CB mcb[BTA_HL_NUM_MCLS]; /* application Control Blocks */ + tBTA_HL_CBACK *p_cback; /* pointer to control callback function */ + BOOLEAN in_use; /* this CB is in use*/ + BOOLEAN deregistering; + UINT8 app_id; + UINT32 sdp_handle; /* SDP record handle */ + tBTA_HL_SUP_FEATURE sup_feature; + tBTA_HL_MDL_CFG mdl_cfg[BTA_HL_NUM_MDL_CFGS]; + tBTA_HL_DEVICE_TYPE dev_type; + tBTA_HL_APP_HANDLE app_handle; + UINT16 ctrl_psm; /* L2CAP PSM for the MCAP control channel */ + UINT16 data_psm; /* L2CAP PSM for the MCAP data channel */ + UINT16 sec_mask; /* Security mask for BTM_SetSecurityLevel() */ + + char srv_name[BTA_SERVICE_NAME_LEN +1]; /* service name to be used in the SDP; null terminated*/ + char srv_desp[BTA_SERVICE_DESP_LEN +1]; /* service description to be used in the SDP; null terminated */ + char provider_name[BTA_PROVIDER_NAME_LEN +1]; /* provide name to be used in the SDP; null terminated */ + + tMCA_CTRL_CBACK *p_mcap_cback; /* pointer to MCAP callback function */ + tMCA_DATA_CBACK *p_data_cback; +}tBTA_HL_APP_CB; + + +typedef struct +{ + BOOLEAN in_use; + tBTA_HL_SDP_OPER sdp_oper; + UINT8 app_idx; + UINT8 mcl_idx; + UINT8 mdl_idx; +}tBTA_HL_SDP_CB; + +typedef struct +{ + BOOLEAN in_use; + UINT8 app_idx; + UINT8 mcl_idx; +}tBTA_HL_TIMER_CB; + +typedef struct +{ + tBTA_HL_APP_CB acb[BTA_HL_NUM_APPS]; /* HL Control Blocks */ + tBTA_HL_CTRL_CBACK *p_ctrl_cback; /* pointer to control callback function */ + BOOLEAN enable; + BOOLEAN disabling; + + tBTA_HL_SDP_CB scb[BTA_HL_NUM_SDP_CBACKS]; + tBTA_HL_TIMER_CB tcb[BTA_HL_NUM_TIMERS]; + BOOLEAN enable_random_psm; + tBTA_HL_ALLOCATE_PSM *p_alloc_psm; +}tBTA_HL_CB; + +/****************************************************************************** +** Configuration Definitions +*******************************************************************************/ +/* Configuration structure */ + +/***************************************************************************** +** Global data +*****************************************************************************/ + +/* HL control block */ +#if BTA_DYNAMIC_MEMORY == FALSE +extern tBTA_HL_CB bta_hl_cb; +#else +extern tBTA_HL_CB *bta_hl_cb_ptr; + #define bta_hl_cb (*bta_hl_cb_ptr) +#endif + +#define BTA_HL_GET_CB_PTR() &(bta_hl_cb) +#define BTA_HL_GET_APP_CB_PTR(app_idx) &(bta_hl_cb.acb[(app_idx)]) +#define BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx) &(bta_hl_cb.acb[(app_idx)].mcb[(mcl_idx)]) +#define BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx) &(bta_hl_cb.acb[(app_idx)].mcb[(mcl_idx)].mdl[mdl_idx]) +#define BTA_HL_GET_MDL_CFG_PTR(app_idx, item_idx) &(bta_hl_cb.acb[(app_idx)].mdl_cfg[(item_idx)]) +#define BTA_HL_GET_ECHO_CFG_PTR(app_idx) &(bta_hl_cb.acb[(app_idx)].sup_feature.echo_cfg) +#define BTA_HL_GET_MDEP_CFG_PTR(app_idx, mdep_cfg_idx) &(bta_hl_cb.acb[(app_idx)].sup_feature.mdep[mdep_cfg_idx].mdep_cfg) +#define BTA_HL_GET_DATA_CFG_PTR(app_idx, mdep_cfg_idx, data_cfg_idx) \ + &(bta_hl_cb.acb[(app_idx)].sup_feature.mdep[mdep_cfg_idx].mdep_cfg.data_cfg[data_cfg_idx]) +#define BTA_HL_GET_BUF_PTR(p_pkt) ((UINT8 *)((UINT8 *) (p_pkt+1) + p_pkt->offset)) + +/***************************************************************************** +** Function prototypes +*****************************************************************************/ + +#ifdef __cplusplus +extern "C" +{ +#endif + /* main */ + extern BOOLEAN bta_hl_hdl_event(BT_HDR *p_msg); + /* sdp */ + extern BOOLEAN bta_hl_fill_sup_feature_list( const tSDP_DISC_ATTR *p_attr, + tBTA_HL_SUP_FEATURE_LIST_ELEM *p_list); + + extern tBTA_HL_STATUS bta_hl_sdp_register (UINT8 app_idx); + extern tSDP_DISC_REC *bta_hl_find_sink_or_src_srv_class_in_db (const tSDP_DISCOVERY_DB *p_db, + const tSDP_DISC_REC *p_start_rec); + + /* action routines */ + extern void bta_hl_dch_ci_get_tx_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_ci_put_rx_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_ci_get_echo_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + + extern void bta_hl_dch_echo_test(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_ci_put_echo_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_send_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_sdp_fail(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_cong_change(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_reconnect_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_reconnect_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_reconnect(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_sdp_init(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_close_echo_test(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_create_rsp(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_rcv_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_close_cmpl(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_close_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_close_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_close(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_delete_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + + extern void bta_hl_dch_mca_delete_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_delete(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_abort_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_abort_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_abort(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_open_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_open_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_create_ind(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_create_cfm(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_dch_mca_create(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_DATA *p_data); + extern void bta_hl_deallocate_spd_cback(UINT8 sdp_cback_idx); + extern tSDP_DISC_CMPL_CB *bta_hl_allocate_spd_cback(tBTA_HL_SDP_OPER sdp_oper, UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdl_idx, + UINT8 *p_sdp_cback_idx); + extern tBTA_HL_STATUS bta_hl_init_sdp(tBTA_HL_SDP_OPER sdp_oper, UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdl_idx); + extern void bta_hl_cch_sdp_init(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data); + extern void bta_hl_cch_mca_open(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data); + extern void bta_hl_cch_mca_close(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data); + extern void bta_hl_cch_close_cmpl(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data); + extern void bta_hl_cch_mca_disconnect(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data); + extern void bta_hl_cch_mca_rsp_tout(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data); + extern void bta_hl_cch_mca_connect(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data); + + /* State machine drivers */ + extern void bta_hl_cch_sm_execute(UINT8 inst_idx, UINT8 mcl_idx, + UINT16 event, tBTA_HL_DATA *p_data); + extern void bta_hl_dch_sm_execute(UINT8 inst_idx, UINT8 mcl_idx, UINT8 mdl_idx, + UINT16 event, tBTA_HL_DATA *p_data); + /* MCAP callback functions */ + extern void bta_hl_mcap_ctrl_cback(tMCA_HANDLE handle, tMCA_CL mcl, UINT8 event, + tMCA_CTRL *p_data); + + extern void bta_hl_mcap_data_cback(tMCA_DL mdl, BT_HDR *p_pkt); + + /* utility functions */ + extern BOOLEAN bta_hl_set_ctrl_psm_for_dch(UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdl_idx, UINT16 ctrl_psm); + extern BOOLEAN bta_hl_find_sdp_idx_using_ctrl_psm(tBTA_HL_SDP *p_sdp, + UINT16 ctrl_psm, + UINT8 *p_sdp_idx); + extern UINT8 bta_hl_set_user_tx_pool_id(UINT16 max_tx_size); + extern UINT8 bta_hl_set_user_rx_pool_id(UINT16 mtu); + extern UINT8 bta_hl_set_tx_win_size(UINT16 mtu, UINT16 mps); + extern UINT16 bta_hl_set_mps(UINT16 mtu); + extern void bta_hl_clean_mdl_cb(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx); + extern BT_HDR * bta_hl_get_buf(UINT16 data_size); + extern BOOLEAN bta_hl_find_service_in_db( UINT8 app_idx, UINT8 mcl_idx, + UINT16 service_uuid, + tSDP_DISC_REC **pp_rec ); + extern UINT16 bta_hl_get_service_uuids(UINT8 sdp_oper, UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdl_idx ); + extern BOOLEAN bta_hl_find_echo_cfg_rsp(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdep_idx, UINT8 cfg, + UINT8 *p_cfg_rsp); + extern BOOLEAN bta_hl_validate_cfg(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + UINT8 cfg); + extern BOOLEAN bta_hl_find_cch_cb_indexes(tBTA_HL_DATA *p_msg, + UINT8 *p_app_idx, + UINT8 *p_mcl_idx); + extern BOOLEAN bta_hl_find_dch_cb_indexes(tBTA_HL_DATA *p_msg, + UINT8 *p_app_idx, + UINT8 *p_mcl_idx, + UINT8 *p_mdl_idx); + extern UINT16 bta_hl_allocate_mdl_id(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx ); + extern BOOLEAN bta_hl_find_mdl_idx_using_handle(tBTA_HL_MDL_HANDLE mdl_handle, + UINT8 *p_app_idx, UINT8 *p_mcl_idx, + UINT8 *p_mdl_idx); + extern BOOLEAN bta_hl_find_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, UINT16 mdl_id, + UINT8 *p_mdl_idx); + extern BOOLEAN bta_hl_find_an_active_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, + UINT8 *p_mdl_idx); + extern BOOLEAN bta_hl_find_dch_setup_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, + UINT8 *p_mdl_idx); + extern BOOLEAN bta_hl_find_an_in_use_mcl_idx(UINT8 app_idx, + UINT8 *p_mcl_idx); + extern BOOLEAN bta_hl_find_an_in_use_app_idx(UINT8 *p_app_idx); + extern BOOLEAN bta_hl_find_app_idx(UINT8 app_id, UINT8 *p_app_idx); + extern BOOLEAN bta_hl_find_app_idx_using_handle(tBTA_HL_APP_HANDLE app_handle, + UINT8 *p_app_idx); + extern BOOLEAN bta_hl_find_mcl_idx_using_handle( tBTA_HL_MCL_HANDLE mcl_handle, + UINT8 *p_app_idx, UINT8 *p_mcl_idx); + extern BOOLEAN bta_hl_find_mcl_idx(UINT8 app_idx, BD_ADDR p_bd_addr, UINT8 *p_mcl_idx); + extern BOOLEAN bta_hl_is_the_first_reliable_existed(UINT8 app_idx, UINT8 mcl_idx ); + extern BOOLEAN bta_hl_find_non_active_mdl_cfg(UINT8 app_idx, UINT8 start_mdl_cfg_idx, + UINT8 *p_mdl_cfg_idx); + extern BOOLEAN bta_hl_find_avail_mdl_cfg_idx(UINT8 app_idx, UINT8 mcl_idx, + UINT8 *p_mdl_cfg_idx); + extern BOOLEAN bta_hl_find_mdl_cfg_idx(UINT8 app_idx, UINT8 mcl_idx, + tBTA_HL_MDL_ID mdl_id, UINT8 *p_mdl_cfg_idx); + extern BOOLEAN bta_hl_get_cur_time(UINT8 app_idx, UINT8 *p_cur_time); + extern void bta_hl_sort_cfg_time_idx(UINT8 app_idx, UINT8 *a, UINT8 n); + extern void bta_hl_compact_mdl_cfg_time(UINT8 app_idx); + extern BOOLEAN bta_hl_is_mdl_exsit_in_mcl(UINT8 app_idx, BD_ADDR bd_addr, + tBTA_HL_MDL_ID mdl_id); + extern BOOLEAN bta_hl_delete_mdl_cfg(UINT8 app_idx, BD_ADDR bd_addr, + tBTA_HL_MDL_ID mdl_id); + extern BOOLEAN bta_hl_is_mdl_value_valid(tBTA_HL_MDL_ID mdl_id); + extern BOOLEAN bta_hl_find_mdep_cfg_idx(UINT8 app_idx, + tBTA_HL_MDEP_ID local_mdep_id, UINT8 *p_mdep_cfg_idx); + extern void bta_hl_find_rxtx_apdu_size(UINT8 app_idx, UINT8 mdep_cfg_idx, + UINT16 *p_rx_apu_size, + UINT16 *p_tx_apu_size); + extern BOOLEAN bta_hl_validate_peer_cfg(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_MDEP_ID peer_mdep_id, + tBTA_HL_MDEP_ROLE peer_mdep_role, + UINT8 sdp_idx); + extern tBTA_HL_STATUS bta_hl_chk_local_cfg(UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdep_cfg_idx, + tBTA_HL_DCH_CFG local_cfg); + + extern BOOLEAN bta_hl_validate_reconnect_params(UINT8 app_idx, UINT8 mcl_idx, + tBTA_HL_API_DCH_RECONNECT *p_reconnect, + UINT8 *p_mdep_cfg_idx, UINT8 *p_mdl_cfg_idx); + extern BOOLEAN bta_hl_find_avail_mcl_idx(UINT8 app_idx, UINT8 *p_mcl_idx); + extern BOOLEAN bta_hl_find_avail_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, + UINT8 *p_mdl_idx); + extern BOOLEAN bta_hl_is_a_duplicate_id(UINT8 app_id); + extern BOOLEAN bta_hl_find_avail_app_idx(UINT8 *p_idx); + extern tBTA_HL_STATUS bta_hl_app_registration(UINT8 app_idx); + extern void bta_hl_discard_data(UINT16 event, tBTA_HL_DATA *p_data); + extern void bta_hl_save_mdl_cfg(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx ); + extern void bta_hl_set_dch_chan_cfg(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, tBTA_HL_DATA *p_data); + extern BOOLEAN bta_hl_get_l2cap_cfg(tBTA_HL_MDL_HANDLE mdl_hnd, tBTA_HL_L2CAP_CFG_INFO *p_cfg); + extern BOOLEAN bta_hl_validate_chan_cfg(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx); + extern BOOLEAN bta_hl_is_cong_on(UINT8 app_id, BD_ADDR bd_addr, tBTA_HL_MDL_ID mdl_id); + extern void bta_hl_check_cch_close(UINT8 app_idx, UINT8 mcl_idx, + tBTA_HL_DATA *p_data, BOOLEAN check_dch_setup); + extern void bta_hl_clean_app(UINT8 app_idx); + extern void bta_hl_check_deregistration(UINT8 app_idx, tBTA_HL_DATA *p_data ); + extern void bta_hl_check_disable(tBTA_HL_DATA *p_data ); + extern void bta_hl_build_abort_ind(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle); + extern void bta_hl_build_abort_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_STATUS status); + extern void bta_hl_build_dch_close_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_HANDLE mdl_handle, + tBTA_HL_STATUS status); + extern void bta_hl_build_dch_close_ind(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_HANDLE mdl_handle, + BOOLEAN intentional); + extern void bta_hl_build_send_data_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_HANDLE mdl_handle, + tBTA_HL_STATUS status ); + extern void bta_hl_build_rcv_data_ind(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_HANDLE mdl_handle); + extern void bta_hl_build_cch_open_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + BD_ADDR bd_addr, + tBTA_HL_STATUS status ); + extern void bta_hl_build_cch_open_ind(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + BD_ADDR bd_addr); + extern void bta_hl_build_cch_close_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_STATUS status ); + extern void bta_hl_build_cch_close_ind(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + BOOLEAN intentional); + + extern void bta_hl_build_dch_open_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_HANDLE mdl_handle, + tBTA_HL_MDEP_ID local_mdep_id, + tBTA_HL_MDL_ID mdl_id, + tBTA_HL_DCH_MODE dch_mode, + BOOLEAN first_reliable, + UINT16 mtu, + tBTA_HL_STATUS status); + + extern void bta_hl_build_delete_mdl_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_ID mdl_id, + tBTA_HL_STATUS status); + extern void bta_hl_build_echo_test_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_STATUS status ); + extern void bta_hl_build_sdp_query_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + BD_ADDR bd_addr, + tBTA_HL_SDP *p_sdp, + tBTA_HL_STATUS status); + +#if (BTA_HL_DEBUG == TRUE) + extern char *bta_hl_status_code(tBTA_HL_STATUS status); + extern char *bta_hl_evt_code(tBTA_HL_INT_EVT evt_code); +#endif +#ifdef __cplusplus +} +#endif +#endif /* BTA_MSE_INT_H */ + + diff --git a/bta/hl/bta_hl_main.c b/bta/hl/bta_hl_main.c new file mode 100644 index 0000000..3bfca86 --- /dev/null +++ b/bta/hl/bta_hl_main.c @@ -0,0 +1,1907 @@ +/***************************************************************************** +** +** Name: bta_hl_main.c +** +** Description: This file contains the HeaLth device profile main functions +** and state machine. +** +** Copyright (c) 1998-2011, Broadcom Corp., All Rights Reserved. +** Broadcom Bluetooth Core. Proprietary and confidential. +** +*****************************************************************************/ +#include <string.h> + +#include "bt_target.h" +#if defined(HL_INCLUDED) && (HL_INCLUDED == TRUE) + + + +#include "bta_hl_api.h" +#include "bta_hl_int.h" +#include "gki.h" +#include "utl.h" +#include "bd.h" +#include "l2c_api.h" +#include "mca_defs.h" + + +#if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) +static char *bta_hl_cch_state_code(tBTA_HL_CCH_STATE state_code); +static char *bta_hl_dch_state_code(tBTA_HL_DCH_STATE state_code); +#endif + +extern UINT16 L2CA_AllocateRandomPsm(void); +extern UINT16 L2CA_AllocatePsm(void); +/***************************************************************************** +** DCH State Table +*****************************************************************************/ +/***************************************************************************** +** Constants and types +*****************************************************************************/ +/* state machine action enumeration list for DCH */ +/* The order of this enumeration must be the same as bta_hl_dch_act_tbl[] */ +enum +{ + BTA_HL_DCH_MCA_CREATE, + BTA_HL_DCH_MCA_CREATE_CFM, + BTA_HL_DCH_MCA_CREATE_IND, + BTA_HL_DCH_MCA_OPEN_CFM, + BTA_HL_DCH_MCA_OPEN_IND, + BTA_HL_DCH_MCA_CLOSE, + BTA_HL_DCH_MCA_CLOSE_CFM, + BTA_HL_DCH_MCA_CLOSE_IND, + BTA_HL_DCH_CLOSE_CMPL, + BTA_HL_DCH_MCA_RCV_DATA, + + BTA_HL_DCH_SDP_INIT, + BTA_HL_DCH_MCA_RECONNECT, + BTA_HL_DCH_MCA_RECONNECT_IND, + BTA_HL_DCH_MCA_RECONNECT_CFM, + BTA_HL_DCH_CLOSE_ECHO_TEST, + BTA_HL_DCH_CREATE_RSP, + BTA_HL_DCH_MCA_ABORT, + BTA_HL_DCH_MCA_ABORT_IND, + BTA_HL_DCH_MCA_ABORT_CFM, + BTA_HL_DCH_MCA_CONG_CHANGE, + + BTA_HL_DCH_SDP_FAIL, + BTA_HL_DCH_SEND_DATA, + BTA_HL_DCH_CI_GET_TX_DATA, + BTA_HL_DCH_CI_PUT_RX_DATA, + BTA_HL_DCH_CI_GET_ECHO_DATA, + BTA_HL_DCH_ECHO_TEST, + BTA_HL_DCH_CI_PUT_ECHO_DATA, + BTA_HL_DCH_IGNORE +}; + +typedef void (*tBTA_HL_DCH_ACTION)(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, tBTA_HL_DATA *p_data); + +static const tBTA_HL_DCH_ACTION bta_hl_dch_action[] = +{ + bta_hl_dch_mca_create, + bta_hl_dch_mca_create_cfm, + bta_hl_dch_mca_create_ind, + bta_hl_dch_mca_open_cfm, + bta_hl_dch_mca_open_ind, + bta_hl_dch_mca_close, + bta_hl_dch_mca_close_cfm, + bta_hl_dch_mca_close_ind, + bta_hl_dch_close_cmpl, + bta_hl_dch_mca_rcv_data, + + bta_hl_dch_sdp_init, + bta_hl_dch_mca_reconnect, + bta_hl_dch_mca_reconnect_ind, + bta_hl_dch_mca_reconnect_cfm, + bta_hl_dch_close_echo_test, + bta_hl_dch_create_rsp, + bta_hl_dch_mca_abort, + bta_hl_dch_mca_abort_ind, + bta_hl_dch_mca_abort_cfm, + bta_hl_dch_mca_cong_change, + + bta_hl_dch_sdp_fail, + bta_hl_dch_send_data, + bta_hl_dch_ci_get_tx_data, + bta_hl_dch_ci_put_rx_data, + bta_hl_dch_ci_get_echo_data, + bta_hl_dch_echo_test, + bta_hl_dch_ci_put_echo_data, +}; + + +/* state table information */ +#define BTA_HL_DCH_ACTIONS 1 /* number of actions */ +#define BTA_HL_DCH_ACTION_COL 0 /* position of action */ +#define BTA_HL_DCH_NEXT_STATE 1 /* position of next state */ +#define BTA_HL_DCH_NUM_COLS 2 /* number of columns in state tables */ + +/* state table for idle state */ +static const UINT8 bta_hl_dch_st_idle[][BTA_HL_DCH_NUM_COLS] = +{ +/* Event Action 1 Next state */ +/* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_SDP_INIT, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_MCA_CREATE, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_MCA_CREATE_IND, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, + +/* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, + +/* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_MCA_RECONNECT, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_MCA_RECONNECT_IND, BTA_HL_DCH_OPENING_ST}, + +/* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, + +/* BTA_HL_MCA_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_ECHO_TEST, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST} +}; + +/* state table for opening state */ +static const UINT8 bta_hl_dch_st_opening[][BTA_HL_DCH_NUM_COLS] = +{ +/* Event Action 1 Next state */ +/* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_SDP_INIT, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_MCA_CREATE, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_MCA_CREATE_CFM, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_MCA_OPEN_IND, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_MCA_OPEN_CFM, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_MCA_CLOSE_IND, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, + +/* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_MCA_RECONNECT, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_SDP_FAIL, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_MCA_RECONNECT_CFM, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_CREATE_RSP, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_MCA_ABORT, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_MCA_ABORT_IND, BTA_HL_DCH_OPENING_ST}, + +/* BTA_HL_MCA_ABORT_CFM_EVT */ {BTA_HL_DCH_MCA_ABORT_CFM, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_ECHO_TEST, BTA_HL_DCH_OPENING_ST}, +/* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST} +}; + +/* state table for open state */ +static const UINT8 bta_hl_dch_st_open[][BTA_HL_DCH_NUM_COLS] = +{ +/* Event Action 1 Next state */ +/* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_MCA_CLOSE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_MCA_CLOSE_IND, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_SEND_DATA, BTA_HL_DCH_OPEN_ST}, + +/* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_MCA_RCV_DATA, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_CLOSE_ECHO_TEST, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, + +/* BTA_HL_DCH_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_MCA_CONG_CHANGE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_CI_GET_TX_DATA, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_CI_PUT_RX_DATA, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, +/* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_PUT_ECHO_DATA, BTA_HL_DCH_OPEN_ST} +}; + + +/* state table for closing state */ +static const UINT8 bta_hl_dch_st_closing[][BTA_HL_DCH_NUM_COLS] = +{ +/* Event Action 1 Next state */ +/* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_MCA_CLOSE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, + +/* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST}, +/* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, + +/* BTA_HL_DCH_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_CI_GET_TX_DATA, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_CI_PUT_RX_DATA, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, +/* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_PUT_ECHO_DATA, BTA_HL_DCH_CLOSING_ST} +}; + +/* type for state table */ +typedef const UINT8 (*tBTA_HL_DCH_ST_TBL)[BTA_HL_DCH_NUM_COLS]; + +/* state table */ +const tBTA_HL_DCH_ST_TBL bta_hl_dch_st_tbl[] = +{ + bta_hl_dch_st_idle, + bta_hl_dch_st_opening, + bta_hl_dch_st_open, + bta_hl_dch_st_closing +}; + +/***************************************************************************** +** CCH State Table +*****************************************************************************/ +/***************************************************************************** +** Constants and types +*****************************************************************************/ +/* state machine action enumeration list for CCH */ +enum +{ + BTA_HL_CCH_SDP_INIT, + BTA_HL_CCH_MCA_OPEN, + BTA_HL_CCH_MCA_CLOSE, + BTA_HL_CCH_CLOSE_CMPL, + BTA_HL_CCH_MCA_CONNECT, + BTA_HL_CCH_MCA_DISCONNECT, + BTA_HL_CCH_MCA_RSP_TOUT, + BTA_HL_CCH_IGNORE +}; + +/* type for action functions */ +typedef void (*tBTA_HL_CCH_ACTION)(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data); + +/* action function list for MAS */ +const tBTA_HL_CCH_ACTION bta_hl_cch_action[] = +{ + bta_hl_cch_sdp_init, + bta_hl_cch_mca_open, + bta_hl_cch_mca_close, + bta_hl_cch_close_cmpl, + bta_hl_cch_mca_connect, + bta_hl_cch_mca_disconnect, + bta_hl_cch_mca_rsp_tout +}; + + +/* state table information */ +#define BTA_HL_CCH_ACTIONS 1 /* number of actions */ +#define BTA_HL_CCH_NEXT_STATE 1 /* position of next state */ +#define BTA_HL_CCH_NUM_COLS 2 /* number of columns in state tables */ + + +/* state table for MAS idle state */ +static const UINT8 bta_hl_cch_st_idle[][BTA_HL_CCH_NUM_COLS] = +{ +/* Event Action 1 Next state */ +/* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_SDP_INIT, BTA_HL_CCH_OPENING_ST}, +/* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST}, +/* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST}, +/* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_CONNECT, BTA_HL_CCH_OPEN_ST}, +/* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST}, +/* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST}, +/* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST}, +/* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST} +}; + +/* state table for obex/rfcomm connection state */ +static const UINT8 bta_hl_cch_st_opening[][BTA_HL_CCH_NUM_COLS] = +{ +/* Event Action 1 Next state */ +/* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPENING_ST}, +/* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_MCA_OPEN, BTA_HL_CCH_OPENING_ST}, +/* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_CLOSE_CMPL, BTA_HL_CCH_IDLE_ST}, +/* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_CONNECT, BTA_HL_CCH_OPEN_ST}, +/* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT, BTA_HL_CCH_CLOSING_ST}, +/* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE, BTA_HL_CCH_CLOSING_ST}, +/* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_CLOSE_CMPL, BTA_HL_CCH_IDLE_ST}, +/* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_MCA_RSP_TOUT, BTA_HL_CCH_CLOSING_ST} +}; + +/* state table for open state */ +static const UINT8 bta_hl_cch_st_open[][BTA_HL_CCH_NUM_COLS] = +{ +/* Event Action 1 Next state */ +/* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST}, +/* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST}, +/* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST}, +/* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST}, +/* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT, BTA_HL_CCH_CLOSING_ST}, +/* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE, BTA_HL_CCH_CLOSING_ST}, +/* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST}, +/* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_MCA_RSP_TOUT, BTA_HL_CCH_CLOSING_ST} +}; + +/* state table for closing state */ +static const UINT8 bta_hl_cch_st_closing[][BTA_HL_CCH_NUM_COLS] = +{ +/* Event Action 1 Next state */ +/* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_CLOSING_ST}, +/* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_CLOSE_CMPL, BTA_HL_CCH_IDLE_ST}, +/* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_CLOSE_CMPL, BTA_HL_CCH_IDLE_ST}, +/* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_CONNECT, BTA_HL_CCH_OPEN_ST}, +/* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT, BTA_HL_CCH_CLOSING_ST}, +/* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE, BTA_HL_CCH_CLOSING_ST}, +/* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_CLOSE_CMPL, BTA_HL_CCH_IDLE_ST}, +/* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_CLOSING_ST} +}; + +/* type for state table CCH */ +typedef const UINT8 (*tBTA_HL_CCH_ST_TBL)[BTA_HL_CCH_NUM_COLS]; + +/* MAS state table */ +const tBTA_HL_CCH_ST_TBL bta_hl_cch_st_tbl[] = +{ + bta_hl_cch_st_idle, + bta_hl_cch_st_opening, + bta_hl_cch_st_open, + bta_hl_cch_st_closing +}; + + +/***************************************************************************** +** Global data +*****************************************************************************/ + +/* HL control block */ +#if BTA_DYNAMIC_MEMORY == FALSE +tBTA_HL_CB bta_hl_cb; +#endif + + +/******************************************************************************* +** +** Function bta_hl_cch_sm_execute +** +** Description State machine event handling function for CCH +** +** Returns void +** +*******************************************************************************/ +void bta_hl_cch_sm_execute(UINT8 app_idx, UINT8 mcl_idx, + UINT16 event, tBTA_HL_DATA *p_data) +{ + tBTA_HL_CCH_ST_TBL state_table; + UINT8 action; + int i; + tBTA_HL_MCL_CB *p_cb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + +#if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) + tBTA_HL_CCH_STATE in_state = p_cb->cch_state; + UINT16 cur_evt = event; + APPL_TRACE_DEBUG3("HDP CCH Event Handler: State 0x%02x [%s], Event [%s]", in_state, + bta_hl_cch_state_code(in_state), + bta_hl_evt_code(cur_evt)); +#endif + + /* look up the state table for the current state */ + state_table = bta_hl_cch_st_tbl[p_cb->cch_state]; + + event &= 0x00FF; + + /* set next state */ + p_cb->cch_state = state_table[event][BTA_HL_CCH_NEXT_STATE]; + + for (i = 0; i < BTA_HL_CCH_ACTIONS; i++) + { + if ((action = state_table[event][i]) != BTA_HL_CCH_IGNORE) + { + (*bta_hl_cch_action[action])(app_idx, mcl_idx, p_data); + } + else + { + /* discard HDP data */ + bta_hl_discard_data(p_data->hdr.event, p_data); + break; + } + } +#if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) + if (in_state != p_cb->cch_state) + { + APPL_TRACE_DEBUG3("HL CCH State Change: [%s] -> [%s] after [%s]", + bta_hl_cch_state_code(in_state), + bta_hl_cch_state_code(p_cb->cch_state), + bta_hl_evt_code(cur_evt)); + } +#endif + +} + +/******************************************************************************* +** +** Function bta_hl_dch_sm_execute +** +** Description State machine event handling function for DCH +** +** Returns void +** +*******************************************************************************/ +void bta_hl_dch_sm_execute(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + UINT16 event, tBTA_HL_DATA *p_data) +{ + tBTA_HL_DCH_ST_TBL state_table; + UINT8 action; + int i; + tBTA_HL_MDL_CB *p_cb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + +#if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) + tBTA_HL_DCH_STATE in_state = p_cb->dch_state; + UINT16 cur_evt = event; + APPL_TRACE_DEBUG3("HDP DCH Event Handler: State 0x%02x [%s], Event [%s]", in_state, + bta_hl_dch_state_code(in_state), + bta_hl_evt_code(cur_evt)); +#endif + + /* look up the state table for the current state */ + state_table = bta_hl_dch_st_tbl[p_cb->dch_state]; + event -= BTA_HL_DCH_EVT_MIN; + + /* set next state */ + p_cb->dch_state = state_table[event][BTA_HL_DCH_NEXT_STATE]; + + for (i = 0; i < BTA_HL_DCH_ACTIONS; i++) + { + if ((action = state_table[event][i]) != BTA_HL_DCH_IGNORE) + { + (*bta_hl_dch_action[action])(app_idx, mcl_idx, mdl_idx, p_data); + } + else + { + /* discard mas data */ + bta_hl_discard_data(p_data->hdr.event, p_data); + break; + } + } + + +#if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) + if (in_state != p_cb->dch_state) + { + APPL_TRACE_DEBUG3("HL DCH State Change: [%s] -> [%s] after [%s]", + bta_hl_dch_state_code(in_state), + bta_hl_dch_state_code(p_cb->dch_state), + bta_hl_evt_code(cur_evt)); + } +#endif +} +/******************************************************************************* +** +** Function bta_hl_api_enable +** +** Description Process the API enable request to enable the HL subsystem +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_enable(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL_CTRL evt_data; + + /* If already enabled then reject this request */ + if (p_cb->enable) + { + APPL_TRACE_ERROR0("HL is already enabled"); + evt_data.enable_cfm.status = BTA_HL_STATUS_FAIL; + if (p_data->api_enable.p_cback) + p_data->api_enable.p_cback(BTA_HL_CTRL_ENABLE_CFM_EVT, (tBTA_HL_CTRL *) &evt_data); + return; + } + + /* Done with checking. now perform the enable oepration*/ + /* initialize control block */ + memset(p_cb, 0, sizeof(tBTA_HL_CB)); + p_cb->enable = TRUE; + p_cb->p_ctrl_cback = p_data->api_enable.p_cback; + evt_data.enable_cfm.status = BTA_HL_STATUS_OK; + if (p_data->api_enable.p_cback) + p_data->api_enable.p_cback(BTA_HL_CTRL_ENABLE_CFM_EVT, (tBTA_HL_CTRL *) &evt_data); + +} +/******************************************************************************* +** +** Function bta_hl_api_disable +** +** Description Process the API disable request to disable the HL subsystem +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_disable(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL_CTRL evt_data; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + + if (p_cb->enable) + { + p_cb->disabling = TRUE; + bta_hl_check_disable(p_data); + } + else + { + status = BTA_HL_STATUS_FAIL; + evt_data.disable_cfm.status = status; + if (p_cb->p_ctrl_cback) p_cb->p_ctrl_cback(BTA_HL_CTRL_DISABLE_CFM_EVT, (tBTA_HL_CTRL *) &evt_data); + } + + +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_disable status =%s", bta_hl_status_code(status)); + } +#endif + +} + +/******************************************************************************* +** +** Function bta_hl_api_register +** +** Description Process the API registration request to register an HDP applciation +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_register(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + UINT8 app_idx; + tBTA_HL_APP_CB *p_acb; + tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL; + + if (p_cb->enable) + { + if (!bta_hl_is_a_duplicate_id(p_data->api_reg.app_id)) + { + if (bta_hl_find_avail_app_idx(&app_idx)) + { + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + p_acb->in_use = TRUE; + p_acb->app_id = p_data->api_reg.app_id; + p_acb->p_cback = p_data->api_reg.p_cback; + p_acb->sec_mask = p_data->api_reg.sec_mask; + p_acb->dev_type = p_data->api_reg.dev_type; + BCM_STRNCPY_S(p_acb->srv_name, sizeof(p_acb->srv_name), p_data->api_reg.srv_name, BTA_SERVICE_NAME_LEN); + BCM_STRNCPY_S(p_acb->srv_desp, sizeof(p_acb->srv_desp), p_data->api_reg.srv_desp, BTA_SERVICE_DESP_LEN); + BCM_STRNCPY_S(p_acb->provider_name, sizeof(p_acb->provider_name), p_data->api_reg.provider_name, BTA_PROVIDER_NAME_LEN); + bta_hl_cb.p_alloc_psm = L2CA_AllocatePSM; + p_acb->ctrl_psm = bta_hl_cb.p_alloc_psm(); + p_acb->data_psm = bta_hl_cb.p_alloc_psm(); + p_acb->p_mcap_cback = bta_hl_mcap_ctrl_cback; + status = bta_hl_app_registration(app_idx); + } + else + { + status = BTA_HL_STATUS_NO_RESOURCE; + } + } + else + { + status = BTA_HL_STATUS_DUPLICATE_APP_ID; + } + } + + if (status != BTA_HL_STATUS_OK) + { + if ((status != BTA_HL_STATUS_DUPLICATE_APP_ID) && + (status != BTA_HL_STATUS_NO_RESOURCE)) + { + memset(p_acb, 0, sizeof(tBTA_HL_APP_CB)); + } + } +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_register status =%s", bta_hl_status_code(status)); + } +#endif + + evt_data.reg_cfm.status = status; + evt_data.reg_cfm.app_id = p_data->api_reg.app_id; + evt_data.reg_cfm.app_handle = p_acb->app_handle; + if (p_data->api_reg.p_cback) + { + p_data->api_reg.p_cback(BTA_HL_REGISTER_CFM_EVT, (tBTA_HL *) &evt_data); + } + + if (status == BTA_HL_STATUS_OK) + { + evt_data.sdp_info_ind.app_handle = p_acb->app_handle; + evt_data.sdp_info_ind.ctrl_psm = p_acb->ctrl_psm; + evt_data.sdp_info_ind.data_psm = p_acb->data_psm; + evt_data.sdp_info_ind.data_x_spec = BTA_HL_SDP_IEEE_11073_20601; + evt_data.sdp_info_ind.mcap_sup_procs = BTA_HL_MCAP_SUP_PROC_MASK ; + + if (p_data->api_reg.p_cback) + { + p_data->api_reg.p_cback(BTA_HL_SDP_INFO_IND_EVT, (tBTA_HL *) &evt_data); + } + } +} + +/******************************************************************************* +** +** Function bta_hl_api_deregister +** +** Description Process the API de-registration request +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_deregister(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + + UINT8 app_idx; + tBTA_HL_APP_CB *p_acb; + + if (bta_hl_find_app_idx_using_handle(p_data->api_dereg.app_handle, &app_idx)) + { + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + p_acb->deregistering= TRUE; + bta_hl_check_deregistration(app_idx,p_data); + } + else + { + APPL_TRACE_ERROR1("Inavlide app_handle=%d", p_data->api_dereg.app_handle); + } +} + +/******************************************************************************* +** +** Function bta_hl_api_cch_open +** +** Description Process the API CCH open request +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_cch_open(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + UINT8 app_idx, mcl_idx; + tBTA_HL_APP_CB *p_acb; + tBTA_HL_MCL_CB *p_mcb; + + if (bta_hl_find_app_idx_using_handle(p_data->api_cch_open.app_handle, &app_idx)) + { + + if (!bta_hl_find_mcl_idx(app_idx, p_data->api_cch_open.bd_addr, &mcl_idx)) + { + if (bta_hl_find_avail_mcl_idx(app_idx, &mcl_idx)) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + p_mcb->in_use = TRUE; + p_mcb->req_ctrl_psm = p_data->api_cch_open.ctrl_psm; + p_mcb->sec_mask = p_data->api_cch_open.sec_mask; + bdcpy(p_mcb->bd_addr, p_data->api_cch_open.bd_addr); + p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_OPEN; + } + else + { + status = BTA_HL_STATUS_NO_RESOURCE; + } + } + else + { + /* Only one MCL per BD_ADDR */ + status = BTA_HL_STATUS_FAIL; + } + } + else + { + status = BTA_HL_STATUS_INVALID_APP_HANDLE; + } +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_cch_open status =%s", bta_hl_status_code(status)); + } +#endif + switch (status) + { + case BTA_HL_STATUS_OK: + bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_OPEN_EVT, p_data); + break; + case BTA_HL_STATUS_NO_RESOURCE: + case BTA_HL_STATUS_FAIL: + bta_hl_build_cch_open_cfm(&evt_data, p_data->api_cch_open.app_handle, + 0, + p_data->api_cch_open.bd_addr, + status); + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + p_acb->p_cback(BTA_HL_CCH_OPEN_CFM_EVT,(tBTA_HL *) &evt_data ); + break; + default: + APPL_TRACE_ERROR1("status code=%d", status); + break; + } +} + +/******************************************************************************* +** +** Function bta_hl_api_cch_close +** +** Description Process the API CCH close request +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_cch_close(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + UINT8 app_idx, mcl_idx; + tBTA_HL_APP_CB *p_acb; + tBTA_HL_MCL_CB *p_mcb; + + if (bta_hl_find_mcl_idx_using_handle(p_data->api_cch_close.mcl_handle, &app_idx, &mcl_idx)) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_CLOSE; + } + else + { + status = BTA_HL_STATUS_INVALID_MCL_HANDLE; + } +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_cch_close status =%s", bta_hl_status_code(status)); + } +#endif + switch (status) + { + case BTA_HL_STATUS_OK: + bta_hl_check_cch_close(app_idx, mcl_idx, p_data, TRUE); + break; + + case BTA_HL_STATUS_FAIL: + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + bta_hl_build_cch_close_cfm(&evt_data, + p_acb->app_handle, + p_data->api_cch_close.mcl_handle, + status); + p_acb->p_cback(BTA_HL_CCH_CLOSE_CFM_EVT,(tBTA_HL *) &evt_data ); + break; + + default: + APPL_TRACE_ERROR1("status code=%d", status); + break; + + } + +} + +/******************************************************************************* +** +** Function bta_hl_api_dch_open +** +** Description Process the API DCH open request +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_dch_open(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + UINT8 app_idx, mcl_idx, mdl_idx; + tBTA_HL_APP_CB *p_acb; + tBTA_HL_MCL_CB *p_mcb; + tBTA_HL_MDL_CB *p_dcb; + tBTA_HL_MDEP_CFG *p_mdep_cfg; + UINT8 mdep_cfg_idx; + + if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_open.mcl_handle, &app_idx, &mcl_idx)) + { + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + + if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) + { + if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) + { + p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + + if (bta_hl_find_mdep_cfg_idx(app_idx, p_data->api_dch_open.local_mdep_id, &mdep_cfg_idx)) + { + if ( mdep_cfg_idx && + (p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SINK)) + { + p_data->api_dch_open.local_cfg = BTA_HL_DCH_CFG_NO_PREF; + } + + if ((status = bta_hl_chk_local_cfg(app_idx,mcl_idx,mdep_cfg_idx,p_data->api_dch_open.local_cfg)) + == BTA_HL_STATUS_OK) + { + + if (p_data->api_dch_open.local_mdep_id != BTA_HL_ECHO_TEST_MDEP_ID) + { + if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx, p_data->api_dch_open.ctrl_psm)) + { + p_mdep_cfg = BTA_HL_GET_MDEP_CFG_PTR(app_idx, mdep_cfg_idx); + p_dcb->in_use = TRUE; + p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_OPEN; + p_dcb->sec_mask = p_data->api_dch_open.sec_mask; + p_dcb->local_mdep_id = p_data->api_dch_open.local_mdep_id; + p_dcb->peer_mdep_id = p_data->api_dch_open.peer_mdep_id; + + if (p_mdep_cfg->mdep_role == BTA_HL_MDEP_ROLE_SINK) + { + p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE; + } + else + { + p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SINK; + } + + p_dcb->local_mdep_cfg_idx = mdep_cfg_idx; + p_dcb->local_cfg = p_data->api_dch_open.local_cfg; + + bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx, + &p_dcb->max_rx_apdu_size, + &p_dcb->max_tx_apdu_size); + p_dcb->mdl_id = bta_hl_allocate_mdl_id(app_idx,mcl_idx,mdl_idx); + p_dcb->mdl_cfg_idx_included = FALSE; + } + else + { + status = BTA_HL_STATUS_INVALID_CTRL_PSM; + } + + } + else + { + status = BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID; + } + } + } + else + { + status = BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID; + } + } + else + { + status = BTA_HL_STATUS_NO_RESOURCE; + } + } + else + { + status = BTA_HL_STATUS_NO_CCH; + } + } + else + { + status = BTA_HL_STATUS_INVALID_MCL_HANDLE; + } + +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_dch_open status =%s", bta_hl_status_code(status)); + } +#endif + switch (status) + { + case BTA_HL_STATUS_OK: + if (p_mcb->sdp.num_recs) + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_OPEN_EVT, p_data); + } + else + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_SDP_INIT_EVT, p_data); + } + break; + case BTA_HL_STATUS_INVALID_DCH_CFG: + case BTA_HL_STATUS_NO_FIRST_RELIABLE: + case BTA_HL_STATUS_NO_CCH: + case BTA_HL_STATUS_NO_RESOURCE: + case BTA_HL_STATUS_FAIL: + case BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID: + case BTA_HL_STATUS_INVALID_CTRL_PSM: + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + bta_hl_build_dch_open_cfm(&evt_data, + p_acb->app_handle, + p_data->api_dch_open.mcl_handle, + BTA_HL_INVALID_MDL_HANDLE, + 0,0,0,0,0, status); + p_acb->p_cback(BTA_HL_DCH_OPEN_CFM_EVT,(tBTA_HL *) &evt_data ); + break; + default: + APPL_TRACE_ERROR1("Status code=%d", status); + break; + + } + +} +/******************************************************************************* +** +** Function bta_hl_api_dch_close +** +** Description Process the API DCH close request +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_dch_close(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + UINT8 app_idx, mcl_idx, mdl_idx; + tBTA_HL_APP_CB *p_acb; + tBTA_HL_MCL_CB *p_mcb; + tBTA_HL_MDL_CB *p_dcb; + + + if (bta_hl_find_mdl_idx_using_handle(p_data->api_dch_close.mdl_handle, &app_idx, &mcl_idx, &mdl_idx )) + { + p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + if (p_dcb->dch_state != BTA_HL_DCH_OPEN_ST) + { + status = BTA_HL_STATUS_FAIL; + } + } + else + { + status = BTA_HL_STATUS_INVALID_MDL_HANDLE; + } + +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_dch_close status =%s", bta_hl_status_code(status)); + } +#endif + + switch (status) + { + case BTA_HL_STATUS_OK: + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_EVT, p_data); + break; + case BTA_HL_STATUS_FAIL: + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + bta_hl_build_dch_close_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + p_data->api_dch_close.mdl_handle, + status); + + p_acb->p_cback(BTA_HL_DCH_CLOSE_CFM_EVT,(tBTA_HL *) &evt_data ); + break; + default: + APPL_TRACE_ERROR1("Status code=%d", status); + break; + } +} + + +/******************************************************************************* +** +** Function bta_hl_api_dch_reconnect +** +** Description Process the API DCH reconnect request +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_dch_reconnect(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + UINT8 app_idx, mcl_idx, mdl_idx; + tBTA_HL_APP_CB *p_acb; + tBTA_HL_MCL_CB *p_mcb; + tBTA_HL_MDL_CB *p_dcb; + UINT8 mdep_cfg_idx; + UINT8 mdl_cfg_idx; + + if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_open.mcl_handle, &app_idx, &mcl_idx)) + { + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) + { + if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) + { + p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + if (bta_hl_validate_reconnect_params(app_idx, mcl_idx, &(p_data->api_dch_reconnect), + &mdep_cfg_idx, &mdl_cfg_idx )) + { + if (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx) && + (p_acb->mdl_cfg[mdl_cfg_idx].dch_mode != BTA_HL_DCH_MODE_RELIABLE)) + { + status = BTA_HL_STATUS_NO_FIRST_RELIABLE; + } + else + { + if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx, p_data->api_dch_open.ctrl_psm)) + { + p_dcb->in_use = TRUE; + p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_RECONNECT; + p_dcb->sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); + p_dcb->local_mdep_id = p_acb->mdl_cfg[mdl_cfg_idx].local_mdep_id; + p_dcb->local_mdep_cfg_idx = mdep_cfg_idx; + p_dcb->local_cfg = BTA_HL_DCH_CFG_UNKNOWN; + p_dcb->mdl_id = p_data->api_dch_reconnect.mdl_id; + p_dcb->mdl_cfg_idx_included = TRUE; + p_dcb->mdl_cfg_idx = mdl_cfg_idx; + p_dcb->dch_mode = p_acb->mdl_cfg[mdl_cfg_idx].dch_mode; + bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx, + &p_dcb->max_rx_apdu_size, + &p_dcb->max_tx_apdu_size); + } + else + { + status = BTA_HL_STATUS_INVALID_CTRL_PSM; + } + } + } + else + { + status = BTA_HL_STATUS_INVALID_RECONNECT_CFG; + } + } + else + { + status = BTA_HL_STATUS_NO_RESOURCE; + } + } + else + { + status = BTA_HL_STATUS_NO_CCH; + } + } + else + { + status = BTA_HL_STATUS_INVALID_MCL_HANDLE; + } + +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_dch_reconnect status=%s", bta_hl_status_code(status)); + } +#endif + + switch (status) + { + case BTA_HL_STATUS_OK: + if (p_mcb->sdp.num_recs) + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_RECONNECT_EVT, p_data); + } + else + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_SDP_INIT_EVT, p_data); + } + break; + case BTA_HL_STATUS_INVALID_RECONNECT_CFG: + case BTA_HL_STATUS_NO_FIRST_RELIABLE: + case BTA_HL_STATUS_NO_CCH: + case BTA_HL_STATUS_NO_RESOURCE: + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + bta_hl_build_dch_open_cfm(&evt_data, + p_acb->app_handle, + p_data->api_dch_reconnect.mcl_handle, + BTA_HL_INVALID_MDL_HANDLE, + 0,p_data->api_dch_reconnect.mdl_id,0,0,0, status); + p_acb->p_cback(BTA_HL_DCH_RECONNECT_CFM_EVT,(tBTA_HL *) &evt_data ); + break; + default: + APPL_TRACE_ERROR1("Status code=%d", status); + break; + } +} + +/******************************************************************************* +** +** Function bta_hl_api_dch_echo_test +** +** Description Process the API Echo test request +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_dch_echo_test(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + UINT8 app_idx, mcl_idx, mdl_idx; + tBTA_HL_APP_CB *p_acb; + tBTA_HL_MCL_CB *p_mcb; + tBTA_HL_MDL_CB *p_dcb; + tBTA_HL_ECHO_CFG *p_echo_cfg; + + + if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_echo_test.mcl_handle, &app_idx, &mcl_idx)) + { + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) + { + if (!p_mcb->echo_test ) + { + if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) + { + p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + + if ((p_data->api_dch_echo_test.local_cfg == BTA_HL_DCH_CFG_RELIABLE) || + (p_data->api_dch_echo_test.local_cfg == BTA_HL_DCH_CFG_STREAMING)) + { + if ((p_dcb->p_echo_tx_pkt = bta_hl_get_buf(p_data->api_dch_echo_test.pkt_size)) != NULL ) + { + if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx, p_data->api_dch_open.ctrl_psm)) + { + p_dcb->in_use = TRUE; + p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_OPEN; + p_dcb->sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); + p_dcb->local_mdep_cfg_idx = BTA_HL_ECHO_TEST_MDEP_CFG_IDX; + p_dcb->local_cfg = p_data->api_dch_echo_test.local_cfg; + p_dcb->local_mdep_id = BTA_HL_ECHO_TEST_MDEP_ID; + p_dcb->peer_mdep_id = BTA_HL_ECHO_TEST_MDEP_ID; + p_dcb->mdl_id = bta_hl_allocate_mdl_id(app_idx,mcl_idx,mdl_idx); + p_dcb->mdl_cfg_idx_included = FALSE; + p_echo_cfg = BTA_HL_GET_ECHO_CFG_PTR(app_idx); + p_dcb->max_rx_apdu_size = p_echo_cfg->max_rx_apdu_size; + p_dcb->max_tx_apdu_size = p_echo_cfg->max_tx_apdu_size; + p_mcb->echo_test = TRUE; + p_mcb->echo_mdl_idx = mdl_idx; + } + else + { + status = BTA_HL_STATUS_INVALID_CTRL_PSM; + } + } + else + { + status = BTA_HL_STATUS_NO_RESOURCE; + } + } + else + { + status = BTA_HL_STATUS_INVALID_DCH_CFG; + } + } + else + { + status = BTA_HL_STATUS_NO_RESOURCE; + } + } + else + { + status = BTA_HL_STATUS_ECHO_TEST_BUSY; + } + } + else + { + status = BTA_HL_STATUS_NO_CCH; + } + } + else + { + status = BTA_HL_STATUS_NO_MCL; + } + +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_dch_echo_test status=%s", bta_hl_status_code(status)); + } +#endif + + switch (status) + { + case BTA_HL_STATUS_OK: + if (p_mcb->sdp.num_recs) + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ECHO_TEST_EVT, p_data); + } + else + { + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_SDP_INIT_EVT, p_data); + } + break; + case BTA_HL_STATUS_NO_CCH: + case BTA_HL_STATUS_ECHO_TEST_BUSY: + case BTA_HL_STATUS_NO_RESOURCE: + case BTA_HL_STATUS_INVALID_DCH_CFG: + bta_hl_build_echo_test_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + status); + p_acb->p_cback(BTA_HL_DCH_ECHO_TEST_CFM_EVT,(tBTA_HL *) &evt_data ); + break; + + default: + APPL_TRACE_ERROR1("Status code=%s", status); + break; + } +} + + +/******************************************************************************* +** +** Function bta_hl_api_sdp_query +** +** Description Process the API SDP query request +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_sdp_query(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + UINT8 app_idx, mcl_idx; + tBTA_HL_APP_CB *p_acb; + tBTA_HL_MCL_CB *p_mcb; + + + if (bta_hl_find_app_idx_using_handle(p_data->api_sdp_query.app_handle, &app_idx)) + { + if (!bta_hl_find_mcl_idx(app_idx, p_data->api_sdp_query.bd_addr, &mcl_idx)) + { + if (bta_hl_find_avail_mcl_idx(app_idx, &mcl_idx)) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + p_mcb->in_use = TRUE; + bdcpy(p_mcb->bd_addr, p_data->api_sdp_query.bd_addr); + p_mcb->sdp_oper = BTA_HL_SDP_OP_SDP_QUERY_NEW ; + } + else + { + status = BTA_HL_STATUS_NO_RESOURCE; + } + } + else + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + if (p_mcb->sdp_oper != BTA_HL_SDP_OP_NONE) + { + status = BTA_HL_STATUS_SDP_NO_RESOURCE; + } + else + { + p_mcb->sdp_oper = BTA_HL_SDP_OP_SDP_QUERY_CURRENT; + } + } + } + else + { + status = BTA_HL_STATUS_INVALID_APP_HANDLE; + } + + if (status == BTA_HL_STATUS_OK) + { + status = bta_hl_init_sdp( p_mcb->sdp_oper, app_idx, mcl_idx, 0xFF); + if ( (status != BTA_HL_STATUS_OK) && + (p_mcb->sdp_oper == BTA_HL_SDP_OP_SDP_QUERY_NEW) ) + { + memset(p_mcb, 0 ,sizeof(tBTA_HL_MCL_CB)); + } + } +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_sdp_query status=%s", bta_hl_status_code(status)); + } +#endif + switch (status) + { + case BTA_HL_STATUS_NO_RESOURCE: + case BTA_HL_STATUS_FAIL: + case BTA_HL_STATUS_SDP_NO_RESOURCE: + bta_hl_build_sdp_query_cfm(&evt_data, + p_data->api_sdp_query.app_handle, + p_data->api_sdp_query.bd_addr, + NULL, + status); + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + p_acb->p_cback(BTA_HL_SDP_QUERY_CFM_EVT,(tBTA_HL *) &evt_data ); + break; + case BTA_HL_STATUS_OK: + break; + default: + APPL_TRACE_ERROR1("Status code=%d", status); + break; + } +} + + + + +/******************************************************************************* +** +** Function bta_hl_sdp_query_results +** +** Description Process the SDP query results +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_sdp_query_results(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + UINT8 app_idx = p_data->cch_sdp.app_idx; + UINT8 mcl_idx = p_data->cch_sdp.mcl_idx; + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR( app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR( app_idx, mcl_idx); + tBTA_HL_SDP *p_sdp=NULL; + tBTA_HL_SDP_OPER sdp_oper; + UINT16 event; + BOOLEAN release_sdp_buf=FALSE; + + event = p_data->hdr.event; + sdp_oper = p_mcb->sdp_oper; + + if ( event == BTA_HL_SDP_QUERY_OK_EVT) + { + if ((p_sdp = (tBTA_HL_SDP *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_SDP)))) != NULL) + { + memcpy(p_sdp, &p_mcb->sdp, sizeof(tBTA_HL_SDP)); + release_sdp_buf = TRUE; + } + else + { + status = BTA_HL_STATUS_SDP_NO_RESOURCE; + } + } + else + { + status = BTA_HL_STATUS_SDP_FAIL; + } + +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_sdp_query_results status=%s", bta_hl_status_code(status)); + } +#endif + + bta_hl_build_sdp_query_cfm(&evt_data,p_acb->app_handle, + p_mcb->bd_addr,p_sdp,status); + p_acb->p_cback(BTA_HL_SDP_QUERY_CFM_EVT,(tBTA_HL *) &evt_data ); + + if (release_sdp_buf) + { + utl_freebuf((void **) &p_sdp); + } + + if (p_data->cch_sdp.release_mcl_cb) + { + memset(p_mcb, 0 ,sizeof(tBTA_HL_MCL_CB)); + } + else + { + if (p_mcb->close_pending) + { + bta_hl_check_cch_close(app_idx,mcl_idx,p_data, TRUE); + } + + if (!p_mcb->ctrl_psm) + { + /* this is a control channel acceptor do not store the sdp records*/ + memset(&p_mcb->sdp, 0, sizeof(tBTA_HL_SDP)); + } + } +} + + +/******************************************************************************* +** +** Function bta_hl_api_delete_mdl +** +** Description Process the API DELETE MDL request +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_delete_mdl(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + UINT8 app_idx, mcl_idx; + tBTA_HL_APP_CB *p_acb; + tBTA_HL_MCL_CB *p_mcb; + + if (bta_hl_find_mcl_idx_using_handle(p_data->api_delete_mdl.mcl_handle, &app_idx, &mcl_idx )) + { + if (bta_hl_is_mdl_value_valid(p_data->api_delete_mdl.mdl_id)) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + if (bta_hl_is_mdl_exsit_in_mcl(app_idx, + p_mcb->bd_addr, + p_data->api_delete_mdl.mdl_id)) + { + + + p_mcb->delete_mdl.mcl_handle = p_data->api_delete_mdl.mcl_handle; + p_mcb->delete_mdl.mdl_id = p_data->api_delete_mdl.mdl_id; + p_mcb->delete_mdl.delete_req_pending = TRUE; + + if (MCA_Delete((tMCA_CL) p_mcb->mcl_handle, + p_data->api_delete_mdl.mdl_id)!= MCA_SUCCESS) + { + status = BTA_HL_STATUS_FAIL; + memset(&p_mcb->delete_mdl, 0, sizeof(tBTA_HL_DELETE_MDL)); + } + } + else + { + status = BTA_HL_STATUS_NO_MDL_ID_FOUND; + } + } + else + { + status = BTA_HL_STATUS_INVALID_MDL_ID; + } + } + else + { + status = BTA_HL_STATUS_INVALID_MCL_HANDLE; + } + +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_delete_mdl status=%s", bta_hl_status_code(status)); + } +#endif + switch (status) + { + case BTA_HL_STATUS_OK: + break; + case BTA_HL_STATUS_FAIL: + case BTA_HL_STATUS_NO_MDL_ID_FOUND: + case BTA_HL_STATUS_INVALID_MDL_ID: + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + bta_hl_build_delete_mdl_cfm(&evt_data, + p_acb->app_handle, + p_data->api_delete_mdl.mcl_handle, + p_data->api_delete_mdl.mdl_id, + status); + + p_acb->p_cback(BTA_HL_DELETE_MDL_CFM_EVT,(tBTA_HL *) &evt_data ); + break; + case BTA_HL_STATUS_INVALID_APP_HANDLE: + default: + APPL_TRACE_ERROR1("status code =%d", status); + break; + } +} + +/******************************************************************************* +** +** Function bta_hl_mca_delete_mdl_cfm +** +** Description Process the DELETE MDL confirmation event +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_mca_delete_mdl_cfm(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + UINT8 app_idx, mcl_idx; + tMCA_RSP_EVT *p_delete_cfm = &p_data->mca_evt.mca_data.delete_cfm; + tBTA_HL_MCL_CB *p_mcb; + BOOLEAN send_cfm_evt = TRUE; + tBTA_HL_APP_CB *p_acb; + + if (bta_hl_find_mcl_idx_using_handle(p_data->mca_evt.mcl_handle, &app_idx, &mcl_idx)) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + if ( p_mcb->delete_mdl.delete_req_pending) + { + if (p_delete_cfm->rsp_code == MCA_RSP_SUCCESS ) + { + + if (!bta_hl_delete_mdl_cfg(app_idx, + p_mcb->bd_addr , + p_delete_cfm->mdl_id)) + { + status = BTA_HL_STATUS_FAIL; + } + } + else + { + status = BTA_HL_STATUS_FAIL; + } + + memset(&p_mcb->delete_mdl, 0, sizeof(tBTA_HL_DELETE_MDL)); + } + else + { + send_cfm_evt = FALSE; + } + } + else + { + send_cfm_evt = FALSE; + } + +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_delete_mdl status=%s", bta_hl_status_code(status)); + } +#endif + + if (send_cfm_evt) + { + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + bta_hl_build_delete_mdl_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + p_delete_cfm->mdl_id, + status); + + p_acb->p_cback(BTA_HL_DELETE_MDL_CFM_EVT,(tBTA_HL *) &evt_data ); + } +} + +/******************************************************************************* +** +** Function bta_hl_mca_delete_mdl_ind +** +** Description Process the DELETE MDL indication event +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_mca_delete_mdl_ind(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + tBTA_HL evt_data; + UINT8 app_idx, mcl_idx, mdl_idx; + tMCA_EVT_HDR *p_delete_ind = &p_data->mca_evt.mca_data.delete_ind; + tBTA_HL_MCL_CB *p_mcb; + tBTA_HL_MDL_CB *p_dcb; + BOOLEAN send_ind_evt = TRUE; + tBTA_HL_APP_CB *p_acb; + + if (bta_hl_find_mcl_idx_using_handle(p_data->mca_evt.mcl_handle, &app_idx, &mcl_idx) ) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + + if (bta_hl_find_mdl_idx(app_idx, mcl_idx, p_delete_ind->mdl_id, &mdl_idx )) + { + p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + p_dcb->dch_oper = BTA_HL_DCH_OP_REMOTE_DELETE; + } + if (bta_hl_delete_mdl_cfg(app_idx, + p_mcb->bd_addr , + p_delete_ind->mdl_id)) + { + send_ind_evt = TRUE; + } + } + +#if BTA_HL_DEBUG == TRUE + if (!send_ind_evt) + { + APPL_TRACE_DEBUG1("bta_hl_mca_delete_mdl_ind is_send_ind_evt =%d", send_ind_evt); + } +#endif + + if (send_ind_evt) + { + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + evt_data.delete_mdl_ind.mcl_handle = p_mcb->mcl_handle; + evt_data.delete_mdl_ind.app_handle = p_acb->app_handle; + evt_data.delete_mdl_ind.mdl_id = p_delete_ind->mdl_id; + p_acb->p_cback(BTA_HL_DELETE_MDL_IND_EVT,(tBTA_HL *) &evt_data ); + } +} + + + +/******************************************************************************* +** +** Function bta_hl_api_dch_abort +** +** Description Process the API DCH abort request +** +** Returns void +** +*******************************************************************************/ +static void bta_hl_api_dch_abort(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) +{ + + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + UINT8 app_idx, mcl_idx, mdl_idx; + tBTA_HL_APP_CB *p_acb; + tBTA_HL_MCL_CB *p_mcb; + tBTA_HL_MDL_CB *p_dcb; + tBTA_HL evt_data; + + + if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_abort.mcl_handle, &app_idx, &mcl_idx )) + { + + if (!bta_hl_find_dch_setup_mdl_idx(app_idx, mcl_idx, &mdl_idx )) + { + status = BTA_HL_STATUS_NO_MDL_ID_FOUND; + } + else + { + p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + if (p_dcb->abort_oper) + { + /* abort already in progress*/ + status = BTA_HL_STATUS_FAIL; + } + else + { + p_dcb->abort_oper = BTA_HL_ABORT_LOCAL_MASK; + } + } + } + else + { + status = BTA_HL_STATUS_INVALID_MCL_HANDLE; + } + + +#if BTA_HL_DEBUG == TRUE + if (status != BTA_HL_STATUS_OK) + { + APPL_TRACE_DEBUG1("bta_hl_api_dch_abort status=%s", bta_hl_status_code(status)); + } +#endif + switch (status) + { + case BTA_HL_STATUS_OK: + + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ABORT_EVT, p_data); + break; + case BTA_HL_STATUS_NO_MDL_ID_FOUND: + case BTA_HL_STATUS_FAIL: + + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + bta_hl_build_abort_cfm(&evt_data, + p_acb->app_handle, + p_mcb->mcl_handle, + BTA_HL_STATUS_FAIL); + p_acb->p_cback(BTA_HL_DCH_ABORT_CFM_EVT,(tBTA_HL *) &evt_data ); + break; + case BTA_HL_STATUS_INVALID_BD_ADDR: + case BTA_HL_STATUS_INVALID_APP_HANDLE: + default: + APPL_TRACE_ERROR1("Status code=%d", status); + break; + } +} + +/******************************************************************************* +** +** Function bta_hl_hdl_event +** +** Description HL main event handling function. +** +** Returns void +** +*******************************************************************************/ +BOOLEAN bta_hl_hdl_event(BT_HDR *p_msg) +{ + UINT8 app_idx, mcl_idx, mdl_idx; + BOOLEAN success = TRUE; + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("BTA HL Event Handler: Event [%s]", + bta_hl_evt_code(p_msg->event)); +#endif + + switch (p_msg->event) + { + case BTA_HL_API_ENABLE_EVT: + bta_hl_api_enable(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + case BTA_HL_API_DISABLE_EVT: + bta_hl_api_disable(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + case BTA_HL_API_REGISTER_EVT: + bta_hl_api_register(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + case BTA_HL_API_DEREGISTER_EVT: + bta_hl_api_deregister(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + case BTA_HL_API_CCH_OPEN_EVT: + bta_hl_api_cch_open(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + case BTA_HL_API_CCH_CLOSE_EVT: + bta_hl_api_cch_close(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + case BTA_HL_API_DCH_OPEN_EVT: + bta_hl_api_dch_open(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + case BTA_HL_API_DCH_CLOSE_EVT: + bta_hl_api_dch_close(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + case BTA_HL_API_DELETE_MDL_EVT: + bta_hl_api_delete_mdl(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + case BTA_HL_API_DCH_RECONNECT_EVT: + bta_hl_api_dch_reconnect(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + + case BTA_HL_API_DCH_ECHO_TEST_EVT: + bta_hl_api_dch_echo_test(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + + case BTA_HL_API_SDP_QUERY_EVT: + bta_hl_api_sdp_query(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + + case BTA_HL_MCA_DELETE_CFM_EVT: + bta_hl_mca_delete_mdl_cfm(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + + case BTA_HL_MCA_DELETE_IND_EVT: + bta_hl_mca_delete_mdl_ind(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + + case BTA_HL_SDP_QUERY_OK_EVT: + case BTA_HL_SDP_QUERY_FAIL_EVT: + bta_hl_sdp_query_results(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + case BTA_HL_API_DCH_ABORT_EVT: + bta_hl_api_dch_abort(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); + break; + + + default: + if (p_msg->event < BTA_HL_DCH_EVT_MIN) + { + if (bta_hl_find_cch_cb_indexes((tBTA_HL_DATA *) p_msg, &app_idx, &mcl_idx)) + { + bta_hl_cch_sm_execute( app_idx, + mcl_idx, + p_msg->event, (tBTA_HL_DATA *) p_msg); + } + else + { +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_ERROR1("unable to find control block indexes for CCH: [event=%s]", + bta_hl_evt_code(p_msg->event)); +#else + APPL_TRACE_ERROR1("unable to find control block indexes for CCH: [event=%d]", p_msg->event); +#endif + success = FALSE; + } + } + else + { + if (bta_hl_find_dch_cb_indexes((tBTA_HL_DATA *) p_msg, &app_idx, &mcl_idx, &mdl_idx)) + { + bta_hl_dch_sm_execute( app_idx, + mcl_idx, + mdl_idx, + p_msg->event, (tBTA_HL_DATA *) p_msg); + } + else + { + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_ERROR1("unable to find control block indexes for DCH : [event=%s]", + bta_hl_evt_code(p_msg->event)); +#else + APPL_TRACE_ERROR1("unable to find control block indexes for DCH: [event=%d]", p_msg->event); +#endif + success = FALSE; + } + } + + break; + } + + return(success); +} + + +/***************************************************************************** +** Debug Functions +*****************************************************************************/ +#if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) + +/******************************************************************************* +** +** Function bta_hl_cch_state_code +** +** Description Map CCH state code to the corresponding state string +** +** Returns string pointer for the associated state name +** +*******************************************************************************/ +static char *bta_hl_cch_state_code(tBTA_HL_CCH_STATE state_code) +{ + switch (state_code) + { + case BTA_HL_CCH_IDLE_ST: + return "BTA_HL_CCH_IDLE_ST"; + case BTA_HL_CCH_OPENING_ST: + return "BTA_HL_CCH_OPENING_ST"; + case BTA_HL_CCH_OPEN_ST: + return "BTA_HL_CCH_OPEN_ST"; + case BTA_HL_CCH_CLOSING_ST: + return "BTA_HL_CCH_CLOSING_ST"; + default: + return "Unknown CCH state code"; + } +} + +/******************************************************************************* +** +** Function bta_hl_dch_state_code +** +** Description Map DCH state code to the corresponding state string +** +** Returns string pointer for the associated state name +** +*******************************************************************************/ +static char *bta_hl_dch_state_code(tBTA_HL_DCH_STATE state_code) +{ + switch (state_code) + { + case BTA_HL_DCH_IDLE_ST: + return "BTA_HL_DCH_IDLE_ST"; + case BTA_HL_DCH_OPENING_ST: + return "BTA_HL_DCH_OPENING_ST"; + case BTA_HL_DCH_OPEN_ST: + return "BTA_HL_DCH_OPEN_ST"; + case BTA_HL_DCH_CLOSING_ST: + return "BTA_HL_DCH_CLOSING_ST"; + default: + return "Unknown DCH state code"; + } +} +#endif /* Debug Functions */ +#endif /* HL_INCLUDED */ diff --git a/bta/hl/bta_hl_sdp.c b/bta/hl/bta_hl_sdp.c new file mode 100644 index 0000000..765f6c1 --- /dev/null +++ b/bta/hl/bta_hl_sdp.c @@ -0,0 +1,429 @@ +/***************************************************************************** +** +** Name: bta_hl_sdp.c +** +** File: Implements the SDP functions used by HeaLth device profile +** +** Copyright (c) 1998-2011, Broadcom Corp., All Rights Reserved. +** Broadcom Bluetooth Core. Proprietary and confidential. +** +*****************************************************************************/ + +#include <string.h> + +#include "bt_target.h" +#if defined(HL_INCLUDED) && (HL_INCLUDED == TRUE) + +#include "sdp_api.h" +#include "bta_hl_int.h" + + +/******************************************************************************* +** +** Function bta_hl_fill_sup_feature_list +** +** Description Fill the supported features from teh SDP record +** +** Returns TRUE if found, FALSE if not +** If found, the passed protocol list element is filled in. +** +*******************************************************************************/ +BOOLEAN bta_hl_fill_sup_feature_list( const tSDP_DISC_ATTR *p_attr, + tBTA_HL_SUP_FEATURE_LIST_ELEM *p_list) +{ + tSDP_DISC_ATTR *p_sattr; + UINT8 seq_len, item_cnt; + UINT8 list_cnt=0; + BOOLEAN status=TRUE; + + for (p_attr = p_attr->attr_value.v.p_sub_attr; p_attr; p_attr = p_attr->p_next_attr) + { + /* mdep sequence */ + if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) + { + return(FALSE); + } + seq_len =SDP_DISC_ATTR_LEN(p_attr->attr_len_type); + item_cnt=0; + + for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr && (item_cnt < 4) ; p_sattr = p_sattr->p_next_attr) + { + /* for each mdep list */ + + p_list->list_elem[list_cnt].p_mdep_desp = NULL; + switch (item_cnt) + { + case 0: + p_list->list_elem[list_cnt].mdep_id = p_sattr->attr_value.v.u8; + break; + case 1: + p_list->list_elem[list_cnt].data_type = p_sattr->attr_value.v.u16; + break; + case 2: + p_list->list_elem[list_cnt].mdep_role = (tBTA_HL_MDEP_ROLE) p_sattr->attr_value.v.u8; + break; + case 3: + p_list->list_elem[list_cnt].p_mdep_desp = (char *) p_sattr->attr_value.v.array; + break; + } + + item_cnt++; + } + list_cnt++; + } + p_list->num_elems = list_cnt; + return(status); +} + +/******************************************************************************* +** +** Function bta_hl_compose_supported_feature_list +** +** Description This function is called to compose a data sequence from +** the supported feature element list struct pointer +** +** Returns the length of the data sequence +** +*******************************************************************************/ +int bta_hl_compose_supported_feature_list( UINT8 *p, UINT16 num_elem, + const tBTA_HL_SUP_FEATURE_ELEM *p_elem_list) +{ + UINT16 xx, str_len, seq_len; + UINT8 *p_head = p; + + for (xx = 0; xx < num_elem; xx++, p_elem_list++) + { + UINT8_TO_BE_STREAM (p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); + seq_len=7; + str_len=0; + if (p_elem_list->p_mdep_desp) + { + str_len = strlen(p_elem_list->p_mdep_desp)+1; + seq_len += str_len+2; /* todo add a # symbol for 2 */ + } + + *p++ = (UINT8) seq_len; + + UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE); + UINT8_TO_BE_STREAM (p, p_elem_list->mdep_id); + UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM (p, p_elem_list->data_type); + UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE); + UINT8_TO_BE_STREAM (p, p_elem_list->mdep_role); + + if (str_len) + { + UINT8_TO_BE_STREAM (p, (TEXT_STR_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); + UINT8_TO_BE_STREAM (p, str_len); + ARRAY_TO_BE_STREAM(p, p_elem_list->p_mdep_desp, str_len); + } + } + + return(p - p_head); +} + +/******************************************************************************* +** +** Function bta_hl_add_sup_feature_list +** +** Description This function is called to add a protocol descriptor list to +** a record. This would be through the SDP database maintenance API. +** If the protocol list already exists in the record, it is replaced +** with the new list. +** +** Returns TRUE if added OK, else FALSE +** +*******************************************************************************/ +BOOLEAN bta_hl_add_sup_feature_list (UINT32 handle, UINT16 num_elem, + const tBTA_HL_SUP_FEATURE_ELEM *p_elem_list) +{ + UINT8 *p_buf; + int offset; + BOOLEAN result = FALSE; + + if ((p_buf = (UINT8 *)GKI_getbuf(BTA_HL_SUP_FEATURE_SDP_BUF_SIZE)) != NULL) + { + offset = bta_hl_compose_supported_feature_list(p_buf, num_elem, p_elem_list); + result = SDP_AddAttribute (handle, ATTR_ID_HDP_SUP_FEAT_LIST, + DATA_ELE_SEQ_DESC_TYPE, (UINT32) offset, p_buf); + GKI_freebuf(p_buf); + } + return result; +} +/***************************************************************************** +** +** Function: bta_hl_sdp_register +** +** Purpose: Register an HDP application with SDP +** +** Parameters: p_cb - Pointer to MA instance control block +** p_service_name - MA server name +** inst_id - MAS instance ID +** msg_type - Supported message type(s) +** +** +** Returns: void +** +*****************************************************************************/ +tBTA_HL_STATUS bta_hl_sdp_register (UINT8 app_idx) +{ + UINT16 svc_class_id_list[BTA_HL_NUM_SVC_ELEMS]; + tSDP_PROTOCOL_ELEM proto_elem_list[BTA_HL_NUM_PROTO_ELEMS]; + tSDP_PROTO_LIST_ELEM add_proto_list; + tBTA_HL_SUP_FEATURE_LIST_ELEM sup_feature_list; + UINT16 browse_list[] = {UUID_SERVCLASS_PUBLIC_BROWSE_GROUP}; + UINT8 i,j, cnt,mdep_id, mdep_role; + UINT8 data_exchange_spec = BTA_HL_SDP_IEEE_11073_20601; + UINT8 mcap_sup_proc = BTA_HL_MCAP_SUP_PROC_MASK; + UINT16 profile_uuid = UUID_SERVCLASS_HDP_PROFILE; + UINT16 version = BTA_HL_VERSION_01_00; + UINT8 num_services=1; + tBTA_HL_APP_CB *p_cb = BTA_HL_GET_APP_CB_PTR(app_idx); + BOOLEAN result = TRUE; + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("bta_hl_sdp_register app_idx=%d",app_idx); +#endif + + if ((p_cb->sup_feature.app_role_mask == BTA_HL_MDEP_ROLE_MASK_SOURCE) && + (!p_cb->sup_feature.advertize_source_sdp)) + { + return BTA_HL_STATUS_OK; + } + + if ((p_cb->sdp_handle = SDP_CreateRecord()) == 0) + { + return BTA_HL_STATUS_SDP_NO_RESOURCE; + } + + num_services=1; + svc_class_id_list[0]= UUID_SERVCLASS_HDP_SOURCE; + if (p_cb->sup_feature.app_role_mask == BTA_HL_MDEP_ROLE_MASK_SINK) + { + svc_class_id_list[0]= UUID_SERVCLASS_HDP_SINK; + } + else + { + if (p_cb->sup_feature.app_role_mask != BTA_HL_MDEP_ROLE_MASK_SOURCE) + { + /* dual role */ + num_services=2; + svc_class_id_list[1]= UUID_SERVCLASS_HDP_SINK; + } + } + result &= SDP_AddServiceClassIdList(p_cb->sdp_handle, num_services, svc_class_id_list); + + if (result) + { + /* add the protocol element sequence */ + proto_elem_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP; + proto_elem_list[0].num_params = 1; + proto_elem_list[0].params[0] = p_cb->ctrl_psm; + proto_elem_list[1].protocol_uuid = UUID_PROTOCOL_MCAP_CTRL; + proto_elem_list[1].num_params = 1; + proto_elem_list[1].params[0] = version; + result &= SDP_AddProtocolList(p_cb->sdp_handle, BTA_HL_NUM_PROTO_ELEMS, proto_elem_list); + + result &= SDP_AddProfileDescriptorList(p_cb->sdp_handle, profile_uuid, version); + } + + if (result) + { + add_proto_list.num_elems = BTA_HL_NUM_ADD_PROTO_ELEMS; + add_proto_list.list_elem[0].protocol_uuid = UUID_PROTOCOL_L2CAP; + add_proto_list.list_elem[0].num_params = 1; + add_proto_list.list_elem[0].params[0] = p_cb->data_psm; + add_proto_list.list_elem[1].protocol_uuid = UUID_PROTOCOL_MCAP_DATA; + add_proto_list.list_elem[1].num_params = 0; + result &= SDP_AddAdditionProtoLists(p_cb->sdp_handle, BTA_HL_NUM_ADD_PROTO_LISTS, + (tSDP_PROTO_LIST_ELEM *)&add_proto_list); + } + + if (result) + { + if (p_cb->srv_name[0] ) + { + result &= SDP_AddAttribute(p_cb->sdp_handle, + (UINT16)ATTR_ID_SERVICE_NAME, + (UINT8)TEXT_STR_DESC_TYPE, + (UINT32)(strlen(p_cb->srv_name) + 1), + (UINT8 *)p_cb->srv_name); + } /* end of setting optional service name */ + } + + if (result) + { + if (p_cb->srv_desp[0] ) + { + result &= SDP_AddAttribute(p_cb->sdp_handle, + (UINT16)ATTR_ID_SERVICE_DESCRIPTION, + (UINT8)TEXT_STR_DESC_TYPE, + (UINT32)(strlen(p_cb->srv_desp) + 1), + (UINT8 *)p_cb->srv_desp); + + } /* end of setting optional service description */ + + } + + if (result) + { + if (p_cb->provider_name[0] ) + { + result &= SDP_AddAttribute(p_cb->sdp_handle, + (UINT16)ATTR_ID_PROVIDER_NAME, + (UINT8)TEXT_STR_DESC_TYPE, + (UINT32)(strlen(p_cb->provider_name) + 1), + (UINT8 *)p_cb->provider_name); + } /* end of setting optional provider name */ + } + + /* add supported feture list */ + + if (result) + { + cnt=0; + for (i=1; i<= p_cb->sup_feature.num_of_mdeps; i++) + { + mdep_id = (UINT8)p_cb->sup_feature.mdep[i].mdep_id; + mdep_role = (UINT8)p_cb->sup_feature.mdep[i].mdep_cfg.mdep_role; + + for (j=0; j<p_cb->sup_feature.mdep[i].mdep_cfg.num_of_mdep_data_types; j++) + { + sup_feature_list.list_elem[cnt].mdep_id = mdep_id; + sup_feature_list.list_elem[cnt].mdep_role = mdep_role; + sup_feature_list.list_elem[cnt].data_type = p_cb->sup_feature.mdep[i].mdep_cfg.data_cfg[j].data_type; + if (p_cb->sup_feature.mdep[i].mdep_cfg.data_cfg[j].desp[0] != '\0') + { + sup_feature_list.list_elem[cnt].p_mdep_desp = p_cb->sup_feature.mdep[i].mdep_cfg.data_cfg[j].desp; + } + else + { + sup_feature_list.list_elem[cnt].p_mdep_desp = NULL; + } + + cnt++; + if (cnt>BTA_HL_NUM_SUP_FEATURE_ELEMS) + { + result = FALSE; + break; + } + } + } + sup_feature_list.num_elems = cnt; + result &= bta_hl_add_sup_feature_list (p_cb->sdp_handle, + sup_feature_list.num_elems, + sup_feature_list.list_elem); + } + if (result) + { + result &= SDP_AddAttribute(p_cb->sdp_handle, ATTR_ID_HDP_DATA_EXCH_SPEC, UINT_DESC_TYPE, + (UINT32)1, (UINT8*)&data_exchange_spec); + } + + if (result) + { + + result &= SDP_AddAttribute(p_cb->sdp_handle, ATTR_ID_HDP_MCAP_SUP_PROC, UINT_DESC_TYPE, + (UINT32)1, (UINT8*)&mcap_sup_proc); + } + + if (result) + { + result &= SDP_AddUuidSequence(p_cb->sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, browse_list); + } + + if (result) + { + for(i=0; i < num_services; i++) + { + bta_sys_add_uuid(svc_class_id_list[i]); + APPL_TRACE_DEBUG2("dbg bta_sys_add_uuid i=%d uuid=0x%x", i, svc_class_id_list[i]); //todo + } + } + else + { + if (p_cb->sdp_handle) + { + SDP_DeleteRecord(p_cb->sdp_handle); + p_cb->sdp_handle = 0; + } + status = BTA_HL_STATUS_SDP_FAIL; + } +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("bta_hl_sdp_register status=%s", bta_hl_status_code(status)); +#endif + return status; +} + +/******************************************************************************* +** +** Function bta_hl_find_sink_or_src_srv_class_in_db +** +** Description This function queries an SDP database for either a HDP Sink or +** Source service class ID. +** If the p_start_rec pointer is NULL, it looks from the beginning +** of the database, else it continues from the next record after +** p_start_rec. +** +** Returns Pointer to record containing service class, or NULL +** +*******************************************************************************/ +tSDP_DISC_REC *bta_hl_find_sink_or_src_srv_class_in_db (const tSDP_DISCOVERY_DB *p_db, + const tSDP_DISC_REC *p_start_rec) +{ +#if SDP_CLIENT_ENABLED == TRUE + tSDP_DISC_REC *p_rec; + tSDP_DISC_ATTR *p_attr, *p_sattr; + + /* Must have a valid database */ + if (p_db == NULL) + return(NULL); + + + if (!p_start_rec) + { + + p_rec = p_db->p_first_rec; + } + else + { + p_rec = p_start_rec->p_next_rec; + } + + while (p_rec) + { + p_attr = p_rec->p_first_attr; + while (p_attr) + { + if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) + && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) + { + for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) + { + if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) + && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) + && ( (p_sattr->attr_value.v.u16 == UUID_SERVCLASS_HDP_SINK) || + (p_sattr->attr_value.v.u16 == UUID_SERVCLASS_HDP_SOURCE)) ) + { + return(p_rec); + } + } + break; + } + + p_attr = p_attr->p_next_attr; + } + + p_rec = p_rec->p_next_rec; + } +#endif + /* If here, no matching UUID found */ + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG0("bta_hl_find_sink_or_src_srv_class_in_db failed"); +#endif + + return(NULL); +} +#endif /* HL_INCLUDED */ diff --git a/bta/hl/bta_hl_utils.c b/bta/hl/bta_hl_utils.c new file mode 100644 index 0000000..169e965 --- /dev/null +++ b/bta/hl/bta_hl_utils.c @@ -0,0 +1,3324 @@ +/*********************************************a******************************** +** +** Name: bta_hl_utils.c +** +** Description: This file implements utility functions for the +** HeaLth device profile (HL). +** +** Copyright (c) 2003-2009, Broadcom Corp., All Rights Reserved. +** Broadcom Bluetooth Core. Proprietary and confidential. +** +*****************************************************************************/ + +#include <stdio.h> +#include <string.h> + +#include "bt_target.h" +#if defined(HL_INCLUDED) && (HL_INCLUDED == TRUE) + + +#include "gki.h" +#include "utl.h" +#include "bd.h" +#include "bta_fs_api.h" +#include "bta_hl_int.h" +#include "bta_hl_co.h" +#include "mca_defs.h" +#include "mca_api.h" + + +/******************************************************************************* +** +** Function bta_hl_set_ctrl_psm_for_dch +** +** Description This function set the control PSM for the DCH setup +** +** Returns BOOLEAN - TRUE - control PSM setting is successful +*******************************************************************************/ +BOOLEAN bta_hl_set_ctrl_psm_for_dch(UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdl_idx, UINT16 ctrl_psm) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + BOOLEAN success = TRUE, update_ctrl_psm = FALSE; + + if (p_mcb->sdp.num_recs) + { + if (p_mcb->ctrl_psm != ctrl_psm) + { + /* can not use a different ctrl PSM than the current one*/ + success = FALSE; + } + } + else + { + /* No SDP info control i.e. channel was opened by the peer */ + update_ctrl_psm = TRUE; + } + + if (success && update_ctrl_psm) + { + p_mcb->ctrl_psm = ctrl_psm; + } + + +#if BTA_HL_DEBUG == TRUE + if (!success) + { + APPL_TRACE_DEBUG4("bta_hl_set_ctrl_psm_for_dch num_recs=%d success=%d update_ctrl_psm=%d ctrl_psm=0x%x ", + p_mcb->sdp.num_recs, success, update_ctrl_psm, ctrl_psm ); + } +#endif + + return success; +} + + +/******************************************************************************* +** +** Function bta_hl_find_sdp_idx_using_ctrl_psm +** +** Description +** +** Returns UINT8 pool_id +** +*******************************************************************************/ +BOOLEAN bta_hl_find_sdp_idx_using_ctrl_psm(tBTA_HL_SDP *p_sdp, + UINT16 ctrl_psm, + UINT8 *p_sdp_idx) +{ + BOOLEAN found=FALSE; + tBTA_HL_SDP_REC *p_rec; + UINT8 i; + + if (ctrl_psm != 0) + { + for (i=0; i<p_sdp->num_recs; i++) + { + p_rec = &p_sdp->sdp_rec[i]; + if (p_rec->ctrl_psm == ctrl_psm) + { + *p_sdp_idx = i; + found = TRUE; + break; + } + } + } + else + { + *p_sdp_idx = 0; + found = TRUE; + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG3("bta_hl_find_sdp_idx_using_ctrl_psm found=%d sdp_idx=%d ctrl_psm=0x%x ", + found, *p_sdp_idx, ctrl_psm ); + } +#endif + return found; +} + +/******************************************************************************* +** +** Function bta_hl_set_user_tx_pool_id +** +** Description This function sets the user tx pool id +** +** Returns UINT8 pool_id +** +*******************************************************************************/ + +UINT8 bta_hl_set_user_tx_pool_id(UINT16 max_tx_size) +{ + UINT8 pool_id; + + if (max_tx_size > GKI_get_pool_bufsize (OBX_FCR_TX_POOL_ID)) + { + pool_id = BTA_HL_LRG_DATA_POOL_ID; + } + else + { + pool_id = L2CAP_DEFAULT_ERM_POOL_ID; + } + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG3("bta_hl_set_user_rx_pool_id pool_id=%d max_tx_size=%d default_ertm_pool_size=%d", + pool_id, max_tx_size, GKI_get_pool_bufsize (OBX_FCR_TX_POOL_ID)); +#endif + + return pool_id; +} + +/******************************************************************************* +** +** Function bta_hl_set_user_rx_pool_id +** +** Description This function sets the user trx pool id +** +** Returns UINT8 pool_id +** +*******************************************************************************/ + +UINT8 bta_hl_set_user_rx_pool_id(UINT16 mtu) +{ + UINT8 pool_id; + + if (mtu > GKI_get_pool_bufsize (OBX_FCR_RX_POOL_ID)) + { + pool_id = BTA_HL_LRG_DATA_POOL_ID; + } + else + { + pool_id = L2CAP_DEFAULT_ERM_POOL_ID; + } + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG3("bta_hl_set_user_rx_pool_id pool_id=%d mtu=%d default_ertm_pool_size=%d", + pool_id, mtu, GKI_get_pool_bufsize (OBX_FCR_RX_POOL_ID)); +#endif + + return pool_id; +} + + + +/******************************************************************************* +** +** Function bta_hl_set_tx_win_size +** +** Description This function sets the tx window size +** +** Returns UINT8 tx_win_size +** +*******************************************************************************/ +UINT8 bta_hl_set_tx_win_size(UINT16 mtu, UINT16 mps) +{ + UINT8 tx_win_size; + + if (mtu <= mps) + { + tx_win_size =1; + } + else + { + if (mps > 0) + { + tx_win_size = (mtu/mps)+1; + } + else + { + APPL_TRACE_ERROR0("The MPS is zero"); + tx_win_size = 10; + } + } + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG3("bta_hl_set_tx_win_size win_size=%d mtu=%d mps=%d", + tx_win_size, mtu, mps); +#endif + return tx_win_size; +} + +/******************************************************************************* +** +** Function bta_hl_set_mps +** +** Description This function sets the MPS +** +** Returns UINT16 MPS +** +*******************************************************************************/ +UINT16 bta_hl_set_mps(UINT16 mtu) +{ + UINT16 mps; + if (mtu > BTA_HL_L2C_MPS) + { + mps = BTA_HL_L2C_MPS; + } + else + { + mps = mtu; + } +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG2("bta_hl_set_mps mps=%d mtu=%d", + mps, mtu); +#endif + return mps; +} + + +/******************************************************************************* +** +** Function bta_hl_clean_mdl_cb +** +** Description This function clean up the specified MDL control block +** +** Returns void +** +*******************************************************************************/ +void bta_hl_clean_mdl_cb(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx) +{ + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG3("bta_hl_clean_mdl_cb app_idx=%d mcl_idx=%d mdl_idx=%d", + app_idx, mcl_idx, mdl_idx); +#endif + utl_freebuf((void **) &p_dcb->p_tx_pkt); + utl_freebuf((void **) &p_dcb->p_rx_pkt); + utl_freebuf((void **) &p_dcb->p_echo_tx_pkt); + utl_freebuf((void **) &p_dcb->p_echo_rx_pkt); + + memset((void *)p_dcb, 0 , sizeof(tBTA_HL_MDL_CB)); +} + + +/******************************************************************************* +** +** Function bta_hl_get_buf +** +** Description This function allocate a buffer based on the specified data size +** +** Returns BT_HDR *. +** +*******************************************************************************/ +BT_HDR * bta_hl_get_buf(UINT16 data_size) +{ + BT_HDR *p_new; + UINT16 size = data_size + L2CAP_MIN_OFFSET + BT_HDR_SIZE; + + if (size < GKI_MAX_BUF_SIZE) + { + p_new = (BT_HDR *)GKI_getbuf(size); + } + else + { + p_new = (BT_HDR *) GKI_getpoolbuf(BTA_HL_LRG_DATA_POOL_ID); + } + + if (p_new) + { + p_new->len = data_size; + p_new->offset = L2CAP_MIN_OFFSET; + } + + return p_new; +} + +/******************************************************************************* +** +** Function bta_hl_find_service_in_db +** +** Description This function check the specified service class(es) can be find in +** the received SDP database +** +** Returns BOOLEAN TRUE - found +** FALSE - not found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_service_in_db( UINT8 app_idx, UINT8 mcl_idx, + UINT16 service_uuid, + tSDP_DISC_REC **pp_rec ) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + BOOLEAN found = TRUE; + + switch (service_uuid) + { + case UUID_SERVCLASS_HDP_SINK: + case UUID_SERVCLASS_HDP_SOURCE: + if ((*pp_rec = SDP_FindServiceInDb(p_mcb->p_db, service_uuid, + *pp_rec)) == NULL) + { + found = FALSE; + } + break; + default: + if (((*pp_rec = bta_hl_find_sink_or_src_srv_class_in_db(p_mcb->p_db, + *pp_rec)) == NULL)) + { + found = FALSE; + } + break; + } + return found; +} + +/******************************************************************************* +** +** Function bta_hl_get_service_uuids +** +** +** Description This function finds the service class(es) for both CCH and DCH oeprations +** +** Returns UINT16 - service_id +** if service_uuid = 0xFFFF then it means service uuid +** can be either Sink or Source +** +*******************************************************************************/ +UINT16 bta_hl_get_service_uuids(UINT8 sdp_oper, UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdl_idx ) +{ + tBTA_HL_MDL_CB *p_dcb; + UINT16 service_uuid = 0xFFFF; /* both Sink and Source */ + + switch (sdp_oper) + { + + case BTA_HL_SDP_OP_DCH_OPEN_INIT: + case BTA_HL_SDP_OP_DCH_RECONNECT_INIT: + p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + if (p_dcb->local_mdep_id != BTA_HL_ECHO_TEST_MDEP_ID) + { + if (p_dcb->peer_mdep_role == BTA_HL_MDEP_ROLE_SINK) + { + service_uuid = UUID_SERVCLASS_HDP_SINK; + } + else + { + service_uuid = UUID_SERVCLASS_HDP_SOURCE; + } + } + break; + case BTA_HL_SDP_OP_CCH_INIT: + default: + /* use default that is both Sink and Source */ + break; + } +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("bta_hl_get_service_uuids service_uuid=0x%x",service_uuid ); +#endif + return service_uuid; +} + +/******************************************************************************* +** +** Function bta_hl_find_echo_cfg_rsp +** +** +** Description This function finds the configuration response for the echo test +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_echo_cfg_rsp(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdep_idx, UINT8 cfg, + UINT8 *p_cfg_rsp) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MDEP *p_mdep= &p_acb->sup_feature.mdep[mdep_idx]; + BOOLEAN status =TRUE; + + if (p_mdep->mdep_id == BTA_HL_ECHO_TEST_MDEP_ID) + { + if ((cfg == BTA_HL_DCH_CFG_RELIABLE) || (cfg == BTA_HL_DCH_CFG_STREAMING)) + { + *p_cfg_rsp = cfg; + } + else if (cfg == BTA_HL_DCH_CFG_NO_PREF ) + { + *p_cfg_rsp = BTA_HL_DEFAULT_ECHO_TEST_SRC_DCH_CFG; + } + else + { + status = FALSE; + APPL_TRACE_ERROR0("Inavlid echo cfg value"); + } + return status; + } + +#if BTA_HL_DEBUG == TRUE + if (!status) + { + APPL_TRACE_DEBUG4("bta_hl_find_echo_cfg_rsp status=failed app_idx=%d mcl_idx=%d mdep_idx=%d cfg=%d", + app_idx, mcl_idx, mdep_idx, cfg); + } +#endif + + return status; +} + +/******************************************************************************* +** +** Function bta_hl_validate_dch_cfg +** +** Description This function validate the DCH configuration +** +** Returns BOOLEAN - TRUE cfg is valid +** FALSE not valid +** +*******************************************************************************/ +BOOLEAN bta_hl_validate_cfg(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + UINT8 cfg) +{ + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + BOOLEAN is_valid =FALSE; + + + if (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx) && + (cfg != BTA_HL_DCH_CFG_RELIABLE)) + { + APPL_TRACE_ERROR0("the first DCH should be a reliable channel"); + return is_valid; + } + + switch (p_dcb->local_cfg) + { + case BTA_HL_DCH_CFG_NO_PREF: + + if ((cfg == BTA_HL_DCH_CFG_RELIABLE) || (cfg == BTA_HL_DCH_CFG_STREAMING)) + { + is_valid = TRUE; + } + break; + case BTA_HL_DCH_CFG_RELIABLE: + case BTA_HL_DCH_CFG_STREAMING: + if (p_dcb->local_cfg == cfg ) + { + is_valid = TRUE; + } + break; + default: + break; + } + +#if BTA_HL_DEBUG == TRUE + if (!is_valid) + { + APPL_TRACE_DEBUG2("bta_hl_validate_dch_open_cfg is_valid=%d, cfg=%d", is_valid, cfg ); + } +#endif + return is_valid; +} + +/******************************************************************************* +** +** Function bta_hl_find_cch_cb_indexes +** +** Description This function finds the indexes needed for the CCH state machine +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_cch_cb_indexes(tBTA_HL_DATA *p_msg, + UINT8 *p_app_idx, + UINT8 *p_mcl_idx) +{ + BOOLEAN found = FALSE; + tBTA_HL_MCL_CB *p_mcb; + UINT8 app_idx, mcl_idx; + + switch (p_msg->hdr.event) + { + case BTA_HL_CCH_SDP_OK_EVT: + case BTA_HL_CCH_SDP_FAIL_EVT: + app_idx = p_msg->cch_sdp.app_idx; + mcl_idx = p_msg->cch_sdp.mcl_idx; + found = TRUE; + break; + + case BTA_HL_MCA_CONNECT_IND_EVT: + + if (bta_hl_find_app_idx_using_handle(p_msg->mca_evt.app_handle, &app_idx)) + { + if (bta_hl_find_mcl_idx(app_idx, p_msg->mca_evt.mca_data.connect_ind.bd_addr, &mcl_idx)) + { + /* local initiated */ + found = TRUE; + } + else if (!bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx)&& + bta_hl_find_avail_mcl_idx(app_idx, &mcl_idx)) + { + /* remote initiated */ + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + p_mcb->in_use = TRUE; + p_mcb->cch_oper = BTA_HL_CCH_OP_REMOTE_OPEN; + found = TRUE; + } + } + break; + + case BTA_HL_MCA_DISCONNECT_IND_EVT: + + if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx)) + { + found = TRUE; + } + else if (bta_hl_find_app_idx_using_handle(p_msg->mca_evt.app_handle, &app_idx) && + bta_hl_find_mcl_idx(app_idx, p_msg->mca_evt.mca_data.disconnect_ind.bd_addr, &mcl_idx)) + { + found = TRUE; + } + + if (found) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + if (p_mcb->cch_oper != BTA_HL_CCH_OP_LOCAL_CLOSE) + { + p_mcb->cch_oper = BTA_HL_CCH_OP_REMOTE_CLOSE; + } + } + break; + + case BTA_HL_MCA_RSP_TOUT_IND_EVT: + + if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx)) + { + found = TRUE; + } + + if (found) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + if (p_mcb->cch_oper != BTA_HL_CCH_OP_REMOTE_CLOSE) + { + p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_CLOSE; + } + } + break; + default: + break; + } + + + if (found) + { + *p_app_idx = app_idx; + *p_mcl_idx = mcl_idx; + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG4("bta_hl_find_cch_cb_indexes event=%s found=%d app_idx=%d mcl_idx=%d", + bta_hl_evt_code(p_msg->hdr.event), found, app_idx, mcl_idx); + } +#endif + + return found; +} + +/******************************************************************************* +** +** Function bta_hl_find_dch_cb_indexes +** +** Description This function finds the indexes needed for the DCH state machine +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_dch_cb_indexes(tBTA_HL_DATA *p_msg, + UINT8 *p_app_idx, + UINT8 *p_mcl_idx, + UINT8 *p_mdl_idx) +{ + BOOLEAN found = FALSE; + tBTA_HL_MCL_CB *p_mcb; + UINT8 app_idx, mcl_idx, mdl_idx; + + switch (p_msg->hdr.event) + { + case BTA_HL_MCA_CREATE_CFM_EVT: + if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) && + bta_hl_find_mdl_idx( app_idx, mcl_idx, p_msg->mca_evt.mca_data.create_cfm.mdl_id, &mdl_idx)) + { + found = TRUE; + } + break; + + case BTA_HL_MCA_CREATE_IND_EVT: + case BTA_HL_MCA_RECONNECT_IND_EVT: + if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) && + bta_hl_find_avail_mdl_idx( app_idx, mcl_idx, &mdl_idx)) + { + found = TRUE; + } + break; + + case BTA_HL_MCA_OPEN_CFM_EVT: + if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) && + bta_hl_find_mdl_idx( app_idx, mcl_idx, p_msg->mca_evt.mca_data.open_cfm.mdl_id, &mdl_idx)) + { + found = TRUE; + } + break; + + case BTA_HL_MCA_OPEN_IND_EVT: + if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) && + bta_hl_find_mdl_idx( app_idx, mcl_idx, p_msg->mca_evt.mca_data.open_ind.mdl_id, &mdl_idx)) + { + found = TRUE; + } + break; + + case BTA_HL_MCA_CLOSE_CFM_EVT: + + if (bta_hl_find_mdl_idx_using_handle((tBTA_HL_MDL_HANDLE)p_msg->mca_evt.mca_data.close_cfm.mdl, + &app_idx, &mcl_idx, &mdl_idx)) + { + found = TRUE; + } + break; + case BTA_HL_MCA_CLOSE_IND_EVT: + + if (bta_hl_find_mdl_idx_using_handle((tBTA_HL_MDL_HANDLE)p_msg->mca_evt.mca_data.close_ind.mdl, + &app_idx, &mcl_idx, &mdl_idx)) + { + found = TRUE; + } + break; + case BTA_HL_API_SEND_DATA_EVT: + + if (bta_hl_find_mdl_idx_using_handle(p_msg->api_send_data.mdl_handle, + &app_idx, &mcl_idx, &mdl_idx )) + { + found = TRUE; + } + + break; + + case BTA_HL_MCA_CONG_CHG_EVT: + + if (bta_hl_find_mdl_idx_using_handle((tBTA_HL_MDL_HANDLE)p_msg->mca_evt.mca_data.cong_chg.mdl, + &app_idx, &mcl_idx, &mdl_idx )) + { + found = TRUE; + } + + break; + + case BTA_HL_MCA_RCV_DATA_EVT: + app_idx = p_msg->mca_rcv_data_evt.app_idx; + mcl_idx = p_msg->mca_rcv_data_evt.mcl_idx; + mdl_idx = p_msg->mca_rcv_data_evt.mdl_idx; + found = TRUE; + break; + case BTA_HL_DCH_RECONNECT_EVT: + case BTA_HL_DCH_OPEN_EVT: + case BTA_HL_DCH_ECHO_TEST_EVT: + case BTA_HL_DCH_SDP_FAIL_EVT: + app_idx = p_msg->dch_sdp.app_idx; + mcl_idx = p_msg->dch_sdp.mcl_idx; + mdl_idx = p_msg->dch_sdp.mdl_idx; + found = TRUE; + break; + case BTA_HL_MCA_RECONNECT_CFM_EVT: + if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) && + bta_hl_find_mdl_idx( app_idx, mcl_idx, p_msg->mca_evt.mca_data.reconnect_cfm.mdl_id, &mdl_idx)) + { + found = TRUE; + } + break; + + + case BTA_HL_API_DCH_CREATE_RSP_EVT: + if (bta_hl_find_mcl_idx_using_handle(p_msg->api_dch_create_rsp.mcl_handle, &app_idx, &mcl_idx)&& + bta_hl_find_mdl_idx( app_idx, mcl_idx,p_msg->api_dch_create_rsp.mdl_id, &mdl_idx)) + { + found = TRUE; + } + break; + case BTA_HL_MCA_ABORT_IND_EVT: + if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) && + bta_hl_find_mdl_idx( app_idx, mcl_idx,p_msg->mca_evt.mca_data.abort_ind.mdl_id, &mdl_idx)) + { + found = TRUE; + } + break; + case BTA_HL_MCA_ABORT_CFM_EVT: + if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) && + bta_hl_find_mdl_idx( app_idx, mcl_idx, p_msg->mca_evt.mca_data.abort_cfm.mdl_id, &mdl_idx)) + { + found = TRUE; + } + break; + case BTA_HL_CI_GET_TX_DATA_EVT: + case BTA_HL_CI_PUT_RX_DATA_EVT: + if (bta_hl_find_mdl_idx_using_handle(p_msg->ci_get_put_data.mdl_handle, &app_idx, &mcl_idx, &mdl_idx)) + { + found = TRUE; + } + break; + case BTA_HL_CI_GET_ECHO_DATA_EVT: + case BTA_HL_CI_PUT_ECHO_DATA_EVT: + if (bta_hl_find_mcl_idx_using_handle(p_msg->ci_get_put_echo_data.mcl_handle, &app_idx, &mcl_idx)) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + mdl_idx = p_mcb->echo_mdl_idx; + found = TRUE; + } + break; + + default: + break; + + } + + if (found) + { + *p_app_idx = app_idx; + *p_mcl_idx = mcl_idx; + *p_mdl_idx = mdl_idx; + } +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG5("bta_hl_find_dch_cb_indexes event=%s found=%d app_idx=%d mcl_idx=%d mdl_idx=%d", + bta_hl_evt_code(p_msg->hdr.event), found, *p_app_idx, *p_mcl_idx, *p_mdl_idx ); + } +#endif + + return found; +} + +/******************************************************************************* +** +** Function bta_hl_allocate_mdl_id +** +** Description This function allocates a MDL ID +** +** Returns UINT16 - MDL ID +** +*******************************************************************************/ +UINT16 bta_hl_allocate_mdl_id(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx ) +{ + UINT16 mdl_id=0; + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + BOOLEAN duplicate_id; + UINT8 i, mdl_cfg_idx; + + do + { + duplicate_id = FALSE; + mdl_id = ((mdl_id+1) & 0xFEFF); + /* check mdl_ids that are used for the current conenctions */ + for (i=0; i< BTA_HL_NUM_MDLS_PER_MCL; i++) + { + if (p_mcb->mdl[i].in_use && + (i != mdl_idx) && + (p_mcb->mdl[i].mdl_id == mdl_id) ) + { + duplicate_id = TRUE; + break; + } + } + + if (duplicate_id) + { + /* start from the beginning to get another MDL value*/ + continue; + } + else + { + /* check mdl_ids that are stored in the persistent memory */ + if (bta_hl_find_mdl_cfg_idx(app_idx,mcl_idx, mdl_id, &mdl_cfg_idx)) + { + duplicate_id = TRUE; + } + else + { + /* found a new MDL value */ + break; + } + } + + }while (TRUE); + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("bta_hl_allocate_mdl OK mdl_id=%d", mdl_id); +#endif + return mdl_id; +} +/******************************************************************************* +** +** Function bta_hl_find_mdl_idx +** +** Description This function finds the MDL index based on mdl_id +** +** Returns BOOLEAN TRUE-found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, UINT16 mdl_id, + UINT8 *p_mdl_idx) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + BOOLEAN found=FALSE; + UINT8 i; + + for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++) + { + if (p_mcb->mdl[i].in_use && + (mdl_id !=0) && + (p_mcb->mdl[i].mdl_id== mdl_id)) + { + found = TRUE; + *p_mdl_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG3("bta_hl_find_mdl_idx found=%d mdl_id=%d mdl_idx=%d ", + found, mdl_id, i); + } +#endif + + return found; +} + +/******************************************************************************* +** +** Function bta_hl_find_an_active_mdl_idx +** +** Description This function finds an active MDL +** +** Returns BOOLEAN TRUE-found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_an_active_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, + UINT8 *p_mdl_idx) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + BOOLEAN found=FALSE; + UINT8 i; + + for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++) + { + if (p_mcb->mdl[i].in_use && + (p_mcb->mdl[i].dch_state == BTA_HL_DCH_OPEN_ST)) + { + found = TRUE; + *p_mdl_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (found) + { + APPL_TRACE_DEBUG4("bta_hl_find_an_opened_mdl_idx found=%d app_idx=%d mcl_idx=%d mdl_idx=%d", + found, app_idx, mcl_idx, i); + } +#endif + + return found; +} + +/******************************************************************************* +** +** Function bta_hl_find_dch_setup_mdl_idx +** +** Description This function finds a MDL which in the DCH setup state +** +** Returns BOOLEAN TRUE-found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_dch_setup_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, + UINT8 *p_mdl_idx) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + BOOLEAN found=FALSE; + UINT8 i; + + for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++) + { + if (p_mcb->mdl[i].in_use && + (p_mcb->mdl[i].dch_state == BTA_HL_DCH_OPENING_ST)) + { + found = TRUE; + *p_mdl_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (found) + { + APPL_TRACE_DEBUG4("bta_hl_find_dch_setup_mdl_idx found=%d app_idx=%d mcl_idx=%d mdl_idx=%d", + found, app_idx, mcl_idx, i); + } +#endif + + return found; +} + +/******************************************************************************* +** +** Function bta_hl_find_an_in_use_mcl_idx +** +** Description This function finds an in-use MCL control block index +** +** Returns BOOLEAN TRUE-found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_an_in_use_mcl_idx(UINT8 app_idx, + UINT8 *p_mcl_idx) +{ + tBTA_HL_MCL_CB *p_mcb; + BOOLEAN found=FALSE; + UINT8 i; + + for (i=0; i < BTA_HL_NUM_MCLS ; i ++) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, i); + if (p_mcb->in_use && + (p_mcb->cch_state != BTA_HL_CCH_IDLE_ST)) + { + found = TRUE; + *p_mcl_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (found) + { + APPL_TRACE_DEBUG3("bta_hl_find_an_in_use_mcl_idx found=%d app_idx=%d mcl_idx=%d ", + found, app_idx, i); + } +#endif + + return found; +} + + +/******************************************************************************* +** +** Function bta_hl_find_an_in_use_app_idx +** +** Description This function finds an in-use application control block index +** +** Returns BOOLEAN TRUE-found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_an_in_use_app_idx(UINT8 *p_app_idx) +{ + tBTA_HL_APP_CB *p_acb ; + BOOLEAN found=FALSE; + UINT8 i; + + for (i=0; i < BTA_HL_NUM_APPS ; i ++) + { + p_acb = BTA_HL_GET_APP_CB_PTR(i); + if (p_acb->in_use) + { + found = TRUE; + *p_app_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (found) + { + APPL_TRACE_DEBUG2("bta_hl_find_an_in_use_app_idx found=%d app_idx=%d ", + found, i); + } +#endif + + return found; +} +/******************************************************************************* +** +** Function bta_hl_find_app_idx +** +** Description This function finds the application control block index based on +** the application ID +** +** Returns BOOLEAN TRUE-found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_app_idx(UINT8 app_id, UINT8 *p_app_idx) +{ + BOOLEAN found=FALSE; + UINT8 i; + + for (i=0; i < BTA_HL_NUM_APPS ; i ++) + { + if (bta_hl_cb.acb[i].in_use && + (bta_hl_cb.acb[i].app_id == app_id)) + { + found = TRUE; + *p_app_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG3("bta_hl_find_app_idx found=%d app_id=%d idx=%d ", + found, app_id, i); +#endif + + return found; +} + + +/******************************************************************************* +** +** Function bta_hl_find_app_idx_using_handle +** +** Description This function finds the application control block index based on +** the application handle +** +** Returns BOOLEAN TRUE-found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_app_idx_using_handle(tBTA_HL_APP_HANDLE app_handle, + UINT8 *p_app_idx) +{ + BOOLEAN found=FALSE; + UINT8 i; + + for (i=0; i < BTA_HL_NUM_APPS ; i ++) + { + if (bta_hl_cb.acb[i].in_use && + (bta_hl_cb.acb[i].app_handle == app_handle)) + { + found = TRUE; + *p_app_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG3("bta_hl_find_app_idx_using_mca_handle status=%d handle=%d app_idx=%d ", + found, app_handle , i); + } +#endif + + return found; +} + + +/******************************************************************************* +** +** Function bta_hl_find_mcl_idx_using_handle +** +** Description This function finds the MCL control block index based on +** the MCL handle +** +** Returns BOOLEAN TRUE-found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_mcl_idx_using_handle( tBTA_HL_MCL_HANDLE mcl_handle, + UINT8 *p_app_idx, UINT8 *p_mcl_idx) +{ + tBTA_HL_APP_CB *p_acb; + BOOLEAN found=FALSE; + UINT8 i,j; + + for (i=0; i<BTA_HL_NUM_APPS; i++) + { + p_acb = BTA_HL_GET_APP_CB_PTR(i); + if (p_acb->in_use) + { + for (j=0; j < BTA_HL_NUM_MCLS ; j++) + { + if ( p_acb->mcb[j].mcl_handle == mcl_handle ) + { + found = TRUE; + *p_app_idx = i; + *p_mcl_idx = j; + break; + } + } + } + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG3("bta_hl_find_mcl_idx_using_handle found=%d app_idx=%d mcl_idx=%d", + found, i, j); + } +#endif + return found; +} + +/******************************************************************************* +** +** Function bta_hl_find_mcl_idx +** +** Description This function finds the MCL control block index based on +** the peer BD address +** +** Returns BOOLEAN TRUE-found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_mcl_idx(UINT8 app_idx, BD_ADDR p_bd_addr, UINT8 *p_mcl_idx) +{ + BOOLEAN found=FALSE; + UINT8 i; + tBTA_HL_MCL_CB *p_mcb; + + for (i=0; i < BTA_HL_NUM_MCLS ; i ++) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, i); + + if (bta_hl_cb.acb[app_idx].mcb[i].in_use && + (!memcmp (bta_hl_cb.acb[app_idx].mcb[i].bd_addr, p_bd_addr, BD_ADDR_LEN))) + { + found = TRUE; + *p_mcl_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG2("bta_hl_find_mcl_idx found=%d idx=%d", + found, i); + } +#endif + return found; +} + + + +/******************************************************************************* +** +** Function bta_hl_find_mdl_idx_using_handle +** +** Description This function finds the MDL control block index based on +** the MDL handle +** +** Returns BOOLEAN TRUE-found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_mdl_idx_using_handle(tBTA_HL_MDL_HANDLE mdl_handle, + UINT8 *p_app_idx,UINT8 *p_mcl_idx, + UINT8 *p_mdl_idx) +{ + tBTA_HL_APP_CB *p_acb; + tBTA_HL_MCL_CB *p_mcb; + tBTA_HL_MDL_CB *p_dcb; + BOOLEAN found=FALSE; + UINT8 i,j,k; + + for (i=0; i < BTA_HL_NUM_APPS ; i ++) + { + p_acb = BTA_HL_GET_APP_CB_PTR(i); + if (p_acb->in_use) + { + for (j=0; j< BTA_HL_NUM_MCLS; j++) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(i,j); + if (p_mcb->in_use) + { + for (k=0; k< BTA_HL_NUM_MDLS_PER_MCL; k++) + { + p_dcb = BTA_HL_GET_MDL_CB_PTR(i,j,k); + if (p_dcb->in_use) + { + if (p_dcb->mdl_handle == mdl_handle) + { + found = TRUE; + *p_app_idx = i; + *p_mcl_idx =j; + *p_mdl_idx = k; + break; + } + } + } + } + } + } + } + + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG2("bta_hl_find_mdl_idx_using_handle found=%d mdl_handle=%d ", + found, mdl_handle); + } +#endif + return found; +} +/******************************************************************************* +** +** Function bta_hl_is_the_first_reliable_existed +** +** Description This function checks whether the first reliable DCH channel +** has been setup on the MCL or not +** +** Returns BOOLEAN - TRUE exist +** FALSE does not exist +** +*******************************************************************************/ +BOOLEAN bta_hl_is_the_first_reliable_existed(UINT8 app_idx, UINT8 mcl_idx ) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + BOOLEAN is_existed =FALSE; + UINT8 i ; + + for (i=0; i< BTA_HL_NUM_MDLS_PER_MCL; i++) + { + if (p_mcb->mdl[i].in_use && p_mcb->mdl[i].is_the_first_reliable) + { + is_existed = TRUE; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("bta_hl_is_the_first_reliable_existed is_existed=%d ",is_existed ); +#endif + return is_existed; +} + +/******************************************************************************* +** +** Function bta_hl_find_non_active_mdl_cfg +** +** Description This function finds a valid MDL configiration index and this +** MDL ID is not active +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_non_active_mdl_cfg(UINT8 app_idx, UINT8 start_mdl_cfg_idx, + UINT8 *p_mdl_cfg_idx) +{ + + tBTA_HL_MCL_CB *p_mcb; + tBTA_HL_MDL_CB *p_dcb; + tBTA_HL_MDL_CFG *p_mdl; + BOOLEAN mdl_in_use; + BOOLEAN found = FALSE; + UINT8 i,j,k; + + for (i = start_mdl_cfg_idx; i< BTA_HL_NUM_MDL_CFGS; i++) + { + mdl_in_use = FALSE; + p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i); + for (j=0; j< BTA_HL_NUM_MCLS; j++) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, j); + if (p_mcb->in_use && + !memcmp(p_mdl->peer_bd_addr,p_mcb->bd_addr,BD_ADDR_LEN)) + { + + for (k=0; k<BTA_HL_NUM_MDLS_PER_MCL; k++) + { + p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, j, k); + + if (p_dcb->in_use && p_mdl->mdl_id == p_dcb->mdl_id) + { + mdl_in_use = TRUE; + break; + } + } + } + + if (mdl_in_use) + { + break; + } + } + + if (!mdl_in_use) + { + *p_mdl_cfg_idx = i; + found = TRUE; + break; + } + } + + return found; +} + +/******************************************************************************* +** +** Function bta_hl_find_mdl_cfg_idx +** +** Description This function finds an available MDL configiration index +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_avail_mdl_cfg_idx(UINT8 app_idx, UINT8 mcl_idx, + UINT8 *p_mdl_cfg_idx) +{ + tBTA_HL_MDL_CFG *p_mdl, *p_mdl1, *p_mdl2; + UINT8 i; + BOOLEAN found=FALSE; + UINT8 first_mdl_cfg_idx, second_mdl_cfg_idx, older_mdl_cfg_idx; + BOOLEAN done; + + + for (i=0; i< BTA_HL_NUM_MDL_CFGS; i++) + { + p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i); + if (!p_mdl->active ) + { + /* found an unused space to store mdl cfg*/ + found=TRUE; + *p_mdl_cfg_idx =i; + break; + } + } + + if (!found) + { + /* all available mdl cfg spaces are in use so we need to find the mdl cfg which is + not currently in use and has the the oldest time stamp to remove*/ + + found = TRUE; + if (bta_hl_find_non_active_mdl_cfg(app_idx,0, &first_mdl_cfg_idx)) + { + if (bta_hl_find_non_active_mdl_cfg(app_idx,(UINT8) (first_mdl_cfg_idx+1), &second_mdl_cfg_idx)) + { + done = FALSE; + while (!done) + { + p_mdl1 = BTA_HL_GET_MDL_CFG_PTR(app_idx, first_mdl_cfg_idx); + p_mdl2 = BTA_HL_GET_MDL_CFG_PTR(app_idx, second_mdl_cfg_idx); + + if (p_mdl1->time < p_mdl2->time) + { + older_mdl_cfg_idx = first_mdl_cfg_idx; + } + else + { + older_mdl_cfg_idx = second_mdl_cfg_idx; + } + + if (bta_hl_find_non_active_mdl_cfg(app_idx,(UINT8) (second_mdl_cfg_idx+1), &second_mdl_cfg_idx)) + { + first_mdl_cfg_idx = older_mdl_cfg_idx; + } + else + { + done = TRUE; + } + } + + *p_mdl_cfg_idx = older_mdl_cfg_idx; + + } + else + { + *p_mdl_cfg_idx = first_mdl_cfg_idx; + } + + } + else + { + found = FALSE; + } + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG2("bta_hl_find_avail_mdl_cfg_idx found=%d mdl_cfg_idx=%d ",found, *p_mdl_cfg_idx ); + } +#endif + + return found; + + +} + +/******************************************************************************* +** +** Function bta_hl_find_mdl_cfg_idx +** +** Description This function finds the MDL configuration index based on +** the MDL ID +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_mdl_cfg_idx(UINT8 app_idx, UINT8 mcl_idx, + tBTA_HL_MDL_ID mdl_id, UINT8 *p_mdl_cfg_idx) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CFG *p_mdl; + UINT8 i ; + BOOLEAN found=FALSE; + for (i=0; i< BTA_HL_NUM_MDL_CFGS; i++) + { + p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i); + if (p_mdl->active && + (!memcmp (p_mcb->bd_addr, p_mdl->peer_bd_addr, BD_ADDR_LEN))&& + (p_mdl->mdl_id == mdl_id)) + { + found=TRUE; + *p_mdl_cfg_idx =i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG2("bta_hl_find_mdl_cfg_idx found=%d mdl_cfg_idx=%d ",found, i ); + } +#endif + + return found; + + +} + + +/******************************************************************************* +** +** Function bta_hl_get_cur_time +** +** Description This function get the cuurent time value +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +BOOLEAN bta_hl_get_cur_time(UINT8 app_idx, UINT8 *p_cur_time) +{ + tBTA_HL_MDL_CFG *p_mdl; + UINT8 i, j, time_latest, time; + BOOLEAN found=FALSE, result=TRUE; + + for (i=0; i< BTA_HL_NUM_MDL_CFGS; i++) + { + p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i); + if (p_mdl->active) + { + found=TRUE; + time_latest = p_mdl->time; + for (j=(i+1); j< BTA_HL_NUM_MDL_CFGS; j++ ) + { + p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, j); + if (p_mdl->active) + { + time = p_mdl->time; + if (time > time_latest) + { + time_latest = time; + } + } + } + break; + } + } + + + if (found) + { + if (time_latest < BTA_HL_MAX_TIME) + { + *p_cur_time = time_latest+1; + } + else + { + /* need to wrap around */ + result = FALSE; + } + } + else + { + *p_cur_time = BTA_HL_MIN_TIME; + } + +#if BTA_HL_DEBUG == TRUE + if (!result) + { + APPL_TRACE_DEBUG2("bta_hl_get_cur_time result=%s cur_time=%d", + (result?"OK":"FAIL"), *p_cur_time); + } +#endif + + return result; +} + +/******************************************************************************* +** +** Function bta_hl_sort_cfg_time_idx +** +** Description This function sort the mdl configuration idx stored in array a +** based on decending time value +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +void bta_hl_sort_cfg_time_idx(UINT8 app_idx, UINT8 *a, UINT8 n) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + UINT8 temp_time, temp_idx; + INT16 i, j; + for (i = 1; i < n; ++i) + { + temp_idx = a[i]; + temp_time = p_acb->mdl_cfg[temp_idx].time; + j = i - 1; + while ((j >= 0) && (temp_time < p_acb->mdl_cfg[a[j]].time)) + { + a[j + 1] = a[j]; + --j; + } + a[j + 1] = temp_idx; + } +} + +/******************************************************************************* +** +** Function bta_hl_compact_mdl_cfg_time +** +** Description This function finds the MDL configuration index based on +** the MDL ID +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +void bta_hl_compact_mdl_cfg_time(UINT8 app_idx) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MDL_CFG *p_mdl; + UINT8 i, time_min, cnt=0; + UINT8 s_arr[BTA_HL_NUM_MDL_CFGS]; + + + for (i=0; i< BTA_HL_NUM_MDL_CFGS; i++) + { + p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i); + if (p_mdl->active ) + { + s_arr[cnt]= i; + cnt++; + } + } + + + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("bta_hl_compact_mdl_cfg_time cnt=%d ",cnt ); +#endif + + + if (cnt) + { + bta_hl_sort_cfg_time_idx(app_idx, s_arr, cnt); + time_min = BTA_HL_MIN_TIME; + for (i=0;i<cnt; i++) + { + p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, s_arr[i]); + p_mdl->time = time_min + i; + bta_hl_co_save_mdl(p_acb->app_id, s_arr[i], p_mdl); + } + } + + +} + + + +/******************************************************************************* +** +** Function bta_hl_is_mdl_exsit_in_mcl +** +** Description This function checks whether the MDL ID +** has already existed in teh MCL or not +** +** Returns BOOLEAN - TRUE exist +** FALSE does not exist +** +*******************************************************************************/ +BOOLEAN bta_hl_is_mdl_exsit_in_mcl(UINT8 app_idx, BD_ADDR bd_addr, + tBTA_HL_MDL_ID mdl_id) +{ + tBTA_HL_MDL_CFG *p_mdl; + BOOLEAN found = FALSE; + UINT8 i; + + for (i = 0; i< BTA_HL_NUM_MDL_CFGS; i++) + { + p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i); + if (p_mdl->active && + !memcmp(p_mdl->peer_bd_addr, bd_addr,BD_ADDR_LEN)) + { + if (mdl_id != BTA_HL_DELETE_ALL_MDL_IDS) + { + if (p_mdl->mdl_id == mdl_id) + { + found = TRUE; + break; + } + } + else + { + found = TRUE; + break; + } + } + } + + return found; +} + +/******************************************************************************* +** +** Function bta_hl_delete_mdl_cfg +** +** Description This function delete the specified MDL ID +** +** Returns BOOLEAN - TRUE Success +** FALSE Failed +** +*******************************************************************************/ +BOOLEAN bta_hl_delete_mdl_cfg(UINT8 app_idx, BD_ADDR bd_addr, + tBTA_HL_MDL_ID mdl_id) +{ + tBTA_HL_MDL_CFG *p_mdl; + BOOLEAN success = FALSE; + UINT8 i; + tBTA_HL_APP_CB *p_acb= BTA_HL_GET_APP_CB_PTR(app_idx); + UINT8 app_id = p_acb->app_id; + + for (i = 0; i< BTA_HL_NUM_MDL_CFGS; i++) + { + p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i); + if (p_mdl->active && + !memcmp(p_mdl->peer_bd_addr, bd_addr,BD_ADDR_LEN)) + { + if (mdl_id != BTA_HL_DELETE_ALL_MDL_IDS) + { + if (p_mdl->mdl_id == mdl_id) + { + bta_hl_co_delete_mdl(app_id, i); + memset(p_mdl, 0, sizeof(tBTA_HL_MDL_CFG)); + success = TRUE; + break; + } + } + else + { + bta_hl_co_delete_mdl(app_id, i); + memset(p_mdl, 0, sizeof(tBTA_HL_MDL_CFG)); + success = TRUE; + } + } + } + + return success; +} + + +/******************************************************************************* +** +** Function bta_hl_is_mdl_value_valid +** +** +** Description This function checks the specified MDL ID is in valid range or not +** +** Returns BOOLEAN - TRUE Success +** FALSE Failed +** +** note: mdl_id range 0x0000 reserved, +** 0x0001-oxFEFF dynamic range, +** 0xFF00-0xFFFE reserved, +** 0xFFFF indicates all MDLs (for delete operation only) +** +*******************************************************************************/ +BOOLEAN bta_hl_is_mdl_value_valid(tBTA_HL_MDL_ID mdl_id) +{ + BOOLEAN status = TRUE; + + if (mdl_id != BTA_HL_DELETE_ALL_MDL_IDS) + { + if (mdl_id != 0) + { + if (mdl_id > BTA_HL_MAX_MDL_VAL ) + { + status = FALSE; + } + } + else + { + status = FALSE; + } + } + + return status; +} + +/******************************************************************************* +** +** Function bta_hl_find_mdep_cfg_idx +** +** Description This function finds the MDEP configuration index based +** on the local MDEP ID +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_mdep_cfg_idx(UINT8 app_idx, tBTA_HL_MDEP_ID local_mdep_id, + UINT8 *p_mdep_cfg_idx) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_SUP_FEATURE *p_sup_feature= &p_acb->sup_feature; + BOOLEAN found =FALSE; + UINT8 i; + + for (i=0; i< p_sup_feature->num_of_mdeps; i++) + { + if ( p_sup_feature->mdep[i].mdep_id == local_mdep_id) + { + found = TRUE; + *p_mdep_cfg_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG3("bta_hl_find_mdep_cfg_idx found=%d mdep_idx=%d local_mdep_id=%d ", + found,i, local_mdep_id ); + } +#endif + return found; +} + + +/******************************************************************************* +** +** Function bta_hl_find_rxtx_apdu_size +** +** Description This function finds the maximum APDU rx and tx sizes based on +** the MDEP configuration data +** +** Returns void +** +*******************************************************************************/ +void bta_hl_find_rxtx_apdu_size(UINT8 app_idx, UINT8 mdep_cfg_idx, + UINT16 *p_rx_apu_size, + UINT16 *p_tx_apu_size) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MDEP_CFG *p_mdep_cfg; + UINT8 i; + UINT16 max_rx_apdu_size=0, max_tx_apdu_size=0; + + p_mdep_cfg = &p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg; + + + for (i=0; i< p_mdep_cfg->num_of_mdep_data_types ; i++) + { + + if (max_rx_apdu_size < p_mdep_cfg->data_cfg[i].max_rx_apdu_size) + { + max_rx_apdu_size = p_mdep_cfg->data_cfg[i].max_rx_apdu_size; + } + + if (max_tx_apdu_size < p_mdep_cfg->data_cfg[i].max_tx_apdu_size) + { + max_tx_apdu_size = p_mdep_cfg->data_cfg[i].max_tx_apdu_size; + } + } + + + *p_rx_apu_size = max_rx_apdu_size; + *p_tx_apu_size = max_tx_apdu_size; + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG2("bta_hl_find_rxtx_apdu_size max_rx_apdu_size=%d max_tx_apdu_size=%d ", + max_rx_apdu_size, max_tx_apdu_size ); +#endif + + +} + +/******************************************************************************* +** +** Function bta_hl_validate_peer_cfg +** +** Description This function validates the peer DCH configuration +** +** Returns BOOLEAN - TRUE validation is successful +** FALSE validation failed +** +*******************************************************************************/ +BOOLEAN bta_hl_validate_peer_cfg(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, + tBTA_HL_MDEP_ID peer_mdep_id, + tBTA_HL_MDEP_ROLE peer_mdep_role, + UINT8 sdp_idx) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + tBTA_HL_SDP_REC *p_rec; + BOOLEAN peer_found =FALSE; + UINT8 i; + + APPL_TRACE_DEBUG1("bta_hl_validate_peer_cfg sdp_idx=%d", sdp_idx); + + + if (p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID) + { + return TRUE; + } + + p_rec = &p_mcb->sdp.sdp_rec[sdp_idx]; + for (i=0; i< p_rec->num_mdeps; i++) + { + if ( (p_rec->mdep_cfg[i].mdep_id == peer_mdep_id) && + (p_rec->mdep_cfg[i].mdep_role == peer_mdep_role)) + { + peer_found = TRUE; + + break; + } + } + + +#if BTA_HL_DEBUG == TRUE + if (!peer_found) + { + APPL_TRACE_DEBUG1("bta_hl_validate_peer_cfg failed num_mdeps=%d",p_rec->num_mdeps); + } +#endif + return peer_found; +} + + +/******************************************************************************* +** +** Function bta_hl_chk_local_cfg +** +** Description This function check whether the local DCH configuration is OK or not +** +** Returns tBTA_HL_STATUS - OK - local DCH configuration is OK +** NO_FIRST_RELIABLE - the streaming DCH configuration +** is not OK and it needs to use +** reliable DCH configuration +** +*******************************************************************************/ +tBTA_HL_STATUS bta_hl_chk_local_cfg(UINT8 app_idx, UINT8 mcl_idx, + UINT8 mdep_cfg_idx, + tBTA_HL_DCH_CFG local_cfg) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + + if ( mdep_cfg_idx && + (p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SOURCE) && + (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx)) && + (local_cfg != BTA_HL_DCH_CFG_RELIABLE)) + { + status = BTA_HL_STATUS_NO_FIRST_RELIABLE; + APPL_TRACE_ERROR0("BTA_HL_STATUS_INVALID_DCH_CFG"); + } + + return status; +} + + +/******************************************************************************* +** +** Function bta_hl_validate_reconnect_params +** +** Description This function validates the reconnect parameters +** +** Returns BOOLEAN - TRUE validation is successful +** FALSE validation failed +*******************************************************************************/ +BOOLEAN bta_hl_validate_reconnect_params(UINT8 app_idx, UINT8 mcl_idx, + tBTA_HL_API_DCH_RECONNECT *p_reconnect, + UINT8 *p_mdep_cfg_idx, UINT8 *p_mdl_cfg_idx) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_SUP_FEATURE *p_sup_feature = &p_acb->sup_feature; + UINT8 num_mdeps; + UINT8 mdl_cfg_idx; + BOOLEAN local_mdep_id_found =FALSE; + BOOLEAN mdl_cfg_found =FALSE; + BOOLEAN status=FALSE; + UINT8 i, in_use_mdl_idx; + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("bta_hl_validate_reconnect_params mdl_id=%d", p_reconnect->mdl_id); +#endif + if (bta_hl_find_mdl_cfg_idx(app_idx, mcl_idx, p_reconnect->mdl_id, &mdl_cfg_idx)) + { + mdl_cfg_found = TRUE; + } + +#if BTA_HL_DEBUG == TRUE + if (!mdl_cfg_found) + { + APPL_TRACE_DEBUG0("mdl_cfg_found not found"); + } +#endif + + + if (mdl_cfg_found) + { + num_mdeps = p_sup_feature->num_of_mdeps; + for (i=0; i< num_mdeps ; i++) + { + if ( p_sup_feature->mdep[i].mdep_id == p_acb->mdl_cfg[mdl_cfg_idx].local_mdep_id) + { + local_mdep_id_found = TRUE; + *p_mdep_cfg_idx =i; + *p_mdl_cfg_idx = mdl_cfg_idx; + break; + } + } + } + +#if BTA_HL_DEBUG == TRUE + if (!local_mdep_id_found) + { + APPL_TRACE_DEBUG0("local_mdep_id not found"); + } +#endif + + + if (local_mdep_id_found) + { + if (!bta_hl_find_mdl_idx(app_idx,mcl_idx, p_reconnect->mdl_id, &in_use_mdl_idx)) + { + status= TRUE; + } + else + { + APPL_TRACE_ERROR1("mdl_id=%d is curreltly in use",p_reconnect->mdl_id); + } + } + +#if BTA_HL_DEBUG == TRUE + if (!status) + { + APPL_TRACE_DEBUG3("Reconnect validation failed local_mdep_id found=%d mdl_cfg_idx found=%d in_use_mdl_idx=%d ", + local_mdep_id_found, mdl_cfg_found, in_use_mdl_idx); + } +#endif + return status; +} + +/******************************************************************************* +** +** Function bta_hl_find_avail_mcl_idx +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_avail_mcl_idx(UINT8 app_idx, UINT8 *p_mcl_idx) +{ + BOOLEAN found=FALSE; + UINT8 i; + + for (i=0; i < BTA_HL_NUM_MCLS ; i ++) + { + if (!bta_hl_cb.acb[app_idx].mcb[i].in_use) + { + found = TRUE; + *p_mcl_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG2("bta_hl_find_avail_mcl_idx found=%d idx=%d", + found, i); + } +#endif + return found; +} + + + +/******************************************************************************* +** +** Function bta_hl_find_avail_mdl_idx +** +** Description This function finds an available MDL control block index +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_avail_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, + UINT8 *p_mdl_idx) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + BOOLEAN found=FALSE; + UINT8 i; + + for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++) + { + if (!p_mcb->mdl[i].in_use) + { + memset((void *)&p_mcb->mdl[i],0, sizeof(tBTA_HL_MDL_CB)); + found = TRUE; + *p_mdl_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG2("bta_hl_find_avail_mdl_idx found=%d idx=%d", + found, i); + } +#endif + return found; +} + +/******************************************************************************* +** +** Function bta_hl_is_a_duplicate_id +** +** Description This function finds the application has been used or not +** +** Returns BOOLEAN - TRUE the app_id is a duplicate ID +** FALSE not a duplicate ID +*******************************************************************************/ +BOOLEAN bta_hl_is_a_duplicate_id(UINT8 app_id) +{ + BOOLEAN is_duplicate=FALSE; + UINT8 i; + + for (i=0; i < BTA_HL_NUM_APPS ; i ++) + { + if (bta_hl_cb.acb[i].in_use && + (bta_hl_cb.acb[i].app_id == app_id)) + { + is_duplicate = TRUE; + + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (is_duplicate) + { + + APPL_TRACE_DEBUG2("bta_hl_is_a_duplicate_id app_id=%d is_duplicate=%d", + app_id, is_duplicate); + } +#endif + + return is_duplicate; +} + + +/******************************************************************************* +** +** Function bta_hl_find_avail_app_idx +** +** Description This function finds an available application control block index +** +** Returns BOOLEAN - TRUE found +** FALSE not found +** +*******************************************************************************/ +BOOLEAN bta_hl_find_avail_app_idx(UINT8 *p_idx) +{ + BOOLEAN found=FALSE; + UINT8 i; + + for (i=0; i < BTA_HL_NUM_APPS ; i ++) + { + if (!bta_hl_cb.acb[i].in_use) + { + found = TRUE; + *p_idx = i; + break; + } + } + +#if BTA_HL_DEBUG == TRUE + if (!found) + { + APPL_TRACE_DEBUG2("bta_hl_find_avail_app_idx found=%d app_idx=%d", + found, i); + } +#endif + return found; +} + +/******************************************************************************* +** +** Function bta_hl_app_registration +** +** Description This function registers an HDP application MCAP and DP +** +** Returns tBTA_HL_STATUS -registration status +** +*******************************************************************************/ +tBTA_HL_STATUS bta_hl_app_registration(UINT8 app_idx) +{ + tBTA_HL_STATUS status = BTA_HL_STATUS_OK; + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tMCA_REG reg; + tMCA_CS mca_cs; + UINT8 i, num_of_mdeps; + + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("bta_hl_app_registration app_idx=%d", app_idx); +#endif + + reg.ctrl_psm = p_acb->ctrl_psm; + reg.data_psm = p_acb->data_psm; + reg.sec_mask = p_acb->sec_mask; + reg.rsp_tout = BTA_HL_MCAP_RSP_TOUT; + + if ( (p_acb->app_handle = (tBTA_HL_APP_HANDLE) MCA_Register(®, bta_hl_mcap_ctrl_cback))!=0) + { + mca_cs.type = MCA_TDEP_ECHO; + mca_cs.max_mdl = BTA_HL_NUM_MDLS_PER_MDEP; + mca_cs.p_data_cback = bta_hl_mcap_data_cback; + + if (MCA_CreateDep((tMCA_HANDLE)p_acb->app_handle, + &(p_acb->sup_feature.mdep[0].mdep_id), + &mca_cs) == MCA_SUCCESS) + { + if (p_acb->sup_feature.mdep[0].mdep_id != BTA_HL_ECHO_TEST_MDEP_ID) + { + status = BTA_HL_STATUS_MCAP_REG_FAIL; + APPL_TRACE_ERROR1("BAD MDEP ID for echo test mdep_id=%d", + p_acb->sup_feature.mdep[0].mdep_id ); + } + } + else + { + status = BTA_HL_STATUS_MCAP_REG_FAIL; + APPL_TRACE_ERROR0("MCA_CreateDep for echo test(mdep_id=0) failed"); + } + + + if ((status == BTA_HL_STATUS_OK) && + bta_hl_co_get_num_of_mdep(p_acb->app_id, &num_of_mdeps)) + { + p_acb->sup_feature.num_of_mdeps = num_of_mdeps+1; + + for (i=1; i<p_acb->sup_feature.num_of_mdeps; i++) + { + mca_cs.type = MCA_TDEP_DATA; + mca_cs.max_mdl = BTA_HL_NUM_MDLS_PER_MDEP; + mca_cs.p_data_cback = bta_hl_mcap_data_cback; + + if (MCA_CreateDep((tMCA_HANDLE)p_acb->app_handle, + &(p_acb->sup_feature.mdep[i].mdep_id), &mca_cs) == MCA_SUCCESS) + { + if (bta_hl_co_get_mdep_config(p_acb->app_id, + i, + p_acb->sup_feature.mdep[i].mdep_id, + &p_acb->sup_feature.mdep[i].mdep_cfg)) + { + if (p_acb->sup_feature.mdep[i].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SOURCE) + { + p_acb->sup_feature.app_role_mask |= BTA_HL_MDEP_ROLE_MASK_SOURCE; + } + else if (p_acb->sup_feature.mdep[i].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SINK) + { + p_acb->sup_feature.app_role_mask |= BTA_HL_MDEP_ROLE_MASK_SINK; + } + else + { + status = BTA_HL_STATUS_MDEP_CO_FAIL; + break; + } + } + else + { + status = BTA_HL_STATUS_MDEP_CO_FAIL; + break; + } + } + else + { + status = BTA_HL_STATUS_MCAP_REG_FAIL; + break; + } + } + + + + if ((status == BTA_HL_STATUS_OK) && + (p_acb->sup_feature.app_role_mask == BTA_HL_MDEP_ROLE_MASK_SOURCE)) + { + /* this is a source only applciation */ + p_acb->sup_feature.advertize_source_sdp = + bta_hl_co_advrtise_source_sdp(p_acb->app_id); + } + + if ((status == BTA_HL_STATUS_OK)&& + (!bta_hl_co_get_echo_config(p_acb->app_id, &p_acb->sup_feature.echo_cfg))) + { + status = BTA_HL_STATUS_ECHO_CO_FAIL; + } + + if ((status == BTA_HL_STATUS_OK)&& + (!bta_hl_co_load_mdl_config(p_acb->app_id, BTA_HL_NUM_MDL_CFGS, &p_acb->mdl_cfg[0]))) + { + status = BTA_HL_STATUS_MDL_CFG_CO_FAIL; + } + } + else + { + status = BTA_HL_STATUS_MDEP_CO_FAIL; + } + } + else + { + status = BTA_HL_STATUS_MCAP_REG_FAIL; + } + + if (status == BTA_HL_STATUS_OK) + { + status = bta_hl_sdp_register(app_idx); + } + + return status; +} + + +/******************************************************************************* +** +** Function bta_hl_discard_data +** +** Description This function discard an HDP event +** +** Returns void +** +*******************************************************************************/ +void bta_hl_discard_data(UINT16 event, tBTA_HL_DATA *p_data) +{ + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_ERROR1("BTA HL Discard event=%s",bta_hl_evt_code(event)); + +#endif + + switch (event) + { + case BTA_HL_API_SEND_DATA_EVT: + break; + + case BTA_HL_MCA_RCV_DATA_EVT: + utl_freebuf((void**)&p_data->mca_rcv_data_evt.p_pkt); + break; + + default: + /*Nothing to free*/ + break; + } +} + +/******************************************************************************* +** +** Function bta_hl_save_mdl_cfg +** +** Description This function saves the MDL configuration +** +** Returns void +** +*******************************************************************************/ +void bta_hl_save_mdl_cfg(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx ) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + UINT8 mdl_cfg_idx; + tBTA_HL_MDL_ID mdl_id; + BOOLEAN found=TRUE; + tBTA_HL_MDL_CFG mdl_cfg; + tBTA_HL_MDEP *p_mdep_cfg; + tBTA_HL_L2CAP_CFG_INFO l2cap_cfg; + UINT8 time_val; + mdl_id = p_dcb->mdl_id; + if (!bta_hl_find_mdl_cfg_idx(app_idx, mcl_idx, mdl_id, &mdl_cfg_idx)) + { + if (!bta_hl_find_avail_mdl_cfg_idx(app_idx, mcl_idx, &mdl_cfg_idx)) + { + APPL_TRACE_ERROR0("No space to save the MDL config"); + found= FALSE; /*no space available*/ + } + } + + if (found) + { + bta_hl_get_l2cap_cfg(p_dcb->mdl_handle, &l2cap_cfg); + if (!bta_hl_get_cur_time(app_idx, &time_val )) + { + bta_hl_compact_mdl_cfg_time(app_idx); + bta_hl_get_cur_time(app_idx, &time_val); + } + mdl_cfg.active = TRUE; + mdl_cfg.time = time_val; + mdl_cfg.mdl_id = p_dcb->mdl_id; + mdl_cfg.dch_mode = p_dcb->dch_mode; + mdl_cfg.mtu = l2cap_cfg.mtu; + mdl_cfg.fcs = l2cap_cfg.fcs; + + bdcpy(mdl_cfg.peer_bd_addr, p_mcb->bd_addr); + mdl_cfg.local_mdep_id= p_dcb->local_mdep_id; + p_mdep_cfg = &p_acb->sup_feature.mdep[p_dcb->local_mdep_cfg_idx]; + mdl_cfg.local_mdep_role= p_mdep_cfg->mdep_cfg.mdep_role; + memcpy(&p_acb->mdl_cfg[mdl_cfg_idx], &mdl_cfg, sizeof(tBTA_HL_MDL_CFG)); + bta_hl_co_save_mdl(p_acb->app_id, mdl_cfg_idx, &mdl_cfg); + } + +#if BTA_HL_DEBUG == TRUE + if (found) + { + if (p_dcb->mtu != l2cap_cfg.mtu) + { + APPL_TRACE_WARNING2("MCAP and L2CAP peer mtu size out of sync from MCAP mtu=%d from l2cap mtu=%d", + p_dcb->mtu, l2cap_cfg.mtu); + } + APPL_TRACE_DEBUG1("bta_hl_save_mdl_cfg saved=%d", found); + APPL_TRACE_DEBUG4("Saved. L2cap cfg mdl_id=%d mtu=%d fcs=%d dch_mode=%d", + mdl_cfg.mdl_id, mdl_cfg.mtu, mdl_cfg.fcs, mdl_cfg.dch_mode); + } +#endif + + + +} + +/******************************************************************************* +** +** Function bta_hl_set_dch_chan_cfg +** +** Description This function setups the L2CAP DCH channel configuration +** +** Returns void +*******************************************************************************/ +void bta_hl_set_dch_chan_cfg(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,tBTA_HL_DATA *p_data) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + UINT8 l2cap_mode = L2CAP_FCR_ERTM_MODE; + tBTA_HL_SUP_FEATURE *p_sup_feature= &p_acb->sup_feature; + UINT8 local_mdep_cfg_idx = p_dcb->local_mdep_cfg_idx; + + switch (p_dcb->dch_oper) + { + case BTA_HL_DCH_OP_LOCAL_RECONNECT: + case BTA_HL_DCH_OP_REMOTE_RECONNECT: + if (p_dcb->dch_mode == BTA_HL_DCH_MODE_STREAMING) + l2cap_mode = L2CAP_FCR_STREAM_MODE; + break; + case BTA_HL_DCH_OP_LOCAL_OPEN: + if (p_data->mca_evt.mca_data.create_cfm.cfg == BTA_HL_DCH_CFG_STREAMING) + l2cap_mode = L2CAP_FCR_STREAM_MODE; + break; + case BTA_HL_DCH_OP_REMOTE_OPEN: + if (p_dcb->local_cfg == BTA_HL_DCH_CFG_STREAMING ) + l2cap_mode = L2CAP_FCR_STREAM_MODE; + break; + default: + APPL_TRACE_ERROR1("Invalid dch oper=%d for set dch chan cfg", p_dcb->dch_oper); + break; + } + p_dcb->chnl_cfg.fcr_opt.mode = l2cap_mode; + p_dcb->chnl_cfg.fcr_opt.mps = bta_hl_set_mps(p_dcb->max_rx_apdu_size); + p_dcb->chnl_cfg.fcr_opt.tx_win_sz = bta_hl_set_tx_win_size(p_dcb->max_rx_apdu_size, + p_dcb->chnl_cfg.fcr_opt.mps); + p_dcb->chnl_cfg.fcr_opt.max_transmit= BTA_HL_L2C_MAX_TRANSMIT; + p_dcb->chnl_cfg.fcr_opt.rtrans_tout = BTA_HL_L2C_RTRANS_TOUT; + p_dcb->chnl_cfg.fcr_opt.mon_tout = BTA_HL_L2C_MON_TOUT; + + p_dcb->chnl_cfg.user_rx_pool_id = bta_hl_set_user_rx_pool_id(p_dcb->max_rx_apdu_size); + p_dcb->chnl_cfg.user_tx_pool_id = bta_hl_set_user_tx_pool_id(p_dcb->max_tx_apdu_size); + p_dcb->chnl_cfg.fcr_rx_pool_id = BTA_HL_L2C_FCR_RX_POOL_ID; + p_dcb->chnl_cfg.fcr_tx_pool_id = BTA_HL_L2C_FCR_TX_POOL_ID; + p_dcb->chnl_cfg.data_mtu = p_dcb->max_rx_apdu_size; + + p_dcb->chnl_cfg.fcs = BTA_HL_MCA_NO_FCS; + if (local_mdep_cfg_idx != BTA_HL_ECHO_TEST_MDEP_CFG_IDX) + { + if (p_sup_feature->mdep[local_mdep_cfg_idx].mdep_cfg.mdep_role == + BTA_HL_MDEP_ROLE_SOURCE) + { + p_dcb->chnl_cfg.fcs = BTA_HL_DEFAULT_SOURCE_FCS; + } + } + else + { + p_dcb->chnl_cfg.fcs = BTA_HL_MCA_USE_FCS; + } + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG1("L2CAP Params l2cap_mode[3-ERTM 4-STREAM]=%d", l2cap_mode); + APPL_TRACE_DEBUG2("Use FCS =%s mtu=%d", ((p_dcb->chnl_cfg.fcs & 1)?"YES":"NO"), + p_dcb->chnl_cfg.data_mtu); + APPL_TRACE_DEBUG5("tx_win_sz=%d, max_transmit=%d, rtrans_tout=%d, mon_tout=%d, mps=%d", + p_dcb->chnl_cfg.fcr_opt.tx_win_sz, + p_dcb->chnl_cfg.fcr_opt.max_transmit, + p_dcb->chnl_cfg.fcr_opt.rtrans_tout, + p_dcb->chnl_cfg.fcr_opt.mon_tout, + p_dcb->chnl_cfg.fcr_opt.mps); + + APPL_TRACE_DEBUG4("USER rx_pool_id=%d, tx_pool_id=%d, FCR rx_pool_id=%d, tx_pool_id=%d", + p_dcb->chnl_cfg.user_rx_pool_id, + p_dcb->chnl_cfg.user_tx_pool_id, + p_dcb->chnl_cfg.fcr_rx_pool_id, + p_dcb->chnl_cfg.fcr_tx_pool_id); + +#endif + + + + + + + + +} + +/******************************************************************************* +** +** Function bta_hl_get_l2cap_cfg +** +** Description This function get the current L2CAP channel configuration +** +** Returns BOOLEAN - TRUE - operation is successful +*******************************************************************************/ +BOOLEAN bta_hl_get_l2cap_cfg(tBTA_HL_MDL_HANDLE mdl_hnd, tBTA_HL_L2CAP_CFG_INFO *p_cfg) +{ + BOOLEAN success = FALSE; + UINT16 lcid; + tL2CAP_CFG_INFO *p_our_cfg; + tL2CAP_CH_CFG_BITS our_cfg_bits; + tL2CAP_CFG_INFO *p_peer_cfg; + tL2CAP_CH_CFG_BITS peer_cfg_bits; + + lcid = MCA_GetL2CapChannel((tMCA_DL) mdl_hnd); + if ( lcid && + L2CA_GetCurrentConfig(lcid, &p_our_cfg, &our_cfg_bits, &p_peer_cfg, + &peer_cfg_bits)) + { + p_cfg->fcs = BTA_HL_MCA_NO_FCS; + if (our_cfg_bits & L2CAP_CH_CFG_MASK_FCS) + { + p_cfg->fcs |= p_our_cfg->fcs; + } + else + { + p_cfg->fcs = BTA_HL_MCA_USE_FCS; + } + + if (p_cfg->fcs != BTA_HL_MCA_USE_FCS ) + { + if (peer_cfg_bits & L2CAP_CH_CFG_MASK_FCS) + { + p_cfg->fcs |= p_peer_cfg->fcs; + } + else + { + p_cfg->fcs = BTA_HL_MCA_USE_FCS; + } + } + + p_cfg->mtu =0; + if (peer_cfg_bits & L2CAP_CH_CFG_MASK_MTU) + { + p_cfg->mtu = p_peer_cfg->mtu; + } + else + { + p_cfg->mtu = L2CAP_DEFAULT_MTU; + } + success = TRUE; + } + +#if BTA_HL_DEBUG == TRUE + if (!success) + { + APPL_TRACE_DEBUG3("bta_hl_get_l2cap_cfg success=%d mdl=%d lcid=%d", success, mdl_hnd, lcid); + APPL_TRACE_DEBUG2("l2cap mtu=%d fcs=%d", p_cfg->mtu, p_cfg->fcs); + } +#endif + + return success; +} + +/******************************************************************************* +** +** Function bta_hl_validate_chan_cfg +** +** Description This function validates the L2CAP channel configuration +** +** Returns BOOLEAN - TRUE - validation is successful +*******************************************************************************/ +BOOLEAN bta_hl_validate_chan_cfg(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + BOOLEAN success = FALSE; + UINT8 mdl_cfg_idx; + tBTA_HL_L2CAP_CFG_INFO l2cap_cfg; + + + if (bta_hl_get_l2cap_cfg(p_dcb->mdl_handle, &l2cap_cfg) && + bta_hl_find_mdl_cfg_idx(app_idx, mcl_idx, p_dcb->mdl_id, &mdl_cfg_idx)) + { + if ((p_acb->mdl_cfg[mdl_cfg_idx].mtu <= l2cap_cfg.mtu) && + (p_acb->mdl_cfg[mdl_cfg_idx].fcs == l2cap_cfg.fcs) && + (p_acb->mdl_cfg[mdl_cfg_idx].dch_mode == p_dcb->dch_mode)) + { + success = TRUE; + } + } + + +#if BTA_HL_DEBUG == TRUE + + if (p_dcb->mtu != l2cap_cfg.mtu) + { + APPL_TRACE_WARNING2("MCAP and L2CAP peer mtu size out of sync from MCAP mtu=%d from l2cap mtu=%d", + p_dcb->mtu, l2cap_cfg.mtu); + } + + if (!success) + { + APPL_TRACE_DEBUG4("bta_hl_validate_chan_cfg success=%d app_idx=%d mcl_idx=%d mdl_idx=%d",success, app_idx, mcl_idx, mdl_idx); + APPL_TRACE_DEBUG3("Cur. L2cap cfg mtu=%d fcs=%d dch_mode=%d", l2cap_cfg.mtu, l2cap_cfg.fcs, p_dcb->dch_mode); + APPL_TRACE_DEBUG3("From saved: L2cap cfg mtu=%d fcs=%d dch_mode=%d", p_acb->mdl_cfg[mdl_cfg_idx].mtu, + p_acb->mdl_cfg[mdl_cfg_idx].fcs , p_acb->mdl_cfg[mdl_cfg_idx].dch_mode); + } +#endif + + return success; +} + + +/******************************************************************************* +** +** Function bta_hl_is_cong_on +** +** Description This function checks whether the congestion condition is on or not +** +** Returns BOOLEAN - TRUE DCH is congested +** FALSE not congested +** +*******************************************************************************/ +BOOLEAN bta_hl_is_cong_on(UINT8 app_id, BD_ADDR bd_addr, tBTA_HL_MDL_ID mdl_id) + +{ + tBTA_HL_MDL_CB *p_dcb; + UINT8 app_idx, mcl_idx, mdl_idx; + BOOLEAN cong_status = TRUE; + + if (bta_hl_find_app_idx(app_id, &app_idx)) + { + if (bta_hl_find_mcl_idx(app_idx, bd_addr, &mcl_idx )) + { + if (bta_hl_find_mdl_idx(app_idx, mcl_idx, mdl_id, &mdl_idx )) + { + p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + cong_status = p_dcb->cong; + } + } + } + + return cong_status; +} + +/******************************************************************************* +** +** Function bta_hl_check_cch_close +** +** Description This function checks whether there is a pending CCH close request +** or not +** +** Returns void +*******************************************************************************/ +void bta_hl_check_cch_close(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data, BOOLEAN check_dch_setup ) +{ + tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + tBTA_HL_MDL_CB *p_dcb; + UINT8 mdl_idx; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG1("bta_hl_check_cch_close cch_close_dch_oper=%d",p_mcb->cch_close_dch_oper ); +#endif + + if (p_mcb->cch_oper == BTA_HL_CCH_OP_LOCAL_CLOSE) + { + if (check_dch_setup && bta_hl_find_dch_setup_mdl_idx(app_idx, mcl_idx, &mdl_idx)) + { + p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); + if (!p_mcb->rsp_tout) + { + p_mcb->cch_close_dch_oper = BTA_HL_CCH_CLOSE_OP_DCH_ABORT; + + if (!p_dcb->abort_oper) + { + p_dcb->abort_oper |= BTA_HL_ABORT_CCH_CLOSE_MASK; + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ABORT_EVT, p_data); + } + } + else + { + p_mcb->cch_close_dch_oper = BTA_HL_CCH_CLOSE_OP_DCH_CLOSE; + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data); + } + } + else if (bta_hl_find_an_active_mdl_idx(app_idx, mcl_idx,&mdl_idx)) + { + p_mcb->cch_close_dch_oper = BTA_HL_CCH_CLOSE_OP_DCH_CLOSE; + bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_EVT, p_data); + } + else + { + p_mcb->cch_close_dch_oper = BTA_HL_CCH_CLOSE_OP_DCH_NONE; + bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_EVT, p_data); + } + } +} + +/******************************************************************************* +** +** Function bta_hl_clean_app +** +** Description Cleans up the HDP application resources and control block +** +** Returns void +** +*******************************************************************************/ +void bta_hl_clean_app(UINT8 app_idx) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + int i, num_act_apps=0; + +#if BTA_HL_DEBUG == TRUE + APPL_TRACE_DEBUG0("bta_hl_clean_app"); +#endif + MCA_Deregister((tMCA_HANDLE)p_acb->app_handle); + + if (p_acb->sdp_handle) SDP_DeleteRecord(p_acb->sdp_handle); + + memset((void *) p_acb, 0, sizeof(tBTA_HL_APP_CB)); + + /* check any application is still active */ + for (i=0; i < BTA_HL_NUM_APPS ; i ++) + { + p_acb = BTA_HL_GET_APP_CB_PTR(i); + if (p_acb->in_use) num_act_apps++; + } + + if (!num_act_apps) + { + bta_sys_remove_uuid(UUID_SERVCLASS_HDP_PROFILE); + } +} + +/******************************************************************************* +** +** Function bta_hl_check_deregistration +** +** Description This function checks whether there is a pending deregistration +** request or not +** +** Returns void +*******************************************************************************/ +void bta_hl_check_deregistration(UINT8 app_idx, tBTA_HL_DATA *p_data ) +{ + tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + tBTA_HL_MCL_CB *p_mcb; + UINT8 mcl_idx; + tBTA_HL evt_data; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_check_deregistration"); +#endif + + if (p_acb->deregistering) + { + if (bta_hl_find_an_in_use_mcl_idx(app_idx, &mcl_idx)) + { + p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); + if (p_mcb->cch_oper != BTA_HL_CCH_OP_LOCAL_CLOSE) + { + p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_CLOSE; + bta_hl_check_cch_close(app_idx,mcl_idx,p_data, TRUE); + } + } + else + { + /* all cchs are closed */ + evt_data.dereg_cfm.app_handle = p_acb->app_handle; + evt_data.dereg_cfm.status = BTA_HL_STATUS_OK; + p_acb->p_cback(BTA_HL_DEREGISTER_CFM_EVT, (tBTA_HL *) &evt_data ); + bta_hl_clean_app(app_idx); + bta_hl_check_disable(p_data); + } + } +} + + +/******************************************************************************* +** +** Function bta_hl_check_disable +** +** Description This function checks whether there is a pending disable +** request or not +** +** Returns void +** +*******************************************************************************/ +void bta_hl_check_disable(tBTA_HL_DATA *p_data ) +{ + tBTA_HL_CB *p_cb= &bta_hl_cb; + tBTA_HL_APP_CB *p_acb; + UINT8 app_idx; + tBTA_HL_CTRL evt_data; + +#if (BTA_HL_DEBUG == TRUE) + APPL_TRACE_DEBUG0("bta_hl_check_disable"); +#endif + + if (bta_hl_cb.disabling) + { + if (bta_hl_find_an_in_use_app_idx(&app_idx)) + { + p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); + if (!p_acb->deregistering) + { + p_acb->deregistering = TRUE; + bta_hl_check_deregistration(app_idx, p_data); + } + } + else + { + /* all apps are deregistered */ + bta_sys_deregister(BTA_ID_HL); + evt_data.disable_cfm.status = BTA_HL_STATUS_OK; + if (p_cb->p_ctrl_cback) p_cb->p_ctrl_cback(BTA_HL_CTRL_DISABLE_CFM_EVT, (tBTA_HL_CTRL *) &evt_data); + memset((void *) p_cb, 0, sizeof(tBTA_HL_CB)); + } + } +} + +/******************************************************************************* +** +** Function bta_hl_build_abort_cfm +** +** Description This function builds the abort confirmation event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_abort_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_STATUS status) +{ + p_evt_data->dch_abort_cfm.status = status; + p_evt_data->dch_abort_cfm.mcl_handle = mcl_handle; + p_evt_data->dch_abort_cfm.app_handle = app_handle; +} + +/******************************************************************************* +** +** Function bta_hl_build_abort_ind +** +** Description This function builds the abort indication event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_abort_ind(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle) +{ + p_evt_data->dch_abort_ind.mcl_handle = mcl_handle; + p_evt_data->dch_abort_ind.app_handle = app_handle; +} +/******************************************************************************* +** +** Function bta_hl_build_close_cfm +** +** Description This function builds the close confirmation event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_dch_close_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_HANDLE mdl_handle, + tBTA_HL_STATUS status) +{ + p_evt_data->dch_close_cfm.status = status; + p_evt_data->dch_close_cfm.mdl_handle = mdl_handle; + p_evt_data->dch_close_cfm.mcl_handle = mcl_handle; + p_evt_data->dch_close_cfm.app_handle = app_handle; +} + +/******************************************************************************* +** +** Function bta_hl_build_dch_close_ind +** +** Description This function builds the close indication event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_dch_close_ind(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_HANDLE mdl_handle, + BOOLEAN intentional) +{ + p_evt_data->dch_close_ind.mdl_handle = mdl_handle; + p_evt_data->dch_close_ind.mcl_handle = mcl_handle; + p_evt_data->dch_close_ind.app_handle = app_handle; + p_evt_data->dch_close_ind.intentional = intentional; +} + +/******************************************************************************* +** +** Function bta_hl_build_send_data_cfm +** +** Description This function builds the send data confirmation event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_send_data_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_HANDLE mdl_handle, + tBTA_HL_STATUS status ) +{ + + p_evt_data->dch_send_data_cfm.mdl_handle = mdl_handle; + p_evt_data->dch_send_data_cfm.mcl_handle = mcl_handle; + p_evt_data->dch_send_data_cfm.app_handle = app_handle; + p_evt_data->dch_send_data_cfm.status = status; +} + +/******************************************************************************* +** +** Function bta_hl_build_rcv_data_ind +** +** Description This function builds the received data indication event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_rcv_data_ind(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_HANDLE mdl_handle) +{ + p_evt_data->dch_rcv_data_ind.mdl_handle = mdl_handle; + p_evt_data->dch_rcv_data_ind.mcl_handle = mcl_handle; + p_evt_data->dch_rcv_data_ind.app_handle = app_handle; +} + + +/******************************************************************************* +** +** Function bta_hl_build_cch_open_cfm +** +** Description This function builds the CCH open confirmation event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_cch_open_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + BD_ADDR bd_addr, + tBTA_HL_STATUS status ) +{ + + p_evt_data->cch_open_cfm.app_handle = app_handle; + p_evt_data->cch_open_cfm.mcl_handle = mcl_handle; + bdcpy(p_evt_data->cch_open_cfm.bd_addr, bd_addr); + p_evt_data->cch_open_cfm.status = status; +} + +/******************************************************************************* +** +** Function bta_hl_build_cch_open_ind +** +** Description This function builds the CCH open indication event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_cch_open_ind(tBTA_HL *p_evt_data, tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + BD_ADDR bd_addr ) +{ + + p_evt_data->cch_open_ind.app_handle = app_handle; + p_evt_data->cch_open_ind.mcl_handle = mcl_handle; + bdcpy(p_evt_data->cch_open_ind.bd_addr, bd_addr); +} + +/******************************************************************************* +** +** Function bta_hl_build_cch_close_cfm +** +** Description This function builds the CCH close confirmation event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_cch_close_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_STATUS status ) +{ + p_evt_data->cch_close_cfm.mcl_handle = mcl_handle; + p_evt_data->cch_close_cfm.app_handle = app_handle; + p_evt_data->cch_close_cfm.status = status; +} + + +/******************************************************************************* +** +** Function bta_hl_build_cch_close_ind +** +** Description This function builds the CCH colse indication event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_cch_close_ind(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + BOOLEAN intentional) +{ + p_evt_data->cch_close_ind.mcl_handle = mcl_handle; + p_evt_data->cch_close_ind.app_handle = app_handle; + p_evt_data->cch_close_ind.intentional = intentional; +} + +/******************************************************************************* +** +** Function bta_hl_build_dch_open_cfm +** +** Description This function builds the DCH open confirmation event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_dch_open_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_HANDLE mdl_handle, + tBTA_HL_MDEP_ID local_mdep_id, + tBTA_HL_MDL_ID mdl_id, + tBTA_HL_DCH_MODE dch_mode, + BOOLEAN first_reliable, + UINT16 mtu, + tBTA_HL_STATUS status) + +{ + p_evt_data->dch_open_cfm.mdl_handle = mdl_handle; + p_evt_data->dch_open_cfm.mcl_handle = mcl_handle; + p_evt_data->dch_open_cfm.app_handle = app_handle; + p_evt_data->dch_open_cfm.local_mdep_id = local_mdep_id; + p_evt_data->dch_open_cfm.mdl_id = mdl_id; + p_evt_data->dch_open_cfm.dch_mode = dch_mode; + p_evt_data->dch_open_cfm.first_reliable = first_reliable; + p_evt_data->dch_open_cfm.mtu = mtu; + p_evt_data->dch_open_cfm.status = status; +} + + +/******************************************************************************* +** +** Function bta_hl_build_sdp_query_cfm +** +** Description This function builds the SDP query indication event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_sdp_query_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + BD_ADDR bd_addr, + tBTA_HL_SDP *p_sdp, + tBTA_HL_STATUS status) + +{ + p_evt_data->sdp_query_cfm.app_handle = app_handle; + bdcpy(p_evt_data->sdp_query_cfm.bd_addr, bd_addr); + p_evt_data->sdp_query_cfm.p_sdp = p_sdp; + p_evt_data->sdp_query_cfm.status = status; +} + + +/******************************************************************************* +** +** Function bta_hl_build_delete_mdl_cfm +** +** Description This function builds the delete MDL confirmation event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_delete_mdl_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_MDL_ID mdl_id, + tBTA_HL_STATUS status) + +{ + p_evt_data->delete_mdl_cfm.mcl_handle = mcl_handle; + p_evt_data->delete_mdl_cfm.app_handle = app_handle; + p_evt_data->delete_mdl_cfm.mdl_id = mdl_id; + p_evt_data->delete_mdl_cfm.status = status; +} + +/******************************************************************************* +** +** Function bta_hl_build_echo_test_cfm +** +** Description This function builds the echo test confirmation event data +** +** Returns None +** +*******************************************************************************/ +void bta_hl_build_echo_test_cfm(tBTA_HL *p_evt_data, + tBTA_HL_APP_HANDLE app_handle, + tBTA_HL_MCL_HANDLE mcl_handle, + tBTA_HL_STATUS status ) +{ + p_evt_data->echo_test_cfm.mcl_handle = mcl_handle; + p_evt_data->echo_test_cfm.app_handle = app_handle; + p_evt_data->echo_test_cfm.status = status; +} + + +/***************************************************************************** +** Debug Functions +*****************************************************************************/ +#if (BTA_HL_DEBUG == TRUE) + +/******************************************************************************* +** +** Function bta_hl_status_code +** +** Description get the status string pointer +** +** Returns char * - status string pointer +** +*******************************************************************************/ +char *bta_hl_status_code(tBTA_HL_STATUS status) +{ + switch (status) + { + case BTA_HL_STATUS_OK: + return "BTA_HL_STATUS_OK"; + case BTA_HL_STATUS_FAIL: + return "BTA_HL_STATUS_FAIL"; + case BTA_HL_STATUS_ABORTED: + return "BTA_HL_STATUS_ABORTED"; + case BTA_HL_STATUS_NO_RESOURCE: + return "BTA_HL_STATUS_NO_RESOURCE"; + case BTA_HL_STATUS_LAST_ITEM: + return "BTA_HL_STATUS_LAST_ITEM"; + case BTA_HL_STATUS_DUPLICATE_APP_ID: + return "BTA_HL_STATUS_DUPLICATE_APP_ID"; + case BTA_HL_STATUS_INVALID_APP_HANDLE: + return "BTA_HL_STATUS_INVALID_APP_HANDLE"; + case BTA_HL_STATUS_INVALID_MCL_HANDLE: + return "BTA_HL_STATUS_INVALID_MCL_HANDLE"; + case BTA_HL_STATUS_MCAP_REG_FAIL: + return "BTA_HL_STATUS_MCAP_REG_FAIL"; + case BTA_HL_STATUS_MDEP_CO_FAIL: + return "BTA_HL_STATUS_MDEP_CO_FAIL"; + case BTA_HL_STATUS_ECHO_CO_FAIL: + return "BTA_HL_STATUS_ECHO_CO_FAIL"; + case BTA_HL_STATUS_MDL_CFG_CO_FAIL: + return "BTA_HL_STATUS_MDL_CFG_CO_FAIL"; + case BTA_HL_STATUS_SDP_NO_RESOURCE: + return "BTA_HL_STATUS_SDP_NO_RESOURCE"; + case BTA_HL_STATUS_SDP_FAIL: + return "BTA_HL_STATUS_SDP_FAIL"; + case BTA_HL_STATUS_NO_CCH: + return "BTA_HL_STATUS_NO_CCH"; + case BTA_HL_STATUS_NO_MCL: + return "BTA_HL_STATUS_NO_MCL"; + + case BTA_HL_STATUS_NO_FIRST_RELIABLE: + return "BTA_HL_STATUS_NO_FIRST_RELIABLE"; + case BTA_HL_STATUS_INVALID_DCH_CFG: + return "BTA_HL_STATUS_INVALID_DCH_CFG"; + case BTA_HL_STATUS_INVALID_BD_ADDR: + return "BTA_HL_STATUS_INVALID_BD_ADDR"; + case BTA_HL_STATUS_INVALID_RECONNECT_CFG: + return "BTA_HL_STATUS_INVALID_RECONNECT_CFG"; + case BTA_HL_STATUS_ECHO_TEST_BUSY: + return "BTA_HL_STATUS_ECHO_TEST_BUSY"; + case BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID: + return "BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID"; + case BTA_HL_STATUS_INVALID_MDL_ID: + return "BTA_HL_STATUS_INVALID_MDL_ID"; + case BTA_HL_STATUS_NO_MDL_ID_FOUND: + return "BTA_HL_STATUS_NO_MDL_ID_FOUND"; + case BTA_HL_STATUS_DCH_BUSY: + return "BTA_HL_STATUS_DCH_BUSY"; + default: + return "Unknown status code"; + } +} +/******************************************************************************* +** +** Function bta_hl_evt_code +** +** Description Maps HL event code to the corresponding event string +** +** Returns string pointer for the associated event name +** +*******************************************************************************/ +char *bta_hl_evt_code(tBTA_HL_INT_EVT evt_code) +{ + switch (evt_code) + { + case BTA_HL_CCH_OPEN_EVT: + return "BTA_HL_CCH_OPEN_EVT"; + case BTA_HL_CCH_SDP_OK_EVT: + return "BTA_HL_CCH_SDP_OK_EVT"; + case BTA_HL_CCH_SDP_FAIL_EVT: + return "BTA_HL_CCH_SDP_FAIL_EVT"; + case BTA_HL_MCA_CONNECT_IND_EVT: + return "BTA_HL_MCA_CONNECT_IND_EVT"; + case BTA_HL_MCA_DISCONNECT_IND_EVT: + return "BTA_HL_MCA_DISCONNECT_IND_EVT"; + + case BTA_HL_CCH_CLOSE_EVT: + return "BTA_HL_CCH_CLOSE_EVT"; + case BTA_HL_CCH_CLOSE_CMPL_EVT: + return "BTA_HL_CCH_CLOSE_CMPL_EVT"; + case BTA_HL_DCH_OPEN_EVT: + return "BTA_HL_DCH_OPEN_EVT"; + case BTA_HL_MCA_CREATE_IND_EVT: + return "BTA_HL_MCA_CREATE_IND_EVT"; + case BTA_HL_MCA_CREATE_CFM_EVT: + return "BTA_HL_MCA_CREATE_CFM_EVT"; + case BTA_HL_MCA_OPEN_IND_EVT: + return "BTA_HL_MCA_OPEN_IND_EVT"; + case BTA_HL_MCA_OPEN_CFM_EVT: + return "BTA_HL_MCA_OPEN_CFM_EVT"; + case BTA_HL_DCH_CLOSE_EVT: + return "BTA_HL_DCH_CLOSE_EVT"; + case BTA_HL_MCA_CLOSE_IND_EVT: + return "BTA_HL_MCA_CLOSE_IND_EVT"; + case BTA_HL_MCA_CLOSE_CFM_EVT: + return "BTA_HL_MCA_CLOSE_CFM_EVT"; + case BTA_HL_API_SEND_DATA_EVT: + return "BTA_HL_API_SEND_DATA_EVT"; + case BTA_HL_MCA_RCV_DATA_EVT: + return "BTA_HL_MCA_RCV_DATA_EVT"; + case BTA_HL_DCH_CLOSE_CMPL_EVT: + return "BTA_HL_DCH_CLOSE_CMPL_EVT"; + + case BTA_HL_API_ENABLE_EVT: + return "BTA_HL_API_ENABLE_EVT"; + case BTA_HL_API_DISABLE_EVT: + return "BTA_HL_API_DISABLE_EVT"; + case BTA_HL_API_REGISTER_EVT: + return "BTA_HL_API_REGISTER_EVT"; + case BTA_HL_API_DEREGISTER_EVT: + return "BTA_HL_API_DEREGISTER_EVT"; + + case BTA_HL_API_CCH_OPEN_EVT: + return "BTA_HL_API_CCH_OPEN_EVT"; + + case BTA_HL_API_CCH_CLOSE_EVT: + return "BTA_HL_API_CCH_CLOSE_EVT"; + case BTA_HL_API_DCH_OPEN_EVT: + return "BTA_HL_API_DCH_OPEN_EVT"; + + case BTA_HL_API_DCH_RECONNECT_EVT: + return "BTA_HL_API_DCH_RECONNECT_EVT"; + case BTA_HL_API_DCH_CLOSE_EVT: + return "BTA_HL_API_DCH_CLOSE_EVT"; + case BTA_HL_API_DELETE_MDL_EVT: + return "BTA_HL_API_DELETE_MDL_EVT"; + case BTA_HL_API_DCH_ABORT_EVT: + return "BTA_HL_API_DCH_ABORT_EVT"; + + case BTA_HL_DCH_RECONNECT_EVT: + return "BTA_HL_DCH_RECONNECT_EVT"; + case BTA_HL_DCH_SDP_INIT_EVT: + return "BTA_HL_DCH_SDP_INIT_EVT"; + case BTA_HL_DCH_SDP_FAIL_EVT: + return "BTA_HL_DCH_SDP_FAIL_EVT"; + case BTA_HL_API_DCH_ECHO_TEST_EVT: + return "BTA_HL_API_DCH_ECHO_TEST_EVT"; + case BTA_HL_DCH_CLOSE_ECHO_TEST_EVT: + return "BTA_HL_DCH_CLOSE_ECHO_TEST_EVT"; + case BTA_HL_MCA_RECONNECT_IND_EVT: + return "BTA_HL_MCA_RECONNECT_IND_EVT"; + case BTA_HL_MCA_RECONNECT_CFM_EVT: + return "BTA_HL_MCA_RECONNECT_CFM_EVT"; + case BTA_HL_API_DCH_CREATE_RSP_EVT: + return "BTA_HL_API_DCH_CREATE_RSP_EVT"; + case BTA_HL_DCH_ABORT_EVT: + return "BTA_HL_DCH_ABORT_EVT"; + case BTA_HL_MCA_ABORT_IND_EVT: + return "BTA_HL_MCA_ABORT_IND_EVT"; + case BTA_HL_MCA_ABORT_CFM_EVT: + return "BTA_HL_MCA_ABORT_CFM_EVT"; + case BTA_HL_MCA_DELETE_IND_EVT: + return "BTA_HL_MCA_DELETE_IND_EVT"; + case BTA_HL_MCA_DELETE_CFM_EVT: + return "BTA_HL_MCA_DELETE_CFM_EVT"; + case BTA_HL_MCA_CONG_CHG_EVT: + return "BTA_HL_MCA_CONG_CHG_EVT"; + case BTA_HL_CI_GET_TX_DATA_EVT: + return "BTA_HL_CI_GET_TX_DATA_EVT"; + case BTA_HL_CI_PUT_RX_DATA_EVT: + return "BTA_HL_CI_PUT_RX_DATA_EVT"; + case BTA_HL_CI_GET_ECHO_DATA_EVT: + return "BTA_HL_CI_GET_ECHO_DATA_EVT"; + case BTA_HL_DCH_ECHO_TEST_EVT: + return "BTA_HL_DCH_ECHO_TEST_EVT"; + case BTA_HL_CI_PUT_ECHO_DATA_EVT: + return "BTA_HL_CI_PUT_ECHO_DATA_EVT"; + case BTA_HL_API_SDP_QUERY_EVT: + return "BTA_HL_API_SDP_QUERY_EVT"; + case BTA_HL_SDP_QUERY_OK_EVT: + return "BTA_HL_SDP_QUERY_OK_EVT"; + case BTA_HL_SDP_QUERY_FAIL_EVT: + return "BTA_HL_SDP_QUERY_FAIL_EVT"; + case BTA_HL_MCA_RSP_TOUT_IND_EVT: + return "BTA_HL_MCA_RSP_TOUT_IND_EVT"; + + default: + return "Unknown HL event code"; + } +} + +#endif /* Debug Functions */ +#endif // HL_INCLUDED + + + + + + + + |