1 /******************************************************************************
2  *
3  *  Copyright (C) 2016 The Android Open Source Project
4  *  Copyright (C) 2002-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 #ifndef BTA_HD_API_H
20 #define BTA_HD_API_H
21 
22 #include "bta_api.h"
23 #include "stack/hidd_api.h"
24 
25 #if BTA_HD_INCLUDED == TRUE
26 
27 /*****************************************************************************
28  *  Constants and Type Definitions
29  ****************************************************************************/
30 
31 #ifndef BTA_HD_DEBUG
32 #define BTA_HD_DEBUG TRUE
33 #endif
34 
35 /* BTA HID Device callback events */
36 #define BTA_HD_ENABLE_EVT 0         /* BT-HD enabled */
37 #define BTA_HD_DISABLE_EVT 1        /* BT-HD disabled */
38 #define BTA_HD_REGISTER_APP_EVT 2   /* application registered */
39 #define BTA_HD_UNREGISTER_APP_EVT 3 /* application unregistered */
40 #define BTA_HD_OPEN_EVT 4           /* connection to host opened */
41 #define BTA_HD_CLOSE_EVT 5          /* connection to host closed */
42 #define BTA_HD_GET_REPORT_EVT 6     /* GET_REPORT request from host */
43 #define BTA_HD_SET_REPORT_EVT 7     /* SET_REPORT request from host */
44 #define BTA_HD_SET_PROTOCOL_EVT 8   /* SET_PROTOCOL request from host */
45 #define BTA_HD_INTR_DATA_EVT 9      /* DATA received from host on intr */
46 #define BTA_HD_VC_UNPLUG_EVT 10     /* Virtual Cable Unplug */
47 // #define BTA_HD_CONN_STATE_EVT 11    /* Report connection state change */
48 #define BTA_HD_SEND_REPORT_EVT 12     /* Send report finish */
49 #define BTA_HD_REPORT_ERR_EVT 13     /* Report Handshake finish */
50 #define BTA_HD_API_ERR_EVT 99       /* BT-HD API error */
51 
52 typedef uint16_t tBTA_HD_EVT;
53 
54 enum { BTA_HD_OK, BTA_HD_ERROR };
55 
56 typedef enum {
57     BTA_HD_CONN_STATE_CONNECTED,
58     BTA_HD_CONN_STATE_CONNECTING,
59     BTA_HD_CONN_STATE_DISCONNECTED,
60     BTA_HD_CONN_STATE_DISCONNECTING,
61     BTA_HD_CONN_STATE_UNKNOWN
62 } tBTA_HD_CONN_STAT;
63 
64 typedef uint8_t tBTA_HD_STATUS;
65 typedef tHID_DEV_DSCP_INFO tBTA_HD_DEV_DESCR;
66 
67 typedef struct {
68     char *p_name;
69     char *p_description;
70     char *p_provider;
71     uint8_t subclass;
72     tBTA_HD_DEV_DESCR descriptor;
73 } tBTA_HD_APP_INFO;
74 
75 typedef struct {
76     uint8_t service_type;
77     uint32_t token_rate;
78     uint32_t token_bucket_size;
79     uint32_t peak_bandwidth;
80     uint32_t access_latency;
81     uint32_t delay_variation;
82 } tBTA_HD_QOS_INFO;
83 
84 typedef struct {
85     bool use_intr;
86     uint8_t type;
87     uint8_t id;
88     uint16_t len;
89     uint8_t *p_data;
90 } tBTA_HD_REPORT;
91 
92 typedef struct {
93     tBTA_HD_STATUS status;
94     bool in_use;
95     BD_ADDR bda;
96 } tBTA_HD_REG_STATUS;
97 
98 typedef struct {
99     BD_ADDR bda;
100     tBTA_HD_STATUS status;
101     tBTA_HD_CONN_STAT conn_status;
102 } tBTA_HD_CONN;
103 
104 typedef struct {
105     uint8_t report_type;
106     uint8_t report_id;
107     uint16_t buffer_size;
108 } tBTA_HD_GET_REPORT;
109 
110 typedef struct {
111     uint8_t report_type;
112     uint8_t report_id;
113     uint16_t len;
114     uint8_t *p_data;
115 } tBTA_HD_SET_REPORT;
116 
117 typedef uint8_t tBTA_HD_SET_PROTOCOL;
118 
119 typedef struct {
120     uint8_t report_id;
121     uint16_t len;
122     uint8_t *p_data;
123 } tBTA_HD_INTR_DATA;
124 
125 typedef struct {
126     tBTA_HD_STATUS status;
127     uint8_t reason;
128     uint8_t report_type;
129     uint8_t report_id;
130 } tBTA_HD_API_SEND_REPORT;
131 
132 typedef struct {
133     tBTA_HD_STATUS status;
134     uint8_t reason;
135 } tBTA_HD_API_REPORT_ERR;
136 
137 /* union of data associated with HD callback */
138 typedef union {
139     tBTA_HD_STATUS status;                  /* BTA_HD_ENABLE_EVT
140                                                BTA_HD_DISABLE_EVT
141                                                BTA_HD_UNREGISTER_APP_EVT */
142     tBTA_HD_REG_STATUS reg_status;          /* BTA_HD_REGISTER_APP_EVT */
143     tBTA_HD_CONN conn;                      /* BTA_HD_OPEN_EVT
144                                                BTA_HD_CLOSE_EVT
145                                                BTA_HD_VC_UNPLUG_EVT
146                                                BTA_HD_OWN_VC_UNPLUG_EVT */
147     tBTA_HD_GET_REPORT get_report;          /* BTA_HD_GET_REPORT */
148     tBTA_HD_SET_REPORT set_report;          /* BTA_HD_SET_REPORT */
149     tBTA_HD_SET_PROTOCOL set_protocol;      /* BTA_HD_SETPROTOCOL */
150     tBTA_HD_INTR_DATA intr_data;            /* BTA_HD_INTR_DATA_EVT */
151     tBTA_HD_API_SEND_REPORT send_report;    /* BTA_HD_API_SEND_REPORT_EVT */
152     tBTA_HD_API_REPORT_ERR report_err;      /* BTA_HD_API_REPORT_ERR_EVT */
153 } tBTA_HD;
154 
155 /* BTA HD callback function */
156 typedef void (tBTA_HD_CBACK)(tBTA_HD_EVT event, tBTA_HD *p_data);
157 
158 /*****************************************************************************
159  *  External Function Declarations
160  ****************************************************************************/
161 #ifdef __cplusplus
162 extern "C" {
163 #endif
164 
165 /*******************************************************************************
166  *
167  * Function         BTA_HhRegister
168  *
169  * Description      This function enable HID host and registers HID-Host with
170  *                  lower layers.
171  *
172  * Returns          void
173  *
174  ******************************************************************************/
175 extern void BTA_HdEnable(tBTA_HD_CBACK *p_cback);
176 
177 /*******************************************************************************
178  *
179  * Function         BTA_HhDeregister
180  *
181  * Description      This function is called when the host is about power down.
182  *
183  * Returns          void
184  *
185  ******************************************************************************/
186 extern void BTA_HdDisable(void);
187 
188 /*******************************************************************************
189  *
190  * Function         BTA_HdRegisterApp
191  *
192  * Description      This function is called when application should be
193  *                  registered
194  *
195  * Returns          void
196  *
197  ******************************************************************************/
198 extern void BTA_HdRegisterApp(tBTA_HD_APP_INFO *p_app_info, tBTA_HD_QOS_INFO *p_in_qos, tBTA_HD_QOS_INFO *p_out_qos);
199 
200 /*******************************************************************************
201  *
202  * Function         BTA_HdUnregisterApp
203  *
204  * Description      This function is called when application should be
205  *                  unregistered
206  *
207  * Returns          void
208  *
209  ******************************************************************************/
210 extern void BTA_HdUnregisterApp(void);
211 
212 /*******************************************************************************
213  *
214  * Function         BTA_HdSendReport
215  *
216  * Description      This function is called when report is to be sent
217  *
218  * Returns          void
219  *
220  ******************************************************************************/
221 extern void BTA_HdSendReport(tBTA_HD_REPORT *p_report);
222 
223 /*******************************************************************************
224  *
225  * Function         BTA_HdVirtualCableUnplug
226  *
227  * Description      This function is called when VCU shall be sent
228  *
229  * Returns          void
230  *
231  ******************************************************************************/
232 extern void BTA_HdVirtualCableUnplug(void);
233 
234 /*******************************************************************************
235  *
236  * Function         BTA_HdConnect
237  *
238  * Description      This function is called when connection to host shall be
239  *                  made.
240  *
241  * Returns          void
242  *
243  ******************************************************************************/
244 extern void BTA_HdConnect(BD_ADDR addr);
245 
246 /*******************************************************************************
247  *
248  * Function         BTA_HdDisconnect
249  *
250  * Description      This function is called when host shall be disconnected
251  *
252  * Returns          void
253  *
254  ******************************************************************************/
255 extern void BTA_HdDisconnect(void);
256 
257 /*******************************************************************************
258  *
259  * Function         BTA_HdAddDevice
260  *
261  * Description      This function is called when a device is virtually cabled
262  *
263  * Returns          void
264  *
265  ******************************************************************************/
266 extern void BTA_HdAddDevice(BD_ADDR addr);
267 
268 /*******************************************************************************
269  *
270  * Function         BTA_HdRemoveDevice
271  *
272  * Description      This function is called when a device is virtually uncabled
273  *
274  * Returns          void
275  *
276  ******************************************************************************/
277 extern void BTA_HdRemoveDevice(BD_ADDR addr);
278 
279 /*******************************************************************************
280  *
281  * Function         BTA_HdReportError
282  *
283  * Description      This function is called when reporting error for set report
284  *
285  * Returns          void
286  *
287  ******************************************************************************/
288 extern void BTA_HdReportError(uint8_t error);
289 
290 #ifdef __cplusplus
291 }
292 #endif
293 
294 #endif /* BTA_HD_INCLUDED */
295 #endif /* BTA_HD_API_H */
296