1 /******************************************************************************
3 * Copyright (C) 2009-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This is the implementation file for the HeaLth device profile (HL)
22 * subsystem call-out functions.
24 ******************************************************************************/
32 #include <sys/socket.h>
33 #include <sys/types.h>
38 #include "bta_hl_api.h"
39 #include "bta_hl_ci.h"
40 #include "bta_hl_co.h"
43 #include "btif_util.h"
46 /*****************************************************************************
47 ** Constants and Data Types
48 *****************************************************************************/
49 /**************************
51 ***************************/
56 /*******************************************************************************
58 ** Function bta_hl_co_get_num_of_mdep
60 ** Description This function is called to get the number of MDEPs for this
63 ** Parameters app_id - application ID
64 ** p_num_of_mdep (output) - number of MDEP configurations supported
67 ** Returns Bloolean - TRUE success
69 *******************************************************************************/
70 BOOLEAN bta_hl_co_get_num_of_mdep(UINT8 app_id, UINT8 *p_num_of_mdep)
73 BOOLEAN success = FALSE;
75 if (btif_hl_find_app_idx(app_id, &app_idx))
77 *p_num_of_mdep = p_btif_hl_cb->acb[app_idx].sup_feature.num_of_mdeps;
82 BTIF_TRACE_DEBUG("%s success=%d num_mdeps=%d",
83 __FUNCTION__, success, *p_num_of_mdep );
87 /*******************************************************************************
89 ** Function bta_hl_co_advrtise_source_sdp
91 ** Description This function is called to find out whether the SOURCE MDEP
92 ** configuration information should be advertize in the SDP or nopt
94 ** Parameters app_id - application ID
96 ** Returns Bloolean - TRUE advertise the SOURCE MDEP configuration
99 *******************************************************************************/
100 BOOLEAN bta_hl_co_advrtise_source_sdp(UINT8 app_id)
102 BOOLEAN advertize_source_sdp=FALSE;
105 if (btif_hl_find_app_idx(app_id, &app_idx))
107 advertize_source_sdp = p_btif_hl_cb->acb[app_idx].sup_feature.advertize_source_sdp;
111 BTIF_TRACE_DEBUG("%s advertize_flag=%d", __FUNCTION__, advertize_source_sdp );
113 return advertize_source_sdp;
115 /*******************************************************************************
117 ** Function bta_hl_co_get_mdep_config
119 ** Description This function is called to get the supported feature
120 ** configuration for the specified mdep index and it also assigns
121 ** the MDEP ID for the specified mdep index
123 ** Parameters app_id - HDP application ID
124 ** mdep_idx - the mdep index
125 ** mdep_counter - number of mdeps
126 ** mdep_id - the assigned MDEP ID for the specified medp_idx
127 ** p_mdl_cfg (output) - pointer to the MDEP configuration
130 ** Returns Bloolean - TRUE success
131 *******************************************************************************/
132 BOOLEAN bta_hl_co_get_mdep_config(UINT8 app_id,
135 tBTA_HL_MDEP_ID mdep_id,
136 tBTA_HL_MDEP_CFG *p_mdep_cfg)
140 BOOLEAN success = FALSE;
142 BTIF_TRACE_DEBUG("%s app_id=%d mdep_idx=%d mdep_id=%d mdep_counter=%d",
143 __FUNCTION__, app_id,mdep_idx,mdep_id,mdep_counter);
145 if (btif_hl_find_app_idx(app_id, &app_idx))
147 idx = mdep_idx -mdep_counter-1;
148 p_btif_hl_cb->acb[app_idx].sup_feature.mdep[idx].mdep_id = mdep_id;
150 &p_btif_hl_cb->acb[app_idx].sup_feature.mdep[idx].mdep_cfg,
151 sizeof(tBTA_HL_MDEP_CFG));
156 BTIF_TRACE_DEBUG("%s success=%d mdep_idx=%d mdep_id=%d",
157 __FUNCTION__, success, mdep_idx, mdep_id );
163 /*******************************************************************************
165 ** Function bta_hl_co_get_echo_config
167 ** Description This function is called to get the echo test
168 ** maximum APDU size configurations
170 ** Parameters app_id - HDP application ID
171 ** p_echo_cfg (output) - pointer to the Echo test maximum APDU size
174 ** Returns Bloolean - TRUE success
175 *******************************************************************************/
176 BOOLEAN bta_hl_co_get_echo_config(UINT8 app_id,
177 tBTA_HL_ECHO_CFG *p_echo_cfg)
180 BOOLEAN success = FALSE;
181 btif_hl_app_cb_t *p_acb;
182 tBTA_HL_SUP_FEATURE *p_sup;
184 BTIF_TRACE_DEBUG("%s app_id=%d",__FUNCTION__, app_id );
186 if (btif_hl_find_app_idx(app_id, &app_idx))
188 p_acb = BTIF_HL_GET_APP_CB_PTR(app_idx);
189 p_sup = &p_acb->sup_feature;
190 p_echo_cfg->max_rx_apdu_size = p_sup->echo_cfg.max_rx_apdu_size;
191 p_echo_cfg->max_tx_apdu_size = p_sup->echo_cfg.max_tx_apdu_size;
195 BTIF_TRACE_DEBUG("%s success=%d max tx_size=%d rx_size=%d",
196 __FUNCTION__, success, p_echo_cfg->max_tx_apdu_size,
197 p_echo_cfg->max_rx_apdu_size );
203 /*******************************************************************************
205 ** Function bta_hl_co_save_mdl
207 ** Description This function is called to save a MDL configuration item in persistent
210 ** Parameters app_id - HDP application ID
211 ** item_idx - the MDL configuration storage index
212 ** p_mdl_cfg - pointer to the MDL configuration data
216 *******************************************************************************/
217 void bta_hl_co_save_mdl(UINT8 mdep_id, UINT8 item_idx, tBTA_HL_MDL_CFG *p_mdl_cfg )
220 BTIF_TRACE_DEBUG("%s mdep_id =%d, item_idx=%d active=%d mdl_id=%d time=%d",
221 __FUNCTION__, mdep_id, item_idx,
226 btif_hl_save_mdl_cfg(mdep_id, item_idx, p_mdl_cfg);
230 /*******************************************************************************
232 ** Function bta_hl_co_delete_mdl
234 ** Description This function is called to delete a MDL configuration item in persistent
237 ** Parameters app_id - HDP application ID
238 ** item_idx - the MDL configuration storage index
242 *******************************************************************************/
243 void bta_hl_co_delete_mdl(UINT8 mdep_id, UINT8 item_idx)
247 BTIF_TRACE_DEBUG("%s mdep_id=%d, item_idx=%d", __FUNCTION__, mdep_id, item_idx);
249 btif_hl_delete_mdl_cfg(mdep_id, item_idx);
254 /*******************************************************************************
256 ** Function bta_hl_co_get_mdl_config
258 ** Description This function is called to get the MDL configuration
259 ** from the persistent memory. This function shall only be called
260 *8 once after the device is powered up
262 ** Parameters app_id - HDP application ID
263 ** buffer_size - the unit of the buffer size is sizeof(tBTA_HL_MDL_CFG)
264 ** p_mdl_buf - Point to the starting location of the buffer
269 *******************************************************************************/
270 BOOLEAN bta_hl_co_load_mdl_config (UINT8 app_id, UINT8 buffer_size,
271 tBTA_HL_MDL_CFG *p_mdl_buf )
273 BOOLEAN result = TRUE;
277 BTIF_TRACE_DEBUG("%s app_id=%d, num_items=%d",
278 __FUNCTION__, app_id, buffer_size);
280 if (buffer_size > BTA_HL_NUM_MDL_CFGS)
285 result = btif_hl_load_mdl_config(app_id, buffer_size, p_mdl_buf);
289 for (i=0, p=p_mdl_buf; i<buffer_size; i++, p++ )
293 BTIF_TRACE_DEBUG("i=%d mdl_id=0x%x dch_mode=%d local mdep_role=%d mdep_id=%d mtu=%d",
294 i, p->mdl_id, p->dch_mode, p->local_mdep_role, p->local_mdep_role, p->mtu);
299 BTIF_TRACE_DEBUG("%s success=%d num_items=%d", __FUNCTION__, result, buffer_size);
304 /*******************************************************************************
306 ** Function bta_hl_co_get_tx_data
308 ** Description Get the data to be sent
310 ** Parameters app_id - HDP application ID
311 ** mdl_handle - MDL handle
312 ** buf_size - the size of the buffer
313 ** p_buf - the buffer pointer
314 ** evt - the evt to be passed back to the HL in the
315 ** bta_hl_ci_get_tx_data call-in function
319 *******************************************************************************/
320 void bta_hl_co_get_tx_data (UINT8 app_id, tBTA_HL_MDL_HANDLE mdl_handle,
321 UINT16 buf_size, UINT8 *p_buf, UINT16 evt)
323 UINT8 app_idx, mcl_idx, mdl_idx;
324 btif_hl_mdl_cb_t *p_dcb;
325 tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL;
327 BTIF_TRACE_DEBUG("%s app_id=%d mdl_handle=0x%x buf_size=%d",
328 __FUNCTION__, app_id, mdl_handle, buf_size);
330 if (btif_hl_find_mdl_idx_using_handle(mdl_handle, &app_idx, &mcl_idx, &mdl_idx))
332 p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
334 if (p_dcb->tx_size <= buf_size )
336 memcpy(p_buf, p_dcb->p_tx_pkt, p_dcb->tx_size);
337 btif_hl_free_buf((void **) &p_dcb->p_tx_pkt);
339 status = BTA_HL_STATUS_OK;
344 bta_hl_ci_get_tx_data(mdl_handle, status, evt);
349 /*******************************************************************************
351 ** Function bta_hl_co_put_rx_data
353 ** Description Put the received data
355 ** Parameters app_id - HDP application ID
356 ** mdl_handle - MDL handle
357 ** data_size - the size of the data
358 ** p_data - the data pointer
359 ** evt - the evt to be passed back to the HL in the
360 ** bta_hl_ci_put_rx_data call-in function
364 *******************************************************************************/
365 void bta_hl_co_put_rx_data (UINT8 app_id, tBTA_HL_MDL_HANDLE mdl_handle,
366 UINT16 data_size, UINT8 *p_data, UINT16 evt)
368 UINT8 app_idx, mcl_idx, mdl_idx;
369 btif_hl_mdl_cb_t *p_dcb;
370 tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL;
372 BTIF_TRACE_DEBUG("%s app_id=%d mdl_handle=0x%x data_size=%d",
373 __FUNCTION__,app_id, mdl_handle, data_size);
375 if (btif_hl_find_mdl_idx_using_handle(mdl_handle, &app_idx, &mcl_idx, &mdl_idx))
377 p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
379 if ((p_dcb->p_rx_pkt = (UINT8 *)btif_hl_get_buf(data_size)) != NULL)
381 memcpy(p_dcb->p_rx_pkt, p_data, data_size);
384 BTIF_TRACE_DEBUG("app_idx=%d mcl_idx=0x%x mdl_idx=0x%x data_size=%d",
385 app_idx, mcl_idx, mdl_idx, data_size);
386 r = send(p_dcb->p_scb->socket_id[1], p_dcb->p_rx_pkt, data_size, 0);
390 BTIF_TRACE_DEBUG("socket send success data_size=%d", data_size);
391 status = BTA_HL_STATUS_OK;
395 BTIF_TRACE_ERROR("socket send failed r=%d data_size=%d",r, data_size);
400 btif_hl_free_buf((void **) &p_dcb->p_rx_pkt);
404 bta_hl_ci_put_rx_data(mdl_handle, status, evt);
408 /*******************************************************************************
410 ** Function bta_hl_co_get_tx_data
412 ** Description Get the Echo data to be sent
414 ** Parameters app_id - HDP application ID
415 ** mcl_handle - MCL handle
416 ** buf_size - the size of the buffer
417 ** p_buf - the buffer pointer
418 ** evt - the evt to be passed back to the HL in the
419 ** bta_hl_ci_get_tx_data call-in function
423 *******************************************************************************/
424 void bta_hl_co_get_echo_data (UINT8 app_id, tBTA_HL_MCL_HANDLE mcl_handle,
425 UINT16 buf_size, UINT8 *p_buf, UINT16 evt)
427 tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL;
432 BTIF_TRACE_ERROR("%s not supported",__FUNCTION__);
433 bta_hl_ci_get_echo_data(mcl_handle, status, evt);
437 /*******************************************************************************
439 ** Function bta_hl_co_put_echo_data
441 ** Description Put the received loopback echo data
443 ** Parameters app_id - HDP application ID
444 ** mcl_handle - MCL handle
445 ** data_size - the size of the data
446 ** p_data - the data pointer
447 ** evt - the evt to be passed back to the HL in the
448 ** bta_hl_ci_put_echo_data call-in function
452 *******************************************************************************/
453 void bta_hl_co_put_echo_data (UINT8 app_id, tBTA_HL_MCL_HANDLE mcl_handle,
454 UINT16 data_size, UINT8 *p_data, UINT16 evt)
456 tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL;
461 BTIF_TRACE_ERROR("%s not supported",__FUNCTION__);
462 bta_hl_ci_put_echo_data(mcl_handle, status, evt);