• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //#if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
20 
21 #include <ctype.h>
22 #include <fcntl.h>
23 #include <sys/poll.h>
24 #include <pthread.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdint.h>
28 #include <errno.h>
29 #include <unistd.h>
30 #include <linux/uhid.h>
31 #include <unistd.h>
32 #include "btif_hh.h"
33 #include "bta_api.h"
34 #include "bta_hh_api.h"
35 #include "btif_util.h"
36 #include "bta_hh_co.h"
37 
38 const char *dev_path = "/dev/uhid";
39 
40 #if (BLE_INCLUDED == TRUE && BTA_HH_LE_INCLUDED == TRUE)
41 #include "btif_config.h"
42 #define BTA_HH_NV_LOAD_MAX       16
43 static tBTA_HH_RPT_CACHE_ENTRY sReportCache[BTA_HH_NV_LOAD_MAX];
44 #endif
45 
uhid_set_non_blocking(int fd)46 void uhid_set_non_blocking(int fd)
47 {
48     int opts = fcntl(fd, F_GETFL);
49     if (opts < 0)
50         APPL_TRACE_ERROR("%s() Getting flags failed (%s)", __func__, strerror(errno));
51 
52     opts |= O_NONBLOCK;
53 
54     if (fcntl(fd, F_SETFL, opts) < 0)
55         APPL_TRACE_EVENT("%s() Setting non-blocking flag failed (%s)", __func__, strerror(errno));
56 }
57 
58 /*Internal function to perform UHID write and error checking*/
uhid_write(int fd,const struct uhid_event * ev)59 static int uhid_write(int fd, const struct uhid_event *ev)
60 {
61     ssize_t ret = TEMP_FAILURE_RETRY(write(fd, ev, sizeof(*ev)));
62     if (ret < 0){
63         int rtn = -errno;
64         APPL_TRACE_ERROR("%s: Cannot write to uhid:%s",
65                          __FUNCTION__, strerror(errno));
66         return rtn;
67     } else if (ret != (ssize_t)sizeof(*ev)) {
68         APPL_TRACE_ERROR("%s: Wrong size written to uhid: %zd != %zu",
69                          __FUNCTION__, ret, sizeof(*ev));
70         return -EFAULT;
71     }
72 
73     return 0;
74 }
75 
76 /* Internal function to parse the events received from UHID driver*/
uhid_event(btif_hh_device_t * p_dev)77 static int uhid_event(btif_hh_device_t *p_dev)
78 {
79     struct uhid_event ev;
80     ssize_t ret;
81     memset(&ev, 0, sizeof(ev));
82     if(!p_dev)
83     {
84         APPL_TRACE_ERROR("%s: Device not found",__FUNCTION__)
85         return -1;
86     }
87     ret = TEMP_FAILURE_RETRY(read(p_dev->fd, &ev, sizeof(ev)));
88     if (ret == 0) {
89         APPL_TRACE_ERROR("%s: Read HUP on uhid-cdev %s", __FUNCTION__,
90                                                  strerror(errno));
91         return -EFAULT;
92     } else if (ret < 0) {
93         APPL_TRACE_ERROR("%s: Cannot read uhid-cdev: %s", __FUNCTION__,
94                                                 strerror(errno));
95         return -errno;
96     } else if ((ev.type == UHID_OUTPUT) || (ev.type==UHID_OUTPUT_EV)) {
97         // Only these two types havae payload,
98         // ensure we read full event descriptor
99         if (ret < (ssize_t)sizeof(ev)) {
100             APPL_TRACE_ERROR("%s: Invalid size read from uhid-dev: %ld != %lu",
101                          __FUNCTION__, ret, sizeof(ev.type));
102             return -EFAULT;
103         }
104     }
105 
106     switch (ev.type) {
107     case UHID_START:
108         APPL_TRACE_DEBUG("UHID_START from uhid-dev\n");
109         p_dev->ready_for_data = TRUE;
110         break;
111     case UHID_STOP:
112         APPL_TRACE_DEBUG("UHID_STOP from uhid-dev\n");
113         p_dev->ready_for_data = FALSE;
114         break;
115     case UHID_OPEN:
116         APPL_TRACE_DEBUG("UHID_OPEN from uhid-dev\n");
117         break;
118     case UHID_CLOSE:
119         APPL_TRACE_DEBUG("UHID_CLOSE from uhid-dev\n");
120         p_dev->ready_for_data = FALSE;
121         break;
122     case UHID_OUTPUT:
123         if (ret < (ssize_t)(sizeof(ev.type) + sizeof(ev.u.output))) {
124             APPL_TRACE_ERROR("%s: Invalid size read from uhid-dev: %zd < %zu",
125                              __FUNCTION__, ret,
126                              sizeof(ev.type) + sizeof(ev.u.output));
127             return -EFAULT;
128         }
129 
130         APPL_TRACE_DEBUG("UHID_OUTPUT: Report type = %d, report_size = %d"
131                             ,ev.u.output.rtype, ev.u.output.size);
132         //Send SET_REPORT with feature report if the report type in output event is FEATURE
133         if(ev.u.output.rtype == UHID_FEATURE_REPORT)
134             btif_hh_setreport(p_dev, BTHH_FEATURE_REPORT,
135                               ev.u.output.size, ev.u.output.data);
136         else if(ev.u.output.rtype == UHID_OUTPUT_REPORT)
137             btif_hh_setreport(p_dev, BTHH_OUTPUT_REPORT,
138                               ev.u.output.size, ev.u.output.data);
139         else
140             btif_hh_setreport(p_dev, BTHH_INPUT_REPORT,
141                               ev.u.output.size, ev.u.output.data);
142            break;
143     case UHID_OUTPUT_EV:
144         APPL_TRACE_DEBUG("UHID_OUTPUT_EV from uhid-dev\n");
145         break;
146     case UHID_FEATURE:
147         APPL_TRACE_DEBUG("UHID_FEATURE from uhid-dev\n");
148         break;
149     case UHID_FEATURE_ANSWER:
150         APPL_TRACE_DEBUG("UHID_FEATURE_ANSWER from uhid-dev\n");
151         break;
152 
153     default:
154         APPL_TRACE_DEBUG("Invalid event from uhid-dev: %u\n", ev.type);
155     }
156 
157     return 0;
158 }
159 
160 /*******************************************************************************
161 **
162 ** Function create_thread
163 **
164 ** Description creat a select loop
165 **
166 ** Returns pthread_t
167 **
168 *******************************************************************************/
create_thread(void * (* start_routine)(void *),void * arg)169 static inline pthread_t create_thread(void *(*start_routine)(void *), void * arg){
170     APPL_TRACE_DEBUG("create_thread: entered");
171     pthread_attr_t thread_attr;
172 
173     pthread_attr_init(&thread_attr);
174     pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
175     pthread_t thread_id = -1;
176     if ( pthread_create(&thread_id, &thread_attr, start_routine, arg)!=0 )
177     {
178         APPL_TRACE_ERROR("pthread_create : %s", strerror(errno));
179         return -1;
180     }
181     APPL_TRACE_DEBUG("create_thread: thread created successfully");
182     return thread_id;
183 }
184 
185 /*******************************************************************************
186 **
187 ** Function btif_hh_poll_event_thread
188 **
189 ** Description the polling thread which polls for event from UHID driver
190 **
191 ** Returns void
192 **
193 *******************************************************************************/
btif_hh_poll_event_thread(void * arg)194 static void *btif_hh_poll_event_thread(void *arg)
195 {
196     btif_hh_device_t *p_dev = arg;
197     APPL_TRACE_DEBUG("%s: Thread created fd = %d", __FUNCTION__, p_dev->fd);
198     struct pollfd pfds[1];
199     int ret;
200 
201     pfds[0].fd = p_dev->fd;
202     pfds[0].events = POLLIN;
203 
204     // Set the uhid fd as non-blocking to ensure we never block the BTU thread
205     uhid_set_non_blocking(p_dev->fd);
206 
207     while(p_dev->hh_keep_polling){
208         ret = TEMP_FAILURE_RETRY(poll(pfds, 1, 50));
209         if (ret < 0) {
210             APPL_TRACE_ERROR("%s: Cannot poll for fds: %s\n", __FUNCTION__, strerror(errno));
211             break;
212         }
213         if (pfds[0].revents & POLLIN) {
214             APPL_TRACE_DEBUG("btif_hh_poll_event_thread: POLLIN");
215             ret = uhid_event(p_dev);
216             if (ret){
217                 break;
218             }
219         }
220     }
221 
222     p_dev->hh_poll_thread_id = -1;
223     return 0;
224 }
225 
btif_hh_close_poll_thread(btif_hh_device_t * p_dev)226 static inline void btif_hh_close_poll_thread(btif_hh_device_t *p_dev)
227 {
228     APPL_TRACE_DEBUG("%s", __FUNCTION__);
229     p_dev->hh_keep_polling = 0;
230     if(p_dev->hh_poll_thread_id > 0)
231         pthread_join(p_dev->hh_poll_thread_id,NULL);
232 
233     return;
234 }
235 
bta_hh_co_destroy(int fd)236 void bta_hh_co_destroy(int fd)
237 {
238     struct uhid_event ev;
239     memset(&ev, 0, sizeof(ev));
240     ev.type = UHID_DESTROY;
241     uhid_write(fd, &ev);
242     APPL_TRACE_DEBUG("%s: Closing fd=%d", __func__, fd);
243     close(fd);
244 }
245 
bta_hh_co_write(int fd,UINT8 * rpt,UINT16 len)246 int bta_hh_co_write(int fd, UINT8* rpt, UINT16 len)
247 {
248     APPL_TRACE_DEBUG("%s: UHID write %d", __func__, len);
249 
250     struct uhid_event ev;
251     memset(&ev, 0, sizeof(ev));
252     ev.type = UHID_INPUT;
253     ev.u.input.size = len;
254     if(len > sizeof(ev.u.input.data)){
255         APPL_TRACE_WARNING("%s: Report size greater than allowed size",
256                            __FUNCTION__);
257         return -1;
258     }
259     memcpy(ev.u.input.data, rpt, len);
260 
261     return uhid_write(fd, &ev);
262 
263 }
264 
265 
266 /*******************************************************************************
267 **
268 ** Function      bta_hh_co_open
269 **
270 ** Description   When connection is opened, this call-out function is executed
271 **               by HH to do platform specific initialization.
272 **
273 ** Returns       void.
274 *******************************************************************************/
bta_hh_co_open(UINT8 dev_handle,UINT8 sub_class,tBTA_HH_ATTR_MASK attr_mask,UINT8 app_id)275 void bta_hh_co_open(UINT8 dev_handle, UINT8 sub_class, tBTA_HH_ATTR_MASK attr_mask,
276                     UINT8 app_id)
277 {
278     UINT32 i;
279     btif_hh_device_t *p_dev = NULL;
280 
281     if (dev_handle == BTA_HH_INVALID_HANDLE) {
282         APPL_TRACE_WARNING("%s: Oops, dev_handle (%d) is invalid...",
283                            __FUNCTION__, dev_handle);
284         return;
285     }
286 
287     for (i = 0; i < BTIF_HH_MAX_HID; i++) {
288         p_dev = &btif_hh_cb.devices[i];
289         if (p_dev->dev_status != BTHH_CONN_STATE_UNKNOWN &&
290             p_dev->dev_handle == dev_handle) {
291             // We found a device with the same handle. Must be a device reconnected.
292             APPL_TRACE_WARNING("%s: Found an existing device with the same handle "
293                                                                 "dev_status = %d",__FUNCTION__,
294                                                                 p_dev->dev_status);
295             APPL_TRACE_WARNING("%s:     bd_addr = [%02X:%02X:%02X:%02X:%02X:]", __FUNCTION__,
296                  p_dev->bd_addr.address[0], p_dev->bd_addr.address[1], p_dev->bd_addr.address[2],
297                  p_dev->bd_addr.address[3], p_dev->bd_addr.address[4]);
298                  APPL_TRACE_WARNING("%s:     attr_mask = 0x%04x, sub_class = 0x%02x, app_id = %d",
299                                   __FUNCTION__, p_dev->attr_mask, p_dev->sub_class, p_dev->app_id);
300 
301             if(p_dev->fd<0) {
302                 p_dev->fd = TEMP_FAILURE_RETRY(open(dev_path, O_RDWR | O_CLOEXEC));
303                 if (p_dev->fd < 0){
304                     APPL_TRACE_ERROR("%s: Error: failed to open uhid, err:%s",
305                                                                     __FUNCTION__,strerror(errno));
306                     return;
307                 }else
308                     APPL_TRACE_DEBUG("%s: uhid fd = %d", __FUNCTION__, p_dev->fd);
309             }
310 
311             p_dev->hh_keep_polling = 1;
312             p_dev->hh_poll_thread_id = create_thread(btif_hh_poll_event_thread, p_dev);
313             break;
314         }
315         p_dev = NULL;
316     }
317 
318     if (p_dev == NULL) {
319         // Did not find a device reconnection case. Find an empty slot now.
320         for (i = 0; i < BTIF_HH_MAX_HID; i++) {
321             if (btif_hh_cb.devices[i].dev_status == BTHH_CONN_STATE_UNKNOWN) {
322                 p_dev = &btif_hh_cb.devices[i];
323                 p_dev->dev_handle = dev_handle;
324                 p_dev->attr_mask  = attr_mask;
325                 p_dev->sub_class  = sub_class;
326                 p_dev->app_id     = app_id;
327                 p_dev->local_vup  = FALSE;
328 
329                 btif_hh_cb.device_num++;
330                 // This is a new device,open the uhid driver now.
331                 p_dev->fd = TEMP_FAILURE_RETRY(open(dev_path, O_RDWR | O_CLOEXEC));
332                 if (p_dev->fd < 0){
333                     APPL_TRACE_ERROR("%s: Error: failed to open uhid, err:%s",
334                                                                     __FUNCTION__,strerror(errno));
335                     return;
336                 }else{
337                     APPL_TRACE_DEBUG("%s: uhid fd = %d", __FUNCTION__, p_dev->fd);
338                     p_dev->hh_keep_polling = 1;
339                     p_dev->hh_poll_thread_id = create_thread(btif_hh_poll_event_thread, p_dev);
340                 }
341 
342 
343                 break;
344             }
345         }
346     }
347 
348     if (p_dev == NULL) {
349         APPL_TRACE_ERROR("%s: Error: too many HID devices are connected", __FUNCTION__);
350         return;
351     }
352 
353     p_dev->dev_status = BTHH_CONN_STATE_CONNECTED;
354     APPL_TRACE_DEBUG("%s: Return device status %d", __FUNCTION__, p_dev->dev_status);
355 }
356 
357 
358 /*******************************************************************************
359 **
360 ** Function      bta_hh_co_close
361 **
362 ** Description   When connection is closed, this call-out function is executed
363 **               by HH to do platform specific finalization.
364 **
365 ** Parameters    dev_handle  - device handle
366 **                  app_id      - application id
367 **
368 ** Returns          void.
369 *******************************************************************************/
bta_hh_co_close(UINT8 dev_handle,UINT8 app_id)370 void bta_hh_co_close(UINT8 dev_handle, UINT8 app_id)
371 {
372     UINT32 i;
373     btif_hh_device_t *p_dev = NULL;
374 
375     APPL_TRACE_WARNING("%s: dev_handle = %d, app_id = %d", __FUNCTION__, dev_handle, app_id);
376     if (dev_handle == BTA_HH_INVALID_HANDLE) {
377         APPL_TRACE_WARNING("%s: Oops, dev_handle (%d) is invalid...", __FUNCTION__, dev_handle);
378         return;
379     }
380 
381     for (i = 0; i < BTIF_HH_MAX_HID; i++) {
382         p_dev = &btif_hh_cb.devices[i];
383         if (p_dev->dev_status != BTHH_CONN_STATE_UNKNOWN && p_dev->dev_handle == dev_handle) {
384             APPL_TRACE_WARNING("%s: Found an existing device with the same handle "
385                                                         "dev_status = %d, dev_handle =%d"
386                                                         ,__FUNCTION__,p_dev->dev_status
387                                                         ,p_dev->dev_handle);
388             btif_hh_close_poll_thread(p_dev);
389             break;
390         }
391      }
392 }
393 
394 
395 /*******************************************************************************
396 **
397 ** Function         bta_hh_co_data
398 **
399 ** Description      This function is executed by BTA when HID host receive a data
400 **                  report.
401 **
402 ** Parameters       dev_handle  - device handle
403 **                  *p_rpt      - pointer to the report data
404 **                  len         - length of report data
405 **                  mode        - Hid host Protocol Mode
406 **                  sub_clas    - Device Subclass
407 **                  app_id      - application id
408 **
409 ** Returns          void
410 *******************************************************************************/
bta_hh_co_data(UINT8 dev_handle,UINT8 * p_rpt,UINT16 len,tBTA_HH_PROTO_MODE mode,UINT8 sub_class,UINT8 ctry_code,BD_ADDR peer_addr,UINT8 app_id)411 void bta_hh_co_data(UINT8 dev_handle, UINT8 *p_rpt, UINT16 len, tBTA_HH_PROTO_MODE mode,
412                     UINT8 sub_class, UINT8 ctry_code, BD_ADDR peer_addr, UINT8 app_id)
413 {
414     btif_hh_device_t *p_dev;
415     UNUSED(peer_addr);
416 
417     APPL_TRACE_DEBUG("%s: dev_handle = %d, subclass = 0x%02X, mode = %d, "
418          "ctry_code = %d, app_id = %d",
419          __FUNCTION__, dev_handle, sub_class, mode, ctry_code, app_id);
420 
421     p_dev = btif_hh_find_connected_dev_by_handle(dev_handle);
422     if (p_dev == NULL) {
423         APPL_TRACE_WARNING("%s: Error: unknown HID device handle %d", __FUNCTION__, dev_handle);
424         return;
425     }
426 
427     // Send the HID data to the kernel.
428     if ((p_dev->fd >= 0) && p_dev->ready_for_data) {
429         bta_hh_co_write(p_dev->fd, p_rpt, len);
430     }else {
431         APPL_TRACE_WARNING("%s: Error: fd = %d, ready %d, len = %d", __FUNCTION__, p_dev->fd,
432                             p_dev->ready_for_data, len);
433     }
434 }
435 
436 
437 /*******************************************************************************
438 **
439 ** Function         bta_hh_co_send_hid_info
440 **
441 ** Description      This function is called in btif_hh.c to process DSCP received.
442 **
443 ** Parameters       dev_handle  - device handle
444 **                  dscp_len    - report descriptor length
445 **                  *p_dscp     - report descriptor
446 **
447 ** Returns          void
448 *******************************************************************************/
bta_hh_co_send_hid_info(btif_hh_device_t * p_dev,char * dev_name,UINT16 vendor_id,UINT16 product_id,UINT16 version,UINT8 ctry_code,int dscp_len,UINT8 * p_dscp)449 void bta_hh_co_send_hid_info(btif_hh_device_t *p_dev, char *dev_name, UINT16 vendor_id,
450                              UINT16 product_id, UINT16 version, UINT8 ctry_code,
451                              int dscp_len, UINT8 *p_dscp)
452 {
453     int result;
454     struct uhid_event ev;
455 
456     if (p_dev->fd < 0) {
457         APPL_TRACE_WARNING("%s: Error: fd = %d, dscp_len = %d", __FUNCTION__, p_dev->fd, dscp_len);
458         return;
459     }
460 
461     APPL_TRACE_WARNING("%s: fd = %d, name = [%s], dscp_len = %d", __FUNCTION__,
462                                                                     p_dev->fd, dev_name, dscp_len);
463     APPL_TRACE_WARNING("%s: vendor_id = 0x%04x, product_id = 0x%04x, version= 0x%04x,"
464                                                                     "ctry_code=0x%02x",__FUNCTION__,
465                                                                     vendor_id, product_id,
466                                                                     version, ctry_code);
467 
468     //Create and send hid descriptor to kernel
469     memset(&ev, 0, sizeof(ev));
470     ev.type = UHID_CREATE;
471     strncpy((char*)ev.u.create.name, dev_name, sizeof(ev.u.create.name) - 1);
472     snprintf((char*)ev.u.create.uniq, sizeof(ev.u.create.uniq),
473              "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
474              p_dev->bd_addr.address[5], p_dev->bd_addr.address[4],
475              p_dev->bd_addr.address[3], p_dev->bd_addr.address[2],
476              p_dev->bd_addr.address[1], p_dev->bd_addr.address[0]);
477     ev.u.create.rd_size = dscp_len;
478     ev.u.create.rd_data = p_dscp;
479     ev.u.create.bus = BUS_BLUETOOTH;
480     ev.u.create.vendor = vendor_id;
481     ev.u.create.product = product_id;
482     ev.u.create.version = version;
483     ev.u.create.country = ctry_code;
484     result = uhid_write(p_dev->fd, &ev);
485 
486     APPL_TRACE_WARNING("%s: wrote descriptor to fd = %d, dscp_len = %d, result = %d", __FUNCTION__,
487                                                                     p_dev->fd, dscp_len, result);
488 
489     if (result) {
490         APPL_TRACE_WARNING("%s: Error: failed to send DSCP, result = %d", __FUNCTION__, result);
491 
492         /* The HID report descriptor is corrupted. Close the driver. */
493         close(p_dev->fd);
494         p_dev->fd = -1;
495     }
496 }
497 
498 #if (BLE_INCLUDED == TRUE && BTA_HH_LE_INCLUDED == TRUE)
499 /*******************************************************************************
500 **
501 ** Function         bta_hh_le_co_rpt_info
502 **
503 ** Description      This callout function is to convey the report information on
504 **                  a HOGP device to the application. Application can save this
505 **                  information in NV if device is bonded and load it back when
506 **                  stack reboot.
507 **
508 ** Parameters       remote_bda  - remote device address
509 **                  p_entry     - report entry pointer
510 **                  app_id      - application id
511 **
512 ** Returns          void.
513 **
514 *******************************************************************************/
bta_hh_le_co_rpt_info(BD_ADDR remote_bda,tBTA_HH_RPT_CACHE_ENTRY * p_entry,UINT8 app_id)515 void bta_hh_le_co_rpt_info(BD_ADDR remote_bda, tBTA_HH_RPT_CACHE_ENTRY *p_entry, UINT8 app_id)
516 {
517     UNUSED(app_id);
518 
519     unsigned idx = 0;
520 
521     bdstr_t bdstr;
522     sprintf(bdstr, "%02x:%02x:%02x:%02x:%02x:%02x",
523         remote_bda[0], remote_bda[1], remote_bda[2],
524         remote_bda[3], remote_bda[4], remote_bda[5]);
525 
526     size_t len = btif_config_get_bin_length(bdstr, "HidReport");
527     if (len >= sizeof(tBTA_HH_RPT_CACHE_ENTRY) && len <= sizeof(sReportCache))
528     {
529         btif_config_get_bin(bdstr, "HidReport", (uint8_t *)sReportCache, &len);
530         idx = len / sizeof(tBTA_HH_RPT_CACHE_ENTRY);
531     }
532 
533     if (idx < BTA_HH_NV_LOAD_MAX)
534     {
535         memcpy(&sReportCache[idx++], p_entry, sizeof(tBTA_HH_RPT_CACHE_ENTRY));
536         btif_config_set_bin(bdstr, "HidReport", (const uint8_t *)sReportCache,
537             idx * sizeof(tBTA_HH_RPT_CACHE_ENTRY));
538         BTIF_TRACE_DEBUG("%s() - Saving report; dev=%s, idx=%d", __FUNCTION__, bdstr, idx);
539     }
540 }
541 
542 
543 /*******************************************************************************
544 **
545 ** Function         bta_hh_le_co_cache_load
546 **
547 ** Description      This callout function is to request the application to load the
548 **                  cached HOGP report if there is any. When cache reading is completed,
549 **                  bta_hh_le_ci_cache_load() is called by the application.
550 **
551 ** Parameters       remote_bda  - remote device address
552 **                  p_num_rpt: number of cached report
553 **                  app_id      - application id
554 **
555 ** Returns          the acched report array
556 **
557 *******************************************************************************/
bta_hh_le_co_cache_load(BD_ADDR remote_bda,UINT8 * p_num_rpt,UINT8 app_id)558 tBTA_HH_RPT_CACHE_ENTRY * bta_hh_le_co_cache_load (BD_ADDR remote_bda,
559                                                    UINT8 *p_num_rpt, UINT8 app_id)
560 {
561     UNUSED(app_id);
562 
563     unsigned idx = 0;
564 
565     bdstr_t bdstr;
566     sprintf(bdstr, "%02x:%02x:%02x:%02x:%02x:%02x",
567         remote_bda[0], remote_bda[1], remote_bda[2],
568         remote_bda[3], remote_bda[4], remote_bda[5]);
569 
570     size_t len = btif_config_get_bin_length(bdstr, "HidReport");
571     if (!p_num_rpt && len < sizeof(tBTA_HH_RPT_CACHE_ENTRY))
572         return NULL;
573 
574     if (len > sizeof(sReportCache))
575         len = sizeof(sReportCache);
576     btif_config_get_bin(bdstr, "HidReport", (uint8_t *)sReportCache, &len);
577     *p_num_rpt = len / sizeof(tBTA_HH_RPT_CACHE_ENTRY);
578 
579     BTIF_TRACE_DEBUG("%s() - Loaded %d reports; dev=%s", __FUNCTION__, *p_num_rpt, bdstr);
580 
581     return sReportCache;
582 }
583 
584 /*******************************************************************************
585 **
586 ** Function         bta_hh_le_co_reset_rpt_cache
587 **
588 ** Description      This callout function is to reset the HOGP device cache.
589 **
590 ** Parameters       remote_bda  - remote device address
591 **
592 ** Returns          none
593 **
594 *******************************************************************************/
bta_hh_le_co_reset_rpt_cache(BD_ADDR remote_bda,UINT8 app_id)595 void bta_hh_le_co_reset_rpt_cache (BD_ADDR remote_bda, UINT8 app_id)
596 {
597     UNUSED(app_id);
598 
599     bdstr_t bdstr;
600     sprintf(bdstr, "%02x:%02x:%02x:%02x:%02x:%02x",
601         remote_bda[0], remote_bda[1], remote_bda[2],
602         remote_bda[3], remote_bda[4], remote_bda[5]);
603     btif_config_remove(bdstr, "HidReport");
604 
605     BTIF_TRACE_DEBUG("%s() - Reset cache for bda %s", __FUNCTION__, bdstr);
606 }
607 #endif /* #if (BLE_INCLUDED == TRUE && BTA_HH_LE_INCLUDED == TRUE) */
608 
609