• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 extern 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 extern 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 extern void BTA_HdRegisterApp(tBTA_HD_APP_INFO* p_app_info,
174                               tBTA_HD_QOS_INFO* p_in_qos,
175                               tBTA_HD_QOS_INFO* p_out_qos);
176 
177 /*******************************************************************************
178  *
179  * Function         BTA_HdUnregisterApp
180  *
181  * Description      This function is called when application should be
182 *unregistered
183  *
184  * Returns          void
185  *
186  ******************************************************************************/
187 extern void BTA_HdUnregisterApp(void);
188 
189 /*******************************************************************************
190  *
191  * Function         BTA_HdSendReport
192  *
193  * Description      This function is called when report is to be sent
194  *
195  * Returns          void
196  *
197  ******************************************************************************/
198 extern void BTA_HdSendReport(tBTA_HD_REPORT* p_report);
199 
200 /*******************************************************************************
201  *
202  * Function         BTA_HdVirtualCableUnplug
203  *
204  * Description      This function is called when VCU shall be sent
205  *
206  * Returns          void
207  *
208  ******************************************************************************/
209 extern void BTA_HdVirtualCableUnplug(void);
210 
211 /*******************************************************************************
212  *
213  * Function         BTA_HdConnect
214  *
215  * Description      This function is called when connection to host shall be
216  *                  made
217  *
218  * Returns          void
219  *
220  ******************************************************************************/
221 extern void BTA_HdConnect(const RawAddress& addr);
222 
223 /*******************************************************************************
224  *
225  * Function         BTA_HdDisconnect
226  *
227  * Description      This function is called when host shall be disconnected
228  *
229  * Returns          void
230  *
231  ******************************************************************************/
232 extern void BTA_HdDisconnect(void);
233 
234 /*******************************************************************************
235  *
236  * Function         BTA_HdAddDevice
237  *
238  * Description      This function is called when a device is virtually cabled
239  *
240  * Returns          void
241  *
242  ******************************************************************************/
243 extern void BTA_HdAddDevice(const RawAddress& addr);
244 
245 /*******************************************************************************
246  *
247  * Function         BTA_HdRemoveDevice
248  *
249  * Description      This function is called when a device is virtually uncabled
250  *
251  * Returns          void
252  *
253  ******************************************************************************/
254 extern void BTA_HdRemoveDevice(const RawAddress& addr);
255 
256 /*******************************************************************************
257  *
258  * Function         BTA_HdReportError
259  *
260  * Description      This function is called when reporting error for set report
261  *
262  * Returns          void
263  *
264  ******************************************************************************/
265 extern void BTA_HdReportError(uint8_t error);
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 
271 #endif /* BTA_HD_API_H */
272