blob: cdf13b681134ad27e04f7ee9507e5359b797d50f [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 2009-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 * Filename: btif_hl.c
22 *
23 * Description: Health Device Profile Bluetooth Interface
24 *
25 *
26 ***********************************************************************************/
27#define LOG_TAG "BTIF_HL"
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <errno.h>
32#include <string.h>
33#include <sys/types.h>
34#include <sys/socket.h>
35#include <sys/un.h>
36#include <time.h>
37#include <fcntl.h>
38#include <unistd.h>
39#include <pthread.h>
40#include <signal.h>
41#include <ctype.h>
42#include <sys/select.h>
43#include <sys/poll.h>
44#include <cutils/sockets.h>
45#include <cutils/log.h>
46
47#include <hardware/bluetooth.h>
48#include <hardware/bt_hl.h>
49
50#include "btif_common.h"
51#include "btif_util.h"
52#include "gki.h"
53#include "bd.h"
54#include "bta_api.h"
55#include "bta_hl_api.h"
56#include "mca_api.h"
57#include "btif_hl.h"
58#include "btif_storage.h"
59#include "btu.h"
60
Priti Agheraf8f30c22013-04-02 15:31:19 -070061#define MAX_DATATYPE_SUPPORTED 8
62
The Android Open Source Project5738f832012-12-12 16:00:35 -080063extern int btif_hl_update_maxfd( int max_org_s);
64extern void btif_hl_select_monitor_callback( fd_set *p_cur_set, fd_set *p_org_set );
65extern void btif_hl_select_wakeup_callback( fd_set *p_org_set , int wakeup_signal );
66extern int btif_hl_update_maxfd( int max_org_s);
67extern void btif_hl_select_monitor_callback( fd_set *p_cur_set, fd_set *p_org_set );
68extern void btif_hl_select_wakeup_callback( fd_set *p_org_set , int wakeup_signal );
69extern void btif_hl_soc_thread_init(void);
70extern void btif_hl_release_mcl_sockets(UINT8 app_idx, UINT8 mcl_idx);
71extern BOOLEAN btif_hl_create_socket(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx);
72extern void btif_hl_release_socket(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx);
73
74btif_hl_cb_t btif_hl_cb;
75btif_hl_cb_t *p_btif_hl_cb = &btif_hl_cb;
Priti Agheraf8f30c22013-04-02 15:31:19 -070076
The Android Open Source Project5738f832012-12-12 16:00:35 -080077/************************************************************************************
78** Static variables
79************************************************************************************/
80static bthl_callbacks_t bt_hl_callbacks_cb;
81static bthl_callbacks_t *bt_hl_callbacks=NULL;
82
83/* signal socketpair to wake up select loop */
84
85const int btif_hl_signal_select_wakeup = 1;
86const int btif_hl_signal_select_exit = 2;
87const int btif_hl_signal_select_close_connected = 3;
88
89static int listen_s = -1;
90static int connected_s = -1;
91static int select_thread_id = -1;
92static int signal_fds[2];
93static BUFFER_Q soc_queue;
Priti Agheraf8f30c22013-04-02 15:31:19 -070094static int reg_counter;
The Android Open Source Project5738f832012-12-12 16:00:35 -080095
96static inline int btif_hl_select_wakeup(void);
97static inline int btif_hl_select_exit(void);
98static inline int btif_hl_select_close_connected(void);
99static inline int btif_hl_close_select_thread(void);
100static UINT8 btif_hl_get_next_app_id(void);
101static int btif_hl_get_next_channel_id(UINT8 app_id);
102static void btif_hl_init_next_app_id(void);
103static void btif_hl_init_next_channel_id(void);
104static void btif_hl_ctrl_cback(tBTA_HL_CTRL_EVT event, tBTA_HL_CTRL *p_data);
105static void btif_hl_set_state(btif_hl_state_t state);
106static btif_hl_state_t btif_hl_get_state(void);
107static void btif_hl_cback(tBTA_HL_EVT event, tBTA_HL *p_data);
108static void btif_hl_proc_cb_evt(UINT16 event, char* p_param);
109
110#define CHECK_CALL_CBACK(P_CB, P_CBACK, ...)\
111 if (P_CB && P_CB->P_CBACK) { \
112 P_CB->P_CBACK(__VA_ARGS__); \
113 } \
114 else { \
115 ASSERTC(0, "Callback is NULL", 0); \
116 }
117
118
119#define BTIF_HL_CALL_CBACK(P_CB, P_CBACK, ...)\
120 if((p_btif_hl_cb->state != BTIF_HL_STATE_DISABLING) &&\
121 (p_btif_hl_cb->state != BTIF_HL_STATE_DISABLED)) \
122 { \
123 if (P_CB && P_CB->P_CBACK) { \
124 P_CB->P_CBACK(__VA_ARGS__); \
125 } \
126 else { \
127 ASSERTC(0, "Callback is NULL", 0); \
128 } \
129 }
130
131
132#define CHECK_BTHL_INIT() if (bt_hl_callbacks == NULL)\
133 {\
134 BTIF_TRACE_WARNING1("BTHL: %s: BTHL not initialized", __FUNCTION__);\
135 return BT_STATUS_NOT_READY;\
136 }\
137 else\
138 {\
139 BTIF_TRACE_EVENT1("BTHL: %s", __FUNCTION__);\
140 }
141
142
143static const btif_hl_data_type_cfg_t data_type_table[] = {
144 /* Data Specilization Ntx Nrx (from Bluetooth SIG's HDP whitepaper)*/
145 {BTIF_HL_DATA_TYPE_PULSE_OXIMETER, 9216, 256},
146 {BTIF_HL_DATA_TYPE_BLOOD_PRESSURE_MON, 896, 224},
147 {BTIF_HL_DATA_TYPE_BODY_THERMOMETER, 896, 224},
148 {BTIF_HL_DATA_TYPE_BODY_WEIGHT_SCALE, 896, 224},
149 {BTIF_HL_DATA_TYPE_GLUCOSE_METER, 896, 224},
Priti Agherac8a9f432013-05-22 13:25:58 -0700150 {BTIF_HL_DATA_TYPE_STEP_COUNTER, 6624, 224},
151 {BTIF_HL_DATA_TYPE_BCA, 7730, 1230},
152 {BTIF_HL_DATA_TYPE_PEAK_FLOW , 2030, 224},
153 {BTIF_HL_DATA_TYPE_ACTIVITY_HUB, 5120, 224},
154 {BTIF_HL_DATA_TYPE_AMM, 1024, 64}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800155};
156
157#define BTIF_HL_DATA_TABLE_SIZE (sizeof(data_type_table) / sizeof(btif_hl_data_type_cfg_t))
158#define BTIF_HL_DEFAULT_SRC_TX_APDU_SIZE 10240 /* use this size if the data type is not
159 defined in the table; for future proof */
160#define BTIF_HL_DEFAULT_SRC_RX_APDU_SIZE 512 /* use this size if the data type is not
161 defined in the table; for future proof */
162
163#define BTIF_HL_ECHO_MAX_TX_RX_APDU_SIZE 1024
164
165/************************************************************************************
166** Static utility functions
167************************************************************************************/
168
169#define BTIF_IF_GET_NAME 16
170void btif_hl_display_calling_process_name(void)
171{
172 char name[16];
173 prctl(BTIF_IF_GET_NAME, name, 0, 0, 0);
174 BTIF_TRACE_DEBUG1("Process name (%s)", name);
175}
Priti Agheraf8f30c22013-04-02 15:31:19 -0700176#define BTIF_TIMEOUT_CCH_NO_DCH_SECS 30
The Android Open Source Project5738f832012-12-12 16:00:35 -0800177/*******************************************************************************
178**
179** Function btif_hl_if_channel_setup_pending
180**
181** Description check whether channel id is in setup pending state or not
182**
183** Returns BOOLEAN
184**
185*******************************************************************************/
186BOOLEAN btif_hl_if_channel_setup_pending(int channel_id, UINT8 *p_app_idx, UINT8 *p_mcl_idx)
187{
188 btif_hl_app_cb_t *p_acb;
189 btif_hl_mcl_cb_t *p_mcb;
190 UINT8 i, j;
191 BOOLEAN found=FALSE;
192 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
193 {
194 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
195 if (p_acb->in_use)
196 {
197 for (j=0; j< BTA_HL_NUM_MCLS; j++)
198 {
199 p_mcb = BTIF_HL_GET_MCL_CB_PTR(i, j);
200 if (p_mcb->in_use &&
201 p_mcb->is_connected && p_mcb->pcb.channel_id == channel_id )
202 {
203 found = TRUE;
204 *p_app_idx = i;
205 *p_mcl_idx = j;
206 break;
207 }
208 }
209 }
210 if (found)
211 break;
212 }
213 BTIF_TRACE_DEBUG5("%s found=%d channel_id=0x%08x",
214 __FUNCTION__, found, channel_id, *p_app_idx, *p_mcl_idx);
215 return found;
216
217}
218/*******************************************************************************
219**
220** Function btif_hl_num_dchs_in_use
221**
222** Description find number of DCHs in use
223**
224** Returns UINT8
225*******************************************************************************/
Priti Agheraf8f30c22013-04-02 15:31:19 -0700226UINT8 btif_hl_num_dchs_in_use(UINT8 mcl_handle){
The Android Open Source Project5738f832012-12-12 16:00:35 -0800227
Priti Agheraf8f30c22013-04-02 15:31:19 -0700228 btif_hl_app_cb_t * p_acb;
229 btif_hl_mcl_cb_t *p_mcb;
230 UINT8 i,j,x;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800231 UINT8 cnt=0;
232
Priti Agheraf8f30c22013-04-02 15:31:19 -0700233 for (i=0; i<BTA_HL_NUM_APPS; i++)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800234 {
Priti Agheraf8f30c22013-04-02 15:31:19 -0700235 BTIF_TRACE_DEBUG1("btif_hl_num_dchs:i = %d",i);
236 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
237 if (p_acb && p_acb->in_use)
238 {
239 for (j=0; j < BTA_HL_NUM_MCLS ; j++)
240 {
241 if(p_acb->mcb[j].in_use)
242 BTIF_TRACE_DEBUG3("btif_hl_num_dchs:mcb in use j=%d, mcl_handle=%d,mcb handle=%d",
243 j,mcl_handle, p_acb->mcb[j].mcl_handle);
244 if (p_acb->mcb[j].in_use &&
245 (p_acb->mcb[j].mcl_handle == mcl_handle))
246 {
247 p_mcb = &p_acb->mcb[j];
248 BTIF_TRACE_DEBUG1("btif_hl_num_dchs: mcl handle found j =%d",j);
249 for (x=0; x < BTA_HL_NUM_MDLS_PER_MCL ; x ++)
250 {
251 if (p_mcb->mdl[x].in_use)
252 {
253 BTIF_TRACE_DEBUG1("btif_hl_num_dchs_in_use:found x =%d",x);
254 cnt++;
255 }
256 }
257 }
258 }
259 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800260 }
Priti Agheraf8f30c22013-04-02 15:31:19 -0700261
The Android Open Source Project5738f832012-12-12 16:00:35 -0800262 BTIF_TRACE_DEBUG2("%s dch in use count=%d", __FUNCTION__, cnt);
263 return cnt;
264}
265/*******************************************************************************
266**
267** Function btif_hl_tmr_hdlr
268**
269** Description Process timer timeout
270**
271** Returns void
272*******************************************************************************/
273void btif_hl_tmr_hdlr(TIMER_LIST_ENT *tle)
274{
275 btif_hl_mcl_cb_t *p_mcb;
276 UINT8 i,j;
277 BTIF_TRACE_DEBUG2("%s timer_in_use=%d", __FUNCTION__, tle->in_use );
278
279 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
280 {
281 for (j=0; j< BTA_HL_NUM_MCLS; j++)
282 {
283 p_mcb =BTIF_HL_GET_MCL_CB_PTR(i,j);
284
285 if (p_mcb->cch_timer_active)
286 {
287 BTIF_TRACE_DEBUG3("%app_idx=%d, mcl_idx=%d mcl-connected=%d",
288 i, j, p_mcb->is_connected);
289 p_mcb->cch_timer_active = FALSE;
290 if (p_mcb->is_connected)
291 {
292 BTIF_TRACE_DEBUG3("Idle timeout Close CCH app_idx=%d mcl_idx=%d mcl_handle=%d",
293 i ,j, p_mcb->mcl_handle);
294 BTA_HlCchClose(p_mcb->mcl_handle);
295 }
296 else
297 {
298 BTIF_TRACE_DEBUG2("CCH idle timeout But CCH not connected app_idx=%d mcl_idx=%d ",i,j);
299 }
300 }
301 }
302 }
303}
304/*******************************************************************************
305**
306** Function btif_hl_stop_cch_timer
307**
308** Description stop CCH timer
309**
310** Returns void
311*******************************************************************************/
312void btif_hl_stop_cch_timer(UINT8 app_idx, UINT8 mcl_idx)
313{
314 btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
315 BTIF_TRACE_DEBUG4("%s app_idx=%d, mcl_idx=%d timer_in_use=%d",
316 __FUNCTION__,app_idx, mcl_idx, p_mcb->cch_timer.in_use);
317
318 p_mcb->cch_timer_active = FALSE;
319 if (p_mcb->cch_timer.in_use)
320 {
321 BTIF_TRACE_DEBUG0("stop CCH timer ");
322 btu_stop_timer(&p_mcb->cch_timer);
323 }
324}
325/*******************************************************************************
326**
327** Function btif_hl_start_cch_timer
328**
329** Description start CCH timer
330**
331** Returns void
332*******************************************************************************/
333void btif_hl_start_cch_timer(UINT8 app_idx, UINT8 mcl_idx)
334{
335 btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
336 BTIF_TRACE_DEBUG5("%s app_idx=%d, mcl_idx=%d timer_active=%d timer_in_use=%d",
337 __FUNCTION__,app_idx, mcl_idx,
338 p_mcb->cch_timer_active, p_mcb->cch_timer.in_use);
339
340 p_mcb->cch_timer_active = TRUE;
341 if (!p_mcb->cch_timer.in_use)
342 {
343 BTIF_TRACE_DEBUG0("Start CCH timer ");
344 memset(&p_mcb->cch_timer, 0, sizeof(TIMER_LIST_ENT));
345 p_mcb->cch_timer.param = (UINT32)btif_hl_tmr_hdlr;
346 btu_start_timer(&p_mcb->cch_timer, BTU_TTYPE_USER_FUNC,
347 BTIF_TIMEOUT_CCH_NO_DCH_SECS);
348 }
349 else
350 {
351 BTIF_TRACE_DEBUG0("Restart CCH timer ");
352 btu_stop_timer(&p_mcb->cch_timer);
353 btu_start_timer(&p_mcb->cch_timer, BTU_TTYPE_USER_FUNC,
354 BTIF_TIMEOUT_CCH_NO_DCH_SECS);
355 }
356
357}
358/*******************************************************************************
359**
360** Function btif_hl_find_mdl_idx
361**
362** Description Find the MDL index using MDL ID
363**
364** Returns BOOLEAN
365**
366*******************************************************************************/
367static BOOLEAN btif_hl_find_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, UINT16 mdl_id,
368 UINT8 *p_mdl_idx)
369{
370 btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
371 BOOLEAN found=FALSE;
372 UINT8 i;
373
374 for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++)
375 {
376 if (p_mcb->mdl[i].in_use &&
377 (mdl_id !=0) &&
378 (p_mcb->mdl[i].mdl_id== mdl_id))
379 {
380 found = TRUE;
381 *p_mdl_idx = i;
382 break;
383 }
384 }
385
386 BTIF_TRACE_DEBUG4("%s found=%d mdl_id=%d mdl_idx=%d ",
387 __FUNCTION__,found, mdl_id, i);
388
389 return found;
390}
391
392/*******************************************************************************
393**
394** Function btif_hl_get_buf
395**
396** Description get buffer
397**
398** Returns void
399**
400*******************************************************************************/
401void * btif_hl_get_buf(UINT16 size)
402{
403 void *p_new;
404
405 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
406 BTIF_TRACE_DEBUG2("ret size=%d GKI_MAX_BUF_SIZE=%d",size, 6000);
407
408 if (size < 6000)
409 {
410 p_new = GKI_getbuf(size);
411 }
412 else
413 {
414 BTIF_TRACE_DEBUG0("btif_hl_get_buf use HL large data pool");
415 p_new = GKI_getpoolbuf(4);
416 }
417
418 return p_new;
419}
420/*******************************************************************************
421**
422** Function btif_hl_free_buf
423**
424** Description free buffer
425**
426** Return void
427**
428*******************************************************************************/
429void btif_hl_free_buf(void **p)
430{
431 if (*p != NULL)
432 {
433 BTIF_TRACE_DEBUG1("%s OK", __FUNCTION__ );
434 GKI_freebuf(*p);
435 *p = NULL;
436 }
437 else
438 BTIF_TRACE_ERROR1("%s NULL pointer",__FUNCTION__ );
439}
440/*******************************************************************************
441**
442** Function btif_hl_is_the_first_reliable_existed
443**
444** Description This function checks whether the first reliable DCH channel
445** has been setup on the MCL or not
446**
447** Returns BOOLEAN - TRUE exist
448** FALSE does not exist
449**
450*******************************************************************************/
451BOOLEAN btif_hl_is_the_first_reliable_existed(UINT8 app_idx, UINT8 mcl_idx )
452{
453 btif_hl_mcl_cb_t *p_mcb =BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
454 BOOLEAN is_existed =FALSE;
455 UINT8 i ;
456
457 for (i=0; i< BTA_HL_NUM_MDLS_PER_MCL; i++)
458 {
459 if (p_mcb->mdl[i].in_use && p_mcb->mdl[i].is_the_first_reliable)
460 {
461 is_existed = TRUE;
462 break;
463 }
464 }
465
466 BTIF_TRACE_DEBUG1("bta_hl_is_the_first_reliable_existed is_existed=%d ",is_existed );
467 return is_existed;
468}
469/*******************************************************************************
470**
471** Function btif_hl_clean_delete_mdl
472**
473** Description Cleanup the delete mdl control block
474**
475** Returns Nothing
476**
477*******************************************************************************/
478static void btif_hl_clean_delete_mdl(btif_hl_delete_mdl_t *p_cb)
479{
480 BTIF_TRACE_DEBUG1("%s", __FUNCTION__ );
481 memset(p_cb, 0 , sizeof(btif_hl_delete_mdl_t));
482}
483
484/*******************************************************************************
485**
486** Function btif_hl_clean_pcb
487**
488** Description Cleanup the pending chan control block
489**
490** Returns Nothing
491**
492*******************************************************************************/
493static void btif_hl_clean_pcb(btif_hl_pending_chan_cb_t *p_pcb)
494{
495 BTIF_TRACE_DEBUG1("%s", __FUNCTION__ );
496 memset(p_pcb, 0 , sizeof(btif_hl_pending_chan_cb_t));
497}
498
499
500/*******************************************************************************
501**
502** Function btif_hl_clean_mdl_cb
503**
504** Description Cleanup the MDL control block
505**
506** Returns Nothing
507**
508*******************************************************************************/
509static void btif_hl_clean_mdl_cb(btif_hl_mdl_cb_t *p_dcb)
510{
511 BTIF_TRACE_DEBUG1("%s", __FUNCTION__ );
512 btif_hl_free_buf((void **) &p_dcb->p_rx_pkt);
513 btif_hl_free_buf((void **) &p_dcb->p_tx_pkt);
514 memset(p_dcb, 0 , sizeof(btif_hl_mdl_cb_t));
515}
516
517
518/*******************************************************************************
519**
520** Function btif_hl_reset_mcb
521**
522** Description Reset MCL control block
523**
524** Returns BOOLEAN
525**
526*******************************************************************************/
527static void btif_hl_clean_mcl_cb(UINT8 app_idx, UINT8 mcl_idx)
528{
529 btif_hl_mcl_cb_t *p_mcb;
530 BTIF_TRACE_DEBUG3("%s app_idx=%d, mcl_idx=%d", __FUNCTION__,app_idx, mcl_idx);
531 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
532 memset(p_mcb, 0, sizeof(btif_hl_mcl_cb_t));
533}
534
535
536/*******************************************************************************
537**
538** Function btif_hl_find_sdp_idx_using_mdep_filter
539**
540** Description This function finds the SDP record index using MDEP filter parameters
541**
542** Returns BOOLEAN
543**
544*******************************************************************************/
545static void btif_hl_reset_mdep_filter(UINT8 app_idx)
546{
547 btif_hl_app_cb_t *p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx);
548 p_acb->filter.num_elems = 0;
549}
550
551/*******************************************************************************
552**
553** Function btif_hl_find_sdp_idx_using_mdep_filter
554**
555** Description This function finds the SDP record index using MDEP filter parameters
556**
557** Returns BOOLEAN
558**
559*******************************************************************************/
560static BOOLEAN btif_hl_find_sdp_idx_using_mdep_filter(UINT8 app_idx, UINT8 mcl_idx, UINT8 *p_sdp_idx)
561{
562 btif_hl_app_cb_t *p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx);
563 btif_hl_mcl_cb_t *p_mcb =BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
564 UINT8 i, j, num_recs,num_elems, num_mdeps, mdep_cnt, mdep_idx;
565 tBTA_HL_MDEP_ROLE peer_mdep_role;
566 UINT16 data_type;
567 tBTA_HL_SDP_MDEP_CFG *p_mdep;
568 BOOLEAN found = FALSE;
569 BOOLEAN elem_found;
570
Priti Agheraf8f30c22013-04-02 15:31:19 -0700571 BTIF_TRACE_DEBUG0("btif_hl_find_sdp_idx_using_mdep_filter");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800572 num_recs = p_mcb->sdp.num_recs;
573 num_elems = p_acb->filter.num_elems;
574 if (!num_elems)
575 {
Priti Agheraf8f30c22013-04-02 15:31:19 -0700576 BTIF_TRACE_DEBUG0("btif_hl_find_sdp_idx_using_mdep_filter num_elem=0");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800577 *p_sdp_idx = 0;
578 found = TRUE;
579 return found;
580 }
581
582 for (i=0; i<num_recs; i++)
583 {
584 num_mdeps = p_mcb->sdp.sdp_rec[i].num_mdeps;
585 for (j=0; j<num_elems; j++ )
586 {
587 data_type = p_acb->filter.elem[j].data_type;
588 peer_mdep_role = p_acb->filter.elem[j].peer_mdep_role;
589 elem_found = FALSE;
590 mdep_cnt =0;
591 mdep_idx=0;
592 while (!elem_found && mdep_idx < num_mdeps )
593 {
594 p_mdep = &(p_mcb->sdp.sdp_rec[i].mdep_cfg[mdep_idx]);
595 if ( (p_mdep->data_type == data_type) &&
596 (p_mdep->mdep_role == peer_mdep_role) )
597 {
598 elem_found = TRUE;
599 }
600 else
601 {
602 mdep_idx++;
603 }
604 }
605
606 if (!elem_found)
607 {
608 found = FALSE;
609 break;
610 }
611 else
612 {
613 found = TRUE;
614 }
615 }
616
617 if (found)
618 {
Priti Agheraf8f30c22013-04-02 15:31:19 -0700619 BTIF_TRACE_DEBUG1("btif_hl_find_sdp_idx_using_mdep_filter found idx=%d",i);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800620 *p_sdp_idx = i;
621 break;
622 }
623 }
624
625 BTIF_TRACE_DEBUG3("%s found=%d sdp_idx=%d",__FUNCTION__ , found, *p_sdp_idx);
626
627 btif_hl_reset_mdep_filter(app_idx);
628
629 return found;
630}
631/*******************************************************************************
632**
633** Function btif_hl_is_reconnect_possible
634**
635** Description check reconnect is possible or not
636**
637** Returns BOOLEAN
638**
639*******************************************************************************/
640BOOLEAN btif_hl_is_reconnect_possible(UINT8 app_idx, UINT8 mcl_idx, int mdep_cfg_idx,
641 tBTA_HL_DCH_OPEN_PARAM *p_dch_open_api, tBTA_HL_MDL_ID *p_mdl_id)
642{
643 btif_hl_app_cb_t *p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
644 btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
645 tBTA_HL_DCH_CFG local_cfg = p_dch_open_api->local_cfg;
646 tBTA_HL_DCH_MODE dch_mode = BTA_HL_DCH_MODE_RELIABLE;
647 BOOLEAN use_mdl_dch_mode=FALSE;
648 btif_hl_mdl_cfg_t *p_mdl;
649 btif_hl_mdl_cfg_t *p_mdl1;
650 UINT8 i, j;
651 BOOLEAN is_reconnect_ok=FALSE;
652 BOOLEAN stream_mode_avail=FALSE;
653 UINT16 data_type = p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.data_cfg[0].data_type;
654 tBTA_HL_MDEP_ID peer_mdep_id = p_dch_open_api->peer_mdep_id;
655 UINT8 mdl_idx;
656
657
658 BTIF_TRACE_DEBUG4("%s app_idx=%d mcl_idx=%d mdep_cfg_idx=%d",
659 __FUNCTION__, app_idx, mcl_idx, mdep_cfg_idx );
660 switch (local_cfg)
661 {
662 case BTA_HL_DCH_CFG_NO_PREF:
663 if (!btif_hl_is_the_first_reliable_existed(app_idx, mcl_idx))
664 {
665 dch_mode = BTA_HL_DCH_MODE_RELIABLE;
666 }
667 else
668 {
669 use_mdl_dch_mode = TRUE;
670 }
671 break;
672 case BTA_HL_DCH_CFG_RELIABLE:
673 dch_mode = BTA_HL_DCH_MODE_RELIABLE;
674 break;
675 case BTA_HL_DCH_CFG_STREAMING:
676 dch_mode = BTA_HL_DCH_MODE_STREAMING;
677 break;
678 default:
679 BTIF_TRACE_ERROR1("Invalid local_cfg=%d",local_cfg );
680 return is_reconnect_ok;
681 break;
682
683 }
684
685 BTIF_TRACE_DEBUG3("local_cfg=%d use_mdl_dch_mode=%d dch_mode=%d ",
686 local_cfg, use_mdl_dch_mode, dch_mode );
687
688 for (i=0, p_mdl=&p_acb->mdl_cfg[0] ; i< BTA_HL_NUM_MDL_CFGS; i++, p_mdl++ )
689 {
690 if (p_mdl->base.active &&
691 p_mdl->extra.data_type ==data_type &&
692 (p_mdl->extra.peer_mdep_id != BTA_HL_INVALID_MDEP_ID && p_mdl->extra.peer_mdep_id == peer_mdep_id) &&
693 memcpy(p_mdl->base.peer_bd_addr, p_mcb->bd_addr,sizeof(BD_ADDR) ) &&
694 p_mdl->base.mdl_id &&
695 !btif_hl_find_mdl_idx(app_idx, mcl_idx,p_mdl->base.mdl_id, &mdl_idx))
696 {
Priti Agheraf8f30c22013-04-02 15:31:19 -0700697 BTIF_TRACE_DEBUG4("i=%d Matched active=%d mdl_id =%d, mdl_dch_mode=%d",
698 i, p_mdl->base.active, p_mdl->base.mdl_id,p_mdl->base.dch_mode);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800699 if (!use_mdl_dch_mode)
700 {
701 if (p_mdl->base.dch_mode == dch_mode)
702 {
703 is_reconnect_ok = TRUE;
704 *p_mdl_id = p_mdl->base.mdl_id;
705 BTIF_TRACE_DEBUG2("reconnect is possible dch_mode=%d mdl_id=%d", dch_mode, p_mdl->base.mdl_id );
706 break;
707 }
708 }
709 else
710 {
711 is_reconnect_ok = TRUE;
712 for (j=i, p_mdl1=&p_acb->mdl_cfg[i]; j< BTA_HL_NUM_MDL_CFGS; j++, p_mdl1++)
713 {
714 if (p_mdl1->base.active &&
715 p_mdl1->extra.data_type == data_type &&
716 (p_mdl1->extra.peer_mdep_id != BTA_HL_INVALID_MDEP_ID && p_mdl1->extra.peer_mdep_id == peer_mdep_id) &&
717 memcpy(p_mdl1->base.peer_bd_addr, p_mcb->bd_addr,sizeof(BD_ADDR)) &&
718 p_mdl1->base.dch_mode == BTA_HL_DCH_MODE_STREAMING)
719 {
720 stream_mode_avail = TRUE;
721 BTIF_TRACE_DEBUG1("found streaming mode mdl index=%d", j);
722 break;
723 }
724 }
725
726 if (stream_mode_avail)
727 {
728 dch_mode = BTA_HL_DCH_MODE_STREAMING;
729 *p_mdl_id = p_mdl1->base.mdl_id;
730 BTIF_TRACE_DEBUG2("reconnect is ok index=%d dch_mode=streaming mdl_id=%d", j, *p_mdl_id);
731 break;
732 }
733 else
734 {
735 dch_mode= p_mdl->base.dch_mode;
736 *p_mdl_id = p_mdl->base.mdl_id;
737 BTIF_TRACE_DEBUG3("reconnect is ok index=%d dch_mode=%d mdl_id=%d", i, p_mdl->base.dch_mode, *p_mdl_id);
738 break;
739
740 }
741 }
742
743 }
744
745 }
746
747 BTIF_TRACE_DEBUG3("is_reconnect_ok dch_mode=%d mdl_id=%d",is_reconnect_ok, dch_mode, *p_mdl_id);
748 return is_reconnect_ok;
749}
750
751/*******************************************************************************
752**
753** Function btif_hl_dch_open
754**
755** Description Process DCH open request using the DCH Open API parameters
756**
757** Returns BOOLEAN
758**
759*******************************************************************************/
760BOOLEAN btif_hl_dch_open(UINT8 app_id, BD_ADDR bd_addr,
761 tBTA_HL_DCH_OPEN_PARAM *p_dch_open_api,
762 int mdep_cfg_idx,
763 btif_hl_pend_dch_op_t op, int *channel_id){
764 btif_hl_app_cb_t *p_acb;
765 btif_hl_mcl_cb_t *p_mcb;
766 btif_hl_pending_chan_cb_t *p_pcb;
767 UINT8 app_idx, mcl_idx;
768 BOOLEAN status = FALSE;
769 tBTA_HL_MDL_ID mdl_id;
770 tBTA_HL_DCH_RECONNECT_PARAM reconnect_param;
771
772 BTIF_TRACE_DEBUG2("%s app_id=%d ",
773 __FUNCTION__, app_id );
774 BTIF_TRACE_DEBUG6("DB [%02x:%02x:%02x:%02x:%02x:%02x]",
775 bd_addr[0], bd_addr[1],bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]);
776
777 if (btif_hl_find_app_idx(app_id, &app_idx))
778 {
779 if (btif_hl_find_mcl_idx(app_idx, bd_addr , &mcl_idx))
780 {
781 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
782
783 p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx);
784 if (!p_pcb->in_use)
785 {
786 p_mcb->req_ctrl_psm = p_dch_open_api->ctrl_psm;
787
788 p_pcb->in_use = TRUE;
789 *channel_id =
790 p_pcb->channel_id = (int) btif_hl_get_next_channel_id(app_id);
791 p_pcb->cb_state = BTIF_HL_CHAN_CB_STATE_CONNECTING_PENDING;
792 p_pcb->mdep_cfg_idx = mdep_cfg_idx;
Priti Agheraf8f30c22013-04-02 15:31:19 -0700793 memcpy(p_pcb->bd_addr, bd_addr, sizeof(BD_ADDR));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800794 p_pcb->op = op;
795
796 if (p_mcb->sdp.num_recs)
797 {
798 if (p_mcb->valid_sdp_idx)
799 {
800 p_dch_open_api->ctrl_psm = p_mcb->ctrl_psm;
801 }
802
803 if (!btif_hl_is_reconnect_possible(app_idx, mcl_idx, mdep_cfg_idx, p_dch_open_api, &mdl_id ))
804 {
805
806 BTIF_TRACE_DEBUG0("Issue DCH open" );
807 BTA_HlDchOpen(p_mcb->mcl_handle, p_dch_open_api);
808 }
809 else
810 {
811 reconnect_param.ctrl_psm = p_mcb->ctrl_psm;
812 reconnect_param.mdl_id = mdl_id;;
813 BTIF_TRACE_DEBUG2("Issue Reconnect ctrl_psm=0x%x mdl_id=0x%x",reconnect_param.ctrl_psm, reconnect_param.mdl_id );
814 BTA_HlDchReconnect(p_mcb->mcl_handle, &reconnect_param);
815 }
816
817 status = TRUE;
818 }
819 else
820 {
821 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
822 p_mcb->cch_oper = BTIF_HL_CCH_OP_DCH_OPEN;
Priti Agheraf8f30c22013-04-02 15:31:19 -0700823 BTA_HlSdpQuery(app_id,p_acb->app_handle, bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800824 status = TRUE;
825 }
826 }
827 }
828 }
829
830 BTIF_TRACE_DEBUG1("status=%d ", status);
831 return status;
832}
833/*******************************************************************************
834**
835** Function btif_hl_copy_bda
836**
837** Description copy bt_bdaddr_t to BD_ADDR format
838**
839** Returns void
840**
841*******************************************************************************/
842void btif_hl_copy_bda(bt_bdaddr_t *bd_addr, BD_ADDR bda){
843 UINT8 i;
844 for (i=0; i<6; i++)
845 {
846 bd_addr->address[i] = bda[i] ;
847 }
848}
849/*******************************************************************************
850**
851** Function btif_hl_copy_bda
852**
853** Description display bt_bdaddr_t
854**
855** Returns BOOLEAN
856**
857*******************************************************************************/
858void btif_hl_display_bt_bda(bt_bdaddr_t *bd_addr){
859 BTIF_TRACE_DEBUG6("DB [%02x:%02x:%02x:%02x:%02x:%02x]",
860 bd_addr->address[0], bd_addr->address[1], bd_addr->address[2],
861 bd_addr->address[3], bd_addr->address[4], bd_addr->address[5]);
862}
863
864/*******************************************************************************
865**
866** Function btif_hl_dch_abort
867**
868** Description Process DCH abort request
869**
870** Returns Nothing
871**
872*******************************************************************************/
873void btif_hl_dch_abort(UINT8 app_idx, UINT8 mcl_idx){
874 btif_hl_mcl_cb_t *p_mcb;
875
876 BTIF_TRACE_DEBUG3("%s app_idx=%d mcl_idx=%d",__FUNCTION__, app_idx, mcl_idx );
877 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
878 if (p_mcb->is_connected)
879 {
880 BTA_HlDchAbort(p_mcb->mcl_handle);
881 }
882 else
883 {
884 p_mcb->pcb.abort_pending = TRUE;
885 }
886
887}
888/*******************************************************************************
889**
890** Function btif_hl_cch_open
891**
892** Description Process CCH open request
893**
894** Returns Nothing
895**
896*******************************************************************************/
897BOOLEAN btif_hl_cch_open(UINT8 app_id, BD_ADDR bd_addr, UINT16 ctrl_psm,
898 int mdep_cfg_idx,
899 btif_hl_pend_dch_op_t op, int *channel_id){
900
901 btif_hl_app_cb_t *p_acb;
902 btif_hl_mcl_cb_t *p_mcb;
903 btif_hl_pending_chan_cb_t *p_pcb;
904 UINT8 app_idx, mcl_idx, chan_idx;
905 BOOLEAN status = TRUE;
906
907 BTIF_TRACE_DEBUG5("%s app_id=%d ctrl_psm=%d mdep_cfg_idx=%d op=%d",
908 __FUNCTION__, app_id, ctrl_psm, mdep_cfg_idx, op);
909 BTIF_TRACE_DEBUG6("DB [%02x:%02x:%02x:%02x:%02x:%02x]",
910 bd_addr[0], bd_addr[1],bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]);
911
912 if (btif_hl_find_app_idx(app_id, &app_idx))
913 {
914 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
915
916 if (!btif_hl_find_mcl_idx(app_idx, bd_addr, &mcl_idx))
917 {
918 if (btif_hl_find_avail_mcl_idx(app_idx, &mcl_idx))
919 {
920 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
921 memset(p_mcb,0, sizeof(btif_hl_mcl_cb_t));
922 p_mcb->in_use = TRUE;
923 bdcpy(p_mcb->bd_addr, bd_addr);
924
925 if (!ctrl_psm)
926 {
927 p_mcb->cch_oper = BTIF_HL_CCH_OP_MDEP_FILTERING;
928 }
929 else
930 {
931 p_mcb->cch_oper = BTIF_HL_CCH_OP_MATCHED_CTRL_PSM;
932 p_mcb->req_ctrl_psm = ctrl_psm;
933 }
934
935 p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx);
936 p_pcb->in_use = TRUE;
937 p_pcb->mdep_cfg_idx = mdep_cfg_idx;
938 memcpy(p_pcb->bd_addr, bd_addr, sizeof(BD_ADDR));
939 p_pcb->op = op;
940
941 switch (op)
942 {
943 case BTIF_HL_PEND_DCH_OP_OPEN:
944 *channel_id =
945 p_pcb->channel_id = (int) btif_hl_get_next_channel_id(app_id);
946 p_pcb->cb_state = BTIF_HL_CHAN_CB_STATE_CONNECTING_PENDING;
947 break;
948 case BTIF_HL_PEND_DCH_OP_DELETE_MDL:
949 p_pcb->channel_id = p_acb->delete_mdl.channel_id;
950 p_pcb->cb_state = BTIF_HL_CHAN_CB_STATE_DESTROYED_PENDING;
951 break;
952 default:
953 break;
954 }
Priti Agheraf8f30c22013-04-02 15:31:19 -0700955 BTA_HlSdpQuery(app_id,p_acb->app_handle, bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800956 }
957 else
958 {
959 status = FALSE;
960 BTIF_TRACE_ERROR0("Open CCH request discarded- No mcl cb");
961 }
962 }
963 else
964 {
965 status = FALSE;
966 BTIF_TRACE_ERROR0("Open CCH request discarded- already in USE");
967 }
968 }
969 else
970 {
971 status = FALSE;
972 BTIF_TRACE_ERROR1("Invalid app_id=%d", app_id);
973 }
974
975 if (channel_id)
976 {
977 BTIF_TRACE_DEBUG2("status=%d channel_id=0x%08x", status, *channel_id);
978 }
979 else
980 {
981 BTIF_TRACE_DEBUG1("status=%d ", status);
982 }
983 return status;
984}
985
986
987/*******************************************************************************
988**
989** Function btif_hl_find_mdl_idx_using_handle
990**
991** Description Find the MDL index using channel id
992**
993** Returns BOOLEAN
994**
995*******************************************************************************/
996BOOLEAN btif_hl_find_mdl_cfg_idx_using_channel_id(int channel_id,
997 UINT8 *p_app_idx,
998 UINT8 *p_mdl_cfg_idx){
999 btif_hl_app_cb_t *p_acb;
1000 btif_hl_mdl_cfg_t *p_mdl;
1001 BOOLEAN found=FALSE;
1002 UINT8 i,j;
1003 int mdl_cfg_channel_id;
1004
1005 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
1006 {
1007 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
1008 for (j=0; j< BTA_HL_NUM_MDL_CFGS; j++)
1009 {
1010 p_mdl =BTIF_HL_GET_MDL_CFG_PTR(i,j);
1011 mdl_cfg_channel_id = *(BTIF_HL_GET_MDL_CFG_CHANNEL_ID_PTR(i,j));
1012 if (p_acb->in_use &&
1013 p_mdl->base.active &&
1014 (mdl_cfg_channel_id == channel_id))
1015 {
1016 found = TRUE;
1017 *p_app_idx = i;
1018 *p_mdl_cfg_idx =j;
1019 break;
1020 }
1021 }
1022 }
1023
1024 BTIF_TRACE_EVENT5("%s found=%d channel_id=0x%08x, app_idx=%d mdl_cfg_idx=%d ",
1025 __FUNCTION__,found,channel_id, i,j );
1026 return found;
1027}
1028/*******************************************************************************
1029**
1030** Function btif_hl_find_mdl_idx_using_handle
1031**
1032** Description Find the MDL index using channel id
1033**
1034** Returns BOOLEAN
1035**
1036*******************************************************************************/
1037BOOLEAN btif_hl_find_mdl_idx_using_channel_id(int channel_id,
1038 UINT8 *p_app_idx,UINT8 *p_mcl_idx,
1039 UINT8 *p_mdl_idx){
1040 btif_hl_app_cb_t *p_acb;
1041 btif_hl_mcl_cb_t *p_mcb;
1042 btif_hl_mdl_cb_t *p_dcb;
1043 BOOLEAN found=FALSE;
1044 UINT8 i,j,k;
1045
1046 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
1047 {
1048 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
1049 for (j=0; j< BTA_HL_NUM_MCLS; j++)
1050 {
1051 p_mcb =BTIF_HL_GET_MCL_CB_PTR(i,j);
1052 for (k=0; k< BTA_HL_NUM_MDLS_PER_MCL; k++)
1053 {
1054 p_dcb =BTIF_HL_GET_MDL_CB_PTR(i,j,k);
1055 if (p_acb->in_use &&
1056 p_mcb->in_use &&
1057 p_dcb->in_use &&
1058 (p_dcb->channel_id == channel_id))
1059 {
1060 found = TRUE;
1061 *p_app_idx = i;
1062 *p_mcl_idx =j;
1063 *p_mdl_idx = k;
1064 break;
1065 }
1066 }
1067 }
1068 }
1069 BTIF_TRACE_DEBUG5("%s found=%d app_idx=%d mcl_idx=%d mdl_idx=%d ",
1070 __FUNCTION__,found,i,j,k );
1071 return found;
1072}
1073
1074/*******************************************************************************
1075**
1076** Function btif_hl_find_channel_id_using_mdl_id
1077**
1078** Description Find channel id using mdl_id'
1079**
1080** Returns BOOLEAN
1081*********************************************************************************/
1082BOOLEAN btif_hl_find_channel_id_using_mdl_id(UINT8 app_idx, tBTA_HL_MDL_ID mdl_id,
1083 int *p_channel_id){
1084 btif_hl_app_cb_t *p_acb;
1085 btif_hl_mdl_cfg_t *p_mdl;
1086 BOOLEAN found=FALSE;
1087 UINT8 j=0;
1088 int mdl_cfg_channel_id;
1089 p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx);
1090 if (p_acb && p_acb->in_use)
1091 {
1092 for (j=0; j< BTA_HL_NUM_MDL_CFGS; j++)
1093 {
1094 p_mdl =BTIF_HL_GET_MDL_CFG_PTR(app_idx,j);
1095 mdl_cfg_channel_id = *(BTIF_HL_GET_MDL_CFG_CHANNEL_ID_PTR(app_idx,j));
1096 if ( p_mdl->base.active && (p_mdl->base.mdl_id == mdl_id))
1097 {
1098 found = TRUE;
1099 *p_channel_id = mdl_cfg_channel_id;
1100 break;
1101 }
1102 }
1103 }
1104 BTIF_TRACE_EVENT6("%s found=%d channel_id=0x%08x, mdl_id=0x%x app_idx=%d mdl_cfg_idx=%d ",
1105 __FUNCTION__,found,*p_channel_id,mdl_id, app_idx,j );
1106 return found;
1107}
1108
1109
1110/*******************************************************************************
1111**
1112** Function btif_hl_find_mdl_idx_using_handle
1113**
1114** Description Find the MDL index using handle
1115**
1116** Returns BOOLEAN
1117**
1118*******************************************************************************/
1119BOOLEAN btif_hl_find_mdl_idx_using_handle(tBTA_HL_MDL_HANDLE mdl_handle,
1120 UINT8 *p_app_idx,UINT8 *p_mcl_idx,
1121 UINT8 *p_mdl_idx){
1122 btif_hl_app_cb_t *p_acb;
1123 btif_hl_mcl_cb_t *p_mcb;
1124 btif_hl_mdl_cb_t *p_dcb;
1125 BOOLEAN found=FALSE;
1126 UINT8 i,j,k;
1127
1128 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
1129 {
1130 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
1131 for (j=0; j< BTA_HL_NUM_MCLS; j++)
1132 {
1133 p_mcb =BTIF_HL_GET_MCL_CB_PTR(i,j);
1134 for (k=0; k< BTA_HL_NUM_MDLS_PER_MCL; k++)
1135 {
1136 p_dcb =BTIF_HL_GET_MDL_CB_PTR(i,j,k);
1137 if (p_acb->in_use &&
1138 p_mcb->in_use &&
1139 p_dcb->in_use &&
1140 (p_dcb->mdl_handle == mdl_handle))
1141 {
1142 found = TRUE;
1143 *p_app_idx = i;
1144 *p_mcl_idx =j;
1145 *p_mdl_idx = k;
1146 break;
1147 }
1148 }
1149 }
1150 }
1151
1152
1153 BTIF_TRACE_EVENT5("%s found=%d app_idx=%d mcl_idx=%d mdl_idx=%d ",
1154 __FUNCTION__,found,i,j,k );
1155 return found;
1156}
1157/*******************************************************************************
1158**
1159** Function btif_hl_find_peer_mdep_id
1160**
1161** Description Find the peer MDEP ID from the received SPD records
1162**
1163** Returns BOOLEAN
1164**
1165*******************************************************************************/
1166static BOOLEAN btif_hl_find_peer_mdep_id(UINT8 app_id, BD_ADDR bd_addr,
1167 tBTA_HL_MDEP_ROLE local_mdep_role,
1168 UINT16 data_type,
1169 tBTA_HL_MDEP_ID *p_peer_mdep_id){
1170 UINT8 app_idx, mcl_idx;
1171 btif_hl_app_cb_t *p_acb;
1172 btif_hl_mcl_cb_t *p_mcb;
1173 tBTA_HL_SDP_REC *p_rec;
1174 UINT8 i, num_mdeps;
1175 BOOLEAN found = FALSE;
1176 tBTA_HL_MDEP_ROLE peer_mdep_role;
1177
1178
1179 BTIF_TRACE_DEBUG4("%s app_id=%d local_mdep_role=%d, data_type=%d",
1180 __FUNCTION__, app_id, local_mdep_role, data_type);
1181
1182 BTIF_TRACE_DEBUG6("DB [%02x:%02x:%02x:%02x:%02x:%02x]",
1183 bd_addr[0], bd_addr[1],
1184 bd_addr[2], bd_addr[3],
1185 bd_addr[4], bd_addr[5]);
1186
1187
1188 BTIF_TRACE_DEBUG1("local_mdep_role=%d", local_mdep_role);
1189 BTIF_TRACE_DEBUG1("data_type=%d", data_type);
1190
1191 if (local_mdep_role == BTA_HL_MDEP_ROLE_SINK)
1192 peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE;
1193 else
1194 peer_mdep_role = BTA_HL_MDEP_ROLE_SINK;
1195
1196 if (btif_hl_find_app_idx(app_id, &app_idx) )
1197 {
1198 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
1199 if (btif_hl_find_mcl_idx(app_idx, bd_addr, &mcl_idx))
1200 {
1201 p_mcb =BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1202
1203 BTIF_TRACE_DEBUG2("app_idx=%d mcl_idx=%d",app_idx, mcl_idx);
1204 BTIF_TRACE_DEBUG2("valid_spd_idx=%d sdp_idx=%d",p_mcb->valid_sdp_idx, p_mcb->sdp_idx);
1205 if (p_mcb->valid_sdp_idx)
1206 {
1207 p_rec = &p_mcb->sdp.sdp_rec[p_mcb->sdp_idx];
1208 num_mdeps = p_rec->num_mdeps;
1209 BTIF_TRACE_DEBUG1("num_mdeps=%d", num_mdeps);
1210
1211 for (i=0; i< num_mdeps; i++)
1212 {
1213 BTIF_TRACE_DEBUG2("p_rec->mdep_cfg[%d].mdep_role=%d",i, p_rec->mdep_cfg[i].mdep_role);
1214 BTIF_TRACE_DEBUG2("p_rec->mdep_cfg[%d].data_type =%d",i, p_rec->mdep_cfg[i].data_type );
1215 if ((p_rec->mdep_cfg[i].mdep_role == peer_mdep_role) &&
1216 (p_rec->mdep_cfg[i].data_type == data_type))
1217 {
1218 found = TRUE;
1219 *p_peer_mdep_id = p_rec->mdep_cfg[i].mdep_id;
1220 break;
1221 }
1222 }
1223 }
1224 }
1225 }
1226
1227 BTIF_TRACE_DEBUG2("found =%d *p_peer_mdep_id=%d", found, *p_peer_mdep_id);
1228
1229 return found;
1230}
1231/*******************************************************************************
1232**
1233** Function btif_hl_find_local_mdep_id
1234**
1235** Description Find the local MDEP ID from the MDEP configuration
1236**
1237** Returns BOOLEAN
1238**
1239*******************************************************************************/
1240static BOOLEAN btif_hl_find_local_mdep_id(UINT8 app_id,
1241 tBTA_HL_MDEP_ROLE local_mdep_role,
1242 UINT16 mdep_data_type,
1243 tBTA_HL_MDEP_ID *p_local_mdep_id){
1244 UINT8 app_idx;
1245 btif_hl_app_cb_t *p_acb;
1246 UINT8 i,j;
1247 BOOLEAN found = FALSE;
1248
1249 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
1250
1251 if (btif_hl_find_app_idx(app_id, &app_idx) )
1252 {
1253 p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx);
1254
1255 for (i=0; i< p_acb->sup_feature.num_of_mdeps; i++)
1256 {
1257 if (p_acb->sup_feature.mdep[i].mdep_cfg.mdep_role == local_mdep_role )
1258 {
1259 for (j=0; j< p_acb->sup_feature.mdep[i].mdep_cfg.num_of_mdep_data_types; j++)
1260 {
1261 if ( p_acb->sup_feature.mdep[i].mdep_cfg.data_cfg[j].data_type == mdep_data_type)
1262 {
1263 found = TRUE;
1264 *p_local_mdep_id = p_acb->sup_feature.mdep[i].mdep_id;
1265 return found;
1266 }
1267 }
1268 }
1269 }
1270
1271
1272 }
1273 BTIF_TRACE_DEBUG2("found=%d local mdep id=%d", found, *p_local_mdep_id );
1274 return found;
1275}
1276
1277/*******************************************************************************
1278**
1279** Function btif_hl_find_mdep_cfg_idx
1280**
1281** Description Find the MDEP configuration index using local MDEP_ID
1282**
1283** Returns BOOLEAN
1284**
1285*******************************************************************************/
1286static BOOLEAN btif_hl_find_mdep_cfg_idx(UINT8 app_idx, tBTA_HL_MDEP_ID local_mdep_id,
1287 UINT8 *p_mdep_cfg_idx){
1288 btif_hl_app_cb_t *p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx);
1289 tBTA_HL_SUP_FEATURE *p_sup_feature= &p_acb->sup_feature;
1290 BOOLEAN found =FALSE;
1291 UINT8 i;
1292
1293 for (i=0; i< p_sup_feature->num_of_mdeps; i++)
1294 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07001295 BTIF_TRACE_DEBUG2("btif_hl_find_mdep_cfg_idx: mdep_id=%d app_idx = %d",
1296 p_sup_feature->mdep[i].mdep_id,app_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001297 if ( p_sup_feature->mdep[i].mdep_id == local_mdep_id)
1298 {
1299 found = TRUE;
1300 *p_mdep_cfg_idx = i;
1301 break;
1302 }
1303 }
1304
Priti Agheraf8f30c22013-04-02 15:31:19 -07001305 BTIF_TRACE_DEBUG5("%s found=%d mdep_idx=%d local_mdep_id=%d app_idx=%d ",
1306 __FUNCTION__, found,i, local_mdep_id,app_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001307 return found;
1308}
1309
1310
1311
1312/*******************************************************************************
1313**
1314** Function btif_hl_find_mcl_idx
1315**
1316** Description Find the MCL index using BD address
1317**
1318** Returns BOOLEAN
1319**
1320*******************************************************************************/
1321BOOLEAN btif_hl_find_mcl_idx(UINT8 app_idx, BD_ADDR p_bd_addr, UINT8 *p_mcl_idx){
1322 BOOLEAN found=FALSE;
1323 UINT8 i;
1324 btif_hl_app_cb_t *p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx);
1325 btif_hl_mcl_cb_t *p_mcb;
1326
1327 for (i=0; i < BTA_HL_NUM_MCLS ; i ++)
1328 {
1329 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, i);
1330 if (p_mcb->in_use &&
1331 (!memcmp (p_mcb->bd_addr, p_bd_addr, BD_ADDR_LEN)))
1332 {
1333 found = TRUE;
1334 *p_mcl_idx = i;
1335 break;
1336 }
1337 }
1338
1339
1340 BTIF_TRACE_DEBUG3("%s found=%d idx=%d",__FUNCTION__, found, i);
1341 return found;
1342}
1343/*******************************************************************************
1344**
1345** Function btif_hl_init
1346**
1347** Description HL initialization function.
1348**
1349** Returns void
1350**
1351*******************************************************************************/
1352static void btif_hl_init(void){
1353 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
1354 memset(p_btif_hl_cb, 0, sizeof(btif_hl_cb_t));
1355 btif_hl_init_next_app_id();
1356 btif_hl_init_next_channel_id();
1357}
1358/*******************************************************************************
1359**
1360** Function btif_hl_disable
1361**
1362** Description Disable initialization function.
1363**
1364** Returns void
1365**
1366*******************************************************************************/
1367static void btif_hl_disable(void){
1368 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
1369
1370 if ((p_btif_hl_cb->state != BTIF_HL_STATE_DISABLING) &&
1371 (p_btif_hl_cb->state != BTIF_HL_STATE_DISABLED))
1372 {
1373 btif_hl_set_state(BTIF_HL_STATE_DISABLING);
1374 BTA_HlDisable();
1375 }
1376}
1377/*******************************************************************************
1378**
1379** Function btif_hl_is_no_active_app
1380**
1381** Description Find whether or not any APP is still in use
1382**
1383** Returns BOOLEAN
1384**
1385*******************************************************************************/
1386static BOOLEAN btif_hl_is_no_active_app(void){
1387 BOOLEAN no_active_app = TRUE;
1388 UINT8 i;
1389
1390 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
1391 {
1392 if (btif_hl_cb.acb[i].in_use)
1393 {
1394 no_active_app = FALSE;
1395 break;
1396 }
1397 }
1398
1399 BTIF_TRACE_DEBUG2("%s no_active_app=%d ", __FUNCTION__, no_active_app );
1400 return no_active_app;
1401}
1402
1403/*******************************************************************************
1404**
1405** Function btif_hl_free_app_idx
1406**
1407** Description free an application control block
1408**
1409** Returns void
1410**
1411*******************************************************************************/
1412static void btif_hl_free_app_idx(UINT8 app_idx){
1413
1414 if ((app_idx < BTA_HL_NUM_APPS) && btif_hl_cb.acb[app_idx].in_use )
1415 {
1416 btif_hl_cb.acb[app_idx].in_use = FALSE;
1417 memset (&btif_hl_cb.acb[app_idx], 0, sizeof(btif_hl_app_cb_t));
1418 }
1419}
1420/*******************************************************************************
1421**
1422** Function btif_hl_set_state
1423**
1424** Description set HL state
1425**
1426** Returns void
1427**
1428*******************************************************************************/
1429static void btif_hl_set_state(btif_hl_state_t state){
1430 BTIF_TRACE_DEBUG2("btif_hl_set_state: %d ---> %d ", p_btif_hl_cb->state, state);
1431 p_btif_hl_cb->state = state;
1432}
1433
1434/*******************************************************************************
1435**
1436** Function btif_hl_set_state
1437**
1438** Description get HL state
1439**
1440** Returns btif_hl_state_t
1441**
1442*******************************************************************************/
1443
1444static btif_hl_state_t btif_hl_get_state(void){
1445 BTIF_TRACE_DEBUG1("btif_hl_get_state: %d ", p_btif_hl_cb->state);
1446 return p_btif_hl_cb->state;
1447}
1448
1449/*******************************************************************************
1450**
1451** Function btif_hl_find_data_type_idx
1452**
1453** Description Find the index in the data type table
1454**
1455** Returns BOOLEAN
1456**
1457*******************************************************************************/
1458static BOOLEAN btif_hl_find_data_type_idx(UINT16 data_type, UINT8 *p_idx){
1459 BOOLEAN found = FALSE;
1460 UINT8 i;
1461
1462 for (i=0; i< BTIF_HL_DATA_TABLE_SIZE; i++ )
1463 {
1464 if (data_type_table[i].data_type == data_type)
1465 {
1466 found = TRUE;
1467 *p_idx= i;
1468 break;
1469 }
1470 }
1471
1472 BTIF_TRACE_DEBUG4("%s found=%d, data_type=0x%x idx=%d", __FUNCTION__, found, data_type, i);
1473 return found;
1474}
1475
1476/*******************************************************************************
1477**
1478** Function btif_hl_get_max_tx_apdu_size
1479**
1480** Description Find the maximum TX APDU size for the specified data type and
1481** MDEP role
1482**
1483** Returns UINT16
1484**
1485*******************************************************************************/
1486UINT16 btif_hl_get_max_tx_apdu_size(tBTA_HL_MDEP_ROLE mdep_role,
1487 UINT16 data_type ){
1488 UINT8 idx;
1489 UINT16 max_tx_apdu_size =0;
1490
1491 if (btif_hl_find_data_type_idx(data_type, &idx))
1492 {
1493 if (mdep_role == BTA_HL_MDEP_ROLE_SOURCE)
1494 {
1495 max_tx_apdu_size = data_type_table[idx].max_tx_apdu_size;
1496 }
1497 else
1498 {
1499 max_tx_apdu_size = data_type_table[idx].max_rx_apdu_size;
1500 }
1501 }
1502 else
1503 {
1504 if (mdep_role == BTA_HL_MDEP_ROLE_SOURCE)
1505 {
1506 max_tx_apdu_size = BTIF_HL_DEFAULT_SRC_TX_APDU_SIZE;
1507 }
1508 else
1509 {
1510 max_tx_apdu_size = BTIF_HL_DEFAULT_SRC_RX_APDU_SIZE;
1511 }
1512
1513
1514 }
1515
1516 BTIF_TRACE_DEBUG4("%s mdep_role=%d data_type=0x%4x size=%d",
1517 __FUNCTION__, mdep_role, data_type, max_tx_apdu_size);
1518 return max_tx_apdu_size;
1519}
1520
1521
1522/*******************************************************************************
1523**
1524** Function btif_hl_get_max_rx_apdu_size
1525**
1526** Description Find the maximum RX APDU size for the specified data type and
1527** MDEP role
1528**
1529** Returns UINT16
1530**
1531*******************************************************************************/
1532UINT16 btif_hl_get_max_rx_apdu_size(tBTA_HL_MDEP_ROLE mdep_role,
1533 UINT16 data_type ){
1534 UINT8 idx;
1535 UINT16 max_rx_apdu_size =0;
1536
1537 if (btif_hl_find_data_type_idx(data_type, &idx))
1538 {
1539 if (mdep_role == BTA_HL_MDEP_ROLE_SOURCE)
1540 {
1541 max_rx_apdu_size = data_type_table[idx].max_rx_apdu_size;
1542 }
1543 else
1544 {
1545 max_rx_apdu_size = data_type_table[idx].max_tx_apdu_size;
1546 }
1547 }
1548 else
1549 {
1550 if (mdep_role == BTA_HL_MDEP_ROLE_SOURCE)
1551 {
1552 max_rx_apdu_size = BTIF_HL_DEFAULT_SRC_RX_APDU_SIZE;
1553 }
1554 else
1555 {
1556 max_rx_apdu_size = BTIF_HL_DEFAULT_SRC_TX_APDU_SIZE;
1557 }
1558 }
1559
1560
1561 BTIF_TRACE_DEBUG4("%s mdep_role=%d data_type=0x%4x size=%d",
1562 __FUNCTION__, mdep_role, data_type, max_rx_apdu_size);
1563
1564 return max_rx_apdu_size;
1565}
1566
1567/*******************************************************************************
1568**
1569** Function btif_hl_if_channel_setup_pending
1570**
1571** Description
1572**
1573** Returns BOOLEAN
1574**
1575*******************************************************************************/
1576
1577static BOOLEAN btif_hl_get_bta_mdep_role(bthl_mdep_role_t mdep, tBTA_HL_MDEP_ROLE *p){
1578 BOOLEAN status = TRUE;
1579 switch (mdep)
1580 {
1581 case BTHL_MDEP_ROLE_SOURCE:
1582 *p = BTA_HL_MDEP_ROLE_SOURCE;
1583 break;
1584 case BTHL_MDEP_ROLE_SINK:
1585 *p = BTA_HL_MDEP_ROLE_SINK;
1586 break;
1587 default:
1588 status = FALSE;
1589 break;
1590 }
1591
1592 BTIF_TRACE_DEBUG4("%s status=%d bta_mdep_role=%d (%d:btif)",
1593 __FUNCTION__, status, *p, mdep);
1594 return status;
1595}
1596/*******************************************************************************
1597**
1598** Function btif_hl_get_bta_channel_type
1599**
1600** Description convert bthl channel type to BTA DCH channel type
1601**
1602** Returns BOOLEAN
1603**
1604*******************************************************************************/
1605
1606static BOOLEAN btif_hl_get_bta_channel_type(bthl_channel_type_t channel_type, tBTA_HL_DCH_CFG *p){
1607 BOOLEAN status = TRUE;
1608 switch (channel_type)
1609 {
1610 case BTHL_CHANNEL_TYPE_RELIABLE:
1611 *p = BTA_HL_DCH_CFG_RELIABLE;
1612 break;
1613 case BTHL_CHANNEL_TYPE_STREAMING:
1614 *p = BTA_HL_DCH_CFG_STREAMING;
1615 break;
1616 case BTHL_CHANNEL_TYPE_ANY:
1617 *p = BTA_HL_DCH_CFG_NO_PREF;
1618 break;
1619 default:
1620 status = FALSE;
1621 break;
1622 }
1623 BTIF_TRACE_DEBUG3("%s status = %d BTA DCH CFG=%d (1-rel 2-strm",
1624 __FUNCTION__, status, *p);
1625 return status;
1626}
1627/*******************************************************************************
1628**
1629** Function btif_hl_get_next_app_id
1630**
1631** Description get next applcation id
1632**
1633** Returns UINT8
1634**
1635*******************************************************************************/
1636
1637static UINT8 btif_hl_get_next_app_id(){
1638 UINT8 next_app_id = btif_hl_cb.next_app_id;
1639
1640 btif_hl_cb.next_app_id++;
1641 return next_app_id;
1642}
1643/*******************************************************************************
1644**
1645** Function btif_hl_get_next_channel_id
1646**
1647** Description get next channel id
1648**
1649** Returns int
1650**
1651*******************************************************************************/
1652static int btif_hl_get_next_channel_id(UINT8 app_id){
1653 UINT16 next_channel_id = btif_hl_cb.next_channel_id;
1654 int channel_id;
1655 btif_hl_cb.next_channel_id++;
1656 channel_id = (app_id << 16) + next_channel_id;
1657 BTIF_TRACE_DEBUG4("%s channel_id=0x%08x, app_id=0x%02x next_channel_id=0x%04x", __FUNCTION__,
1658 channel_id, app_id, next_channel_id);
1659 return channel_id;
1660}
1661/*******************************************************************************
1662**
1663** Function btif_hl_get_app_id
1664**
1665** Description get the applicaiton id associated with the channel id
1666**
1667** Returns UINT8
1668**
1669*******************************************************************************/
1670
1671static UINT8 btif_hl_get_app_id(int channel_id){
1672 UINT8 app_id =(UINT8) (channel_id >> 16);
1673 BTIF_TRACE_DEBUG3("%s channel_id=0x%08x, app_id=0x%02x ", __FUNCTION__,channel_id, app_id);
1674 return app_id;
1675}
1676/*******************************************************************************
1677**
1678** Function btif_hl_init_next_app_id
1679**
1680** Description initialize the application id
1681**
1682** Returns void
1683**
1684*******************************************************************************/
1685static void btif_hl_init_next_app_id(void){
1686 btif_hl_cb.next_app_id = 1;
1687}
1688/*******************************************************************************
1689**
1690** Function btif_hl_init_next_channel_id
1691**
1692** Description initialize the channel id
1693**
1694** Returns void
1695**
1696*******************************************************************************/
1697static void btif_hl_init_next_channel_id(void){
1698 btif_hl_cb.next_channel_id = 1;
1699}
1700
The Android Open Source Project5738f832012-12-12 16:00:35 -08001701
1702/*******************************************************************************
1703**
1704** Function btif_hl_find_app_idx_using_handle
1705**
1706** Description Find the applicaiton index using handle
1707**
1708** Returns BOOLEAN
1709**
1710*******************************************************************************/
1711BOOLEAN btif_hl_find_app_idx_using_handle(tBTA_HL_APP_HANDLE app_handle,
1712 UINT8 *p_app_idx){
1713 BOOLEAN found=FALSE;
1714 UINT8 i;
1715
1716 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
1717 {
1718 if (btif_hl_cb.acb[i].in_use &&
1719 (btif_hl_cb.acb[i].app_handle == app_handle))
1720 {
1721 found = TRUE;
1722 *p_app_idx = i;
1723 break;
1724 }
1725 }
1726
1727 BTIF_TRACE_EVENT4("%s status=%d handle=%d app_idx=%d ",
1728 __FUNCTION__, found, app_handle , i);
1729
1730 return found;
1731}
1732
1733/*******************************************************************************
1734**
Priti Agheraf8f30c22013-04-02 15:31:19 -07001735** Function btif_hl_find_app_idx_using_app_id
1736**
1737** Description Find the applicaiton index using app_id
1738**
1739** Returns BOOLEAN
1740**
1741*******************************************************************************/
1742BOOLEAN btif_hl_find_app_idx_using_app_id(UINT8 app_id,
1743 UINT8 *p_app_idx){
1744 BOOLEAN found=FALSE;
1745 UINT8 i;
1746
1747 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
1748 {
1749 if (btif_hl_cb.acb[i].in_use &&
1750 (btif_hl_cb.acb[i].app_id == app_id))
1751 {
1752 found = TRUE;
1753 *p_app_idx = i;
1754 break;
1755 }
1756 }
1757
1758 BTIF_TRACE_EVENT4("%s found=%d app_id=%d app_idx=%d ",
1759 __FUNCTION__, found, app_id , i);
1760
1761 return found;
1762}
1763
1764/*******************************************************************************
1765**
The Android Open Source Project5738f832012-12-12 16:00:35 -08001766** Function btif_hl_find_mcl_idx_using_handle
1767**
1768** Description Find the MCL index using handle
1769**
1770** Returns BOOLEAN
1771**
1772*******************************************************************************/
1773BOOLEAN btif_hl_find_mcl_idx_using_handle( tBTA_HL_MCL_HANDLE mcl_handle,
1774 UINT8 *p_app_idx, UINT8 *p_mcl_idx){
1775 btif_hl_app_cb_t *p_acb;
1776 BOOLEAN found=FALSE;
1777 UINT8 i,j;
1778
1779 for (i=0; i<BTA_HL_NUM_APPS; i++)
1780 {
1781 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
1782 for (j=0; j < BTA_HL_NUM_MCLS ; j++)
1783 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07001784 if (p_acb->mcb[j].in_use)
1785 BTIF_TRACE_DEBUG3("btif_hl_find_mcl_idx_using_handle:app_idx=%d,"
1786 "mcl_idx =%d mcl_handle=%d",i,j,p_acb->mcb[j].mcl_handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001787 if (p_acb->mcb[j].in_use &&
1788 (p_acb->mcb[j].mcl_handle == mcl_handle))
1789 {
1790 found = TRUE;
1791 *p_app_idx = i;
1792 *p_mcl_idx = j;
1793 break;
1794 }
1795 }
1796 }
1797 BTIF_TRACE_DEBUG4("%s found=%d app_idx=%d mcl_idx=%d",__FUNCTION__,
1798 found, i, j);
1799 return found;
1800}
1801
1802/*******************************************************************************
1803**
Priti Agheraf8f30c22013-04-02 15:31:19 -07001804** Function btif_hl_find_mdl_idx_using_mdl_id
1805**
1806** Description Find the mdl index using mdl_id
1807**
1808** Returns BOOLEAN
1809**
1810*******************************************************************************/
1811BOOLEAN btif_hl_find_mcl_idx_using_mdl_id( UINT8 mdl_id,UINT8 mcl_handle,
1812 UINT8 *p_app_idx, UINT8 *p_mcl_idx){
1813 btif_hl_app_cb_t *p_acb;
1814 btif_hl_mcl_cb_t *p_mcb;
1815 BOOLEAN found=FALSE;
1816 UINT8 i,j,x;
1817
1818 for (i=0; i<BTA_HL_NUM_APPS; i++)
1819 {
1820 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
1821 for (j=0; j < BTA_HL_NUM_MCLS ; j++)
1822 {
1823 if (p_acb->mcb[j].in_use &&
1824 (p_acb->mcb[j].mcl_handle == mcl_handle))
1825 {
1826 p_mcb = &p_acb->mcb[j];
1827 BTIF_TRACE_DEBUG1("btif_hl_find_mcl_idx_using_mdl_id: mcl handle found j =%d",j);
1828 for (x=0; x < BTA_HL_NUM_MDLS_PER_MCL ; x ++)
1829 {
1830 if (p_mcb->mdl[x].in_use && p_mcb->mdl[x].mdl_id == mdl_id)
1831 {
1832 BTIF_TRACE_DEBUG1("btif_hl_find_mcl_idx_using_mdl_id:found x =%d",x);
1833 found = TRUE;
1834 *p_app_idx = i;
1835 *p_mcl_idx = j;
1836 break;
1837 }
1838 }
1839 }
1840 }
1841 }
1842 BTIF_TRACE_DEBUG4("%s found=%d app_idx=%d mcl_idx=%d",__FUNCTION__,
1843 found, i, j);
1844 return found;
1845}
1846
1847/*******************************************************************************
1848**
1849** Function btif_hl_find_mcl_idx_using_deleted_mdl_id
1850**
1851** Description Find the app index deleted_mdl_id
1852**
1853** Returns BOOLEAN
1854**
1855*******************************************************************************/
1856BOOLEAN btif_hl_find_app_idx_using_deleted_mdl_id( UINT8 mdl_id,
1857 UINT8 *p_app_idx){
1858 btif_hl_app_cb_t *p_acb;
1859 BOOLEAN found=FALSE;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08001860 UINT8 i;
Priti Agheraf8f30c22013-04-02 15:31:19 -07001861
1862 for (i=0; i<BTA_HL_NUM_APPS; i++)
1863 {
1864 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08001865 if (p_acb->delete_mdl.active) {
1866 BTIF_TRACE_DEBUG3("btif_hl_find_app_idx_using_deleted_mdl_id: app_idx=%d,"
1867 "mdl_id=%d mcl_handle=%d",i,mdl_id,p_acb->mcb[i].mcl_handle);
1868 }
1869 if (p_acb->delete_mdl.active &&
1870 (p_acb->delete_mdl.mdl_id == mdl_id))
1871 {
1872 found = TRUE;
1873 *p_app_idx = i;
1874 break;
1875 }
Priti Agheraf8f30c22013-04-02 15:31:19 -07001876 }
1877 BTIF_TRACE_DEBUG3("%s found=%d app_idx=%d",__FUNCTION__,
1878 found, i);
1879 return found;
1880}
1881
1882/*******************************************************************************
1883**
1884** Function btif_hl_stop_timer_using_handle
1885**
1886** Description clean control channel cb using handle
1887**
1888** Returns void
1889**
1890*******************************************************************************/
1891static void btif_hl_stop_timer_using_handle( tBTA_HL_MCL_HANDLE mcl_handle){
1892 btif_hl_app_cb_t *p_acb;
1893 BOOLEAN found=FALSE;
1894 UINT8 i,j;
1895
1896 for (i=0; i<BTA_HL_NUM_APPS; i++)
1897 {
1898 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
1899 for (j=0; j < BTA_HL_NUM_MCLS ; j++)
1900 {
1901 if (p_acb->mcb[j].in_use &&
1902 (p_acb->mcb[j].mcl_handle == mcl_handle))
1903 {
1904 btif_hl_stop_cch_timer(i, j);
1905 }
1906 }
1907 }
1908}
1909
1910/*******************************************************************************
1911**
1912** Function btif_hl_find_mcl_idx_using_app_idx
1913**
1914** Description Find the MCL index using handle
1915**
1916** Returns BOOLEAN
1917**
1918*******************************************************************************/
1919BOOLEAN btif_hl_find_mcl_idx_using_app_idx( tBTA_HL_MCL_HANDLE mcl_handle,
1920 UINT8 p_app_idx, UINT8 *p_mcl_idx){
1921 btif_hl_app_cb_t *p_acb;
1922 BOOLEAN found=FALSE;
1923 UINT8 i,j;
1924
1925 p_acb =BTIF_HL_GET_APP_CB_PTR(p_app_idx);
1926 for (j=0; j < BTA_HL_NUM_MCLS ; j++)
1927 {
1928 if (p_acb->mcb[j].in_use &&
1929 (p_acb->mcb[j].mcl_handle == mcl_handle))
1930 {
1931 found = TRUE;
1932 *p_mcl_idx = j;
1933 break;
1934 }
1935 }
1936 BTIF_TRACE_DEBUG3("%s found=%dmcl_idx=%d",__FUNCTION__,
1937 found, j);
1938 return found;
1939}
1940
1941/*******************************************************************************
1942**
1943** Function btif_hl_clean_mdls_using_app_idx
1944**
1945** Description clean dch cpntrol bloack using app_idx
1946**
1947** Returns void
1948**
1949*******************************************************************************/
1950void btif_hl_clean_mdls_using_app_idx( UINT8 app_idx){
1951 btif_hl_app_cb_t *p_acb;
1952 btif_hl_mcl_cb_t *p_mcb;
1953 btif_hl_mdl_cb_t *p_dcb;
1954 UINT8 i,j,x,y;
1955 bt_bdaddr_t bd_addr;
1956
1957 p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx);
1958 for (j=0; j < BTA_HL_NUM_MCLS ; j++)
1959 {
1960 if (p_acb->mcb[j].in_use)
1961 {
1962 p_mcb = &p_acb->mcb[j];
1963 BTIF_TRACE_DEBUG1("btif_hl_find_mcl_idx_using_mdl_id: mcl handle found j =%d",j);
1964 for (x=0; x < BTA_HL_NUM_MDLS_PER_MCL ; x ++)
1965 {
1966 if (p_mcb->mdl[x].in_use)
1967 {
1968 p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, j,x);
1969 btif_hl_release_socket(app_idx,j,x);
1970 for (y=0; y<6; y++)
1971 {
1972 bd_addr.address[y] = p_mcb->bd_addr[y];
1973 }
1974 BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, p_acb->app_id,
1975 &bd_addr, p_dcb->local_mdep_cfg_idx,
1976 p_dcb->channel_id, BTHL_CONN_STATE_DISCONNECTED, 0 );
1977 btif_hl_clean_mdl_cb(p_dcb);
1978 if (!btif_hl_num_dchs_in_use(p_mcb->mcl_handle))
1979 BTA_HlCchClose(p_mcb->mcl_handle);
1980 BTIF_TRACE_DEBUG1("remote DCH close success mdl_idx=%d", x);
1981 }
1982 }
1983 }
1984 }
1985}
1986
1987/*******************************************************************************
1988**
The Android Open Source Project5738f832012-12-12 16:00:35 -08001989** Function btif_hl_find_app_idx
1990**
1991** Description Find the application index using application ID
1992**
1993** Returns BOOLEAN
1994**
1995*******************************************************************************/
1996BOOLEAN btif_hl_find_app_idx(UINT8 app_id, UINT8 *p_app_idx){
1997 BOOLEAN found=FALSE;
1998 UINT8 i;
1999
2000 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
2001 {
2002
2003 if (btif_hl_cb.acb[i].in_use &&
2004 (btif_hl_cb.acb[i].app_id == app_id))
2005 {
2006 found = TRUE;
2007 *p_app_idx = i;
2008 break;
2009 }
2010 }
2011 BTIF_TRACE_DEBUG3("%s found=%d app_idx=%d", __FUNCTION__, found, i );
2012
2013 return found;
2014}
2015
Priti Agheraf8f30c22013-04-02 15:31:19 -07002016/*******************************************************************************
2017**
2018** Function btif_hl_find_app_idx
2019**
2020** Description Find the application index using application ID
2021**
2022** Returns BOOLEAN
2023**
2024*******************************************************************************/
2025BOOLEAN btif_hl_find_app_idx_using_mdepId(UINT8 mdep_id, UINT8 *p_app_idx){
2026 BOOLEAN found=FALSE;
2027 UINT8 i;
2028
2029 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
2030 {
2031 BTIF_TRACE_DEBUG1("btif_hl_find_app_idx_using_mdepId: MDEP-ID = %d",
2032 btif_hl_cb.acb[i].sup_feature.mdep[0].mdep_id);
2033 if (btif_hl_cb.acb[i].in_use &&
2034 (btif_hl_cb.acb[i].sup_feature.mdep[0].mdep_id == mdep_id))
2035 {
2036 found = TRUE;
2037 *p_app_idx = i;
2038 break;
2039 }
2040 }
2041 BTIF_TRACE_DEBUG3("%s found=%d app_idx=%d", __FUNCTION__, found, i );
2042
2043 return found;
2044}
The Android Open Source Project5738f832012-12-12 16:00:35 -08002045
2046/*******************************************************************************
2047**
2048** Function btif_hl_find_avail_mdl_idx
2049**
2050** Description Find a not in-use MDL index
2051**
2052** Returns BOOLEAN
2053**
2054*******************************************************************************/
2055BOOLEAN btif_hl_find_avail_mdl_idx(UINT8 app_idx, UINT8 mcl_idx,
2056 UINT8 *p_mdl_idx){
2057 btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2058 BOOLEAN found=FALSE;
2059 UINT8 i;
2060
2061 for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++)
2062 {
2063 if (!p_mcb->mdl[i].in_use)
2064 {
2065 btif_hl_clean_mdl_cb(&p_mcb->mdl[i]);
2066 found = TRUE;
2067 *p_mdl_idx = i;
2068 break;
2069 }
2070 }
2071
2072 BTIF_TRACE_DEBUG3("%s found=%d idx=%d",__FUNCTION__, found, i);
2073 return found;
2074}
2075
2076/*******************************************************************************
2077**
2078** Function btif_hl_find_avail_mcl_idx
2079**
2080** Description Find a not in-use MDL index
2081**
2082** Returns BOOLEAN
2083**
2084*******************************************************************************/
2085BOOLEAN btif_hl_find_avail_mcl_idx(UINT8 app_idx, UINT8 *p_mcl_idx){
2086 BOOLEAN found=FALSE;
2087 UINT8 i;
2088
2089 for (i=0; i < BTA_HL_NUM_MCLS ; i ++)
2090 {
2091 if (!btif_hl_cb.acb[app_idx].mcb[i].in_use)
2092 {
2093 found = TRUE;
2094 *p_mcl_idx = i;
2095 break;
2096 }
2097 }
Priti Agheraf8f30c22013-04-02 15:31:19 -07002098 BTIF_TRACE_DEBUG3("%s found=%d mcl_idx=%d", __FUNCTION__, found, i);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002099 return found;
2100}
2101
2102/*******************************************************************************
2103**
2104** Function btif_hl_find_avail_app_idx
2105**
2106** Description Find a not in-use APP index
2107**
2108** Returns BOOLEAN
2109**
2110*******************************************************************************/
2111static BOOLEAN btif_hl_find_avail_app_idx(UINT8 *p_idx){
2112 BOOLEAN found = FALSE;
2113 UINT8 i;
2114
2115 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
2116 {
2117 if (!btif_hl_cb.acb[i].in_use)
2118 {
2119 found = TRUE;
2120 *p_idx = i;
2121 break;
2122 }
2123 }
2124
2125 BTIF_TRACE_DEBUG3("%s found=%d app_idx=%d", __FUNCTION__, found, i);
2126 return found;
2127}
2128
2129
2130/*******************************************************************************
2131**
2132** Function btif_hl_proc_dereg_cfm
2133**
2134** Description Process the de-registration confirmation
2135**
2136** Returns Nothing
2137**
2138*******************************************************************************/
2139static void btif_hl_proc_dereg_cfm(tBTA_HL *p_data)
2140
2141{
2142 btif_hl_app_cb_t *p_acb;
2143 UINT8 app_idx;
2144 int app_id = 0;
2145 bthl_app_reg_state_t state = BTHL_APP_REG_STATE_DEREG_SUCCESS;
Priti Agheraf8f30c22013-04-02 15:31:19 -07002146 bt_status_t status = BT_STATUS_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002147
Priti Agheraf8f30c22013-04-02 15:31:19 -07002148 BTIF_TRACE_DEBUG3("%s de-reg status=%d app_handle=%d", __FUNCTION__,
2149 p_data->dereg_cfm.status, p_data->dereg_cfm.app_handle);
2150
2151 if (btif_hl_find_app_idx_using_app_id(p_data->dereg_cfm.app_id, &app_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002152 {
2153 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
2154 app_id = (int) p_acb->app_id;
2155 if (p_data->dereg_cfm.status == BTA_HL_STATUS_OK)
Priti Agheraf8f30c22013-04-02 15:31:19 -07002156 {
2157 btif_hl_clean_mdls_using_app_idx(app_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002158 memset(p_acb, 0,sizeof(btif_hl_app_cb_t));
Priti Agheraf8f30c22013-04-02 15:31:19 -07002159 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002160 else
2161 state = BTHL_APP_REG_STATE_DEREG_FAILED;
2162
2163 BTIF_TRACE_DEBUG2("call reg state callback app_id=%d state=%d", app_id, state);
2164 BTIF_HL_CALL_CBACK(bt_hl_callbacks, app_reg_state_cb, app_id, state );
2165
2166 if (btif_hl_is_no_active_app())
2167 {
2168 btif_hl_disable();
2169 }
2170 }
2171}
2172
2173/*******************************************************************************
2174**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002175** Function btif_hl_proc_reg_cfm
2176**
2177** Description Process the registration confirmation
2178**
2179** Returns Nothing
2180**
2181*******************************************************************************/
2182static void btif_hl_proc_reg_cfm(tBTA_HL *p_data){
2183 btif_hl_app_cb_t *p_acb;
2184 UINT8 app_idx;
2185 bthl_app_reg_state_t state = BTHL_APP_REG_STATE_REG_SUCCESS;
2186 bt_status_t bt_status;
2187
2188 BTIF_TRACE_DEBUG3("%s reg status=%d app_handle=%d", __FUNCTION__, p_data->reg_cfm.status, p_data->reg_cfm.app_handle);
2189
2190 if (btif_hl_find_app_idx(p_data->reg_cfm.app_id, &app_idx))
2191 {
2192 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002193 if (p_data->reg_cfm.status == BTA_HL_STATUS_OK)
2194 {
2195 p_acb->app_handle = p_data->reg_cfm.app_handle;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002196 }
2197 else
2198 {
2199 btif_hl_free_app_idx(app_idx);
Priti Agheraf8f30c22013-04-02 15:31:19 -07002200 reg_counter--;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002201 state = BTHL_APP_REG_STATE_REG_FAILED;
2202 }
2203
2204 BTIF_TRACE_DEBUG3("%s call reg state callback app_id=%d reg state=%d", __FUNCTION__, p_data->reg_cfm.app_id, state);
2205 BTIF_HL_CALL_CBACK(bt_hl_callbacks, app_reg_state_cb, ((int) p_data->reg_cfm.app_id), state );
2206 }
2207}
2208
2209/*******************************************************************************
2210**
2211** Function btif_hl_proc_sdp_info_ind
2212**
2213** Description Process the SDP info indication
2214**
2215** Returns Nothing
2216**
2217*******************************************************************************/
2218static void btif_hl_proc_sdp_info_ind(tBTA_HL *p_data)
2219
2220{
2221 btif_hl_app_cb_t *p_acb;
2222 UINT8 app_idx;
2223
2224 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
2225 if (btif_hl_find_app_idx_using_handle(p_data->sdp_info_ind.app_handle, &app_idx))
2226 {
2227 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
2228 memcpy(&p_acb->sdp_info_ind, &p_data->sdp_info_ind, sizeof(tBTA_HL_SDP_INFO_IND));
2229 }
2230}
2231/*******************************************************************************
2232**
2233** Function btif_hl_set_chan_cb_state
2234**
2235** Description set the channel callback state
2236**
2237** Returns void
2238**
2239*******************************************************************************/
2240void btif_hl_set_chan_cb_state(UINT8 app_idx, UINT8 mcl_idx, btif_hl_chan_cb_state_t state){
2241 btif_hl_pending_chan_cb_t *p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx);
2242 btif_hl_chan_cb_state_t cur_state = p_pcb->cb_state;
2243
2244 if (cur_state != state)
2245 {
2246 p_pcb->cb_state = state;
2247 BTIF_TRACE_DEBUG3("%s state %d--->%d",__FUNCTION__, cur_state, state);
2248 }
2249
2250
2251}
2252/*******************************************************************************
2253**
2254** Function btif_hl_send_destroyed_cb
2255**
2256** Description send the channel destroyed callback
2257**
2258** Returns void
2259**
2260*******************************************************************************/
2261void btif_hl_send_destroyed_cb(btif_hl_app_cb_t *p_acb ){
2262 bt_bdaddr_t bd_addr;
2263 int app_id = (int) btif_hl_get_app_id(p_acb->delete_mdl.channel_id);
2264
2265 btif_hl_copy_bda(&bd_addr, p_acb->delete_mdl.bd_addr);
2266 BTIF_TRACE_DEBUG1("%s",__FUNCTION__);
2267 BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d, state=%d fd=%d",p_acb->delete_mdl.channel_id,
2268 p_acb->delete_mdl.mdep_cfg_idx, BTHL_CONN_STATE_DESTROYED, 0);
2269 btif_hl_display_bt_bda(&bd_addr);
2270
2271 BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id,
2272 &bd_addr, p_acb->delete_mdl.mdep_cfg_idx,
2273 p_acb->delete_mdl.channel_id, BTHL_CONN_STATE_DESTROYED, 0 );
2274}
2275/*******************************************************************************
2276**
2277** Function btif_hl_send_disconnecting_cb
2278**
2279** Description send a channel disconnecting callback
2280**
2281** Returns void
2282**
2283*******************************************************************************/
2284void btif_hl_send_disconnecting_cb(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx){
2285 btif_hl_mdl_cb_t *p_dcb = BTIF_HL_GET_MDL_CB_PTR( app_idx, mcl_idx, mdl_idx);
2286 btif_hl_soc_cb_t *p_scb = p_dcb->p_scb;
2287 bt_bdaddr_t bd_addr;
2288 int app_id = (int) btif_hl_get_app_id(p_scb->channel_id);
2289
2290 btif_hl_copy_bda(&bd_addr, p_scb->bd_addr);
2291
2292 BTIF_TRACE_DEBUG1("%s",__FUNCTION__);
2293 BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d, state=%d fd=%d",p_scb->channel_id,
2294 p_scb->mdep_cfg_idx, BTHL_CONN_STATE_DISCONNECTING, p_scb->socket_id[0]);
2295 btif_hl_display_bt_bda(&bd_addr);
2296 BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id,
2297 &bd_addr, p_scb->mdep_cfg_idx,
2298 p_scb->channel_id, BTHL_CONN_STATE_DISCONNECTING, p_scb->socket_id[0] );
2299}
2300/*******************************************************************************
2301**
2302** Function btif_hl_send_setup_connecting_cb
2303**
2304** Description send a channel connecting callback
2305**
2306** Returns void
2307**
2308*******************************************************************************/
2309void btif_hl_send_setup_connecting_cb(UINT8 app_idx, UINT8 mcl_idx){
2310 btif_hl_pending_chan_cb_t *p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx);
2311 bt_bdaddr_t bd_addr;
2312 int app_id = (int) btif_hl_get_app_id(p_pcb->channel_id);
2313
2314 btif_hl_copy_bda(&bd_addr, p_pcb->bd_addr);
2315
2316 if (p_pcb->in_use && p_pcb->cb_state == BTIF_HL_CHAN_CB_STATE_CONNECTING_PENDING)
2317 {
2318 BTIF_TRACE_DEBUG1("%s",__FUNCTION__);
2319 BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id,
2320 p_pcb->mdep_cfg_idx, BTHL_CONN_STATE_CONNECTING, 0);
2321 btif_hl_display_bt_bda(&bd_addr);
2322
2323 BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id,
2324 &bd_addr, p_pcb->mdep_cfg_idx,
2325 p_pcb->channel_id, BTHL_CONN_STATE_CONNECTING, 0 );
2326 btif_hl_set_chan_cb_state(app_idx, mcl_idx, BTIF_HL_CHAN_CB_STATE_CONNECTED_PENDING);
2327 }
2328}
2329/*******************************************************************************
2330**
2331** Function btif_hl_send_setup_disconnected_cb
2332**
2333** Description send a channel disconnected callback
2334**
2335** Returns void
2336**
2337*******************************************************************************/
2338void btif_hl_send_setup_disconnected_cb(UINT8 app_idx, UINT8 mcl_idx){
2339 btif_hl_pending_chan_cb_t *p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx);
2340 bt_bdaddr_t bd_addr;
2341 int app_id = (int) btif_hl_get_app_id(p_pcb->channel_id);
2342
2343 btif_hl_copy_bda(&bd_addr, p_pcb->bd_addr);
2344
2345 BTIF_TRACE_DEBUG2("%s p_pcb->in_use=%d",__FUNCTION__, p_pcb->in_use);
2346 if (p_pcb->in_use)
2347 {
2348 BTIF_TRACE_DEBUG1("%p_pcb->cb_state=%d",p_pcb->cb_state);
2349 if (p_pcb->cb_state == BTIF_HL_CHAN_CB_STATE_CONNECTING_PENDING)
2350 {
2351 BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id,
2352 p_pcb->mdep_cfg_idx, BTHL_CONN_STATE_CONNECTING, 0);
2353 btif_hl_display_bt_bda(&bd_addr);
2354 BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id,
2355 &bd_addr, p_pcb->mdep_cfg_idx,
2356 p_pcb->channel_id, BTHL_CONN_STATE_CONNECTING, 0 );
2357
2358 BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id,
2359 p_pcb->mdep_cfg_idx, BTHL_CONN_STATE_DISCONNECTED, 0);
2360 btif_hl_display_bt_bda(&bd_addr);
2361 BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id,
2362 &bd_addr, p_pcb->mdep_cfg_idx,
2363 p_pcb->channel_id, BTHL_CONN_STATE_DISCONNECTED, 0 );
2364 }
2365 else if (p_pcb->cb_state == BTIF_HL_CHAN_CB_STATE_CONNECTED_PENDING)
2366 {
2367 BTIF_TRACE_DEBUG4("call channel state callback channel_id=0x%08x mdep_cfg_idx=%d state=%d fd=%d",p_pcb->channel_id,
2368 p_pcb->mdep_cfg_idx, BTHL_CONN_STATE_DISCONNECTED, 0);
2369 btif_hl_display_bt_bda(&bd_addr);
2370 BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, app_id,
2371 &bd_addr, p_pcb->mdep_cfg_idx,
2372 p_pcb->channel_id, BTHL_CONN_STATE_DISCONNECTED, 0 );
2373 }
2374 btif_hl_clean_pcb(p_pcb);
2375 }
2376}
2377/*******************************************************************************
2378**
2379** Function btif_hl_proc_sdp_query_cfm
2380**
2381** Description Process the SDP query confirmation
2382**
2383** Returns Nothing
2384**
2385*******************************************************************************/
2386static BOOLEAN btif_hl_proc_sdp_query_cfm(tBTA_HL *p_data){
2387 btif_hl_app_cb_t *p_acb;
2388 btif_hl_mcl_cb_t *p_mcb;
2389 tBTA_HL_SDP *p_sdp;
2390 tBTA_HL_CCH_OPEN_PARAM open_param;
2391 UINT8 app_idx, mcl_idx, sdp_idx = 0;
2392 UINT8 num_recs, i, num_mdeps, j;
2393 btif_hl_cch_op_t old_cch_oper;
2394 BOOLEAN status =FALSE;
2395 btif_hl_pending_chan_cb_t *p_pcb;
2396
2397 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
2398
2399 p_sdp = p_data->sdp_query_cfm.p_sdp;
2400 num_recs = p_sdp->num_recs;
2401
2402 BTIF_TRACE_DEBUG1("num of SDP records=%d",num_recs);
2403 for (i=0; i<num_recs; i++)
2404 {
2405 BTIF_TRACE_DEBUG3("rec_idx=%d ctrl_psm=0x%x data_psm=0x%x",
2406 (i+1),p_sdp->sdp_rec[i].ctrl_psm, p_sdp->sdp_rec[i].data_psm);
2407 BTIF_TRACE_DEBUG1("MCAP supported procedures=0x%x",p_sdp->sdp_rec[i].mcap_sup_proc);
2408 num_mdeps = p_sdp->sdp_rec[i].num_mdeps;
2409 BTIF_TRACE_DEBUG1("num of mdeps =%d",num_mdeps);
2410 for (j=0; j< num_mdeps; j++)
2411 {
2412 BTIF_TRACE_DEBUG4("mdep_idx=%d mdep_id=0x%x data_type=0x%x mdep_role=0x%x",
2413 (j+1),
2414 p_sdp->sdp_rec[i].mdep_cfg[j].mdep_id,
2415 p_sdp->sdp_rec[i].mdep_cfg[j].data_type,
2416 p_sdp->sdp_rec[i].mdep_cfg[j].mdep_role );
2417 }
2418 }
2419
Priti Agheraf8f30c22013-04-02 15:31:19 -07002420 if (btif_hl_find_app_idx_using_app_id(p_data->sdp_query_cfm.app_id, &app_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002421 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07002422 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
2423
2424 if (btif_hl_find_mcl_idx(app_idx, p_data->sdp_query_cfm.bd_addr, &mcl_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002425 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07002426 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2427 if (p_mcb->cch_oper != BTIF_HL_CCH_OP_NONE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002428 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07002429 memcpy(&p_mcb->sdp, p_sdp, sizeof(tBTA_HL_SDP));
2430 old_cch_oper = p_mcb->cch_oper;
2431 p_mcb->cch_oper = BTIF_HL_CCH_OP_NONE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002432
2433 switch (old_cch_oper)
2434 {
2435 case BTIF_HL_CCH_OP_MDEP_FILTERING:
Priti Agheraf8f30c22013-04-02 15:31:19 -07002436 status = btif_hl_find_sdp_idx_using_mdep_filter(app_idx,
2437 mcl_idx, &sdp_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002438 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002439 default:
The Android Open Source Project5738f832012-12-12 16:00:35 -08002440 break;
2441 }
2442
Priti Agheraf8f30c22013-04-02 15:31:19 -07002443 if (status)
2444 {
2445 p_mcb->sdp_idx = sdp_idx;
2446 p_mcb->valid_sdp_idx = TRUE;
2447 p_mcb->ctrl_psm = p_mcb->sdp.sdp_rec[sdp_idx].ctrl_psm;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002448
Priti Agheraf8f30c22013-04-02 15:31:19 -07002449 switch (old_cch_oper)
2450 {
2451 case BTIF_HL_CCH_OP_MDEP_FILTERING:
2452 p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx);
2453 if (p_pcb->in_use)
2454 {
2455 if (!p_pcb->abort_pending)
2456 {
2457 switch (p_pcb->op)
2458 {
2459 case BTIF_HL_PEND_DCH_OP_OPEN:
2460 btif_hl_send_setup_connecting_cb(app_idx, mcl_idx);
2461 break;
2462 case BTIF_HL_PEND_DCH_OP_DELETE_MDL:
2463 default:
2464 break;
2465 }
2466 open_param.ctrl_psm = p_mcb->ctrl_psm;
2467 bdcpy(open_param.bd_addr, p_mcb->bd_addr);
2468 open_param.sec_mask =
2469 (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
2470 BTA_HlCchOpen(p_acb->app_id,p_acb->app_handle, &open_param);
2471 }
2472 else
2473 {
2474 BTIF_TRACE_DEBUG0("channel abort pending");
2475 }
2476 }
2477 break;
2478
2479 case BTIF_HL_CCH_OP_DCH_OPEN:
2480 status = btif_hl_proc_pending_op(app_idx,mcl_idx);
2481 break;
2482
2483 default:
2484 BTIF_TRACE_ERROR1("Invalid CCH oper %d", old_cch_oper);
2485 break;
2486 }
2487 }
2488 else
2489 {
2490 BTIF_TRACE_ERROR0("Can not find SDP idx discard CCH Open request");
2491 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002492 }
2493 }
2494 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002495 return status;
2496}
2497
2498
2499/*******************************************************************************
2500**
2501** Function btif_hl_proc_cch_open_ind
2502**
2503** Description Process the CCH open indication
2504**
2505** Returns Nothing
2506**
2507*******************************************************************************/
2508static void btif_hl_proc_cch_open_ind(tBTA_HL *p_data)
2509
2510{
2511 btif_hl_mcl_cb_t *p_mcb;
2512 UINT8 app_idx, mcl_idx;
Priti Agheraf8f30c22013-04-02 15:31:19 -07002513 int i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002514
2515 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
Priti Agheraf8f30c22013-04-02 15:31:19 -07002516 for(i=0; i<BTA_HL_NUM_APPS; i++)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002517 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07002518 if (btif_hl_cb.acb[i].in_use)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002519 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07002520 if (!btif_hl_find_mcl_idx(i, p_data->cch_open_ind.bd_addr, &mcl_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002521 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07002522 if (btif_hl_find_avail_mcl_idx(i, &mcl_idx))
2523 {
2524 p_mcb = BTIF_HL_GET_MCL_CB_PTR(i, mcl_idx);
2525 memset(p_mcb, 0, sizeof(btif_hl_mcl_cb_t));
2526 p_mcb->in_use = TRUE;
2527 p_mcb->is_connected = TRUE;
2528 p_mcb->mcl_handle = p_data->cch_open_ind.mcl_handle;
2529 bdcpy(p_mcb->bd_addr, p_data->cch_open_ind.bd_addr);
2530 btif_hl_start_cch_timer(i, mcl_idx);
2531 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002532 }
Priti Agheraf8f30c22013-04-02 15:31:19 -07002533 else
2534 {
2535 BTIF_TRACE_ERROR0("The MCL already exist for cch_open_ind");
2536 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002537 }
2538 }
2539}
2540
2541/*******************************************************************************
2542**
2543** Function btif_hl_proc_pending_op
2544**
2545** Description Process the pending dch operation.
2546**
2547** Returns Nothing
2548**
2549*******************************************************************************/
2550BOOLEAN btif_hl_proc_pending_op(UINT8 app_idx, UINT8 mcl_idx)
2551
2552{
2553
2554 btif_hl_app_cb_t *p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
2555 btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2556 btif_hl_pending_chan_cb_t *p_pcb;
2557 BOOLEAN status = FALSE;
2558 tBTA_HL_DCH_OPEN_PARAM dch_open;
2559 tBTA_HL_MDL_ID mdl_id;
2560 tBTA_HL_DCH_RECONNECT_PARAM reconnect_param;
2561
2562 p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx);
2563 if (p_pcb->in_use)
2564 {
2565 switch (p_pcb->op)
2566 {
2567 case BTIF_HL_PEND_DCH_OP_OPEN:
2568 if (!p_pcb->abort_pending)
2569 {
2570 BTIF_TRACE_DEBUG0("op BTIF_HL_PEND_DCH_OP_OPEN");
2571 dch_open.ctrl_psm = p_mcb->ctrl_psm;
2572 dch_open.local_mdep_id = p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_id;
2573 if (btif_hl_find_peer_mdep_id(p_acb->app_id, p_mcb->bd_addr,
2574 p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_cfg.mdep_role,
2575 p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_cfg.data_cfg[0].data_type, &dch_open.peer_mdep_id ))
2576 {
2577 dch_open.local_cfg = p_acb->channel_type[p_pcb->mdep_cfg_idx];
2578 if ((p_acb->sup_feature.mdep[p_pcb->mdep_cfg_idx].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SOURCE)
2579 && !btif_hl_is_the_first_reliable_existed(app_idx, mcl_idx))
2580 {
2581 dch_open.local_cfg = BTA_HL_DCH_CFG_RELIABLE;
2582 }
2583 dch_open.sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
2584 BTIF_TRACE_DEBUG1("dch_open.local_cfg=%d ", dch_open.local_cfg);
2585 btif_hl_send_setup_connecting_cb(app_idx,mcl_idx);
2586
2587 if (!btif_hl_is_reconnect_possible(app_idx, mcl_idx, p_pcb->mdep_cfg_idx, &dch_open, &mdl_id ))
2588 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07002589 BTIF_TRACE_DEBUG1("Issue DCH open, mcl_handle=%d",p_mcb->mcl_handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002590 BTA_HlDchOpen(p_mcb->mcl_handle, &dch_open);
2591 }
2592 else
2593 {
2594 reconnect_param.ctrl_psm = p_mcb->ctrl_psm;
2595 reconnect_param.mdl_id = mdl_id;;
2596 BTIF_TRACE_DEBUG2("Issue Reconnect ctrl_psm=0x%x mdl_id=0x%x",reconnect_param.ctrl_psm, reconnect_param.mdl_id);
2597 BTA_HlDchReconnect(p_mcb->mcl_handle, &reconnect_param);
2598 }
2599 status = TRUE;
2600 }
2601 }
2602 else
2603 {
2604 btif_hl_send_setup_disconnected_cb(app_idx, mcl_idx);
2605 status = TRUE;
2606 }
2607 break;
2608 case BTIF_HL_PEND_DCH_OP_DELETE_MDL:
2609 BTA_HlDeleteMdl(p_mcb->mcl_handle, p_acb->delete_mdl.mdl_id);
2610 status = TRUE;
2611 break;
2612
2613 default:
2614 break;
2615 }
2616 }
2617 return status;
2618}
2619
2620/*******************************************************************************
2621**
2622** Function btif_hl_proc_cch_open_cfm
2623**
2624** Description Process the CCH open confirmation
2625**
2626** Returns Nothing
2627**
2628*******************************************************************************/
2629static BOOLEAN btif_hl_proc_cch_open_cfm(tBTA_HL *p_data)
2630
2631{
2632 btif_hl_app_cb_t *p_acb;
2633 btif_hl_mcl_cb_t *p_mcb;
2634 UINT8 app_idx, mcl_idx;
2635 BOOLEAN status = FALSE;
2636 tBTA_HL_DCH_OPEN_PARAM dch_open;
2637
2638
2639 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
2640
Priti Agheraf8f30c22013-04-02 15:31:19 -07002641 if (btif_hl_find_app_idx_using_app_id(p_data->cch_open_cfm.app_id, &app_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002642 {
2643 BTIF_TRACE_DEBUG1("app_idx=%d", app_idx);
2644 if (btif_hl_find_mcl_idx(app_idx, p_data->cch_open_cfm.bd_addr, &mcl_idx))
2645 {
2646 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
2647
2648 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Priti Agheraf8f30c22013-04-02 15:31:19 -07002649 BTIF_TRACE_DEBUG2("mcl_idx=%d, mcl_handle=%d", mcl_idx,p_data->cch_open_cfm.mcl_handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002650 p_mcb->mcl_handle = p_data->cch_open_cfm.mcl_handle;
2651 p_mcb->is_connected = TRUE;
2652 status = btif_hl_proc_pending_op(app_idx, mcl_idx);
2653 if (status)
2654 btif_hl_start_cch_timer(app_idx, mcl_idx);
2655 }
2656 }
2657
2658 return status;
2659}
2660
Priti Agheraf8f30c22013-04-02 15:31:19 -07002661/*******************************************************************************
2662**
2663** Function btif_hl_clean_mcb_using_handle
2664**
2665** Description clean control channel cb using handle
2666**
2667** Returns void
2668**
2669*******************************************************************************/
2670static void btif_hl_clean_mcb_using_handle( tBTA_HL_MCL_HANDLE mcl_handle){
2671 btif_hl_app_cb_t *p_acb;
2672 UINT8 i,j;
2673
2674 for (i=0; i<BTA_HL_NUM_APPS; i++)
2675 {
2676 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
2677 for (j=0; j < BTA_HL_NUM_MCLS ; j++)
2678 {
2679 if (p_acb->mcb[j].in_use)
2680 BTIF_TRACE_DEBUG3("btif_hl_find_mcl_idx_using_handle: app_idx=%d,"
2681 "mcl_idx =%d mcl_handle=%d",i,j,p_acb->mcb[j].mcl_handle);
2682 if (p_acb->mcb[j].in_use &&
2683 (p_acb->mcb[j].mcl_handle == mcl_handle))
2684 {
2685 btif_hl_stop_cch_timer(i, j);
2686 btif_hl_release_mcl_sockets(i, j);
2687 btif_hl_send_setup_disconnected_cb(i, j);
2688 btif_hl_clean_mcl_cb(i, j);
2689 }
2690 }
2691 }
2692}
The Android Open Source Project5738f832012-12-12 16:00:35 -08002693
2694/*******************************************************************************
2695**
2696** Function btif_hl_proc_cch_close_ind
2697**
2698** Description Process the CCH close indication
2699**
2700** Returns Nothing
2701**
2702*******************************************************************************/
2703static void btif_hl_proc_cch_close_ind(tBTA_HL *p_data)
2704
2705{
2706 UINT8 app_idx, mcl_idx;
2707 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
2708
Priti Agheraf8f30c22013-04-02 15:31:19 -07002709 btif_hl_clean_mcb_using_handle(p_data->cch_close_ind.mcl_handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002710}
2711
2712
2713/*******************************************************************************
2714**
2715** Function btif_hl_proc_cch_close_cfm
2716**
2717** Description Process the CCH close confirmation
2718**
2719** Returns Nothing
2720**
2721*******************************************************************************/
2722static void btif_hl_proc_cch_close_cfm(tBTA_HL *p_data)
2723{
2724 UINT8 app_idx, mcl_idx;
2725 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
2726
Priti Agheraf8f30c22013-04-02 15:31:19 -07002727 btif_hl_clean_mcb_using_handle(p_data->cch_close_ind.mcl_handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002728}
2729
2730/*******************************************************************************
2731**
2732** Function btif_hl_proc_create_ind
2733**
2734** Description Process the MDL create indication
2735**
2736** Returns Nothing
2737**
2738*******************************************************************************/
2739static void btif_hl_proc_create_ind(tBTA_HL *p_data){
2740 btif_hl_app_cb_t *p_acb;
2741 btif_hl_mcl_cb_t *p_mcb;
2742 tBTA_HL_MDEP *p_mdep;
Priti Agheraf8f30c22013-04-02 15:31:19 -07002743 UINT8 app_idx, orig_app_idx, mcl_idx, mdep_cfg_idx;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002744 BOOLEAN first_reliable_exist;
2745 BOOLEAN success = TRUE;
2746 tBTA_HL_DCH_CFG rsp_cfg = BTA_HL_DCH_CFG_UNKNOWN;
2747 tBTA_HL_DCH_CREATE_RSP rsp_code = BTA_HL_DCH_CREATE_RSP_CFG_REJ;
2748 tBTA_HL_DCH_CREATE_RSP_PARAM create_rsp_param;
2749
2750 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
2751
Priti Agheraf8f30c22013-04-02 15:31:19 -07002752// Find the correct app_idx based on the mdep_id;
2753 btif_hl_find_app_idx_using_mdepId(p_data->dch_create_ind.local_mdep_id,&orig_app_idx);
2754 if (btif_hl_find_mcl_idx(orig_app_idx, p_data->dch_create_ind.bd_addr, &mcl_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002755 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07002756 p_acb =BTIF_HL_GET_APP_CB_PTR(orig_app_idx);
2757 p_mcb =BTIF_HL_GET_MCL_CB_PTR(orig_app_idx, mcl_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002758
Priti Agheraf8f30c22013-04-02 15:31:19 -07002759 if (btif_hl_find_mdep_cfg_idx(orig_app_idx, p_data->dch_create_ind.local_mdep_id, &mdep_cfg_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002760 {
2761 p_mdep = &(p_acb->sup_feature.mdep[mdep_cfg_idx]);
Priti Agheraf8f30c22013-04-02 15:31:19 -07002762 first_reliable_exist = btif_hl_is_the_first_reliable_existed(orig_app_idx, mcl_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002763 switch (p_mdep->mdep_cfg.mdep_role)
2764 {
2765 case BTA_HL_MDEP_ROLE_SOURCE:
2766 if (p_data->dch_create_ind.cfg == BTA_HL_DCH_CFG_NO_PREF)
2767 {
2768 if (first_reliable_exist)
2769 {
2770 rsp_cfg = p_acb->channel_type[mdep_cfg_idx];
2771 }
2772 else
2773 {
2774 rsp_cfg = BTA_HL_DCH_CFG_RELIABLE;
2775 }
2776 rsp_code = BTA_HL_DCH_CREATE_RSP_SUCCESS;
2777 }
2778
2779 break;
2780 case BTA_HL_MDEP_ROLE_SINK:
2781
Priti Agheraf8f30c22013-04-02 15:31:19 -07002782 BTIF_TRACE_DEBUG0("btif_hl_proc_create_ind:BTA_HL_MDEP_ROLE_SINK");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002783 if ((p_data->dch_create_ind.cfg == BTA_HL_DCH_CFG_RELIABLE) ||
2784 (first_reliable_exist && (p_data->dch_create_ind.cfg == BTA_HL_DCH_CFG_STREAMING)))
2785 {
2786 rsp_code = BTA_HL_DCH_CREATE_RSP_SUCCESS;
2787 rsp_cfg = p_data->dch_create_ind.cfg;
Priti Agheraf8f30c22013-04-02 15:31:19 -07002788 BTIF_TRACE_DEBUG1("btif_hl_proc_create_ind:BTA_HL_MDEP_ROLE_SINK cfg = %d",rsp_cfg);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002789 }
2790 break;
2791 default:
2792 break;
2793 }
2794 }
2795 }
2796 else
2797 {
2798 success = FALSE;
2799 }
2800
2801 if (success)
2802 {
2803 BTIF_TRACE_DEBUG2("create response rsp_code=%d rsp_cfg=%d", rsp_code, rsp_cfg );
2804 create_rsp_param.local_mdep_id = p_data->dch_create_ind.local_mdep_id;
2805 create_rsp_param.mdl_id = p_data->dch_create_ind.mdl_id;
2806 create_rsp_param.rsp_code = rsp_code;
2807 create_rsp_param.cfg_rsp = rsp_cfg;
2808 BTA_HlDchCreateRsp(p_mcb->mcl_handle, &create_rsp_param);
2809 }
2810}
2811
2812/*******************************************************************************
2813**
2814** Function btif_hl_proc_dch_open_ind
2815**
2816** Description Process the DCH open indication
2817**
2818** Returns Nothing
2819**
2820*******************************************************************************/
2821static void btif_hl_proc_dch_open_ind(tBTA_HL *p_data)
2822
2823{
2824 btif_hl_app_cb_t *p_acb;
2825 btif_hl_mcl_cb_t *p_mcb;
2826 btif_hl_mdl_cb_t *p_dcb;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002827 UINT8 orig_app_idx, mcl_idx, mdl_idx, mdep_cfg_idx;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002828 UINT8 dc_cfg;
2829 BOOLEAN close_dch = FALSE;
2830
2831 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
2832
Priti Agheraf8f30c22013-04-02 15:31:19 -07002833 // Find the correct app_idx based on the mdep_id;
2834 btif_hl_find_app_idx_using_mdepId(p_data->dch_open_ind.local_mdep_id,&orig_app_idx);
2835
2836 if (btif_hl_find_mcl_idx_using_app_idx(p_data->dch_open_ind.mcl_handle, orig_app_idx, &mcl_idx ))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002837 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07002838 p_acb =BTIF_HL_GET_APP_CB_PTR(orig_app_idx);
2839 p_mcb =BTIF_HL_GET_MCL_CB_PTR(orig_app_idx, mcl_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002840
Priti Agheraf8f30c22013-04-02 15:31:19 -07002841 if (btif_hl_find_avail_mdl_idx(orig_app_idx, mcl_idx, &mdl_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002842 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07002843 p_dcb = BTIF_HL_GET_MDL_CB_PTR(orig_app_idx, mcl_idx, mdl_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002844
Priti Agheraf8f30c22013-04-02 15:31:19 -07002845 if (btif_hl_find_mdep_cfg_idx(orig_app_idx, p_data->dch_open_ind.local_mdep_id, &mdep_cfg_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002846 {
2847 p_dcb->in_use = TRUE;
2848 p_dcb->mdl_handle = p_data->dch_open_ind.mdl_handle;
2849 p_dcb->local_mdep_cfg_idx = mdep_cfg_idx;
2850 p_dcb->local_mdep_id = p_data->dch_open_ind.local_mdep_id;
2851 p_dcb->mdl_id = p_data->dch_open_ind.mdl_id;
2852 p_dcb->dch_mode = p_data->dch_open_ind.dch_mode;
2853 p_dcb->dch_mode = p_data->dch_open_ind.dch_mode;
2854 p_dcb->is_the_first_reliable = p_data->dch_open_ind.first_reliable;
2855 p_dcb->mtu = p_data->dch_open_ind.mtu;
2856
Priti Agheraf8f30c22013-04-02 15:31:19 -07002857 if(btif_hl_find_channel_id_using_mdl_id(orig_app_idx,p_dcb->mdl_id , &p_dcb->channel_id))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002858 {
2859 BTIF_TRACE_DEBUG4(" app_idx=%d mcl_idx=%d mdl_idx=%d channel_id=%d",
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002860 orig_app_idx, mcl_idx, mdl_idx, p_dcb->channel_id );
Priti Agheraf8f30c22013-04-02 15:31:19 -07002861 if (!btif_hl_create_socket(orig_app_idx, mcl_idx, mdl_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002862 {
2863 BTIF_TRACE_ERROR0("Unable to create socket");
2864 close_dch = TRUE;
2865 }
2866 }
2867 else
2868 {
2869 BTIF_TRACE_ERROR1("Unable find channel id for mdl_id=0x%x", p_dcb->mdl_id );
2870 close_dch = TRUE;
2871 }
2872 }
2873 else
2874 {
2875 BTIF_TRACE_ERROR1("INVALID_LOCAL_MDEP_ID mdep_id=%d",p_data->dch_open_cfm.local_mdep_id);
2876 close_dch = TRUE;
2877 }
2878
2879 if (close_dch)
2880 btif_hl_clean_mdl_cb(p_dcb);
2881 }
2882 else
2883 close_dch = TRUE;
2884 }
2885 else
2886 close_dch = TRUE;
2887
2888 if (close_dch)
2889 BTA_HlDchClose(p_data->dch_open_cfm.mdl_handle);
2890}
2891
2892/*******************************************************************************
2893**
2894** Function btif_hl_proc_dch_open_cfm
2895**
2896** Description Process the DCH close confirmation
2897**
2898** Returns Nothing
2899**
2900*******************************************************************************/
2901static BOOLEAN btif_hl_proc_dch_open_cfm(tBTA_HL *p_data)
2902
2903{
2904 btif_hl_app_cb_t *p_acb;
2905 btif_hl_mcl_cb_t *p_mcb;
2906 btif_hl_mdl_cb_t *p_dcb;
2907 btif_hl_pending_chan_cb_t *p_pcb;
2908 UINT8 app_idx, mcl_idx, mdl_idx, mdep_cfg_idx;
2909 BOOLEAN status = FALSE;
2910 BOOLEAN close_dch = FALSE;
2911
2912 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
2913
Priti Agheraf8f30c22013-04-02 15:31:19 -07002914 // Find the correct app_idx based on the mdep_id;
2915 btif_hl_find_app_idx_using_mdepId(p_data->dch_open_cfm.local_mdep_id,&app_idx);
2916
2917 if (btif_hl_find_mcl_idx_using_app_idx(p_data->dch_open_cfm.mcl_handle, app_idx, &mcl_idx ))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002918 {
2919 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
2920 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2921 p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx);
2922
2923 if (btif_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx))
2924 {
2925 p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
2926
2927 if (btif_hl_find_mdep_cfg_idx(app_idx, p_data->dch_open_cfm.local_mdep_id, &mdep_cfg_idx))
2928 {
2929 p_dcb->in_use = TRUE;
2930 p_dcb->mdl_handle = p_data->dch_open_cfm.mdl_handle;
2931 p_dcb->local_mdep_cfg_idx = mdep_cfg_idx;
2932 p_dcb->local_mdep_id = p_data->dch_open_cfm.local_mdep_id;
2933 p_dcb->mdl_id = p_data->dch_open_cfm.mdl_id;
2934 p_dcb->dch_mode = p_data->dch_open_cfm.dch_mode;
2935 p_dcb->is_the_first_reliable= p_data->dch_open_cfm.first_reliable;
2936 p_dcb->mtu = p_data->dch_open_cfm.mtu;
2937 p_dcb->channel_id = p_pcb->channel_id;
2938
2939 BTIF_TRACE_DEBUG3("app_idx=%d mcl_idx=%d mdl_idx=%d", app_idx, mcl_idx, mdl_idx );
2940 btif_hl_send_setup_connecting_cb(app_idx, mcl_idx);
2941 if (btif_hl_create_socket(app_idx, mcl_idx, mdl_idx))
2942 {
2943 status = TRUE;
2944 BTIF_TRACE_DEBUG4("app_idx=%d mcl_idx=%d mdl_idx=%d p_dcb->channel_id=0x%08x",
2945 app_idx, mcl_idx, mdl_idx, p_dcb->channel_id);
2946 btif_hl_clean_pcb(p_pcb);
2947 }
2948 else
2949 {
2950 BTIF_TRACE_ERROR0("Unable to create socket");
2951 close_dch = TRUE;
2952 }
2953 }
2954 else
2955 {
2956 BTIF_TRACE_ERROR1("INVALID_LOCAL_MDEP_ID mdep_id=%d",p_data->dch_open_cfm.local_mdep_id);
2957 close_dch = TRUE;
2958 }
2959
2960 if (close_dch)
2961 {
2962 btif_hl_clean_mdl_cb(p_dcb);
2963 BTA_HlDchClose(p_data->dch_open_cfm.mdl_handle);
2964 }
2965 }
2966 }
2967
2968 return status;
2969}
2970/*******************************************************************************
2971**
2972** Function btif_hl_proc_dch_reconnect_cfm
2973**
2974** Description Process the DCH reconnect indication
2975**
2976** Returns Nothing
2977**
2978*******************************************************************************/
2979static BOOLEAN btif_hl_proc_dch_reconnect_cfm(tBTA_HL *p_data)
2980{
2981 btif_hl_app_cb_t *p_acb;
2982 btif_hl_mcl_cb_t *p_mcb;
2983 btif_hl_mdl_cb_t *p_dcb;
2984 btif_hl_pending_chan_cb_t *p_pcb;
2985 UINT8 app_idx, mcl_idx, mdl_idx, mdep_cfg_idx;
2986 BOOLEAN status = FALSE;
2987 BOOLEAN close_dch = FALSE;
2988
2989 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
2990
Priti Agheraf8f30c22013-04-02 15:31:19 -07002991 btif_hl_find_app_idx_using_mdepId(p_data->dch_reconnect_cfm.local_mdep_id,&app_idx);
2992
2993 if (btif_hl_find_mcl_idx_using_app_idx(p_data->dch_reconnect_cfm.mcl_handle, app_idx, &mcl_idx ))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002994 {
2995 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
2996 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2997 p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx);
2998
2999 if (btif_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx))
3000 {
3001 p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
3002
3003 if (btif_hl_find_mdep_cfg_idx(app_idx, p_data->dch_reconnect_cfm.local_mdep_id, &mdep_cfg_idx))
3004 {
3005 p_dcb->in_use = TRUE;
3006 p_dcb->mdl_handle = p_data->dch_reconnect_cfm.mdl_handle;
3007 p_dcb->local_mdep_cfg_idx = mdep_cfg_idx;
3008 p_dcb->local_mdep_id = p_data->dch_reconnect_cfm.local_mdep_id;
3009 p_dcb->mdl_id = p_data->dch_reconnect_cfm.mdl_id;
3010 p_dcb->dch_mode = p_data->dch_reconnect_cfm.dch_mode;
3011 p_dcb->is_the_first_reliable= p_data->dch_reconnect_cfm.first_reliable;
3012 p_dcb->mtu = p_data->dch_reconnect_cfm.mtu;
3013 p_dcb->channel_id = p_pcb->channel_id;
3014
3015 BTIF_TRACE_DEBUG3("app_idx=%d mcl_idx=%d mdl_idx=%d", app_idx, mcl_idx, mdl_idx );
3016 btif_hl_send_setup_connecting_cb(app_idx, mcl_idx);
3017 if (btif_hl_create_socket(app_idx, mcl_idx, mdl_idx))
3018 {
3019 status = TRUE;
3020 BTIF_TRACE_DEBUG4("app_idx=%d mcl_idx=%d mdl_idx=%d p_dcb->channel_id=0x%08x",
3021 app_idx, mcl_idx, mdl_idx, p_dcb->channel_id);
3022 btif_hl_clean_pcb(p_pcb);
3023 }
3024 else
3025 {
3026 BTIF_TRACE_ERROR0("Unable to create socket");
3027 close_dch = TRUE;
3028 }
3029 }
3030 else
3031 {
3032 BTIF_TRACE_ERROR1("INVALID_LOCAL_MDEP_ID mdep_id=%d",p_data->dch_open_cfm.local_mdep_id);
3033 close_dch = TRUE;
3034 }
3035
3036 if (close_dch)
3037 {
3038 btif_hl_clean_mdl_cb(p_dcb);
3039 BTA_HlDchClose(p_data->dch_reconnect_cfm.mdl_handle);
3040 }
3041 }
3042 }
3043
3044 return status;
3045
3046}
3047/*******************************************************************************
3048**
3049** Function btif_hl_proc_dch_reconnect_ind
3050**
3051** Description Process the DCH reconnect indication
3052**
3053** Returns Nothing
3054**
3055*******************************************************************************/
3056static void btif_hl_proc_dch_reconnect_ind(tBTA_HL *p_data)
3057
3058{
3059 btif_hl_app_cb_t *p_acb;
3060 btif_hl_mcl_cb_t *p_mcb;
3061 btif_hl_mdl_cb_t *p_dcb;
3062 UINT8 app_idx, mcl_idx, mdl_idx, mdep_cfg_idx, dc_cfg;
3063 BOOLEAN close_dch = FALSE;
3064
3065 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
3066
Priti Agheraf8f30c22013-04-02 15:31:19 -07003067 // Find the correct app_idx based on the mdep_id;
3068 btif_hl_find_app_idx_using_mdepId(p_data->dch_reconnect_ind.local_mdep_id,&app_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003069
Priti Agheraf8f30c22013-04-02 15:31:19 -07003070 if (btif_hl_find_mcl_idx_using_app_idx(p_data->dch_reconnect_ind.mcl_handle, app_idx, &mcl_idx ))
The Android Open Source Project5738f832012-12-12 16:00:35 -08003071 {
3072 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
Priti Agheraf8f30c22013-04-02 15:31:19 -07003073 BTIF_TRACE_DEBUG2("btif_hl_proc_dch_reconnect_ind: app_idx = %d, mcl_idx = %d",
3074 app_idx, mcl_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003075 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
3076
3077 if (btif_hl_find_avail_mdl_idx(app_idx, mcl_idx, &mdl_idx))
3078 {
3079 p_dcb =BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
3080
3081 if (btif_hl_find_mdep_cfg_idx(app_idx, p_data->dch_reconnect_ind.local_mdep_id, &mdep_cfg_idx))
3082 {
3083 p_dcb->in_use = TRUE;
3084 p_dcb->mdl_handle = p_data->dch_reconnect_ind.mdl_handle;
3085 p_dcb->local_mdep_cfg_idx = mdep_cfg_idx;
3086 p_dcb->local_mdep_id = p_data->dch_reconnect_ind.local_mdep_id;
3087 p_dcb->mdl_id = p_data->dch_reconnect_ind.mdl_id;
3088 p_dcb->dch_mode = p_data->dch_reconnect_ind.dch_mode;
3089 p_dcb->dch_mode = p_data->dch_reconnect_ind.dch_mode;
3090 p_dcb->is_the_first_reliable= p_data->dch_reconnect_ind.first_reliable;
3091 p_dcb->mtu = p_data->dch_reconnect_ind.mtu;
3092 p_dcb->channel_id = btif_hl_get_next_channel_id(p_acb->app_id);
3093
3094 BTIF_TRACE_DEBUG4(" app_idx=%d mcl_idx=%d mdl_idx=%d channel_id=%d",
3095 app_idx, mcl_idx, mdl_idx, p_dcb->channel_id );
3096 if (!btif_hl_create_socket(app_idx, mcl_idx, mdl_idx))
3097 {
3098 BTIF_TRACE_ERROR0("Unable to create socket");
3099 close_dch = TRUE;
3100 }
3101 }
3102 else
3103 {
3104 BTIF_TRACE_ERROR1("INVALID_LOCAL_MDEP_ID mdep_id=%d",p_data->dch_open_cfm.local_mdep_id);
3105 close_dch = TRUE;
3106 }
3107
3108 if (close_dch)
3109 btif_hl_clean_mdl_cb(p_dcb);
3110 }
3111 else
3112 close_dch = TRUE;
3113 }
3114 else
3115 close_dch = TRUE;
3116
3117 if (close_dch)
3118 BTA_HlDchClose(p_data->dch_reconnect_ind.mdl_handle);
3119
3120}
3121
3122/*******************************************************************************
3123**
3124** Function btif_hl_proc_dch_close_ind
3125**
3126** Description Process the DCH close indication
3127**
3128** Returns Nothing
3129**
3130*******************************************************************************/
3131static void btif_hl_proc_dch_close_ind(tBTA_HL *p_data)
3132
3133{
3134 btif_hl_mdl_cb_t *p_dcb;
Priti Agheraf8f30c22013-04-02 15:31:19 -07003135 btif_hl_mcl_cb_t *p_mcb;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003136 UINT8 app_idx, mcl_idx, mdl_idx;
3137
3138 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
3139 if (btif_hl_find_mdl_idx_using_handle(p_data->dch_close_ind.mdl_handle,
3140 &app_idx, &mcl_idx, &mdl_idx ))
3141 {
3142 p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
3143 btif_hl_release_socket(app_idx,mcl_idx, mdl_idx);
Priti Agheraf8f30c22013-04-02 15:31:19 -07003144 btif_hl_send_setup_disconnected_cb(app_idx, mcl_idx);
3145 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx,mcl_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003146 btif_hl_clean_mdl_cb(p_dcb);
Priti Agheraf8f30c22013-04-02 15:31:19 -07003147 if (!btif_hl_num_dchs_in_use(p_mcb->mcl_handle))
The Android Open Source Project5738f832012-12-12 16:00:35 -08003148 btif_hl_start_cch_timer(app_idx, mcl_idx);
3149 BTIF_TRACE_DEBUG1("remote DCH close success mdl_idx=%d", mdl_idx);
3150 }
3151}
3152
3153/*******************************************************************************
3154**
3155** Function btif_hl_proc_dch_close_cfm
3156**
3157** Description Process the DCH reconnect confirmation
3158**
3159** Returns Nothing
3160**
3161*******************************************************************************/
3162static void btif_hl_proc_dch_close_cfm(tBTA_HL *p_data)
3163
3164{
3165 btif_hl_mdl_cb_t *p_dcb;
Priti Agheraf8f30c22013-04-02 15:31:19 -07003166 btif_hl_mcl_cb_t *p_mcb;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003167 UINT8 app_idx, mcl_idx, mdl_idx;
3168
3169 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
3170 if (btif_hl_find_mdl_idx_using_handle(p_data->dch_close_cfm.mdl_handle,
3171 &app_idx, &mcl_idx, &mdl_idx ))
3172 {
3173 p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
3174 btif_hl_release_socket(app_idx,mcl_idx,mdl_idx);
3175 btif_hl_clean_mdl_cb(p_dcb);
Priti Agheraf8f30c22013-04-02 15:31:19 -07003176 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx,mcl_idx);
3177 if (!btif_hl_num_dchs_in_use(p_mcb->mcl_handle))
The Android Open Source Project5738f832012-12-12 16:00:35 -08003178 btif_hl_start_cch_timer(app_idx, mcl_idx);
Priti Agheraf8f30c22013-04-02 15:31:19 -07003179 BTIF_TRACE_DEBUG1(" local DCH close success mdl_idx=%d", mdl_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003180 }
3181}
3182
3183
3184/*******************************************************************************
3185**
3186** Function btif_hl_proc_abort_ind
3187**
3188** Description Process the abort indicaiton
3189**
3190** Returns Nothing
3191**
3192*******************************************************************************/
3193static void btif_hl_proc_abort_ind(tBTA_HL_MCL_HANDLE mcl_handle){
3194
3195 UINT8 app_idx,mcl_idx;
3196 BTIF_TRACE_DEBUG1("%s", __FUNCTION__ );
Priti Agheraf8f30c22013-04-02 15:31:19 -07003197 btif_hl_app_cb_t *p_acb;
3198 UINT8 i,j;
3199
3200 for (i=0; i<BTA_HL_NUM_APPS; i++)
The Android Open Source Project5738f832012-12-12 16:00:35 -08003201 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07003202 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
3203 for (j=0; j < BTA_HL_NUM_MCLS ; j++)
3204 {
3205 if (p_acb->mcb[j].in_use)
3206 BTIF_TRACE_DEBUG3("btif_hl_find_mcl_idx_using_handle: app_idx=%d,mcl_idx =%d mcl_handle=%d",i,j,p_acb->mcb[j].mcl_handle);
3207 if (p_acb->mcb[j].in_use &&
3208 (p_acb->mcb[j].mcl_handle == mcl_handle))
3209 {
3210 btif_hl_stop_cch_timer(i, j);
3211 btif_hl_send_setup_disconnected_cb(i, j);
3212 btif_hl_clean_mcl_cb(i, j);
3213 }
3214 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08003215 }
3216}
3217
3218/*******************************************************************************
3219**
3220** Function btif_hl_proc_abort_cfm
3221**
3222** Description Process the abort confirmation
3223**
3224** Returns Nothing
3225**
3226*******************************************************************************/
3227static void btif_hl_proc_abort_cfm(tBTA_HL_MCL_HANDLE mcl_handle){
3228 UINT8 app_idx,mcl_idx;
3229
3230 BTIF_TRACE_DEBUG1("%s", __FUNCTION__ );
Priti Agheraf8f30c22013-04-02 15:31:19 -07003231 btif_hl_app_cb_t *p_acb;
3232 UINT8 i,j;
3233
3234 for (i=0; i<BTA_HL_NUM_APPS; i++)
The Android Open Source Project5738f832012-12-12 16:00:35 -08003235 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07003236 p_acb =BTIF_HL_GET_APP_CB_PTR(i);
3237 for (j=0; j < BTA_HL_NUM_MCLS ; j++)
3238 {
3239 if (p_acb->mcb[j].in_use)
3240 BTIF_TRACE_DEBUG3("btif_hl_find_mcl_idx_using_handle: app_idx=%d,mcl_idx =%d mcl_handle=%d",i,j,p_acb->mcb[j].mcl_handle);
3241 if (p_acb->mcb[j].in_use &&
3242 (p_acb->mcb[j].mcl_handle == mcl_handle))
3243 {
3244 btif_hl_stop_cch_timer(i, j);
3245 btif_hl_send_setup_disconnected_cb(i, j);
3246 btif_hl_clean_mcl_cb(i, j);
3247 }
3248 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08003249 }
Priti Agheraf8f30c22013-04-02 15:31:19 -07003250
The Android Open Source Project5738f832012-12-12 16:00:35 -08003251}
3252
3253/*******************************************************************************
3254**
3255** Function btif_hl_proc_send_data_cfm
3256**
3257** Description Process the send data confirmation
3258**
3259** Returns Nothing
3260**
3261*******************************************************************************/
3262static void btif_hl_proc_send_data_cfm(tBTA_HL_MDL_HANDLE mdl_handle,
3263 tBTA_HL_STATUS status){
3264 UINT8 app_idx,mcl_idx, mdl_idx;
3265 btif_hl_mdl_cb_t *p_dcb;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08003266 UNUSED(status);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003267
3268 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
3269 if (btif_hl_find_mdl_idx_using_handle(mdl_handle,
3270 &app_idx, &mcl_idx, &mdl_idx ))
3271 {
3272 p_dcb =BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
3273 btif_hl_free_buf((void **) &p_dcb->p_tx_pkt);
3274 BTIF_TRACE_DEBUG1("send success free p_tx_pkt tx_size=%d", p_dcb->tx_size);
3275 p_dcb->tx_size = 0;
3276 }
3277}
3278
3279/*******************************************************************************
3280**
3281** Function btif_hl_proc_dch_cong_ind
3282**
3283** Description Process the DCH congestion change indication
3284**
3285** Returns Nothing
3286**
3287*******************************************************************************/
3288static void btif_hl_proc_dch_cong_ind(tBTA_HL *p_data)
3289
3290{
3291 btif_hl_mdl_cb_t *p_dcb;
3292 UINT8 app_idx, mcl_idx, mdl_idx;
3293
3294 BTIF_TRACE_DEBUG0("btif_hl_proc_dch_cong_ind");
3295
3296
3297 if (btif_hl_find_mdl_idx_using_handle(p_data->dch_cong_ind.mdl_handle, &app_idx, &mcl_idx, &mdl_idx))
3298 {
3299 p_dcb =BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
3300 p_dcb->cong = p_data->dch_cong_ind.cong;
3301 }
3302}
3303
The Android Open Source Project5738f832012-12-12 16:00:35 -08003304/*******************************************************************************
3305**
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08003306** Function btif_hl_proc_reg_request
The Android Open Source Project5738f832012-12-12 16:00:35 -08003307**
3308** Description Process registration request
3309**
3310** Returns void
3311**
3312*******************************************************************************/
3313static void btif_hl_proc_reg_request(UINT8 app_idx, UINT8 app_id,
3314 tBTA_HL_REG_PARAM *p_reg_param,
3315 tBTA_HL_CBACK *p_cback){
3316 bt_status_t status= BT_STATUS_SUCCESS;
3317 UINT8 i;
3318 btif_hl_app_data_t *p_data;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08003319 UNUSED(p_cback);
3320
Priti Agheraf8f30c22013-04-02 15:31:19 -07003321 BTIF_TRACE_DEBUG3("%s app_idx=%d app_id=%d", __FUNCTION__, app_idx, app_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003322
Priti Agheraf8f30c22013-04-02 15:31:19 -07003323 if(reg_counter >1)
The Android Open Source Project5738f832012-12-12 16:00:35 -08003324 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07003325 BTIF_TRACE_DEBUG0("btif_hl_proc_reg_request: calling uPDATE");
3326 BTA_HlUpdate(app_id, p_reg_param,TRUE, btif_hl_cback);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003327 }
Priti Agheraf8f30c22013-04-02 15:31:19 -07003328 else
3329 BTA_HlRegister(app_id, p_reg_param, btif_hl_cback);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003330}
3331
3332
3333/*******************************************************************************
3334**
3335** Function btif_hl_proc_cb_evt
3336**
3337** Description Process HL callback events
3338**
3339** Returns void
3340**
3341*******************************************************************************/
3342static void btif_hl_proc_cb_evt(UINT16 event, char* p_param){
3343
3344 btif_hl_evt_cb_t *p_data = (btif_hl_evt_cb_t *)p_param;
3345 bt_bdaddr_t bd_addr;
3346 bthl_channel_state_t state=BTHL_CONN_STATE_DISCONNECTED;
3347 BOOLEAN send_chan_cb=TRUE;
3348 tBTA_HL_REG_PARAM reg_param;
3349 btif_hl_app_cb_t *p_acb;
3350 bthl_app_reg_state_t reg_state = BTHL_APP_REG_STATE_REG_FAILED;
3351 int app_id;
3352 UINT8 preg_idx;
3353 bt_status_t bt_status;
3354
3355 BTIF_TRACE_DEBUG2("%s event %d", __FUNCTION__, event);
3356 btif_hl_display_calling_process_name();
3357
3358 switch (event)
3359 {
3360 case BTIF_HL_SEND_CONNECTED_CB:
3361 case BTIF_HL_SEND_DISCONNECTED_CB:
3362 if (p_data->chan_cb.cb_state == BTIF_HL_CHAN_CB_STATE_CONNECTED_PENDING)
3363 state = BTHL_CONN_STATE_CONNECTED;
3364 else if (p_data->chan_cb.cb_state == BTIF_HL_CHAN_CB_STATE_DISCONNECTED_PENDING)
3365 state = BTHL_CONN_STATE_DISCONNECTED;
3366 else
3367 send_chan_cb = FALSE;
3368
3369 if (send_chan_cb)
3370 {
3371 btif_hl_copy_bda(&bd_addr, p_data->chan_cb.bd_addr);
3372 BTIF_TRACE_DEBUG4("state callbk: ch_id=0x%08x cb_state=%d state=%d fd=%d",
3373 p_data->chan_cb.channel_id,
3374 p_data->chan_cb.cb_state,
3375 state, p_data->chan_cb.fd);
3376 btif_hl_display_bt_bda(&bd_addr);
3377 BTIF_HL_CALL_CBACK(bt_hl_callbacks, channel_state_cb, p_data->chan_cb.app_id,
3378 &bd_addr, p_data->chan_cb.mdep_cfg_index,
3379 p_data->chan_cb.channel_id, state, p_data->chan_cb.fd );
3380 }
3381
3382 break;
3383 case BTIF_HL_REG_APP:
3384 p_acb = BTIF_HL_GET_APP_CB_PTR(p_data->reg.app_idx);
3385 app_id = (int) p_acb->app_id;
3386 BTIF_TRACE_DEBUG2("Rcv BTIF_HL_REG_APP app_idx=%d reg_pending=%d", p_data->reg.app_idx, p_acb->reg_pending);
Priti Agheraf8f30c22013-04-02 15:31:19 -07003387 if (btif_hl_get_state() == BTIF_HL_STATE_ENABLED && p_acb->reg_pending)
The Android Open Source Project5738f832012-12-12 16:00:35 -08003388 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07003389 BTIF_TRACE_DEBUG1("Rcv BTIF_HL_REG_APP reg_counter=%d",reg_counter);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003390 p_acb->reg_pending = FALSE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003391 reg_param.dev_type = p_acb->dev_type;
3392 reg_param.sec_mask = BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT;
3393 reg_param.p_srv_name = p_acb->srv_name;
3394 reg_param.p_srv_desp = p_acb->srv_desp;
3395 reg_param.p_provider_name = p_acb->provider_name;
3396 btif_hl_proc_reg_request (p_data->reg.app_idx, p_acb->app_id, &reg_param, btif_hl_cback);
3397 }
3398 else
3399 {
3400 BTIF_TRACE_DEBUG2("reg request is processed state=%d reg_pending=%d", btif_hl_get_state(), p_acb->reg_pending);
3401 }
3402
3403 break;
3404
3405 case BTIF_HL_UNREG_APP:
3406 BTIF_TRACE_DEBUG1("Rcv BTIF_HL_UNREG_APP app_idx=%d", p_data->unreg.app_idx );
3407 p_acb = BTIF_HL_GET_APP_CB_PTR(p_data->unreg.app_idx);
Priti Agheraf8f30c22013-04-02 15:31:19 -07003408 if (btif_hl_get_state() == BTIF_HL_STATE_ENABLED)
3409 {
3410 if(reg_counter >= 1)
3411 BTA_HlUpdate(p_acb->app_id,NULL,FALSE,NULL);
3412 else
3413 BTA_HlDeregister(p_acb->app_id, p_acb->app_handle);
3414 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08003415 break;
3416 case BTIF_HL_UPDATE_MDL:
3417 BTIF_TRACE_DEBUG1("Rcv BTIF_HL_UPDATE_MDL app_idx=%d", p_data->update_mdl.app_idx );
3418 p_acb = BTIF_HL_GET_APP_CB_PTR(p_data->update_mdl.app_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003419 break;
3420
3421 default:
3422 BTIF_TRACE_ERROR1("Unknown event %d", event);
3423 break;
3424 }
3425}
3426
3427/*******************************************************************************
3428**
3429** Function btif_hl_upstreams_evt
3430**
3431** Description Process HL events
3432**
3433** Returns void
3434**
3435*******************************************************************************/
3436static void btif_hl_upstreams_evt(UINT16 event, char* p_param){
3437 tBTA_HL *p_data = (tBTA_HL *)p_param;
3438 UINT8 app_idx, mcl_idx;
3439 btif_hl_app_cb_t *p_acb;
3440 btif_hl_mcl_cb_t *p_mcb = NULL;
3441 BD_ADDR bd_addr;
3442 btif_hl_pend_dch_op_t pending_op;
3443 BOOLEAN status;
3444
3445 BTIF_TRACE_DEBUG2("%s event %d", __FUNCTION__, event);
3446 btif_hl_display_calling_process_name();
3447 switch (event)
3448 {
3449 case BTA_HL_REGISTER_CFM_EVT:
3450 BTIF_TRACE_DEBUG0("Rcv BTA_HL_REGISTER_CFM_EVT");
3451 BTIF_TRACE_DEBUG3("app_id=%d app_handle=%d status=%d ",
3452 p_data->reg_cfm.app_id,
3453 p_data->reg_cfm.app_handle,
3454 p_data->reg_cfm.status );
3455
3456 btif_hl_proc_reg_cfm(p_data);
3457 break;
3458 case BTA_HL_SDP_INFO_IND_EVT:
3459 BTIF_TRACE_DEBUG0("Rcv BTA_HL_SDP_INFO_IND_EVT");
3460 BTIF_TRACE_DEBUG5("app_handle=%d ctrl_psm=0x%04x data_psm=0x%04x x_spec=%d mcap_sup_procs=0x%02x",
3461 p_data->sdp_info_ind.app_handle,
3462 p_data->sdp_info_ind.ctrl_psm,
3463 p_data->sdp_info_ind.data_psm,
3464 p_data->sdp_info_ind.data_x_spec,
3465 p_data->sdp_info_ind.mcap_sup_procs);
Priti Agheraf8f30c22013-04-02 15:31:19 -07003466 //btif_hl_proc_sdp_info_ind(p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003467 break;
3468
3469 case BTA_HL_DEREGISTER_CFM_EVT:
3470 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DEREGISTER_CFM_EVT");
3471 BTIF_TRACE_DEBUG2("app_handle=%d status=%d ",
3472 p_data->dereg_cfm.app_handle,
3473 p_data->dereg_cfm.status );
3474 btif_hl_proc_dereg_cfm(p_data);
3475 break;
3476
3477 case BTA_HL_SDP_QUERY_CFM_EVT:
3478 BTIF_TRACE_DEBUG0("Rcv BTA_HL_SDP_QUERY_CFM_EVT");
Priti Agheraf8f30c22013-04-02 15:31:19 -07003479 BTIF_TRACE_DEBUG3("app_handle=%d app_id =%d,status =%d",
3480 p_data->sdp_query_cfm.app_handle,p_data->sdp_query_cfm.app_id,
The Android Open Source Project5738f832012-12-12 16:00:35 -08003481 p_data->sdp_query_cfm.status);
3482
3483 BTIF_TRACE_DEBUG6("DB [%02x] [%02x] [%02x] [%02x] [%02x] [%02x]",
3484 p_data->sdp_query_cfm.bd_addr[0], p_data->sdp_query_cfm.bd_addr[1],
3485 p_data->sdp_query_cfm.bd_addr[2], p_data->sdp_query_cfm.bd_addr[3],
3486 p_data->sdp_query_cfm.bd_addr[4], p_data->sdp_query_cfm.bd_addr[5]);
3487
3488 if (p_data->sdp_query_cfm.status == BTA_HL_STATUS_OK)
3489 status = btif_hl_proc_sdp_query_cfm(p_data);
3490 else
3491 status = FALSE;
3492
3493 if (!status)
3494 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07003495 BTIF_TRACE_DEBUG1("BTA_HL_SDP_QUERY_CFM_EVT Status = %d",
3496 p_data->sdp_query_cfm.status);
3497 if (btif_hl_find_app_idx_using_app_id(p_data->sdp_query_cfm.app_id, &app_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08003498 {
3499 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
3500 if (btif_hl_find_mcl_idx(app_idx, p_data->sdp_query_cfm.bd_addr, &mcl_idx))
3501 {
3502 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Ajay Dudani4420e412013-07-27 09:11:08 -07003503 if ( (p_mcb->cch_oper == BTIF_HL_CCH_OP_MDEP_FILTERING) ||
The Android Open Source Project5738f832012-12-12 16:00:35 -08003504 (p_mcb->cch_oper == BTIF_HL_CCH_OP_DCH_OPEN) )
3505 {
3506 pending_op = p_mcb->pcb.op;
3507 switch (pending_op)
3508 {
3509 case BTIF_HL_PEND_DCH_OP_OPEN:
3510 btif_hl_send_setup_disconnected_cb(app_idx, mcl_idx);
3511 break;
3512 case BTIF_HL_PEND_DCH_OP_RECONNECT:
3513 case BTIF_HL_PEND_DCH_OP_DELETE_MDL:
3514 default:
3515 break;
3516 }
3517 if (!p_mcb->is_connected)
3518 btif_hl_clean_mcl_cb(app_idx, mcl_idx);
3519 }
3520 }
3521 }
3522 }
3523
3524 break;
3525
3526
3527 case BTA_HL_CCH_OPEN_CFM_EVT:
3528 BTIF_TRACE_DEBUG0("Rcv BTA_HL_CCH_OPEN_CFM_EVT");
Priti Agheraf8f30c22013-04-02 15:31:19 -07003529 BTIF_TRACE_DEBUG4("app_id=%d,app_handle=%d mcl_handle=%d status =%d",
3530 p_data->cch_open_cfm.app_id,
The Android Open Source Project5738f832012-12-12 16:00:35 -08003531 p_data->cch_open_cfm.app_handle,
3532 p_data->cch_open_cfm.mcl_handle,
3533 p_data->cch_open_cfm.status);
3534 BTIF_TRACE_DEBUG6("DB [%02x] [%02x] [%02x] [%02x] [%02x] [%02x]",
3535 p_data->cch_open_cfm.bd_addr[0], p_data->cch_open_cfm.bd_addr[1],
3536 p_data->cch_open_cfm.bd_addr[2], p_data->cch_open_cfm.bd_addr[3],
3537 p_data->cch_open_cfm.bd_addr[4], p_data->cch_open_cfm.bd_addr[5]);
3538
Priti Agheraf8f30c22013-04-02 15:31:19 -07003539 if (p_data->cch_open_cfm.status == BTA_HL_STATUS_OK ||
3540 p_data->cch_open_cfm.status == BTA_HL_STATUS_DUPLICATE_CCH_OPEN)
The Android Open Source Project5738f832012-12-12 16:00:35 -08003541 {
3542 status = btif_hl_proc_cch_open_cfm(p_data);
3543 }
3544 else
3545 {
3546 status = FALSE;
3547 }
3548
3549 if (!status)
3550 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07003551 if (btif_hl_find_app_idx_using_app_id(p_data->cch_open_cfm.app_id, &app_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08003552 {
3553 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
3554 if (btif_hl_find_mcl_idx(app_idx, p_data->cch_open_cfm.bd_addr, &mcl_idx))
3555 {
3556 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
3557 pending_op = p_mcb->pcb.op;
3558 switch (pending_op)
3559 {
3560 case BTIF_HL_PEND_DCH_OP_OPEN:
3561 btif_hl_send_setup_disconnected_cb(app_idx, mcl_idx);
3562 break;
3563 case BTIF_HL_PEND_DCH_OP_RECONNECT:
3564 case BTIF_HL_PEND_DCH_OP_DELETE_MDL:
3565 default:
3566 break;
3567 }
3568 btif_hl_clean_mcl_cb(app_idx, mcl_idx);
3569 }
3570 }
3571 }
3572 break;
3573
3574 case BTA_HL_DCH_OPEN_CFM_EVT:
3575 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_OPEN_CFM_EVT");
3576 BTIF_TRACE_DEBUG3("mcl_handle=%d mdl_handle=0x%x status=%d ",
3577 p_data->dch_open_cfm.mcl_handle,
3578 p_data->dch_open_cfm.mdl_handle,
3579 p_data->dch_open_cfm.status);
3580 BTIF_TRACE_DEBUG5("first_reliable =%d dch_mode=%d local_mdep_id=%d mdl_id=%d mtu=%d",
3581 p_data->dch_open_cfm.first_reliable,
3582 p_data->dch_open_cfm.dch_mode,
3583 p_data->dch_open_cfm.local_mdep_id,
3584 p_data->dch_open_cfm.mdl_id,
3585 p_data->dch_open_cfm.mtu);
3586 if (p_data->dch_open_cfm.status == BTA_HL_STATUS_OK)
3587 {
3588 status = btif_hl_proc_dch_open_cfm(p_data);
3589 }
3590 else
3591 {
3592 status = FALSE;
3593 }
3594
3595 if (!status)
3596 {
3597 if (btif_hl_find_mcl_idx_using_handle(p_data->dch_open_cfm.mcl_handle,&app_idx, &mcl_idx))
3598 {
3599 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
3600 pending_op = p_mcb->pcb.op;
3601 switch (pending_op)
3602 {
3603 case BTIF_HL_PEND_DCH_OP_OPEN:
3604 btif_hl_send_setup_disconnected_cb(app_idx, mcl_idx);
3605 break;
3606 case BTIF_HL_PEND_DCH_OP_RECONNECT:
3607 case BTIF_HL_PEND_DCH_OP_DELETE_MDL:
3608 default:
3609 break;
3610 }
3611 }
3612 }
3613 break;
3614
3615
3616 case BTA_HL_CCH_OPEN_IND_EVT:
3617 BTIF_TRACE_DEBUG0("Rcv BTA_HL_CCH_OPEN_IND_EVT");
3618 BTIF_TRACE_DEBUG2("app_handle=%d mcl_handle=%d",
3619 p_data->cch_open_ind.app_handle,
3620 p_data->cch_open_ind.mcl_handle);
3621 BTIF_TRACE_DEBUG6("DB [%02x] [%02x] [%02x] [%02x] [%02x] [%02x]",
3622 p_data->cch_open_ind.bd_addr[0], p_data->cch_open_ind.bd_addr[1],
3623 p_data->cch_open_ind.bd_addr[2], p_data->cch_open_ind.bd_addr[3],
3624 p_data->cch_open_ind.bd_addr[4], p_data->cch_open_ind.bd_addr[5]);
3625
3626 btif_hl_proc_cch_open_ind(p_data);
3627 break;
3628
3629 case BTA_HL_DCH_CREATE_IND_EVT:
3630 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_CREATE_IND_EVT");
3631 BTIF_TRACE_DEBUG1("mcl_handle=%d",
3632 p_data->dch_create_ind.mcl_handle );
3633 BTIF_TRACE_DEBUG3("local_mdep_id =%d mdl_id=%d cfg=%d",
3634 p_data->dch_create_ind.local_mdep_id,
3635 p_data->dch_create_ind.mdl_id,
3636 p_data->dch_create_ind.cfg);
3637 btif_hl_proc_create_ind(p_data);
3638 break;
3639
3640 case BTA_HL_DCH_OPEN_IND_EVT:
3641 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_OPEN_IND_EVT");
3642 BTIF_TRACE_DEBUG2("mcl_handle=%d mdl_handle=0x%x",
3643 p_data->dch_open_ind.mcl_handle,
3644 p_data->dch_open_ind.mdl_handle );
3645 BTIF_TRACE_DEBUG5("first_reliable =%d dch_mode=%d local_mdep_id=%d mdl_id=%d mtu=%d",
3646 p_data->dch_open_ind.first_reliable,
3647 p_data->dch_open_ind.dch_mode,
3648 p_data->dch_open_ind.local_mdep_id,
3649 p_data->dch_open_ind.mdl_id,
3650 p_data->dch_open_ind.mtu);
3651
3652 btif_hl_proc_dch_open_ind(p_data);
3653 break;
3654
3655 case BTA_HL_DELETE_MDL_IND_EVT:
3656 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DELETE_MDL_IND_EVT");
3657 BTIF_TRACE_DEBUG2("mcl_handle=%d mdl_id=0x%x",
3658 p_data->delete_mdl_ind.mcl_handle,
3659 p_data->delete_mdl_ind.mdl_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003660 break;
3661
3662 case BTA_HL_DELETE_MDL_CFM_EVT:
3663 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DELETE_MDL_CFM_EVT");
3664 BTIF_TRACE_DEBUG3("mcl_handle=%d mdl_id=0x%x status=%d",
3665 p_data->delete_mdl_cfm.mcl_handle,
3666 p_data->delete_mdl_cfm.mdl_id,
3667 p_data->delete_mdl_cfm.status);
3668
Priti Agheraf8f30c22013-04-02 15:31:19 -07003669 if (btif_hl_find_app_idx_using_deleted_mdl_id( p_data->delete_mdl_cfm.mdl_id,
3670 &app_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08003671 {
3672 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003673 btif_hl_send_destroyed_cb(p_acb);
3674 btif_hl_clean_delete_mdl(&p_acb->delete_mdl);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003675 }
3676 break;
3677
3678 case BTA_HL_DCH_RECONNECT_CFM_EVT:
3679 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_RECONNECT_CFM_EVT");
3680 BTIF_TRACE_DEBUG3("mcl_handle=%d mdl_handle=%d status=%d ",
3681 p_data->dch_reconnect_cfm.mcl_handle,
3682 p_data->dch_reconnect_cfm.mdl_handle,
3683 p_data->dch_reconnect_cfm.status);
3684 BTIF_TRACE_DEBUG4("first_reliable =%d dch_mode=%d mdl_id=%d mtu=%d",
3685 p_data->dch_reconnect_cfm.first_reliable,
3686 p_data->dch_reconnect_cfm.dch_mode,
3687 p_data->dch_reconnect_cfm.mdl_id,
3688 p_data->dch_reconnect_cfm.mtu);
3689
3690
3691 if (p_data->dch_reconnect_cfm.status == BTA_HL_STATUS_OK)
3692 {
3693 status = btif_hl_proc_dch_reconnect_cfm(p_data);
3694 }
3695 else
3696 {
3697 status = FALSE;
3698 }
3699
3700 if (!status)
3701 {
3702 if (btif_hl_find_mcl_idx_using_handle(p_data->dch_open_cfm.mcl_handle,&app_idx, &mcl_idx))
3703 {
3704 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
3705 pending_op = p_mcb->pcb.op;
3706 switch (pending_op)
3707 {
3708 case BTIF_HL_PEND_DCH_OP_OPEN:
3709 btif_hl_send_setup_disconnected_cb(app_idx, mcl_idx);
3710 break;
3711 case BTIF_HL_PEND_DCH_OP_RECONNECT:
3712 case BTIF_HL_PEND_DCH_OP_DELETE_MDL:
3713 default:
3714 break;
3715 }
3716 }
3717 }
3718
3719 break;
3720
3721 case BTA_HL_CCH_CLOSE_CFM_EVT:
3722 BTIF_TRACE_DEBUG0("Rcv BTA_HL_CCH_CLOSE_CFM_EVT");
3723 BTIF_TRACE_DEBUG2("mcl_handle=%d status =%d",
3724 p_data->cch_close_cfm.mcl_handle,
3725 p_data->cch_close_cfm.status);
3726 if (p_data->cch_close_cfm.status == BTA_HL_STATUS_OK)
3727 {
3728 btif_hl_proc_cch_close_cfm(p_data);
3729 }
3730 break;
3731
3732 case BTA_HL_CCH_CLOSE_IND_EVT:
3733 BTIF_TRACE_DEBUG0("Rcv BTA_HL_CCH_CLOSE_IND_EVT");
3734 BTIF_TRACE_DEBUG2("mcl_handle =%d intentional_close=%s",
3735 p_data->cch_close_ind.mcl_handle,
3736 (p_data->cch_close_ind.intentional?"Yes":"No"));
3737
3738 btif_hl_proc_cch_close_ind(p_data);
3739 break;
3740
3741 case BTA_HL_DCH_CLOSE_IND_EVT:
3742 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_CLOSE_IND_EVT");
3743 BTIF_TRACE_DEBUG2("mdl_handle=%d intentional_close=%s",
3744 p_data->dch_close_ind.mdl_handle,
3745 (p_data->dch_close_ind.intentional?"Yes":"No") );
3746
3747 btif_hl_proc_dch_close_ind(p_data);
3748 break;
3749
3750 case BTA_HL_DCH_CLOSE_CFM_EVT:
3751 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_CLOSE_CFM_EVT");
3752 BTIF_TRACE_DEBUG2("mdl_handle=%d status=%d ",
3753 p_data->dch_close_cfm.mdl_handle,
3754 p_data->dch_close_cfm.status);
3755
3756 if (p_data->dch_close_cfm.status == BTA_HL_STATUS_OK)
3757 {
3758 btif_hl_proc_dch_close_cfm(p_data);
3759 }
3760 break;
3761
3762 case BTA_HL_DCH_ECHO_TEST_CFM_EVT:
3763 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_ECHO_TEST_CFM_EVT");
3764 BTIF_TRACE_DEBUG2("mcl_handle=%d status=%d",
3765 p_data->echo_test_cfm.mcl_handle,
3766 p_data->echo_test_cfm.status );
3767 /* not supported */
3768 break;
3769
3770
3771 case BTA_HL_DCH_RECONNECT_IND_EVT:
3772 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_RECONNECT_IND_EVT");
3773
3774 BTIF_TRACE_DEBUG2("mcl_handle=%d mdl_handle=5d",
3775 p_data->dch_reconnect_ind.mcl_handle,
3776 p_data->dch_reconnect_ind.mdl_handle );
3777 BTIF_TRACE_DEBUG4("first_reliable =%d dch_mode=%d mdl_id=%d mtu=%d",
3778 p_data->dch_reconnect_ind.first_reliable,
3779 p_data->dch_reconnect_ind.dch_mode,
3780 p_data->dch_reconnect_ind.mdl_id,
3781 p_data->dch_reconnect_ind.mtu);
3782
3783 btif_hl_proc_dch_reconnect_ind(p_data);
3784 break;
3785
3786 case BTA_HL_CONG_CHG_IND_EVT:
3787 BTIF_TRACE_DEBUG0("Rcv BTA_HL_CONG_CHG_IND_EVT");
3788 BTIF_TRACE_DEBUG2("mdl_handle=%d cong =%d",
3789 p_data->dch_cong_ind.mdl_handle,
3790 p_data->dch_cong_ind.cong);
3791 btif_hl_proc_dch_cong_ind(p_data);
3792 break;
3793
3794 case BTA_HL_DCH_ABORT_IND_EVT:
3795 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_ABORT_IND_EVT");
3796 BTIF_TRACE_DEBUG1("mcl_handle=%d",
3797 p_data->dch_abort_ind.mcl_handle );
3798 btif_hl_proc_abort_ind(p_data->dch_abort_ind.mcl_handle);
3799 break;
3800 case BTA_HL_DCH_ABORT_CFM_EVT:
3801 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_ABORT_CFM_EVT");
3802 BTIF_TRACE_DEBUG2("mcl_handle=%d status =%d",
3803 p_data->dch_abort_cfm.mcl_handle,
3804 p_data->dch_abort_cfm.status);
3805 if (p_data->dch_abort_cfm.status == BTA_HL_STATUS_OK)
3806 {
3807 btif_hl_proc_abort_cfm(p_data->dch_abort_ind.mcl_handle);
3808 }
3809 break;
3810
3811 case BTA_HL_DCH_SEND_DATA_CFM_EVT:
3812 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_SEND_DATA_CFM_EVT");
3813 BTIF_TRACE_DEBUG2("mdl_handle=0x%x status =%d",
3814 p_data->dch_send_data_cfm.mdl_handle,
3815 p_data->dch_send_data_cfm.status);
3816 btif_hl_proc_send_data_cfm(p_data->dch_send_data_cfm.mdl_handle,
3817 p_data->dch_send_data_cfm.status);
3818 break;
3819
3820 case BTA_HL_DCH_RCV_DATA_IND_EVT:
3821 BTIF_TRACE_DEBUG0("Rcv BTA_HL_DCH_RCV_DATA_IND_EVT");
3822 BTIF_TRACE_DEBUG1("mdl_handle=0x%x ",
3823 p_data->dch_rcv_data_ind.mdl_handle);
3824 /* do nothing here */
3825 break;
3826
3827 default:
3828 BTIF_TRACE_DEBUG1("Unknown Event (0x%02x)...", event);
3829 break;
3830 }
3831}
3832
3833/*******************************************************************************
3834**
3835** Function btif_hl_cback
3836**
3837** Description Callback function for HL events
3838**
3839** Returns void
3840**
3841*******************************************************************************/
3842static void btif_hl_cback(tBTA_HL_EVT event, tBTA_HL *p_data){
3843 bt_status_t status;
3844 int param_len = 0;
3845 BTIF_TRACE_DEBUG2("%s event %d", __FUNCTION__, event);
3846 btif_hl_display_calling_process_name();
3847 switch (event)
3848 {
3849 case BTA_HL_REGISTER_CFM_EVT:
3850 param_len = sizeof(tBTA_HL_REGISTER_CFM);
3851 break;
3852 case BTA_HL_SDP_INFO_IND_EVT:
3853 param_len = sizeof(tBTA_HL_SDP_INFO_IND);
3854 break;
3855 case BTA_HL_DEREGISTER_CFM_EVT:
3856 param_len = sizeof(tBTA_HL_DEREGISTER_CFM);
3857 break;
3858 case BTA_HL_SDP_QUERY_CFM_EVT:
3859 param_len = sizeof(tBTA_HL_SDP_QUERY_CFM);
3860 break;
3861 case BTA_HL_CCH_OPEN_CFM_EVT:
3862 param_len = sizeof(tBTA_HL_CCH_OPEN_CFM);
3863 break;
3864 case BTA_HL_DCH_OPEN_CFM_EVT:
3865 param_len = sizeof(tBTA_HL_DCH_OPEN_CFM);
3866 break;
3867 case BTA_HL_CCH_OPEN_IND_EVT:
3868 param_len = sizeof(tBTA_HL_CCH_OPEN_IND);
3869 break;
3870 case BTA_HL_DCH_CREATE_IND_EVT:
3871 param_len = sizeof(tBTA_HL_DCH_CREATE_IND);
3872 break;
3873 case BTA_HL_DCH_OPEN_IND_EVT:
3874 param_len = sizeof(tBTA_HL_DCH_OPEN_IND);
3875 break;
3876 case BTA_HL_DELETE_MDL_IND_EVT:
3877 param_len = sizeof(tBTA_HL_MDL_IND);
3878 break;
3879 case BTA_HL_DELETE_MDL_CFM_EVT:
3880 param_len = sizeof(tBTA_HL_MDL_CFM);
3881 break;
3882 case BTA_HL_DCH_RECONNECT_CFM_EVT:
3883 param_len = sizeof(tBTA_HL_DCH_OPEN_CFM);
3884 break;
3885 case BTA_HL_CCH_CLOSE_CFM_EVT:
3886 param_len = sizeof(tBTA_HL_MCL_CFM);
3887 break;
3888 case BTA_HL_CCH_CLOSE_IND_EVT:
3889 param_len = sizeof(tBTA_HL_CCH_CLOSE_IND);
3890 break;
3891 case BTA_HL_DCH_CLOSE_IND_EVT:
3892 param_len = sizeof(tBTA_HL_DCH_CLOSE_IND);
3893 break;
3894 case BTA_HL_DCH_CLOSE_CFM_EVT:
3895 param_len = sizeof(tBTA_HL_MDL_CFM);
3896 break;
3897 case BTA_HL_DCH_ECHO_TEST_CFM_EVT:
3898 param_len = sizeof(tBTA_HL_MCL_CFM);
3899 break;
3900 case BTA_HL_DCH_RECONNECT_IND_EVT:
3901 param_len = sizeof(tBTA_HL_DCH_OPEN_IND);
3902 break;
3903 case BTA_HL_CONG_CHG_IND_EVT:
3904 param_len = sizeof(tBTA_HL_DCH_CONG_IND);
3905 break;
3906 case BTA_HL_DCH_ABORT_IND_EVT:
3907 param_len = sizeof(tBTA_HL_MCL_IND);
3908 break;
3909 case BTA_HL_DCH_ABORT_CFM_EVT:
3910 param_len = sizeof(tBTA_HL_MCL_CFM);
3911 break;
3912 case BTA_HL_DCH_SEND_DATA_CFM_EVT:
3913 param_len = sizeof(tBTA_HL_MDL_CFM);
3914 break;
3915 case BTA_HL_DCH_RCV_DATA_IND_EVT:
3916 param_len = sizeof(tBTA_HL_MDL_IND);
3917 break;
3918 default:
3919 param_len = sizeof(tBTA_HL_MDL_IND);
3920 break;
3921 }
3922 status = btif_transfer_context(btif_hl_upstreams_evt, (uint16_t)event, (void*)p_data, param_len, NULL);
3923
3924 /* catch any failed context transfers */
3925 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
3926}
3927
3928/*******************************************************************************
3929**
3930** Function btif_hl_upstreams_ctrl_evt
3931**
3932** Description Callback function for HL control events in the BTIF task context
3933**
3934** Returns void
3935**
3936*******************************************************************************/
3937static void btif_hl_upstreams_ctrl_evt(UINT16 event, char* p_param){
3938 tBTA_HL_CTRL *p_data = (tBTA_HL_CTRL *) p_param;
3939 UINT8 i;
3940 tBTA_HL_REG_PARAM reg_param;
3941 btif_hl_app_cb_t *p_acb;
3942
3943 BTIF_TRACE_DEBUG2("%s event %d", __FUNCTION__, event);
3944 btif_hl_display_calling_process_name();
3945
3946 switch ( event )
3947 {
3948 case BTA_HL_CTRL_ENABLE_CFM_EVT:
3949 BTIF_TRACE_DEBUG0("Rcv BTA_HL_CTRL_ENABLE_CFM_EVT");
3950 BTIF_TRACE_DEBUG1("status=%d", p_data->enable_cfm.status);
3951
3952 if (p_data->enable_cfm.status == BTA_HL_STATUS_OK)
3953 {
3954 btif_hl_set_state(BTIF_HL_STATE_ENABLED);
3955
3956
3957 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
3958 {
3959 p_acb = BTIF_HL_GET_APP_CB_PTR(i);
3960 if (p_acb->in_use && p_acb->reg_pending)
3961 {
3962 p_acb->reg_pending = FALSE;
3963 reg_param.dev_type = p_acb->dev_type;
3964 reg_param.sec_mask = BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT;
3965 reg_param.p_srv_name = p_acb->srv_name;
3966 reg_param.p_srv_desp = p_acb->srv_desp;
3967 reg_param.p_provider_name = p_acb->provider_name;
3968
3969 BTIF_TRACE_DEBUG1("Register pending app_id=%d", p_acb->app_id);
3970 btif_hl_proc_reg_request (i, p_acb->app_id, &reg_param, btif_hl_cback);
3971 }
3972 }
3973 }
3974
3975 break;
3976 case BTA_HL_CTRL_DISABLE_CFM_EVT:
3977 BTIF_TRACE_DEBUG0("Rcv BTA_HL_CTRL_DISABLE_CFM_EVT");
3978 BTIF_TRACE_DEBUG1("status=%d",
3979 p_data->disable_cfm.status);
3980
3981 if (p_data->disable_cfm.status == BTA_HL_STATUS_OK)
3982 {
3983 memset(p_btif_hl_cb, 0, sizeof(btif_hl_cb_t));
3984 btif_hl_set_state(BTIF_HL_STATE_DISABLED);
3985 }
3986
3987 break;
3988 default:
3989 break;
3990 }
3991}
3992
3993/*******************************************************************************
3994**
3995** Function btif_hl_ctrl_cback
3996**
3997** Description Callback function for HL control events
3998**
3999** Returns void
4000**
4001*******************************************************************************/
4002static void btif_hl_ctrl_cback(tBTA_HL_CTRL_EVT event, tBTA_HL_CTRL *p_data){
4003 bt_status_t status;
4004 int param_len = 0;
4005
4006 BTIF_TRACE_DEBUG2("%s event %d", __FUNCTION__, event);
4007 btif_hl_display_calling_process_name();
4008
4009 switch ( event )
4010 {
4011 case BTA_HL_CTRL_ENABLE_CFM_EVT:
4012 case BTA_HL_CTRL_DISABLE_CFM_EVT:
4013 param_len = sizeof(tBTA_HL_CTRL_ENABLE_DISABLE);
4014 break;
4015 default:
4016 break;
4017 }
4018
4019 status = btif_transfer_context(btif_hl_upstreams_ctrl_evt, (uint16_t)event, (void*)p_data, param_len, NULL);
4020 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
4021}
4022/*******************************************************************************
4023**
4024** Function connect_channel
4025**
4026** Description connect a data channel
4027**
4028** Returns bt_status_t
4029**
4030*******************************************************************************/
4031static bt_status_t connect_channel(int app_id, bt_bdaddr_t *bd_addr, int mdep_cfg_index, int *channel_id){
4032 UINT8 app_idx, mcl_idx;
4033 btif_hl_app_cb_t *p_acb = NULL;
Priti Agheraf8f30c22013-04-02 15:31:19 -07004034 btif_hl_pending_chan_cb_t *p_pcb = NULL;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004035 btif_hl_mcl_cb_t *p_mcb=NULL;
4036 bt_status_t status = BT_STATUS_SUCCESS;
4037 tBTA_HL_DCH_OPEN_PARAM dch_open;
4038 BD_ADDR bda;
4039 UINT8 i;
4040
4041 CHECK_BTHL_INIT();
4042 BTIF_TRACE_EVENT1("%s", __FUNCTION__);
4043 btif_hl_display_calling_process_name();
4044
4045
4046 for (i=0; i<6; i++)
4047 {
4048 bda[i] = (UINT8) bd_addr->address[i];
4049 }
4050 if (btif_hl_find_app_idx(((UINT8)app_id), &app_idx))
4051 {
4052 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
4053 if (btif_hl_find_mcl_idx(app_idx, bda , &mcl_idx))
4054 {
4055 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
4056 if (p_mcb->is_connected)
4057 {
4058 dch_open.ctrl_psm = p_mcb->ctrl_psm;
4059 dch_open.local_mdep_id = p_acb->sup_feature.mdep[mdep_cfg_index].mdep_id;
Priti Agheraf8f30c22013-04-02 15:31:19 -07004060 BTIF_TRACE_DEBUG4("connect_channel: app_idx =%d, mdep_cfg_indx =%d, mdep_id =%d app_id= %d", app_idx,
4061 mdep_cfg_index, dch_open.local_mdep_id, app_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -08004062 if (btif_hl_find_peer_mdep_id(p_acb->app_id, p_mcb->bd_addr,
4063 p_acb->sup_feature.mdep[mdep_cfg_index].mdep_cfg.mdep_role,
4064 p_acb->sup_feature.mdep[mdep_cfg_index].mdep_cfg.data_cfg[0].data_type, &dch_open.peer_mdep_id ))
4065 {
4066 dch_open.local_cfg = p_acb->channel_type[mdep_cfg_index];
4067 if ((p_acb->sup_feature.mdep[mdep_cfg_index].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SOURCE)
4068 && !btif_hl_is_the_first_reliable_existed(app_idx,mcl_idx))
4069 {
4070 dch_open.local_cfg = BTA_HL_DCH_CFG_RELIABLE;
4071 }
4072 dch_open.sec_mask = (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
4073
4074 if( !btif_hl_dch_open(p_acb->app_id, bda, &dch_open,
4075 mdep_cfg_index, BTIF_HL_PEND_DCH_OP_OPEN, channel_id ))
4076 {
4077 status = BT_STATUS_FAIL;
4078 BTIF_TRACE_EVENT1("%s loc0 status = BT_STATUS_FAIL", __FUNCTION__);
4079 }
4080 }
4081 else
4082 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07004083 p_mcb->cch_oper = BTIF_HL_CCH_OP_MDEP_FILTERING;
4084
4085 p_pcb = BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx);
4086 p_pcb->in_use = TRUE;
4087 p_pcb->mdep_cfg_idx = mdep_cfg_index;
4088 memcpy(p_pcb->bd_addr, bda, sizeof(BD_ADDR));
4089 p_pcb->op = BTIF_HL_PEND_DCH_OP_OPEN;
4090 BTA_HlSdpQuery(app_id,p_acb->app_handle, bda);
The Android Open Source Project5738f832012-12-12 16:00:35 -08004091 }
4092 }
4093 else
4094 {
4095 status = BT_STATUS_FAIL;
4096 }
4097 }
4098 else
4099 {
4100 p_acb->filter.num_elems =1;
4101 p_acb->filter.elem[0].data_type = p_acb->sup_feature.mdep[mdep_cfg_index].mdep_cfg.data_cfg[mdep_cfg_index].data_type;
4102 if (p_acb->sup_feature.mdep[mdep_cfg_index].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SINK)
4103 p_acb->filter.elem[0].peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE;
4104 else
4105 p_acb->filter.elem[0].peer_mdep_role = BTA_HL_MDEP_ROLE_SINK;
4106
4107 if ( !btif_hl_cch_open(p_acb->app_id, bda, 0, mdep_cfg_index,
4108 BTIF_HL_PEND_DCH_OP_OPEN,
4109 channel_id))
4110 {
4111 status = BT_STATUS_FAIL;
4112 }
4113 }
4114 }
4115 else
4116 {
4117 status = BT_STATUS_FAIL;
4118 }
4119
4120 BTIF_TRACE_DEBUG3("%s status=%d channel_id=0x%08x", __FUNCTION__, status, *channel_id);
4121
4122 return status;
4123}
4124/*******************************************************************************
4125**
4126** Function destroy_channel
4127**
4128** Description destroy a data channel
4129**
4130** Returns bt_status_t
4131**
4132*******************************************************************************/
4133static bt_status_t destroy_channel(int channel_id){
4134 UINT8 app_idx, mcl_idx, mdl_idx, mdl_cfg_idx, app_id, mdep_cfg_idx;
4135 bt_status_t status = BT_STATUS_SUCCESS;
4136 btif_hl_mdl_cfg_t *p_mdl;
4137 btif_hl_mcl_cb_t *p_mcb;
Priti Agheraf8f30c22013-04-02 15:31:19 -07004138 btif_hl_mdl_cb_t *p_dcb;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004139 btif_hl_app_cb_t *p_acb;
4140
4141 CHECK_BTHL_INIT();
4142 BTIF_TRACE_EVENT2("%s channel_id=0x%08x", __FUNCTION__, channel_id);
4143 btif_hl_display_calling_process_name();
4144
4145
4146 if (btif_hl_if_channel_setup_pending(channel_id, &app_idx, &mcl_idx))
4147 {
4148 btif_hl_dch_abort(app_idx, mcl_idx);
4149 }
4150 else
4151 {
4152 if (btif_hl_find_mdl_cfg_idx_using_channel_id(channel_id, &app_idx, &mdl_cfg_idx))
Priti Agheraf8f30c22013-04-02 15:31:19 -07004153 // if(btif_hl_find_mdl_idx_using_channel_id(channel_id, &app_idx,&mcl_idx, &mdl_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08004154 {
4155 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
4156 if (!p_acb->delete_mdl.active)
4157 {
4158 p_mdl =BTIF_HL_GET_MDL_CFG_PTR(app_idx, mdl_cfg_idx);
4159 p_acb->delete_mdl.active = TRUE;
4160 p_acb->delete_mdl.mdl_id = p_mdl->base.mdl_id;
4161 p_acb->delete_mdl.channel_id = channel_id;
4162 p_acb->delete_mdl.mdep_cfg_idx = p_mdl->extra.mdep_cfg_idx;
4163 memcpy(p_acb->delete_mdl.bd_addr, p_mdl->base.peer_bd_addr,sizeof(BD_ADDR));
4164
4165 if (btif_hl_find_mcl_idx(app_idx, p_mdl->base.peer_bd_addr, &mcl_idx))
4166 {
4167 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
4168 if (p_mcb->is_connected)
4169 {
4170 BTIF_TRACE_DEBUG1("calling BTA_HlDeleteMdl mdl_id=%d",p_acb->delete_mdl.mdl_id );
4171 BTA_HlDeleteMdl(p_mcb->mcl_handle, p_acb->delete_mdl.mdl_id);
4172 }
4173 else
4174 {
4175 status = BT_STATUS_FAIL;
4176 }
4177 }
4178 else
4179 {
4180 BTIF_TRACE_DEBUG0("btif_hl_delete_mdl calling btif_hl_cch_open" );
4181 mdep_cfg_idx = p_mdl->extra.mdep_cfg_idx;
4182 p_acb->filter.num_elems =1;
4183 p_acb->filter.elem[0].data_type = p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.data_cfg[mdep_cfg_idx].data_type;
4184 if (p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SINK)
4185 p_acb->filter.elem[0].peer_mdep_role = BTA_HL_MDEP_ROLE_SOURCE;
4186 else
4187 p_acb->filter.elem[0].peer_mdep_role = BTA_HL_MDEP_ROLE_SINK;
4188 if (btif_hl_cch_open(p_acb->app_id, p_acb->delete_mdl.bd_addr, 0,
4189 mdep_cfg_idx,
4190 BTIF_HL_PEND_DCH_OP_DELETE_MDL, NULL))
4191 {
4192 status = BT_STATUS_FAIL;
4193 }
4194 }
4195
4196 if ( status == BT_STATUS_FAIL)
4197 {
4198 /* fail for now */
4199 btif_hl_clean_delete_mdl(&p_acb->delete_mdl);
4200 }
4201 }
4202 else
4203 {
4204 status = BT_STATUS_BUSY;
4205 }
4206 }
4207 else
4208 {
4209 status = BT_STATUS_FAIL;
4210 }
4211
4212 }
4213 return status;
4214}
4215/*******************************************************************************
4216**
4217** Function unregister_application
4218**
4219** Description unregister an HDP application
4220**
4221** Returns bt_status_t
4222**
4223*******************************************************************************/
4224static bt_status_t unregister_application(int app_id){
4225 btif_hl_app_cb_t *p_acb;
4226 UINT8 app_idx;
4227 int len;
4228 bt_status_t status = BT_STATUS_SUCCESS;
4229 btif_hl_evt_cb_t evt_param;
4230
4231 CHECK_BTHL_INIT();
4232 BTIF_TRACE_EVENT2("%s app_id=%d", __FUNCTION__, app_id);
4233 btif_hl_display_calling_process_name();
4234
4235 if (btif_hl_find_app_idx(((UINT8)app_id), &app_idx))
4236 {
4237 evt_param.unreg.app_idx = app_idx;
Priti Agheraf8f30c22013-04-02 15:31:19 -07004238 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
4239 reg_counter --;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004240 len = sizeof(btif_hl_unreg_t);
4241 status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_UNREG_APP,
4242 (char*) &evt_param, len, NULL);
4243 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
The Android Open Source Project5738f832012-12-12 16:00:35 -08004244 }
4245 else
4246 {
4247 status = BT_STATUS_FAIL;
4248 }
4249
4250 BTIF_TRACE_DEBUG1("de-reg return status=%d", status);
4251 return status;
4252}
4253/*******************************************************************************
4254**
4255** Function register_application
4256**
4257** Description register an HDP application
4258**
4259** Returns bt_status_t
4260**
4261*******************************************************************************/
4262static bt_status_t register_application(bthl_reg_param_t *p_reg_param, int *app_id){
4263 btif_hl_app_cb_t *p_acb;
4264 tBTA_HL_SUP_FEATURE *p_sup;
4265 tBTA_HL_MDEP_CFG *p_cfg;
4266 tBTA_HL_MDEP_DATA_TYPE_CFG *p_data;
4267 UINT8 app_idx=0, i=0, pending_reg_idx=0;
4268 bthl_mdep_cfg_t *p_mdep_cfg;
4269 bt_status_t status = BT_STATUS_SUCCESS;
4270 btif_hl_evt_cb_t evt_param;
4271 int len;
4272
4273 CHECK_BTHL_INIT();
4274 BTIF_TRACE_EVENT1("%s", __FUNCTION__);
4275 btif_hl_display_calling_process_name();
4276
4277 if (btif_hl_get_state() == BTIF_HL_STATE_DISABLED)
4278 {
4279 btif_hl_init();
4280 btif_hl_set_state(BTIF_HL_STATE_ENABLING);
4281 BTA_HlEnable(btif_hl_ctrl_cback);
4282 }
4283
4284 if (!btif_hl_find_avail_app_idx(&app_idx))
4285 {
4286 BTIF_TRACE_ERROR0("Unable to allocate a new application control block");
4287 return BT_STATUS_FAIL;
4288 }
4289
4290 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
4291 p_acb->in_use = TRUE;
4292
4293
4294 p_acb->app_id = btif_hl_get_next_app_id();
4295
4296 if (p_reg_param->application_name != NULL )
4297 strncpy(p_acb->application_name, p_reg_param->application_name, BTIF_HL_APPLICATION_NAME_LEN);
4298
4299 if (p_reg_param->provider_name != NULL )
4300 strncpy(p_acb->provider_name, p_reg_param->provider_name, BTA_PROVIDER_NAME_LEN);
4301
4302 if (p_reg_param->srv_name != NULL )
4303 strncpy(p_acb->srv_name, p_reg_param->srv_name, BTA_SERVICE_NAME_LEN);
4304
4305 if (p_reg_param->srv_desp != NULL )
4306 strncpy(p_acb->srv_desp, p_reg_param->srv_desp, BTA_SERVICE_DESP_LEN);
4307
4308 p_sup = &p_acb->sup_feature;
4309 p_sup->advertize_source_sdp = TRUE;
4310 p_sup->echo_cfg.max_rx_apdu_size = BTIF_HL_ECHO_MAX_TX_RX_APDU_SIZE;
4311 p_sup->echo_cfg.max_tx_apdu_size = BTIF_HL_ECHO_MAX_TX_RX_APDU_SIZE;
4312 p_sup->num_of_mdeps = p_reg_param->number_of_mdeps;
4313
4314 for (i=0, p_mdep_cfg = p_reg_param->mdep_cfg ; i< p_sup->num_of_mdeps; i++, p_mdep_cfg++ )
4315 {
4316 p_cfg = &p_sup->mdep[i].mdep_cfg;
4317 p_cfg->num_of_mdep_data_types = 1;
4318 p_data = &p_cfg->data_cfg[0];
4319
4320 if ( !btif_hl_get_bta_mdep_role(p_mdep_cfg->mdep_role, &(p_cfg->mdep_role)))
4321 {
4322 BTIF_TRACE_ERROR1("Invalid mdep_role=%d", p_mdep_cfg->mdep_role);
4323 status = BT_STATUS_FAIL;
4324 break;
4325 }
4326 else
4327 {
4328 if (p_cfg->mdep_role == BTA_HL_MDEP_ROLE_SINK )
4329 p_sup->app_role_mask |= BTA_HL_MDEP_ROLE_MASK_SINK;
4330 else
4331 p_sup->app_role_mask |= BTA_HL_MDEP_ROLE_MASK_SOURCE;
4332
4333 if ( (p_sup->app_role_mask & BTA_HL_MDEP_ROLE_MASK_SINK) &&
4334 (p_sup->app_role_mask & BTA_HL_MDEP_ROLE_MASK_SINK) )
4335 {
4336 p_acb->dev_type = BTA_HL_DEVICE_TYPE_DUAL;
4337 }
4338 else if ( p_sup->app_role_mask & BTA_HL_MDEP_ROLE_MASK_SINK )
4339 p_acb->dev_type = BTA_HL_DEVICE_TYPE_SINK;
4340 else
4341
4342 p_acb->dev_type = BTA_HL_DEVICE_TYPE_SOURCE;
4343
4344 p_data->data_type = (UINT16) p_mdep_cfg->data_type;
4345 p_data->max_rx_apdu_size = btif_hl_get_max_rx_apdu_size(p_cfg->mdep_role, p_data->data_type);
4346 p_data->max_tx_apdu_size = btif_hl_get_max_tx_apdu_size(p_cfg->mdep_role, p_data->data_type);
4347
4348 if (p_mdep_cfg->mdep_description != NULL )
4349 strncpy(p_data->desp, p_mdep_cfg->mdep_description, BTA_SERVICE_DESP_LEN);
4350
4351 if ( !btif_hl_get_bta_channel_type(p_mdep_cfg->channel_type, &(p_acb->channel_type[i])))
4352 {
4353 BTIF_TRACE_ERROR1("Invalid channel_type=%d", p_mdep_cfg->channel_type);
4354 status = BT_STATUS_FAIL;
4355 break;
4356 }
4357 }
4358 }
4359
4360 if (status == BT_STATUS_SUCCESS)
4361 {
4362 *app_id = (int) p_acb->app_id;
4363 evt_param.reg.app_idx = app_idx;
4364 len = sizeof(btif_hl_reg_t);
4365 p_acb->reg_pending = TRUE;
Priti Agheraf8f30c22013-04-02 15:31:19 -07004366 reg_counter++;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004367 BTIF_TRACE_DEBUG2("calling btif_transfer_context status=%d app_id=%d", status, *app_id);
4368 status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_REG_APP,
4369 (char*) &evt_param, len, NULL);
4370 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
4371
4372 }
4373 else
4374 {
4375 btif_hl_free_app_idx(app_idx);
4376 }
4377
4378 BTIF_TRACE_DEBUG2("register_application status=%d app_id=%d", status, *app_id);
4379 return status;
4380}
Priti Agheraf8f30c22013-04-02 15:31:19 -07004381
4382/*******************************************************************************
4383**
4384** Function btif_hl_save_mdl_cfg
4385**
4386** Description Save the MDL configuration
4387**
4388** Returns BOOLEAN
4389**
4390*******************************************************************************/
4391BOOLEAN btif_hl_save_mdl_cfg(UINT8 mdep_id, UINT8 item_idx,
4392 tBTA_HL_MDL_CFG *p_mdl_cfg){
4393 btif_hl_mdl_cfg_t *p_mdl=NULL;
4394 BOOLEAN success = FALSE;
4395 btif_hl_app_cb_t *p_acb;
4396 btif_hl_mcl_cb_t *p_mcb;
4397 UINT8 app_idx, mcl_idx, mdl_idx, len;
4398 bt_status_t bt_status;
4399 btif_hl_evt_cb_t evt_param;
4400 int *p_channel_id;
4401
4402 BTIF_TRACE_DEBUG6("%s mdep_id=%d item_idx=%d, local_mdep_id=%d mdl_id=0x%x dch_mode=%d",
4403 __FUNCTION__, mdep_id, item_idx, p_mdl_cfg->local_mdep_id,
4404 p_mdl_cfg->mdl_id, p_mdl_cfg->dch_mode );
4405
4406 if(btif_hl_find_app_idx_using_mdepId(mdep_id,&app_idx))
4407 {
4408 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
4409 p_mdl = BTIF_HL_GET_MDL_CFG_PTR(app_idx, item_idx);
4410 p_channel_id = BTIF_HL_GET_MDL_CFG_CHANNEL_ID_PTR(app_idx, item_idx);
4411 if (p_mdl)
4412 {
4413 memcpy(&p_mdl->base, p_mdl_cfg, sizeof(tBTA_HL_MDL_CFG));
4414 if (btif_hl_find_mcl_idx(app_idx, p_mdl->base.peer_bd_addr , &mcl_idx))
4415 {
4416 p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
4417 if (p_mcb->pcb.in_use)
4418 *p_channel_id = p_mcb->pcb.channel_id;
4419 else
4420 *p_channel_id = btif_hl_get_next_channel_id(p_acb->app_id);
4421 p_mdl->extra.mdep_cfg_idx = p_mcb->pcb.mdep_cfg_idx;
4422 p_mdl->extra.data_type = p_acb->sup_feature.mdep[p_mcb->pcb.mdep_cfg_idx].mdep_cfg.data_cfg[0].data_type;
4423
4424 if (!btif_hl_find_peer_mdep_id(p_acb->app_id, p_mcb->bd_addr,
4425 p_acb->sup_feature.mdep[p_mcb->pcb.mdep_cfg_idx].mdep_cfg.mdep_role,
4426 p_acb->sup_feature.mdep[p_mcb->pcb.mdep_cfg_idx].mdep_cfg.data_cfg[0].data_type,
4427 &p_mdl->extra.peer_mdep_id))
4428 {
4429 p_mdl->extra.peer_mdep_id = BTA_HL_INVALID_MDEP_ID;
4430 }
4431 BTIF_TRACE_DEBUG4("%s app_idx=%d item_idx=%d mld_id=0x%x",
4432 __FUNCTION__, app_idx, item_idx, p_mdl->base.mdl_id);
4433 evt_param.update_mdl.app_idx = app_idx;
4434 len = sizeof(btif_hl_update_mdl_t);
4435 BTIF_TRACE_DEBUG1("send BTIF_HL_UPDATE_MDL event app_idx=%d ",app_idx);
4436 if ((bt_status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_UPDATE_MDL,
4437 (char*) &evt_param, len, NULL)) == BT_STATUS_SUCCESS)
4438 {
4439 success = TRUE;
4440 }
4441 ASSERTC(bt_status == BT_STATUS_SUCCESS, "context transfer failed", bt_status);
4442 }
4443 }
4444 }
4445 BTIF_TRACE_DEBUG2("%s success=%d ",__FUNCTION__, success );
4446
4447 return success;
4448}
4449
4450/*******************************************************************************
4451**
4452** Function btif_hl_delete_mdl_cfg
4453**
4454** Description Delete the MDL configuration
4455**
4456** Returns BOOLEAN
4457**
4458*******************************************************************************/
4459BOOLEAN btif_hl_delete_mdl_cfg(UINT8 mdep_id, UINT8 item_idx){
4460 btif_hl_mdl_cfg_t *p_mdl=NULL;
4461 BOOLEAN success = FALSE;
4462 btif_hl_app_cb_t *p_acb;
4463 UINT8 app_idx, len;
4464 bt_status_t bt_status;
4465 btif_hl_evt_cb_t evt_param;
4466
4467 if(btif_hl_find_app_idx_using_mdepId(mdep_id,&app_idx))
4468 {
4469
4470 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
4471
4472 p_mdl = BTIF_HL_GET_MDL_CFG_PTR(app_idx, item_idx);
4473 if (p_mdl)
4474 {
4475 memset(p_mdl, 0, sizeof(btif_hl_mdl_cfg_t));
4476 evt_param.update_mdl.app_idx = app_idx;
4477 len = sizeof(btif_hl_update_mdl_t);
4478 BTIF_TRACE_DEBUG1("send BTIF_HL_UPDATE_MDL event app_idx=%d ",app_idx);
4479 if ((bt_status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_UPDATE_MDL,
4480 (char*) &evt_param, len, NULL)) == BT_STATUS_SUCCESS)
4481 {
4482 success = TRUE;
4483 }
4484 ASSERTC(bt_status == BT_STATUS_SUCCESS, "context transfer failed", bt_status);
4485 }
4486 }
4487
4488 BTIF_TRACE_DEBUG2("%s success=%d ",__FUNCTION__, success );
4489 return success;
4490}
4491
4492/*******************************************************************************
4493**
4494** Function get_device_datatype
4495**
4496** Description Start SDP on remote device and look for Remote HDP Data type and role
4497**
4498** Returns bt_status_t
4499**
4500*******************************************************************************/
4501static bt_status_t get_device_datatype(int app_id, bt_bdaddr_t *bd_addr){
4502 btif_hl_app_cb_t *p_acb;
4503 UINT8 app_idx;
4504 bt_status_t status = BT_STATUS_SUCCESS;
4505 BD_ADDR bda;
4506 UINT8 i;
4507
4508 CHECK_BTHL_INIT();
4509 BTIF_TRACE_EVENT2("%s app_id=%d", __FUNCTION__, app_id);
4510 btif_hl_display_calling_process_name();
4511
4512 for (i=0; i<6; i++)
4513 {
4514 bda[i] = (UINT8) bd_addr->address[i];
4515 }
4516
4517 if (btif_hl_find_app_idx(((UINT8)app_id), &app_idx))
4518 {
4519 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
4520 BTA_HlSdpQuery(app_id,p_acb->app_handle,bda);
4521 }
4522 else
4523 {
4524 status = BT_STATUS_FAIL;
4525 }
4526
4527 BTIF_TRACE_DEBUG1("de-reg return status=%d", status);
4528 return status;
4529}
4530
The Android Open Source Project5738f832012-12-12 16:00:35 -08004531/*******************************************************************************
4532**
4533** Function init
4534**
4535** Description initializes the hl interface
4536**
4537** Returns bt_status_t
4538**
4539*******************************************************************************/
4540static bt_status_t init( bthl_callbacks_t* callbacks ){
4541 bt_status_t status = BT_STATUS_SUCCESS;
4542
4543 BTIF_TRACE_EVENT1("%s", __FUNCTION__);
4544 btif_hl_display_calling_process_name();
4545 bt_hl_callbacks_cb = *callbacks;
4546 bt_hl_callbacks = &bt_hl_callbacks_cb;
4547 btif_hl_soc_thread_init();
Priti Agheraf8f30c22013-04-02 15:31:19 -07004548 reg_counter = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004549 return status;
4550}
4551/*******************************************************************************
4552**
4553** Function cleanup
4554**
4555** Description Closes the HL interface
4556**
4557** Returns void
4558**
4559*******************************************************************************/
4560static void cleanup( void ){
4561 BTIF_TRACE_EVENT1("%s", __FUNCTION__);
4562 btif_hl_display_calling_process_name();
4563 if (bt_hl_callbacks)
4564 {
4565 btif_disable_service(BTA_HDP_SERVICE_ID);
4566 bt_hl_callbacks = NULL;
Priti Agheraf8f30c22013-04-02 15:31:19 -07004567 reg_counter = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004568 }
4569
4570 btif_hl_disable();
4571 btif_hl_close_select_thread();
4572}
4573
4574static const bthl_interface_t bthlInterface = {
Priti Agheraf8f30c22013-04-02 15:31:19 -07004575 sizeof(bthl_interface_t),
The Android Open Source Project5738f832012-12-12 16:00:35 -08004576 init,
4577 register_application,
4578 unregister_application,
4579 connect_channel,
4580 destroy_channel,
4581 cleanup,
4582};
4583
4584
4585/*******************************************************************************
4586**
4587** Function btif_hl_get_interface
4588**
4589** Description Get the hl callback interface
4590**
4591** Returns bthf_interface_t
4592**
4593*******************************************************************************/
4594const bthl_interface_t *btif_hl_get_interface(){
4595 BTIF_TRACE_EVENT1("%s", __FUNCTION__);
4596 return &bthlInterface;
4597}
4598
4599/*******************************************************************************
4600**
4601** Function btif_hl_update_maxfd
4602**
4603** Description Update the max fd if the input fd is greater than the current max fd
4604**
4605** Returns int
4606**
4607*******************************************************************************/
4608int btif_hl_update_maxfd( int max_org_s){
4609 btif_hl_soc_cb_t *p_scb = NULL;
4610 int maxfd=0;
4611
4612 BTIF_TRACE_DEBUG1("btif_hl_update_maxfd max_org_s= %d", max_org_s);
4613
4614 maxfd = max_org_s;
4615 if (!GKI_queue_is_empty(&soc_queue))
4616 {
4617 p_scb = (btif_hl_soc_cb_t *)GKI_getfirst((void *)&soc_queue);
4618 if (maxfd < p_scb->max_s)
4619 {
4620 maxfd = p_scb->max_s;
4621 BTIF_TRACE_DEBUG1("btif_hl_update_maxfd 1 maxfd=%d", maxfd);
4622 }
4623 while (p_scb != NULL)
4624 {
4625 if (maxfd < p_scb->max_s)
4626 {
4627 maxfd = p_scb->max_s;
4628 BTIF_TRACE_DEBUG1("btif_hl_update_maxfd 2 maxfd=%d", maxfd);
4629 }
4630 p_scb = (btif_hl_soc_cb_t *)GKI_getnext((void *)p_scb );
4631 }
4632 }
4633
4634 BTIF_TRACE_DEBUG1("btif_hl_update_maxfd final *p_max_s=%d", maxfd);
4635 return maxfd;
4636}
4637/*******************************************************************************
4638**
4639** Function btif_hl_get_socket_state
4640**
4641** Description get socket state
4642**
4643** Returns btif_hl_soc_state_t
4644**
4645*******************************************************************************/
4646btif_hl_soc_state_t btif_hl_get_socket_state(btif_hl_soc_cb_t *p_scb){
4647 BTIF_TRACE_DEBUG1("btif_hl_get_socket_state state=%d", p_scb->state);
4648 return p_scb->state;
4649}
4650/*******************************************************************************
4651**
4652** Function btif_hl_set_socket_state
4653**
4654** Description set socket state
4655**
4656** Returns void
4657**
4658*******************************************************************************/
4659void btif_hl_set_socket_state(btif_hl_soc_cb_t *p_scb, btif_hl_soc_state_t new_state){
4660 BTIF_TRACE_DEBUG2("btif_hl_set_socket_state %d---->%d", p_scb->state, new_state);
4661 p_scb->state = new_state;
4662}
4663/*******************************************************************************
4664**
4665** Function btif_hl_release_mcl_sockets
4666**
4667** Description Release all sockets on the MCL
4668**
4669** Returns void
4670**
4671*******************************************************************************/
4672void btif_hl_release_mcl_sockets(UINT8 app_idx, UINT8 mcl_idx){
4673 btif_hl_soc_cb_t *p_scb = NULL;
4674 UINT8 i;
4675 btif_hl_mdl_cb_t *p_dcb;
4676 BOOLEAN found= FALSE;
4677 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
4678 for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++)
4679 {
4680 p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, i);
4681 if (p_dcb && p_dcb->in_use && p_dcb->p_scb)
4682 {
4683 BTIF_TRACE_DEBUG3("found socket for app_idx=%d mcl_id=%d, mdl_idx=%d", app_idx, mcl_idx, i);
4684 btif_hl_set_socket_state (p_dcb->p_scb, BTIF_HL_SOC_STATE_W4_REL);
4685 p_dcb->p_scb = NULL;
4686 found = TRUE;
4687 }
4688 }
4689 if (found)
4690 btif_hl_select_close_connected();
4691}
4692/*******************************************************************************
4693**
4694** Function btif_hl_release_socket
4695**
4696** Description release a specified socket
4697**
4698** Returns void
4699**
4700*******************************************************************************/
4701void btif_hl_release_socket(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx){
4702 btif_hl_soc_cb_t *p_scb = NULL;
4703 btif_hl_mdl_cb_t *p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
4704
4705 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
4706 BTIF_TRACE_DEBUG3("app_idx=%d mcl_idx=%d mdl_idx=%d", app_idx, mcl_idx, mdl_idx );
4707
4708 if (p_dcb && p_dcb->p_scb)
4709 {
4710 p_scb = p_dcb->p_scb;
4711 btif_hl_set_socket_state(p_scb, BTIF_HL_SOC_STATE_W4_REL);
4712 p_dcb->p_scb = NULL;
4713 btif_hl_select_close_connected();
4714 }
4715}
4716/*******************************************************************************
4717**
4718** Function btif_hl_create_socket
4719**
4720** Description create a socket
4721**
4722** Returns BOOLEAN
4723**
4724*******************************************************************************/
4725BOOLEAN btif_hl_create_socket(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx){
4726 btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
4727 btif_hl_mdl_cb_t *p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
4728 btif_hl_soc_cb_t *p_scb = NULL;
4729 UINT8 soc_idx;
4730 BOOLEAN status = FALSE;
4731
4732 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
4733
4734 if (p_dcb && ((p_scb = (btif_hl_soc_cb_t *)GKI_getbuf((UINT16)sizeof(btif_hl_soc_cb_t)))!=NULL))
4735 {
4736 if (socketpair(AF_UNIX, SOCK_STREAM, 0, p_scb->socket_id) >= 0)
4737 {
4738 BTIF_TRACE_DEBUG2("socket id[0]=%d id[1]=%d",p_scb->socket_id[0], p_scb->socket_id[1] );
4739 p_dcb->p_scb = p_scb;
4740 p_scb->app_idx = app_idx;
4741 p_scb->mcl_idx = mcl_idx;
4742 p_scb->mdl_idx = mdl_idx;
4743 p_scb->channel_id = p_dcb->channel_id;
4744 p_scb->mdep_cfg_idx = p_dcb->local_mdep_cfg_idx;
4745 memcpy(p_scb->bd_addr, p_mcb->bd_addr,sizeof(BD_ADDR));
4746 btif_hl_set_socket_state(p_scb, BTIF_HL_SOC_STATE_W4_ADD);
4747 p_scb->max_s = p_scb->socket_id[1];
4748 GKI_enqueue(&soc_queue, (void *) p_scb);
4749 btif_hl_select_wakeup();
4750 status = TRUE;
4751 }
4752 else
4753 {
4754
4755 btif_hl_free_buf((void **)&p_scb);
4756 }
4757 }
4758
4759 BTIF_TRACE_DEBUG2("%s status=%d", __FUNCTION__, status);
4760 return status;
4761}
4762/*******************************************************************************
4763**
4764** Function btif_hl_add_socket_to_set
4765**
4766** Description Add a socket
4767**
4768** Returns void
4769**
4770*******************************************************************************/
4771void btif_hl_add_socket_to_set( fd_set *p_org_set){
4772 btif_hl_soc_cb_t *p_scb = NULL;
4773 btif_hl_mdl_cb_t *p_dcb = NULL;
4774 btif_hl_mcl_cb_t *p_mcb = NULL;
Priti Agheraf8f30c22013-04-02 15:31:19 -07004775 btif_hl_app_cb_t *p_acb = NULL;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004776 btif_hl_evt_cb_t evt_param;
4777 bt_status_t status;
4778 int len;
4779
4780 BTIF_TRACE_DEBUG1("entering %s",__FUNCTION__);
4781
4782 if (!GKI_queue_is_empty(&soc_queue))
4783 {
4784 p_scb = (btif_hl_soc_cb_t *)GKI_getfirst((void *)&soc_queue);
4785 BTIF_TRACE_DEBUG1("btif_hl_add_socket_to_set first p_scb=0x%x", p_scb);
4786 while (p_scb != NULL)
4787 {
4788 if (btif_hl_get_socket_state(p_scb) == BTIF_HL_SOC_STATE_W4_ADD)
4789 {
4790 btif_hl_set_socket_state(p_scb, BTIF_HL_SOC_STATE_W4_READ);
4791 FD_SET(p_scb->socket_id[1], p_org_set);
4792 BTIF_TRACE_DEBUG2("found and set socket_id=%d is_set=%d", p_scb->socket_id[1], FD_ISSET(p_scb->socket_id[1], p_org_set));
4793 p_mcb = BTIF_HL_GET_MCL_CB_PTR(p_scb->app_idx, p_scb->mcl_idx);
4794 p_dcb = BTIF_HL_GET_MDL_CB_PTR(p_scb->app_idx, p_scb->mcl_idx, p_scb->mdl_idx);
Priti Agheraf8f30c22013-04-02 15:31:19 -07004795 p_acb = BTIF_HL_GET_APP_CB_PTR(p_scb->app_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08004796 if (p_mcb && p_dcb)
4797 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07004798 btif_hl_stop_timer_using_handle(p_mcb->mcl_handle);
4799 evt_param.chan_cb.app_id = p_acb->app_id;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004800 memcpy(evt_param.chan_cb.bd_addr, p_mcb->bd_addr, sizeof(BD_ADDR));
4801 evt_param.chan_cb.channel_id = p_dcb->channel_id;
4802 evt_param.chan_cb.fd = p_scb->socket_id[0];
4803 evt_param.chan_cb.mdep_cfg_index = (int ) p_dcb->local_mdep_cfg_idx;
4804 evt_param.chan_cb.cb_state = BTIF_HL_CHAN_CB_STATE_CONNECTED_PENDING;
4805 len = sizeof(btif_hl_send_chan_state_cb_t);
4806 status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_SEND_CONNECTED_CB,
4807 (char*) &evt_param, len, NULL);
4808 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
4809 }
4810 }
4811 p_scb = (btif_hl_soc_cb_t *)GKI_getnext((void *)p_scb );
4812 BTIF_TRACE_DEBUG1("next p_scb=0x%x", p_scb);
4813 }
4814 }
4815
4816 BTIF_TRACE_DEBUG1("leaving %s",__FUNCTION__);
4817}
4818/*******************************************************************************
4819**
4820** Function btif_hl_close_socket
4821**
4822** Description close a socket
4823**
4824** Returns void
4825**
4826*******************************************************************************/
4827void btif_hl_close_socket( fd_set *p_org_set){
4828 btif_hl_soc_cb_t *p_scb = NULL;
4829 BOOLEAN element_removed = FALSE;
4830 btif_hl_mdl_cb_t *p_dcb = NULL ;
Priti Agheraf8f30c22013-04-02 15:31:19 -07004831 btif_hl_app_cb_t *p_acb = NULL ;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004832 btif_hl_evt_cb_t evt_param;
4833 int len;
Priti Agheraf8f30c22013-04-02 15:31:19 -07004834 int app_idx;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004835 bt_status_t status;
4836
4837 BTIF_TRACE_DEBUG1("entering %s",__FUNCTION__);
4838 if (!GKI_queue_is_empty(&soc_queue))
4839 {
4840 p_scb = (btif_hl_soc_cb_t *)GKI_getfirst((void *)&soc_queue);
4841 while (p_scb != NULL)
4842 {
4843 if (btif_hl_get_socket_state(p_scb) == BTIF_HL_SOC_STATE_W4_REL)
4844 {
4845 BTIF_TRACE_DEBUG3("app_idx=%d mcl_id=%d, mdl_idx=%d",
4846 p_scb->app_idx, p_scb->mcl_idx, p_scb->mdl_idx);
4847 btif_hl_set_socket_state(p_scb, BTIF_HL_SOC_STATE_IDLE);
4848 if (p_scb->socket_id[1] != -1)
4849 {
4850 FD_CLR(p_scb->socket_id[1] , p_org_set);
4851 shutdown(p_scb->socket_id[1], SHUT_RDWR);
4852 close(p_scb->socket_id[1]);
4853
4854 evt_param.chan_cb.app_id = (int) btif_hl_get_app_id(p_scb->channel_id);
4855 memcpy(evt_param.chan_cb.bd_addr, p_scb->bd_addr, sizeof(BD_ADDR));
4856 evt_param.chan_cb.channel_id = p_scb->channel_id;
4857 evt_param.chan_cb.fd = p_scb->socket_id[0];
4858 evt_param.chan_cb.mdep_cfg_index = (int ) p_scb->mdep_cfg_idx;
4859 evt_param.chan_cb.cb_state = BTIF_HL_CHAN_CB_STATE_DISCONNECTED_PENDING;
4860 len = sizeof(btif_hl_send_chan_state_cb_t);
4861 status = btif_transfer_context (btif_hl_proc_cb_evt, BTIF_HL_SEND_DISCONNECTED_CB,
4862 (char*) &evt_param, len, NULL);
4863 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
4864
4865
The Android Open Source Project5738f832012-12-12 16:00:35 -08004866 }
4867 }
4868 p_scb = (btif_hl_soc_cb_t *)GKI_getnext((void *)p_scb );
4869 BTIF_TRACE_DEBUG1("while loop next p_scb=0x%x", p_scb);
4870 }
4871
4872 p_scb = (btif_hl_soc_cb_t *)GKI_getfirst((void *)&soc_queue);
4873 while (p_scb != NULL)
4874 {
4875 if (btif_hl_get_socket_state(p_scb) == BTIF_HL_SOC_STATE_IDLE)
4876 {
4877 p_dcb = BTIF_HL_GET_MDL_CB_PTR(p_scb->app_idx, p_scb->mcl_idx, p_scb->mdl_idx);
4878 BTIF_TRACE_DEBUG4("idle socket app_idx=%d mcl_id=%d, mdl_idx=%d p_dcb->in_use=%d",
4879 p_scb->app_idx, p_scb->mcl_idx, p_scb->mdl_idx, p_dcb->in_use);
4880 GKI_remove_from_queue((void *)&soc_queue, p_scb);
4881 btif_hl_free_buf((void **)&p_scb);
4882 p_dcb->p_scb = NULL;
4883 element_removed = TRUE;
4884 }
4885 BTIF_TRACE_DEBUG2("element_removed=%d p_scb=0x%x", element_removed, p_scb);
4886 if (element_removed)
4887 {
4888 element_removed = FALSE;
4889 p_scb = (btif_hl_soc_cb_t *)GKI_getfirst((void *)&soc_queue);
4890 }
4891 else
4892 p_scb = (btif_hl_soc_cb_t *)GKI_getnext((void *)p_scb );
4893
4894 BTIF_TRACE_DEBUG1("while loop p_scb=0x%x", p_scb);
4895 }
4896 }
4897 BTIF_TRACE_DEBUG1("leaving %s",__FUNCTION__);
4898}
4899/*******************************************************************************
4900**
4901** Function btif_hl_select_wakeup_callback
4902**
4903** Description Select wakup callback to add or close a socket
4904**
4905** Returns void
4906**
4907*******************************************************************************/
4908
4909void btif_hl_select_wakeup_callback( fd_set *p_org_set , int wakeup_signal){
4910 BTIF_TRACE_DEBUG2("entering %s wakeup_signal=0x%04x",__FUNCTION__, wakeup_signal);
4911
4912 if (wakeup_signal == btif_hl_signal_select_wakeup )
4913 {
4914 btif_hl_add_socket_to_set(p_org_set);
4915 }
4916 else if (wakeup_signal == btif_hl_signal_select_close_connected)
4917 {
4918 btif_hl_close_socket(p_org_set);
4919 }
4920 BTIF_TRACE_DEBUG1("leaving %s",__FUNCTION__);
4921}
4922
4923/*******************************************************************************
4924**
4925** Function btif_hl_select_monitor_callback
4926**
4927** Description Select monitor callback to check pending socket actions
4928**
4929** Returns void
4930**
4931*******************************************************************************/
4932void btif_hl_select_monitor_callback( fd_set *p_cur_set , fd_set *p_org_set){
4933 btif_hl_soc_cb_t *p_scb = NULL;
4934 btif_hl_mdl_cb_t *p_dcb = NULL;
4935 int r;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08004936 UNUSED(p_org_set);
The Android Open Source Project5738f832012-12-12 16:00:35 -08004937
4938 BTIF_TRACE_DEBUG1("entering %s",__FUNCTION__);
4939
4940 if (!GKI_queue_is_empty(&soc_queue))
4941 {
4942 p_scb = (btif_hl_soc_cb_t *)GKI_getfirst((void *)&soc_queue);
4943 BTIF_TRACE_DEBUG0(" GKI queue is not empty ");
4944 while (p_scb != NULL)
4945 {
4946 if (btif_hl_get_socket_state(p_scb) == BTIF_HL_SOC_STATE_W4_READ)
4947 {
4948 if (FD_ISSET(p_scb->socket_id[1], p_cur_set))
4949 {
4950 BTIF_TRACE_DEBUG0("read data");
4951 BTIF_TRACE_DEBUG0("state= BTIF_HL_SOC_STATE_W4_READ");
4952 p_dcb = BTIF_HL_GET_MDL_CB_PTR(p_scb->app_idx, p_scb->mcl_idx, p_scb->mdl_idx);
4953 if (p_dcb->p_tx_pkt)
4954 {
4955 BTIF_TRACE_ERROR1("Rcv new pkt but the last pkt is still not been sent tx_size=%d", p_dcb->tx_size);
4956 btif_hl_free_buf((void **) &p_dcb->p_tx_pkt);
4957 }
4958 p_dcb->p_tx_pkt = btif_hl_get_buf (p_dcb->mtu);
4959 if (p_dcb )
4960 {
4961 //do
4962 // {
4963 // r = recv(p_scb->socket_id[1], p_dcb->p_tx_pkt, p_dcb->mtu , MSG_DONTWAIT));
4964 // } while (r == SOCKET_ERROR && errno == EINTR);
4965
4966 if ((r = (int)recv(p_scb->socket_id[1], p_dcb->p_tx_pkt, p_dcb->mtu , MSG_DONTWAIT)) > 0)
4967 {
4968 BTIF_TRACE_DEBUG1("btif_hl_select_monitor_callback send data r =%d", r);
4969 p_dcb->tx_size = r;
4970 BTIF_TRACE_DEBUG1("btif_hl_select_monitor_callback send data tx_size=%d", p_dcb->tx_size );
4971 BTA_HlSendData(p_dcb->mdl_handle, p_dcb->tx_size );
4972 }
4973
4974 if (r <= 0 )
4975 {
4976 BTIF_TRACE_DEBUG1("btif_hl_select_monitor_callback receive failed r=%d",r);
4977 BTA_HlDchClose(p_dcb->mdl_handle );
4978 }
4979 }
4980 }
4981 }
4982 p_scb = (btif_hl_soc_cb_t *)GKI_getnext((void *)p_scb );
4983 }
4984 }
4985 else
4986 {
4987 BTIF_TRACE_DEBUG0("btif_hl_select_monitor_queue is empty");
4988 }
4989 BTIF_TRACE_DEBUG1("leaving %s",__FUNCTION__);
4990}
4991/*******************************************************************************
4992**
4993** Function btif_hl_select_wakeup_init
4994**
4995** Description select loop wakup init
4996**
4997** Returns int
4998**
4999*******************************************************************************/
5000static inline int btif_hl_select_wakeup_init(fd_set* set){
5001 BTIF_TRACE_DEBUG0("btif_hl_select_wakeup_init");
5002 if (socketpair(AF_UNIX, SOCK_STREAM, 0, signal_fds) < 0)
5003 {
5004 BTIF_TRACE_ERROR1("socketpair failed: %s", strerror(errno));
5005 return -1;
5006 }
5007
5008 BTIF_TRACE_DEBUG2("btif_hl_select_wakeup_init signal_fds[0]=%d signal_fds[1]=%d",signal_fds[0], signal_fds[1] );
5009 FD_SET(signal_fds[0], set);
5010
5011 return signal_fds[0];
5012}
5013
5014/*******************************************************************************
5015**
5016** Function btif_hl_select_wakeup
5017**
5018** Description send a signal to wakupo the select loop
5019**
5020** Returns int
5021**
5022*******************************************************************************/
5023static inline int btif_hl_select_wakeup(void){
5024 char sig_on = btif_hl_signal_select_wakeup;
5025 BTIF_TRACE_DEBUG0("btif_hl_select_wakeup");
5026 return send(signal_fds[1], &sig_on, sizeof(sig_on), 0);
5027}
5028
5029/*******************************************************************************
5030**
5031** Function btif_hl_select_close_connected
5032**
5033** Description send a signal to close a socket
5034**
5035** Returns int
5036**
5037*******************************************************************************/
5038static inline int btif_hl_select_close_connected(void){
5039 char sig_on = btif_hl_signal_select_close_connected;
5040 BTIF_TRACE_DEBUG0("btif_hl_select_close_connected");
5041 return send(signal_fds[1], &sig_on, sizeof(sig_on), 0);
5042}
5043
5044/*******************************************************************************
5045**
5046** Function btif_hl_close_select_thread
5047**
5048** Description send signal to close the thread and then close all signal FDs
5049**
5050** Returns int
5051**
5052*******************************************************************************/
5053static inline int btif_hl_close_select_thread(void)
5054{
5055 int result = 0;
5056 char sig_on = btif_hl_signal_select_exit;
5057 BTIF_TRACE_DEBUG0("btif_hl_signal_select_exit");
5058 result = send(signal_fds[1], &sig_on, sizeof(sig_on), 0);
Ganesh Ganapathi Battaf7083df2014-04-28 16:25:52 -07005059 if (btif_is_enabled())
5060 {
5061 /* Wait for the select_thread_id to exit if BT is still enabled
5062 and only this profile getting cleaned up*/
5063 if (select_thread_id != -1) {
5064 pthread_join(select_thread_id, NULL);
5065 select_thread_id = -1;
5066 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08005067 }
5068 /* Cleanup signal sockets */
5069 if(signal_fds[0] != -1)
5070 {
5071 close(signal_fds[0]);
5072 signal_fds[0] = -1;
5073 }
5074 if(signal_fds[1] != -1)
5075 {
5076 close(signal_fds[1]);
5077 signal_fds[1] = -1;
5078 }
5079 return result;
5080}
5081
5082/*******************************************************************************
5083**
5084** Function btif_hl_select_wake_reset
5085**
5086** Description clear the received signal for the select loop
5087**
5088** Returns int
5089**
5090*******************************************************************************/
5091static inline int btif_hl_select_wake_reset(void){
5092 char sig_recv = 0;
5093
5094 BTIF_TRACE_DEBUG0("btif_hl_select_wake_reset");
5095 recv(signal_fds[0], &sig_recv, sizeof(sig_recv), MSG_WAITALL);
5096 return(int)sig_recv;
5097}
5098/*******************************************************************************
5099**
5100** Function btif_hl_select_wake_signaled
5101**
5102** Description check whether a fd is set or not
5103**
5104** Returns int
5105**
5106*******************************************************************************/
5107static inline int btif_hl_select_wake_signaled(fd_set* set){
5108 BTIF_TRACE_DEBUG0("btif_hl_select_wake_signaled");
5109 return FD_ISSET(signal_fds[0], set);
5110}
5111/*******************************************************************************
5112**
5113** Function btif_hl_thread_cleanup
5114**
5115** Description shut down and clean up the select loop
5116**
5117** Returns void
5118**
5119*******************************************************************************/
5120static void btif_hl_thread_cleanup(){
5121 if (listen_s != -1)
5122 close(listen_s);
5123 if (connected_s != -1)
5124 {
5125 shutdown(connected_s, SHUT_RDWR);
5126 close(connected_s);
5127 }
5128 listen_s = connected_s = -1;
5129 BTIF_TRACE_DEBUG0("hl thread cleanup");
5130}
5131/*******************************************************************************
5132**
5133** Function btif_hl_select_thread
5134**
5135** Description the select loop
5136**
5137** Returns void
5138**
5139*******************************************************************************/
5140static void *btif_hl_select_thread(void *arg){
5141 fd_set org_set, curr_set;
5142 int r, max_curr_s, max_org_s;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08005143 UNUSED(arg);
The Android Open Source Project5738f832012-12-12 16:00:35 -08005144
5145 BTIF_TRACE_DEBUG0("entered btif_hl_select_thread");
5146 FD_ZERO(&org_set);
5147 max_org_s = btif_hl_select_wakeup_init(&org_set);
5148 BTIF_TRACE_DEBUG1("max_s=%d ", max_org_s);
5149
5150 for (;;)
5151 {
5152 r = 0;
5153 BTIF_TRACE_DEBUG0("set curr_set = org_set ");
5154 curr_set = org_set;
5155 max_curr_s = max_org_s;
5156 int ret = select((max_curr_s + 1), &curr_set, NULL, NULL, NULL);
5157 BTIF_TRACE_DEBUG1("select unblocked ret=%d", ret);
5158 if (ret == -1)
5159 {
5160 BTIF_TRACE_DEBUG0("select() ret -1, exit the thread");
5161 btif_hl_thread_cleanup();
5162 select_thread_id = -1;
5163 return 0;
5164 }
5165 else if (ret)
5166 {
5167 BTIF_TRACE_DEBUG1("btif_hl_select_wake_signaled, signal ret=%d", ret);
5168 if (btif_hl_select_wake_signaled(&curr_set))
5169 {
5170 r = btif_hl_select_wake_reset();
5171 BTIF_TRACE_DEBUG1("btif_hl_select_wake_signaled, signal:%d", r);
5172 if (r == btif_hl_signal_select_wakeup || r == btif_hl_signal_select_close_connected )
5173 {
5174 btif_hl_select_wakeup_callback(&org_set, r);
5175 }
5176 else if( r == btif_hl_signal_select_exit)
5177 {
5178 btif_hl_thread_cleanup();
5179 BTIF_TRACE_DEBUG0("Exit hl_select_thread for btif_hl_signal_select_exit");
5180 return 0;
5181 }
5182 }
5183
5184 btif_hl_select_monitor_callback(&curr_set, &org_set);
5185 max_org_s = btif_hl_update_maxfd(max_org_s);
5186 }
5187 else
5188 BTIF_TRACE_DEBUG1("no data, select ret: %d\n", ret);
5189 }
5190 BTIF_TRACE_DEBUG0("leaving hl_select_thread");
5191 return 0;
5192}
5193
5194/*******************************************************************************
5195**
5196** Function create_thread
5197**
5198** Description creat a select loop
5199**
5200** Returns pthread_t
5201**
5202*******************************************************************************/
5203static inline pthread_t create_thread(void *(*start_routine)(void *), void * arg){
5204 BTIF_TRACE_DEBUG0("create_thread: entered");
5205 pthread_attr_t thread_attr;
5206
5207 pthread_attr_init(&thread_attr);
5208 pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
5209 pthread_t thread_id = -1;
5210 if ( pthread_create(&thread_id, &thread_attr, start_routine, arg)!=0 )
5211 {
5212 BTIF_TRACE_ERROR1("pthread_create : %s", strerror(errno));
5213 return -1;
5214 }
5215 BTIF_TRACE_DEBUG0("create_thread: thread created successfully");
5216 return thread_id;
5217}
5218
5219/*******************************************************************************
5220**
5221** Function btif_hl_soc_thread_init
5222**
5223** Description HL select loop init function.
5224**
5225** Returns void
5226**
5227*******************************************************************************/
5228void btif_hl_soc_thread_init(void){
5229 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
5230 GKI_init_q(&soc_queue);
5231 select_thread_id = create_thread(btif_hl_select_thread, NULL);
5232}
5233/*******************************************************************************
5234**
5235** Function btif_hl_load_mdl_config
5236**
5237** Description load the MDL configuation from the application control block
5238**
5239** Returns BOOLEAN
5240**
5241*******************************************************************************/
5242BOOLEAN btif_hl_load_mdl_config (UINT8 app_id, UINT8 buffer_size,
5243 tBTA_HL_MDL_CFG *p_mdl_buf ){
5244 UINT8 app_idx;
5245 BOOLEAN result = FALSE;
5246 btif_hl_app_cb_t *p_acb;
5247 tBTA_HL_MDL_CFG *p;
5248 int i;
5249 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
5250
5251 if (btif_hl_find_app_idx(app_id, &app_idx))
5252 {
5253 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
5254 for (i=0, p=p_mdl_buf; i<buffer_size; i++, p++)
5255 {
5256 memcpy(p, &p_acb->mdl_cfg[i].base, sizeof(tBTA_HL_MDL_CFG));
5257 }
5258 result = TRUE;
5259 }
5260
5261 BTIF_TRACE_DEBUG1("result=%d", result);
5262 return result;
5263}