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