blob: 3939e161c3d7d17585ac9a1ce6ac0b93c504fc55 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 2003-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19/******************************************************************************
20 *
21 * This file implements utility functions for the HeaLth device profile
22 * (HL).
23 *
24 ******************************************************************************/
25
26#include <stdio.h>
27#include <string.h>
28
29#include "bt_target.h"
Marie Janssene9e58ce2016-06-17 14:12:17 -070030#if (HL_INCLUDED == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -080031
32
Pavlin Radoslavov258c2532015-09-27 20:59:05 -070033#include "bt_common.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080034#include "utl.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080035#include "bta_hl_int.h"
36#include "bta_hl_co.h"
37#include "mca_defs.h"
38#include "mca_api.h"
39
40
41/*******************************************************************************
42**
43** Function bta_hl_set_ctrl_psm_for_dch
44**
45** Description This function set the control PSM for the DCH setup
46**
Marie Janssene9e58ce2016-06-17 14:12:17 -070047** Returns bool - true - control PSM setting is successful
The Android Open Source Project5738f832012-12-12 16:00:35 -080048*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -070049bool bta_hl_set_ctrl_psm_for_dch(uint8_t app_idx, uint8_t mcl_idx,
50 uint8_t mdl_idx, uint16_t ctrl_psm)
The Android Open Source Project5738f832012-12-12 16:00:35 -080051{
52 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -070053 bool success = true, update_ctrl_psm = false;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -080054 UNUSED(mdl_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -080055
56 if (p_mcb->sdp.num_recs)
57 {
58 if (p_mcb->ctrl_psm != ctrl_psm)
59 {
60 /* can not use a different ctrl PSM than the current one*/
Marie Janssene9e58ce2016-06-17 14:12:17 -070061 success = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -080062 }
63 }
64 else
65 {
66 /* No SDP info control i.e. channel was opened by the peer */
Marie Janssene9e58ce2016-06-17 14:12:17 -070067 update_ctrl_psm = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -080068 }
69
70 if (success && update_ctrl_psm)
71 {
72 p_mcb->ctrl_psm = ctrl_psm;
73 }
74
75
Marie Janssene9e58ce2016-06-17 14:12:17 -070076#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -080077 if (!success)
78 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -070079 APPL_TRACE_DEBUG("bta_hl_set_ctrl_psm_for_dch num_recs=%d success=%d update_ctrl_psm=%d ctrl_psm=0x%x ",
The Android Open Source Project5738f832012-12-12 16:00:35 -080080 p_mcb->sdp.num_recs, success, update_ctrl_psm, ctrl_psm );
81 }
82#endif
83
84 return success;
85}
86
87
88/*******************************************************************************
89**
90** Function bta_hl_find_sdp_idx_using_ctrl_psm
91**
92** Description
93**
Marie Janssene9e58ce2016-06-17 14:12:17 -070094** Returns true if found
The Android Open Source Project5738f832012-12-12 16:00:35 -080095**
96*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -070097bool bta_hl_find_sdp_idx_using_ctrl_psm(tBTA_HL_SDP *p_sdp,
98 uint16_t ctrl_psm,
99 uint8_t *p_sdp_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800100{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700101 bool found=false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800102 tBTA_HL_SDP_REC *p_rec;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700103 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800104
105 if (ctrl_psm != 0)
106 {
107 for (i=0; i<p_sdp->num_recs; i++)
108 {
109 p_rec = &p_sdp->sdp_rec[i];
110 if (p_rec->ctrl_psm == ctrl_psm)
111 {
112 *p_sdp_idx = i;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700113 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800114 break;
115 }
116 }
117 }
118 else
119 {
120 *p_sdp_idx = 0;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700121 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800122 }
123
Marie Janssene9e58ce2016-06-17 14:12:17 -0700124#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800125 if (!found)
126 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700127 APPL_TRACE_DEBUG("bta_hl_find_sdp_idx_using_ctrl_psm found=%d sdp_idx=%d ctrl_psm=0x%x ",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800128 found, *p_sdp_idx, ctrl_psm );
129 }
130#endif
131 return found;
132}
133
134/*******************************************************************************
135**
Pavlin Radoslavov1d5b8592015-09-23 10:08:20 -0700136** Function bta_hl_set_user_tx_buf_size
The Android Open Source Project5738f832012-12-12 16:00:35 -0800137**
Pavlin Radoslavov1d5b8592015-09-23 10:08:20 -0700138** Description This function sets the user tx buffer size
The Android Open Source Project5738f832012-12-12 16:00:35 -0800139**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700140** Returns uint16_t buf_size
The Android Open Source Project5738f832012-12-12 16:00:35 -0800141**
142*******************************************************************************/
143
Marie Janssene9e58ce2016-06-17 14:12:17 -0700144uint16_t bta_hl_set_user_tx_buf_size(uint16_t max_tx_size)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800145{
Pavlin Radoslavov70ae7de2015-09-23 14:49:24 -0700146 if (max_tx_size > BT_DEFAULT_BUFFER_SIZE)
Pavlin Radoslavov1d5b8592015-09-23 10:08:20 -0700147 return BTA_HL_LRG_DATA_BUF_SIZE;
148 return L2CAP_INVALID_ERM_BUF_SIZE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800149}
150
151/*******************************************************************************
152**
Pavlin Radoslavov1d5b8592015-09-23 10:08:20 -0700153** Function bta_hl_set_user_rx_buf_size
The Android Open Source Project5738f832012-12-12 16:00:35 -0800154**
Pavlin Radoslavov1d5b8592015-09-23 10:08:20 -0700155** Description This function sets the user rx buffer size
The Android Open Source Project5738f832012-12-12 16:00:35 -0800156**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700157** Returns uint16_t buf_size
The Android Open Source Project5738f832012-12-12 16:00:35 -0800158**
159*******************************************************************************/
160
Marie Janssene9e58ce2016-06-17 14:12:17 -0700161uint16_t bta_hl_set_user_rx_buf_size(uint16_t mtu)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800162{
Pavlin Radoslavov70ae7de2015-09-23 14:49:24 -0700163 if (mtu > BT_DEFAULT_BUFFER_SIZE)
Pavlin Radoslavov1d5b8592015-09-23 10:08:20 -0700164 return BTA_HL_LRG_DATA_BUF_SIZE;
165 return L2CAP_INVALID_ERM_BUF_SIZE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800166}
167
168
169
170/*******************************************************************************
171**
172** Function bta_hl_set_tx_win_size
173**
174** Description This function sets the tx window size
175**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700176** Returns uint8_t tx_win_size
The Android Open Source Project5738f832012-12-12 16:00:35 -0800177**
178*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700179uint8_t bta_hl_set_tx_win_size(uint16_t mtu, uint16_t mps)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800180{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700181 uint8_t tx_win_size;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800182
183 if (mtu <= mps)
184 {
185 tx_win_size =1;
186 }
187 else
188 {
189 if (mps > 0)
190 {
191 tx_win_size = (mtu/mps)+1;
192 }
193 else
194 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700195 APPL_TRACE_ERROR("The MPS is zero");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800196 tx_win_size = 10;
197 }
198 }
199
Marie Janssene9e58ce2016-06-17 14:12:17 -0700200#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700201 APPL_TRACE_DEBUG("bta_hl_set_tx_win_size win_size=%d mtu=%d mps=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800202 tx_win_size, mtu, mps);
203#endif
204 return tx_win_size;
205}
206
207/*******************************************************************************
208**
209** Function bta_hl_set_mps
210**
211** Description This function sets the MPS
212**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700213** Returns uint16_t MPS
The Android Open Source Project5738f832012-12-12 16:00:35 -0800214**
215*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700216uint16_t bta_hl_set_mps(uint16_t mtu)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800217{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700218 uint16_t mps;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800219 if (mtu > BTA_HL_L2C_MPS)
220 {
221 mps = BTA_HL_L2C_MPS;
222 }
223 else
224 {
225 mps = mtu;
226 }
Marie Janssene9e58ce2016-06-17 14:12:17 -0700227#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700228 APPL_TRACE_DEBUG("bta_hl_set_mps mps=%d mtu=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800229 mps, mtu);
230#endif
231 return mps;
232}
233
234
235/*******************************************************************************
236**
237** Function bta_hl_clean_mdl_cb
238**
239** Description This function clean up the specified MDL control block
240**
241** Returns void
242**
243*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700244void bta_hl_clean_mdl_cb(uint8_t app_idx, uint8_t mcl_idx, uint8_t mdl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800245{
246 tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -0700247#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700248 APPL_TRACE_DEBUG("bta_hl_clean_mdl_cb app_idx=%d mcl_idx=%d mdl_idx=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800249 app_idx, mcl_idx, mdl_idx);
250#endif
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -0800251 osi_free_and_reset((void **)&p_dcb->p_tx_pkt);
252 osi_free_and_reset((void **)&p_dcb->p_rx_pkt);
253 osi_free_and_reset((void **)&p_dcb->p_echo_tx_pkt);
254 osi_free_and_reset((void **)&p_dcb->p_echo_rx_pkt);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800255
256 memset((void *)p_dcb, 0 , sizeof(tBTA_HL_MDL_CB));
257}
258
259
260/*******************************************************************************
261**
262** Function bta_hl_get_buf
263**
264** Description This function allocate a buffer based on the specified data size
265**
266** Returns BT_HDR *.
267**
268*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700269BT_HDR * bta_hl_get_buf(uint16_t data_size, bool fcs_use)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800270{
Srinu Jellaf6a64de2016-03-15 16:36:19 +0530271 size_t size = data_size + L2CAP_MIN_OFFSET + BT_HDR_SIZE + L2CAP_FCS_LEN
272 + L2CAP_EXT_CONTROL_OVERHEAD;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800273
Jacob Lee4d7575b2015-09-11 14:06:48 +0800274 if (fcs_use)
Jacob Lee4d7575b2015-09-11 14:06:48 +0800275 size += L2CAP_FCS_LEN;
Jacob Lee4d7575b2015-09-11 14:06:48 +0800276
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800277 BT_HDR *p_new = (BT_HDR *)osi_malloc(size);
278 p_new->len = data_size;
279 p_new->offset = L2CAP_MIN_OFFSET;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800280
281 return p_new;
282}
283
284/*******************************************************************************
285**
286** Function bta_hl_find_service_in_db
287**
288** Description This function check the specified service class(es) can be find in
289** the received SDP database
290**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700291** Returns bool true - found
292** false - not found
The Android Open Source Project5738f832012-12-12 16:00:35 -0800293**
294*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700295bool bta_hl_find_service_in_db( uint8_t app_idx, uint8_t mcl_idx,
296 uint16_t service_uuid,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800297 tSDP_DISC_REC **pp_rec )
298{
299 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -0700300 bool found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800301
302 switch (service_uuid)
303 {
304 case UUID_SERVCLASS_HDP_SINK:
305 case UUID_SERVCLASS_HDP_SOURCE:
306 if ((*pp_rec = SDP_FindServiceInDb(p_mcb->p_db, service_uuid,
307 *pp_rec)) == NULL)
308 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700309 found = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800310 }
311 break;
312 default:
313 if (((*pp_rec = bta_hl_find_sink_or_src_srv_class_in_db(p_mcb->p_db,
314 *pp_rec)) == NULL))
315 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700316 found = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800317 }
318 break;
319 }
320 return found;
321}
322
323/*******************************************************************************
324**
325** Function bta_hl_get_service_uuids
326**
327**
328** Description This function finds the service class(es) for both CCH and DCH oeprations
329**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700330** Returns uint16_t - service_id
The Android Open Source Project5738f832012-12-12 16:00:35 -0800331** if service_uuid = 0xFFFF then it means service uuid
332** can be either Sink or Source
333**
334*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700335uint16_t bta_hl_get_service_uuids(uint8_t sdp_oper, uint8_t app_idx, uint8_t mcl_idx,
336 uint8_t mdl_idx )
The Android Open Source Project5738f832012-12-12 16:00:35 -0800337{
338 tBTA_HL_MDL_CB *p_dcb;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700339 uint16_t service_uuid = 0xFFFF; /* both Sink and Source */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800340
341 switch (sdp_oper)
342 {
343
344 case BTA_HL_SDP_OP_DCH_OPEN_INIT:
345 case BTA_HL_SDP_OP_DCH_RECONNECT_INIT:
346 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
347 if (p_dcb->local_mdep_id != BTA_HL_ECHO_TEST_MDEP_ID)
348 {
349 if (p_dcb->peer_mdep_role == BTA_HL_MDEP_ROLE_SINK)
350 {
351 service_uuid = UUID_SERVCLASS_HDP_SINK;
352 }
353 else
354 {
355 service_uuid = UUID_SERVCLASS_HDP_SOURCE;
356 }
357 }
358 break;
359 case BTA_HL_SDP_OP_CCH_INIT:
360 default:
361 /* use default that is both Sink and Source */
362 break;
363 }
Marie Janssene9e58ce2016-06-17 14:12:17 -0700364#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700365 APPL_TRACE_DEBUG("bta_hl_get_service_uuids service_uuid=0x%x",service_uuid );
The Android Open Source Project5738f832012-12-12 16:00:35 -0800366#endif
367 return service_uuid;
368}
369
370/*******************************************************************************
371**
372** Function bta_hl_find_echo_cfg_rsp
373**
374**
375** Description This function finds the configuration response for the echo test
376**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700377** Returns bool - true found
378** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -0800379**
380*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700381bool bta_hl_find_echo_cfg_rsp(uint8_t app_idx, uint8_t mcl_idx, uint8_t mdep_idx, uint8_t cfg,
382 uint8_t *p_cfg_rsp)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800383{
384 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
385 tBTA_HL_MDEP *p_mdep= &p_acb->sup_feature.mdep[mdep_idx];
Marie Janssene9e58ce2016-06-17 14:12:17 -0700386 bool status =true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800387
388 if (p_mdep->mdep_id == BTA_HL_ECHO_TEST_MDEP_ID)
389 {
390 if ((cfg == BTA_HL_DCH_CFG_RELIABLE) || (cfg == BTA_HL_DCH_CFG_STREAMING))
391 {
392 *p_cfg_rsp = cfg;
393 }
394 else if (cfg == BTA_HL_DCH_CFG_NO_PREF )
395 {
396 *p_cfg_rsp = BTA_HL_DEFAULT_ECHO_TEST_SRC_DCH_CFG;
397 }
398 else
399 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700400 status = false;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700401 APPL_TRACE_ERROR("Inavlid echo cfg value");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800402 }
403 return status;
404 }
405
Marie Janssene9e58ce2016-06-17 14:12:17 -0700406#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800407 if (!status)
408 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700409 APPL_TRACE_DEBUG("bta_hl_find_echo_cfg_rsp status=failed app_idx=%d mcl_idx=%d mdep_idx=%d cfg=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800410 app_idx, mcl_idx, mdep_idx, cfg);
411 }
412#endif
413
414 return status;
415}
416
417/*******************************************************************************
418**
419** Function bta_hl_validate_dch_cfg
420**
421** Description This function validate the DCH configuration
422**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700423** Returns bool - true cfg is valid
424** false not valid
The Android Open Source Project5738f832012-12-12 16:00:35 -0800425**
426*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700427bool bta_hl_validate_cfg(uint8_t app_idx, uint8_t mcl_idx, uint8_t mdl_idx,
428 uint8_t cfg)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800429{
430 tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -0700431 bool is_valid =false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800432
433
434 if (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx) &&
435 (cfg != BTA_HL_DCH_CFG_RELIABLE))
436 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700437 APPL_TRACE_ERROR("the first DCH should be a reliable channel");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800438 return is_valid;
439 }
440
441 switch (p_dcb->local_cfg)
442 {
443 case BTA_HL_DCH_CFG_NO_PREF:
444
445 if ((cfg == BTA_HL_DCH_CFG_RELIABLE) || (cfg == BTA_HL_DCH_CFG_STREAMING))
446 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700447 is_valid = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800448 }
449 break;
450 case BTA_HL_DCH_CFG_RELIABLE:
451 case BTA_HL_DCH_CFG_STREAMING:
452 if (p_dcb->local_cfg == cfg )
453 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700454 is_valid = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800455 }
456 break;
457 default:
458 break;
459 }
460
Marie Janssene9e58ce2016-06-17 14:12:17 -0700461#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800462 if (!is_valid)
463 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700464 APPL_TRACE_DEBUG("bta_hl_validate_dch_open_cfg is_valid=%d, cfg=%d", is_valid, cfg );
The Android Open Source Project5738f832012-12-12 16:00:35 -0800465 }
466#endif
467 return is_valid;
468}
469
470/*******************************************************************************
471**
472** Function bta_hl_find_cch_cb_indexes
473**
474** Description This function finds the indexes needed for the CCH state machine
475**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700476** Returns bool - true found
477** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -0800478**
479*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700480bool bta_hl_find_cch_cb_indexes(tBTA_HL_DATA *p_msg,
481 uint8_t *p_app_idx,
482 uint8_t *p_mcl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800483{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700484 bool found = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800485 tBTA_HL_MCL_CB *p_mcb;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700486 uint8_t app_idx = 0, mcl_idx = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800487
488 switch (p_msg->hdr.event)
489 {
490 case BTA_HL_CCH_SDP_OK_EVT:
491 case BTA_HL_CCH_SDP_FAIL_EVT:
492 app_idx = p_msg->cch_sdp.app_idx;
493 mcl_idx = p_msg->cch_sdp.mcl_idx;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700494 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800495 break;
496
497 case BTA_HL_MCA_CONNECT_IND_EVT:
498
499 if (bta_hl_find_app_idx_using_handle(p_msg->mca_evt.app_handle, &app_idx))
500 {
501 if (bta_hl_find_mcl_idx(app_idx, p_msg->mca_evt.mca_data.connect_ind.bd_addr, &mcl_idx))
502 {
503 /* local initiated */
Marie Janssene9e58ce2016-06-17 14:12:17 -0700504 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800505 }
506 else if (!bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx)&&
507 bta_hl_find_avail_mcl_idx(app_idx, &mcl_idx))
508 {
509 /* remote initiated */
510 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -0700511 p_mcb->in_use = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800512 p_mcb->cch_oper = BTA_HL_CCH_OP_REMOTE_OPEN;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700513 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800514 }
515 }
516 break;
517
518 case BTA_HL_MCA_DISCONNECT_IND_EVT:
519
520 if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx))
521 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700522 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800523 }
524 else if (bta_hl_find_app_idx_using_handle(p_msg->mca_evt.app_handle, &app_idx) &&
525 bta_hl_find_mcl_idx(app_idx, p_msg->mca_evt.mca_data.disconnect_ind.bd_addr, &mcl_idx))
526 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700527 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800528 }
529
530 if (found)
531 {
532 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800533 if ((p_mcb->cch_oper != BTA_HL_CCH_OP_LOCAL_CLOSE) && (p_mcb->cch_oper != BTA_HL_CCH_OP_LOCAL_OPEN) )
The Android Open Source Project5738f832012-12-12 16:00:35 -0800534 {
535 p_mcb->cch_oper = BTA_HL_CCH_OP_REMOTE_CLOSE;
536 }
537 }
538 break;
539
540 case BTA_HL_MCA_RSP_TOUT_IND_EVT:
541
542 if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx))
543 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700544 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800545 }
546
547 if (found)
548 {
549 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800550 if ((p_mcb->cch_oper != BTA_HL_CCH_OP_REMOTE_CLOSE) && (p_mcb->cch_oper != BTA_HL_CCH_OP_LOCAL_OPEN))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800551 {
552 p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_CLOSE;
553 }
554 }
555 break;
556 default:
557 break;
558 }
559
560
561 if (found)
562 {
563 *p_app_idx = app_idx;
564 *p_mcl_idx = mcl_idx;
565 }
566
Marie Janssene9e58ce2016-06-17 14:12:17 -0700567#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800568 if (!found)
569 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700570 APPL_TRACE_DEBUG("bta_hl_find_cch_cb_indexes event=%s found=%d app_idx=%d mcl_idx=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800571 bta_hl_evt_code(p_msg->hdr.event), found, app_idx, mcl_idx);
572 }
573#endif
574
575 return found;
576}
577
578/*******************************************************************************
579**
580** Function bta_hl_find_dch_cb_indexes
581**
582** Description This function finds the indexes needed for the DCH state machine
583**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700584** Returns bool - true found
585** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -0800586**
587*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700588bool bta_hl_find_dch_cb_indexes(tBTA_HL_DATA *p_msg,
589 uint8_t *p_app_idx,
590 uint8_t *p_mcl_idx,
591 uint8_t *p_mdl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800592{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700593 bool found = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800594 tBTA_HL_MCL_CB *p_mcb;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700595 uint8_t app_idx = 0, mcl_idx = 0, mdl_idx = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800596
597 switch (p_msg->hdr.event)
598 {
599 case BTA_HL_MCA_CREATE_CFM_EVT:
600 if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) &&
601 bta_hl_find_mdl_idx( app_idx, mcl_idx, p_msg->mca_evt.mca_data.create_cfm.mdl_id, &mdl_idx))
602 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700603 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800604 }
605 break;
606
607 case BTA_HL_MCA_CREATE_IND_EVT:
608 case BTA_HL_MCA_RECONNECT_IND_EVT:
609 if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) &&
610 bta_hl_find_avail_mdl_idx( app_idx, mcl_idx, &mdl_idx))
611 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700612 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800613 }
614 break;
615
616 case BTA_HL_MCA_OPEN_CFM_EVT:
617 if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) &&
618 bta_hl_find_mdl_idx( app_idx, mcl_idx, p_msg->mca_evt.mca_data.open_cfm.mdl_id, &mdl_idx))
619 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700620 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800621 }
622 break;
623
624 case BTA_HL_MCA_OPEN_IND_EVT:
625 if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) &&
626 bta_hl_find_mdl_idx( app_idx, mcl_idx, p_msg->mca_evt.mca_data.open_ind.mdl_id, &mdl_idx))
627 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700628 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800629 }
630 break;
631
632 case BTA_HL_MCA_CLOSE_CFM_EVT:
633
634 if (bta_hl_find_mdl_idx_using_handle((tBTA_HL_MDL_HANDLE)p_msg->mca_evt.mca_data.close_cfm.mdl,
635 &app_idx, &mcl_idx, &mdl_idx))
636 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700637 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800638 }
639 break;
640 case BTA_HL_MCA_CLOSE_IND_EVT:
641
642 if (bta_hl_find_mdl_idx_using_handle((tBTA_HL_MDL_HANDLE)p_msg->mca_evt.mca_data.close_ind.mdl,
643 &app_idx, &mcl_idx, &mdl_idx))
644 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700645 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800646 }
647 break;
648 case BTA_HL_API_SEND_DATA_EVT:
649
650 if (bta_hl_find_mdl_idx_using_handle(p_msg->api_send_data.mdl_handle,
651 &app_idx, &mcl_idx, &mdl_idx ))
652 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700653 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800654 }
655
656 break;
657
658 case BTA_HL_MCA_CONG_CHG_EVT:
659
660 if (bta_hl_find_mdl_idx_using_handle((tBTA_HL_MDL_HANDLE)p_msg->mca_evt.mca_data.cong_chg.mdl,
661 &app_idx, &mcl_idx, &mdl_idx ))
662 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700663 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800664 }
665
666 break;
667
668 case BTA_HL_MCA_RCV_DATA_EVT:
669 app_idx = p_msg->mca_rcv_data_evt.app_idx;
670 mcl_idx = p_msg->mca_rcv_data_evt.mcl_idx;
671 mdl_idx = p_msg->mca_rcv_data_evt.mdl_idx;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700672 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800673 break;
674 case BTA_HL_DCH_RECONNECT_EVT:
675 case BTA_HL_DCH_OPEN_EVT:
676 case BTA_HL_DCH_ECHO_TEST_EVT:
677 case BTA_HL_DCH_SDP_FAIL_EVT:
678 app_idx = p_msg->dch_sdp.app_idx;
679 mcl_idx = p_msg->dch_sdp.mcl_idx;
680 mdl_idx = p_msg->dch_sdp.mdl_idx;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700681 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800682 break;
683 case BTA_HL_MCA_RECONNECT_CFM_EVT:
684 if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) &&
685 bta_hl_find_mdl_idx( app_idx, mcl_idx, p_msg->mca_evt.mca_data.reconnect_cfm.mdl_id, &mdl_idx))
686 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700687 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800688 }
689 break;
690
691
692 case BTA_HL_API_DCH_CREATE_RSP_EVT:
693 if (bta_hl_find_mcl_idx_using_handle(p_msg->api_dch_create_rsp.mcl_handle, &app_idx, &mcl_idx)&&
694 bta_hl_find_mdl_idx( app_idx, mcl_idx,p_msg->api_dch_create_rsp.mdl_id, &mdl_idx))
695 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700696 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800697 }
698 break;
699 case BTA_HL_MCA_ABORT_IND_EVT:
700 if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) &&
701 bta_hl_find_mdl_idx( app_idx, mcl_idx,p_msg->mca_evt.mca_data.abort_ind.mdl_id, &mdl_idx))
702 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700703 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800704 }
705 break;
706 case BTA_HL_MCA_ABORT_CFM_EVT:
707 if (bta_hl_find_mcl_idx_using_handle(p_msg->mca_evt.mcl_handle, &app_idx, &mcl_idx) &&
708 bta_hl_find_mdl_idx( app_idx, mcl_idx, p_msg->mca_evt.mca_data.abort_cfm.mdl_id, &mdl_idx))
709 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700710 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800711 }
712 break;
713 case BTA_HL_CI_GET_TX_DATA_EVT:
714 case BTA_HL_CI_PUT_RX_DATA_EVT:
715 if (bta_hl_find_mdl_idx_using_handle(p_msg->ci_get_put_data.mdl_handle, &app_idx, &mcl_idx, &mdl_idx))
716 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700717 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800718 }
719 break;
720 case BTA_HL_CI_GET_ECHO_DATA_EVT:
721 case BTA_HL_CI_PUT_ECHO_DATA_EVT:
722 if (bta_hl_find_mcl_idx_using_handle(p_msg->ci_get_put_echo_data.mcl_handle, &app_idx, &mcl_idx))
723 {
724 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
725 mdl_idx = p_mcb->echo_mdl_idx;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700726 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800727 }
728 break;
729
730 default:
731 break;
732
733 }
734
735 if (found)
736 {
737 *p_app_idx = app_idx;
738 *p_mcl_idx = mcl_idx;
739 *p_mdl_idx = mdl_idx;
740 }
Marie Janssene9e58ce2016-06-17 14:12:17 -0700741#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800742 if (!found)
743 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700744 APPL_TRACE_DEBUG("bta_hl_find_dch_cb_indexes event=%s found=%d app_idx=%d mcl_idx=%d mdl_idx=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800745 bta_hl_evt_code(p_msg->hdr.event), found, *p_app_idx, *p_mcl_idx, *p_mdl_idx );
746 }
747#endif
748
749 return found;
750}
751
752/*******************************************************************************
753**
754** Function bta_hl_allocate_mdl_id
755**
756** Description This function allocates a MDL ID
757**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700758** Returns uint16_t - MDL ID
The Android Open Source Project5738f832012-12-12 16:00:35 -0800759**
760*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700761uint16_t bta_hl_allocate_mdl_id(uint8_t app_idx, uint8_t mcl_idx, uint8_t mdl_idx )
The Android Open Source Project5738f832012-12-12 16:00:35 -0800762{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700763 uint16_t mdl_id=0;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800764 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -0700765 bool duplicate_id;
766 uint8_t i, mdl_cfg_idx;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800767
768 do
769 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700770 duplicate_id = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800771 mdl_id = ((mdl_id+1) & 0xFEFF);
772 /* check mdl_ids that are used for the current conenctions */
773 for (i=0; i< BTA_HL_NUM_MDLS_PER_MCL; i++)
774 {
775 if (p_mcb->mdl[i].in_use &&
776 (i != mdl_idx) &&
777 (p_mcb->mdl[i].mdl_id == mdl_id) )
778 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700779 duplicate_id = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800780 break;
781 }
782 }
783
784 if (duplicate_id)
785 {
786 /* start from the beginning to get another MDL value*/
787 continue;
788 }
789 else
790 {
791 /* check mdl_ids that are stored in the persistent memory */
792 if (bta_hl_find_mdl_cfg_idx(app_idx,mcl_idx, mdl_id, &mdl_cfg_idx))
793 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700794 duplicate_id = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800795 }
796 else
797 {
798 /* found a new MDL value */
799 break;
800 }
801 }
802
Marie Janssene9e58ce2016-06-17 14:12:17 -0700803 }while (true);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800804
Marie Janssene9e58ce2016-06-17 14:12:17 -0700805#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700806 APPL_TRACE_DEBUG("bta_hl_allocate_mdl OK mdl_id=%d", mdl_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800807#endif
808 return mdl_id;
809}
810/*******************************************************************************
811**
812** Function bta_hl_find_mdl_idx
813**
814** Description This function finds the MDL index based on mdl_id
815**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700816** Returns bool true-found
The Android Open Source Project5738f832012-12-12 16:00:35 -0800817**
818*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700819bool bta_hl_find_mdl_idx(uint8_t app_idx, uint8_t mcl_idx, uint16_t mdl_id,
820 uint8_t *p_mdl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800821{
822 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -0700823 bool found=false;
824 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800825
826 for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++)
827 {
828 if (p_mcb->mdl[i].in_use &&
829 (mdl_id !=0) &&
830 (p_mcb->mdl[i].mdl_id== mdl_id))
831 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700832 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800833 *p_mdl_idx = i;
834 break;
835 }
836 }
837
Marie Janssene9e58ce2016-06-17 14:12:17 -0700838#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800839 if (!found)
840 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700841 APPL_TRACE_DEBUG("bta_hl_find_mdl_idx found=%d mdl_id=%d mdl_idx=%d ",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800842 found, mdl_id, i);
843 }
844#endif
845
846 return found;
847}
848
849/*******************************************************************************
850**
851** Function bta_hl_find_an_active_mdl_idx
852**
853** Description This function finds an active MDL
854**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700855** Returns bool true-found
The Android Open Source Project5738f832012-12-12 16:00:35 -0800856**
857*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700858bool bta_hl_find_an_active_mdl_idx(uint8_t app_idx, uint8_t mcl_idx,
859 uint8_t *p_mdl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800860{
861 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -0700862 bool found=false;
863 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800864
865 for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++)
866 {
867 if (p_mcb->mdl[i].in_use &&
868 (p_mcb->mdl[i].dch_state == BTA_HL_DCH_OPEN_ST))
869 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700870 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800871 *p_mdl_idx = i;
872 break;
873 }
874 }
875
Marie Janssene9e58ce2016-06-17 14:12:17 -0700876#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800877 if (found)
878 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700879 APPL_TRACE_DEBUG("bta_hl_find_an_opened_mdl_idx found=%d app_idx=%d mcl_idx=%d mdl_idx=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800880 found, app_idx, mcl_idx, i);
881 }
882#endif
883
884 return found;
885}
886
887/*******************************************************************************
888**
889** Function bta_hl_find_dch_setup_mdl_idx
890**
891** Description This function finds a MDL which in the DCH setup state
892**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700893** Returns bool true-found
The Android Open Source Project5738f832012-12-12 16:00:35 -0800894**
895*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700896bool bta_hl_find_dch_setup_mdl_idx(uint8_t app_idx, uint8_t mcl_idx,
897 uint8_t *p_mdl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800898{
899 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -0700900 bool found=false;
901 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800902
903 for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++)
904 {
905 if (p_mcb->mdl[i].in_use &&
906 (p_mcb->mdl[i].dch_state == BTA_HL_DCH_OPENING_ST))
907 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700908 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800909 *p_mdl_idx = i;
910 break;
911 }
912 }
913
Marie Janssene9e58ce2016-06-17 14:12:17 -0700914#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800915 if (found)
916 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700917 APPL_TRACE_DEBUG("bta_hl_find_dch_setup_mdl_idx found=%d app_idx=%d mcl_idx=%d mdl_idx=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800918 found, app_idx, mcl_idx, i);
919 }
920#endif
921
922 return found;
923}
924
925/*******************************************************************************
926**
927** Function bta_hl_find_an_in_use_mcl_idx
928**
929** Description This function finds an in-use MCL control block index
930**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700931** Returns bool true-found
The Android Open Source Project5738f832012-12-12 16:00:35 -0800932**
933*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700934bool bta_hl_find_an_in_use_mcl_idx(uint8_t app_idx,
935 uint8_t *p_mcl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800936{
937 tBTA_HL_MCL_CB *p_mcb;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700938 bool found=false;
939 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800940
941 for (i=0; i < BTA_HL_NUM_MCLS ; i ++)
942 {
943 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, i);
944 if (p_mcb->in_use &&
945 (p_mcb->cch_state != BTA_HL_CCH_IDLE_ST))
946 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700947 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800948 *p_mcl_idx = i;
949 break;
950 }
951 }
952
Marie Janssene9e58ce2016-06-17 14:12:17 -0700953#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800954 if (found)
955 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700956 APPL_TRACE_DEBUG("bta_hl_find_an_in_use_mcl_idx found=%d app_idx=%d mcl_idx=%d ",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800957 found, app_idx, i);
958 }
959#endif
960
961 return found;
962}
963
964
965/*******************************************************************************
966**
967** Function bta_hl_find_an_in_use_app_idx
968**
969** Description This function finds an in-use application control block index
970**
Marie Janssene9e58ce2016-06-17 14:12:17 -0700971** Returns bool true-found
The Android Open Source Project5738f832012-12-12 16:00:35 -0800972**
973*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -0700974bool bta_hl_find_an_in_use_app_idx(uint8_t *p_app_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800975{
976 tBTA_HL_APP_CB *p_acb ;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700977 bool found=false;
978 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800979
980 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
981 {
982 p_acb = BTA_HL_GET_APP_CB_PTR(i);
983 if (p_acb->in_use)
984 {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700985 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800986 *p_app_idx = i;
987 break;
988 }
989 }
990
Marie Janssene9e58ce2016-06-17 14:12:17 -0700991#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800992 if (found)
993 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700994 APPL_TRACE_DEBUG("bta_hl_find_an_in_use_app_idx found=%d app_idx=%d ",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800995 found, i);
996 }
997#endif
998
999 return found;
1000}
1001/*******************************************************************************
1002**
1003** Function bta_hl_find_app_idx
1004**
1005** Description This function finds the application control block index based on
1006** the application ID
1007**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001008** Returns bool true-found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001009**
1010*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001011bool bta_hl_find_app_idx(uint8_t app_id, uint8_t *p_app_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001012{
Marie Janssene9e58ce2016-06-17 14:12:17 -07001013 bool found=false;
1014 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001015
1016 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
1017 {
1018 if (bta_hl_cb.acb[i].in_use &&
1019 (bta_hl_cb.acb[i].app_id == app_id))
1020 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001021 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001022 *p_app_idx = i;
1023 break;
1024 }
1025 }
1026
Marie Janssene9e58ce2016-06-17 14:12:17 -07001027#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001028 APPL_TRACE_DEBUG("bta_hl_find_app_idx found=%d app_id=%d idx=%d ",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001029 found, app_id, i);
1030#endif
1031
1032 return found;
1033}
1034
1035
1036/*******************************************************************************
1037**
1038** Function bta_hl_find_app_idx_using_handle
1039**
1040** Description This function finds the application control block index based on
1041** the application handle
1042**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001043** Returns bool true-found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001044**
1045*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001046bool bta_hl_find_app_idx_using_handle(tBTA_HL_APP_HANDLE app_handle,
1047 uint8_t *p_app_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001048{
Marie Janssene9e58ce2016-06-17 14:12:17 -07001049 bool found=false;
1050 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001051
1052 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
1053 {
1054 if (bta_hl_cb.acb[i].in_use &&
1055 (bta_hl_cb.acb[i].app_handle == app_handle))
1056 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001057 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001058 *p_app_idx = i;
1059 break;
1060 }
1061 }
1062
Marie Janssene9e58ce2016-06-17 14:12:17 -07001063#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001064 if (!found)
1065 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001066 APPL_TRACE_DEBUG("bta_hl_find_app_idx_using_mca_handle status=%d handle=%d app_idx=%d ",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001067 found, app_handle , i);
1068 }
1069#endif
1070
1071 return found;
1072}
1073
1074
1075/*******************************************************************************
1076**
1077** Function bta_hl_find_mcl_idx_using_handle
1078**
1079** Description This function finds the MCL control block index based on
1080** the MCL handle
1081**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001082** Returns bool true-found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001083**
1084*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001085bool bta_hl_find_mcl_idx_using_handle( tBTA_HL_MCL_HANDLE mcl_handle,
1086 uint8_t *p_app_idx, uint8_t *p_mcl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001087{
1088 tBTA_HL_APP_CB *p_acb;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001089 bool found=false;
1090 uint8_t i = 0,j = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001091
1092 for (i=0; i<BTA_HL_NUM_APPS; i++)
1093 {
1094 p_acb = BTA_HL_GET_APP_CB_PTR(i);
1095 if (p_acb->in_use)
1096 {
1097 for (j=0; j < BTA_HL_NUM_MCLS ; j++)
1098 {
1099 if ( p_acb->mcb[j].mcl_handle == mcl_handle )
1100 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001101 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001102 *p_app_idx = i;
1103 *p_mcl_idx = j;
1104 break;
1105 }
1106 }
1107 }
1108 }
1109
Marie Janssene9e58ce2016-06-17 14:12:17 -07001110#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001111 if (!found)
1112 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001113 APPL_TRACE_DEBUG("bta_hl_find_mcl_idx_using_handle found=%d app_idx=%d mcl_idx=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001114 found, i, j);
1115 }
1116#endif
1117 return found;
1118}
1119
1120/*******************************************************************************
1121**
1122** Function bta_hl_find_mcl_idx
1123**
1124** Description This function finds the MCL control block index based on
1125** the peer BD address
1126**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001127** Returns bool true-found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001128**
1129*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001130bool bta_hl_find_mcl_idx(uint8_t app_idx, BD_ADDR p_bd_addr, uint8_t *p_mcl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001131{
Marie Janssene9e58ce2016-06-17 14:12:17 -07001132 bool found=false;
1133 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001134
1135 for (i=0; i < BTA_HL_NUM_MCLS ; i ++)
1136 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001137 if (bta_hl_cb.acb[app_idx].mcb[i].in_use &&
1138 (!memcmp (bta_hl_cb.acb[app_idx].mcb[i].bd_addr, p_bd_addr, BD_ADDR_LEN)))
1139 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001140 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001141 *p_mcl_idx = i;
1142 break;
1143 }
1144 }
1145
Marie Janssene9e58ce2016-06-17 14:12:17 -07001146#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001147 if (!found)
1148 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001149 APPL_TRACE_DEBUG("bta_hl_find_mcl_idx found=%d idx=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001150 found, i);
1151 }
1152#endif
1153 return found;
1154}
1155
1156
1157
1158/*******************************************************************************
1159**
1160** Function bta_hl_find_mdl_idx_using_handle
1161**
1162** Description This function finds the MDL control block index based on
1163** the MDL handle
1164**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001165** Returns bool true-found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001166**
1167*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001168bool bta_hl_find_mdl_idx_using_handle(tBTA_HL_MDL_HANDLE mdl_handle,
1169 uint8_t *p_app_idx,uint8_t *p_mcl_idx,
1170 uint8_t *p_mdl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001171{
1172 tBTA_HL_APP_CB *p_acb;
1173 tBTA_HL_MCL_CB *p_mcb;
1174 tBTA_HL_MDL_CB *p_dcb;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001175 bool found=false;
1176 uint8_t i,j,k;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001177
1178 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
1179 {
1180 p_acb = BTA_HL_GET_APP_CB_PTR(i);
1181 if (p_acb->in_use)
1182 {
1183 for (j=0; j< BTA_HL_NUM_MCLS; j++)
1184 {
1185 p_mcb = BTA_HL_GET_MCL_CB_PTR(i,j);
1186 if (p_mcb->in_use)
1187 {
1188 for (k=0; k< BTA_HL_NUM_MDLS_PER_MCL; k++)
1189 {
1190 p_dcb = BTA_HL_GET_MDL_CB_PTR(i,j,k);
1191 if (p_dcb->in_use)
1192 {
1193 if (p_dcb->mdl_handle == mdl_handle)
1194 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001195 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001196 *p_app_idx = i;
1197 *p_mcl_idx =j;
1198 *p_mdl_idx = k;
1199 break;
1200 }
1201 }
1202 }
1203 }
1204 }
1205 }
1206 }
1207
1208
Marie Janssene9e58ce2016-06-17 14:12:17 -07001209#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001210 if (!found)
1211 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001212 APPL_TRACE_DEBUG("bta_hl_find_mdl_idx_using_handle found=%d mdl_handle=%d ",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001213 found, mdl_handle);
1214 }
1215#endif
1216 return found;
1217}
1218/*******************************************************************************
1219**
1220** Function bta_hl_is_the_first_reliable_existed
1221**
1222** Description This function checks whether the first reliable DCH channel
1223** has been setup on the MCL or not
1224**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001225** Returns bool - true exist
1226** false does not exist
The Android Open Source Project5738f832012-12-12 16:00:35 -08001227**
1228*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001229bool bta_hl_is_the_first_reliable_existed(uint8_t app_idx, uint8_t mcl_idx )
The Android Open Source Project5738f832012-12-12 16:00:35 -08001230{
1231 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -07001232 bool is_existed =false;
1233 uint8_t i ;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001234
1235 for (i=0; i< BTA_HL_NUM_MDLS_PER_MCL; i++)
1236 {
1237 if (p_mcb->mdl[i].in_use && p_mcb->mdl[i].is_the_first_reliable)
1238 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001239 is_existed = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001240 break;
1241 }
1242 }
1243
Marie Janssene9e58ce2016-06-17 14:12:17 -07001244#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001245 APPL_TRACE_DEBUG("bta_hl_is_the_first_reliable_existed is_existed=%d ",is_existed );
The Android Open Source Project5738f832012-12-12 16:00:35 -08001246#endif
1247 return is_existed;
1248}
1249
1250/*******************************************************************************
1251**
1252** Function bta_hl_find_non_active_mdl_cfg
1253**
1254** Description This function finds a valid MDL configiration index and this
1255** MDL ID is not active
1256**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001257** Returns bool - true found
1258** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001259**
1260*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001261bool bta_hl_find_non_active_mdl_cfg(uint8_t app_idx, uint8_t start_mdl_cfg_idx,
1262 uint8_t *p_mdl_cfg_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001263{
1264
1265 tBTA_HL_MCL_CB *p_mcb;
1266 tBTA_HL_MDL_CB *p_dcb;
1267 tBTA_HL_MDL_CFG *p_mdl;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001268 bool mdl_in_use;
1269 bool found = false;
1270 uint8_t i,j,k;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001271
1272 for (i = start_mdl_cfg_idx; i< BTA_HL_NUM_MDL_CFGS; i++)
1273 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001274 mdl_in_use = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001275 p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i);
1276 for (j=0; j< BTA_HL_NUM_MCLS; j++)
1277 {
1278 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, j);
1279 if (p_mcb->in_use &&
1280 !memcmp(p_mdl->peer_bd_addr,p_mcb->bd_addr,BD_ADDR_LEN))
1281 {
1282
1283 for (k=0; k<BTA_HL_NUM_MDLS_PER_MCL; k++)
1284 {
1285 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, j, k);
1286
1287 if (p_dcb->in_use && p_mdl->mdl_id == p_dcb->mdl_id)
1288 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001289 mdl_in_use = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001290 break;
1291 }
1292 }
1293 }
1294
1295 if (mdl_in_use)
1296 {
1297 break;
1298 }
1299 }
1300
1301 if (!mdl_in_use)
1302 {
1303 *p_mdl_cfg_idx = i;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001304 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001305 break;
1306 }
1307 }
1308
1309 return found;
1310}
1311
1312/*******************************************************************************
1313**
1314** Function bta_hl_find_mdl_cfg_idx
1315**
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08001316** Description This function finds an available MDL configuration index
The Android Open Source Project5738f832012-12-12 16:00:35 -08001317**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001318** Returns bool - true found
1319** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001320**
1321*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001322bool bta_hl_find_avail_mdl_cfg_idx(uint8_t app_idx, uint8_t mcl_idx,
1323 uint8_t *p_mdl_cfg_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001324{
1325 tBTA_HL_MDL_CFG *p_mdl, *p_mdl1, *p_mdl2;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001326 uint8_t i;
1327 bool found=false;
1328 uint8_t first_mdl_cfg_idx, second_mdl_cfg_idx, older_mdl_cfg_idx;
1329 bool done;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08001330 UNUSED(mcl_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001331
1332 for (i=0; i< BTA_HL_NUM_MDL_CFGS; i++)
1333 {
1334 p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i);
1335 if (!p_mdl->active )
1336 {
1337 /* found an unused space to store mdl cfg*/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001338 found=true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001339 *p_mdl_cfg_idx =i;
1340 break;
1341 }
1342 }
1343
1344 if (!found)
1345 {
1346 /* all available mdl cfg spaces are in use so we need to find the mdl cfg which is
1347 not currently in use and has the the oldest time stamp to remove*/
1348
Marie Janssene9e58ce2016-06-17 14:12:17 -07001349 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001350 if (bta_hl_find_non_active_mdl_cfg(app_idx,0, &first_mdl_cfg_idx))
1351 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001352 if (bta_hl_find_non_active_mdl_cfg(app_idx,(uint8_t) (first_mdl_cfg_idx+1), &second_mdl_cfg_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001353 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001354 done = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001355 while (!done)
1356 {
1357 p_mdl1 = BTA_HL_GET_MDL_CFG_PTR(app_idx, first_mdl_cfg_idx);
1358 p_mdl2 = BTA_HL_GET_MDL_CFG_PTR(app_idx, second_mdl_cfg_idx);
1359
1360 if (p_mdl1->time < p_mdl2->time)
1361 {
1362 older_mdl_cfg_idx = first_mdl_cfg_idx;
1363 }
1364 else
1365 {
1366 older_mdl_cfg_idx = second_mdl_cfg_idx;
1367 }
1368
Marie Janssene9e58ce2016-06-17 14:12:17 -07001369 if (bta_hl_find_non_active_mdl_cfg(app_idx,(uint8_t) (second_mdl_cfg_idx+1), &second_mdl_cfg_idx))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001370 {
1371 first_mdl_cfg_idx = older_mdl_cfg_idx;
1372 }
1373 else
1374 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001375 done = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001376 }
1377 }
1378
1379 *p_mdl_cfg_idx = older_mdl_cfg_idx;
1380
1381 }
1382 else
1383 {
1384 *p_mdl_cfg_idx = first_mdl_cfg_idx;
1385 }
1386
1387 }
1388 else
1389 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001390 found = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001391 }
1392 }
1393
Marie Janssene9e58ce2016-06-17 14:12:17 -07001394#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001395 if (!found)
1396 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001397 APPL_TRACE_DEBUG("bta_hl_find_avail_mdl_cfg_idx found=%d mdl_cfg_idx=%d ",found, *p_mdl_cfg_idx );
The Android Open Source Project5738f832012-12-12 16:00:35 -08001398 }
1399#endif
1400
1401 return found;
1402
1403
1404}
1405
1406/*******************************************************************************
1407**
1408** Function bta_hl_find_mdl_cfg_idx
1409**
1410** Description This function finds the MDL configuration index based on
1411** the MDL ID
1412**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001413** Returns bool - true found
1414** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001415**
1416*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001417bool bta_hl_find_mdl_cfg_idx(uint8_t app_idx, uint8_t mcl_idx,
1418 tBTA_HL_MDL_ID mdl_id, uint8_t *p_mdl_cfg_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001419{
1420 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1421 tBTA_HL_MDL_CFG *p_mdl;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001422 uint8_t i ;
1423 bool found=false;
Matthew Xiebea41312014-05-09 01:04:04 -07001424
1425 *p_mdl_cfg_idx = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001426 for (i=0; i< BTA_HL_NUM_MDL_CFGS; i++)
1427 {
1428 p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i);
Priti Agheraf8f30c22013-04-02 15:31:19 -07001429 if(p_mdl->active)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001430 APPL_TRACE_DEBUG("bta_hl_find_mdl_cfg_idx: mdl_id =%d, p_mdl->mdl_id=%d",mdl_id,
Priti Agheraf8f30c22013-04-02 15:31:19 -07001431 p_mdl->mdl_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001432 if (p_mdl->active &&
1433 (!memcmp (p_mcb->bd_addr, p_mdl->peer_bd_addr, BD_ADDR_LEN))&&
1434 (p_mdl->mdl_id == mdl_id))
1435 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001436 found=true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001437 *p_mdl_cfg_idx =i;
1438 break;
1439 }
1440 }
1441
Marie Janssene9e58ce2016-06-17 14:12:17 -07001442#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001443 if (!found)
1444 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001445 APPL_TRACE_DEBUG("bta_hl_find_mdl_cfg_idx found=%d mdl_cfg_idx=%d ",found, i );
The Android Open Source Project5738f832012-12-12 16:00:35 -08001446 }
1447#endif
1448
1449 return found;
1450
1451
1452}
1453
1454
1455/*******************************************************************************
1456**
1457** Function bta_hl_get_cur_time
1458**
1459** Description This function get the cuurent time value
1460**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001461** Returns bool - true found
1462** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001463**
1464*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001465bool bta_hl_get_cur_time(uint8_t app_idx, uint8_t *p_cur_time)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001466{
1467 tBTA_HL_MDL_CFG *p_mdl;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001468 uint8_t i, j, time_latest, time;
1469 bool found=false, result=true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001470
1471 for (i=0; i< BTA_HL_NUM_MDL_CFGS; i++)
1472 {
1473 p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i);
1474 if (p_mdl->active)
1475 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001476 found=true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001477 time_latest = p_mdl->time;
1478 for (j=(i+1); j< BTA_HL_NUM_MDL_CFGS; j++ )
1479 {
1480 p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, j);
1481 if (p_mdl->active)
1482 {
1483 time = p_mdl->time;
1484 if (time > time_latest)
1485 {
1486 time_latest = time;
1487 }
1488 }
1489 }
1490 break;
1491 }
1492 }
1493
1494
1495 if (found)
1496 {
1497 if (time_latest < BTA_HL_MAX_TIME)
1498 {
1499 *p_cur_time = time_latest+1;
1500 }
1501 else
1502 {
1503 /* need to wrap around */
Marie Janssene9e58ce2016-06-17 14:12:17 -07001504 result = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001505 }
1506 }
1507 else
1508 {
1509 *p_cur_time = BTA_HL_MIN_TIME;
1510 }
1511
Marie Janssene9e58ce2016-06-17 14:12:17 -07001512#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001513 if (!result)
1514 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001515 APPL_TRACE_DEBUG("bta_hl_get_cur_time result=%s cur_time=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001516 (result?"OK":"FAIL"), *p_cur_time);
1517 }
1518#endif
1519
1520 return result;
1521}
1522
1523/*******************************************************************************
1524**
1525** Function bta_hl_sort_cfg_time_idx
1526**
1527** Description This function sort the mdl configuration idx stored in array a
1528** based on decending time value
1529**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001530** Returns bool - true found
1531** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001532**
1533*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001534void bta_hl_sort_cfg_time_idx(uint8_t app_idx, uint8_t *a, uint8_t n)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001535{
1536 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -07001537 uint8_t temp_time, temp_idx;
1538 int16_t i, j;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001539 for (i = 1; i < n; ++i)
1540 {
1541 temp_idx = a[i];
1542 temp_time = p_acb->mdl_cfg[temp_idx].time;
1543 j = i - 1;
1544 while ((j >= 0) && (temp_time < p_acb->mdl_cfg[a[j]].time))
1545 {
1546 a[j + 1] = a[j];
1547 --j;
1548 }
1549 a[j + 1] = temp_idx;
1550 }
1551}
1552
1553/*******************************************************************************
1554**
1555** Function bta_hl_compact_mdl_cfg_time
1556**
1557** Description This function finds the MDL configuration index based on
1558** the MDL ID
1559**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001560** Returns bool - true found
1561** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001562**
1563*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001564void bta_hl_compact_mdl_cfg_time(uint8_t app_idx, uint8_t mdep_id)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001565{
The Android Open Source Project5738f832012-12-12 16:00:35 -08001566 tBTA_HL_MDL_CFG *p_mdl;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001567 uint8_t i, time_min, cnt=0;
1568 uint8_t s_arr[BTA_HL_NUM_MDL_CFGS];
The Android Open Source Project5738f832012-12-12 16:00:35 -08001569
1570
1571 for (i=0; i< BTA_HL_NUM_MDL_CFGS; i++)
1572 {
1573 p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i);
1574 if (p_mdl->active )
1575 {
1576 s_arr[cnt]= i;
1577 cnt++;
1578 }
1579 }
1580
1581
1582
Marie Janssene9e58ce2016-06-17 14:12:17 -07001583#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001584 APPL_TRACE_DEBUG("bta_hl_compact_mdl_cfg_time cnt=%d ",cnt );
The Android Open Source Project5738f832012-12-12 16:00:35 -08001585#endif
1586
1587
1588 if (cnt)
1589 {
1590 bta_hl_sort_cfg_time_idx(app_idx, s_arr, cnt);
1591 time_min = BTA_HL_MIN_TIME;
1592 for (i=0;i<cnt; i++)
1593 {
1594 p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, s_arr[i]);
1595 p_mdl->time = time_min + i;
Priti Agheraf8f30c22013-04-02 15:31:19 -07001596 bta_hl_co_save_mdl(mdep_id, s_arr[i], p_mdl);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001597 }
1598 }
1599
1600
1601}
1602
1603
1604
1605/*******************************************************************************
1606**
1607** Function bta_hl_is_mdl_exsit_in_mcl
1608**
1609** Description This function checks whether the MDL ID
1610** has already existed in teh MCL or not
1611**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001612** Returns bool - true exist
1613** false does not exist
The Android Open Source Project5738f832012-12-12 16:00:35 -08001614**
1615*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001616bool bta_hl_is_mdl_exsit_in_mcl(uint8_t app_idx, BD_ADDR bd_addr,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001617 tBTA_HL_MDL_ID mdl_id)
1618{
1619 tBTA_HL_MDL_CFG *p_mdl;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001620 bool found = false;
1621 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001622
1623 for (i = 0; i< BTA_HL_NUM_MDL_CFGS; i++)
1624 {
1625 p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i);
1626 if (p_mdl->active &&
1627 !memcmp(p_mdl->peer_bd_addr, bd_addr,BD_ADDR_LEN))
1628 {
1629 if (mdl_id != BTA_HL_DELETE_ALL_MDL_IDS)
1630 {
1631 if (p_mdl->mdl_id == mdl_id)
1632 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001633 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001634 break;
1635 }
1636 }
1637 else
1638 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001639 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001640 break;
1641 }
1642 }
1643 }
1644
1645 return found;
1646}
1647
1648/*******************************************************************************
1649**
1650** Function bta_hl_delete_mdl_cfg
1651**
1652** Description This function delete the specified MDL ID
1653**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001654** Returns bool - true Success
1655** false Failed
The Android Open Source Project5738f832012-12-12 16:00:35 -08001656**
1657*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001658bool bta_hl_delete_mdl_cfg(uint8_t app_idx, BD_ADDR bd_addr,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001659 tBTA_HL_MDL_ID mdl_id)
1660{
1661 tBTA_HL_MDL_CFG *p_mdl;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001662 bool success = false;
1663 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001664
1665 for (i = 0; i< BTA_HL_NUM_MDL_CFGS; i++)
1666 {
1667 p_mdl = BTA_HL_GET_MDL_CFG_PTR(app_idx, i);
1668 if (p_mdl->active &&
1669 !memcmp(p_mdl->peer_bd_addr, bd_addr,BD_ADDR_LEN))
1670 {
1671 if (mdl_id != BTA_HL_DELETE_ALL_MDL_IDS)
1672 {
1673 if (p_mdl->mdl_id == mdl_id)
1674 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07001675 bta_hl_co_delete_mdl(p_mdl->local_mdep_id, i);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001676 memset(p_mdl, 0, sizeof(tBTA_HL_MDL_CFG));
Marie Janssene9e58ce2016-06-17 14:12:17 -07001677 success = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001678 break;
1679 }
1680 }
1681 else
1682 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07001683 bta_hl_co_delete_mdl(p_mdl->local_mdep_id, i);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001684 memset(p_mdl, 0, sizeof(tBTA_HL_MDL_CFG));
Marie Janssene9e58ce2016-06-17 14:12:17 -07001685 success = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001686 }
1687 }
1688 }
1689
1690 return success;
1691}
1692
1693
1694/*******************************************************************************
1695**
1696** Function bta_hl_is_mdl_value_valid
1697**
1698**
1699** Description This function checks the specified MDL ID is in valid range or not
1700**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001701** Returns bool - true Success
1702** false Failed
The Android Open Source Project5738f832012-12-12 16:00:35 -08001703**
1704** note: mdl_id range 0x0000 reserved,
1705** 0x0001-oxFEFF dynamic range,
1706** 0xFF00-0xFFFE reserved,
1707** 0xFFFF indicates all MDLs (for delete operation only)
1708**
1709*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001710bool bta_hl_is_mdl_value_valid(tBTA_HL_MDL_ID mdl_id)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001711{
Marie Janssene9e58ce2016-06-17 14:12:17 -07001712 bool status = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001713
1714 if (mdl_id != BTA_HL_DELETE_ALL_MDL_IDS)
1715 {
1716 if (mdl_id != 0)
1717 {
1718 if (mdl_id > BTA_HL_MAX_MDL_VAL )
1719 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001720 status = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001721 }
1722 }
1723 else
1724 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001725 status = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001726 }
1727 }
1728
1729 return status;
1730}
1731
1732/*******************************************************************************
1733**
1734** Function bta_hl_find_mdep_cfg_idx
1735**
1736** Description This function finds the MDEP configuration index based
1737** on the local MDEP ID
1738**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001739** Returns bool - true found
1740** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001741**
1742*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001743bool bta_hl_find_mdep_cfg_idx(uint8_t app_idx, tBTA_HL_MDEP_ID local_mdep_id,
1744 uint8_t *p_mdep_cfg_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001745{
1746 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1747 tBTA_HL_SUP_FEATURE *p_sup_feature= &p_acb->sup_feature;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001748 bool found =false;
1749 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001750
1751 for (i=0; i< p_sup_feature->num_of_mdeps; i++)
1752 {
1753 if ( p_sup_feature->mdep[i].mdep_id == local_mdep_id)
1754 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001755 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001756 *p_mdep_cfg_idx = i;
1757 break;
1758 }
1759 }
1760
Marie Janssene9e58ce2016-06-17 14:12:17 -07001761#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001762 if (!found)
1763 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001764 APPL_TRACE_DEBUG("bta_hl_find_mdep_cfg_idx found=%d mdep_idx=%d local_mdep_id=%d ",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001765 found,i, local_mdep_id );
1766 }
1767#endif
1768 return found;
1769}
1770
1771
1772/*******************************************************************************
1773**
1774** Function bta_hl_find_rxtx_apdu_size
1775**
1776** Description This function finds the maximum APDU rx and tx sizes based on
1777** the MDEP configuration data
1778**
1779** Returns void
1780**
1781*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001782void bta_hl_find_rxtx_apdu_size(uint8_t app_idx, uint8_t mdep_cfg_idx,
1783 uint16_t *p_rx_apu_size,
1784 uint16_t *p_tx_apu_size)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001785{
1786 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1787 tBTA_HL_MDEP_CFG *p_mdep_cfg;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001788 uint8_t i;
1789 uint16_t max_rx_apdu_size=0, max_tx_apdu_size=0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001790
1791 p_mdep_cfg = &p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg;
1792
1793
1794 for (i=0; i< p_mdep_cfg->num_of_mdep_data_types ; i++)
1795 {
1796
1797 if (max_rx_apdu_size < p_mdep_cfg->data_cfg[i].max_rx_apdu_size)
1798 {
1799 max_rx_apdu_size = p_mdep_cfg->data_cfg[i].max_rx_apdu_size;
1800 }
1801
1802 if (max_tx_apdu_size < p_mdep_cfg->data_cfg[i].max_tx_apdu_size)
1803 {
1804 max_tx_apdu_size = p_mdep_cfg->data_cfg[i].max_tx_apdu_size;
1805 }
1806 }
1807
1808
1809 *p_rx_apu_size = max_rx_apdu_size;
1810 *p_tx_apu_size = max_tx_apdu_size;
1811
Marie Janssene9e58ce2016-06-17 14:12:17 -07001812#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001813 APPL_TRACE_DEBUG("bta_hl_find_rxtx_apdu_size max_rx_apdu_size=%d max_tx_apdu_size=%d ",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001814 max_rx_apdu_size, max_tx_apdu_size );
1815#endif
1816
1817
1818}
1819
1820/*******************************************************************************
1821**
1822** Function bta_hl_validate_peer_cfg
1823**
1824** Description This function validates the peer DCH configuration
1825**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001826** Returns bool - true validation is successful
1827** false validation failed
The Android Open Source Project5738f832012-12-12 16:00:35 -08001828**
1829*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001830bool bta_hl_validate_peer_cfg(uint8_t app_idx, uint8_t mcl_idx, uint8_t mdl_idx,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001831 tBTA_HL_MDEP_ID peer_mdep_id,
1832 tBTA_HL_MDEP_ROLE peer_mdep_role,
Marie Janssene9e58ce2016-06-17 14:12:17 -07001833 uint8_t sdp_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001834{
1835 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
1836 tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
1837 tBTA_HL_SDP_REC *p_rec;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001838 bool peer_found =false;
1839 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001840
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001841 APPL_TRACE_DEBUG("bta_hl_validate_peer_cfg sdp_idx=%d app_idx %d", sdp_idx, app_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001842
1843
1844 if (p_dcb->local_mdep_id == BTA_HL_ECHO_TEST_MDEP_ID)
1845 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001846 return true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001847 }
1848
1849 p_rec = &p_mcb->sdp.sdp_rec[sdp_idx];
1850 for (i=0; i< p_rec->num_mdeps; i++)
1851 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001852 APPL_TRACE_DEBUG("mdep_id %d peer_mdep_id %d",p_rec->mdep_cfg[i].mdep_id , peer_mdep_id);
1853 APPL_TRACE_DEBUG("mdep_role %d peer_mdep_role %d",p_rec->mdep_cfg[i].mdep_role,
Priti Agheraf8f30c22013-04-02 15:31:19 -07001854 peer_mdep_role)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001855 if ( (p_rec->mdep_cfg[i].mdep_id == peer_mdep_id) &&
1856 (p_rec->mdep_cfg[i].mdep_role == peer_mdep_role))
1857 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001858 peer_found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001859
1860 break;
1861 }
1862 }
1863
Marie Janssene9e58ce2016-06-17 14:12:17 -07001864#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001865 if (!peer_found)
1866 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001867 APPL_TRACE_DEBUG("bta_hl_validate_peer_cfg failed num_mdeps=%d",p_rec->num_mdeps);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001868 }
1869#endif
1870 return peer_found;
1871}
1872
The Android Open Source Project5738f832012-12-12 16:00:35 -08001873/*******************************************************************************
1874**
1875** Function bta_hl_chk_local_cfg
1876**
1877** Description This function check whether the local DCH configuration is OK or not
1878**
1879** Returns tBTA_HL_STATUS - OK - local DCH configuration is OK
1880** NO_FIRST_RELIABLE - the streaming DCH configuration
1881** is not OK and it needs to use
1882** reliable DCH configuration
1883**
1884*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001885tBTA_HL_STATUS bta_hl_chk_local_cfg(uint8_t app_idx, uint8_t mcl_idx,
1886 uint8_t mdep_cfg_idx,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001887 tBTA_HL_DCH_CFG local_cfg)
1888{
1889 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1890 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
1891
1892 if ( mdep_cfg_idx &&
1893 (p_acb->sup_feature.mdep[mdep_cfg_idx].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SOURCE) &&
1894 (!bta_hl_is_the_first_reliable_existed(app_idx, mcl_idx)) &&
1895 (local_cfg != BTA_HL_DCH_CFG_RELIABLE))
1896 {
1897 status = BTA_HL_STATUS_NO_FIRST_RELIABLE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001898 APPL_TRACE_ERROR("BTA_HL_STATUS_INVALID_DCH_CFG");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001899 }
1900
1901 return status;
1902}
1903
1904
1905/*******************************************************************************
1906**
1907** Function bta_hl_validate_reconnect_params
1908**
1909** Description This function validates the reconnect parameters
1910**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001911** Returns bool - true validation is successful
1912** false validation failed
The Android Open Source Project5738f832012-12-12 16:00:35 -08001913*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001914bool bta_hl_validate_reconnect_params(uint8_t app_idx, uint8_t mcl_idx,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001915 tBTA_HL_API_DCH_RECONNECT *p_reconnect,
Marie Janssene9e58ce2016-06-17 14:12:17 -07001916 uint8_t *p_mdep_cfg_idx, uint8_t *p_mdl_cfg_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001917{
1918 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
1919 tBTA_HL_SUP_FEATURE *p_sup_feature = &p_acb->sup_feature;
Marie Janssene9e58ce2016-06-17 14:12:17 -07001920 uint8_t num_mdeps;
1921 uint8_t mdl_cfg_idx;
1922 bool local_mdep_id_found =false;
1923 bool mdl_cfg_found =false;
1924 bool status=false;
1925 uint8_t i, in_use_mdl_idx = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001926
Marie Janssene9e58ce2016-06-17 14:12:17 -07001927#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001928 APPL_TRACE_DEBUG("bta_hl_validate_reconnect_params mdl_id=%d app_idx=%d", p_reconnect->mdl_id, app_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001929#endif
1930 if (bta_hl_find_mdl_cfg_idx(app_idx, mcl_idx, p_reconnect->mdl_id, &mdl_cfg_idx))
1931 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001932 mdl_cfg_found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001933 }
1934
Marie Janssene9e58ce2016-06-17 14:12:17 -07001935#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001936 if (!mdl_cfg_found)
1937 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001938 APPL_TRACE_DEBUG("mdl_cfg_found not found");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001939 }
1940#endif
1941
1942
1943 if (mdl_cfg_found)
1944 {
1945 num_mdeps = p_sup_feature->num_of_mdeps;
1946 for (i=0; i< num_mdeps ; i++)
1947 {
1948 if ( p_sup_feature->mdep[i].mdep_id == p_acb->mdl_cfg[mdl_cfg_idx].local_mdep_id)
1949 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001950 local_mdep_id_found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001951 *p_mdep_cfg_idx =i;
1952 *p_mdl_cfg_idx = mdl_cfg_idx;
1953 break;
1954 }
1955 }
1956 }
1957
Marie Janssene9e58ce2016-06-17 14:12:17 -07001958#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001959 if (!local_mdep_id_found)
1960 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001961 APPL_TRACE_DEBUG("local_mdep_id not found");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001962 }
1963#endif
1964
1965
1966 if (local_mdep_id_found)
1967 {
1968 if (!bta_hl_find_mdl_idx(app_idx,mcl_idx, p_reconnect->mdl_id, &in_use_mdl_idx))
1969 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07001970 status= true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001971 }
1972 else
1973 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001974 APPL_TRACE_ERROR("mdl_id=%d is curreltly in use",p_reconnect->mdl_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001975 }
1976 }
1977
Marie Janssene9e58ce2016-06-17 14:12:17 -07001978#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001979 if (!status)
1980 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001981 APPL_TRACE_DEBUG("Reconnect validation failed local_mdep_id found=%d mdl_cfg_idx found=%d in_use_mdl_idx=%d ",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001982 local_mdep_id_found, mdl_cfg_found, in_use_mdl_idx);
1983 }
1984#endif
1985 return status;
1986}
1987
1988/*******************************************************************************
1989**
1990** Function bta_hl_find_avail_mcl_idx
1991**
Marie Janssene9e58ce2016-06-17 14:12:17 -07001992** Returns bool - true found
1993** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -08001994**
1995*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07001996bool bta_hl_find_avail_mcl_idx(uint8_t app_idx, uint8_t *p_mcl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001997{
Marie Janssene9e58ce2016-06-17 14:12:17 -07001998 bool found=false;
1999 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002000
2001 for (i=0; i < BTA_HL_NUM_MCLS ; i ++)
2002 {
2003 if (!bta_hl_cb.acb[app_idx].mcb[i].in_use)
2004 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07002005 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002006 *p_mcl_idx = i;
2007 break;
2008 }
2009 }
2010
Marie Janssene9e58ce2016-06-17 14:12:17 -07002011#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002012 if (!found)
2013 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002014 APPL_TRACE_DEBUG("bta_hl_find_avail_mcl_idx found=%d idx=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08002015 found, i);
2016 }
2017#endif
2018 return found;
2019}
2020
2021
2022
2023/*******************************************************************************
2024**
2025** Function bta_hl_find_avail_mdl_idx
2026**
2027** Description This function finds an available MDL control block index
2028**
Marie Janssene9e58ce2016-06-17 14:12:17 -07002029** Returns bool - true found
2030** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -08002031**
2032*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002033bool bta_hl_find_avail_mdl_idx(uint8_t app_idx, uint8_t mcl_idx,
2034 uint8_t *p_mdl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002035{
2036 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -07002037 bool found=false;
2038 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002039
2040 for (i=0; i < BTA_HL_NUM_MDLS_PER_MCL ; i ++)
2041 {
2042 if (!p_mcb->mdl[i].in_use)
2043 {
2044 memset((void *)&p_mcb->mdl[i],0, sizeof(tBTA_HL_MDL_CB));
Marie Janssene9e58ce2016-06-17 14:12:17 -07002045 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002046 *p_mdl_idx = i;
2047 break;
2048 }
2049 }
2050
Marie Janssene9e58ce2016-06-17 14:12:17 -07002051#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002052 if (!found)
2053 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002054 APPL_TRACE_DEBUG("bta_hl_find_avail_mdl_idx found=%d idx=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08002055 found, i);
2056 }
2057#endif
2058 return found;
2059}
2060
2061/*******************************************************************************
2062**
2063** Function bta_hl_is_a_duplicate_id
2064**
2065** Description This function finds the application has been used or not
2066**
Marie Janssene9e58ce2016-06-17 14:12:17 -07002067** Returns bool - true the app_id is a duplicate ID
2068** false not a duplicate ID
The Android Open Source Project5738f832012-12-12 16:00:35 -08002069*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002070bool bta_hl_is_a_duplicate_id(uint8_t app_id)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002071{
Marie Janssene9e58ce2016-06-17 14:12:17 -07002072 bool is_duplicate=false;
2073 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002074
2075 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
2076 {
2077 if (bta_hl_cb.acb[i].in_use &&
2078 (bta_hl_cb.acb[i].app_id == app_id))
2079 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07002080 is_duplicate = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002081
2082 break;
2083 }
2084 }
2085
Marie Janssene9e58ce2016-06-17 14:12:17 -07002086#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002087 if (is_duplicate)
2088 {
2089
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002090 APPL_TRACE_DEBUG("bta_hl_is_a_duplicate_id app_id=%d is_duplicate=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08002091 app_id, is_duplicate);
2092 }
2093#endif
2094
2095 return is_duplicate;
2096}
2097
2098
2099/*******************************************************************************
2100**
2101** Function bta_hl_find_avail_app_idx
2102**
2103** Description This function finds an available application control block index
2104**
Marie Janssene9e58ce2016-06-17 14:12:17 -07002105** Returns bool - true found
2106** false not found
The Android Open Source Project5738f832012-12-12 16:00:35 -08002107**
2108*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002109bool bta_hl_find_avail_app_idx(uint8_t *p_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002110{
Marie Janssene9e58ce2016-06-17 14:12:17 -07002111 bool found=false;
2112 uint8_t i;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002113
2114 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
2115 {
2116 if (!bta_hl_cb.acb[i].in_use)
2117 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07002118 found = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002119 *p_idx = i;
2120 break;
2121 }
2122 }
2123
Marie Janssene9e58ce2016-06-17 14:12:17 -07002124#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002125 if (!found)
2126 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002127 APPL_TRACE_DEBUG("bta_hl_find_avail_app_idx found=%d app_idx=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08002128 found, i);
2129 }
2130#endif
2131 return found;
2132}
2133
2134/*******************************************************************************
2135**
Priti Agheraf8f30c22013-04-02 15:31:19 -07002136** Function bta_hl_app_update
2137**
2138** Description This function registers an HDP application MCAP and DP
2139**
2140** Returns tBTA_HL_STATUS -registration status
2141**
2142*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002143tBTA_HL_STATUS bta_hl_app_update(uint8_t app_id, bool is_register)
Priti Agheraf8f30c22013-04-02 15:31:19 -07002144{
2145 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
2146 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(0);
2147 tMCA_CS mca_cs;
Marie Janssene9e58ce2016-06-17 14:12:17 -07002148 uint8_t i, mdep_idx, num_of_mdeps;
2149 uint8_t mdep_counter = 0;
Priti Agheraf8f30c22013-04-02 15:31:19 -07002150
2151
Marie Janssene9e58ce2016-06-17 14:12:17 -07002152#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002153 APPL_TRACE_DEBUG("bta_hl_app_update app_id=%d", app_id);
Priti Agheraf8f30c22013-04-02 15:31:19 -07002154#endif
2155
2156 if (is_register)
2157 {
2158 if ((status == BTA_HL_STATUS_OK) &&
2159 bta_hl_co_get_num_of_mdep(app_id, &num_of_mdeps))
2160 {
2161 for (i=0; i < num_of_mdeps; i++)
2162 {
2163 mca_cs.type = MCA_TDEP_DATA;
2164 mca_cs.max_mdl = BTA_HL_NUM_MDLS_PER_MDEP;
2165 mca_cs.p_data_cback = bta_hl_mcap_data_cback;
2166 /* Find the first available mdep index, and create a MDL Endpoint */
2167 // make a function later if needed
2168 for (mdep_idx = 1; mdep_idx < BTA_HL_NUM_MDEPS; mdep_idx++)
2169 {
2170 if ( p_acb->sup_feature.mdep[mdep_idx].mdep_id == 0)
2171 {
2172 break; /* We found an available index */
2173 }
2174 else
2175 {
2176 mdep_counter++;
2177 }
2178 }
2179 /* If no available MDEPs, return error */
2180 if (mdep_idx == BTA_HL_NUM_MDEPS)
2181 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002182 APPL_TRACE_ERROR("bta_hl_app_update: Out of MDEP IDs");
Priti Agheraf8f30c22013-04-02 15:31:19 -07002183 status = BTA_HL_STATUS_MCAP_REG_FAIL;
2184 break;
2185 }
2186 if (MCA_CreateDep((tMCA_HANDLE)p_acb->app_handle,
2187 &(p_acb->sup_feature.mdep[mdep_idx].mdep_id), &mca_cs) == MCA_SUCCESS)
2188 {
2189 if (bta_hl_co_get_mdep_config(app_id,
2190 mdep_idx,
2191 mdep_counter,
2192 p_acb->sup_feature.mdep[mdep_idx].mdep_id,
2193 &p_acb->sup_feature.mdep[mdep_idx].mdep_cfg))
2194 {
2195 p_acb->sup_feature.mdep[mdep_idx].ori_app_id = app_id;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002196 APPL_TRACE_DEBUG("mdep idx %d id %d ori_app_id %d num data type %d",mdep_idx,
Priti Agheraf8f30c22013-04-02 15:31:19 -07002197 p_acb->sup_feature.mdep[mdep_idx].mdep_id,
2198 p_acb->sup_feature.mdep[mdep_idx].ori_app_id,
2199 p_acb->sup_feature.mdep[mdep_idx].mdep_cfg.num_of_mdep_data_types);
2200 if (p_acb->sup_feature.mdep[mdep_idx].mdep_cfg.mdep_role ==
2201 BTA_HL_MDEP_ROLE_SOURCE)
2202 {
2203 p_acb->sup_feature.app_role_mask |= BTA_HL_MDEP_ROLE_MASK_SOURCE;
2204 }
2205 else if (p_acb->sup_feature.mdep[mdep_idx].mdep_cfg.mdep_role ==
2206 BTA_HL_MDEP_ROLE_SINK)
2207 {
2208 p_acb->sup_feature.app_role_mask |= BTA_HL_MDEP_ROLE_MASK_SINK;
2209 }
2210 else
2211 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002212 APPL_TRACE_ERROR("bta_hl_app_registration: Invalid Role %d",
Priti Agheraf8f30c22013-04-02 15:31:19 -07002213 p_acb->sup_feature.mdep[mdep_idx].mdep_cfg.mdep_role);
2214 status = BTA_HL_STATUS_MDEP_CO_FAIL;
2215 break;
2216 }
2217 }
2218 else
2219 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002220 APPL_TRACE_ERROR("bta_hl_app_registration: Cfg callout failed");
Priti Agheraf8f30c22013-04-02 15:31:19 -07002221 status = BTA_HL_STATUS_MDEP_CO_FAIL;
2222 break;
2223 }
2224 }
2225 else
2226 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002227 APPL_TRACE_ERROR("bta_hl_app_registration: MCA_CreateDep failed");
Priti Agheraf8f30c22013-04-02 15:31:19 -07002228 status = BTA_HL_STATUS_MCAP_REG_FAIL;
2229 break;
2230 }
2231
2232 }
2233 p_acb->sup_feature.num_of_mdeps += num_of_mdeps;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002234 APPL_TRACE_DEBUG("num_of_mdeps %d", p_acb->sup_feature.num_of_mdeps);
Priti Agheraf8f30c22013-04-02 15:31:19 -07002235
2236 if ((status == BTA_HL_STATUS_OK) &&
2237 (p_acb->sup_feature.app_role_mask == BTA_HL_MDEP_ROLE_MASK_SOURCE))
2238 {
2239 p_acb->sup_feature.advertize_source_sdp =
2240 bta_hl_co_advrtise_source_sdp(app_id);
2241 }
2242
2243 if ((status == BTA_HL_STATUS_OK)&&
2244 (!bta_hl_co_get_echo_config(app_id, &p_acb->sup_feature.echo_cfg)))
2245 {
2246 status = BTA_HL_STATUS_ECHO_CO_FAIL;
2247 }
2248
2249 if ((status == BTA_HL_STATUS_OK)&&
2250 (!bta_hl_co_load_mdl_config(app_id, BTA_HL_NUM_MDL_CFGS, &p_acb->mdl_cfg[0])))
2251 {
2252 status = BTA_HL_STATUS_MDL_CFG_CO_FAIL;
2253 }
2254 }
2255 else
2256 {
2257 status = BTA_HL_STATUS_MDEP_CO_FAIL;
2258 }
2259 }
2260 else
2261 {
2262 for (i=1; i<BTA_HL_NUM_MDEPS; i++)
2263 {
2264 if (p_acb->sup_feature.mdep[i].ori_app_id == app_id)
2265 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002266 APPL_TRACE_DEBUG("Found index %", i);
Priti Agheraf8f30c22013-04-02 15:31:19 -07002267
2268
2269 if (MCA_DeleteDep((tMCA_HANDLE)p_acb->app_handle,
2270 (p_acb->sup_feature.mdep[i].mdep_id)) != MCA_SUCCESS)
2271 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002272 APPL_TRACE_ERROR("Error deregistering");
Priti Agheraf8f30c22013-04-02 15:31:19 -07002273 status = BTA_HL_STATUS_MCAP_REG_FAIL;
2274 return status;
2275 }
2276 memset(&p_acb->sup_feature.mdep[i], 0, sizeof(tBTA_HL_MDEP));
2277 }
2278 }
2279
2280
2281 }
2282
2283 if (status == BTA_HL_STATUS_OK)
2284 {
2285 /* Register/Update MDEP(s) in SDP Record */
2286 status = bta_hl_sdp_update(app_id);
2287 }
2288 /* else do cleanup */
2289
2290
2291 return status;
2292}
2293
2294
2295/*******************************************************************************
2296**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002297** Function bta_hl_app_registration
2298**
2299** Description This function registers an HDP application MCAP and DP
2300**
2301** Returns tBTA_HL_STATUS -registration status
2302**
2303*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002304tBTA_HL_STATUS bta_hl_app_registration(uint8_t app_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002305{
2306 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
2307 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
2308 tMCA_REG reg;
2309 tMCA_CS mca_cs;
Marie Janssene9e58ce2016-06-17 14:12:17 -07002310 uint8_t i, num_of_mdeps;
2311 uint8_t mdep_counter = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002312
Marie Janssene9e58ce2016-06-17 14:12:17 -07002313#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002314 APPL_TRACE_DEBUG("bta_hl_app_registration app_idx=%d", app_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002315#endif
2316
2317 reg.ctrl_psm = p_acb->ctrl_psm;
2318 reg.data_psm = p_acb->data_psm;
2319 reg.sec_mask = p_acb->sec_mask;
2320 reg.rsp_tout = BTA_HL_MCAP_RSP_TOUT;
2321
2322 if ( (p_acb->app_handle = (tBTA_HL_APP_HANDLE) MCA_Register(&reg, bta_hl_mcap_ctrl_cback))!=0)
2323 {
2324 mca_cs.type = MCA_TDEP_ECHO;
2325 mca_cs.max_mdl = BTA_HL_NUM_MDLS_PER_MDEP;
2326 mca_cs.p_data_cback = bta_hl_mcap_data_cback;
2327
2328 if (MCA_CreateDep((tMCA_HANDLE)p_acb->app_handle,
2329 &(p_acb->sup_feature.mdep[0].mdep_id),
2330 &mca_cs) == MCA_SUCCESS)
2331 {
2332 if (p_acb->sup_feature.mdep[0].mdep_id != BTA_HL_ECHO_TEST_MDEP_ID)
2333 {
2334 status = BTA_HL_STATUS_MCAP_REG_FAIL;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002335 APPL_TRACE_ERROR("BAD MDEP ID for echo test mdep_id=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08002336 p_acb->sup_feature.mdep[0].mdep_id );
2337 }
2338 }
2339 else
2340 {
2341 status = BTA_HL_STATUS_MCAP_REG_FAIL;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002342 APPL_TRACE_ERROR("MCA_CreateDep for echo test(mdep_id=0) failed");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002343 }
2344
2345
2346 if ((status == BTA_HL_STATUS_OK) &&
2347 bta_hl_co_get_num_of_mdep(p_acb->app_id, &num_of_mdeps))
2348 {
2349 p_acb->sup_feature.num_of_mdeps = num_of_mdeps+1;
2350
2351 for (i=1; i<p_acb->sup_feature.num_of_mdeps; i++)
2352 {
2353 mca_cs.type = MCA_TDEP_DATA;
2354 mca_cs.max_mdl = BTA_HL_NUM_MDLS_PER_MDEP;
2355 mca_cs.p_data_cback = bta_hl_mcap_data_cback;
2356
2357 if (MCA_CreateDep((tMCA_HANDLE)p_acb->app_handle,
2358 &(p_acb->sup_feature.mdep[i].mdep_id), &mca_cs) == MCA_SUCCESS)
2359 {
2360 if (bta_hl_co_get_mdep_config(p_acb->app_id,
Priti Agheraf8f30c22013-04-02 15:31:19 -07002361 i,mdep_counter,
The Android Open Source Project5738f832012-12-12 16:00:35 -08002362 p_acb->sup_feature.mdep[i].mdep_id,
2363 &p_acb->sup_feature.mdep[i].mdep_cfg))
2364 {
2365 if (p_acb->sup_feature.mdep[i].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SOURCE)
2366 {
2367 p_acb->sup_feature.app_role_mask |= BTA_HL_MDEP_ROLE_MASK_SOURCE;
2368 }
2369 else if (p_acb->sup_feature.mdep[i].mdep_cfg.mdep_role == BTA_HL_MDEP_ROLE_SINK)
2370 {
2371 p_acb->sup_feature.app_role_mask |= BTA_HL_MDEP_ROLE_MASK_SINK;
2372 }
2373 else
2374 {
2375 status = BTA_HL_STATUS_MDEP_CO_FAIL;
2376 break;
2377 }
Priti Agheraf8f30c22013-04-02 15:31:19 -07002378 p_acb->sup_feature.mdep[i].ori_app_id = p_acb->app_id;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002379 APPL_TRACE_DEBUG("index %d ori_app_id %d", i,
Priti Agheraf8f30c22013-04-02 15:31:19 -07002380 p_acb->sup_feature.mdep[i].ori_app_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002381 }
2382 else
2383 {
2384 status = BTA_HL_STATUS_MDEP_CO_FAIL;
2385 break;
2386 }
2387 }
2388 else
2389 {
2390 status = BTA_HL_STATUS_MCAP_REG_FAIL;
2391 break;
2392 }
2393 }
2394
2395
2396
2397 if ((status == BTA_HL_STATUS_OK) &&
2398 (p_acb->sup_feature.app_role_mask == BTA_HL_MDEP_ROLE_MASK_SOURCE))
2399 {
2400 /* this is a source only applciation */
2401 p_acb->sup_feature.advertize_source_sdp =
2402 bta_hl_co_advrtise_source_sdp(p_acb->app_id);
2403 }
2404
2405 if ((status == BTA_HL_STATUS_OK)&&
2406 (!bta_hl_co_get_echo_config(p_acb->app_id, &p_acb->sup_feature.echo_cfg)))
2407 {
2408 status = BTA_HL_STATUS_ECHO_CO_FAIL;
2409 }
2410
2411 if ((status == BTA_HL_STATUS_OK)&&
2412 (!bta_hl_co_load_mdl_config(p_acb->app_id, BTA_HL_NUM_MDL_CFGS, &p_acb->mdl_cfg[0])))
2413 {
2414 status = BTA_HL_STATUS_MDL_CFG_CO_FAIL;
2415 }
2416 }
2417 else
2418 {
2419 status = BTA_HL_STATUS_MDEP_CO_FAIL;
2420 }
2421 }
2422 else
2423 {
2424 status = BTA_HL_STATUS_MCAP_REG_FAIL;
2425 }
2426
2427 if (status == BTA_HL_STATUS_OK)
2428 {
2429 status = bta_hl_sdp_register(app_idx);
2430 }
2431
2432 return status;
2433}
2434
2435
2436/*******************************************************************************
2437**
2438** Function bta_hl_discard_data
2439**
2440** Description This function discard an HDP event
2441**
2442** Returns void
2443**
2444*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002445void bta_hl_discard_data(uint16_t event, tBTA_HL_DATA *p_data)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002446{
2447
Marie Janssene9e58ce2016-06-17 14:12:17 -07002448#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002449 APPL_TRACE_ERROR("BTA HL Discard event=%s",bta_hl_evt_code(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002450
2451#endif
2452
2453 switch (event)
2454 {
2455 case BTA_HL_API_SEND_DATA_EVT:
2456 break;
2457
2458 case BTA_HL_MCA_RCV_DATA_EVT:
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -08002459 osi_free_and_reset((void **)&p_data->mca_rcv_data_evt.p_pkt);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002460 break;
2461
2462 default:
2463 /*Nothing to free*/
2464 break;
2465 }
2466}
2467
2468/*******************************************************************************
2469**
2470** Function bta_hl_save_mdl_cfg
2471**
2472** Description This function saves the MDL configuration
2473**
2474** Returns void
2475**
2476*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002477void bta_hl_save_mdl_cfg(uint8_t app_idx, uint8_t mcl_idx, uint8_t mdl_idx )
The Android Open Source Project5738f832012-12-12 16:00:35 -08002478{
2479 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
2480 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2481 tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -07002482 uint8_t mdl_cfg_idx;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002483 tBTA_HL_MDL_ID mdl_id;
Marie Janssene9e58ce2016-06-17 14:12:17 -07002484 bool found=true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002485 tBTA_HL_MDL_CFG mdl_cfg;
2486 tBTA_HL_MDEP *p_mdep_cfg;
2487 tBTA_HL_L2CAP_CFG_INFO l2cap_cfg;
Marie Janssene9e58ce2016-06-17 14:12:17 -07002488 uint8_t time_val = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002489 mdl_id = p_dcb->mdl_id;
2490 if (!bta_hl_find_mdl_cfg_idx(app_idx, mcl_idx, mdl_id, &mdl_cfg_idx))
2491 {
2492 if (!bta_hl_find_avail_mdl_cfg_idx(app_idx, mcl_idx, &mdl_cfg_idx))
2493 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002494 APPL_TRACE_ERROR("No space to save the MDL config");
Marie Janssene9e58ce2016-06-17 14:12:17 -07002495 found= false; /*no space available*/
The Android Open Source Project5738f832012-12-12 16:00:35 -08002496 }
2497 }
2498
2499 if (found)
2500 {
2501 bta_hl_get_l2cap_cfg(p_dcb->mdl_handle, &l2cap_cfg);
2502 if (!bta_hl_get_cur_time(app_idx, &time_val ))
2503 {
Priti Agheraf8f30c22013-04-02 15:31:19 -07002504 bta_hl_compact_mdl_cfg_time(app_idx,p_dcb->local_mdep_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002505 bta_hl_get_cur_time(app_idx, &time_val);
2506 }
Marie Janssene9e58ce2016-06-17 14:12:17 -07002507 mdl_cfg.active = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002508 mdl_cfg.time = time_val;
2509 mdl_cfg.mdl_id = p_dcb->mdl_id;
2510 mdl_cfg.dch_mode = p_dcb->dch_mode;
2511 mdl_cfg.mtu = l2cap_cfg.mtu;
2512 mdl_cfg.fcs = l2cap_cfg.fcs;
2513
2514 bdcpy(mdl_cfg.peer_bd_addr, p_mcb->bd_addr);
2515 mdl_cfg.local_mdep_id= p_dcb->local_mdep_id;
2516 p_mdep_cfg = &p_acb->sup_feature.mdep[p_dcb->local_mdep_cfg_idx];
2517 mdl_cfg.local_mdep_role= p_mdep_cfg->mdep_cfg.mdep_role;
2518 memcpy(&p_acb->mdl_cfg[mdl_cfg_idx], &mdl_cfg, sizeof(tBTA_HL_MDL_CFG));
Priti Agheraf8f30c22013-04-02 15:31:19 -07002519 bta_hl_co_save_mdl(mdl_cfg.local_mdep_id, mdl_cfg_idx, &mdl_cfg);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002520 }
2521
Marie Janssene9e58ce2016-06-17 14:12:17 -07002522#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002523 if (found)
2524 {
2525 if (p_dcb->mtu != l2cap_cfg.mtu)
2526 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002527 APPL_TRACE_WARNING("MCAP and L2CAP peer mtu size out of sync from MCAP mtu=%d from l2cap mtu=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08002528 p_dcb->mtu, l2cap_cfg.mtu);
2529 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002530 APPL_TRACE_DEBUG("bta_hl_save_mdl_cfg saved=%d", found);
2531 APPL_TRACE_DEBUG("Saved. L2cap cfg mdl_id=%d mtu=%d fcs=%d dch_mode=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08002532 mdl_cfg.mdl_id, mdl_cfg.mtu, mdl_cfg.fcs, mdl_cfg.dch_mode);
2533 }
2534#endif
2535
2536
2537
2538}
2539
2540/*******************************************************************************
2541**
2542** Function bta_hl_set_dch_chan_cfg
2543**
2544** Description This function setups the L2CAP DCH channel configuration
2545**
2546** Returns void
2547*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002548void bta_hl_set_dch_chan_cfg(uint8_t app_idx, uint8_t mcl_idx, uint8_t mdl_idx,tBTA_HL_DATA *p_data)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002549{
2550 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
2551 tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -07002552 uint8_t l2cap_mode = L2CAP_FCR_ERTM_MODE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002553 tBTA_HL_SUP_FEATURE *p_sup_feature= &p_acb->sup_feature;
Marie Janssene9e58ce2016-06-17 14:12:17 -07002554 uint8_t local_mdep_cfg_idx = p_dcb->local_mdep_cfg_idx;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002555
2556 switch (p_dcb->dch_oper)
2557 {
2558 case BTA_HL_DCH_OP_LOCAL_RECONNECT:
2559 case BTA_HL_DCH_OP_REMOTE_RECONNECT:
2560 if (p_dcb->dch_mode == BTA_HL_DCH_MODE_STREAMING)
2561 l2cap_mode = L2CAP_FCR_STREAM_MODE;
2562 break;
2563 case BTA_HL_DCH_OP_LOCAL_OPEN:
2564 if (p_data->mca_evt.mca_data.create_cfm.cfg == BTA_HL_DCH_CFG_STREAMING)
2565 l2cap_mode = L2CAP_FCR_STREAM_MODE;
2566 break;
2567 case BTA_HL_DCH_OP_REMOTE_OPEN:
2568 if (p_dcb->local_cfg == BTA_HL_DCH_CFG_STREAMING )
2569 l2cap_mode = L2CAP_FCR_STREAM_MODE;
2570 break;
2571 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002572 APPL_TRACE_ERROR("Invalid dch oper=%d for set dch chan cfg", p_dcb->dch_oper);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002573 break;
2574 }
2575 p_dcb->chnl_cfg.fcr_opt.mode = l2cap_mode;
2576 p_dcb->chnl_cfg.fcr_opt.mps = bta_hl_set_mps(p_dcb->max_rx_apdu_size);
2577 p_dcb->chnl_cfg.fcr_opt.tx_win_sz = bta_hl_set_tx_win_size(p_dcb->max_rx_apdu_size,
2578 p_dcb->chnl_cfg.fcr_opt.mps);
2579 p_dcb->chnl_cfg.fcr_opt.max_transmit= BTA_HL_L2C_MAX_TRANSMIT;
2580 p_dcb->chnl_cfg.fcr_opt.rtrans_tout = BTA_HL_L2C_RTRANS_TOUT;
2581 p_dcb->chnl_cfg.fcr_opt.mon_tout = BTA_HL_L2C_MON_TOUT;
2582
Pavlin Radoslavov1d5b8592015-09-23 10:08:20 -07002583 p_dcb->chnl_cfg.user_rx_buf_size = bta_hl_set_user_rx_buf_size(p_dcb->max_rx_apdu_size);
2584 p_dcb->chnl_cfg.user_tx_buf_size = bta_hl_set_user_tx_buf_size(p_dcb->max_tx_apdu_size);
2585 p_dcb->chnl_cfg.fcr_rx_buf_size = L2CAP_INVALID_ERM_BUF_SIZE;
2586 p_dcb->chnl_cfg.fcr_tx_buf_size = L2CAP_INVALID_ERM_BUF_SIZE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002587 p_dcb->chnl_cfg.data_mtu = p_dcb->max_rx_apdu_size;
2588
2589 p_dcb->chnl_cfg.fcs = BTA_HL_MCA_NO_FCS;
2590 if (local_mdep_cfg_idx != BTA_HL_ECHO_TEST_MDEP_CFG_IDX)
2591 {
2592 if (p_sup_feature->mdep[local_mdep_cfg_idx].mdep_cfg.mdep_role ==
2593 BTA_HL_MDEP_ROLE_SOURCE)
2594 {
2595 p_dcb->chnl_cfg.fcs = BTA_HL_DEFAULT_SOURCE_FCS;
2596 }
2597 }
2598 else
2599 {
2600 p_dcb->chnl_cfg.fcs = BTA_HL_MCA_USE_FCS;
2601 }
2602
Marie Janssene9e58ce2016-06-17 14:12:17 -07002603#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002604 APPL_TRACE_DEBUG("L2CAP Params l2cap_mode[3-ERTM 4-STREAM]=%d", l2cap_mode);
2605 APPL_TRACE_DEBUG("Use FCS =%s mtu=%d", ((p_dcb->chnl_cfg.fcs & 1)?"YES":"NO"),
The Android Open Source Project5738f832012-12-12 16:00:35 -08002606 p_dcb->chnl_cfg.data_mtu);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002607 APPL_TRACE_DEBUG("tx_win_sz=%d, max_transmit=%d, rtrans_tout=%d, mon_tout=%d, mps=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08002608 p_dcb->chnl_cfg.fcr_opt.tx_win_sz,
2609 p_dcb->chnl_cfg.fcr_opt.max_transmit,
2610 p_dcb->chnl_cfg.fcr_opt.rtrans_tout,
2611 p_dcb->chnl_cfg.fcr_opt.mon_tout,
2612 p_dcb->chnl_cfg.fcr_opt.mps);
2613
Pavlin Radoslavov1d5b8592015-09-23 10:08:20 -07002614 APPL_TRACE_DEBUG("USER rx_buf_size=%d, tx_buf_size=%d, FCR rx_buf_size=%d, tx_buf_size=%d",
2615 p_dcb->chnl_cfg.user_rx_buf_size,
2616 p_dcb->chnl_cfg.user_tx_buf_size,
2617 p_dcb->chnl_cfg.fcr_rx_buf_size,
2618 p_dcb->chnl_cfg.fcr_tx_buf_size);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002619
2620#endif
2621
2622
2623
2624
2625
2626
2627
2628
2629}
2630
2631/*******************************************************************************
2632**
2633** Function bta_hl_get_l2cap_cfg
2634**
2635** Description This function get the current L2CAP channel configuration
2636**
Marie Janssene9e58ce2016-06-17 14:12:17 -07002637** Returns bool - true - operation is successful
The Android Open Source Project5738f832012-12-12 16:00:35 -08002638*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002639bool bta_hl_get_l2cap_cfg(tBTA_HL_MDL_HANDLE mdl_hnd, tBTA_HL_L2CAP_CFG_INFO *p_cfg)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002640{
Marie Janssene9e58ce2016-06-17 14:12:17 -07002641 bool success = false;
2642 uint16_t lcid;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002643 tL2CAP_CFG_INFO *p_our_cfg;
2644 tL2CAP_CH_CFG_BITS our_cfg_bits;
2645 tL2CAP_CFG_INFO *p_peer_cfg;
2646 tL2CAP_CH_CFG_BITS peer_cfg_bits;
2647
2648 lcid = MCA_GetL2CapChannel((tMCA_DL) mdl_hnd);
2649 if ( lcid &&
2650 L2CA_GetCurrentConfig(lcid, &p_our_cfg, &our_cfg_bits, &p_peer_cfg,
2651 &peer_cfg_bits))
2652 {
2653 p_cfg->fcs = BTA_HL_MCA_NO_FCS;
2654 if (our_cfg_bits & L2CAP_CH_CFG_MASK_FCS)
2655 {
2656 p_cfg->fcs |= p_our_cfg->fcs;
2657 }
2658 else
2659 {
2660 p_cfg->fcs = BTA_HL_MCA_USE_FCS;
2661 }
2662
2663 if (p_cfg->fcs != BTA_HL_MCA_USE_FCS )
2664 {
2665 if (peer_cfg_bits & L2CAP_CH_CFG_MASK_FCS)
2666 {
2667 p_cfg->fcs |= p_peer_cfg->fcs;
2668 }
2669 else
2670 {
2671 p_cfg->fcs = BTA_HL_MCA_USE_FCS;
2672 }
2673 }
2674
2675 p_cfg->mtu =0;
2676 if (peer_cfg_bits & L2CAP_CH_CFG_MASK_MTU)
2677 {
2678 p_cfg->mtu = p_peer_cfg->mtu;
2679 }
2680 else
2681 {
2682 p_cfg->mtu = L2CAP_DEFAULT_MTU;
2683 }
Marie Janssene9e58ce2016-06-17 14:12:17 -07002684 success = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002685 }
Matthew Xiebea41312014-05-09 01:04:04 -07002686 else
2687 {
2688 p_cfg->mtu = L2CAP_DEFAULT_MTU;
2689 p_cfg->fcs = BTA_HL_L2C_NO_FCS;
2690 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002691
Marie Janssene9e58ce2016-06-17 14:12:17 -07002692#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002693 if (!success)
2694 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002695 APPL_TRACE_DEBUG("bta_hl_get_l2cap_cfg success=%d mdl=%d lcid=%d", success, mdl_hnd, lcid);
2696 APPL_TRACE_DEBUG("l2cap mtu=%d fcs=%d", p_cfg->mtu, p_cfg->fcs);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002697 }
2698#endif
2699
2700 return success;
2701}
2702
2703/*******************************************************************************
2704**
2705** Function bta_hl_validate_chan_cfg
2706**
2707** Description This function validates the L2CAP channel configuration
2708**
Marie Janssene9e58ce2016-06-17 14:12:17 -07002709** Returns bool - true - validation is successful
The Android Open Source Project5738f832012-12-12 16:00:35 -08002710*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002711bool bta_hl_validate_chan_cfg(uint8_t app_idx, uint8_t mcl_idx, uint8_t mdl_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002712{
2713 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
2714 tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
Marie Janssene9e58ce2016-06-17 14:12:17 -07002715 bool success = false;
2716 uint8_t mdl_cfg_idx = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002717 tBTA_HL_L2CAP_CFG_INFO l2cap_cfg;
Marie Janssene9e58ce2016-06-17 14:12:17 -07002718 bool get_l2cap_result, get_mdl_result;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002719
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002720 get_l2cap_result = bta_hl_get_l2cap_cfg(p_dcb->mdl_handle, &l2cap_cfg);
2721 get_mdl_result = bta_hl_find_mdl_cfg_idx(app_idx, mcl_idx, p_dcb->mdl_id, &mdl_cfg_idx);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002722
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002723 if (get_l2cap_result && get_mdl_result)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002724 {
2725 if ((p_acb->mdl_cfg[mdl_cfg_idx].mtu <= l2cap_cfg.mtu) &&
2726 (p_acb->mdl_cfg[mdl_cfg_idx].fcs == l2cap_cfg.fcs) &&
2727 (p_acb->mdl_cfg[mdl_cfg_idx].dch_mode == p_dcb->dch_mode))
2728 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07002729 success = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002730 }
2731 }
2732
2733
Marie Janssene9e58ce2016-06-17 14:12:17 -07002734#if (BTA_HL_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002735
2736 if (p_dcb->mtu != l2cap_cfg.mtu)
2737 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002738 APPL_TRACE_WARNING("MCAP and L2CAP peer mtu size out of sync from MCAP mtu=%d from l2cap mtu=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08002739 p_dcb->mtu, l2cap_cfg.mtu);
2740 }
2741
2742 if (!success)
2743 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002744 APPL_TRACE_DEBUG("bta_hl_validate_chan_cfg success=%d app_idx=%d mcl_idx=%d mdl_idx=%d",success, app_idx, mcl_idx, mdl_idx);
2745 APPL_TRACE_DEBUG("Cur. L2cap cfg mtu=%d fcs=%d dch_mode=%d", l2cap_cfg.mtu, l2cap_cfg.fcs, p_dcb->dch_mode);
2746 APPL_TRACE_DEBUG("From saved: L2cap cfg mtu=%d fcs=%d dch_mode=%d", p_acb->mdl_cfg[mdl_cfg_idx].mtu,
The Android Open Source Project5738f832012-12-12 16:00:35 -08002747 p_acb->mdl_cfg[mdl_cfg_idx].fcs , p_acb->mdl_cfg[mdl_cfg_idx].dch_mode);
2748 }
2749#endif
2750
2751 return success;
2752}
2753
2754
2755/*******************************************************************************
2756**
2757** Function bta_hl_is_cong_on
2758**
2759** Description This function checks whether the congestion condition is on or not
2760**
Marie Janssene9e58ce2016-06-17 14:12:17 -07002761** Returns bool - true DCH is congested
2762** false not congested
The Android Open Source Project5738f832012-12-12 16:00:35 -08002763**
2764*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002765bool bta_hl_is_cong_on(uint8_t app_id, BD_ADDR bd_addr, tBTA_HL_MDL_ID mdl_id)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002766
2767{
2768 tBTA_HL_MDL_CB *p_dcb;
Marie Janssene9e58ce2016-06-17 14:12:17 -07002769 uint8_t app_idx = 0, mcl_idx, mdl_idx;
2770 bool cong_status = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002771
2772 if (bta_hl_find_app_idx(app_id, &app_idx))
2773 {
2774 if (bta_hl_find_mcl_idx(app_idx, bd_addr, &mcl_idx ))
2775 {
2776 if (bta_hl_find_mdl_idx(app_idx, mcl_idx, mdl_id, &mdl_idx ))
2777 {
2778 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
2779 cong_status = p_dcb->cong;
2780 }
2781 }
2782 }
2783
2784 return cong_status;
2785}
2786
2787/*******************************************************************************
2788**
2789** Function bta_hl_check_cch_close
2790**
2791** Description This function checks whether there is a pending CCH close request
2792** or not
2793**
2794** Returns void
2795*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002796void bta_hl_check_cch_close(uint8_t app_idx, uint8_t mcl_idx, tBTA_HL_DATA *p_data, bool check_dch_setup )
The Android Open Source Project5738f832012-12-12 16:00:35 -08002797{
2798 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2799 tBTA_HL_MDL_CB *p_dcb;
Marie Janssene9e58ce2016-06-17 14:12:17 -07002800 uint8_t mdl_idx;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002801
2802#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002803 APPL_TRACE_DEBUG("bta_hl_check_cch_close cch_close_dch_oper=%d",p_mcb->cch_close_dch_oper );
The Android Open Source Project5738f832012-12-12 16:00:35 -08002804#endif
2805
2806 if (p_mcb->cch_oper == BTA_HL_CCH_OP_LOCAL_CLOSE)
2807 {
2808 if (check_dch_setup && bta_hl_find_dch_setup_mdl_idx(app_idx, mcl_idx, &mdl_idx))
2809 {
2810 p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
2811 if (!p_mcb->rsp_tout)
2812 {
2813 p_mcb->cch_close_dch_oper = BTA_HL_CCH_CLOSE_OP_DCH_ABORT;
2814
2815 if (!p_dcb->abort_oper)
2816 {
2817 p_dcb->abort_oper |= BTA_HL_ABORT_CCH_CLOSE_MASK;
2818 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_ABORT_EVT, p_data);
2819 }
2820 }
2821 else
2822 {
2823 p_mcb->cch_close_dch_oper = BTA_HL_CCH_CLOSE_OP_DCH_CLOSE;
2824 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_CMPL_EVT, p_data);
2825 }
2826 }
2827 else if (bta_hl_find_an_active_mdl_idx(app_idx, mcl_idx,&mdl_idx))
2828 {
2829 p_mcb->cch_close_dch_oper = BTA_HL_CCH_CLOSE_OP_DCH_CLOSE;
2830 bta_hl_dch_sm_execute(app_idx, mcl_idx, mdl_idx, BTA_HL_DCH_CLOSE_EVT, p_data);
2831 }
2832 else
2833 {
2834 p_mcb->cch_close_dch_oper = BTA_HL_CCH_CLOSE_OP_DCH_NONE;
2835 bta_hl_cch_sm_execute(app_idx, mcl_idx, BTA_HL_CCH_CLOSE_EVT, p_data);
2836 }
2837 }
2838}
2839
2840/*******************************************************************************
2841**
2842** Function bta_hl_clean_app
2843**
2844** Description Cleans up the HDP application resources and control block
2845**
2846** Returns void
2847**
2848*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002849void bta_hl_clean_app(uint8_t app_idx)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002850{
2851 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
2852 int i, num_act_apps=0;
2853
Marie Janssene9e58ce2016-06-17 14:12:17 -07002854#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002855 APPL_TRACE_DEBUG("bta_hl_clean_app");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002856#endif
2857 MCA_Deregister((tMCA_HANDLE)p_acb->app_handle);
2858
2859 if (p_acb->sdp_handle) SDP_DeleteRecord(p_acb->sdp_handle);
2860
2861 memset((void *) p_acb, 0, sizeof(tBTA_HL_APP_CB));
2862
2863 /* check any application is still active */
2864 for (i=0; i < BTA_HL_NUM_APPS ; i ++)
2865 {
2866 p_acb = BTA_HL_GET_APP_CB_PTR(i);
2867 if (p_acb->in_use) num_act_apps++;
2868 }
2869
2870 if (!num_act_apps)
2871 {
2872 bta_sys_remove_uuid(UUID_SERVCLASS_HDP_PROFILE);
2873 }
2874}
2875
2876/*******************************************************************************
2877**
2878** Function bta_hl_check_deregistration
2879**
2880** Description This function checks whether there is a pending deregistration
2881** request or not
2882**
2883** Returns void
2884*******************************************************************************/
Marie Janssene9e58ce2016-06-17 14:12:17 -07002885void bta_hl_check_deregistration(uint8_t app_idx, tBTA_HL_DATA *p_data )
The Android Open Source Project5738f832012-12-12 16:00:35 -08002886{
2887 tBTA_HL_APP_CB *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
2888 tBTA_HL_MCL_CB *p_mcb;
Marie Janssene9e58ce2016-06-17 14:12:17 -07002889 uint8_t mcl_idx;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002890 tBTA_HL evt_data;
2891
2892#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002893 APPL_TRACE_DEBUG("bta_hl_check_deregistration");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002894#endif
2895
2896 if (p_acb->deregistering)
2897 {
2898 if (bta_hl_find_an_in_use_mcl_idx(app_idx, &mcl_idx))
2899 {
2900 p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
2901 if (p_mcb->cch_oper != BTA_HL_CCH_OP_LOCAL_CLOSE)
2902 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002903 if (p_mcb->cch_state == BTA_HL_CCH_OPENING_ST)
Marie Janssene9e58ce2016-06-17 14:12:17 -07002904 p_mcb->force_close_local_cch_opening = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002905 p_mcb->cch_oper = BTA_HL_CCH_OP_LOCAL_CLOSE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002906 APPL_TRACE_DEBUG("p_mcb->force_close_local_cch_opening=%d", p_mcb->force_close_local_cch_opening );
Marie Janssene9e58ce2016-06-17 14:12:17 -07002907 bta_hl_check_cch_close(app_idx,mcl_idx,p_data, true);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002908 }
2909 }
2910 else
2911 {
2912 /* all cchs are closed */
2913 evt_data.dereg_cfm.app_handle = p_acb->app_handle;
Priti Agheraf8f30c22013-04-02 15:31:19 -07002914 evt_data.dereg_cfm.app_id = p_data->api_dereg.app_id;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002915 evt_data.dereg_cfm.status = BTA_HL_STATUS_OK;
2916 p_acb->p_cback(BTA_HL_DEREGISTER_CFM_EVT, (tBTA_HL *) &evt_data );
2917 bta_hl_clean_app(app_idx);
2918 bta_hl_check_disable(p_data);
2919 }
2920 }
2921}
2922
2923
2924/*******************************************************************************
2925**
2926** Function bta_hl_check_disable
2927**
2928** Description This function checks whether there is a pending disable
2929** request or not
2930**
2931** Returns void
2932**
2933*******************************************************************************/
2934void bta_hl_check_disable(tBTA_HL_DATA *p_data )
2935{
2936 tBTA_HL_CB *p_cb= &bta_hl_cb;
2937 tBTA_HL_APP_CB *p_acb;
Marie Janssene9e58ce2016-06-17 14:12:17 -07002938 uint8_t app_idx;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002939 tBTA_HL_CTRL evt_data;
2940
2941#if (BTA_HL_DEBUG == TRUE)
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002942 APPL_TRACE_DEBUG("bta_hl_check_disable");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002943#endif
2944
2945 if (bta_hl_cb.disabling)
2946 {
2947 if (bta_hl_find_an_in_use_app_idx(&app_idx))
2948 {
2949 p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
2950 if (!p_acb->deregistering)
2951 {
Marie Janssene9e58ce2016-06-17 14:12:17 -07002952 p_acb->deregistering = true;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002953 bta_hl_check_deregistration(app_idx, p_data);
2954 }
2955 }
2956 else
2957 {
2958 /* all apps are deregistered */
2959 bta_sys_deregister(BTA_ID_HL);
2960 evt_data.disable_cfm.status = BTA_HL_STATUS_OK;
2961 if (p_cb->p_ctrl_cback) p_cb->p_ctrl_cback(BTA_HL_CTRL_DISABLE_CFM_EVT, (tBTA_HL_CTRL *) &evt_data);
2962 memset((void *) p_cb, 0, sizeof(tBTA_HL_CB));
2963 }
2964 }
2965}
2966
2967/*******************************************************************************
2968**
2969** Function bta_hl_build_abort_cfm
2970**
2971** Description This function builds the abort confirmation event data
2972**
2973** Returns None
2974**
2975*******************************************************************************/
2976void bta_hl_build_abort_cfm(tBTA_HL *p_evt_data,
2977 tBTA_HL_APP_HANDLE app_handle,
2978 tBTA_HL_MCL_HANDLE mcl_handle,
2979 tBTA_HL_STATUS status)
2980{
2981 p_evt_data->dch_abort_cfm.status = status;
2982 p_evt_data->dch_abort_cfm.mcl_handle = mcl_handle;
2983 p_evt_data->dch_abort_cfm.app_handle = app_handle;
2984}
2985
2986/*******************************************************************************
2987**
2988** Function bta_hl_build_abort_ind
2989**
2990** Description This function builds the abort indication event data
2991**
2992** Returns None
2993**
2994*******************************************************************************/
2995void bta_hl_build_abort_ind(tBTA_HL *p_evt_data,
2996 tBTA_HL_APP_HANDLE app_handle,
2997 tBTA_HL_MCL_HANDLE mcl_handle)
2998{
2999 p_evt_data->dch_abort_ind.mcl_handle = mcl_handle;
3000 p_evt_data->dch_abort_ind.app_handle = app_handle;
3001}
3002/*******************************************************************************
3003**
3004** Function bta_hl_build_close_cfm
3005**
3006** Description This function builds the close confirmation event data
3007**
3008** Returns None
3009**
3010*******************************************************************************/
3011void bta_hl_build_dch_close_cfm(tBTA_HL *p_evt_data,
3012 tBTA_HL_APP_HANDLE app_handle,
3013 tBTA_HL_MCL_HANDLE mcl_handle,
3014 tBTA_HL_MDL_HANDLE mdl_handle,
3015 tBTA_HL_STATUS status)
3016{
3017 p_evt_data->dch_close_cfm.status = status;
3018 p_evt_data->dch_close_cfm.mdl_handle = mdl_handle;
3019 p_evt_data->dch_close_cfm.mcl_handle = mcl_handle;
3020 p_evt_data->dch_close_cfm.app_handle = app_handle;
3021}
3022
3023/*******************************************************************************
3024**
3025** Function bta_hl_build_dch_close_ind
3026**
3027** Description This function builds the close indication event data
3028**
3029** Returns None
3030**
3031*******************************************************************************/
3032void bta_hl_build_dch_close_ind(tBTA_HL *p_evt_data,
3033 tBTA_HL_APP_HANDLE app_handle,
3034 tBTA_HL_MCL_HANDLE mcl_handle,
3035 tBTA_HL_MDL_HANDLE mdl_handle,
Marie Janssene9e58ce2016-06-17 14:12:17 -07003036 bool intentional)
The Android Open Source Project5738f832012-12-12 16:00:35 -08003037{
3038 p_evt_data->dch_close_ind.mdl_handle = mdl_handle;
3039 p_evt_data->dch_close_ind.mcl_handle = mcl_handle;
3040 p_evt_data->dch_close_ind.app_handle = app_handle;
3041 p_evt_data->dch_close_ind.intentional = intentional;
3042}
3043
3044/*******************************************************************************
3045**
3046** Function bta_hl_build_send_data_cfm
3047**
3048** Description This function builds the send data confirmation event data
3049**
3050** Returns None
3051**
3052*******************************************************************************/
3053void bta_hl_build_send_data_cfm(tBTA_HL *p_evt_data,
3054 tBTA_HL_APP_HANDLE app_handle,
3055 tBTA_HL_MCL_HANDLE mcl_handle,
3056 tBTA_HL_MDL_HANDLE mdl_handle,
3057 tBTA_HL_STATUS status )
3058{
3059
3060 p_evt_data->dch_send_data_cfm.mdl_handle = mdl_handle;
3061 p_evt_data->dch_send_data_cfm.mcl_handle = mcl_handle;
3062 p_evt_data->dch_send_data_cfm.app_handle = app_handle;
3063 p_evt_data->dch_send_data_cfm.status = status;
3064}
3065
3066/*******************************************************************************
3067**
3068** Function bta_hl_build_rcv_data_ind
3069**
3070** Description This function builds the received data indication event data
3071**
3072** Returns None
3073**
3074*******************************************************************************/
3075void bta_hl_build_rcv_data_ind(tBTA_HL *p_evt_data,
3076 tBTA_HL_APP_HANDLE app_handle,
3077 tBTA_HL_MCL_HANDLE mcl_handle,
3078 tBTA_HL_MDL_HANDLE mdl_handle)
3079{
3080 p_evt_data->dch_rcv_data_ind.mdl_handle = mdl_handle;
3081 p_evt_data->dch_rcv_data_ind.mcl_handle = mcl_handle;
3082 p_evt_data->dch_rcv_data_ind.app_handle = app_handle;
3083}
3084
3085
3086/*******************************************************************************
3087**
3088** Function bta_hl_build_cch_open_cfm
3089**
3090** Description This function builds the CCH open confirmation event data
3091**
3092** Returns None
3093**
3094*******************************************************************************/
3095void bta_hl_build_cch_open_cfm(tBTA_HL *p_evt_data,
Marie Janssene9e58ce2016-06-17 14:12:17 -07003096 uint8_t app_id,
The Android Open Source Project5738f832012-12-12 16:00:35 -08003097 tBTA_HL_APP_HANDLE app_handle,
3098 tBTA_HL_MCL_HANDLE mcl_handle,
3099 BD_ADDR bd_addr,
3100 tBTA_HL_STATUS status )
3101{
Priti Agheraf8f30c22013-04-02 15:31:19 -07003102 p_evt_data->cch_open_cfm.app_id = app_id;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003103 p_evt_data->cch_open_cfm.app_handle = app_handle;
3104 p_evt_data->cch_open_cfm.mcl_handle = mcl_handle;
3105 bdcpy(p_evt_data->cch_open_cfm.bd_addr, bd_addr);
3106 p_evt_data->cch_open_cfm.status = status;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003107 APPL_TRACE_DEBUG("bta_hl_build_cch_open_cfm: status=%d",status);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003108}
3109
3110/*******************************************************************************
3111**
3112** Function bta_hl_build_cch_open_ind
3113**
3114** Description This function builds the CCH open indication event data
3115**
3116** Returns None
3117**
3118*******************************************************************************/
3119void bta_hl_build_cch_open_ind(tBTA_HL *p_evt_data, tBTA_HL_APP_HANDLE app_handle,
3120 tBTA_HL_MCL_HANDLE mcl_handle,
3121 BD_ADDR bd_addr )
3122{
3123
3124 p_evt_data->cch_open_ind.app_handle = app_handle;
3125 p_evt_data->cch_open_ind.mcl_handle = mcl_handle;
3126 bdcpy(p_evt_data->cch_open_ind.bd_addr, bd_addr);
3127}
3128
3129/*******************************************************************************
3130**
3131** Function bta_hl_build_cch_close_cfm
3132**
3133** Description This function builds the CCH close confirmation event data
3134**
3135** Returns None
3136**
3137*******************************************************************************/
3138void bta_hl_build_cch_close_cfm(tBTA_HL *p_evt_data,
3139 tBTA_HL_APP_HANDLE app_handle,
3140 tBTA_HL_MCL_HANDLE mcl_handle,
3141 tBTA_HL_STATUS status )
3142{
3143 p_evt_data->cch_close_cfm.mcl_handle = mcl_handle;
3144 p_evt_data->cch_close_cfm.app_handle = app_handle;
3145 p_evt_data->cch_close_cfm.status = status;
3146}
3147
3148
3149/*******************************************************************************
3150**
3151** Function bta_hl_build_cch_close_ind
3152**
3153** Description This function builds the CCH colse indication event data
3154**
3155** Returns None
3156**
3157*******************************************************************************/
3158void bta_hl_build_cch_close_ind(tBTA_HL *p_evt_data,
3159 tBTA_HL_APP_HANDLE app_handle,
3160 tBTA_HL_MCL_HANDLE mcl_handle,
Marie Janssene9e58ce2016-06-17 14:12:17 -07003161 bool intentional)
The Android Open Source Project5738f832012-12-12 16:00:35 -08003162{
3163 p_evt_data->cch_close_ind.mcl_handle = mcl_handle;
3164 p_evt_data->cch_close_ind.app_handle = app_handle;
3165 p_evt_data->cch_close_ind.intentional = intentional;
3166}
3167
3168/*******************************************************************************
3169**
3170** Function bta_hl_build_dch_open_cfm
3171**
3172** Description This function builds the DCH open confirmation event data
3173**
3174** Returns None
3175**
3176*******************************************************************************/
3177void bta_hl_build_dch_open_cfm(tBTA_HL *p_evt_data,
3178 tBTA_HL_APP_HANDLE app_handle,
3179 tBTA_HL_MCL_HANDLE mcl_handle,
3180 tBTA_HL_MDL_HANDLE mdl_handle,
3181 tBTA_HL_MDEP_ID local_mdep_id,
3182 tBTA_HL_MDL_ID mdl_id,
3183 tBTA_HL_DCH_MODE dch_mode,
Marie Janssene9e58ce2016-06-17 14:12:17 -07003184 bool first_reliable,
3185 uint16_t mtu,
The Android Open Source Project5738f832012-12-12 16:00:35 -08003186 tBTA_HL_STATUS status)
3187
3188{
3189 p_evt_data->dch_open_cfm.mdl_handle = mdl_handle;
3190 p_evt_data->dch_open_cfm.mcl_handle = mcl_handle;
3191 p_evt_data->dch_open_cfm.app_handle = app_handle;
3192 p_evt_data->dch_open_cfm.local_mdep_id = local_mdep_id;
3193 p_evt_data->dch_open_cfm.mdl_id = mdl_id;
3194 p_evt_data->dch_open_cfm.dch_mode = dch_mode;
3195 p_evt_data->dch_open_cfm.first_reliable = first_reliable;
3196 p_evt_data->dch_open_cfm.mtu = mtu;
3197 p_evt_data->dch_open_cfm.status = status;
3198}
3199
3200
3201/*******************************************************************************
3202**
3203** Function bta_hl_build_sdp_query_cfm
3204**
3205** Description This function builds the SDP query indication event data
3206**
3207** Returns None
3208**
3209*******************************************************************************/
3210void bta_hl_build_sdp_query_cfm(tBTA_HL *p_evt_data,
Marie Janssene9e58ce2016-06-17 14:12:17 -07003211 uint8_t app_id,
The Android Open Source Project5738f832012-12-12 16:00:35 -08003212 tBTA_HL_APP_HANDLE app_handle,
3213 BD_ADDR bd_addr,
3214 tBTA_HL_SDP *p_sdp,
3215 tBTA_HL_STATUS status)
3216
3217{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003218 APPL_TRACE_DEBUG("bta_hl_build_sdp_query_cfm: app_id = %d, app_handle=%d",
Priti Agheraf8f30c22013-04-02 15:31:19 -07003219 app_id,app_handle);
3220 p_evt_data->sdp_query_cfm.app_id = app_id;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003221 p_evt_data->sdp_query_cfm.app_handle = app_handle;
3222 bdcpy(p_evt_data->sdp_query_cfm.bd_addr, bd_addr);
3223 p_evt_data->sdp_query_cfm.p_sdp = p_sdp;
3224 p_evt_data->sdp_query_cfm.status = status;
3225}
3226
3227
3228/*******************************************************************************
3229**
3230** Function bta_hl_build_delete_mdl_cfm
3231**
3232** Description This function builds the delete MDL confirmation event data
3233**
3234** Returns None
3235**
3236*******************************************************************************/
3237void bta_hl_build_delete_mdl_cfm(tBTA_HL *p_evt_data,
3238 tBTA_HL_APP_HANDLE app_handle,
3239 tBTA_HL_MCL_HANDLE mcl_handle,
3240 tBTA_HL_MDL_ID mdl_id,
3241 tBTA_HL_STATUS status)
3242
3243{
3244 p_evt_data->delete_mdl_cfm.mcl_handle = mcl_handle;
3245 p_evt_data->delete_mdl_cfm.app_handle = app_handle;
3246 p_evt_data->delete_mdl_cfm.mdl_id = mdl_id;
3247 p_evt_data->delete_mdl_cfm.status = status;
3248}
3249
3250/*******************************************************************************
3251**
3252** Function bta_hl_build_echo_test_cfm
3253**
3254** Description This function builds the echo test confirmation event data
3255**
3256** Returns None
3257**
3258*******************************************************************************/
3259void bta_hl_build_echo_test_cfm(tBTA_HL *p_evt_data,
3260 tBTA_HL_APP_HANDLE app_handle,
3261 tBTA_HL_MCL_HANDLE mcl_handle,
3262 tBTA_HL_STATUS status )
3263{
3264 p_evt_data->echo_test_cfm.mcl_handle = mcl_handle;
3265 p_evt_data->echo_test_cfm.app_handle = app_handle;
3266 p_evt_data->echo_test_cfm.status = status;
3267}
3268
3269
3270/*****************************************************************************
3271** Debug Functions
3272*****************************************************************************/
3273#if (BTA_HL_DEBUG == TRUE)
3274
3275/*******************************************************************************
3276**
3277** Function bta_hl_status_code
3278**
3279** Description get the status string pointer
3280**
3281** Returns char * - status string pointer
3282**
3283*******************************************************************************/
3284char *bta_hl_status_code(tBTA_HL_STATUS status)
3285{
3286 switch (status)
3287 {
3288 case BTA_HL_STATUS_OK:
3289 return "BTA_HL_STATUS_OK";
3290 case BTA_HL_STATUS_FAIL:
3291 return "BTA_HL_STATUS_FAIL";
3292 case BTA_HL_STATUS_ABORTED:
3293 return "BTA_HL_STATUS_ABORTED";
3294 case BTA_HL_STATUS_NO_RESOURCE:
3295 return "BTA_HL_STATUS_NO_RESOURCE";
3296 case BTA_HL_STATUS_LAST_ITEM:
3297 return "BTA_HL_STATUS_LAST_ITEM";
3298 case BTA_HL_STATUS_DUPLICATE_APP_ID:
3299 return "BTA_HL_STATUS_DUPLICATE_APP_ID";
3300 case BTA_HL_STATUS_INVALID_APP_HANDLE:
3301 return "BTA_HL_STATUS_INVALID_APP_HANDLE";
3302 case BTA_HL_STATUS_INVALID_MCL_HANDLE:
3303 return "BTA_HL_STATUS_INVALID_MCL_HANDLE";
3304 case BTA_HL_STATUS_MCAP_REG_FAIL:
3305 return "BTA_HL_STATUS_MCAP_REG_FAIL";
3306 case BTA_HL_STATUS_MDEP_CO_FAIL:
3307 return "BTA_HL_STATUS_MDEP_CO_FAIL";
3308 case BTA_HL_STATUS_ECHO_CO_FAIL:
3309 return "BTA_HL_STATUS_ECHO_CO_FAIL";
3310 case BTA_HL_STATUS_MDL_CFG_CO_FAIL:
3311 return "BTA_HL_STATUS_MDL_CFG_CO_FAIL";
3312 case BTA_HL_STATUS_SDP_NO_RESOURCE:
3313 return "BTA_HL_STATUS_SDP_NO_RESOURCE";
3314 case BTA_HL_STATUS_SDP_FAIL:
3315 return "BTA_HL_STATUS_SDP_FAIL";
3316 case BTA_HL_STATUS_NO_CCH:
3317 return "BTA_HL_STATUS_NO_CCH";
3318 case BTA_HL_STATUS_NO_MCL:
3319 return "BTA_HL_STATUS_NO_MCL";
3320
3321 case BTA_HL_STATUS_NO_FIRST_RELIABLE:
3322 return "BTA_HL_STATUS_NO_FIRST_RELIABLE";
3323 case BTA_HL_STATUS_INVALID_DCH_CFG:
3324 return "BTA_HL_STATUS_INVALID_DCH_CFG";
3325 case BTA_HL_STATUS_INVALID_BD_ADDR:
3326 return "BTA_HL_STATUS_INVALID_BD_ADDR";
3327 case BTA_HL_STATUS_INVALID_RECONNECT_CFG:
3328 return "BTA_HL_STATUS_INVALID_RECONNECT_CFG";
3329 case BTA_HL_STATUS_ECHO_TEST_BUSY:
3330 return "BTA_HL_STATUS_ECHO_TEST_BUSY";
3331 case BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID:
3332 return "BTA_HL_STATUS_INVALID_LOCAL_MDEP_ID";
3333 case BTA_HL_STATUS_INVALID_MDL_ID:
3334 return "BTA_HL_STATUS_INVALID_MDL_ID";
3335 case BTA_HL_STATUS_NO_MDL_ID_FOUND:
3336 return "BTA_HL_STATUS_NO_MDL_ID_FOUND";
3337 case BTA_HL_STATUS_DCH_BUSY:
3338 return "BTA_HL_STATUS_DCH_BUSY";
3339 default:
3340 return "Unknown status code";
3341 }
3342}
3343/*******************************************************************************
3344**
3345** Function bta_hl_evt_code
3346**
3347** Description Maps HL event code to the corresponding event string
3348**
3349** Returns string pointer for the associated event name
3350**
3351*******************************************************************************/
3352char *bta_hl_evt_code(tBTA_HL_INT_EVT evt_code)
3353{
3354 switch (evt_code)
3355 {
3356 case BTA_HL_CCH_OPEN_EVT:
3357 return "BTA_HL_CCH_OPEN_EVT";
3358 case BTA_HL_CCH_SDP_OK_EVT:
3359 return "BTA_HL_CCH_SDP_OK_EVT";
3360 case BTA_HL_CCH_SDP_FAIL_EVT:
3361 return "BTA_HL_CCH_SDP_FAIL_EVT";
3362 case BTA_HL_MCA_CONNECT_IND_EVT:
3363 return "BTA_HL_MCA_CONNECT_IND_EVT";
3364 case BTA_HL_MCA_DISCONNECT_IND_EVT:
3365 return "BTA_HL_MCA_DISCONNECT_IND_EVT";
3366
3367 case BTA_HL_CCH_CLOSE_EVT:
3368 return "BTA_HL_CCH_CLOSE_EVT";
3369 case BTA_HL_CCH_CLOSE_CMPL_EVT:
3370 return "BTA_HL_CCH_CLOSE_CMPL_EVT";
3371 case BTA_HL_DCH_OPEN_EVT:
3372 return "BTA_HL_DCH_OPEN_EVT";
3373 case BTA_HL_MCA_CREATE_IND_EVT:
3374 return "BTA_HL_MCA_CREATE_IND_EVT";
3375 case BTA_HL_MCA_CREATE_CFM_EVT:
3376 return "BTA_HL_MCA_CREATE_CFM_EVT";
3377 case BTA_HL_MCA_OPEN_IND_EVT:
3378 return "BTA_HL_MCA_OPEN_IND_EVT";
3379 case BTA_HL_MCA_OPEN_CFM_EVT:
3380 return "BTA_HL_MCA_OPEN_CFM_EVT";
3381 case BTA_HL_DCH_CLOSE_EVT:
3382 return "BTA_HL_DCH_CLOSE_EVT";
3383 case BTA_HL_MCA_CLOSE_IND_EVT:
3384 return "BTA_HL_MCA_CLOSE_IND_EVT";
3385 case BTA_HL_MCA_CLOSE_CFM_EVT:
3386 return "BTA_HL_MCA_CLOSE_CFM_EVT";
3387 case BTA_HL_API_SEND_DATA_EVT:
3388 return "BTA_HL_API_SEND_DATA_EVT";
3389 case BTA_HL_MCA_RCV_DATA_EVT:
3390 return "BTA_HL_MCA_RCV_DATA_EVT";
3391 case BTA_HL_DCH_CLOSE_CMPL_EVT:
3392 return "BTA_HL_DCH_CLOSE_CMPL_EVT";
3393
3394 case BTA_HL_API_ENABLE_EVT:
3395 return "BTA_HL_API_ENABLE_EVT";
3396 case BTA_HL_API_DISABLE_EVT:
3397 return "BTA_HL_API_DISABLE_EVT";
Priti Agheraf8f30c22013-04-02 15:31:19 -07003398 case BTA_HL_API_UPDATE_EVT:
3399 return "BTA_HL_API_UPDATE_EVT";
The Android Open Source Project5738f832012-12-12 16:00:35 -08003400 case BTA_HL_API_REGISTER_EVT:
3401 return "BTA_HL_API_REGISTER_EVT";
3402 case BTA_HL_API_DEREGISTER_EVT:
3403 return "BTA_HL_API_DEREGISTER_EVT";
3404
3405 case BTA_HL_API_CCH_OPEN_EVT:
3406 return "BTA_HL_API_CCH_OPEN_EVT";
3407
3408 case BTA_HL_API_CCH_CLOSE_EVT:
3409 return "BTA_HL_API_CCH_CLOSE_EVT";
3410 case BTA_HL_API_DCH_OPEN_EVT:
3411 return "BTA_HL_API_DCH_OPEN_EVT";
3412
3413 case BTA_HL_API_DCH_RECONNECT_EVT:
3414 return "BTA_HL_API_DCH_RECONNECT_EVT";
3415 case BTA_HL_API_DCH_CLOSE_EVT:
3416 return "BTA_HL_API_DCH_CLOSE_EVT";
3417 case BTA_HL_API_DELETE_MDL_EVT:
3418 return "BTA_HL_API_DELETE_MDL_EVT";
3419 case BTA_HL_API_DCH_ABORT_EVT:
3420 return "BTA_HL_API_DCH_ABORT_EVT";
3421
3422 case BTA_HL_DCH_RECONNECT_EVT:
3423 return "BTA_HL_DCH_RECONNECT_EVT";
3424 case BTA_HL_DCH_SDP_INIT_EVT:
3425 return "BTA_HL_DCH_SDP_INIT_EVT";
3426 case BTA_HL_DCH_SDP_FAIL_EVT:
3427 return "BTA_HL_DCH_SDP_FAIL_EVT";
3428 case BTA_HL_API_DCH_ECHO_TEST_EVT:
3429 return "BTA_HL_API_DCH_ECHO_TEST_EVT";
3430 case BTA_HL_DCH_CLOSE_ECHO_TEST_EVT:
3431 return "BTA_HL_DCH_CLOSE_ECHO_TEST_EVT";
3432 case BTA_HL_MCA_RECONNECT_IND_EVT:
3433 return "BTA_HL_MCA_RECONNECT_IND_EVT";
3434 case BTA_HL_MCA_RECONNECT_CFM_EVT:
3435 return "BTA_HL_MCA_RECONNECT_CFM_EVT";
3436 case BTA_HL_API_DCH_CREATE_RSP_EVT:
3437 return "BTA_HL_API_DCH_CREATE_RSP_EVT";
3438 case BTA_HL_DCH_ABORT_EVT:
3439 return "BTA_HL_DCH_ABORT_EVT";
3440 case BTA_HL_MCA_ABORT_IND_EVT:
3441 return "BTA_HL_MCA_ABORT_IND_EVT";
3442 case BTA_HL_MCA_ABORT_CFM_EVT:
3443 return "BTA_HL_MCA_ABORT_CFM_EVT";
3444 case BTA_HL_MCA_DELETE_IND_EVT:
3445 return "BTA_HL_MCA_DELETE_IND_EVT";
3446 case BTA_HL_MCA_DELETE_CFM_EVT:
3447 return "BTA_HL_MCA_DELETE_CFM_EVT";
3448 case BTA_HL_MCA_CONG_CHG_EVT:
3449 return "BTA_HL_MCA_CONG_CHG_EVT";
3450 case BTA_HL_CI_GET_TX_DATA_EVT:
3451 return "BTA_HL_CI_GET_TX_DATA_EVT";
3452 case BTA_HL_CI_PUT_RX_DATA_EVT:
3453 return "BTA_HL_CI_PUT_RX_DATA_EVT";
3454 case BTA_HL_CI_GET_ECHO_DATA_EVT:
3455 return "BTA_HL_CI_GET_ECHO_DATA_EVT";
3456 case BTA_HL_DCH_ECHO_TEST_EVT:
3457 return "BTA_HL_DCH_ECHO_TEST_EVT";
3458 case BTA_HL_CI_PUT_ECHO_DATA_EVT:
3459 return "BTA_HL_CI_PUT_ECHO_DATA_EVT";
3460 case BTA_HL_API_SDP_QUERY_EVT:
3461 return "BTA_HL_API_SDP_QUERY_EVT";
3462 case BTA_HL_SDP_QUERY_OK_EVT:
3463 return "BTA_HL_SDP_QUERY_OK_EVT";
3464 case BTA_HL_SDP_QUERY_FAIL_EVT:
3465 return "BTA_HL_SDP_QUERY_FAIL_EVT";
3466 case BTA_HL_MCA_RSP_TOUT_IND_EVT:
3467 return "BTA_HL_MCA_RSP_TOUT_IND_EVT";
3468
3469 default:
3470 return "Unknown HL event code";
3471 }
3472}
3473
3474#endif /* Debug Functions */
3475#endif // HL_INCLUDED
3476
3477
3478
3479
3480
3481
3482
3483