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 of the API for the HeaLth device profile (HL)
22 * subsystem of BTA, Broadcom Corp's Bluetooth application layer for mobile
25 ******************************************************************************/
29 #include "bt_target.h"
30 #if defined(HL_INCLUDED) && (HL_INCLUDED == TRUE)
32 #include "bt_common.h"
33 #include "bta_hl_api.h"
34 #include "bta_hl_int.h"
36 /*****************************************************************************
38 *****************************************************************************/
40 static const tBTA_SYS_REG bta_hl_reg =
46 /*******************************************************************************
48 ** Function BTA_HlEnable
50 ** Description Enable the HL subsystems. This function must be
51 ** called before any other functions in the HL API are called.
52 ** When the enable operation is completed the callback function
53 ** will be called with an BTA_HL_CTRL_ENABLE_CFM_EVT event.
55 ** Parameters p_cback - HL event call back function
59 *******************************************************************************/
60 void BTA_HlEnable(tBTA_HL_CTRL_CBACK *p_ctrl_cback)
62 tBTA_HL_API_ENABLE *p_buf =
63 (tBTA_HL_API_ENABLE *)osi_malloc(sizeof(tBTA_HL_API_ENABLE));
65 /* register with BTA system manager */
66 bta_sys_register(BTA_ID_HL, &bta_hl_reg);
68 p_buf->hdr.event = BTA_HL_API_ENABLE_EVT;
69 p_buf->p_cback = p_ctrl_cback;
71 bta_sys_sendmsg(p_buf);
74 /*******************************************************************************
76 ** Function BTA_HlDisable
78 ** Description Disable the HL subsystem.
82 *******************************************************************************/
83 void BTA_HlDisable(void)
85 BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
87 bta_sys_deregister(BTA_ID_HL);
88 p_buf->event = BTA_HL_API_DISABLE_EVT;
90 bta_sys_sendmsg(p_buf);
93 /*******************************************************************************
95 ** Function BTA_HlUpdate
97 ** Description Register an HDP application
99 ** Parameters app_id - Application ID
100 ** p_reg_param - non-platform related parameters for the
102 ** p_cback - HL event callback fucntion
106 *******************************************************************************/
107 void BTA_HlUpdate(UINT8 app_id, tBTA_HL_REG_PARAM *p_reg_param,
108 BOOLEAN is_register, tBTA_HL_CBACK *p_cback)
110 tBTA_HL_API_UPDATE *p_buf =
111 (tBTA_HL_API_UPDATE *)osi_malloc(sizeof(tBTA_HL_API_UPDATE));
113 APPL_TRACE_DEBUG("%s", __func__);
115 p_buf->hdr.event = BTA_HL_API_UPDATE_EVT;
116 p_buf->app_id = app_id;
117 p_buf->is_register = is_register;
120 p_buf->sec_mask = (p_reg_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
121 p_buf->p_cback = p_cback;
122 if (p_reg_param->p_srv_name)
123 strlcpy(p_buf->srv_name, p_reg_param->p_srv_name, BTA_SERVICE_NAME_LEN);
125 p_buf->srv_name[0] = 0;
127 if (p_reg_param->p_srv_desp)
128 strlcpy(p_buf->srv_desp, p_reg_param->p_srv_desp, BTA_SERVICE_DESP_LEN);
130 p_buf->srv_desp[0] = 0;
132 if (p_reg_param->p_provider_name)
133 strlcpy(p_buf->provider_name, p_reg_param->p_provider_name, BTA_PROVIDER_NAME_LEN);
135 p_buf->provider_name[0] = 0;
138 bta_sys_sendmsg(p_buf);
141 /*******************************************************************************
143 ** Function BTA_HlRegister
145 ** Description Register an HDP application
147 ** Parameters app_id - Application ID
148 ** p_reg_param - non-platform related parameters for the
150 ** p_cback - HL event callback fucntion
154 *******************************************************************************/
155 void BTA_HlRegister(UINT8 app_id,
156 tBTA_HL_REG_PARAM *p_reg_param,
157 tBTA_HL_CBACK *p_cback)
159 tBTA_HL_API_REGISTER *p_buf =
160 (tBTA_HL_API_REGISTER *)osi_malloc(sizeof(tBTA_HL_API_REGISTER));
162 p_buf->hdr.event = BTA_HL_API_REGISTER_EVT;
163 p_buf->app_id = app_id;
164 p_buf->sec_mask = (p_reg_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
165 p_buf->p_cback = p_cback;
167 if (p_reg_param->p_srv_name)
168 strlcpy(p_buf->srv_name, p_reg_param->p_srv_name, BTA_SERVICE_NAME_LEN);
170 p_buf->srv_name[0] = 0;
172 if (p_reg_param->p_srv_desp)
173 strlcpy(p_buf->srv_desp, p_reg_param->p_srv_desp, BTA_SERVICE_DESP_LEN);
175 p_buf->srv_desp[0] = 0;
177 if (p_reg_param->p_provider_name)
178 strlcpy(p_buf->provider_name, p_reg_param->p_provider_name, BTA_PROVIDER_NAME_LEN);
180 p_buf->provider_name[0] = 0;
182 bta_sys_sendmsg(p_buf);
185 /*******************************************************************************
187 ** Function BTA_HlDeregister
189 ** Description Deregister an HDP application
191 ** Parameters app_handle - Application handle
195 *******************************************************************************/
196 void BTA_HlDeregister(UINT8 app_id,tBTA_HL_APP_HANDLE app_handle)
198 tBTA_HL_API_DEREGISTER *p_buf =
199 (tBTA_HL_API_DEREGISTER *)osi_malloc(sizeof(tBTA_HL_API_DEREGISTER));
201 p_buf->hdr.event = BTA_HL_API_DEREGISTER_EVT;
202 p_buf->app_id = app_id;
203 p_buf->app_handle = app_handle;
205 bta_sys_sendmsg(p_buf);
208 /*******************************************************************************
210 ** Function BTA_HlCchOpen
212 ** Description Open a Control channel connection with the specified BD address
214 ** Parameters app_handle - Application Handle
215 ** p_open_param - parameters for opening a control channel
219 ** Note: The control PSM value is used to select which
220 ** HDP insatnce should be used in case the peer device support
221 ** multiple HDP instances. Also, if the control PSM value is zero
222 ** then the first HDP instance is used for the control channel setup
223 *******************************************************************************/
224 void BTA_HlCchOpen(UINT8 app_id, tBTA_HL_APP_HANDLE app_handle,
225 tBTA_HL_CCH_OPEN_PARAM *p_open_param)
227 tBTA_HL_API_CCH_OPEN *p_buf =
228 (tBTA_HL_API_CCH_OPEN *)osi_malloc(sizeof(tBTA_HL_API_CCH_OPEN));
230 p_buf->hdr.event = BTA_HL_API_CCH_OPEN_EVT;
231 p_buf->app_id = app_id;
232 p_buf->app_handle = app_handle;
233 p_buf->sec_mask = (p_open_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
234 bdcpy(p_buf->bd_addr, p_open_param->bd_addr);
235 p_buf->ctrl_psm = p_open_param->ctrl_psm;
237 bta_sys_sendmsg(p_buf);
240 /*******************************************************************************
242 ** Function BTA_HlCchClose
244 ** Description Close a Control channel connection with the specified MCL
247 ** Parameters mcl_handle - MCL handle
251 *******************************************************************************/
252 void BTA_HlCchClose(tBTA_HL_MCL_HANDLE mcl_handle)
254 tBTA_HL_API_CCH_CLOSE *p_buf =
255 (tBTA_HL_API_CCH_CLOSE *)osi_malloc(sizeof(tBTA_HL_API_CCH_CLOSE));
257 p_buf->hdr.event = BTA_HL_API_CCH_CLOSE_EVT;
258 p_buf->mcl_handle = mcl_handle;
260 bta_sys_sendmsg(p_buf);
263 /*******************************************************************************
265 ** Function BTA_HlDchOpen
267 ** Description Open a data channel connection with the specified DCH parameters
269 ** Parameters mcl_handle - MCL handle
270 ** p_open_param - parameters for opening a data channel
274 *******************************************************************************/
275 void BTA_HlDchOpen(tBTA_HL_MCL_HANDLE mcl_handle,
276 tBTA_HL_DCH_OPEN_PARAM *p_open_param)
278 tBTA_HL_API_DCH_OPEN *p_buf =
279 (tBTA_HL_API_DCH_OPEN *)osi_malloc(sizeof(tBTA_HL_API_DCH_OPEN));
281 p_buf->hdr.event = BTA_HL_API_DCH_OPEN_EVT;
282 p_buf->mcl_handle = mcl_handle;
283 p_buf->ctrl_psm = p_open_param->ctrl_psm;
284 p_buf->local_mdep_id = p_open_param->local_mdep_id;
285 p_buf->peer_mdep_id = p_open_param->peer_mdep_id;
286 p_buf->local_cfg = p_open_param->local_cfg;
287 p_buf->sec_mask = (p_open_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
289 bta_sys_sendmsg(p_buf);
292 /*******************************************************************************
294 ** Function BTA_HlDchReconnect
296 ** Description Reconnect a data channel with the specified MDL_ID
298 ** Parameters mcl_handle - MCL handle
299 *8 p_recon_param - parameters for reconnecting a data channel
303 *******************************************************************************/
304 void BTA_HlDchReconnect(tBTA_HL_MCL_HANDLE mcl_handle,
305 tBTA_HL_DCH_RECONNECT_PARAM *p_recon_param)
307 tBTA_HL_API_DCH_RECONNECT *p_buf =
308 (tBTA_HL_API_DCH_RECONNECT *)osi_malloc(sizeof(tBTA_HL_API_DCH_RECONNECT));
310 p_buf->hdr.event = BTA_HL_API_DCH_RECONNECT_EVT;
311 p_buf->mcl_handle = mcl_handle;
312 p_buf->ctrl_psm = p_recon_param->ctrl_psm;
313 p_buf->mdl_id = p_recon_param->mdl_id;
315 bta_sys_sendmsg(p_buf);
318 /*******************************************************************************
320 ** Function BTA_HlDchClose
322 ** Description Close a data channel with the specified MDL handle
324 ** Parameters mdl_handle - MDL handle
328 *******************************************************************************/
329 void BTA_HlDchClose(tBTA_HL_MDL_HANDLE mdl_handle)
331 tBTA_HL_API_DCH_CLOSE *p_buf =
332 (tBTA_HL_API_DCH_CLOSE *)osi_malloc(sizeof(tBTA_HL_API_DCH_CLOSE));
334 p_buf->hdr.event = BTA_HL_API_DCH_CLOSE_EVT;
335 p_buf->mdl_handle = mdl_handle;
337 bta_sys_sendmsg(p_buf);
340 /*******************************************************************************
342 ** Function BTA_HlDchAbort
344 ** Description Abort the current data channel setup with the specified MCL
347 ** Parameters mcl_handle - MCL handle
352 *******************************************************************************/
353 void BTA_HlDchAbort(tBTA_HL_MCL_HANDLE mcl_handle)
355 tBTA_HL_API_DCH_ABORT *p_buf =
356 (tBTA_HL_API_DCH_ABORT *)osi_malloc(sizeof(tBTA_HL_API_DCH_ABORT));
358 p_buf->hdr.event = BTA_HL_API_DCH_ABORT_EVT;
359 p_buf->mcl_handle = mcl_handle;
361 bta_sys_sendmsg(p_buf);
364 /*******************************************************************************
366 ** Function BTA_HlSendData
368 ** Description Send an APDU to the peer device
370 ** Parameters mdl_handle - MDL handle
371 ** pkt_size - size of the data packet to be sent
375 *******************************************************************************/
376 void BTA_HlSendData(tBTA_HL_MDL_HANDLE mdl_handle,
379 tBTA_HL_API_SEND_DATA *p_buf =
380 (tBTA_HL_API_SEND_DATA *)osi_malloc(sizeof(tBTA_HL_API_SEND_DATA));
382 p_buf->hdr.event = BTA_HL_API_SEND_DATA_EVT;
383 p_buf->mdl_handle = mdl_handle;
384 p_buf->pkt_size = pkt_size;
386 bta_sys_sendmsg(p_buf);
389 /*******************************************************************************
391 ** Function BTA_HlDeleteMdl
393 ** Description Delete the specified MDL_ID within the specified MCL handle
395 ** Parameters mcl_handle - MCL handle
400 ** note: If mdl_id = 0xFFFF then this means to delete all MDLs
401 ** and this value can only be used with DeleteMdl request only
402 ** not other requests
404 *******************************************************************************/
405 void BTA_HlDeleteMdl(tBTA_HL_MCL_HANDLE mcl_handle,
406 tBTA_HL_MDL_ID mdl_id )
408 tBTA_HL_API_DELETE_MDL *p_buf =
409 (tBTA_HL_API_DELETE_MDL *)osi_malloc(sizeof(tBTA_HL_API_DELETE_MDL));
411 p_buf->hdr.event = BTA_HL_API_DELETE_MDL_EVT;
412 p_buf->mcl_handle = mcl_handle;
413 p_buf->mdl_id = mdl_id;
415 bta_sys_sendmsg(p_buf);
418 /*******************************************************************************
420 ** Function BTA_HlDchEchoTest
422 ** Description Initiate an echo test with the specified MCL handle
424 ** Parameters mcl_handle - MCL handle
425 *8 p_echo_test_param - parameters for echo testing
429 *******************************************************************************/
430 void BTA_HlDchEchoTest( tBTA_HL_MCL_HANDLE mcl_handle,
431 tBTA_HL_DCH_ECHO_TEST_PARAM *p_echo_test_param)
433 tBTA_HL_API_DCH_ECHO_TEST *p_buf =
434 (tBTA_HL_API_DCH_ECHO_TEST *)osi_malloc(sizeof(tBTA_HL_API_DCH_ECHO_TEST));
436 p_buf->hdr.event = BTA_HL_API_DCH_ECHO_TEST_EVT;
437 p_buf->mcl_handle = mcl_handle;
438 p_buf->ctrl_psm = p_echo_test_param->ctrl_psm;
439 p_buf->local_cfg = p_echo_test_param->local_cfg;
440 p_buf->pkt_size = p_echo_test_param->pkt_size;
442 bta_sys_sendmsg(p_buf);
445 /*******************************************************************************
447 ** Function BTA_HlSdpQuery
449 ** Description SDP query request for the specified BD address
451 ** Parameters app_handle - application handle
452 ** bd_addr - BD address
456 *******************************************************************************/
457 void BTA_HlSdpQuery(UINT8 app_id,tBTA_HL_APP_HANDLE app_handle,
460 tBTA_HL_API_SDP_QUERY *p_buf =
461 (tBTA_HL_API_SDP_QUERY *)osi_malloc(sizeof(tBTA_HL_API_SDP_QUERY));
463 p_buf->hdr.event = BTA_HL_API_SDP_QUERY_EVT;
464 p_buf->app_id = app_id;
465 p_buf->app_handle = app_handle;
466 bdcpy(p_buf->bd_addr, bd_addr);
468 bta_sys_sendmsg(p_buf);
471 /*******************************************************************************
473 ** Function BTA_HlDchCreateMdlRsp
475 ** Description Set the Response and configuration values for the Create MDL
478 ** Parameters mcl_handle - MCL handle
479 ** p_rsp_param - parameters specified whether the request should
480 ** be accepted or not and if it should be accepted
481 ** then it also specified the configuration response
486 *******************************************************************************/
487 void BTA_HlDchCreateRsp(tBTA_HL_MCL_HANDLE mcl_handle,
488 tBTA_HL_DCH_CREATE_RSP_PARAM *p_rsp_param)
490 tBTA_HL_API_DCH_CREATE_RSP *p_buf =
491 (tBTA_HL_API_DCH_CREATE_RSP *)osi_malloc(sizeof(tBTA_HL_API_DCH_CREATE_RSP));
493 p_buf->hdr.event = BTA_HL_API_DCH_CREATE_RSP_EVT;
494 p_buf->mcl_handle = mcl_handle;
495 p_buf->mdl_id = p_rsp_param->mdl_id;
496 p_buf->local_mdep_id = p_rsp_param->local_mdep_id;
497 p_buf->rsp_code = p_rsp_param->rsp_code;
498 p_buf->cfg_rsp = p_rsp_param->cfg_rsp;
500 bta_sys_sendmsg(p_buf);
503 #endif /* HL_INCLUDED */