summaryrefslogtreecommitdiffstats
path: root/bta/hl/bta_hl_api.c
blob: 65ab7bd864581a31b370045e5b57800268e9c58c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
/*****************************************************************************
**
**  Name:           bta_hl_api.c
**
**  Description:    This is the implementation of the API for the HeaLth
**                  device profile (HL) subsystem of BTA, Broadcom Corp's Bluetooth
**                  application layer for mobile phones.
**
**  Copyright (c) 2009-2011 Broadcom Corp., All Rights Reserved.
**  Broadcom Bluetooth Core. Proprietary and confidential.
**
*****************************************************************************/

#include <string.h>

#include "bt_target.h"
#if defined(HL_INCLUDED) && (HL_INCLUDED == TRUE)

#include "gki.h"
#include "bd.h"
#include "bta_hl_api.h"
#include "bta_hl_int.h"

/*****************************************************************************
**  Constants
*****************************************************************************/

static const tBTA_SYS_REG bta_hl_reg =
{
    bta_hl_hdl_event,
    BTA_HlDisable
};

/*******************************************************************************
**
** Function         BTA_HlEnable
**
** Description      Enable the HL subsystems.  This function must be
**                  called before any other functions in the HL API are called.
**                  When the enable operation is completed the callback function
**                  will be called with an BTA_HL_CTRL_ENABLE_CFM_EVT event.
**
** Parameters       p_cback - HL event call back function
**
** Returns          void
**
*******************************************************************************/
void BTA_HlEnable(tBTA_HL_CTRL_CBACK *p_ctrl_cback)
{
    tBTA_HL_API_ENABLE *p_buf;

    /* register with BTA system manager */
    GKI_sched_lock();
    bta_sys_register(BTA_ID_HL, &bta_hl_reg);
    GKI_sched_unlock();

    if ((p_buf = (tBTA_HL_API_ENABLE *)GKI_getbuf(sizeof(tBTA_HL_API_ENABLE))) != NULL)
    {
        p_buf->hdr.event    = BTA_HL_API_ENABLE_EVT;
        p_buf->p_cback      = p_ctrl_cback;
        bta_sys_sendmsg(p_buf);
    }
}

/*******************************************************************************
**
** Function         BTA_HlDisable
**
** Description     Disable the HL subsystem.                 
**
** Returns          void
**
*******************************************************************************/
void BTA_HlDisable(void)
{
    BT_HDR  *p_buf;

    bta_sys_deregister(BTA_ID_HL);
    if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR))) != NULL)
    {
        p_buf->event = BTA_HL_API_DISABLE_EVT;
        bta_sys_sendmsg(p_buf);
    }
}

