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