1 /****************************************************************************** 2 * 3 * Copyright 2016 The Android Open Source Project 4 * Copyright 2005-2012 Broadcom Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 ******************************************************************************/ 19 20 /****************************************************************************** 21 * 22 * This file contains the HID DEVICE API in the subsystem of BTA. 23 * 24 ******************************************************************************/ 25 26 #include "bt_target.h" 27 28 #if defined(BTA_HD_INCLUDED) && (BTA_HD_INCLUDED == TRUE) 29 30 #include <stdio.h> 31 #include <stdlib.h> 32 #include <string.h> 33 34 #include "bta_hd_api.h" 35 #include "bta_hd_int.h" 36 37 /***************************************************************************** 38 * Constants 39 ****************************************************************************/ 40 41 static const tBTA_SYS_REG bta_hd_reg = {bta_hd_hdl_event, BTA_HdDisable}; 42 43 /******************************************************************************* 44 * 45 * Function BTA_HdEnable 46 * 47 * Description Enables HID device 48 * 49 * Returns void 50 * 51 ******************************************************************************/ 52 void BTA_HdEnable(tBTA_HD_CBACK* p_cback) { 53 APPL_TRACE_API("%s", __func__); 54 55 bta_sys_register(BTA_ID_HD, &bta_hd_reg); 56 57 tBTA_HD_API_ENABLE* p_buf = 58 (tBTA_HD_API_ENABLE*)osi_malloc((uint16_t)sizeof(tBTA_HD_API_ENABLE)); 59 60 memset(p_buf, 0, sizeof(tBTA_HD_API_ENABLE)); 61 62 p_buf->hdr.event = BTA_HD_API_ENABLE_EVT; 63 p_buf->p_cback = p_cback; 64 65 bta_sys_sendmsg(p_buf); 66 } 67 68 /******************************************************************************* 69 * 70 * Function BTA_HdDisable 71 * 72 * Description Disables HID device. 73 * 74 * Returns void 75 * 76 ******************************************************************************/ 77 void BTA_HdDisable(void) { 78 APPL_TRACE_API("%s", __func__); 79 80 bta_sys_deregister(BTA_ID_HD); 81 82 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR)); 83 p_buf->event = BTA_HD_API_DISABLE_EVT; 84 bta_sys_sendmsg(p_buf); 85 } 86 87 /******************************************************************************* 88 * 89 * Function BTA_HdRegisterApp 90 * 91 * Description This function is called when application should be 92 *registered 93 * 94 * Returns void 95 * 96 ******************************************************************************/ 97 extern void BTA_HdRegisterApp(tBTA_HD_APP_INFO* p_app_info, 98 tBTA_HD_QOS_INFO* p_in_qos, 99 tBTA_HD_QOS_INFO* p_out_qos) { 100 APPL_TRACE_API("%s", __func__); 101 102 tBTA_HD_REGISTER_APP* p_buf = 103 (tBTA_HD_REGISTER_APP*)osi_malloc(sizeof(tBTA_HD_REGISTER_APP)); 104 p_buf->hdr.event = BTA_HD_API_REGISTER_APP_EVT; 105 106 if (p_app_info->p_name) { 107 strlcpy(p_buf->name, p_app_info->p_name, BTA_HD_APP_NAME_LEN); 108 } else { 109 p_buf->name[0] = '\0'; 110 } 111 112 if (p_app_info->p_description) { 113 strlcpy(p_buf->description, p_app_info->p_description, 114 BTA_HD_APP_DESCRIPTION_LEN); 115 } else { 116 p_buf->description[0] = '\0'; 117 } 118 119 if (p_app_info->p_provider) { 120 strlcpy(p_buf->provider, p_app_info->p_provider, BTA_HD_APP_PROVIDER_LEN); 121 } else { 122 p_buf->provider[0] = '\0'; 123 } 124 125 p_buf->subclass = p_app_info->subclass; 126 127 p_buf->d_len = p_app_info->descriptor.dl_len; 128 memcpy(p_buf->d_data, p_app_info->descriptor.dsc_list, 129 p_app_info->descriptor.dl_len); 130 131 // copy qos data as-is 132 memcpy(&p_buf->in_qos, p_in_qos, sizeof(tBTA_HD_QOS_INFO)); 133 memcpy(&p_buf->out_qos, p_out_qos, sizeof(tBTA_HD_QOS_INFO)); 134 135 bta_sys_sendmsg(p_buf); 136 } 137 138 /******************************************************************************* 139 * 140 * Function BTA_HdUnregisterApp 141 * 142 * Description This function is called when application should be 143 *unregistered 144 * 145 * Returns void 146 * 147 ******************************************************************************/ 148 extern void BTA_HdUnregisterApp(void) { 149 APPL_TRACE_API("%s", __func__); 150 151 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR)); 152 p_buf->event = BTA_HD_API_UNREGISTER_APP_EVT; 153 154 bta_sys_sendmsg(p_buf); 155 } 156 157 /******************************************************************************* 158 * 159 * Function BTA_HdSendReport 160 * 161 * Description This function is called when report is to be sent 162 * 163 * Returns void 164 * 165 ******************************************************************************/ 166 extern void BTA_HdSendReport(tBTA_HD_REPORT* p_report) { 167 APPL_TRACE_VERBOSE("%s", __func__); 168 169 if (p_report->len > BTA_HD_REPORT_LEN) { 170 APPL_TRACE_WARNING( 171 "%s, report len (%d) > MTU len (%d), can't send report." 172 " Increase value of HID_DEV_MTU_SIZE to send larger reports", 173 __func__, p_report->len, BTA_HD_REPORT_LEN); 174 return; 175 } 176 177 tBTA_HD_SEND_REPORT* p_buf = 178 (tBTA_HD_SEND_REPORT*)osi_malloc(sizeof(tBTA_HD_SEND_REPORT)); 179 p_buf->hdr.event = BTA_HD_API_SEND_REPORT_EVT; 180 181 p_buf->use_intr = p_report->use_intr; 182 p_buf->type = p_report->type; 183 p_buf->id = p_report->id; 184 p_buf->len = p_report->len; 185 memcpy(p_buf->data, p_report->p_data, p_report->len); 186 187 bta_sys_sendmsg(p_buf); 188 } 189 190 /******************************************************************************* 191 * 192 * Function BTA_HdVirtualCableUnplug 193 * 194 * Description This function is called when VCU shall be sent 195 * 196 * Returns void 197 * 198 ******************************************************************************/ 199 extern void BTA_HdVirtualCableUnplug(void) { 200 APPL_TRACE_API("%s", __func__); 201 202 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR)); 203 p_buf->event = BTA_HD_API_VC_UNPLUG_EVT; 204 205 bta_sys_sendmsg(p_buf); 206 } 207 208 /******************************************************************************* 209 * 210 * Function BTA_HdConnect 211 * 212 * Description This function is called when connection to host shall be 213 *made 214 * 215 * Returns void 216 * 217 ******************************************************************************/ 218 extern void BTA_HdConnect(const RawAddress& addr) { 219 APPL_TRACE_API("%s", __func__); 220 221 tBTA_HD_DEVICE_CTRL* p_buf = 222 (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL)); 223 p_buf->hdr.event = BTA_HD_API_CONNECT_EVT; 224 225 p_buf->addr = addr; 226 227 bta_sys_sendmsg(p_buf); 228 } 229 230 /******************************************************************************* 231 * 232 * Function BTA_HdDisconnect 233 * 234 * Description This function is called when host shall be disconnected 235 * 236 * Returns void 237 * 238 ******************************************************************************/ 239 extern void BTA_HdDisconnect(void) { 240 APPL_TRACE_API("%s", __func__); 241 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR)); 242 p_buf->event = BTA_HD_API_DISCONNECT_EVT; 243 244 bta_sys_sendmsg(p_buf); 245 } 246 247 /******************************************************************************* 248 * 249 * Function BTA_HdAddDevice 250 * 251 * Description This function is called when a device is virtually cabled 252 * 253 * Returns void 254 * 255 ******************************************************************************/ 256 extern void BTA_HdAddDevice(const RawAddress& addr) { 257 APPL_TRACE_API("%s", __func__); 258 tBTA_HD_DEVICE_CTRL* p_buf = 259 (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL)); 260 p_buf->hdr.event = BTA_HD_API_ADD_DEVICE_EVT; 261 262 p_buf->addr = addr; 263 264 bta_sys_sendmsg(p_buf); 265 } 266 267 /******************************************************************************* 268 * 269 * Function BTA_HdRemoveDevice 270 * 271 * Description This function is called when a device is virtually uncabled 272 * 273 * Returns void 274 * 275 ******************************************************************************/ 276 extern void BTA_HdRemoveDevice(const RawAddress& addr) { 277 APPL_TRACE_API("%s", __func__); 278 tBTA_HD_DEVICE_CTRL* p_buf = 279 (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL)); 280 p_buf->hdr.event = BTA_HD_API_REMOVE_DEVICE_EVT; 281 282 p_buf->addr = addr; 283 284 bta_sys_sendmsg(p_buf); 285 } 286 287 /******************************************************************************* 288 * 289 * Function BTA_HdReportError 290 * 291 * Description This function is called when reporting error for set report 292 * 293 * Returns void 294 * 295 ******************************************************************************/ 296 extern void BTA_HdReportError(uint8_t error) { 297 APPL_TRACE_API("%s", __func__); 298 tBTA_HD_REPORT_ERR* p_buf = 299 (tBTA_HD_REPORT_ERR*)osi_malloc(sizeof(tBTA_HD_REPORT_ERR)); 300 p_buf->hdr.event = BTA_HD_API_REPORT_ERROR_EVT; 301 p_buf->error = error; 302 303 bta_sys_sendmsg(p_buf); 304 } 305 306 #endif /* BTA_HD_INCLUDED */ 307