/*******************************************************************************
**
** Function         BTA_HlRegister
**
** Description      Register an HDP application 
**
** Parameters       app_id        - Application ID
**                  p_reg_param   - non-platform related parameters for the 
**                                  HDP application 
**                  p_cback       - HL event callback fucntion
**
** Returns          void
**
*******************************************************************************/
void BTA_HlRegister(UINT8  app_id,
                    tBTA_HL_REG_PARAM *p_reg_param,
                    tBTA_HL_CBACK *p_cback)
{
    tBTA_HL_API_REGISTER *p_buf;

    if ((p_buf = (tBTA_HL_API_REGISTER *)GKI_getbuf((UINT16)sizeof(tBTA_HL_API_REGISTER))) != NULL)
    {
        p_buf->hdr.event    = BTA_HL_API_REGISTER_EVT;
        p_buf->app_id       = app_id;
        p_buf->sec_mask     = (p_reg_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
        p_buf->p_cback = p_cback;
        if (p_reg_param->p_srv_name)
        {
            BCM_STRNCPY_S(p_buf->srv_name, sizeof(p_buf->srv_name),
                          p_reg_param->p_srv_name, BTA_SERVICE_NAME_LEN);
            p_buf->srv_name[BTA_SERVICE_NAME_LEN] = '\0';
        }
        else
            p_buf->srv_name[0]= '\0';

        if (p_reg_param->p_srv_desp)
        {
            BCM_STRNCPY_S(p_buf->srv_desp, sizeof(p_buf->srv_desp),
                          p_reg_param->p_srv_desp, BTA_SERVICE_DESP_LEN);
            p_buf->srv_desp[BTA_SERVICE_DESP_LEN]= '\0';
        }
        else
            p_buf->srv_desp[0]= '\0';

        if (p_reg_param->p_provider_name)
        {
            BCM_STRNCPY_S(p_buf->provider_name, sizeof(p_buf->provider_name),
                          p_reg_param->p_provider_name, BTA_PROVIDER_NAME_LEN);
            p_buf->provider_name[BTA_PROVIDER_NAME_LEN]= '\0';
        }
        else
            p_buf->provider_name[0]= '\0';

        bta_sys_sendmsg(p_buf);
    }
}

/*******************************************************************************
**
** Function         BTA_HlDeregister
**
** Description      Deregister an HDP application
**
** Parameters       app_handle - Application handle       
**
** Returns           void
**   
*******************************************************************************/
void BTA_HlDeregister(tBTA_HL_APP_HANDLE app_handle)
{
    tBTA_HL_API_DEREGISTER  *p_buf;

    if ((p_buf = (tBTA_HL_API_DEREGISTER *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DEREGISTER)))) != NULL)
    {
        p_buf->hdr.event   = BTA_HL_API_DEREGISTER_EVT;
        p_buf->app_handle  = app_handle;
        bta_sys_sendmsg(p_buf);
    }
}
/*******************************************************************************
**
** Function         BTA_HlCchOpen
**
** Description      Open a Control channel connection with the specified BD address
**                      
** Parameters       app_handle - Application Handle  
**                  p_open_param - parameters for opening a control channel
**                                 
** Returns          void
**
**                  Note: The control PSM value is used to select which
**                  HDP insatnce should be used in case the peer device support
**                  multiple HDP instances. Also, if the control PSM value is zero 
**                  then the first HDP instance is used for the control channel setup
*******************************************************************************/
void BTA_HlCchOpen(tBTA_HL_APP_HANDLE app_handle,
                   tBTA_HL_CCH_OPEN_PARAM *p_open_param)
{
    tBTA_HL_API_CCH_OPEN *p_buf;

    if ((p_buf = (tBTA_HL_API_CCH_OPEN *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_CCH_OPEN)))) != NULL)
    {
        p_buf->hdr.event        = BTA_HL_API_CCH_OPEN_EVT; 
        p_buf->app_handle       = app_handle;
        p_buf->sec_mask = (p_open_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
        bdcpy(p_buf->bd_addr, p_open_param->bd_addr); 
        p_buf->ctrl_psm       = p_open_param->ctrl_psm;
        bta_sys_sendmsg(p_buf);
    }
}

/*******************************************************************************
**
** Function         BTA_HlCchClose
**
** Description      Close a Control channel connection with the specified MCL
**                  handle
**
** Parameters       mcl_handle - MCL handle
**
** Returns          void
**
*******************************************************************************/
void BTA_HlCchClose(tBTA_HL_MCL_HANDLE mcl_handle) 
{
    tBTA_HL_API_CCH_CLOSE *p_buf;

    if ((p_buf = (tBTA_HL_API_CCH_CLOSE *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_CCH_CLOSE)))) != NULL)
    {
        p_buf->hdr.event        = BTA_HL_API_CCH_CLOSE_EVT;
        p_buf->mcl_handle       = mcl_handle;
        bta_sys_sendmsg(p_buf);
    }
}

/*******************************************************************************
**
** Function         BTA_HlDchOpen
**
** Description      Open a data channel connection with the specified DCH parameters
**                      
** Parameters       mcl_handle - MCL handle
**                  p_open_param - parameters for opening a data channel        
**
** Returns          void
**
*******************************************************************************/
void BTA_HlDchOpen(tBTA_HL_MCL_HANDLE mcl_handle,
                   tBTA_HL_DCH_OPEN_PARAM *p_open_param)
{
    tBTA_HL_API_DCH_OPEN *p_buf;

    if ((p_buf = (tBTA_HL_API_DCH_OPEN *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_OPEN)))) != NULL)
    {
        p_buf->hdr.event            = BTA_HL_API_DCH_OPEN_EVT;
        p_buf->mcl_handle           = mcl_handle;
        p_buf->ctrl_psm             = p_open_param->ctrl_psm; 
        p_buf->local_mdep_id        = p_open_param->local_mdep_id;
        p_buf->peer_mdep_id         = p_open_param->peer_mdep_id;
        p_buf->local_cfg            = p_open_param->local_cfg;
        p_buf->sec_mask             = (p_open_param->sec_mask | BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
        bta_sys_sendmsg(p_buf);
    }
}

