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 "gki.h"
     33 #include "bd.h"
     34 #include "bta_hl_api.h"
     35 #include "bta_hl_int.h"
     36 
     37 /*****************************************************************************
     38 **  Constants
     39 *****************************************************************************/
     40 
     41 static const tBTA_SYS_REG bta_hl_reg =
     42 {
     43     bta_hl_hdl_event,
     44     BTA_HlDisable
     45 };
     46 
     47 /*******************************************************************************
     48 **
     49 ** Function         BTA_HlEnable
     50 **
     51 ** Description      Enable the HL subsystems.  This function must be
     52 **                  called before any other functions in the HL API are called.
     53 **                  When the enable operation is completed the callback function
     54 **                  will be called with an BTA_HL_CTRL_ENABLE_CFM_EVT event.
     55 **
     56 ** Parameters       p_cback - HL event call back function
     57 **
     58 ** Returns          void
     59 **
     60 *******************************************************************************/
     61 void BTA_HlEnable(tBTA_HL_CTRL_CBACK *p_ctrl_cback)
     62 {
     63     tBTA_HL_API_ENABLE *p_buf;
     64 
     65     /* register with BTA system manager */
     66     GKI_sched_lock();
     67     bta_sys_register(BTA_ID_HL, &bta_hl_reg);
     68     GKI_sched_unlock();
     69 
     70     if ((p_buf = (tBTA_HL_API_ENABLE *)GKI_getbuf(sizeof(tBTA_HL_API_ENABLE))) != NULL)
     71     {
     72         p_buf->hdr.event    = BTA_HL_API_ENABLE_EVT;
     73         p_buf->p_cback      = p_ctrl_cback;
     74         bta_sys_sendmsg(p_buf);
     75     }
     76 }
     77 
     78 /*******************************************************************************
     79 **
     80 ** Function         BTA_HlDisable
     81 **
     82 ** Description     Disable the HL subsystem.
     83 **
     84 ** Returns          void
     85 **
     86 *******************************************************************************/
     87 void BTA_HlDisable(void)
     88 {
     89     BT_HDR  *p_buf;
     90 
     91     bta_sys_deregister(BTA_ID_HL);
     92     if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR))) != NULL)
     93     {
     94         p_buf->event = BTA_HL_API_DISABLE_EVT;
     95         bta_sys_sendmsg(p_buf);
     96     }
     97 }
     98 
     99 /*******************************************************************************
    100 **
    101 ** Function         BTA_HlRegister
    102 **
    103 ** Description      Register an HDP application
    104 **
    105 ** Parameters       app_id        - Application ID
    106 **                  p_reg_param   - non-platform related parameters for the
    107 **                                  HDP application
    108 **                  p_cback       - HL event callback fucntion
    109 **
    110 ** Returns          void
    111 **
    112 *******************************************************************************/
    113 void BTA_HlRegister(UINT8  app_id,
    114                     tBTA_HL_REG_PARAM *p_reg_param,
    115                     tBTA_HL_CBACK *p_cback)
    116 {
    117     tBTA_HL_API_REGISTER *p_buf;
    118 
    119     if ((p_buf = (tBTA_HL_API_REGISTER *)GKI_getbuf((UINT16)sizeof(tBTA_HL_API_REGISTER))) != NULL)
    120     {
    121         p_buf->hdr.event    = BTA_HL_API_REGISTER_EVT;
    122         p_buf->app_id       = app_id;
    123         p_buf->sec_mask     = (p_reg_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
    124         p_buf->p_cback = p_cback;
    125         if (p_reg_param->p_srv_name)
    126         {
    127             BCM_STRNCPY_S(p_buf->srv_name, sizeof(p_buf->srv_name),
    128                           p_reg_param->p_srv_name, BTA_SERVICE_NAME_LEN);
    129             p_buf->srv_name[BTA_SERVICE_NAME_LEN] = '\0';
    130         }
    131         else
    132             p_buf->srv_name[0]= '\0';
    133 
    134         if (p_reg_param->p_srv_desp)
    135         {
    136             BCM_STRNCPY_S(p_buf->srv_desp, sizeof(p_buf->srv_desp),
    137                           p_reg_param->p_srv_desp, BTA_SERVICE_DESP_LEN);
    138             p_buf->srv_desp[BTA_SERVICE_DESP_LEN]= '\0';
    139         }
    140         else
    141             p_buf->srv_desp[0]= '\0';
    142 
    143         if (p_reg_param->p_provider_name)
    144         {
    145             BCM_STRNCPY_S(p_buf->provider_name, sizeof(p_buf->provider_name),
    146                           p_reg_param->p_provider_name, BTA_PROVIDER_NAME_LEN);
    147             p_buf->provider_name[BTA_PROVIDER_NAME_LEN]= '\0';
    148         }
    149         else
    150             p_buf->provider_name[0]= '\0';
    151 
    152         bta_sys_sendmsg(p_buf);
    153     }
    154 }
    155 
    156 /*******************************************************************************
    157 **
    158 ** Function         BTA_HlDeregister
    159 **
    160 ** Description      Deregister an HDP application
    161 **
    162 ** Parameters       app_handle - Application handle
    163 **
    164 ** Returns           void
    165 **
    166 *******************************************************************************/
    167 void BTA_HlDeregister(tBTA_HL_APP_HANDLE app_handle)
    168 {
    169     tBTA_HL_API_DEREGISTER  *p_buf;
    170 
    171     if ((p_buf = (tBTA_HL_API_DEREGISTER *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DEREGISTER)))) != NULL)
    172     {
    173         p_buf->hdr.event   = BTA_HL_API_DEREGISTER_EVT;
    174         p_buf->app_handle  = app_handle;
    175         bta_sys_sendmsg(p_buf);
    176     }
    177 }
    178 /*******************************************************************************
    179 **
    180 ** Function         BTA_HlCchOpen
    181 **
    182 ** Description      Open a Control channel connection with the specified BD address
    183 **
    184 ** Parameters       app_handle - Application Handle
    185 **                  p_open_param - parameters for opening a control channel
    186 **
    187 ** Returns          void
    188 **
    189 **                  Note: The control PSM value is used to select which
    190 **                  HDP insatnce should be used in case the peer device support
    191 **                  multiple HDP instances. Also, if the control PSM value is zero
    192 **                  then the first HDP instance is used for the control channel setup
    193 *******************************************************************************/
    194 void BTA_HlCchOpen(tBTA_HL_APP_HANDLE app_handle,
    195                    tBTA_HL_CCH_OPEN_PARAM *p_open_param)
    196 {
    197     tBTA_HL_API_CCH_OPEN *p_buf;
    198 
    199     if ((p_buf = (tBTA_HL_API_CCH_OPEN *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_CCH_OPEN)))) != NULL)
    200     {
    201         p_buf->hdr.event        = BTA_HL_API_CCH_OPEN_EVT;
    202         p_buf->app_handle       = app_handle;
    203         p_buf->sec_mask = (p_open_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
    204         bdcpy(p_buf->bd_addr, p_open_param->bd_addr);
    205         p_buf->ctrl_psm       = p_open_param->ctrl_psm;
    206         bta_sys_sendmsg(p_buf);
    207     }
    208 }
    209 
    210 /*******************************************************************************
    211 **
    212 ** Function         BTA_HlCchClose
    213 **
    214 ** Description      Close a Control channel connection with the specified MCL
    215 **                  handle
    216 **
    217 ** Parameters       mcl_handle - MCL handle
    218 **
    219 ** Returns          void
    220 **
    221 *******************************************************************************/
    222 void BTA_HlCchClose(tBTA_HL_MCL_HANDLE mcl_handle)
    223 {
    224     tBTA_HL_API_CCH_CLOSE *p_buf;
    225 
    226     if ((p_buf = (tBTA_HL_API_CCH_CLOSE *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_CCH_CLOSE)))) != NULL)
    227     {
    228         p_buf->hdr.event        = BTA_HL_API_CCH_CLOSE_EVT;
    229         p_buf->mcl_handle       = mcl_handle;
    230         bta_sys_sendmsg(p_buf);
    231     }
    232 }
    233 
    234 /*******************************************************************************
    235 **
    236 ** Function         BTA_HlDchOpen
    237 **
    238 ** Description      Open a data channel connection with the specified DCH parameters
    239 **
    240 ** Parameters       mcl_handle - MCL handle
    241 **                  p_open_param - parameters for opening a data channel
    242 **
    243 ** Returns          void
    244 **
    245 *******************************************************************************/
    246 void BTA_HlDchOpen(tBTA_HL_MCL_HANDLE mcl_handle,
    247                    tBTA_HL_DCH_OPEN_PARAM *p_open_param)
    248 {
    249     tBTA_HL_API_DCH_OPEN *p_buf;
    250 
    251     if ((p_buf = (tBTA_HL_API_DCH_OPEN *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_OPEN)))) != NULL)
    252     {
    253         p_buf->hdr.event            = BTA_HL_API_DCH_OPEN_EVT;
    254         p_buf->mcl_handle           = mcl_handle;
    255         p_buf->ctrl_psm             = p_open_param->ctrl_psm;
    256         p_buf->local_mdep_id        = p_open_param->local_mdep_id;
    257         p_buf->peer_mdep_id         = p_open_param->peer_mdep_id;
    258         p_buf->local_cfg            = p_open_param->local_cfg;
    259         p_buf->sec_mask             = (p_open_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
    260         bta_sys_sendmsg(p_buf);
    261     }
    262 }
    263 
    264 /*******************************************************************************
    265 **
    266 ** Function         BTA_HlDchReconnect
    267 **
    268 ** Description      Reconnect a data channel with the specified MDL_ID
    269 **
    270 ** Parameters       mcl_handle      - MCL handle
    271 *8                  p_recon_param   - parameters for reconnecting a data channel
    272 **
    273 ** Returns          void
    274 **
    275 *******************************************************************************/
    276 void BTA_HlDchReconnect(tBTA_HL_MCL_HANDLE mcl_handle,
    277                         tBTA_HL_DCH_RECONNECT_PARAM *p_recon_param)
    278 {
    279     tBTA_HL_API_DCH_RECONNECT *p_buf;
    280 
    281     if ((p_buf = (tBTA_HL_API_DCH_RECONNECT *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_RECONNECT)))) != NULL)
    282     {
    283         p_buf->hdr.event        = BTA_HL_API_DCH_RECONNECT_EVT;
    284         p_buf->mcl_handle       = mcl_handle;
    285         p_buf->ctrl_psm         = p_recon_param->ctrl_psm;
    286         p_buf->mdl_id           = p_recon_param->mdl_id;
    287         bta_sys_sendmsg(p_buf);
    288     }
    289 }
    290 
    291 /*******************************************************************************
    292 **
    293 ** Function         BTA_HlDchClose
    294 **
    295 ** Description      Close a data channel with the specified MDL handle
    296 **
    297 ** Parameters       mdl_handle  - MDL handle
    298 **
    299 ** Returns          void
    300 **
    301 *******************************************************************************/
    302 void BTA_HlDchClose(tBTA_HL_MDL_HANDLE mdl_handle)
    303 {
    304     tBTA_HL_API_DCH_CLOSE *p_buf;
    305 
    306     if ((p_buf = (tBTA_HL_API_DCH_CLOSE *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_CLOSE)))) != NULL)
    307     {
    308         p_buf->hdr.event    = BTA_HL_API_DCH_CLOSE_EVT;
    309         p_buf->mdl_handle   = mdl_handle;
    310         bta_sys_sendmsg(p_buf);
    311     }
    312 }
    313 
    314 /*******************************************************************************
    315 **
    316 ** Function         BTA_HlDchAbort
    317 **
    318 ** Description      Abort the current data channel setup with the specified MCL
    319 **                  handle
    320 **
    321 ** Parameters       mcl_handle  - MCL handle
    322 **
    323 **
    324 ** Returns          void
    325 **
    326 *******************************************************************************/
    327 void BTA_HlDchAbort(tBTA_HL_MCL_HANDLE mcl_handle)
    328 {
    329     tBTA_HL_API_DCH_ABORT *p_buf;
    330 
    331     if ((p_buf = (tBTA_HL_API_DCH_ABORT *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_ABORT)))) != NULL)
    332     {
    333         p_buf->hdr.event        = BTA_HL_API_DCH_ABORT_EVT;
    334         p_buf->mcl_handle       = mcl_handle;
    335         bta_sys_sendmsg(p_buf);
    336     }
    337 }
    338 
    339 /*******************************************************************************
    340 **
    341 ** Function         BTA_HlSendData
    342 **
    343 ** Description      Send an APDU to the peer device
    344 **
    345 ** Parameters       mdl_handle  - MDL handle
    346 **                  pkt_size    - size of the data packet to be sent
    347 **
    348 ** Returns          void
    349 **
    350 *******************************************************************************/
    351 void BTA_HlSendData(tBTA_HL_MDL_HANDLE mdl_handle,
    352                     UINT16           pkt_size)
    353 {
    354     tBTA_HL_API_SEND_DATA *p_buf = NULL;
    355 
    356     if ((p_buf = (tBTA_HL_API_SEND_DATA *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_SEND_DATA)))) != NULL)
    357     {
    358         p_buf->hdr.event        = BTA_HL_API_SEND_DATA_EVT;
    359         p_buf->mdl_handle       = mdl_handle;
    360         p_buf->pkt_size         = pkt_size;
    361         bta_sys_sendmsg(p_buf);
    362     }
    363 
    364 }
    365 
    366 /*******************************************************************************
    367 **
    368 ** Function         BTA_HlDeleteMdl
    369 **
    370 ** Description      Delete the specified MDL_ID within the specified MCL handle
    371 **
    372 ** Parameters       mcl_handle  - MCL handle
    373 **                  mdl_id      - MDL ID
    374 **
    375 ** Returns          void
    376 **
    377 **                  note: If mdl_id = 0xFFFF then this means to delete all MDLs
    378 **                        and this value can only be used with DeleteMdl request only
    379 **                        not other requests
    380 **
    381 *******************************************************************************/
    382 void BTA_HlDeleteMdl(tBTA_HL_MCL_HANDLE mcl_handle,
    383                      tBTA_HL_MDL_ID mdl_id )
    384 {
    385     tBTA_HL_API_DELETE_MDL *p_buf;
    386 
    387     if ((p_buf = (tBTA_HL_API_DELETE_MDL *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DELETE_MDL)))) != NULL)
    388     {
    389         p_buf->hdr.event        = BTA_HL_API_DELETE_MDL_EVT;
    390         p_buf->mcl_handle       = mcl_handle;
    391         p_buf->mdl_id           = mdl_id;
    392         bta_sys_sendmsg(p_buf);
    393     }
    394 }
    395 
    396 /*******************************************************************************
    397 **
    398 ** Function         BTA_HlDchEchoTest
    399 **
    400 ** Description      Initiate an echo test with the specified MCL handle
    401 **
    402 ** Parameters       mcl_handle           - MCL handle
    403 *8                  p_echo_test_param   -  parameters for echo testing
    404 **
    405 ** Returns          void
    406 **
    407 *******************************************************************************/
    408 void BTA_HlDchEchoTest( tBTA_HL_MCL_HANDLE  mcl_handle,
    409                         tBTA_HL_DCH_ECHO_TEST_PARAM *p_echo_test_param)
    410 {
    411     tBTA_HL_API_DCH_ECHO_TEST   *p_buf;
    412 
    413     if ((p_buf = (tBTA_HL_API_DCH_ECHO_TEST *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_ECHO_TEST)))) != NULL)
    414     {
    415         p_buf->hdr.event     = BTA_HL_API_DCH_ECHO_TEST_EVT;
    416         p_buf->mcl_handle    = mcl_handle;
    417         p_buf->ctrl_psm      = p_echo_test_param->ctrl_psm;
    418         p_buf->local_cfg     = p_echo_test_param->local_cfg;
    419         p_buf->pkt_size      = p_echo_test_param->pkt_size;
    420         bta_sys_sendmsg(p_buf);
    421     }
    422 }
    423 
    424 
    425 /*******************************************************************************
    426 **
    427 ** Function         BTA_HlSdpQuery
    428 **
    429 ** Description      SDP query request for the specified BD address
    430 **
    431 ** Parameters       app_handle      - application handle
    432 **                  bd_addr         - BD address
    433 **
    434 ** Returns          void
    435 **
    436 *******************************************************************************/
    437 void BTA_HlSdpQuery(tBTA_HL_APP_HANDLE app_handle,
    438                     BD_ADDR bd_addr)
    439 {
    440     tBTA_HL_API_SDP_QUERY *p_buf;
    441 
    442     if ((p_buf = (tBTA_HL_API_SDP_QUERY *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_SDP_QUERY)))) != NULL)
    443     {
    444         p_buf->hdr.event        = BTA_HL_API_SDP_QUERY_EVT;
    445         p_buf->app_handle       = app_handle;
    446         bdcpy(p_buf->bd_addr, bd_addr);
    447         bta_sys_sendmsg(p_buf);
    448     }
    449 }
    450 
    451 
    452 /*******************************************************************************
    453 **
    454 ** Function         BTA_HlDchCreateMdlRsp
    455 **
    456 ** Description      Set the Response and configuration values for the Create MDL
    457 **                  request
    458 **
    459 ** Parameters       mcl_handle  - MCL handle
    460 **                  p_rsp_param - parameters specified whether the request should
    461 **                                be accepted or not and if it should be accepted
    462 **                                then it also specified the configuration response
    463 **                                value
    464 **
    465 ** Returns          void
    466 **
    467 *******************************************************************************/
    468 void BTA_HlDchCreateRsp(tBTA_HL_MCL_HANDLE mcl_handle,
    469                         tBTA_HL_DCH_CREATE_RSP_PARAM *p_rsp_param)
    470 {
    471     tBTA_HL_API_DCH_CREATE_RSP *p_buf;
    472 
    473     if ((p_buf = (tBTA_HL_API_DCH_CREATE_RSP *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_CREATE_RSP)))) != NULL)
    474     {
    475         p_buf->hdr.event        = BTA_HL_API_DCH_CREATE_RSP_EVT;
    476         p_buf->mcl_handle       = mcl_handle;
    477         p_buf->mdl_id           = p_rsp_param->mdl_id;
    478         p_buf->local_mdep_id    = p_rsp_param->local_mdep_id;
    479         p_buf->rsp_code         = p_rsp_param->rsp_code;
    480         p_buf->cfg_rsp          = p_rsp_param->cfg_rsp;
    481         bta_sys_sendmsg(p_buf);
    482     }
    483 }
    484 
    485 #endif /* HL_INCLUDED */
    486