1 /******************************************************************************
2  *
3  *  Copyright 2016 The Android Open Source Project
4  *  Copyright 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 <cstdint>
23 
24 #include "bta/include/bta_api.h"
25 #include "stack/include/hiddefs.h"
26 #include "types/raw_address.h"
27 
28 /*****************************************************************************
29  *  Constants and Type Definitions
30  ****************************************************************************/
31 #ifndef BTA_HD_DEBUG
32 #define BTA_HD_DEBUG FALSE
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_API_ERR_EVT 99       /* BT-HD API error */
49 
50 typedef uint16_t tBTA_HD_EVT;
51 
52 enum { BTA_HD_OK, BTA_HD_ERROR };
53 typedef uint8_t tBTA_HD_STATUS;
54 
55 typedef tHID_DEV_DSCP_INFO tBTA_HD_DEV_DESCR;
56 
57 typedef struct {
58   char* p_name;
59   char* p_description;
60   char* p_provider;
61   uint8_t subclass;
62   tBTA_HD_DEV_DESCR descriptor;
63 } tBTA_HD_APP_INFO;
64 
65 typedef struct {
66   uint8_t service_type;
67   uint32_t token_rate;
68   uint32_t token_bucket_size;
69   uint32_t peak_bandwidth;
70   uint32_t access_latency;
71   uint32_t delay_variation;
72 } tBTA_HD_QOS_INFO;
73 
74 typedef struct {
75   bool use_intr;
76   uint8_t type;
77   uint8_t id;
78   uint16_t len;
79   uint8_t* p_data;
80 } tBTA_HD_REPORT;
81 
82 typedef struct {
83   tBTA_HD_STATUS status;
84   bool in_use;
85   RawAddress bda;
86 } tBTA_HD_REG_STATUS;
87 
88 typedef struct {
89   RawAddress bda;
90   tBTA_HD_STATUS status;
91 } tBTA_HD_CONN;
92 
93 typedef struct {
94   uint8_t report_type;
95   uint8_t report_id;
96   uint16_t buffer_size;
97 } tBTA_HD_GET_REPORT;
98 
99 typedef struct {
100   uint8_t report_type;
101   uint8_t report_id;
102   uint16_t len;
103   uint8_t* p_data;
104 } tBTA_HD_SET_REPORT;
105 
106 typedef uint8_t tBTA_HD_SET_PROTOCOL;
107 
108 typedef struct {
109   uint8_t report_id;
110   uint16_t len;
111   uint8_t* p_data;
112 } tBTA_HD_INTR_DATA;
113 
114 /* union of data associated with HD callback */
115 typedef union {
116   tBTA_HD_STATUS status;             /* BTA_HD_ENABLE_EVT
117                                         BTA_HD_DISABLE_EVT
118                                         BTA_HD_UNREGISTER_APP_EVT */
119   tBTA_HD_REG_STATUS reg_status;     /* BTA_HD_REGISTER_APP_EVT */
120   tBTA_HD_CONN conn;                 /* BTA_HD_OPEN_EVT
121                                         BTA_HD_CLOSE_EVT
122                                         BTA_HD_VC_UNPLUG_EVT
123                                         BTA_HD_OWN_VC_UNPLUG_EVT */
124   tBTA_HD_GET_REPORT get_report;     /* BTA_HD_GET_REPORT */
125   tBTA_HD_SET_REPORT set_report;     /* BTA_HD_SET_REPORT */
126   tBTA_HD_SET_PROTOCOL set_protocol; /* BTA_HD_SETPROTOCOL */
127   tBTA_HD_INTR_DATA intr_data;       /* BTA_HD_INTR_DATA_EVT */
128 } tBTA_HD;
129 
130 /* BTA HD callback function */
131 typedef void(tBTA_HD_CBACK)(tBTA_HD_EVT event, tBTA_HD* p_data);
132 
133 /*****************************************************************************
134  *  External Function Declarations
135  ****************************************************************************/
136 #ifdef __cplusplus
137 extern "C" {
138 #endif
139 
140 /*******************************************************************************
141  *
142  * Function         BTA_HhRegister
143  *
144  * Description      This function enable HID host and registers HID-Host with
145  *                  lower layers.
146  *
147  * Returns          void
148  *
149  ******************************************************************************/
150 void BTA_HdEnable(tBTA_HD_CBACK* p_cback);
151 
152 /*******************************************************************************
153  *
154  * Function         BTA_HhDeregister
155  *
156  * Description      This function is called when the host is about power down.
157  *
158  * Returns          void
159  *
160  ******************************************************************************/
161 void BTA_HdDisable(void);
162 
163 /*******************************************************************************
164  *
165  * Function         BTA_HdRegisterApp
166  *
167  * Description      This function is called when application should be
168 *registered
169  *
170  * Returns          void
171  *
172  ******************************************************************************/
173 void BTA_HdRegisterApp(tBTA_HD_APP_INFO* p_app_info, tBTA_HD_QOS_INFO* p_in_qos,
174                        tBTA_HD_QOS_INFO* p_out_qos);
175 
176 /*******************************************************************************
177  *
178  * Function         BTA_HdUnregisterApp
179  *
180  * Description      This function is called when application should be
181 *unregistered
182  *
183  * Returns          void
184  *
185  ******************************************************************************/
186 void BTA_HdUnregisterApp(void);
187 
188 /*******************************************************************************
189  *
190  * Function         BTA_HdSendReport
191  *
192  * Description      This function is called when report is to be sent
193  *
194  * Returns          void
195  *
196  ******************************************************************************/
197 void BTA_HdSendReport(tBTA_HD_REPORT* p_report);
198 
199 /*******************************************************************************
200  *
201  * Function         BTA_HdVirtualCableUnplug
202  *
203  * Description      This function is called when VCU shall be sent
204  *
205  * Returns          void
206  *
207  ******************************************************************************/
208 void BTA_HdVirtualCableUnplug(void);
209 
210 /*******************************************************************************
211  *
212  * Function         BTA_HdConnect
213  *
214  * Description      This function is called when connection to host shall be
215  *                  made
216  *
217  * Returns          void
218  *
219  ******************************************************************************/
220 void BTA_HdConnect(const RawAddress& addr);
221 
222 /*******************************************************************************
223  *
224  * Function         BTA_HdDisconnect
225  *
226  * Description      This function is called when host shall be disconnected
227  *
228  * Returns          void
229  *
230  ******************************************************************************/
231 void BTA_HdDisconnect(void);
232 
233 /*******************************************************************************
234  *
235  * Function         BTA_HdAddDevice
236  *
237  * Description      This function is called when a device is virtually cabled
238  *
239  * Returns          void
240  *
241  ******************************************************************************/
242 void BTA_HdAddDevice(const RawAddress& addr);
243 
244 /*******************************************************************************
245  *
246  * Function         BTA_HdRemoveDevice
247  *
248  * Description      This function is called when a device is virtually uncabled
249  *
250  * Returns          void
251  *
252  ******************************************************************************/
253 void BTA_HdRemoveDevice(const RawAddress& addr);
254 
255 /*******************************************************************************
256  *
257  * Function         BTA_HdReportError
258  *
259  * Description      This function is called when reporting error for set report
260  *
261  * Returns          void
262  *
263  ******************************************************************************/
264 void BTA_HdReportError(uint8_t error);
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 
270 #endif /* BTA_HD_API_H */
271