/*******************************************************************************
**
** Function         BTA_HlDchReconnect
**
** Description      Reconnect a data channel with the specified MDL_ID
**                      
** Parameters       mcl_handle      - MCL handle
*8                  p_recon_param   - parameters for reconnecting a data channel
**
** Returns          void
**
*******************************************************************************/
void BTA_HlDchReconnect(tBTA_HL_MCL_HANDLE mcl_handle,  
                        tBTA_HL_DCH_RECONNECT_PARAM *p_recon_param)
{
    tBTA_HL_API_DCH_RECONNECT *p_buf;

    if ((p_buf = (tBTA_HL_API_DCH_RECONNECT *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_RECONNECT)))) != NULL)
    {
        p_buf->hdr.event        = BTA_HL_API_DCH_RECONNECT_EVT;
        p_buf->mcl_handle       = mcl_handle;
        p_buf->ctrl_psm         = p_recon_param->ctrl_psm;
        p_buf->mdl_id           = p_recon_param->mdl_id;
        bta_sys_sendmsg(p_buf);
    }
}

/*******************************************************************************
**
** Function         BTA_HlDchClose
**
** Description      Close a data channel with the specified MDL handle
**
** Parameters       mdl_handle  - MDL handle
**
** Returns          void
**
*******************************************************************************/
void BTA_HlDchClose(tBTA_HL_MDL_HANDLE mdl_handle) 
{
    tBTA_HL_API_DCH_CLOSE *p_buf;

    if ((p_buf = (tBTA_HL_API_DCH_CLOSE *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_CLOSE)))) != NULL)
    {
        p_buf->hdr.event    = BTA_HL_API_DCH_CLOSE_EVT;
        p_buf->mdl_handle   = mdl_handle; 
        bta_sys_sendmsg(p_buf);
    }
}

/*******************************************************************************
**
** Function         BTA_HlDchAbort
**
** Description      Abort the current data channel setup with the specified MCL
**                  handle
**
** Parameters       mcl_handle  - MCL handle
**                 
**
** Returns          void
**
*******************************************************************************/
void BTA_HlDchAbort(tBTA_HL_MCL_HANDLE mcl_handle) 
{
    tBTA_HL_API_DCH_ABORT *p_buf;

    if ((p_buf = (tBTA_HL_API_DCH_ABORT *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_ABORT)))) != NULL)
    {
        p_buf->hdr.event        = BTA_HL_API_DCH_ABORT_EVT;
        p_buf->mcl_handle       = mcl_handle;
        bta_sys_sendmsg(p_buf);
    }
}

/*******************************************************************************
**
** Function         BTA_HlSendData
**
** Description      Send an APDU to the peer device 
**
** Parameters       mdl_handle  - MDL handle
**                  pkt_size    - size of the data packet to be sent
**
** Returns          void  
**
*******************************************************************************/
void BTA_HlSendData(tBTA_HL_MDL_HANDLE mdl_handle,  
                    UINT16           pkt_size)
{
    tBTA_HL_API_SEND_DATA *p_buf = NULL;

    if ((p_buf = (tBTA_HL_API_SEND_DATA *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_SEND_DATA)))) != NULL)
    {
        p_buf->hdr.event        = BTA_HL_API_SEND_DATA_EVT;
        p_buf->mdl_handle       = mdl_handle;
        p_buf->pkt_size         = pkt_size;
        bta_sys_sendmsg(p_buf);
    }

}

