1 /****************************************************************************** 2 * 3 * Copyright (C) 1998-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 /****************************************************************************** 20 * 21 * This file contains the HeaLth device profile main functions and state 22 * machine. 23 * 24 ******************************************************************************/ 25 #include <string.h> 26 27 #include "bt_target.h" 28 #if defined(HL_INCLUDED) && (HL_INCLUDED == TRUE) 29 30 31 32 #include "bta_hl_api.h" 33 #include "bta_hl_int.h" 34 #include "gki.h" 35 #include "utl.h" 36 #include "bd.h" 37 #include "l2c_api.h" 38 #include "mca_defs.h" 39 40 41 #if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) 42 static char *bta_hl_cch_state_code(tBTA_HL_CCH_STATE state_code); 43 static char *bta_hl_dch_state_code(tBTA_HL_DCH_STATE state_code); 44 #endif 45 46 extern UINT16 L2CA_AllocateRandomPsm(void); 47 extern UINT16 L2CA_AllocatePsm(void); 48 /***************************************************************************** 49 ** DCH State Table 50 *****************************************************************************/ 51 /***************************************************************************** 52 ** Constants and types 53 *****************************************************************************/ 54 /* state machine action enumeration list for DCH */ 55 /* The order of this enumeration must be the same as bta_hl_dch_act_tbl[] */ 56 enum 57 { 58 BTA_HL_DCH_MCA_CREATE, 59 BTA_HL_DCH_MCA_CREATE_CFM, 60 BTA_HL_DCH_MCA_CREATE_IND, 61 BTA_HL_DCH_MCA_OPEN_CFM, 62 BTA_HL_DCH_MCA_OPEN_IND, 63 BTA_HL_DCH_MCA_CLOSE, 64 BTA_HL_DCH_MCA_CLOSE_CFM, 65 BTA_HL_DCH_MCA_CLOSE_IND, 66 BTA_HL_DCH_CLOSE_CMPL, 67 BTA_HL_DCH_MCA_RCV_DATA, 68 69 BTA_HL_DCH_SDP_INIT, 70 BTA_HL_DCH_MCA_RECONNECT, 71 BTA_HL_DCH_MCA_RECONNECT_IND, 72 BTA_HL_DCH_MCA_RECONNECT_CFM, 73 BTA_HL_DCH_CLOSE_ECHO_TEST, 74 BTA_HL_DCH_CREATE_RSP, 75 BTA_HL_DCH_MCA_ABORT, 76 BTA_HL_DCH_MCA_ABORT_IND, 77 BTA_HL_DCH_MCA_ABORT_CFM, 78 BTA_HL_DCH_MCA_CONG_CHANGE, 79 80 BTA_HL_DCH_SDP_FAIL, 81 BTA_HL_DCH_SEND_DATA, 82 BTA_HL_DCH_CI_GET_TX_DATA, 83 BTA_HL_DCH_CI_PUT_RX_DATA, 84 BTA_HL_DCH_CI_GET_ECHO_DATA, 85 BTA_HL_DCH_ECHO_TEST, 86 BTA_HL_DCH_CI_PUT_ECHO_DATA, 87 BTA_HL_DCH_IGNORE 88 }; 89 90 typedef void (*tBTA_HL_DCH_ACTION)(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, tBTA_HL_DATA *p_data); 91 92 static const tBTA_HL_DCH_ACTION bta_hl_dch_action[] = 93 { 94 bta_hl_dch_mca_create, 95 bta_hl_dch_mca_create_cfm, 96 bta_hl_dch_mca_create_ind, 97 bta_hl_dch_mca_open_cfm, 98 bta_hl_dch_mca_open_ind, 99 bta_hl_dch_mca_close, 100 bta_hl_dch_mca_close_cfm, 101 bta_hl_dch_mca_close_ind, 102 bta_hl_dch_close_cmpl, 103 bta_hl_dch_mca_rcv_data, 104 105 bta_hl_dch_sdp_init, 106 bta_hl_dch_mca_reconnect, 107 bta_hl_dch_mca_reconnect_ind, 108 bta_hl_dch_mca_reconnect_cfm, 109 bta_hl_dch_close_echo_test, 110 bta_hl_dch_create_rsp, 111 bta_hl_dch_mca_abort, 112 bta_hl_dch_mca_abort_ind, 113 bta_hl_dch_mca_abort_cfm, 114 bta_hl_dch_mca_cong_change, 115 116 bta_hl_dch_sdp_fail, 117 bta_hl_dch_send_data, 118 bta_hl_dch_ci_get_tx_data, 119 bta_hl_dch_ci_put_rx_data, 120 bta_hl_dch_ci_get_echo_data, 121 bta_hl_dch_echo_test, 122 bta_hl_dch_ci_put_echo_data, 123 }; 124 125 126 /* state table information */ 127 #define BTA_HL_DCH_ACTIONS 1 /* number of actions */ 128 #define BTA_HL_DCH_ACTION_COL 0 /* position of action */ 129 #define BTA_HL_DCH_NEXT_STATE 1 /* position of next state */ 130 #define BTA_HL_DCH_NUM_COLS 2 /* number of columns in state tables */ 131 132 /* state table for idle state */ 133 static const UINT8 bta_hl_dch_st_idle[][BTA_HL_DCH_NUM_COLS] = 134 { 135 /* Event Action 1 Next state */ 136 /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_SDP_INIT, BTA_HL_DCH_OPENING_ST}, 137 /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_MCA_CREATE, BTA_HL_DCH_OPENING_ST}, 138 /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_MCA_CREATE_IND, BTA_HL_DCH_OPENING_ST}, 139 /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 140 /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 141 142 /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 143 /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 144 /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 145 /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 146 /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 147 148 /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 149 /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 150 /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_MCA_RECONNECT, BTA_HL_DCH_OPENING_ST}, 151 /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 152 /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_MCA_RECONNECT_IND, BTA_HL_DCH_OPENING_ST}, 153 154 /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 155 /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 156 /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 157 /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 158 /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 159 160 /* BTA_HL_MCA_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 161 /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 162 /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 163 /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 164 /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 165 /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_ECHO_TEST, BTA_HL_DCH_OPENING_ST}, 166 /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST} 167 }; 168 169 /* state table for opening state */ 170 static const UINT8 bta_hl_dch_st_opening[][BTA_HL_DCH_NUM_COLS] = 171 { 172 /* Event Action 1 Next state */ 173 /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_SDP_INIT, BTA_HL_DCH_OPENING_ST}, 174 /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_MCA_CREATE, BTA_HL_DCH_OPENING_ST}, 175 /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, 176 /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_MCA_CREATE_CFM, BTA_HL_DCH_OPENING_ST}, 177 /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_MCA_OPEN_IND, BTA_HL_DCH_OPEN_ST}, 178 /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_MCA_OPEN_CFM, BTA_HL_DCH_OPEN_ST}, 179 /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, 180 /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_MCA_CLOSE_IND, BTA_HL_DCH_CLOSING_ST}, 181 /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM, BTA_HL_DCH_CLOSING_ST}, 182 /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 183 184 /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 185 /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST}, 186 /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_MCA_RECONNECT, BTA_HL_DCH_OPENING_ST}, 187 /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_SDP_FAIL, BTA_HL_DCH_CLOSING_ST}, 188 /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_IDLE_ST}, 189 /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_MCA_RECONNECT_CFM, BTA_HL_DCH_OPENING_ST}, 190 /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, 191 /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_CREATE_RSP, BTA_HL_DCH_OPENING_ST}, 192 /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_MCA_ABORT, BTA_HL_DCH_OPENING_ST}, 193 /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_MCA_ABORT_IND, BTA_HL_DCH_OPENING_ST}, 194 195 /* BTA_HL_MCA_ABORT_CFM_EVT */ {BTA_HL_DCH_MCA_ABORT_CFM, BTA_HL_DCH_OPENING_ST}, 196 /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, 197 /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, 198 /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST}, 199 /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA, BTA_HL_DCH_OPENING_ST}, 200 /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_ECHO_TEST, BTA_HL_DCH_OPENING_ST}, 201 /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPENING_ST} 202 }; 203 204 /* state table for open state */ 205 static const UINT8 bta_hl_dch_st_open[][BTA_HL_DCH_NUM_COLS] = 206 { 207 /* Event Action 1 Next state */ 208 /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 209 /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 210 /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 211 /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 212 /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 213 /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 214 /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_MCA_CLOSE, BTA_HL_DCH_CLOSING_ST}, 215 /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_MCA_CLOSE_IND, BTA_HL_DCH_CLOSING_ST}, 216 /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM, BTA_HL_DCH_CLOSING_ST}, 217 /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_SEND_DATA, BTA_HL_DCH_OPEN_ST}, 218 219 /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_MCA_RCV_DATA, BTA_HL_DCH_OPEN_ST}, 220 /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST}, 221 /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 222 /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 223 /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 224 /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 225 /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_CLOSE_ECHO_TEST, BTA_HL_DCH_CLOSING_ST}, 226 /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 227 /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 228 /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 229 230 /* BTA_HL_DCH_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 231 /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_MCA_CONG_CHANGE, BTA_HL_DCH_OPEN_ST}, 232 /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_CI_GET_TX_DATA, BTA_HL_DCH_OPEN_ST}, 233 /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_CI_PUT_RX_DATA, BTA_HL_DCH_OPEN_ST}, 234 /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA, BTA_HL_DCH_OPEN_ST}, 235 /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_OPEN_ST}, 236 /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_PUT_ECHO_DATA, BTA_HL_DCH_OPEN_ST} 237 }; 238 239 240 /* state table for closing state */ 241 static const UINT8 bta_hl_dch_st_closing[][BTA_HL_DCH_NUM_COLS] = 242 { 243 /* Event Action 1 Next state */ 244 /* BTA_HL_DCH_SDP_INIT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 245 /* BTA_HL_DCH_OPEN_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 246 /* BTA_HL_MCA_CREATE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 247 /* BTA_HL_MCA_CREATE_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 248 /* BTA_HL_MCA_OPEN_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 249 /* BTA_HL_MCA_OPEN_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 250 /* BTA_HL_DCH_CLOSE_EVT */ {BTA_HL_DCH_MCA_CLOSE, BTA_HL_DCH_CLOSING_ST}, 251 /* BTA_HL_MCA_CLOSE_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 252 /* BTA_HL_MCA_CLOSE_CFM_EVT */ {BTA_HL_DCH_MCA_CLOSE_CFM, BTA_HL_DCH_CLOSING_ST}, 253 /* BTA_HL_API_SEND_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 254 255 /* BTA_HL_MCA_RCV_DATA_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 256 /* BTA_HL_DCH_CLOSE_CMPL_EVT */ {BTA_HL_DCH_CLOSE_CMPL, BTA_HL_DCH_IDLE_ST}, 257 /* BTA_HL_DCH_RECONNECT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 258 /* BTA_HL_DCH_SDP_FAIL_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 259 /* BTA_HL_MCA_RECONNECT_IND_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 260 /* BTA_HL_MCA_RECONNECT_CFM_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 261 /* BTA_HL_DCH_CLOSE_ECHO_TEST_EVT*/ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 262 /* BTA_HL_API_DCH_CREATE_RSP_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 263 /* BTA_HL_DCH_ABORT_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 264 /* BTA_HL_MCA_ABORT_IND_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 265 266 /* BTA_HL_DCH_ABORT_CFM_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 267 /* BTA_HL_MCA_CONG_CHG_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 268 /* BTA_HL_CI_GET_TX_DATA_EVT */ {BTA_HL_DCH_CI_GET_TX_DATA, BTA_HL_DCH_CLOSING_ST}, 269 /* BTA_HL_CI_PUT_RX_DATA_EVT */ {BTA_HL_DCH_CI_PUT_RX_DATA, BTA_HL_DCH_CLOSING_ST}, 270 /* BTA_HL_CI_GET_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_GET_ECHO_DATA, BTA_HL_DCH_CLOSING_ST}, 271 /* BTA_HL_DCH_ECHO_TEST_EVT */ {BTA_HL_DCH_IGNORE, BTA_HL_DCH_CLOSING_ST}, 272 /* BTA_HL_CI_PUT_ECHO_DATA_EVT */ {BTA_HL_DCH_CI_PUT_ECHO_DATA, BTA_HL_DCH_CLOSING_ST} 273 }; 274 275 /* type for state table */ 276 typedef const UINT8 (*tBTA_HL_DCH_ST_TBL)[BTA_HL_DCH_NUM_COLS]; 277 278 /* state table */ 279 const tBTA_HL_DCH_ST_TBL bta_hl_dch_st_tbl[] = 280 { 281 bta_hl_dch_st_idle, 282 bta_hl_dch_st_opening, 283 bta_hl_dch_st_open, 284 bta_hl_dch_st_closing 285 }; 286 287 /***************************************************************************** 288 ** CCH State Table 289 *****************************************************************************/ 290 /***************************************************************************** 291 ** Constants and types 292 *****************************************************************************/ 293 /* state machine action enumeration list for CCH */ 294 enum 295 { 296 BTA_HL_CCH_SDP_INIT, 297 BTA_HL_CCH_MCA_OPEN, 298 BTA_HL_CCH_MCA_CLOSE, 299 BTA_HL_CCH_CLOSE_CMPL, 300 BTA_HL_CCH_MCA_CONNECT, 301 BTA_HL_CCH_MCA_DISCONNECT, 302 BTA_HL_CCH_MCA_RSP_TOUT, 303 BTA_HL_CCH_MCA_DISC_OPEN, 304 BTA_HL_CCH_IGNORE 305 }; 306 307 /* type for action functions */ 308 typedef void (*tBTA_HL_CCH_ACTION)(UINT8 app_idx, UINT8 mcl_idx, tBTA_HL_DATA *p_data); 309 310 /* action function list for MAS */ 311 const tBTA_HL_CCH_ACTION bta_hl_cch_action[] = 312 { 313 bta_hl_cch_sdp_init, 314 bta_hl_cch_mca_open, 315 bta_hl_cch_mca_close, 316 bta_hl_cch_close_cmpl, 317 bta_hl_cch_mca_connect, 318 bta_hl_cch_mca_disconnect, 319 bta_hl_cch_mca_rsp_tout, 320 bta_hl_cch_mca_disc_open 321 }; 322 323 324 /* state table information */ 325 #define BTA_HL_CCH_ACTIONS 1 /* number of actions */ 326 #define BTA_HL_CCH_NEXT_STATE 1 /* position of next state */ 327 #define BTA_HL_CCH_NUM_COLS 2 /* number of columns in state tables */ 328 329 330 /* state table for MAS idle state */ 331 static const UINT8 bta_hl_cch_st_idle[][BTA_HL_CCH_NUM_COLS] = 332 { 333 /* Event Action 1 Next state */ 334 /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_SDP_INIT, BTA_HL_CCH_OPENING_ST}, 335 /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST}, 336 /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST}, 337 /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_CONNECT, BTA_HL_CCH_OPEN_ST}, 338 /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST}, 339 /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST}, 340 /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST}, 341 /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_IDLE_ST} 342 }; 343 344 /* state table for obex/rfcomm connection state */ 345 static const UINT8 bta_hl_cch_st_opening[][BTA_HL_CCH_NUM_COLS] = 346 { 347 /* Event Action 1 Next state */ 348 /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPENING_ST}, 349 /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_MCA_OPEN, BTA_HL_CCH_OPENING_ST}, 350 /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_CLOSE_CMPL, BTA_HL_CCH_IDLE_ST}, 351 /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_CONNECT, BTA_HL_CCH_OPEN_ST}, 352 /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT, BTA_HL_CCH_CLOSING_ST}, 353 /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE, BTA_HL_CCH_CLOSING_ST}, 354 /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_CLOSE_CMPL, BTA_HL_CCH_IDLE_ST}, 355 /* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_MCA_RSP_TOUT, BTA_HL_CCH_CLOSING_ST} 356 }; 357 358 /* state table for open state */ 359 static const UINT8 bta_hl_cch_st_open[][BTA_HL_CCH_NUM_COLS] = 360 { 361 /* Event Action 1 Next state */ 362 /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST}, 363 /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST}, 364 /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST}, 365 /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST}, 366 /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT, BTA_HL_CCH_CLOSING_ST}, 367 /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE, BTA_HL_CCH_CLOSING_ST}, 368 /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_OPEN_ST}, 369 /* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_MCA_RSP_TOUT, BTA_HL_CCH_CLOSING_ST} 370 }; 371 372 /* state table for closing state */ 373 static const UINT8 bta_hl_cch_st_closing[][BTA_HL_CCH_NUM_COLS] = 374 { 375 /* Event Action 1 Next state */ 376 /* BTA_HL_CCH_OPEN_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_CLOSING_ST}, 377 /* BTA_HL_CCH_SDP_OK_EVT */ {BTA_HL_CCH_CLOSE_CMPL, BTA_HL_CCH_IDLE_ST}, 378 /* BTA_HL_CCH_SDP_FAIL_EVT */ {BTA_HL_CCH_CLOSE_CMPL, BTA_HL_CCH_IDLE_ST}, 379 /* BTA_HL_MCA_CONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISC_OPEN, BTA_HL_CCH_CLOSING_ST}, 380 /* BTA_HL_MCA_DISCONNECT_IND_EVT */ {BTA_HL_CCH_MCA_DISCONNECT, BTA_HL_CCH_CLOSING_ST}, 381 /* BTA_HL_CCH_CLOSE_EVT */ {BTA_HL_CCH_MCA_CLOSE, BTA_HL_CCH_CLOSING_ST}, 382 /* BTA_HL_CCH_CLOSE_CMPL_EVT */ {BTA_HL_CCH_CLOSE_CMPL, BTA_HL_CCH_IDLE_ST}, 383 /* BTA_HL_MCA_RSP_TOUT_IND_EVT */ {BTA_HL_CCH_IGNORE, BTA_HL_CCH_CLOSING_ST} 384 }; 385 386 /* type for state table CCH */ 387 typedef const UINT8 (*tBTA_HL_CCH_ST_TBL)[BTA_HL_CCH_NUM_COLS]; 388 389 /* MAS state table */ 390 const tBTA_HL_CCH_ST_TBL bta_hl_cch_st_tbl[] = 391 { 392 bta_hl_cch_st_idle, 393 bta_hl_cch_st_opening, 394 bta_hl_cch_st_open, 395 bta_hl_cch_st_closing 396 }; 397 398 399 /***************************************************************************** 400 ** Global data 401 *****************************************************************************/ 402 403 /* HL control block */ 404 #if BTA_DYNAMIC_MEMORY == FALSE 405 tBTA_HL_CB bta_hl_cb; 406 #endif 407 408 409 /******************************************************************************* 410 ** 411 ** Function bta_hl_cch_sm_execute 412 ** 413 ** Description State machine event handling function for CCH 414 ** 415 ** Returns void 416 ** 417 *******************************************************************************/ 418 void bta_hl_cch_sm_execute(UINT8 app_idx, UINT8 mcl_idx, 419 UINT16 event, tBTA_HL_DATA *p_data) 420 { 421 tBTA_HL_CCH_ST_TBL state_table; 422 UINT8 action; 423 int i; 424 tBTA_HL_MCL_CB *p_cb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 425 426 #if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) 427 tBTA_HL_CCH_STATE in_state = p_cb->cch_state; 428 UINT16 cur_evt = event; 429 APPL_TRACE_DEBUG3("HDP CCH Event Handler: State 0x%02x [%s], Event [%s]", in_state, 430 bta_hl_cch_state_code(in_state), 431 bta_hl_evt_code(cur_evt)); 432 #endif 433 434 /* look up the state table for the current state */ 435 state_table = bta_hl_cch_st_tbl[p_cb->cch_state]; 436 437 event &= 0x00FF; 438 439 /* set next state */ 440 p_cb->cch_state = state_table[event][BTA_HL_CCH_NEXT_STATE]; 441 442 for (i = 0; i < BTA_HL_CCH_ACTIONS; i++) 443 { 444 if ((action = state_table[event][i]) != BTA_HL_CCH_IGNORE) 445 { 446 (*bta_hl_cch_action[action])(app_idx, mcl_idx, p_data); 447 } 448 else 449 { 450 /* discard HDP data */ 451 bta_hl_discard_data(p_data->hdr.event, p_data); 452 break; 453 } 454 } 455 #if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) 456 if (in_state != p_cb->cch_state) 457 { 458 APPL_TRACE_DEBUG3("HL CCH State Change: [%s] -> [%s] after [%s]", 459 bta_hl_cch_state_code(in_state), 460 bta_hl_cch_state_code(p_cb->cch_state), 461 bta_hl_evt_code(cur_evt)); 462 } 463 #endif 464 465 } 466 467 /******************************************************************************* 468 ** 469 ** Function bta_hl_dch_sm_execute 470 ** 471 ** Description State machine event handling function for DCH 472 ** 473 ** Returns void 474 ** 475 *******************************************************************************/ 476 void bta_hl_dch_sm_execute(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx, 477 UINT16 event, tBTA_HL_DATA *p_data) 478 { 479 tBTA_HL_DCH_ST_TBL state_table; 480 UINT8 action; 481 int i; 482 tBTA_HL_MDL_CB *p_cb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); 483 484 #if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) 485 tBTA_HL_DCH_STATE in_state = p_cb->dch_state; 486 UINT16 cur_evt = event; 487 APPL_TRACE_DEBUG3("HDP DCH Event Handler: State 0x%02x [%s], Event [%s]", in_state, 488 bta_hl_dch_state_code(in_state), 489 bta_hl_evt_code(cur_evt)); 490 #endif 491 492 /* look up the state table for the current state */ 493 state_table = bta_hl_dch_st_tbl[p_cb->dch_state]; 494 event -= BTA_HL_DCH_EVT_MIN; 495 496 /* set next state */ 497 p_cb->dch_state = state_table[event][BTA_HL_DCH_NEXT_STATE]; 498 499 for (i = 0; i < BTA_HL_DCH_ACTIONS; i++) 500 { 501 if ((action = state_table[event][i]) != BTA_HL_DCH_IGNORE) 502 { 503 (*bta_hl_dch_action[action])(app_idx, mcl_idx, mdl_idx, p_data); 504 } 505 else 506 { 507 /* discard mas data */ 508 bta_hl_discard_data(p_data->hdr.event, p_data); 509 break; 510 } 511 } 512 513 514 #if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) 515 if (in_state != p_cb->dch_state) 516 { 517 APPL_TRACE_DEBUG3("HL DCH State Change: [%s] -> [%s] after [%s]", 518 bta_hl_dch_state_code(in_state), 519 bta_hl_dch_state_code(p_cb->dch_state), 520 bta_hl_evt_code(cur_evt)); 521 } 522 #endif 523 } 524 /******************************************************************************* 525 ** 526 ** Function bta_hl_api_enable 527 ** 528 ** Description Process the API enable request to enable the HL subsystem 529 ** 530 ** Returns void 531 ** 532 *******************************************************************************/ 533 static void bta_hl_api_enable(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 534 { 535 tBTA_HL_CTRL evt_data; 536 537 /* If already enabled then reject this request */ 538 if (p_cb->enable) 539 { 540 APPL_TRACE_ERROR0("HL is already enabled"); 541 evt_data.enable_cfm.status = BTA_HL_STATUS_FAIL; 542 if (p_data->api_enable.p_cback) 543 p_data->api_enable.p_cback(BTA_HL_CTRL_ENABLE_CFM_EVT, (tBTA_HL_CTRL *) &evt_data); 544 return; 545 } 546 547 /* Done with checking. now perform the enable oepration*/ 548 /* initialize control block */ 549 memset(p_cb, 0, sizeof(tBTA_HL_CB)); 550 p_cb->enable = TRUE; 551 p_cb->p_ctrl_cback = p_data->api_enable.p_cback; 552 evt_data.enable_cfm.status = BTA_HL_STATUS_OK; 553 if (p_data->api_enable.p_cback) 554 p_data->api_enable.p_cback(BTA_HL_CTRL_ENABLE_CFM_EVT, (tBTA_HL_CTRL *) &evt_data); 555 556 } 557 /******************************************************************************* 558 ** 559 ** Function bta_hl_api_disable 560 ** 561 ** Description Process the API disable request to disable the HL subsystem 562 ** 563 ** Returns void 564 ** 565 *******************************************************************************/ 566 static void bta_hl_api_disable(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 567 { 568 tBTA_HL_CTRL evt_data; 569 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 570 571 if (p_cb->enable) 572 { 573 p_cb->disabling = TRUE; 574 bta_hl_check_disable(p_data); 575 } 576 else 577 { 578 status = BTA_HL_STATUS_FAIL; 579 evt_data.disable_cfm.status = status; 580 if (p_cb->p_ctrl_cback) p_cb->p_ctrl_cback(BTA_HL_CTRL_DISABLE_CFM_EVT, (tBTA_HL_CTRL *) &evt_data); 581 } 582 583 584 #if BTA_HL_DEBUG == TRUE 585 if (status != BTA_HL_STATUS_OK) 586 { 587 APPL_TRACE_DEBUG1("bta_hl_api_disable status =%s", bta_hl_status_code(status)); 588 } 589 #endif 590 591 } 592 593 /******************************************************************************* 594 ** 595 ** Function bta_hl_api_update 596 ** 597 ** Description Process the API registration request to register an HDP applciation 598 ** 599 ** Returns void 600 ** 601 *******************************************************************************/ 602 static void bta_hl_api_update(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 603 { 604 tBTA_HL evt_data; 605 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(0); 606 tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL; 607 608 609 APPL_TRACE_DEBUG0("bta_hl_api_update"); 610 if (p_cb->enable) 611 { 612 613 status = bta_hl_app_update(p_data->api_update.app_id, p_data->api_update.is_register); 614 if (!p_data->api_update.is_register) 615 { 616 APPL_TRACE_DEBUG0("Deregister"); 617 memset(&evt_data, 0, sizeof(tBTA_HL)); 618 evt_data.dereg_cfm.status = status; 619 evt_data.dereg_cfm.app_id = p_data->api_update.app_id; 620 if (status == BTA_HL_STATUS_OK) 621 evt_data.dereg_cfm.app_handle = p_acb->app_handle; 622 if (p_acb->p_cback) 623 { 624 p_acb->p_cback(BTA_HL_DEREGISTER_CFM_EVT, (tBTA_HL *) &evt_data); 625 } 626 return ; 627 } 628 629 } 630 631 if (status != BTA_HL_STATUS_OK) 632 { 633 if ((status != BTA_HL_STATUS_DUPLICATE_APP_ID) && 634 (status != BTA_HL_STATUS_NO_RESOURCE)) 635 { 636 if (p_acb) 637 memset(p_acb, 0, sizeof(tBTA_HL_APP_CB)); 638 } 639 } 640 #if BTA_HL_DEBUG == TRUE 641 if (status != BTA_HL_STATUS_OK) 642 { 643 APPL_TRACE_DEBUG1("bta_hl_api_register status =%s", bta_hl_status_code(status)); 644 } 645 #endif 646 647 memset(&evt_data, 0, sizeof(tBTA_HL)); 648 evt_data.reg_cfm.status = status; 649 evt_data.reg_cfm.app_id = p_data->api_update.app_id; 650 if (status == BTA_HL_STATUS_OK) 651 evt_data.reg_cfm.app_handle = p_acb->app_handle; 652 if (p_data->api_reg.p_cback) 653 { 654 p_data->api_reg.p_cback(BTA_HL_REGISTER_CFM_EVT, (tBTA_HL *) &evt_data); 655 } 656 657 if (status == BTA_HL_STATUS_OK) 658 { 659 evt_data.sdp_info_ind.app_handle = p_acb->app_handle; 660 evt_data.sdp_info_ind.ctrl_psm = p_acb->ctrl_psm; 661 evt_data.sdp_info_ind.data_psm = p_acb->data_psm; 662 evt_data.sdp_info_ind.data_x_spec = BTA_HL_SDP_IEEE_11073_20601; 663 evt_data.sdp_info_ind.mcap_sup_procs = BTA_HL_MCAP_SUP_PROC_MASK ; 664 665 if (p_data->api_reg.p_cback) 666 { 667 p_data->api_reg.p_cback(BTA_HL_SDP_INFO_IND_EVT, (tBTA_HL *) &evt_data); 668 } 669 } 670 } 671 672 /******************************************************************************* 673 ** 674 ** Function bta_hl_api_register 675 ** 676 ** Description Process the API registration request to register an HDP applciation 677 ** 678 ** Returns void 679 ** 680 *******************************************************************************/ 681 static void bta_hl_api_register(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 682 { 683 tBTA_HL evt_data; 684 UINT8 app_idx; 685 tBTA_HL_APP_CB *p_acb = NULL; 686 tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL; 687 688 689 if (p_cb->enable) 690 { 691 if (!bta_hl_is_a_duplicate_id(p_data->api_reg.app_id)) 692 { 693 if (bta_hl_find_avail_app_idx(&app_idx)) 694 { 695 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 696 p_acb->in_use = TRUE; 697 p_acb->app_id = p_data->api_reg.app_id; 698 p_acb->p_cback = p_data->api_reg.p_cback; 699 p_acb->sec_mask = p_data->api_reg.sec_mask; 700 p_acb->dev_type = p_data->api_reg.dev_type; 701 BCM_STRNCPY_S(p_acb->srv_name, sizeof(p_acb->srv_name), p_data->api_reg.srv_name, BTA_SERVICE_NAME_LEN); 702 BCM_STRNCPY_S(p_acb->srv_desp, sizeof(p_acb->srv_desp), p_data->api_reg.srv_desp, BTA_SERVICE_DESP_LEN); 703 BCM_STRNCPY_S(p_acb->provider_name, sizeof(p_acb->provider_name), p_data->api_reg.provider_name, BTA_PROVIDER_NAME_LEN); 704 bta_hl_cb.p_alloc_psm = L2CA_AllocatePSM; 705 p_acb->ctrl_psm = bta_hl_cb.p_alloc_psm(); 706 p_acb->data_psm = bta_hl_cb.p_alloc_psm(); 707 p_acb->p_mcap_cback = bta_hl_mcap_ctrl_cback; 708 status = bta_hl_app_registration(app_idx); 709 } 710 else 711 { 712 status = BTA_HL_STATUS_NO_RESOURCE; 713 } 714 } 715 else 716 { 717 status = BTA_HL_STATUS_DUPLICATE_APP_ID; 718 } 719 } 720 721 if (status != BTA_HL_STATUS_OK) 722 { 723 if ((status != BTA_HL_STATUS_DUPLICATE_APP_ID) && 724 (status != BTA_HL_STATUS_NO_RESOURCE)) 725 { 726 if (p_acb) 727 memset(p_acb, 0, sizeof(tBTA_HL_APP_CB)); 728 } 729 } 730 #if BTA_HL_DEBUG == TRUE 731 if (status != BTA_HL_STATUS_OK) 732 { 733 APPL_TRACE_DEBUG1("bta_hl_api_register status =%s", bta_hl_status_code(status)); 734 } 735 #endif 736 737 memset(&evt_data, 0, sizeof(tBTA_HL)); 738 evt_data.reg_cfm.status = status; 739 evt_data.reg_cfm.app_id = p_data->api_reg.app_id; 740 if (status == BTA_HL_STATUS_OK) 741 evt_data.reg_cfm.app_handle = p_acb->app_handle; 742 if (p_data->api_reg.p_cback) 743 { 744 p_data->api_reg.p_cback(BTA_HL_REGISTER_CFM_EVT, (tBTA_HL *) &evt_data); 745 } 746 747 if (status == BTA_HL_STATUS_OK) 748 { 749 evt_data.sdp_info_ind.app_handle = p_acb->app_handle; 750 evt_data.sdp_info_ind.ctrl_psm = p_acb->ctrl_psm; 751 evt_data.sdp_info_ind.data_psm = p_acb->data_psm; 752 evt_data.sdp_info_ind.data_x_spec = BTA_HL_SDP_IEEE_11073_20601; 753 evt_data.sdp_info_ind.mcap_sup_procs = BTA_HL_MCAP_SUP_PROC_MASK ; 754 755 if (p_data->api_reg.p_cback) 756 { 757 p_data->api_reg.p_cback(BTA_HL_SDP_INFO_IND_EVT, (tBTA_HL *) &evt_data); 758 } 759 } 760 } 761 762 /******************************************************************************* 763 ** 764 ** Function bta_hl_api_deregister 765 ** 766 ** Description Process the API de-registration request 767 ** 768 ** Returns void 769 ** 770 *******************************************************************************/ 771 static void bta_hl_api_deregister(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 772 { 773 774 UINT8 app_idx; 775 tBTA_HL_APP_CB *p_acb; 776 777 if (bta_hl_find_app_idx_using_handle(p_data->api_dereg.app_handle, &app_idx)) 778 { 779 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 780 p_acb->deregistering= TRUE; 781 bta_hl_check_deregistration(app_idx,p_data); 782 } 783 else 784 { 785 APPL_TRACE_ERROR1("Invalid app_handle=%d", p_data->api_dereg.app_handle); 786 } 787 } 788 789 /******************************************************************************* 790 ** 791 ** Function bta_hl_api_cch_open 792 ** 793 ** Description Process the API CCH open request 794 ** 795 ** Returns void 796 ** 797 *******************************************************************************/ 798 static void bta_hl_api_cch_open(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 799 { 800 tBTA_HL evt_data; 801 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 802 UINT8 app_idx, mcl_idx; 803 tBTA_HL_APP_CB *p_acb; 804 tBTA_HL_MCL_CB *p_mcb; 805 806 if (bta_hl_find_app_idx_using_handle(p_data->api_cch_open.app_handle, &app_idx)) 807 { 808 809 if (!bta_hl_find_mcl_idx(app_idx, p_data->api_cch_open.bd_addr, &mcl_idx)) 810 { 811 if (bta_hl_find_avail_mcl_idx(app_idx, &mcl_idx)) 812 { 813 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 814 p_mcb->in_use = TRUE; 815 p_mcb->req_ctrl_psm = p_data->api_cch_open.ctrl_psm; 816 p_mcb->sec_mask = p_data->api_cch_open.sec_mask; 817 bdcpy(p_mcb->bd_addr, p_data->api_cch_open.bd_addr); 818 p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_OPEN; 819 } 820 else 821 { 822 status = BTA_HL_STATUS_NO_RESOURCE; 823 } 824 } 825 else 826 { 827 /* Only one MCL per BD_ADDR */ 828 status = BTA_HL_STATUS_DUPLICATE_CCH_OPEN; 829 APPL_TRACE_DEBUG1("bta_hl_api_cch_open: CCH already open: status =%d",status) 830 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 831 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 832 if (p_acb->p_cback) 833 { 834 bta_hl_build_cch_open_cfm(&evt_data, p_data->api_cch_open.app_id, 835 p_data->api_cch_open.app_handle, 836 p_mcb->mcl_handle, 837 p_data->api_cch_open.bd_addr, 838 status); 839 p_acb->p_cback(BTA_HL_CCH_OPEN_CFM_EVT,(tBTA_HL *) &evt_data ); 840 } 841 else 842 { 843 APPL_TRACE_ERROR0("bta_hl_api_cch_open Null Callback"); 844 } 845 return; 846 } 847 } 848 else 849 { 850 status = BTA_HL_STATUS_INVALID_APP_HANDLE; 851 } 852 #if BTA_HL_DEBUG == TRUE 853 if (status != BTA_HL_STATUS_OK) 854 { 855 APPL_TRACE_DEBUG1("bta_hl_api_cch_open status =%s", bta_hl_status_code(status)); 856 } 857 #endif 858 switch (status) 859 { 860 case BTA_HL_STATUS_OK: 861 bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_OPEN_EVT, p_data); 862 break; 863 case BTA_HL_STATUS_NO_RESOURCE: 864 case BTA_HL_STATUS_FAIL: 865 866 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 867 if (p_acb->p_cback) 868 { 869 bta_hl_build_cch_open_cfm(&evt_data, p_data->api_cch_open.app_id, 870 p_data->api_cch_open.app_handle, 871 0, 872 p_data->api_cch_open.bd_addr, 873 status); 874 p_acb->p_cback(BTA_HL_CCH_OPEN_CFM_EVT,(tBTA_HL *) &evt_data ); 875 } 876 else 877 { 878 APPL_TRACE_ERROR0("bta_hl_api_cch_open Null Callback"); 879 } 880 break; 881 default: 882 APPL_TRACE_ERROR1("status code=%d", status); 883 break; 884 } 885 } 886 887 /******************************************************************************* 888 ** 889 ** Function bta_hl_api_cch_close 890 ** 891 ** Description Process the API CCH close request 892 ** 893 ** Returns void 894 ** 895 *******************************************************************************/ 896 static void bta_hl_api_cch_close(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 897 { 898 tBTA_HL evt_data; 899 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 900 UINT8 app_idx, mcl_idx; 901 tBTA_HL_APP_CB *p_acb; 902 tBTA_HL_MCL_CB *p_mcb; 903 904 if (bta_hl_find_mcl_idx_using_handle(p_data->api_cch_close.mcl_handle, &app_idx, &mcl_idx)) 905 { 906 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 907 p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_CLOSE; 908 } 909 else 910 { 911 status = BTA_HL_STATUS_INVALID_MCL_HANDLE; 912 } 913 #if BTA_HL_DEBUG == TRUE 914 if (status != BTA_HL_STATUS_OK) 915 { 916 APPL_TRACE_DEBUG1("bta_hl_api_cch_close status =%s", bta_hl_status_code(status)); 917 } 918 #endif 919 switch (status) 920 { 921 case BTA_HL_STATUS_OK: 922 bta_hl_check_cch_close(app_idx, mcl_idx, p_data, TRUE); 923 break; 924 925 case BTA_HL_STATUS_INVALID_MCL_HANDLE: 926 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 927 if (p_acb->p_cback) 928 { 929 bta_hl_build_cch_close_cfm(&evt_data, 930 p_acb->app_handle, 931 p_data->api_cch_close.mcl_handle, 932 status); 933 p_acb->p_cback(BTA_HL_CCH_CLOSE_CFM_EVT,(tBTA_HL *) &evt_data ); 934 } 935 else 936 { 937 APPL_TRACE_ERROR0("bta_hl_api_cch_close Null Callback"); 938 } 939 break; 940 941 default: 942 APPL_TRACE_ERROR1("status code=%d", status); 943 break; 944 945 } 946 947 } 948 949 /******************************************************************************* 950 ** 951 ** Function bta_hl_api_dch_open 952 ** 953 ** Description Process the API DCH open request 954 ** 955 ** Returns void 956 ** 957 *******************************************************************************/ 958 static void bta_hl_api_dch_open(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 959 { 960 tBTA_HL evt_data; 961 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 962 UINT8 app_idx, mcl_idx, mdl_idx; 963 tBTA_HL_APP_CB *p_acb; 964 tBTA_HL_MCL_CB *p_mcb; 965 tBTA_HL_MDL_CB *p_dcb; 966 tBTA_HL_MDEP_CFG *p_mdep_cfg; 967 UINT8 mdep_cfg_idx; 968 969 if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_open.mcl_handle, &app_idx, &mcl_idx)) 970 { 971 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 972 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 973 974 APPL_TRACE_DEBUG4("bta_hl_api_dch_open: app_ix=%d, mcl_idx=%d, cch_state=%d, mcl_handle=%d",app_idx,mcl_idx,p_mcb->cch_state,p_data->api_dch_open.mcl_handle); 975 if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) 976 { 977 if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) 978 { 979 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); 980 981 if (bta_hl_find_mdep_cfg_idx(app_idx, p_data->api_dch_open.local_mdep_id, &mdep_cfg_idx)) 982 { 983 if ( mdep_cfg_idx && 984 (p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SINK)) 985 { 986 p_data->api_dch_open.local_cfg = BTA_HL_DCH_CFG_NO_PREF; 987 } 988 989 if ((status = bta_hl_chk_local_cfg(app_idx,mcl_idx,mdep_cfg_idx,p_data->api_dch_open.local_cfg)) 990 == BTA_HL_STATUS_OK) 991 { 992 993 if (p_data->api_dch_open.local_mdep_id != BTA_HL_ECHO_TEST_MDEP_ID) 994 { 995 if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx, p_data->api_dch_open.ctrl_psm)) 996 { 997 p_mdep_cfg = BTA_HL_GET_MDEP_CFG_PTR(app_idx, mdep_cfg_idx); 998 p_dcb->in_use = TRUE; 999 p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_OPEN; 1000 p_dcb->sec_mask = p_data->api_dch_open.sec_mask; 1001 p_dcb->local_mdep_id = p_data->api_dch_open.local_mdep_id; 1002 p_dcb->peer_mdep_id = p_data->api_dch_open.peer_mdep_id; 1003 1004 if (p_mdep_cfg->mdep_role == BTA_HL_MDEP_ROLE_SINK) 1005 { 1006 p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE; 1007 } 1008 else 1009 { 1010 p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SINK; 1011 } 1012 1013 p_dcb->local_mdep_cfg_idx = mdep_cfg_idx; 1014 p_dcb->local_cfg = p_data->api_dch_open.local_cfg; 1015 1016 bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx, 1017 &p_dcb->max_rx_apdu_size, 1018 &p_dcb->max_tx_apdu_size); 1019 p_dcb->mdl_id = bta_hl_allocate_mdl_id(app_idx,mcl_idx,mdl_idx); 1020 p_dcb->mdl_cfg_idx_included = FALSE; 1021 } 1022 else 1023 { 1024 status = BTA_HL_STATUS_INVALID_CTRL_PSM; 1025 } 1026 1027 } 1028 else 1029 { 1030 status = BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID; 1031 } 1032 } 1033 } 1034 else 1035 { 1036 status = BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID; 1037 } 1038 } 1039 else 1040 { 1041 status = BTA_HL_STATUS_NO_RESOURCE; 1042 } 1043 } 1044 else 1045 { 1046 status = BTA_HL_STATUS_NO_CCH; 1047 } 1048 } 1049 else 1050 { 1051 status = BTA_HL_STATUS_INVALID_MCL_HANDLE; 1052 } 1053 1054 #if BTA_HL_DEBUG == TRUE 1055 if (status != BTA_HL_STATUS_OK) 1056 { 1057 APPL_TRACE_DEBUG1("bta_hl_api_dch_open status =%s", bta_hl_status_code(status)); 1058 } 1059 #endif 1060 switch (status) 1061 { 1062 case BTA_HL_STATUS_OK: 1063 if (p_mcb->sdp.num_recs) 1064 { 1065 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_OPEN_EVT, p_data); 1066 } 1067 else 1068 { 1069 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_SDP_INIT_EVT, p_data); 1070 } 1071 break; 1072 case BTA_HL_STATUS_INVALID_DCH_CFG: 1073 case BTA_HL_STATUS_NO_FIRST_RELIABLE: 1074 case BTA_HL_STATUS_NO_CCH: 1075 case BTA_HL_STATUS_NO_RESOURCE: 1076 case BTA_HL_STATUS_FAIL: 1077 case BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID: 1078 case BTA_HL_STATUS_INVALID_CTRL_PSM: 1079 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 1080 if (p_acb->p_cback) 1081 { 1082 bta_hl_build_dch_open_cfm(&evt_data, 1083 p_acb->app_handle, 1084 p_data->api_dch_open.mcl_handle, 1085 BTA_HL_INVALID_MDL_HANDLE, 1086 0,0,0,0,0, status); 1087 p_acb->p_cback(BTA_HL_DCH_OPEN_CFM_EVT,(tBTA_HL *) &evt_data ); 1088 } 1089 else 1090 { 1091 APPL_TRACE_ERROR0("bta_hl_api_dch_open Null Callback"); 1092 } 1093 1094 break; 1095 default: 1096 APPL_TRACE_ERROR1("Status code=%d", status); 1097 break; 1098 1099 } 1100 1101 } 1102 /******************************************************************************* 1103 ** 1104 ** Function bta_hl_api_dch_close 1105 ** 1106 ** Description Process the API DCH close request 1107 ** 1108 ** Returns void 1109 ** 1110 *******************************************************************************/ 1111 static void bta_hl_api_dch_close(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 1112 { 1113 tBTA_HL evt_data; 1114 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 1115 UINT8 app_idx, mcl_idx, mdl_idx; 1116 tBTA_HL_APP_CB *p_acb; 1117 tBTA_HL_MCL_CB *p_mcb; 1118 tBTA_HL_MDL_CB *p_dcb; 1119 1120 1121 if (bta_hl_find_mdl_idx_using_handle(p_data->api_dch_close.mdl_handle, &app_idx, &mcl_idx, &mdl_idx )) 1122 { 1123 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); 1124 if (p_dcb->dch_state != BTA_HL_DCH_OPEN_ST) 1125 { 1126 status = BTA_HL_STATUS_FAIL; 1127 } 1128 } 1129 else 1130 { 1131 status = BTA_HL_STATUS_INVALID_MDL_HANDLE; 1132 } 1133 1134 #if BTA_HL_DEBUG == TRUE 1135 if (status != BTA_HL_STATUS_OK) 1136 { 1137 APPL_TRACE_DEBUG1("bta_hl_api_dch_close status =%s", bta_hl_status_code(status)); 1138 } 1139 #endif 1140 1141 switch (status) 1142 { 1143 case BTA_HL_STATUS_OK: 1144 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_EVT, p_data); 1145 break; 1146 case BTA_HL_STATUS_FAIL: 1147 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 1148 if (p_acb->p_cback) 1149 { 1150 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 1151 bta_hl_build_dch_close_cfm(&evt_data, 1152 p_acb->app_handle, 1153 p_mcb->mcl_handle, 1154 p_data->api_dch_close.mdl_handle, 1155 status); 1156 1157 p_acb->p_cback(BTA_HL_DCH_CLOSE_CFM_EVT,(tBTA_HL *) &evt_data ); 1158 } 1159 else 1160 { 1161 APPL_TRACE_ERROR0("bta_hl_api_dch_close Null Callback"); 1162 } 1163 break; 1164 default: 1165 APPL_TRACE_ERROR1("Status code=%d", status); 1166 break; 1167 } 1168 } 1169 1170 1171 /******************************************************************************* 1172 ** 1173 ** Function bta_hl_api_dch_reconnect 1174 ** 1175 ** Description Process the API DCH reconnect request 1176 ** 1177 ** Returns void 1178 ** 1179 *******************************************************************************/ 1180 static void bta_hl_api_dch_reconnect(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 1181 { 1182 tBTA_HL evt_data; 1183 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 1184 UINT8 app_idx, mcl_idx, mdl_idx; 1185 tBTA_HL_APP_CB *p_acb; 1186 tBTA_HL_MCL_CB *p_mcb; 1187 tBTA_HL_MDL_CB *p_dcb; 1188 UINT8 mdep_cfg_idx; 1189 UINT8 mdl_cfg_idx; 1190 tBTA_HL_MDEP_CFG *p_mdep_cfg; 1191 1192 if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_reconnect.mcl_handle, &app_idx, &mcl_idx)) 1193 { 1194 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 1195 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 1196 if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) 1197 { 1198 if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) 1199 { 1200 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); 1201 if (bta_hl_validate_reconnect_params(app_idx, mcl_idx, &(p_data->api_dch_reconnect), 1202 &mdep_cfg_idx, &mdl_cfg_idx )) 1203 { 1204 if (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx) && 1205 (p_acb->mdl_cfg[mdl_cfg_idx].dch_mode != BTA_HL_DCH_MODE_RELIABLE)) 1206 { 1207 status = BTA_HL_STATUS_NO_FIRST_RELIABLE; 1208 } 1209 else 1210 { 1211 if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx, p_data->api_dch_open.ctrl_psm)) 1212 { 1213 p_dcb->in_use = TRUE; 1214 p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_RECONNECT; 1215 p_dcb->sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); 1216 p_dcb->local_mdep_id = p_acb->mdl_cfg[mdl_cfg_idx].local_mdep_id; 1217 p_dcb->local_mdep_cfg_idx = mdep_cfg_idx; 1218 p_dcb->local_cfg = BTA_HL_DCH_CFG_UNKNOWN; 1219 p_dcb->mdl_id = p_data->api_dch_reconnect.mdl_id; 1220 p_dcb->mdl_cfg_idx_included = TRUE; 1221 p_dcb->mdl_cfg_idx = mdl_cfg_idx; 1222 p_dcb->dch_mode = p_acb->mdl_cfg[mdl_cfg_idx].dch_mode; 1223 1224 p_mdep_cfg = BTA_HL_GET_MDEP_CFG_PTR(app_idx, mdep_cfg_idx); 1225 1226 if (p_mdep_cfg->mdep_role == BTA_HL_MDEP_ROLE_SINK) 1227 { 1228 p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE; 1229 APPL_TRACE_DEBUG0("peer mdep role = SOURCE "); 1230 } 1231 else 1232 { 1233 p_dcb->peer_mdep_role = BTA_HL_MDEP_ROLE_SINK; 1234 APPL_TRACE_DEBUG0("peer mdep role = SINK "); 1235 } 1236 1237 bta_hl_find_rxtx_apdu_size(app_idx, mdep_cfg_idx, 1238 &p_dcb->max_rx_apdu_size, 1239 &p_dcb->max_tx_apdu_size); 1240 } 1241 else 1242 { 1243 status = BTA_HL_STATUS_INVALID_CTRL_PSM; 1244 } 1245 } 1246 } 1247 else 1248 { 1249 status = BTA_HL_STATUS_INVALID_RECONNECT_CFG; 1250 } 1251 } 1252 else 1253 { 1254 status = BTA_HL_STATUS_NO_RESOURCE; 1255 } 1256 } 1257 else 1258 { 1259 status = BTA_HL_STATUS_NO_CCH; 1260 } 1261 } 1262 else 1263 { 1264 status = BTA_HL_STATUS_INVALID_MCL_HANDLE; 1265 } 1266 1267 #if BTA_HL_DEBUG == TRUE 1268 if (status != BTA_HL_STATUS_OK) 1269 { 1270 APPL_TRACE_DEBUG1("bta_hl_api_dch_reconnect status=%s", bta_hl_status_code(status)); 1271 } 1272 #endif 1273 1274 switch (status) 1275 { 1276 case BTA_HL_STATUS_OK: 1277 if (p_mcb->sdp.num_recs) 1278 { 1279 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_RECONNECT_EVT, p_data); 1280 } 1281 else 1282 { 1283 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_SDP_INIT_EVT, p_data); 1284 } 1285 break; 1286 case BTA_HL_STATUS_INVALID_RECONNECT_CFG: 1287 case BTA_HL_STATUS_NO_FIRST_RELIABLE: 1288 case BTA_HL_STATUS_NO_CCH: 1289 case BTA_HL_STATUS_NO_RESOURCE: 1290 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 1291 if (p_acb->p_cback) 1292 { 1293 bta_hl_build_dch_open_cfm(&evt_data, 1294 p_acb->app_handle, 1295 p_data->api_dch_reconnect.mcl_handle, 1296 BTA_HL_INVALID_MDL_HANDLE, 1297 0,p_data->api_dch_reconnect.mdl_id,0,0,0, status); 1298 p_acb->p_cback(BTA_HL_DCH_RECONNECT_CFM_EVT,(tBTA_HL *) &evt_data ); 1299 } 1300 else 1301 { 1302 APPL_TRACE_ERROR0("bta_hl_api_dch_reconnect Null Callback"); 1303 } 1304 break; 1305 default: 1306 APPL_TRACE_ERROR1("Status code=%d", status); 1307 break; 1308 } 1309 } 1310 1311 /******************************************************************************* 1312 ** 1313 ** Function bta_hl_api_dch_echo_test 1314 ** 1315 ** Description Process the API Echo test request 1316 ** 1317 ** Returns void 1318 ** 1319 *******************************************************************************/ 1320 static void bta_hl_api_dch_echo_test(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 1321 { 1322 tBTA_HL evt_data; 1323 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 1324 UINT8 app_idx, mcl_idx, mdl_idx; 1325 tBTA_HL_APP_CB *p_acb; 1326 tBTA_HL_MCL_CB *p_mcb; 1327 tBTA_HL_MDL_CB *p_dcb; 1328 tBTA_HL_ECHO_CFG *p_echo_cfg; 1329 1330 1331 if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_echo_test.mcl_handle, &app_idx, &mcl_idx)) 1332 { 1333 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 1334 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 1335 if (p_mcb->cch_state == BTA_HL_CCH_OPEN_ST) 1336 { 1337 if (!p_mcb->echo_test ) 1338 { 1339 if (bta_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx)) 1340 { 1341 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); 1342 1343 if ((p_data->api_dch_echo_test.local_cfg == BTA_HL_DCH_CFG_RELIABLE) || 1344 (p_data->api_dch_echo_test.local_cfg == BTA_HL_DCH_CFG_STREAMING)) 1345 { 1346 if ((p_dcb->p_echo_tx_pkt = bta_hl_get_buf(p_data->api_dch_echo_test.pkt_size)) != NULL ) 1347 { 1348 if (bta_hl_set_ctrl_psm_for_dch(app_idx, mcl_idx, mdl_idx, p_data->api_dch_open.ctrl_psm)) 1349 { 1350 p_dcb->in_use = TRUE; 1351 p_dcb->dch_oper = BTA_HL_DCH_OP_LOCAL_OPEN; 1352 p_dcb->sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT); 1353 p_dcb->local_mdep_cfg_idx = BTA_HL_ECHO_TEST_MDEP_CFG_IDX; 1354 p_dcb->local_cfg = p_data->api_dch_echo_test.local_cfg; 1355 p_dcb->local_mdep_id = BTA_HL_ECHO_TEST_MDEP_ID; 1356 p_dcb->peer_mdep_id = BTA_HL_ECHO_TEST_MDEP_ID; 1357 p_dcb->mdl_id = bta_hl_allocate_mdl_id(app_idx,mcl_idx,mdl_idx); 1358 p_dcb->mdl_cfg_idx_included = FALSE; 1359 p_echo_cfg = BTA_HL_GET_ECHO_CFG_PTR(app_idx); 1360 p_dcb->max_rx_apdu_size = p_echo_cfg->max_rx_apdu_size; 1361 p_dcb->max_tx_apdu_size = p_echo_cfg->max_tx_apdu_size; 1362 p_mcb->echo_test = TRUE; 1363 p_mcb->echo_mdl_idx = mdl_idx; 1364 } 1365 else 1366 { 1367 status = BTA_HL_STATUS_INVALID_CTRL_PSM; 1368 } 1369 } 1370 else 1371 { 1372 status = BTA_HL_STATUS_NO_RESOURCE; 1373 } 1374 } 1375 else 1376 { 1377 status = BTA_HL_STATUS_INVALID_DCH_CFG; 1378 } 1379 } 1380 else 1381 { 1382 status = BTA_HL_STATUS_NO_RESOURCE; 1383 } 1384 } 1385 else 1386 { 1387 status = BTA_HL_STATUS_ECHO_TEST_BUSY; 1388 } 1389 } 1390 else 1391 { 1392 status = BTA_HL_STATUS_NO_CCH; 1393 } 1394 } 1395 else 1396 { 1397 status = BTA_HL_STATUS_NO_MCL; 1398 } 1399 1400 #if BTA_HL_DEBUG == TRUE 1401 if (status != BTA_HL_STATUS_OK) 1402 { 1403 APPL_TRACE_DEBUG1("bta_hl_api_dch_echo_test status=%s", bta_hl_status_code(status)); 1404 } 1405 #endif 1406 1407 switch (status) 1408 { 1409 case BTA_HL_STATUS_OK: 1410 if (p_mcb->sdp.num_recs) 1411 { 1412 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ECHO_TEST_EVT, p_data); 1413 } 1414 else 1415 { 1416 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_SDP_INIT_EVT, p_data); 1417 } 1418 break; 1419 case BTA_HL_STATUS_ECHO_TEST_BUSY: 1420 case BTA_HL_STATUS_NO_RESOURCE: 1421 case BTA_HL_STATUS_INVALID_DCH_CFG: 1422 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 1423 if (p_acb->p_cback) 1424 { 1425 bta_hl_build_echo_test_cfm(&evt_data, 1426 p_acb->app_handle, 1427 p_mcb->mcl_handle, 1428 status); 1429 p_acb->p_cback(BTA_HL_DCH_ECHO_TEST_CFM_EVT,(tBTA_HL *) &evt_data ); 1430 } 1431 else 1432 { 1433 APPL_TRACE_ERROR0("bta_hl_api_dch_echo_test Null Callback"); 1434 } 1435 break; 1436 1437 default: 1438 APPL_TRACE_ERROR1("Status code=%s", status); 1439 break; 1440 } 1441 } 1442 1443 1444 /******************************************************************************* 1445 ** 1446 ** Function bta_hl_api_sdp_query 1447 ** 1448 ** Description Process the API SDP query request 1449 ** 1450 ** Returns void 1451 ** 1452 *******************************************************************************/ 1453 static void bta_hl_api_sdp_query(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 1454 { 1455 tBTA_HL evt_data; 1456 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 1457 UINT8 app_idx, mcl_idx; 1458 tBTA_HL_APP_CB *p_acb; 1459 tBTA_HL_MCL_CB *p_mcb; 1460 1461 1462 if (bta_hl_find_app_idx_using_handle(p_data->api_sdp_query.app_handle, &app_idx)) 1463 { 1464 if (!bta_hl_find_mcl_idx(app_idx, p_data->api_sdp_query.bd_addr, &mcl_idx)) 1465 { 1466 if (bta_hl_find_avail_mcl_idx(app_idx, &mcl_idx)) 1467 { 1468 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 1469 p_mcb->in_use = TRUE; 1470 bdcpy(p_mcb->bd_addr, p_data->api_sdp_query.bd_addr); 1471 APPL_TRACE_DEBUG3("bta_hl_api_sdp_query p_mcb->app_id %d app_idx %d mcl_idx %d", p_mcb->app_id, app_idx, mcl_idx); 1472 p_mcb->app_id = p_data->api_sdp_query.app_id; 1473 p_mcb->sdp_oper = BTA_HL_SDP_OP_SDP_QUERY_NEW ; 1474 } 1475 else 1476 { 1477 status = BTA_HL_STATUS_NO_RESOURCE; 1478 } 1479 } 1480 else 1481 { 1482 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 1483 p_mcb->app_id = p_data->api_sdp_query.app_id; 1484 if (p_mcb->sdp_oper != BTA_HL_SDP_OP_NONE) 1485 { 1486 status = BTA_HL_STATUS_SDP_NO_RESOURCE; 1487 } 1488 else 1489 { 1490 p_mcb->sdp_oper = BTA_HL_SDP_OP_SDP_QUERY_CURRENT; 1491 } 1492 } 1493 } 1494 else 1495 { 1496 status = BTA_HL_STATUS_INVALID_APP_HANDLE; 1497 } 1498 1499 if (status == BTA_HL_STATUS_OK) 1500 { 1501 status = bta_hl_init_sdp( p_mcb->sdp_oper, app_idx, mcl_idx, 0xFF); 1502 if ( (status != BTA_HL_STATUS_OK) && 1503 (p_mcb->sdp_oper == BTA_HL_SDP_OP_SDP_QUERY_NEW) ) 1504 { 1505 memset(p_mcb, 0 ,sizeof(tBTA_HL_MCL_CB)); 1506 } 1507 } 1508 #if BTA_HL_DEBUG == TRUE 1509 if (status != BTA_HL_STATUS_OK) 1510 { 1511 APPL_TRACE_DEBUG1("bta_hl_api_sdp_query status=%s", bta_hl_status_code(status)); 1512 } 1513 #endif 1514 switch (status) 1515 { 1516 case BTA_HL_STATUS_NO_RESOURCE: 1517 case BTA_HL_STATUS_FAIL: 1518 case BTA_HL_STATUS_SDP_NO_RESOURCE: 1519 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 1520 if (p_acb->p_cback) 1521 { 1522 bta_hl_build_sdp_query_cfm(&evt_data, 1523 p_data->api_sdp_query.app_id, 1524 p_data->api_sdp_query.app_handle, 1525 p_data->api_sdp_query.bd_addr, 1526 NULL, 1527 status); 1528 p_acb->p_cback(BTA_HL_SDP_QUERY_CFM_EVT,(tBTA_HL *) &evt_data ); 1529 } 1530 else 1531 { 1532 APPL_TRACE_ERROR0("bta_hl_api_sdp_query Null Callback"); 1533 } 1534 break; 1535 case BTA_HL_STATUS_OK: 1536 break; 1537 default: 1538 APPL_TRACE_ERROR1("Status code=%d", status); 1539 break; 1540 } 1541 } 1542 1543 1544 1545 1546 /******************************************************************************* 1547 ** 1548 ** Function bta_hl_sdp_query_results 1549 ** 1550 ** Description Process the SDP query results 1551 ** 1552 ** Returns void 1553 ** 1554 *******************************************************************************/ 1555 static void bta_hl_sdp_query_results(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 1556 { 1557 tBTA_HL evt_data; 1558 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 1559 UINT8 app_idx = p_data->cch_sdp.app_idx; 1560 UINT8 mcl_idx = p_data->cch_sdp.mcl_idx; 1561 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR( app_idx); 1562 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR( app_idx, mcl_idx); 1563 tBTA_HL_SDP *p_sdp=NULL; 1564 tBTA_HL_SDP_OPER sdp_oper; 1565 UINT16 event; 1566 BOOLEAN release_sdp_buf=FALSE; 1567 1568 event = p_data->hdr.event; 1569 sdp_oper = p_mcb->sdp_oper; 1570 1571 if ( event == BTA_HL_SDP_QUERY_OK_EVT) 1572 { 1573 if ((p_sdp = (tBTA_HL_SDP *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_SDP)))) != NULL) 1574 { 1575 memcpy(p_sdp, &p_mcb->sdp, sizeof(tBTA_HL_SDP)); 1576 release_sdp_buf = TRUE; 1577 } 1578 else 1579 { 1580 status = BTA_HL_STATUS_SDP_NO_RESOURCE; 1581 } 1582 } 1583 else 1584 { 1585 status = BTA_HL_STATUS_SDP_FAIL; 1586 } 1587 1588 #if BTA_HL_DEBUG == TRUE 1589 if (status != BTA_HL_STATUS_OK) 1590 { 1591 APPL_TRACE_DEBUG1("bta_hl_sdp_query_results status=%s", bta_hl_status_code(status)); 1592 } 1593 #endif 1594 1595 APPL_TRACE_DEBUG3("bta_hl_sdp_query_results p_mcb->app_id %d app_idx %d mcl_idx %d", p_mcb->app_id, app_idx, mcl_idx); 1596 bta_hl_build_sdp_query_cfm(&evt_data,p_mcb->app_id, p_acb->app_handle, 1597 p_mcb->bd_addr,p_sdp,status); 1598 p_acb->p_cback(BTA_HL_SDP_QUERY_CFM_EVT,(tBTA_HL *) &evt_data ); 1599 1600 if (release_sdp_buf) 1601 { 1602 utl_freebuf((void **) &p_sdp); 1603 } 1604 1605 if (p_data->cch_sdp.release_mcl_cb) 1606 { 1607 memset(p_mcb, 0 ,sizeof(tBTA_HL_MCL_CB)); 1608 } 1609 else 1610 { 1611 if (p_mcb->close_pending) 1612 { 1613 bta_hl_check_cch_close(app_idx,mcl_idx,p_data, TRUE); 1614 } 1615 1616 if (!p_mcb->ctrl_psm) 1617 { 1618 /* this is a control channel acceptor do not store the sdp records*/ 1619 memset(&p_mcb->sdp, 0, sizeof(tBTA_HL_SDP)); 1620 } 1621 } 1622 } 1623 1624 1625 /******************************************************************************* 1626 ** 1627 ** Function bta_hl_api_delete_mdl 1628 ** 1629 ** Description Process the API DELETE MDL request 1630 ** 1631 ** Returns void 1632 ** 1633 *******************************************************************************/ 1634 static void bta_hl_api_delete_mdl(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 1635 { 1636 tBTA_HL evt_data; 1637 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 1638 UINT8 app_idx, mcl_idx; 1639 tBTA_HL_APP_CB *p_acb; 1640 tBTA_HL_MCL_CB *p_mcb; 1641 1642 if (bta_hl_find_mcl_idx_using_handle(p_data->api_delete_mdl.mcl_handle, &app_idx, &mcl_idx )) 1643 { 1644 if (bta_hl_is_mdl_value_valid(p_data->api_delete_mdl.mdl_id)) 1645 { 1646 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 1647 if (bta_hl_is_mdl_exsit_in_mcl(app_idx, 1648 p_mcb->bd_addr, 1649 p_data->api_delete_mdl.mdl_id)) 1650 { 1651 1652 1653 p_mcb->delete_mdl.mcl_handle = p_data->api_delete_mdl.mcl_handle; 1654 p_mcb->delete_mdl.mdl_id = p_data->api_delete_mdl.mdl_id; 1655 p_mcb->delete_mdl.delete_req_pending = TRUE; 1656 1657 if (MCA_Delete((tMCA_CL) p_mcb->mcl_handle, 1658 p_data->api_delete_mdl.mdl_id)!= MCA_SUCCESS) 1659 { 1660 status = BTA_HL_STATUS_FAIL; 1661 memset(&p_mcb->delete_mdl, 0, sizeof(tBTA_HL_DELETE_MDL)); 1662 } 1663 } 1664 else 1665 { 1666 status = BTA_HL_STATUS_NO_MDL_ID_FOUND; 1667 } 1668 } 1669 else 1670 { 1671 status = BTA_HL_STATUS_INVALID_MDL_ID; 1672 } 1673 } 1674 else 1675 { 1676 status = BTA_HL_STATUS_INVALID_MCL_HANDLE; 1677 } 1678 1679 #if BTA_HL_DEBUG == TRUE 1680 if (status != BTA_HL_STATUS_OK) 1681 { 1682 APPL_TRACE_DEBUG1("bta_hl_api_delete_mdl status=%s", bta_hl_status_code(status)); 1683 } 1684 #endif 1685 switch (status) 1686 { 1687 case BTA_HL_STATUS_OK: 1688 break; 1689 case BTA_HL_STATUS_FAIL: 1690 case BTA_HL_STATUS_NO_MDL_ID_FOUND: 1691 case BTA_HL_STATUS_INVALID_MDL_ID: 1692 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 1693 if (p_acb->p_cback) 1694 { 1695 bta_hl_build_delete_mdl_cfm(&evt_data, 1696 p_acb->app_handle, 1697 p_data->api_delete_mdl.mcl_handle, 1698 p_data->api_delete_mdl.mdl_id, 1699 status); 1700 p_acb->p_cback(BTA_HL_DELETE_MDL_CFM_EVT,(tBTA_HL *) &evt_data ); 1701 } 1702 else 1703 { 1704 APPL_TRACE_ERROR0("bta_hl_api_delete_mdl Null Callback"); 1705 } 1706 break; 1707 default: 1708 APPL_TRACE_ERROR1("status code =%d", status); 1709 break; 1710 } 1711 } 1712 1713 /******************************************************************************* 1714 ** 1715 ** Function bta_hl_mca_delete_mdl_cfm 1716 ** 1717 ** Description Process the DELETE MDL confirmation event 1718 ** 1719 ** Returns void 1720 ** 1721 *******************************************************************************/ 1722 static void bta_hl_mca_delete_mdl_cfm(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 1723 { 1724 tBTA_HL evt_data; 1725 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 1726 UINT8 app_idx, mcl_idx; 1727 tMCA_RSP_EVT *p_delete_cfm = &p_data->mca_evt.mca_data.delete_cfm; 1728 tBTA_HL_MCL_CB *p_mcb; 1729 BOOLEAN send_cfm_evt = TRUE; 1730 tBTA_HL_APP_CB *p_acb; 1731 1732 if (bta_hl_find_mcl_idx_using_handle(p_data->mca_evt.mcl_handle, &app_idx, &mcl_idx)) 1733 { 1734 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 1735 if ( p_mcb->delete_mdl.delete_req_pending) 1736 { 1737 if (p_delete_cfm->rsp_code == MCA_RSP_SUCCESS ) 1738 { 1739 1740 if (!bta_hl_delete_mdl_cfg(app_idx, 1741 p_mcb->bd_addr , 1742 p_delete_cfm->mdl_id)) 1743 { 1744 status = BTA_HL_STATUS_FAIL; 1745 } 1746 } 1747 else 1748 { 1749 status = BTA_HL_STATUS_FAIL; 1750 } 1751 1752 memset(&p_mcb->delete_mdl, 0, sizeof(tBTA_HL_DELETE_MDL)); 1753 } 1754 else 1755 { 1756 send_cfm_evt = FALSE; 1757 } 1758 } 1759 else 1760 { 1761 send_cfm_evt = FALSE; 1762 } 1763 1764 #if BTA_HL_DEBUG == TRUE 1765 if (status != BTA_HL_STATUS_OK) 1766 { 1767 APPL_TRACE_DEBUG1("bta_hl_api_delete_mdl status=%s", bta_hl_status_code(status)); 1768 } 1769 #endif 1770 1771 if (send_cfm_evt) 1772 { 1773 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 1774 if (p_acb->p_cback) 1775 { 1776 bta_hl_build_delete_mdl_cfm(&evt_data, 1777 p_acb->app_handle, 1778 p_mcb->mcl_handle, 1779 p_delete_cfm->mdl_id, 1780 status); 1781 1782 p_acb->p_cback(BTA_HL_DELETE_MDL_CFM_EVT,(tBTA_HL *) &evt_data ); 1783 } 1784 else 1785 { 1786 APPL_TRACE_ERROR0("bta_hl_mca_delete_mdl_cfm Null Callback"); 1787 1788 } 1789 } 1790 } 1791 1792 /******************************************************************************* 1793 ** 1794 ** Function bta_hl_mca_delete_mdl_ind 1795 ** 1796 ** Description Process the DELETE MDL indication event 1797 ** 1798 ** Returns void 1799 ** 1800 *******************************************************************************/ 1801 static void bta_hl_mca_delete_mdl_ind(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 1802 { 1803 tBTA_HL evt_data; 1804 UINT8 app_idx, mcl_idx, mdl_idx; 1805 tMCA_EVT_HDR *p_delete_ind = &p_data->mca_evt.mca_data.delete_ind; 1806 tBTA_HL_MCL_CB *p_mcb; 1807 tBTA_HL_MDL_CB *p_dcb; 1808 BOOLEAN send_ind_evt = TRUE; 1809 tBTA_HL_APP_CB *p_acb; 1810 1811 if (bta_hl_find_mcl_idx_using_handle(p_data->mca_evt.mcl_handle, &app_idx, &mcl_idx) ) 1812 { 1813 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 1814 1815 if (bta_hl_find_mdl_idx(app_idx, mcl_idx, p_delete_ind->mdl_id, &mdl_idx )) 1816 { 1817 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); 1818 p_dcb->dch_oper = BTA_HL_DCH_OP_REMOTE_DELETE; 1819 } 1820 if (bta_hl_delete_mdl_cfg(app_idx, 1821 p_mcb->bd_addr , 1822 p_delete_ind->mdl_id)) 1823 { 1824 send_ind_evt = TRUE; 1825 } 1826 } 1827 1828 #if BTA_HL_DEBUG == TRUE 1829 if (!send_ind_evt) 1830 { 1831 APPL_TRACE_DEBUG1("bta_hl_mca_delete_mdl_ind is_send_ind_evt =%d", send_ind_evt); 1832 } 1833 #endif 1834 1835 if (send_ind_evt) 1836 { 1837 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 1838 if (p_acb->p_cback) 1839 { 1840 evt_data.delete_mdl_ind.mcl_handle = p_mcb->mcl_handle; 1841 evt_data.delete_mdl_ind.app_handle = p_acb->app_handle; 1842 evt_data.delete_mdl_ind.mdl_id = p_delete_ind->mdl_id; 1843 p_acb->p_cback(BTA_HL_DELETE_MDL_IND_EVT,(tBTA_HL *) &evt_data ); 1844 } 1845 else 1846 { 1847 APPL_TRACE_ERROR0("bta_hl_mca_delete_mdl_ind Null Callback"); 1848 } 1849 } 1850 } 1851 1852 1853 1854 /******************************************************************************* 1855 ** 1856 ** Function bta_hl_api_dch_abort 1857 ** 1858 ** Description Process the API DCH abort request 1859 ** 1860 ** Returns void 1861 ** 1862 *******************************************************************************/ 1863 static void bta_hl_api_dch_abort(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data) 1864 { 1865 1866 tBTA_HL_STATUS status = BTA_HL_STATUS_OK; 1867 UINT8 app_idx, mcl_idx, mdl_idx; 1868 tBTA_HL_APP_CB *p_acb; 1869 tBTA_HL_MCL_CB *p_mcb; 1870 tBTA_HL_MDL_CB *p_dcb; 1871 tBTA_HL evt_data; 1872 1873 1874 if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_abort.mcl_handle, &app_idx, &mcl_idx )) 1875 { 1876 1877 if (!bta_hl_find_dch_setup_mdl_idx(app_idx, mcl_idx, &mdl_idx )) 1878 { 1879 status = BTA_HL_STATUS_NO_MDL_ID_FOUND; 1880 } 1881 else 1882 { 1883 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx); 1884 if (p_dcb->abort_oper) 1885 { 1886 /* abort already in progress*/ 1887 status = BTA_HL_STATUS_FAIL; 1888 } 1889 else 1890 { 1891 p_dcb->abort_oper = BTA_HL_ABORT_LOCAL_MASK; 1892 } 1893 } 1894 } 1895 else 1896 { 1897 status = BTA_HL_STATUS_INVALID_MCL_HANDLE; 1898 } 1899 1900 1901 #if BTA_HL_DEBUG == TRUE 1902 if (status != BTA_HL_STATUS_OK) 1903 { 1904 APPL_TRACE_DEBUG1("bta_hl_api_dch_abort status=%s", bta_hl_status_code(status)); 1905 } 1906 #endif 1907 switch (status) 1908 { 1909 case BTA_HL_STATUS_OK: 1910 1911 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ABORT_EVT, p_data); 1912 break; 1913 case BTA_HL_STATUS_NO_MDL_ID_FOUND: 1914 case BTA_HL_STATUS_FAIL: 1915 1916 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx); 1917 if (p_acb->p_cback) 1918 { 1919 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx); 1920 bta_hl_build_abort_cfm(&evt_data, 1921 1922 1923 1924 p_acb->app_handle, 1925 p_mcb->mcl_handle, 1926 BTA_HL_STATUS_FAIL); 1927 p_acb->p_cback(BTA_HL_DCH_ABORT_CFM_EVT,(tBTA_HL *) &evt_data); 1928 } 1929 else 1930 { 1931 APPL_TRACE_ERROR0("bta_hl_api_dch_abort Null Callback"); 1932 } 1933 break; 1934 default: 1935 APPL_TRACE_ERROR1("Status code=%d", status); 1936 break; 1937 } 1938 } 1939 1940 /******************************************************************************* 1941 ** 1942 ** Function bta_hl_hdl_event 1943 ** 1944 ** Description HL main event handling function. 1945 ** 1946 ** Returns void 1947 ** 1948 *******************************************************************************/ 1949 BOOLEAN bta_hl_hdl_event(BT_HDR *p_msg) 1950 { 1951 UINT8 app_idx, mcl_idx, mdl_idx; 1952 BOOLEAN success = TRUE; 1953 1954 #if BTA_HL_DEBUG == TRUE 1955 APPL_TRACE_DEBUG1("BTA HL Event Handler: Event [%s]", 1956 bta_hl_evt_code(p_msg->event)); 1957 #endif 1958 1959 switch (p_msg->event) 1960 { 1961 case BTA_HL_API_ENABLE_EVT: 1962 bta_hl_api_enable(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1963 break; 1964 case BTA_HL_API_DISABLE_EVT: 1965 bta_hl_api_disable(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1966 break; 1967 case BTA_HL_API_UPDATE_EVT: 1968 bta_hl_api_update(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1969 break; 1970 case BTA_HL_API_REGISTER_EVT: 1971 bta_hl_api_register(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1972 break; 1973 case BTA_HL_API_DEREGISTER_EVT: 1974 bta_hl_api_deregister(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1975 break; 1976 case BTA_HL_API_CCH_OPEN_EVT: 1977 bta_hl_api_cch_open(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1978 break; 1979 case BTA_HL_API_CCH_CLOSE_EVT: 1980 bta_hl_api_cch_close(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1981 break; 1982 case BTA_HL_API_DCH_OPEN_EVT: 1983 bta_hl_api_dch_open(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1984 break; 1985 case BTA_HL_API_DCH_CLOSE_EVT: 1986 bta_hl_api_dch_close(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1987 break; 1988 case BTA_HL_API_DELETE_MDL_EVT: 1989 bta_hl_api_delete_mdl(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1990 break; 1991 case BTA_HL_API_DCH_RECONNECT_EVT: 1992 bta_hl_api_dch_reconnect(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1993 break; 1994 1995 case BTA_HL_API_DCH_ECHO_TEST_EVT: 1996 bta_hl_api_dch_echo_test(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 1997 break; 1998 1999 case BTA_HL_API_SDP_QUERY_EVT: 2000 bta_hl_api_sdp_query(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 2001 break; 2002 2003 case BTA_HL_MCA_DELETE_CFM_EVT: 2004 bta_hl_mca_delete_mdl_cfm(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 2005 break; 2006 2007 case BTA_HL_MCA_DELETE_IND_EVT: 2008 bta_hl_mca_delete_mdl_ind(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 2009 break; 2010 2011 case BTA_HL_SDP_QUERY_OK_EVT: 2012 case BTA_HL_SDP_QUERY_FAIL_EVT: 2013 bta_hl_sdp_query_results(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 2014 break; 2015 case BTA_HL_API_DCH_ABORT_EVT: 2016 bta_hl_api_dch_abort(&bta_hl_cb, (tBTA_HL_DATA *) p_msg); 2017 break; 2018 2019 2020 default: 2021 if (p_msg->event < BTA_HL_DCH_EVT_MIN) 2022 { 2023 if (bta_hl_find_cch_cb_indexes((tBTA_HL_DATA *) p_msg, &app_idx, &mcl_idx)) 2024 { 2025 bta_hl_cch_sm_execute( app_idx, 2026 mcl_idx, 2027 p_msg->event, (tBTA_HL_DATA *) p_msg); 2028 } 2029 else 2030 { 2031 #if BTA_HL_DEBUG == TRUE 2032 APPL_TRACE_ERROR1("unable to find control block indexes for CCH: [event=%s]", 2033 bta_hl_evt_code(p_msg->event)); 2034 #else 2035 APPL_TRACE_ERROR1("unable to find control block indexes for CCH: [event=%d]", p_msg->event); 2036 #endif 2037 success = FALSE; 2038 } 2039 } 2040 else 2041 { 2042 if (bta_hl_find_dch_cb_indexes((tBTA_HL_DATA *) p_msg, &app_idx, &mcl_idx, &mdl_idx)) 2043 { 2044 bta_hl_dch_sm_execute( app_idx, 2045 mcl_idx, 2046 mdl_idx, 2047 p_msg->event, (tBTA_HL_DATA *) p_msg); 2048 } 2049 else 2050 { 2051 2052 #if BTA_HL_DEBUG == TRUE 2053 APPL_TRACE_ERROR1("unable to find control block indexes for DCH : [event=%s]", 2054 bta_hl_evt_code(p_msg->event)); 2055 #else 2056 APPL_TRACE_ERROR1("unable to find control block indexes for DCH: [event=%d]", p_msg->event); 2057 #endif 2058 success = FALSE; 2059 } 2060 } 2061 2062 break; 2063 } 2064 2065 return(success); 2066 } 2067 2068 2069 /***************************************************************************** 2070 ** Debug Functions 2071 *****************************************************************************/ 2072 #if (BTA_HL_DEBUG == TRUE) && (BT_USE_TRACES == TRUE) 2073 2074 /******************************************************************************* 2075 ** 2076 ** Function bta_hl_cch_state_code 2077 ** 2078 ** Description Map CCH state code to the corresponding state string 2079 ** 2080 ** Returns string pointer for the associated state name 2081 ** 2082 *******************************************************************************/ 2083 static char *bta_hl_cch_state_code(tBTA_HL_CCH_STATE state_code) 2084 { 2085 switch (state_code) 2086 { 2087 case BTA_HL_CCH_IDLE_ST: 2088 return "BTA_HL_CCH_IDLE_ST"; 2089 case BTA_HL_CCH_OPENING_ST: 2090 return "BTA_HL_CCH_OPENING_ST"; 2091 case BTA_HL_CCH_OPEN_ST: 2092 return "BTA_HL_CCH_OPEN_ST"; 2093 case BTA_HL_CCH_CLOSING_ST: 2094 return "BTA_HL_CCH_CLOSING_ST"; 2095 default: 2096 return "Unknown CCH state code"; 2097 } 2098 } 2099 2100 /******************************************************************************* 2101 ** 2102 ** Function bta_hl_dch_state_code 2103 ** 2104 ** Description Map DCH state code to the corresponding state string 2105 ** 2106 ** Returns string pointer for the associated state name 2107 ** 2108 *******************************************************************************/ 2109 static char *bta_hl_dch_state_code(tBTA_HL_DCH_STATE state_code) 2110 { 2111 switch (state_code) 2112 { 2113 case BTA_HL_DCH_IDLE_ST: 2114 return "BTA_HL_DCH_IDLE_ST"; 2115 case BTA_HL_DCH_OPENING_ST: 2116 return "BTA_HL_DCH_OPENING_ST"; 2117 case BTA_HL_DCH_OPEN_ST: 2118 return "BTA_HL_DCH_OPEN_ST"; 2119 case BTA_HL_DCH_CLOSING_ST: 2120 return "BTA_HL_DCH_CLOSING_ST"; 2121 default: 2122 return "Unknown DCH state code"; 2123 } 2124 } 2125 #endif /* Debug Functions */ 2126 #endif /* HL_INCLUDED */ 2127