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 | |
| 19 | /****************************************************************************** |
| 20 | * |
| 21 | * This file contains the HID HOST API in the subsystem of BTA. |
| 22 | * |
| 23 | ******************************************************************************/ |
| 24 | |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 25 | #define LOG_TAG "bt_bta_hh" |
| 26 | |
| 27 | #include "bta_hh_api.h" |
| 28 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 29 | #include "bt_target.h" |
| 30 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 31 | #if (BTA_HH_INCLUDED == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 32 | |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 33 | #include <stdio.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 34 | #include <stdlib.h> |
| 35 | #include <string.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 36 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 37 | #include "bta_hh_int.h" |
| 38 | #include "l2c_api.h" |
Chris Manton | f802700 | 2015-03-12 09:22:48 -0700 | [diff] [blame] | 39 | #include "osi/include/log.h" |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 40 | #include "utl.h" |
Chris Manton | f802700 | 2015-03-12 09:22:48 -0700 | [diff] [blame] | 41 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 42 | /***************************************************************************** |
| 43 | ** Constants |
| 44 | *****************************************************************************/ |
| 45 | |
| 46 | static const tBTA_SYS_REG bta_hh_reg = |
| 47 | { |
| 48 | bta_hh_hdl_event, |
| 49 | BTA_HhDisable |
| 50 | }; |
| 51 | |
| 52 | /******************************************************************************* |
| 53 | ** |
| 54 | ** Function BTA_HhEnable |
| 55 | ** |
| 56 | ** Description Enable the HID host. This function must be called before |
| 57 | ** any other functions in the HID host API are called. When the |
| 58 | ** enable operation is complete the callback function will be |
| 59 | ** called with BTA_HH_ENABLE_EVT. |
| 60 | ** |
| 61 | ** |
| 62 | ** Returns void |
| 63 | ** |
| 64 | *******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 65 | void BTA_HhEnable(tBTA_SEC sec_mask, tBTA_HH_CBACK *p_cback) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 66 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 67 | tBTA_HH_API_ENABLE *p_buf = |
| 68 | (tBTA_HH_API_ENABLE *)osi_calloc(sizeof(tBTA_HH_API_ENABLE)); |
| 69 | |
| 70 | LOG_INFO(LOG_TAG, "%s sec_mask:0x%x p_cback:%p", __func__, sec_mask, |
| 71 | p_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 72 | |
| 73 | /* register with BTA system manager */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 74 | bta_sys_register(BTA_ID_HH, &bta_hh_reg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 75 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 76 | p_buf->hdr.event = BTA_HH_API_ENABLE_EVT; |
| 77 | p_buf->p_cback = p_cback; |
| 78 | p_buf->sec_mask = sec_mask; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 79 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 80 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /******************************************************************************* |
| 84 | ** |
| 85 | ** Function BTA_HhDisable |
| 86 | ** |
| 87 | ** Description Disable the HID host. If the server is currently |
| 88 | ** connected, the connection will be closed. |
| 89 | ** |
| 90 | ** Returns void |
| 91 | ** |
| 92 | *******************************************************************************/ |
| 93 | void BTA_HhDisable(void) |
| 94 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 95 | BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 96 | |
| 97 | bta_sys_deregister(BTA_ID_HH); |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 98 | p_buf->event = BTA_HH_API_DISABLE_EVT; |
| 99 | |
| 100 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /******************************************************************************* |
| 104 | ** |
| 105 | ** Function BTA_HhClose |
| 106 | ** |
| 107 | ** Description Disconnect a connection. |
| 108 | ** |
| 109 | ** Returns void |
| 110 | ** |
| 111 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 112 | void BTA_HhClose(uint8_t dev_handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 113 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 114 | BT_HDR *p_buf = (BT_HDR *)osi_calloc(sizeof(BT_HDR)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 115 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 116 | p_buf->event = BTA_HH_API_CLOSE_EVT; |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 117 | p_buf->layer_specific = (uint16_t)dev_handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 118 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 119 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /******************************************************************************* |
| 123 | ** |
| 124 | ** Function BTA_HhOpen |
| 125 | ** |
| 126 | ** Description Connect to a device of specified BD address in specified |
| 127 | ** protocol mode and security level. |
| 128 | ** |
| 129 | ** Returns void |
| 130 | ** |
| 131 | *******************************************************************************/ |
| 132 | void BTA_HhOpen(BD_ADDR dev_bda, tBTA_HH_PROTO_MODE mode, tBTA_SEC sec_mask) |
| 133 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 134 | tBTA_HH_API_CONN *p_buf = |
| 135 | (tBTA_HH_API_CONN *)osi_calloc(sizeof(tBTA_HH_API_CONN)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 136 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 137 | p_buf->hdr.event = BTA_HH_API_OPEN_EVT; |
| 138 | p_buf->hdr.layer_specific = BTA_HH_INVALID_HANDLE; |
| 139 | p_buf->sec_mask = sec_mask; |
| 140 | p_buf->mode = mode; |
| 141 | bdcpy(p_buf->bd_addr, dev_bda); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 142 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 143 | bta_sys_sendmsg((void *)p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /******************************************************************************* |
| 147 | ** |
| 148 | ** Function bta_hh_snd_write_dev |
| 149 | ** |
| 150 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 151 | static void bta_hh_snd_write_dev(uint8_t dev_handle, uint8_t t_type, uint8_t param, |
| 152 | uint16_t data, uint8_t rpt_id, BT_HDR *p_data) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 153 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 154 | tBTA_HH_CMD_DATA *p_buf = |
| 155 | (tBTA_HH_CMD_DATA *)osi_calloc(sizeof(tBTA_HH_CMD_DATA)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 156 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 157 | p_buf->hdr.event = BTA_HH_API_WRITE_DEV_EVT; |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 158 | p_buf->hdr.layer_specific = (uint16_t)dev_handle; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 159 | p_buf->t_type = t_type; |
| 160 | p_buf->data = data; |
| 161 | p_buf->param = param; |
| 162 | p_buf->p_data = p_data; |
| 163 | p_buf->rpt_id = rpt_id; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 164 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 165 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 166 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 167 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 168 | /******************************************************************************* |
| 169 | ** |
| 170 | ** Function BTA_HhSetReport |
| 171 | ** |
| 172 | ** Description send SET_REPORT to device. |
| 173 | ** |
| 174 | ** Parameter dev_handle: device handle |
| 175 | ** r_type: report type, could be BTA_HH_RPTT_OUTPUT or |
| 176 | ** BTA_HH_RPTT_FEATURE. |
| 177 | ** Returns void |
| 178 | ** |
| 179 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 180 | void BTA_HhSetReport(uint8_t dev_handle, tBTA_HH_RPT_TYPE r_type, BT_HDR *p_data) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 181 | { |
| 182 | bta_hh_snd_write_dev(dev_handle, HID_TRANS_SET_REPORT, r_type, 0, 0, p_data); |
| 183 | } |
| 184 | /******************************************************************************* |
| 185 | ** |
| 186 | ** Function BTA_HhGetReport |
| 187 | ** |
| 188 | ** Description Send a GET_REPORT to HID device. |
| 189 | ** |
| 190 | ** Returns void |
| 191 | ** |
| 192 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 193 | void BTA_HhGetReport(uint8_t dev_handle, tBTA_HH_RPT_TYPE r_type, uint8_t rpt_id, uint16_t buf_size) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 194 | { |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 195 | uint8_t param = (buf_size) ? (r_type | 0x08) : r_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 196 | |
| 197 | bta_hh_snd_write_dev(dev_handle, HID_TRANS_GET_REPORT, param, |
| 198 | buf_size, rpt_id, NULL); |
| 199 | } |
| 200 | /******************************************************************************* |
| 201 | ** |
| 202 | ** Function BTA_HhSetProtoMode |
| 203 | ** |
| 204 | ** Description This function set the protocol mode at specified HID handle |
| 205 | ** |
| 206 | ** Returns void |
| 207 | ** |
| 208 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 209 | void BTA_HhSetProtoMode(uint8_t dev_handle, tBTA_HH_PROTO_MODE p_type) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 210 | { |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 211 | bta_hh_snd_write_dev(dev_handle, HID_TRANS_SET_PROTOCOL, (uint8_t)p_type, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 212 | 0, 0, NULL); |
| 213 | } |
| 214 | /******************************************************************************* |
| 215 | ** |
| 216 | ** Function BTA_HhGetProtoMode |
| 217 | ** |
| 218 | ** Description This function get protocol mode information. |
| 219 | ** |
| 220 | ** Returns void |
| 221 | ** |
| 222 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 223 | void BTA_HhGetProtoMode(uint8_t dev_handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 224 | { |
| 225 | bta_hh_snd_write_dev(dev_handle, HID_TRANS_GET_PROTOCOL, 0, 0, 0, NULL); |
| 226 | } |
| 227 | /******************************************************************************* |
| 228 | ** |
| 229 | ** Function BTA_HhSetIdle |
| 230 | ** |
| 231 | ** Description send SET_IDLE to device. |
| 232 | ** |
| 233 | ** Returns void |
| 234 | ** |
| 235 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 236 | void BTA_HhSetIdle(uint8_t dev_handle, uint16_t idle_rate) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 237 | { |
| 238 | bta_hh_snd_write_dev(dev_handle, HID_TRANS_SET_IDLE, 0, idle_rate, 0, NULL); |
| 239 | } |
| 240 | |
| 241 | /******************************************************************************* |
| 242 | ** |
| 243 | ** Function BTA_HhGetIdle |
| 244 | ** |
| 245 | ** Description Send a GET_IDLE from HID device. |
| 246 | ** |
| 247 | ** Returns void |
| 248 | ** |
| 249 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 250 | void BTA_HhGetIdle(uint8_t dev_handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 251 | { |
| 252 | bta_hh_snd_write_dev(dev_handle, HID_TRANS_GET_IDLE, 0, 0, 0, NULL); |
| 253 | } |
| 254 | /******************************************************************************* |
| 255 | ** |
| 256 | ** Function BTA_HhSendCtrl |
| 257 | ** |
| 258 | ** Description Send a control command to HID device. |
| 259 | ** |
| 260 | ** Returns void |
| 261 | ** |
| 262 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 263 | void BTA_HhSendCtrl(uint8_t dev_handle, tBTA_HH_TRANS_CTRL_TYPE c_type) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 264 | { |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 265 | bta_hh_snd_write_dev(dev_handle, HID_TRANS_CONTROL, (uint8_t)c_type, 0, 0, NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 266 | } |
| 267 | /******************************************************************************* |
| 268 | ** |
| 269 | ** Function BTA_HhSendData |
| 270 | ** |
| 271 | ** Description This function send DATA transaction to HID device. |
| 272 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 273 | ** Parameter dev_handle: device handle |
| 274 | ** dev_bda: remote device address |
| 275 | ** p_data: data to be sent in the DATA transaction; or |
| 276 | ** the data to be write into the Output Report of a LE HID |
| 277 | ** device. The report is identified the report ID which is |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 278 | ** the value of the byte (uint8_t *)(p_buf + 1) + p_buf->offset. |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 279 | ** p_data->layer_specific needs to be set to the report type, |
| 280 | ** it can be OUTPUT report, or FEATURE report. |
| 281 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 282 | ** Returns void |
| 283 | ** |
| 284 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 285 | void BTA_HhSendData(uint8_t dev_handle, BD_ADDR dev_bda, BT_HDR *p_data) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 286 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 287 | UNUSED(dev_bda); |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 288 | #if (BTA_HH_LE_INCLUDED == TRUE) |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 289 | if (p_data->layer_specific != BTA_HH_RPTT_OUTPUT) |
| 290 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 291 | APPL_TRACE_ERROR("ERROR! Wrong report type! Write Command only valid for output report!"); |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 292 | return; |
| 293 | } |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 294 | #endif |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 295 | bta_hh_snd_write_dev(dev_handle, HID_TRANS_DATA, (uint8_t)p_data->layer_specific, 0, 0, p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /******************************************************************************* |
| 299 | ** |
| 300 | ** Function BTA_HhGetDscpInfo |
| 301 | ** |
| 302 | ** Description Get HID device report descriptor |
| 303 | ** |
| 304 | ** Returns void |
| 305 | ** |
| 306 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 307 | void BTA_HhGetDscpInfo(uint8_t dev_handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 308 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 309 | BT_HDR *p_buf = (BT_HDR *)osi_calloc(sizeof(BT_HDR)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 310 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 311 | p_buf->event = BTA_HH_API_GET_DSCP_EVT; |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 312 | p_buf->layer_specific = (uint16_t)dev_handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 313 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 314 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /******************************************************************************* |
| 318 | ** |
| 319 | ** Function BTA_HhAddDev |
| 320 | ** |
| 321 | ** Description Add a virtually cabled device into HID-Host device list |
| 322 | ** to manage and assign a device handle for future API call, |
| 323 | ** host applciation call this API at start-up to initialize its |
| 324 | ** virtually cabled devices. |
| 325 | ** |
| 326 | ** Returns void |
| 327 | ** |
| 328 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 329 | void BTA_HhAddDev(BD_ADDR bda, tBTA_HH_ATTR_MASK attr_mask, uint8_t sub_class, |
| 330 | uint8_t app_id, tBTA_HH_DEV_DSCP_INFO dscp_info) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 331 | { |
Pavlin Radoslavov | cceb430 | 2016-02-05 13:54:43 -0800 | [diff] [blame] | 332 | size_t len = sizeof(tBTA_HH_MAINT_DEV) + dscp_info.descriptor.dl_len; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 333 | tBTA_HH_MAINT_DEV *p_buf = (tBTA_HH_MAINT_DEV *)osi_calloc(len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 334 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 335 | p_buf->hdr.event = BTA_HH_API_MAINT_DEV_EVT; |
| 336 | p_buf->sub_event = BTA_HH_ADD_DEV_EVT; |
| 337 | p_buf->hdr.layer_specific = BTA_HH_INVALID_HANDLE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 338 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 339 | p_buf->attr_mask = (uint16_t) attr_mask; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 340 | p_buf->sub_class = sub_class; |
| 341 | p_buf->app_id = app_id; |
| 342 | bdcpy(p_buf->bda, bda); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 343 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 344 | memcpy(&p_buf->dscp_info, &dscp_info, sizeof(tBTA_HH_DEV_DSCP_INFO)); |
| 345 | if ( dscp_info.descriptor.dl_len != 0 && dscp_info.descriptor.dsc_list) { |
| 346 | p_buf->dscp_info.descriptor.dl_len = dscp_info.descriptor.dl_len; |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 347 | p_buf->dscp_info.descriptor.dsc_list = (uint8_t *)(p_buf + 1); |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 348 | memcpy(p_buf->dscp_info.descriptor.dsc_list, |
| 349 | dscp_info.descriptor.dsc_list, |
| 350 | dscp_info.descriptor.dl_len); |
| 351 | } else { |
| 352 | p_buf->dscp_info.descriptor.dsc_list = NULL; |
| 353 | p_buf->dscp_info.descriptor.dl_len = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 354 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 355 | |
| 356 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 357 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 358 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 359 | /******************************************************************************* |
| 360 | ** |
| 361 | ** Function BTA_HhRemoveDev |
| 362 | ** |
| 363 | ** Description Remove a device from the HID host devices list. |
| 364 | ** |
| 365 | ** Returns void |
| 366 | ** |
| 367 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 368 | void BTA_HhRemoveDev(uint8_t dev_handle ) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 369 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 370 | tBTA_HH_MAINT_DEV *p_buf = |
| 371 | (tBTA_HH_MAINT_DEV *)osi_calloc(sizeof(tBTA_HH_MAINT_DEV)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 372 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 373 | p_buf->hdr.event = BTA_HH_API_MAINT_DEV_EVT; |
| 374 | p_buf->sub_event = BTA_HH_RMV_DEV_EVT; |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 375 | p_buf->hdr.layer_specific = (uint16_t)dev_handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 376 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 377 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 378 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 379 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 380 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 381 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 382 | /*******************************************************************************/ |
| 383 | /* Utility Function */ |
| 384 | /*******************************************************************************/ |
| 385 | |
| 386 | /******************************************************************************* |
| 387 | ** |
| 388 | ** Function BTA_HhParseBootRpt |
| 389 | ** |
| 390 | ** Description This utility function parse a boot mode report. |
| 391 | ** For keyboard report, report data will carry the keycode max |
| 392 | ** up to 6 key press in one report. Application need to convert |
| 393 | ** the keycode into keypress character according to keyboard |
| 394 | ** language. |
| 395 | ** |
| 396 | ** Returns void |
| 397 | ** |
| 398 | *******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 399 | void BTA_HhParseBootRpt(tBTA_HH_BOOT_RPT *p_data, uint8_t *p_report, |
| 400 | uint16_t report_len) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 401 | { |
| 402 | p_data->dev_type = BTA_HH_DEVT_UNKNOWN; |
| 403 | |
| 404 | if (p_report) |
| 405 | { |
| 406 | /* first byte is report ID */ |
| 407 | switch (p_report[0]) |
| 408 | { |
| 409 | case BTA_HH_KEYBD_RPT_ID: /* key board report ID */ |
| 410 | p_data->dev_type = p_report[0]; |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 411 | bta_hh_parse_keybd_rpt(p_data, p_report + 1, (uint16_t)(report_len -1)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 412 | break; |
| 413 | |
| 414 | case BTA_HH_MOUSE_RPT_ID: /* mouse report ID */ |
| 415 | p_data->dev_type = p_report[0]; |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame^] | 416 | bta_hh_parse_mice_rpt(p_data, p_report + 1, (uint16_t)(report_len - 1)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 417 | break; |
| 418 | |
| 419 | default: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 420 | APPL_TRACE_DEBUG("Unknown boot report: %d", p_report[0]);; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 421 | break; |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | #endif /* BTA_HH_INCLUDED */ |