1 /******************************************************************************
3 * Copyright 2016 The Android Open Source Project
4 * Copyright 2005-2012 Broadcom Corporation
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 ******************************************************************************/
20 /******************************************************************************
22 * This file contains the HID DEVICE API in the subsystem of BTA.
24 ******************************************************************************/
26 #include "bt_target.h"
28 #if defined(BTA_HD_INCLUDED) && (BTA_HD_INCLUDED == TRUE)
35 #include "bta_hd_api.h"
36 #include "bta_hd_int.h"
38 /*****************************************************************************
40 ****************************************************************************/
42 static const tBTA_SYS_REG bta_hd_reg = {bta_hd_hdl_event, BTA_HdDisable};
44 /*******************************************************************************
46 * Function BTA_HdEnable
48 * Description Enables HID device
52 ******************************************************************************/
53 void BTA_HdEnable(tBTA_HD_CBACK* p_cback) {
54 APPL_TRACE_API("%s", __func__);
56 bta_sys_register(BTA_ID_HD, &bta_hd_reg);
58 tBTA_HD_API_ENABLE* p_buf =
59 (tBTA_HD_API_ENABLE*)osi_malloc((uint16_t)sizeof(tBTA_HD_API_ENABLE));
61 memset(p_buf, 0, sizeof(tBTA_HD_API_ENABLE));
63 p_buf->hdr.event = BTA_HD_API_ENABLE_EVT;
64 p_buf->p_cback = p_cback;
66 bta_sys_sendmsg(p_buf);
69 /*******************************************************************************
71 * Function BTA_HdDisable
73 * Description Disables HID device.
77 ******************************************************************************/
78 void BTA_HdDisable(void) {
79 APPL_TRACE_API("%s", __func__);
81 bta_sys_deregister(BTA_ID_HD);
83 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
84 p_buf->event = BTA_HD_API_DISABLE_EVT;
85 bta_sys_sendmsg(p_buf);
88 /*******************************************************************************
90 * Function BTA_HdRegisterApp
92 * Description This function is called when application should be
97 ******************************************************************************/
98 extern void BTA_HdRegisterApp(tBTA_HD_APP_INFO* p_app_info,
99 tBTA_HD_QOS_INFO* p_in_qos,
100 tBTA_HD_QOS_INFO* p_out_qos) {
101 APPL_TRACE_API("%s", __func__);
103 tBTA_HD_REGISTER_APP* p_buf =
104 (tBTA_HD_REGISTER_APP*)osi_malloc(sizeof(tBTA_HD_REGISTER_APP));
105 p_buf->hdr.event = BTA_HD_API_REGISTER_APP_EVT;
107 if (p_app_info->p_name) {
108 strlcpy(p_buf->name, p_app_info->p_name, BTA_HD_APP_NAME_LEN);
110 p_buf->name[0] = '\0';
113 if (p_app_info->p_description) {
114 strlcpy(p_buf->description, p_app_info->p_description,
115 BTA_HD_APP_DESCRIPTION_LEN);
117 p_buf->description[0] = '\0';
120 if (p_app_info->p_provider) {
121 strlcpy(p_buf->provider, p_app_info->p_provider, BTA_HD_APP_PROVIDER_LEN);
123 p_buf->provider[0] = '\0';
126 p_buf->subclass = p_app_info->subclass;
128 if (p_app_info->descriptor.dl_len > BTA_HD_APP_DESCRIPTOR_LEN) {
129 p_app_info->descriptor.dl_len = BTA_HD_APP_DESCRIPTOR_LEN;
130 android_errorWriteLog(0x534e4554, "113111784");
132 p_buf->d_len = p_app_info->descriptor.dl_len;
133 memcpy(p_buf->d_data, p_app_info->descriptor.dsc_list,
134 p_app_info->descriptor.dl_len);
136 // copy qos data as-is
137 memcpy(&p_buf->in_qos, p_in_qos, sizeof(tBTA_HD_QOS_INFO));
138 memcpy(&p_buf->out_qos, p_out_qos, sizeof(tBTA_HD_QOS_INFO));
140 bta_sys_sendmsg(p_buf);
143 /*******************************************************************************
145 * Function BTA_HdUnregisterApp
147 * Description This function is called when application should be
152 ******************************************************************************/
153 extern void BTA_HdUnregisterApp(void) {
154 APPL_TRACE_API("%s", __func__);
156 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
157 p_buf->event = BTA_HD_API_UNREGISTER_APP_EVT;
159 bta_sys_sendmsg(p_buf);
162 /*******************************************************************************
164 * Function BTA_HdSendReport
166 * Description This function is called when report is to be sent
170 ******************************************************************************/
171 extern void BTA_HdSendReport(tBTA_HD_REPORT* p_report) {
172 APPL_TRACE_VERBOSE("%s", __func__);
174 if (p_report->len > BTA_HD_REPORT_LEN) {
176 "%s, report len (%d) > MTU len (%d), can't send report."
177 " Increase value of HID_DEV_MTU_SIZE to send larger reports",
178 __func__, p_report->len, BTA_HD_REPORT_LEN);
182 tBTA_HD_SEND_REPORT* p_buf =
183 (tBTA_HD_SEND_REPORT*)osi_malloc(sizeof(tBTA_HD_SEND_REPORT));
184 p_buf->hdr.event = BTA_HD_API_SEND_REPORT_EVT;
186 p_buf->use_intr = p_report->use_intr;
187 p_buf->type = p_report->type;
188 p_buf->id = p_report->id;
189 p_buf->len = p_report->len;
190 memcpy(p_buf->data, p_report->p_data, p_report->len);
192 bta_sys_sendmsg(p_buf);
195 /*******************************************************************************
197 * Function BTA_HdVirtualCableUnplug
199 * Description This function is called when VCU shall be sent
203 ******************************************************************************/
204 extern void BTA_HdVirtualCableUnplug(void) {
205 APPL_TRACE_API("%s", __func__);
207 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
208 p_buf->event = BTA_HD_API_VC_UNPLUG_EVT;
210 bta_sys_sendmsg(p_buf);
213 /*******************************************************************************
215 * Function BTA_HdConnect
217 * Description This function is called when connection to host shall be
222 ******************************************************************************/
223 extern void BTA_HdConnect(const RawAddress& addr) {
224 APPL_TRACE_API("%s", __func__);
226 tBTA_HD_DEVICE_CTRL* p_buf =
227 (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL));
228 p_buf->hdr.event = BTA_HD_API_CONNECT_EVT;
232 bta_sys_sendmsg(p_buf);
235 /*******************************************************************************
237 * Function BTA_HdDisconnect
239 * Description This function is called when host shall be disconnected
243 ******************************************************************************/
244 extern void BTA_HdDisconnect(void) {
245 APPL_TRACE_API("%s", __func__);
246 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
247 p_buf->event = BTA_HD_API_DISCONNECT_EVT;
249 bta_sys_sendmsg(p_buf);
252 /*******************************************************************************
254 * Function BTA_HdAddDevice
256 * Description This function is called when a device is virtually cabled
260 ******************************************************************************/
261 extern void BTA_HdAddDevice(const RawAddress& addr) {
262 APPL_TRACE_API("%s", __func__);
263 tBTA_HD_DEVICE_CTRL* p_buf =
264 (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL));
265 p_buf->hdr.event = BTA_HD_API_ADD_DEVICE_EVT;
269 bta_sys_sendmsg(p_buf);
272 /*******************************************************************************
274 * Function BTA_HdRemoveDevice
276 * Description This function is called when a device is virtually uncabled
280 ******************************************************************************/
281 extern void BTA_HdRemoveDevice(const RawAddress& addr) {
282 APPL_TRACE_API("%s", __func__);
283 tBTA_HD_DEVICE_CTRL* p_buf =
284 (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL));
285 p_buf->hdr.event = BTA_HD_API_REMOVE_DEVICE_EVT;
289 bta_sys_sendmsg(p_buf);
292 /*******************************************************************************
294 * Function BTA_HdReportError
296 * Description This function is called when reporting error for set report
300 ******************************************************************************/
301 extern void BTA_HdReportError(uint8_t error) {
302 APPL_TRACE_API("%s", __func__);
303 tBTA_HD_REPORT_ERR* p_buf =
304 (tBTA_HD_REPORT_ERR*)osi_malloc(sizeof(tBTA_HD_REPORT_ERR));
305 p_buf->hdr.event = BTA_HD_API_REPORT_ERROR_EVT;
306 p_buf->error = error;
308 bta_sys_sendmsg(p_buf);
311 #endif /* BTA_HD_INCLUDED */