blob: 28dd2be54f8ba06f5f9318f13c9fde0336f828de [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 2005-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#include <string.h>
19
20#include "bt_target.h"
Marie Janssene9e58ce2016-06-17 14:12:17 -070021#if (BTA_HH_INCLUDED == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -080022
The Android Open Source Project5738f832012-12-12 16:00:35 -080023#include "bta_hh_int.h"
Myles Watsond7ffd642016-10-27 10:27:36 -070024#include "osi/include/osi.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080025
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080026/* if SSR max latency is not defined by remote device, set the default value
27 as half of the link supervision timeout */
Myles Watsoncd1fd072016-11-09 13:17:43 -080028#define BTA_HH_GET_DEF_SSR_MAX_LAT(x) ((x) >> 1)
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080029
The Android Open Source Project5738f832012-12-12 16:00:35 -080030/*****************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080031 * Constants
32 ****************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -080033#define BTA_HH_KB_CTRL_MASK 0x11
34#define BTA_HH_KB_SHIFT_MASK 0x22
35#define BTA_HH_KB_ALT_MASK 0x44
36#define BTA_HH_KB_GUI_MASK 0x88
The Android Open Source Project5738f832012-12-12 16:00:35 -080037
Myles Watsoncd1fd072016-11-09 13:17:43 -080038#define BTA_HH_KB_CAPS_LOCK 0x39 /* caps lock */
39#define BTA_HH_KB_NUM_LOCK 0x53 /* num lock */
The Android Open Source Project5738f832012-12-12 16:00:35 -080040
Myles Watsoncd1fd072016-11-09 13:17:43 -080041#define BTA_HH_MAX_RPT_CHARS 8
The Android Open Source Project5738f832012-12-12 16:00:35 -080042
Myles Watsoncd1fd072016-11-09 13:17:43 -080043static const uint8_t bta_hh_mod_key_mask[BTA_HH_MOD_MAX_KEY] = {
44 BTA_HH_KB_CTRL_MASK, BTA_HH_KB_SHIFT_MASK, BTA_HH_KB_ALT_MASK,
45 BTA_HH_KB_GUI_MASK};
The Android Open Source Project5738f832012-12-12 16:00:35 -080046
47/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080048 *
49 * Function bta_hh_find_cb
50 *
51 * Description Find best available control block according to BD address.
52 *
53 *
54 * Returns void
55 *
56 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -080057uint8_t bta_hh_find_cb(BD_ADDR bda) {
58 uint8_t xx;
The Android Open Source Project5738f832012-12-12 16:00:35 -080059
Myles Watsoncd1fd072016-11-09 13:17:43 -080060 /* See how many active devices there are. */
61 for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++) {
62 /* check if any active/known devices is a match */
63 if ((!bdcmp(bda, bta_hh_cb.kdev[xx].addr) &&
64 bdcmp(bda, bd_addr_null) != 0)) {
Marie Janssene9e58ce2016-06-17 14:12:17 -070065#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -080066 APPL_TRACE_DEBUG("found kdev_cb[%d] hid_handle = %d ", xx,
67 bta_hh_cb.kdev[xx].hid_handle)
The Android Open Source Project5738f832012-12-12 16:00:35 -080068#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -080069 return xx;
The Android Open Source Project5738f832012-12-12 16:00:35 -080070 }
Marie Janssene9e58ce2016-06-17 14:12:17 -070071#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -080072 else
73 APPL_TRACE_DEBUG("in_use ? [%d] kdev[%d].hid_handle = %d state = [%d]",
74 bta_hh_cb.kdev[xx].in_use, xx,
75 bta_hh_cb.kdev[xx].hid_handle, bta_hh_cb.kdev[xx].state);
76#endif
77 }
78
79 /* if no active device match, find a spot for it */
80 for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++) {
81 if (!bta_hh_cb.kdev[xx].in_use) {
82 bdcpy(bta_hh_cb.kdev[xx].addr, bda);
83 break;
84 }
85 }
86/* If device list full, report BTA_HH_IDX_INVALID */
87#if (BTA_HH_DEBUG == TRUE)
88 APPL_TRACE_DEBUG("bta_hh_find_cb:: index = %d while max = %d", xx,
89 BTA_HH_MAX_DEVICE);
The Android Open Source Project5738f832012-12-12 16:00:35 -080090#endif
91
Myles Watsoncd1fd072016-11-09 13:17:43 -080092 if (xx == BTA_HH_MAX_DEVICE) xx = BTA_HH_IDX_INVALID;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080093
Myles Watsoncd1fd072016-11-09 13:17:43 -080094 return xx;
The Android Open Source Project5738f832012-12-12 16:00:35 -080095}
96
97/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080098 *
99 * Function bta_hh_clean_up_kdev
100 *
101 * Description Clean up device control block when device is removed from
102 * manitainace list, and update control block index map.
103 *
104 * Returns void
105 *
106 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800107void bta_hh_clean_up_kdev(tBTA_HH_DEV_CB* p_cb) {
108 uint8_t index;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800109
Myles Watsoncd1fd072016-11-09 13:17:43 -0800110 if (p_cb->hid_handle != BTA_HH_INVALID_HANDLE) {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700111#if (BTA_HH_LE_INCLUDED == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800112 if (p_cb->is_le_device)
113 bta_hh_cb.le_cb_index[BTA_HH_GET_LE_CB_IDX(p_cb->hid_handle)] =
114 BTA_HH_IDX_INVALID;
115 else
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700116#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -0800117 bta_hh_cb.cb_index[p_cb->hid_handle] = BTA_HH_IDX_INVALID;
118 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800119
Myles Watsoncd1fd072016-11-09 13:17:43 -0800120 /* reset device control block */
121 index = p_cb->index; /* Preserve index for this control block */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800122
Myles Watsoncd1fd072016-11-09 13:17:43 -0800123 /* Free buffer for report descriptor info */
124 osi_free_and_reset((void**)&p_cb->dscp_info.descriptor.dsc_list);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800125
Myles Watsoncd1fd072016-11-09 13:17:43 -0800126 memset(p_cb, 0, sizeof(tBTA_HH_DEV_CB)); /* Reset control block */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800127
Myles Watsoncd1fd072016-11-09 13:17:43 -0800128 p_cb->index = index; /* Restore index for this control block */
129 p_cb->state = BTA_HH_IDLE_ST;
130 p_cb->hid_handle = BTA_HH_INVALID_HANDLE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800131}
132/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800133 *
134 * Function bta_hh_update_di_info
135 *
136 * Description Maintain a known device list for BTA HH.
137 *
138 * Returns void
139 *
140 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800141void bta_hh_update_di_info(tBTA_HH_DEV_CB* p_cb, uint16_t vendor_id,
142 uint16_t product_id, uint16_t version,
Myles Watsond628a062016-10-27 10:02:37 -0700143#if (BTA_HH_LE_INCLUDED == TRUE)
144 uint8_t flag)
145#else
146 UNUSED_ATTR uint8_t flag)
147#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800148{
Marie Janssene9e58ce2016-06-17 14:12:17 -0700149#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800150 APPL_TRACE_DEBUG("vendor_id = 0x%2x product_id = 0x%2x version = 0x%2x",
151 vendor_id, product_id, version);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800152#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -0800153 p_cb->dscp_info.vendor_id = vendor_id;
154 p_cb->dscp_info.product_id = product_id;
155 p_cb->dscp_info.version = version;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700156#if (BTA_HH_LE_INCLUDED == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800157 p_cb->dscp_info.flag = flag;
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700158#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800159}
160/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800161 *
162 * Function bta_hh_add_device_to_list
163 *
164 * Description Maintain a known device list for BTA HH.
165 *
166 * Returns void
167 *
168 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800169void bta_hh_add_device_to_list(tBTA_HH_DEV_CB* p_cb, uint8_t handle,
Marie Janssene9e58ce2016-06-17 14:12:17 -0700170 uint16_t attr_mask,
Myles Watsoncd1fd072016-11-09 13:17:43 -0800171 tHID_DEV_DSCP_INFO* p_dscp_info,
172 uint8_t sub_class, uint16_t ssr_max_latency,
173 uint16_t ssr_min_tout, uint8_t app_id) {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700174#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800175 APPL_TRACE_DEBUG("subclass = 0x%2x", sub_class);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800176#endif
177
Myles Watsoncd1fd072016-11-09 13:17:43 -0800178 p_cb->hid_handle = handle;
179 p_cb->in_use = true;
180 p_cb->attr_mask = attr_mask;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800181
Myles Watsoncd1fd072016-11-09 13:17:43 -0800182 p_cb->sub_class = sub_class;
183 p_cb->app_id = app_id;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800184
Myles Watsoncd1fd072016-11-09 13:17:43 -0800185 p_cb->dscp_info.ssr_max_latency = ssr_max_latency;
186 p_cb->dscp_info.ssr_min_tout = ssr_min_tout;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800187
Myles Watsoncd1fd072016-11-09 13:17:43 -0800188 /* store report descriptor info */
189 if (p_dscp_info) {
190 osi_free_and_reset((void**)&p_cb->dscp_info.descriptor.dsc_list);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800191
Myles Watsoncd1fd072016-11-09 13:17:43 -0800192 if (p_dscp_info->dl_len) {
193 p_cb->dscp_info.descriptor.dsc_list =
194 (uint8_t*)osi_malloc(p_dscp_info->dl_len);
195 p_cb->dscp_info.descriptor.dl_len = p_dscp_info->dl_len;
196 memcpy(p_cb->dscp_info.descriptor.dsc_list, p_dscp_info->dsc_list,
197 p_dscp_info->dl_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800198 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800199 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800200}
201
202/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800203 *
204 * Function bta_hh_tod_spt
205 *
206 * Description Check to see if this type of device is supported
207 *
208 * Returns
209 *
210 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800211bool bta_hh_tod_spt(tBTA_HH_DEV_CB* p_cb, uint8_t sub_class) {
212 uint8_t xx;
213 uint8_t cod = (sub_class >> 2); /* lower two bits are reserved */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800214
Myles Watsoncd1fd072016-11-09 13:17:43 -0800215 for (xx = 0; xx < p_bta_hh_cfg->max_devt_spt; xx++) {
216 if (cod == (uint8_t)p_bta_hh_cfg->p_devt_list[xx].tod) {
217 p_cb->app_id = p_bta_hh_cfg->p_devt_list[xx].app_id;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700218#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800219 APPL_TRACE_EVENT("bta_hh_tod_spt sub_class:0x%x supported", sub_class);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800220#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -0800221 return true;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800222 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800223 }
Marie Janssene9e58ce2016-06-17 14:12:17 -0700224#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800225 APPL_TRACE_EVENT("bta_hh_tod_spt sub_class:0x%x NOT supported", sub_class);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800226#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -0800227 return false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800228}
229
The Android Open Source Project5738f832012-12-12 16:00:35 -0800230/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800231 *
232 * Function bta_hh_parse_keybd_rpt
233 *
234 * Description This utility function parse a boot mode keyboard report.
235 *
236 * Returns void
237 *
238 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800239void bta_hh_parse_keybd_rpt(tBTA_HH_BOOT_RPT* p_kb_data, uint8_t* p_report,
240 uint16_t report_len) {
241 tBTA_HH_KB_CB* p_kb = &bta_hh_cb.kb_cb;
242 tBTA_HH_KEYBD_RPT* p_data = &p_kb_data->data_rpt.keybd_rpt;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800243
Myles Watsoncd1fd072016-11-09 13:17:43 -0800244 uint8_t this_char, ctl_shift;
245 uint16_t xx, yy, key_idx = 0;
246 uint8_t this_report[BTA_HH_MAX_RPT_CHARS];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800247
Marie Janssene9e58ce2016-06-17 14:12:17 -0700248#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800249 APPL_TRACE_DEBUG("bta_hh_parse_keybd_rpt: (report=%p, report_len=%d) called",
250 p_report, report_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800251#endif
252
Myles Watsoncd1fd072016-11-09 13:17:43 -0800253 if (report_len < 2) return;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800254
Myles Watsoncd1fd072016-11-09 13:17:43 -0800255 ctl_shift = *p_report++;
256 report_len--;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800257
Myles Watsoncd1fd072016-11-09 13:17:43 -0800258 if (report_len > BTA_HH_MAX_RPT_CHARS) report_len = BTA_HH_MAX_RPT_CHARS;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800259
Myles Watsoncd1fd072016-11-09 13:17:43 -0800260 memset(this_report, 0, BTA_HH_MAX_RPT_CHARS);
261 memset(p_data, 0, sizeof(tBTA_HH_KEYBD_RPT));
262 memcpy(this_report, p_report, report_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800263
Myles Watsoncd1fd072016-11-09 13:17:43 -0800264 /* Take care of shift, control, GUI and alt, modifier keys */
265 for (xx = 0; xx < BTA_HH_MOD_MAX_KEY; xx++) {
266 if (ctl_shift & bta_hh_mod_key_mask[xx]) {
267 APPL_TRACE_DEBUG("Mod Key[%02x] pressed", bta_hh_mod_key_mask[xx]);
268 p_kb->mod_key[xx] = true;
269 } else if (p_kb->mod_key[xx]) {
270 p_kb->mod_key[xx] = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800271 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800272 /* control key flag is set */
273 p_data->mod_key[xx] = p_kb->mod_key[xx];
274 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800275
Myles Watsoncd1fd072016-11-09 13:17:43 -0800276 /***************************************************************************/
277 /* First step is to remove all characters we saw in the last report */
278 /***************************************************************************/
279 for (xx = 0; xx < report_len; xx++) {
280 for (yy = 0; yy < BTA_HH_MAX_RPT_CHARS; yy++) {
281 if (this_report[xx] == p_kb->last_report[yy]) {
282 this_report[xx] = 0;
283 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800284 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800285 }
286 /***************************************************************************/
287 /* Now, process all the characters in the report, up to 6 keycodes */
288 /***************************************************************************/
289 for (xx = 0; xx < report_len; xx++) {
Marie Janssene9e58ce2016-06-17 14:12:17 -0700290#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800291 APPL_TRACE_DEBUG("this_char = %02x", this_report[xx]);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800292#endif
Marie Janssenf33b6f42016-11-22 15:01:42 -0800293 this_char = this_report[xx];
294 if (this_char == 0) continue;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800295 /* take the key code as the report data */
296 if (this_report[xx] == BTA_HH_KB_CAPS_LOCK)
297 p_kb->caps_lock = p_kb->caps_lock ? false : true;
298 else if (this_report[xx] == BTA_HH_KB_NUM_LOCK)
299 p_kb->num_lock = p_kb->num_lock ? false : true;
300 else
301 p_data->this_char[key_idx++] = this_char;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800302
Marie Janssene9e58ce2016-06-17 14:12:17 -0700303#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800304 APPL_TRACE_DEBUG("found keycode %02x ", this_report[xx]);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800305#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -0800306 p_data->caps_lock = p_kb->caps_lock;
307 p_data->num_lock = p_kb->num_lock;
308 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800309
Myles Watsoncd1fd072016-11-09 13:17:43 -0800310 memset(p_kb->last_report, 0, BTA_HH_MAX_RPT_CHARS);
311 memcpy(p_kb->last_report, p_report, report_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800312
Myles Watsoncd1fd072016-11-09 13:17:43 -0800313 return;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800314}
315
316/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800317 *
318 * Function bta_hh_parse_mice_rpt
319 *
320 * Description This utility function parse a boot mode mouse report.
321 *
322 * Returns void
323 *
324 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800325void bta_hh_parse_mice_rpt(tBTA_HH_BOOT_RPT* p_mice_data, uint8_t* p_report,
326 uint16_t report_len) {
327 tBTA_HH_MICE_RPT* p_data = &p_mice_data->data_rpt.mice_rpt;
Marie Janssene9e58ce2016-06-17 14:12:17 -0700328#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800329 uint8_t xx;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800330
Myles Watsoncd1fd072016-11-09 13:17:43 -0800331 APPL_TRACE_DEBUG(
332 "bta_hh_parse_mice_rpt: bta_keybd_rpt_rcvd(report=%p, \
333 report_len=%d) called",
334 p_report, report_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800335#endif
336
Myles Watsoncd1fd072016-11-09 13:17:43 -0800337 if (report_len < 3) return;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800338
Myles Watsoncd1fd072016-11-09 13:17:43 -0800339 if (report_len > BTA_HH_MAX_RPT_CHARS) report_len = BTA_HH_MAX_RPT_CHARS;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800340
Marie Janssene9e58ce2016-06-17 14:12:17 -0700341#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800342 for (xx = 0; xx < report_len; xx++) {
343 APPL_TRACE_DEBUG("this_char = %02x", p_report[xx]);
344 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800345#endif
346
Myles Watsoncd1fd072016-11-09 13:17:43 -0800347 /* only first bytes lower 3 bits valid */
348 p_data->mouse_button = (p_report[0] & 0x07);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800349
Myles Watsoncd1fd072016-11-09 13:17:43 -0800350 /* x displacement */
351 p_data->delta_x = p_report[1];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800352
Myles Watsoncd1fd072016-11-09 13:17:43 -0800353 /* y displacement */
354 p_data->delta_y = p_report[2];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800355
Marie Janssene9e58ce2016-06-17 14:12:17 -0700356#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800357 APPL_TRACE_DEBUG("mice button: 0x%2x", p_data->mouse_button);
358 APPL_TRACE_DEBUG("mice move: x = %d y = %d", p_data->delta_x,
359 p_data->delta_y);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800360#endif
361
Myles Watsoncd1fd072016-11-09 13:17:43 -0800362 return;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800363}
364
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800365/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800366 *
367 * Function bta_hh_read_ssr_param
368 *
369 * Description Read the SSR Parameter for the remote device
370 *
371 * Returns tBTA_HH_STATUS operation status
372 *
373 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800374tBTA_HH_STATUS bta_hh_read_ssr_param(BD_ADDR bd_addr, uint16_t* p_max_ssr_lat,
375 uint16_t* p_min_ssr_tout) {
376 tBTA_HH_STATUS status = BTA_HH_ERR;
377 tBTA_HH_CB* p_cb = &bta_hh_cb;
378 uint8_t i;
379 uint16_t ssr_max_latency;
380 for (i = 0; i < BTA_HH_MAX_KNOWN; i++) {
381 if (memcmp(p_cb->kdev[i].addr, bd_addr, BD_ADDR_LEN) == 0) {
382 /* if remote device does not have HIDSSRHostMaxLatency attribute in SDP,
383 set SSR max latency default value here. */
384 if (p_cb->kdev[i].dscp_info.ssr_max_latency == HID_SSR_PARAM_INVALID) {
385 /* The default is calculated as half of link supervision timeout.*/
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800386
Myles Watsoncd1fd072016-11-09 13:17:43 -0800387 BTM_GetLinkSuperTout(p_cb->kdev[i].addr, &ssr_max_latency);
388 ssr_max_latency = BTA_HH_GET_DEF_SSR_MAX_LAT(ssr_max_latency);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800389
Myles Watsoncd1fd072016-11-09 13:17:43 -0800390 /* per 1.1 spec, if the newly calculated max latency is greater than
391 BTA_HH_SSR_MAX_LATENCY_DEF which is 500ms, use
392 BTA_HH_SSR_MAX_LATENCY_DEF */
393 if (ssr_max_latency > BTA_HH_SSR_MAX_LATENCY_DEF)
394 ssr_max_latency = BTA_HH_SSR_MAX_LATENCY_DEF;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800395
Myles Watsoncd1fd072016-11-09 13:17:43 -0800396 *p_max_ssr_lat = ssr_max_latency;
397 } else
398 *p_max_ssr_lat = p_cb->kdev[i].dscp_info.ssr_max_latency;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800399
Myles Watsoncd1fd072016-11-09 13:17:43 -0800400 if (p_cb->kdev[i].dscp_info.ssr_min_tout == HID_SSR_PARAM_INVALID)
401 *p_min_ssr_tout = BTA_HH_SSR_MIN_TOUT_DEF;
402 else
403 *p_min_ssr_tout = p_cb->kdev[i].dscp_info.ssr_min_tout;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800404
Myles Watsoncd1fd072016-11-09 13:17:43 -0800405 status = BTA_HH_OK;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800406
Myles Watsoncd1fd072016-11-09 13:17:43 -0800407 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800408 }
Myles Watsoncd1fd072016-11-09 13:17:43 -0800409 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800410
Myles Watsoncd1fd072016-11-09 13:17:43 -0800411 return status;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800412}
413
414/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800415 *
416 * Function bta_hh_cleanup_disable
417 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800418 * Description when disable finished, cleanup control block and send
Myles Watson1baaae32016-11-09 14:25:23 -0800419 * callback
Myles Watson8af480e2016-11-09 10:40:23 -0800420 *
421 *
422 * Returns void
423 *
424 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800425void bta_hh_cleanup_disable(tBTA_HH_STATUS status) {
426 uint8_t xx;
427 /* free buffer in CB holding report descriptors */
428 for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++) {
429 osi_free_and_reset(
430 (void**)&bta_hh_cb.kdev[xx].dscp_info.descriptor.dsc_list);
431 }
432 osi_free_and_reset((void**)&bta_hh_cb.p_disc_db);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800433
Hemant Gupta8843cc82014-04-18 12:34:55 +0530434 if (bta_hh_cb.p_cback) {
435 (*bta_hh_cb.p_cback)(BTA_HH_DISABLE_EVT, (tBTA_HH*)&status);
436 /* all connections are down, no waiting for diconnect */
437 memset(&bta_hh_cb, 0, sizeof(tBTA_HH_CB));
438 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800439}
440
441/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800442 *
443 * Function bta_hh_dev_handle_to_cb_idx
444 *
Myles Watsoncd1fd072016-11-09 13:17:43 -0800445 * Description convert a HID device handle to the device control block
Myles Watson1baaae32016-11-09 14:25:23 -0800446 * index.
Myles Watson8af480e2016-11-09 10:40:23 -0800447 *
448 *
449 * Returns uint8_t: index of the device control block.
450 *
451 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800452uint8_t bta_hh_dev_handle_to_cb_idx(uint8_t dev_handle) {
453 uint8_t index = BTA_HH_IDX_INVALID;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800454
Marie Janssene9e58ce2016-06-17 14:12:17 -0700455#if (BTA_HH_LE_INCLUDED == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800456 if (BTA_HH_IS_LE_DEV_HDL(dev_handle)) {
457 if (BTA_HH_IS_LE_DEV_HDL_VALID(dev_handle))
458 index = bta_hh_cb.le_cb_index[BTA_HH_GET_LE_CB_IDX(dev_handle)];
Marie Janssene9e58ce2016-06-17 14:12:17 -0700459#if (BTA_HH_DEBUG == TRUE)
Myles Watsoncd1fd072016-11-09 13:17:43 -0800460 APPL_TRACE_DEBUG("bta_hh_dev_handle_to_cb_idx dev_handle = %d index = %d",
461 dev_handle, index);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700462#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -0800463 } else
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700464#endif
Myles Watsoncd1fd072016-11-09 13:17:43 -0800465 /* regular HID device checking */
466 if (dev_handle < BTA_HH_MAX_KNOWN)
467 index = bta_hh_cb.cb_index[dev_handle];
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800468
Myles Watsoncd1fd072016-11-09 13:17:43 -0800469 return index;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800470}
Marie Janssene9e58ce2016-06-17 14:12:17 -0700471#if (BTA_HH_DEBUG == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800472/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800473 *
474 * Function bta_hh_trace_dev_db
475 *
476 * Description Check to see if this type of device is supported
477 *
478 * Returns
479 *
480 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800481void bta_hh_trace_dev_db(void) {
482 uint8_t xx;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800483
Myles Watsoncd1fd072016-11-09 13:17:43 -0800484 APPL_TRACE_DEBUG("bta_hh_trace_dev_db:: Device DB list********************");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800485
Myles Watsoncd1fd072016-11-09 13:17:43 -0800486 for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++) {
487 APPL_TRACE_DEBUG("kdev[%d] in_use[%d] handle[%d] ", xx,
488 bta_hh_cb.kdev[xx].in_use, bta_hh_cb.kdev[xx].hid_handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800489
Myles Watsoncd1fd072016-11-09 13:17:43 -0800490 APPL_TRACE_DEBUG(
491 "\t\t\t attr_mask[%04x] state [%d] sub_class[%02x] index = %d",
492 bta_hh_cb.kdev[xx].attr_mask, bta_hh_cb.kdev[xx].state,
493 bta_hh_cb.kdev[xx].sub_class, bta_hh_cb.kdev[xx].index);
494 }
495 APPL_TRACE_DEBUG("*********************************************************");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800496}
497#endif
498#endif /* HL_INCLUDED */