/*******************************************************************************
**
** Function         BTA_HlDeleteMdl
**
** Description      Delete the specified MDL_ID within the specified MCL handle
**
** Parameters       mcl_handle  - MCL handle
**                  mdl_id      - MDL ID
**
** Returns          void
**
**                  note: If mdl_id = 0xFFFF then this means to delete all MDLs
**                        and this value can only be used with DeleteMdl request only 
**                        not other requests
**
*******************************************************************************/
void BTA_HlDeleteMdl(tBTA_HL_MCL_HANDLE mcl_handle, 
                     tBTA_HL_MDL_ID mdl_id ) 
{
    tBTA_HL_API_DELETE_MDL *p_buf;

    if ((p_buf = (tBTA_HL_API_DELETE_MDL *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DELETE_MDL)))) != NULL)
    {
        p_buf->hdr.event        = BTA_HL_API_DELETE_MDL_EVT;
        p_buf->mcl_handle       = mcl_handle;
        p_buf->mdl_id           = mdl_id; 
        bta_sys_sendmsg(p_buf);
    }
}

/*******************************************************************************
**
** Function         BTA_HlDchEchoTest
**
** Description      Initiate an echo test with the specified MCL handle 
**
** Parameters       mcl_handle           - MCL handle
*8                  p_echo_test_param   -  parameters for echo testing              
**
** Returns          void
**
*******************************************************************************/
void BTA_HlDchEchoTest( tBTA_HL_MCL_HANDLE  mcl_handle,  
                        tBTA_HL_DCH_ECHO_TEST_PARAM *p_echo_test_param)
{
    tBTA_HL_API_DCH_ECHO_TEST   *p_buf;

    if ((p_buf = (tBTA_HL_API_DCH_ECHO_TEST *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_ECHO_TEST)))) != NULL)
    {
        p_buf->hdr.event     = BTA_HL_API_DCH_ECHO_TEST_EVT;
        p_buf->mcl_handle    = mcl_handle;
        p_buf->ctrl_psm      = p_echo_test_param->ctrl_psm; 
        p_buf->local_cfg     = p_echo_test_param->local_cfg; 
        p_buf->pkt_size      = p_echo_test_param->pkt_size; 
        bta_sys_sendmsg(p_buf);
    }
}


/*******************************************************************************
**
** Function         BTA_HlSdpQuery
**
** Description      SDP query request for the specified BD address
**
** Parameters       app_handle      - application handle
**                  bd_addr         - BD address
**                      
** Returns          void
**
*******************************************************************************/
void BTA_HlSdpQuery(tBTA_HL_APP_HANDLE app_handle,
                    BD_ADDR bd_addr)
{
    tBTA_HL_API_SDP_QUERY *p_buf;

    if ((p_buf = (tBTA_HL_API_SDP_QUERY *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_SDP_QUERY)))) != NULL)
    {
        p_buf->hdr.event        = BTA_HL_API_SDP_QUERY_EVT;
        p_buf->app_handle       = app_handle;
        bdcpy(p_buf->bd_addr, bd_addr); 
        bta_sys_sendmsg(p_buf);
    }
}


/*******************************************************************************
**
** Function         BTA_HlDchCreateMdlRsp
**
** Description      Set the Response and configuration values for the Create MDL 
**                  request
**
** Parameters       mcl_handle  - MCL handle
**                  p_rsp_param - parameters specified whether the request should 
**                                be accepted or not and if it should be accepted
**                                then it also specified the configuration response 
**                                value  
**  
** Returns          void
**
*******************************************************************************/
void BTA_HlDchCreateRsp(tBTA_HL_MCL_HANDLE mcl_handle, 
                        tBTA_HL_DCH_CREATE_RSP_PARAM *p_rsp_param)
{
    tBTA_HL_API_DCH_CREATE_RSP *p_buf;

    if ((p_buf = (tBTA_HL_API_DCH_CREATE_RSP *)GKI_getbuf((UINT16)(sizeof(tBTA_HL_API_DCH_CREATE_RSP)))) != NULL)
    {
        p_buf->hdr.event        = BTA_HL_API_DCH_CREATE_RSP_EVT;
        p_buf->mcl_handle       = mcl_handle;
        p_buf->mdl_id           = p_rsp_param->mdl_id;
        p_buf->local_mdep_id    = p_rsp_param->local_mdep_id;
        p_buf->rsp_code         = p_rsp_param->rsp_code;
        p_buf->cfg_rsp          = p_rsp_param->cfg_rsp;
        bta_sys_sendmsg(p_buf);
    }
}

#endif /* HL_INCLUDED */