The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 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 Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 21 | #if (BTA_HH_INCLUDED == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 22 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 23 | #include "bta_hh_int.h" |
Myles Watson | d7ffd64 | 2016-10-27 10:27:36 -0700 | [diff] [blame] | 24 | #include "osi/include/osi.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 25 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 26 | /* if SSR max latency is not defined by remote device, set the default value |
| 27 | as half of the link supervision timeout */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 28 | #define BTA_HH_GET_DEF_SSR_MAX_LAT(x) ((x) >> 1) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 29 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 30 | /***************************************************************************** |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 31 | * Constants |
| 32 | ****************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 33 | #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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 37 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 38 | #define BTA_HH_KB_CAPS_LOCK 0x39 /* caps lock */ |
| 39 | #define BTA_HH_KB_NUM_LOCK 0x53 /* num lock */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 40 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 41 | #define BTA_HH_MAX_RPT_CHARS 8 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 42 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 43 | static 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 46 | |
| 47 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 48 | * |
| 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 57 | uint8_t bta_hh_find_cb(BD_ADDR bda) { |
| 58 | uint8_t xx; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 59 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 60 | /* 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 Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 65 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 66 | APPL_TRACE_DEBUG("found kdev_cb[%d] hid_handle = %d ", xx, |
| 67 | bta_hh_cb.kdev[xx].hid_handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 68 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 69 | return xx; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 70 | } |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 71 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 72 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 90 | #endif |
| 91 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 92 | if (xx == BTA_HH_MAX_DEVICE) xx = BTA_HH_IDX_INVALID; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 93 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 94 | return xx; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 98 | * |
| 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 107 | void bta_hh_clean_up_kdev(tBTA_HH_DEV_CB* p_cb) { |
| 108 | uint8_t index; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 109 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 110 | if (p_cb->hid_handle != BTA_HH_INVALID_HANDLE) { |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 111 | #if (BTA_HH_LE_INCLUDED == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 112 | 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 Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 116 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 117 | bta_hh_cb.cb_index[p_cb->hid_handle] = BTA_HH_IDX_INVALID; |
| 118 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 119 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 120 | /* reset device control block */ |
| 121 | index = p_cb->index; /* Preserve index for this control block */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 122 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 123 | /* Free buffer for report descriptor info */ |
| 124 | osi_free_and_reset((void**)&p_cb->dscp_info.descriptor.dsc_list); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 125 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 126 | memset(p_cb, 0, sizeof(tBTA_HH_DEV_CB)); /* Reset control block */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 127 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 128 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 131 | } |
| 132 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 133 | * |
| 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 141 | void bta_hh_update_di_info(tBTA_HH_DEV_CB* p_cb, uint16_t vendor_id, |
| 142 | uint16_t product_id, uint16_t version, |
Myles Watson | d628a06 | 2016-10-27 10:02:37 -0700 | [diff] [blame] | 143 | #if (BTA_HH_LE_INCLUDED == TRUE) |
| 144 | uint8_t flag) |
| 145 | #else |
| 146 | UNUSED_ATTR uint8_t flag) |
| 147 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 148 | { |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 149 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 150 | APPL_TRACE_DEBUG("vendor_id = 0x%2x product_id = 0x%2x version = 0x%2x", |
| 151 | vendor_id, product_id, version); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 152 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 153 | 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 Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 156 | #if (BTA_HH_LE_INCLUDED == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 157 | p_cb->dscp_info.flag = flag; |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 158 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 159 | } |
| 160 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 161 | * |
| 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 169 | void bta_hh_add_device_to_list(tBTA_HH_DEV_CB* p_cb, uint8_t handle, |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 170 | uint16_t attr_mask, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 171 | 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 Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 174 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 175 | APPL_TRACE_DEBUG("subclass = 0x%2x", sub_class); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 176 | #endif |
| 177 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 178 | p_cb->hid_handle = handle; |
| 179 | p_cb->in_use = true; |
| 180 | p_cb->attr_mask = attr_mask; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 181 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 182 | p_cb->sub_class = sub_class; |
| 183 | p_cb->app_id = app_id; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 184 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 185 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 187 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 188 | /* 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 191 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 192 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 198 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 199 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 203 | * |
| 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 211 | bool 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 214 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 215 | 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 Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 218 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 219 | APPL_TRACE_EVENT("bta_hh_tod_spt sub_class:0x%x supported", sub_class); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 220 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 221 | return true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 222 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 223 | } |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 224 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 225 | APPL_TRACE_EVENT("bta_hh_tod_spt sub_class:0x%x NOT supported", sub_class); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 226 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 227 | return false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 228 | } |
| 229 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 230 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 231 | * |
| 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 239 | void 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 243 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 244 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 247 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 248 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 249 | APPL_TRACE_DEBUG("bta_hh_parse_keybd_rpt: (report=%p, report_len=%d) called", |
| 250 | p_report, report_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 251 | #endif |
| 252 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 253 | if (report_len < 2) return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 254 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 255 | ctl_shift = *p_report++; |
| 256 | report_len--; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 257 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 258 | if (report_len > BTA_HH_MAX_RPT_CHARS) report_len = BTA_HH_MAX_RPT_CHARS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 259 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 260 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 263 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 264 | /* 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 271 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 272 | /* control key flag is set */ |
| 273 | p_data->mod_key[xx] = p_kb->mod_key[xx]; |
| 274 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 275 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 276 | /***************************************************************************/ |
| 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 284 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 285 | } |
| 286 | /***************************************************************************/ |
| 287 | /* Now, process all the characters in the report, up to 6 keycodes */ |
| 288 | /***************************************************************************/ |
| 289 | for (xx = 0; xx < report_len; xx++) { |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 290 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 291 | APPL_TRACE_DEBUG("this_char = %02x", this_report[xx]); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 292 | #endif |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 293 | this_char = this_report[xx]; |
| 294 | if (this_char == 0) continue; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 295 | /* 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 302 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 303 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 304 | APPL_TRACE_DEBUG("found keycode %02x ", this_report[xx]); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 305 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 306 | p_data->caps_lock = p_kb->caps_lock; |
| 307 | p_data->num_lock = p_kb->num_lock; |
| 308 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 309 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 310 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 312 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 313 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 317 | * |
| 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 325 | void 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 Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 328 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 329 | uint8_t xx; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 330 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 331 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 335 | #endif |
| 336 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 337 | if (report_len < 3) return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 338 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 339 | if (report_len > BTA_HH_MAX_RPT_CHARS) report_len = BTA_HH_MAX_RPT_CHARS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 340 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 341 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 342 | for (xx = 0; xx < report_len; xx++) { |
| 343 | APPL_TRACE_DEBUG("this_char = %02x", p_report[xx]); |
| 344 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 345 | #endif |
| 346 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 347 | /* only first bytes lower 3 bits valid */ |
| 348 | p_data->mouse_button = (p_report[0] & 0x07); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 349 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 350 | /* x displacement */ |
| 351 | p_data->delta_x = p_report[1]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 352 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 353 | /* y displacement */ |
| 354 | p_data->delta_y = p_report[2]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 355 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 356 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 357 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 360 | #endif |
| 361 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 362 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 365 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 366 | * |
| 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 374 | tBTA_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 Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 386 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 387 | 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 Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 389 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 390 | /* 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 Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 395 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 396 | *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 Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 399 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 400 | 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 Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 404 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 405 | status = BTA_HH_OK; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 406 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 407 | break; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 408 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 409 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 410 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 411 | return status; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 415 | * |
| 416 | * Function bta_hh_cleanup_disable |
| 417 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 418 | * Description when disable finished, cleanup control block and send |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 419 | * callback |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 420 | * |
| 421 | * |
| 422 | * Returns void |
| 423 | * |
| 424 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 425 | void 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 Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 433 | |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame^] | 434 | 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 Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 442 | * |
| 443 | * Function bta_hh_dev_handle_to_cb_idx |
| 444 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 445 | * Description convert a HID device handle to the device control block |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 446 | * index. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 447 | * |
| 448 | * |
| 449 | * Returns uint8_t: index of the device control block. |
| 450 | * |
| 451 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 452 | uint8_t bta_hh_dev_handle_to_cb_idx(uint8_t dev_handle) { |
| 453 | uint8_t index = BTA_HH_IDX_INVALID; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 454 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 455 | #if (BTA_HH_LE_INCLUDED == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 456 | 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 Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 459 | #if (BTA_HH_DEBUG == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 460 | APPL_TRACE_DEBUG("bta_hh_dev_handle_to_cb_idx dev_handle = %d index = %d", |
| 461 | dev_handle, index); |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 462 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 463 | } else |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 464 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 465 | /* regular HID device checking */ |
| 466 | if (dev_handle < BTA_HH_MAX_KNOWN) |
| 467 | index = bta_hh_cb.cb_index[dev_handle]; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 468 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 469 | return index; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 470 | } |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 471 | #if (BTA_HH_DEBUG == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 472 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 473 | * |
| 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 Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 481 | void bta_hh_trace_dev_db(void) { |
| 482 | uint8_t xx; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 483 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 484 | APPL_TRACE_DEBUG("bta_hh_trace_dev_db:: Device DB list********************"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 485 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 486 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 489 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 490 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 496 | } |
| 497 | #endif |
| 498 | #endif /* HL_INCLUDED */ |