1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
43
44
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
81
82
83
84
85
86
87
88
89
90
91
92
93
103
104
105
106
107
108
109
110
111
112
113
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
155
156
157
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
198
199
200
201
202
203
204
205
206
207
214
215
216
217
218
219
220
221
222
223
228
229
230
231
232
233
234
235
236
237
241
242
243
244
245
246
247
248
249
250
254
255
256
257
258
259
260
261
262
263
264
268
269
270
271
272
273
274
275
276
277
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
310
311
312
313
314
315
316
317
318
319
320
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
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
473
474
475
476
477
/* ... */
/* ... */
#include "common/bt_target.h"
#if defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE)
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "bta/bta_hh_api.h"
#include "bta_hh_int.h"
#include "stack/l2c_api.h"
#include "bta/utl.h"
#include "osi/allocator.h"8 includes
/* ... */
static const tBTA_SYS_REG bta_hh_reg = {
bta_hh_hdl_event,
BTA_HhDisable
}{...};
/* ... */
void BTA_HhEnable(tBTA_SEC sec_mask, tBTA_HH_CBACK *p_cback)
{
tBTA_HH_API_ENABLE *p_buf;
bta_sys_register(BTA_ID_HH, &bta_hh_reg);
APPL_TRACE_API("%s sec_mask:0x%x p_cback:%p", __func__, sec_mask, p_cback);
p_buf = (tBTA_HH_API_ENABLE *)osi_malloc((UINT16)sizeof(tBTA_HH_API_ENABLE));
if (p_buf != NULL) {
memset(p_buf, 0, sizeof(tBTA_HH_API_ENABLE));
p_buf->hdr.event = BTA_HH_API_ENABLE_EVT;
p_buf->p_cback = p_cback;
p_buf->sec_mask = sec_mask;
bta_sys_sendmsg(p_buf);
}{...}
}{...}
/* ... */
void BTA_HhDisable(void)
{
BT_HDR *p_buf;
bta_sys_deregister(BTA_ID_HH);
if ((p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_HH_API_DISABLE_EVT;
bta_sys_sendmsg(p_buf);
}{...}
}{...}
/* ... */
void BTA_HhClose(UINT8 dev_handle)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *)osi_malloc((UINT16)sizeof(BT_HDR))) != NULL) {
memset(p_buf, 0, sizeof(BT_HDR));
p_buf->event = BTA_HH_API_CLOSE_EVT;
p_buf->layer_specific = (UINT16) dev_handle;
bta_sys_sendmsg(p_buf);
}{...}
}{...}
/* ... */
void BTA_HhOpen(BD_ADDR dev_bda, tBTA_HH_PROTO_MODE mode, tBTA_SEC sec_mask)
{
tBTA_HH_API_CONN *p_buf;
p_buf = (tBTA_HH_API_CONN *)osi_malloc((UINT16)sizeof(tBTA_HH_API_CONN));
if (p_buf != NULL) {
memset((void *)p_buf, 0, sizeof(tBTA_HH_API_CONN));
p_buf->hdr.event = BTA_HH_API_OPEN_EVT;
p_buf->hdr.layer_specific = BTA_HH_INVALID_HANDLE;
p_buf->sec_mask = sec_mask;
p_buf->mode = mode;
bdcpy(p_buf->bd_addr, dev_bda);
bta_sys_sendmsg((void *)p_buf);
}{...} else {
APPL_TRACE_ERROR("No resource to send HID host Connect request.");
}{...}
}{...}
/* ... */
static void bta_hh_snd_write_dev(UINT8 dev_handle, UINT8 t_type, UINT8 param,
UINT16 data, UINT8 rpt_id, BT_HDR *p_data)
{
tBTA_HH_CMD_DATA *p_buf;
UINT16 len = (UINT16) (sizeof(tBTA_HH_CMD_DATA) );
if ((p_buf = (tBTA_HH_CMD_DATA *)osi_malloc(len)) != NULL) {
memset(p_buf, 0, sizeof(tBTA_HH_CMD_DATA));
p_buf->hdr.event = BTA_HH_API_WRITE_DEV_EVT;
p_buf->hdr.layer_specific = (UINT16) dev_handle;
p_buf->t_type = t_type;
p_buf->data = data;
p_buf->param = param;
p_buf->p_data = p_data;
p_buf->rpt_id = rpt_id;
bta_sys_sendmsg(p_buf);
}{...}
}{...}
/* ... */
void BTA_HhSetReport(UINT8 dev_handle, tBTA_HH_RPT_TYPE r_type, BT_HDR *p_data)
{
bta_hh_snd_write_dev(dev_handle, HID_TRANS_SET_REPORT, r_type, 0, 0, p_data);
}{...}
/* ... */
void BTA_HhGetReport(UINT8 dev_handle, tBTA_HH_RPT_TYPE r_type, UINT8 rpt_id, UINT16 buf_size)
{
UINT8 param = (buf_size) ? (r_type | 0x08) : r_type;
bta_hh_snd_write_dev(dev_handle, HID_TRANS_GET_REPORT, param,
buf_size, rpt_id, NULL);
}{...}
/* ... */
void BTA_HhSetProtoMode(UINT8 dev_handle, tBTA_HH_PROTO_MODE p_type)
{
bta_hh_snd_write_dev(dev_handle, HID_TRANS_SET_PROTOCOL, (UINT8)p_type,
0, 0, NULL);
}{...}
/* ... */
void BTA_HhGetProtoMode(UINT8 dev_handle)
{
bta_hh_snd_write_dev(dev_handle, HID_TRANS_GET_PROTOCOL, 0, 0, 0, NULL);
}{...}
/* ... */
void BTA_HhSetIdle(UINT8 dev_handle, UINT16 idle_rate)
{
bta_hh_snd_write_dev(dev_handle, HID_TRANS_SET_IDLE, 0, idle_rate, 0, NULL);
}{...}
/* ... */
void BTA_HhGetIdle(UINT8 dev_handle)
{
bta_hh_snd_write_dev(dev_handle, HID_TRANS_GET_IDLE, 0, 0, 0, NULL);
}{...}
/* ... */
void BTA_HhSendCtrl(UINT8 dev_handle, tBTA_HH_TRANS_CTRL_TYPE c_type)
{
bta_hh_snd_write_dev(dev_handle, HID_TRANS_CONTROL, (UINT8)c_type, 0, 0, NULL);
}{...}
/* ... */
void BTA_HhSendData(UINT8 dev_handle, BD_ADDR dev_bda, BT_HDR *p_data)
{
UNUSED(dev_bda);
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
if (p_data->layer_specific != BTA_HH_RPTT_OUTPUT) {
APPL_TRACE_ERROR("ERROR! Wrong report type! Write Command only valid for output report!");
return;
}{...}
/* ... */#endif
bta_hh_snd_write_dev(dev_handle, HID_TRANS_DATA, (UINT8)p_data->layer_specific, 0, 0, p_data);
}{...}
/* ... */
void BTA_HhGetDscpInfo(UINT8 dev_handle)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *)osi_malloc((UINT16)sizeof(BT_HDR))) != NULL) {
memset(p_buf, 0, sizeof(BT_HDR));
p_buf->event = BTA_HH_API_GET_DSCP_EVT;
p_buf->layer_specific = (UINT16) dev_handle;
bta_sys_sendmsg(p_buf);
}{...}
}{...}
/* ... */
void BTA_HhAddDev(BD_ADDR bda, tBTA_HH_ATTR_MASK attr_mask, UINT8 sub_class,
UINT8 app_id, tBTA_HH_DEV_DSCP_INFO dscp_info)
{
tBTA_HH_MAINT_DEV *p_buf;
UINT16 len = sizeof(tBTA_HH_MAINT_DEV) + dscp_info.descriptor.dl_len;
p_buf = (tBTA_HH_MAINT_DEV *)osi_malloc(len);
if (p_buf != NULL) {
memset(p_buf, 0, sizeof(tBTA_HH_MAINT_DEV));
p_buf->hdr.event = BTA_HH_API_MAINT_DEV_EVT;
p_buf->sub_event = BTA_HH_ADD_DEV_EVT;
p_buf->hdr.layer_specific = BTA_HH_INVALID_HANDLE;
p_buf->attr_mask = (UINT16) attr_mask;
p_buf->sub_class = sub_class;
p_buf->app_id = app_id;
bdcpy(p_buf->bda, bda);
memcpy(&p_buf->dscp_info, &dscp_info, sizeof(tBTA_HH_DEV_DSCP_INFO));
if ( dscp_info.descriptor.dl_len != 0 && dscp_info.descriptor.dsc_list) {
p_buf->dscp_info.descriptor.dl_len = dscp_info.descriptor.dl_len;
p_buf->dscp_info.descriptor.dsc_list = (UINT8 *)(p_buf + 1);
memcpy(p_buf->dscp_info.descriptor.dsc_list, dscp_info.descriptor.dsc_list, dscp_info.descriptor.dl_len);
}{...} else {
p_buf->dscp_info.descriptor.dsc_list = NULL;
p_buf->dscp_info.descriptor.dl_len = 0;
}{...}
bta_sys_sendmsg(p_buf);
}{...}
}{...}
/* ... */
void BTA_HhRemoveDev(UINT8 dev_handle )
{
tBTA_HH_MAINT_DEV *p_buf;
p_buf = (tBTA_HH_MAINT_DEV *)osi_malloc((UINT16)sizeof(tBTA_HH_MAINT_DEV));
if (p_buf != NULL) {
memset(p_buf, 0, sizeof(tBTA_HH_MAINT_DEV));
p_buf->hdr.event = BTA_HH_API_MAINT_DEV_EVT;
p_buf->sub_event = BTA_HH_RMV_DEV_EVT;
p_buf->hdr.layer_specific = (UINT16) dev_handle;
bta_sys_sendmsg(p_buf);
}{...}
}{...}
#if BTA_HH_LE_INCLUDED == TRUE
/* ... */
void BTA_HhUpdateLeScanParam(UINT8 dev_handle, UINT16 scan_int, UINT16 scan_win)
{
tBTA_HH_SCPP_UPDATE *p_buf;
p_buf = (tBTA_HH_SCPP_UPDATE *)osi_malloc((UINT16)sizeof(tBTA_HH_SCPP_UPDATE));
if (p_buf != NULL) {
memset(p_buf, 0, sizeof(tBTA_HH_SCPP_UPDATE));
p_buf->hdr.event = BTA_HH_API_SCPP_UPDATE_EVT;
p_buf->hdr.layer_specific = (UINT16) dev_handle;
p_buf->scan_int = scan_int;
p_buf->scan_win = scan_win;
bta_sys_sendmsg(p_buf);
}{...}
}{...}
/* ... */#endif
/* ... */
void BTA_HhParseBootRpt(tBTA_HH_BOOT_RPT *p_data, UINT8 *p_report,
UINT16 report_len)
{
p_data->dev_type = BTA_HH_DEVT_UNKNOWN;
if (p_report) {
switch (p_report[0]) {
case BTA_HH_KEYBD_RPT_ID:
p_data->dev_type = p_report[0];
bta_hh_parse_keybd_rpt(p_data, p_report + 1, (UINT16)(report_len - 1));
break;
...
case BTA_HH_MOUSE_RPT_ID:
p_data->dev_type = p_report[0];
bta_hh_parse_mice_rpt(p_data, p_report + 1, (UINT16)(report_len - 1));
break;
...
default:
APPL_TRACE_DEBUG("Unknown boot report: %d", p_report[0]);;
break;...
}{...}
}{...}
return;
}{...}
...
/* ... */#endif