Home | History | Annotate | Download | only in hl
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2009-2012 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 /******************************************************************************
     20  *
     21  *  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
     23  *  phones.
     24  *
     25  ******************************************************************************/
     26 
     27 #include <string.h>
     28 
     29 #include "bt_target.h"
     30 #if defined(HL_INCLUDED) && (HL_INCLUDED == TRUE)
     31 
     32 #include "bt_common.h"
     33 #include "bta_hl_api.h"
     34 #include "bta_hl_int.h"
     35 
     36 /*****************************************************************************
     37 **  Constants
     38 *****************************************************************************/
     39 
     40 static const tBTA_SYS_REG bta_hl_reg =
     41 {
     42     bta_hl_hdl_event,
     43     BTA_HlDisable
     44 };
     45 
     46 /*******************************************************************************
     47 **
     48 ** Function         BTA_HlEnable
     49 **
     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.
     54 **
     55 ** Parameters       p_cback - HL event call back function
     56 **
     57 ** Returns          void
     58 **
     59 *******************************************************************************/
     60 void BTA_HlEnable(tBTA_HL_CTRL_CBACK *p_ctrl_cback)
     61 {
     62     tBTA_HL_API_ENABLE *p_buf =
     63         (tBTA_HL_API_ENABLE *)osi_malloc(sizeof(tBTA_HL_API_ENABLE));
     64 
     65     /* register with BTA system manager */
     66     bta_sys_register(BTA_ID_HL, &bta_hl_reg);
     67 
     68     p_buf->hdr.event = BTA_HL_API_ENABLE_EVT;
     69     p_buf->p_cback = p_ctrl_cback;
     70 
     71     bta_sys_sendmsg(p_buf);
     72 }
     73 
     74 /*******************************************************************************
     75 **
     76 ** Function         BTA_HlDisable
     77 **
     78 ** Description     Disable the HL subsystem.
     79 **
     80 ** Returns          void
     81 **
     82 *******************************************************************************/
     83 void BTA_HlDisable(void)
     84 {
     85     BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
     86 
     87     bta_sys_deregister(BTA_ID_HL);
     88     p_buf->event = BTA_HL_API_DISABLE_EVT;
     89 
     90     bta_sys_sendmsg(p_buf);
     91 }
     92 
     93 /*******************************************************************************
     94 **
     95 ** Function         BTA_HlUpdate
     96 **
     97 ** Description      Register an HDP application
     98 **
     99 ** Parameters       app_id        - Application ID
    100 **                  p_reg_param   - non-platform related parameters for the
    101 **                                  HDP application
    102 **                  p_cback       - HL event callback fucntion
    103 **
    104 ** Returns          void
    105 **
    106 *******************************************************************************/
    107 void BTA_HlUpdate(UINT8 app_id, tBTA_HL_REG_PARAM *p_reg_param,
    108                   BOOLEAN is_register, tBTA_HL_CBACK *p_cback)
    109 {
    110     tBTA_HL_API_UPDATE *p_buf =
    111         (tBTA_HL_API_UPDATE *)osi_malloc(sizeof(tBTA_HL_API_UPDATE));
    112 
    113     APPL_TRACE_DEBUG("%s", __func__);
    114 
    115     p_buf->hdr.event = BTA_HL_API_UPDATE_EVT;
    116     p_buf->app_id = app_id;
    117     p_buf->is_register = is_register;
    118 
    119     if (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);
    124         else
    125             p_buf->srv_name[0] = 0;
    126 
    127         if (p_reg_param->p_srv_desp)
    128             strlcpy(p_buf->srv_desp, p_reg_param->p_srv_desp, BTA_SERVICE_DESP_LEN);
    129         else
    130             p_buf->srv_desp[0] = 0;
    131 
    132         if (p_reg_param->p_provider_name)
    133             strlcpy(p_buf->provider_name, p_reg_param->p_provider_name, BTA_PROVIDER_NAME_LEN);
    134         else
    135             p_buf->provider_name[0] = 0;
    136     }
    137 
    138     bta_sys_sendmsg(p_buf);
    139 }
    140 
    141 /*******************************************************************************
    142 **
    143 ** Function         BTA_HlRegister
    144 **
    145 ** Description      Register an HDP application
    146 **
    147 ** Parameters       app_id        - Application ID
    148 **                  p_reg_param   - non-platform related parameters for the
    149 **                                  HDP application
    150 **                  p_cback       - HL event callback fucntion
    151 **
    152 ** Returns          void
    153 **
    154 *******************************************************************************/
    155 void BTA_HlRegister(UINT8  app_id,
    156                     tBTA_HL_REG_PARAM *p_reg_param,
    157                     tBTA_HL_CBACK *p_cback)
    158 {
    159     tBTA_HL_API_REGISTER *p_buf =
    160         (tBTA_HL_API_REGISTER *)osi_malloc(sizeof(tBTA_HL_API_REGISTER));
    161 
    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;
    166 
    167     if (p_reg_param->p_srv_name)
    168         strlcpy(p_buf->srv_name, p_reg_param->p_srv_name, BTA_SERVICE_NAME_LEN);
    169     else
    170         p_buf->srv_name[0] = 0;
    171 
    172     if (p_reg_param->p_srv_desp)
    173         strlcpy(p_buf->srv_desp, p_reg_param->p_srv_desp, BTA_SERVICE_DESP_LEN);
    174     else
    175         p_buf->srv_desp[0] = 0;
    176 
    177     if (p_reg_param->p_provider_name)
    178         strlcpy(p_buf->provider_name, p_reg_param->p_provider_name, BTA_PROVIDER_NAME_LEN);
    179     else
    180         p_buf->provider_name[0] = 0;
    181 
    182     bta_sys_sendmsg(p_buf);
    183 }
    184 
    185 /*******************************************************************************
    186 **
    187 ** Function         BTA_HlDeregister
    188 **
    189 ** Description      Deregister an HDP application
    190 **
    191 ** Parameters       app_handle - Application handle
    192 **
    193 ** Returns           void
    194 **
    195 *******************************************************************************/
    196 void BTA_HlDeregister(UINT8 app_id,tBTA_HL_APP_HANDLE app_handle)
    197 {
    198     tBTA_HL_API_DEREGISTER *p_buf =
    199         (tBTA_HL_API_DEREGISTER *)osi_malloc(sizeof(tBTA_HL_API_DEREGISTER));
    200 
    201     p_buf->hdr.event   = BTA_HL_API_DEREGISTER_EVT;
    202     p_buf->app_id      = app_id;
    203     p_buf->app_handle  = app_handle;
    204 
    205     bta_sys_sendmsg(p_buf);
    206 }
    207 
    208 /*******************************************************************************
    209 **
    210 ** Function         BTA_HlCchOpen
    211 **
    212 ** Description      Open a Control channel connection with the specified BD address
    213 **
    214 ** Parameters       app_handle - Application Handle
    215 **                  p_open_param - parameters for opening a control channel
    216 **
    217 ** Returns          void
    218 **
    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)
    226 {
    227     tBTA_HL_API_CCH_OPEN *p_buf =
    228         (tBTA_HL_API_CCH_OPEN *)osi_malloc(sizeof(tBTA_HL_API_CCH_OPEN));
    229 
    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;
    236 
    237     bta_sys_sendmsg(p_buf);
    238 }
    239 
    240 /*******************************************************************************
    241 **
    242 ** Function         BTA_HlCchClose
    243 **
    244 ** Description      Close a Control channel connection with the specified MCL
    245 **                  handle
    246 **
    247 ** Parameters       mcl_handle - MCL handle
    248 **
    249 ** Returns          void
    250 **
    251 *******************************************************************************/
    252 void BTA_HlCchClose(tBTA_HL_MCL_HANDLE mcl_handle)
    253 {
    254     tBTA_HL_API_CCH_CLOSE *p_buf =
    255         (tBTA_HL_API_CCH_CLOSE *)osi_malloc(sizeof(tBTA_HL_API_CCH_CLOSE));
    256 
    257     p_buf->hdr.event = BTA_HL_API_CCH_CLOSE_EVT;
    258     p_buf->mcl_handle = mcl_handle;
    259 
    260     bta_sys_sendmsg(p_buf);
    261 }
    262 
    263 /*******************************************************************************
    264 **
    265 ** Function         BTA_HlDchOpen
    266 **
    267 ** Description      Open a data channel connection with the specified DCH parameters
    268 **
    269 ** Parameters       mcl_handle - MCL handle
    270 **                  p_open_param - parameters for opening a data channel
    271 **
    272 ** Returns          void
    273 **
    274 *******************************************************************************/
    275 void BTA_HlDchOpen(tBTA_HL_MCL_HANDLE mcl_handle,
    276                    tBTA_HL_DCH_OPEN_PARAM *p_open_param)
    277 {
    278     tBTA_HL_API_DCH_OPEN *p_buf =
    279         (tBTA_HL_API_DCH_OPEN *)osi_malloc(sizeof(tBTA_HL_API_DCH_OPEN));
    280 
    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);
    288 
    289     bta_sys_sendmsg(p_buf);
    290 }
    291 
    292 /*******************************************************************************
    293 **
    294 ** Function         BTA_HlDchReconnect
    295 **
    296 ** Description      Reconnect a data channel with the specified MDL_ID
    297 **
    298 ** Parameters       mcl_handle      - MCL handle
    299 *8                  p_recon_param   - parameters for reconnecting a data channel
    300 **
    301 ** Returns          void
    302 **
    303 *******************************************************************************/
    304 void BTA_HlDchReconnect(tBTA_HL_MCL_HANDLE mcl_handle,
    305                         tBTA_HL_DCH_RECONNECT_PARAM *p_recon_param)
    306 {
    307     tBTA_HL_API_DCH_RECONNECT *p_buf =
    308         (tBTA_HL_API_DCH_RECONNECT *)osi_malloc(sizeof(tBTA_HL_API_DCH_RECONNECT));
    309 
    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;
    314 
    315     bta_sys_sendmsg(p_buf);
    316 }
    317 
    318 /*******************************************************************************
    319 **
    320 ** Function         BTA_HlDchClose
    321 **
    322 ** Description      Close a data channel with the specified MDL handle
    323 **
    324 ** Parameters       mdl_handle  - MDL handle
    325 **
    326 ** Returns          void
    327 **
    328 *******************************************************************************/
    329 void BTA_HlDchClose(tBTA_HL_MDL_HANDLE mdl_handle)
    330 {
    331     tBTA_HL_API_DCH_CLOSE *p_buf =
    332         (tBTA_HL_API_DCH_CLOSE *)osi_malloc(sizeof(tBTA_HL_API_DCH_CLOSE));
    333 
    334     p_buf->hdr.event = BTA_HL_API_DCH_CLOSE_EVT;
    335     p_buf->mdl_handle = mdl_handle;
    336 
    337     bta_sys_sendmsg(p_buf);
    338 }
    339 
    340 /*******************************************************************************
    341 **
    342 ** Function         BTA_HlDchAbort
    343 **
    344 ** Description      Abort the current data channel setup with the specified MCL
    345 **                  handle
    346 **
    347 ** Parameters       mcl_handle  - MCL handle
    348 **
    349 **
    350 ** Returns          void
    351 **
    352 *******************************************************************************/
    353 void BTA_HlDchAbort(tBTA_HL_MCL_HANDLE mcl_handle)
    354 {
    355     tBTA_HL_API_DCH_ABORT *p_buf =
    356         (tBTA_HL_API_DCH_ABORT *)osi_malloc(sizeof(tBTA_HL_API_DCH_ABORT));
    357 
    358     p_buf->hdr.event = BTA_HL_API_DCH_ABORT_EVT;
    359     p_buf->mcl_handle = mcl_handle;
    360 
    361     bta_sys_sendmsg(p_buf);
    362 }
    363 
    364 /*******************************************************************************
    365 **
    366 ** Function         BTA_HlSendData
    367 **
    368 ** Description      Send an APDU to the peer device
    369 **
    370 ** Parameters       mdl_handle  - MDL handle
    371 **                  pkt_size    - size of the data packet to be sent
    372 **
    373 ** Returns          void
    374 **
    375 *******************************************************************************/
    376 void BTA_HlSendData(tBTA_HL_MDL_HANDLE mdl_handle,
    377                     UINT16           pkt_size)
    378 {
    379     tBTA_HL_API_SEND_DATA *p_buf =
    380         (tBTA_HL_API_SEND_DATA *)osi_malloc(sizeof(tBTA_HL_API_SEND_DATA));
    381 
    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;
    385 
    386     bta_sys_sendmsg(p_buf);
    387 }
    388 
    389 /*******************************************************************************
    390 **
    391 ** Function         BTA_HlDeleteMdl
    392 **
    393 ** Description      Delete the specified MDL_ID within the specified MCL handle
    394 **
    395 ** Parameters       mcl_handle  - MCL handle
    396 **                  mdl_id      - MDL ID
    397 **
    398 ** Returns          void
    399 **
    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
    403 **
    404 *******************************************************************************/
    405 void BTA_HlDeleteMdl(tBTA_HL_MCL_HANDLE mcl_handle,
    406                      tBTA_HL_MDL_ID mdl_id )
    407 {
    408     tBTA_HL_API_DELETE_MDL *p_buf =
    409         (tBTA_HL_API_DELETE_MDL *)osi_malloc(sizeof(tBTA_HL_API_DELETE_MDL));
    410 
    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;
    414 
    415     bta_sys_sendmsg(p_buf);
    416 }
    417 
    418 /*******************************************************************************
    419 **
    420 ** Function         BTA_HlDchEchoTest
    421 **
    422 ** Description      Initiate an echo test with the specified MCL handle
    423 **
    424 ** Parameters       mcl_handle           - MCL handle
    425 *8                  p_echo_test_param   -  parameters for echo testing
    426 **
    427 ** Returns          void
    428 **
    429 *******************************************************************************/
    430 void BTA_HlDchEchoTest( tBTA_HL_MCL_HANDLE  mcl_handle,
    431                         tBTA_HL_DCH_ECHO_TEST_PARAM *p_echo_test_param)
    432 {
    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));
    435 
    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;
    441 
    442     bta_sys_sendmsg(p_buf);
    443 }
    444 
    445 /*******************************************************************************
    446 **
    447 ** Function         BTA_HlSdpQuery
    448 **
    449 ** Description      SDP query request for the specified BD address
    450 **
    451 ** Parameters       app_handle      - application handle
    452 **                  bd_addr         - BD address
    453 **
    454 ** Returns          void
    455 **
    456 *******************************************************************************/
    457 void BTA_HlSdpQuery(UINT8  app_id,tBTA_HL_APP_HANDLE app_handle,
    458                     BD_ADDR bd_addr)
    459 {
    460     tBTA_HL_API_SDP_QUERY *p_buf =
    461         (tBTA_HL_API_SDP_QUERY *)osi_malloc(sizeof(tBTA_HL_API_SDP_QUERY));
    462 
    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);
    467 
    468     bta_sys_sendmsg(p_buf);
    469 }
    470 
    471 /*******************************************************************************
    472 **
    473 ** Function         BTA_HlDchCreateMdlRsp
    474 **
    475 ** Description      Set the Response and configuration values for the Create MDL
    476 **                  request
    477 **
    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
    482 **                                value
    483 **
    484 ** Returns          void
    485 **
    486 *******************************************************************************/
    487 void BTA_HlDchCreateRsp(tBTA_HL_MCL_HANDLE mcl_handle,
    488                         tBTA_HL_DCH_CREATE_RSP_PARAM *p_rsp_param)
    489 {
    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));
    492 
    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;
    499 
    500     bta_sys_sendmsg(p_buf);
    501 }
    502 
    503 #endif /* HL_INCLUDED */
    504