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 HIDD_API_H
20 #define HIDD_API_H
21 #include "hiddefs.h"
22 #include "sdp_api.h"
23 
24 #if (HID_DEV_INCLUDED == TRUE)
25 /*****************************************************************************
26  *  Type Definitions
27  ****************************************************************************/
28 enum {
29     HID_CHANNEL_INTR,
30     HID_CHANNEL_CTRL
31 };
32 /*
33     HID_DHOST_EVT_OPEN  - connected to host device (CTRL and INTR), data = n/a
34     HID_DHOST_EVT_CLOSE - disconnected from host device, data=reason
35     HID_DHOST_EVT_GET_REPORT - got GET_REPORT from host
36     HID_DHOST_EVT_SET_REPORT - got SET_REPORT from host
37     HID_DHOST_EVT_SET_PROTOCOL - got SET_PROTOCOL from host
38 */
39 
40 enum {
41     HID_DHOST_EVT_OPEN,
42     HID_DHOST_EVT_CLOSE,
43     HID_DHOST_EVT_GET_REPORT,
44     HID_DHOST_EVT_SET_REPORT,
45     HID_DHOST_EVT_SET_PROTOCOL,
46     HID_DHOST_EVT_INTR_DATA,
47     HID_DHOST_EVT_VC_UNPLUG,
48     HID_DHOST_EVT_SUSPEND,
49     HID_DHOST_EVT_EXIT_SUSPEND,
50 };
51 
52 typedef void (tHID_DEV_HOST_CALLBACK)(BD_ADDR bd_addr, uint8_t event, uint32_t data, BT_HDR* p_buf);
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 /*****************************************************************************
58  *  External Function Declarations
59  ****************************************************************************/
60 
61 /*******************************************************************************
62  *
63  * Function         HID_DevInit
64  *
65  * Description      Initializes control block
66  *
67  * Returns          tHID_STATUS
68  *
69  ******************************************************************************/
70 extern tHID_STATUS HID_DevInit(void);
71 
72 /*******************************************************************************
73  *
74  * Function         HID_DevInit
75  *
76  * Description      Deinitializes control block
77  *
78  * Returns          void
79  *
80  ******************************************************************************/
81 extern void HID_DevDeinit(void);
82 
83 /*******************************************************************************
84  *
85  * Function         HID_DevRegister
86  *
87  * Description      Registers HID device with lower layers
88  *
89  * Returns          tHID_STATUS
90  *
91  ******************************************************************************/
92 extern tHID_STATUS HID_DevRegister(tHID_DEV_HOST_CALLBACK* host_cback);
93 
94 /*******************************************************************************
95  *
96  * Function         HID_DevDeregister
97  *
98  * Description      Deregisters HID device with lower layers
99  *
100  * Returns          tHID_STATUS
101  *
102  ******************************************************************************/
103 extern tHID_STATUS HID_DevDeregister(void);
104 
105 /*******************************************************************************
106  *
107  * Function         HID_DevSetSecurityLevel
108  *
109  * Description      Sets security level for HID device connections
110  *
111  * Returns          tHID_STATUS
112  *
113  ******************************************************************************/
114 extern tHID_STATUS HID_DevSetSecurityLevel(uint8_t sec_lvl);
115 
116 /*******************************************************************************
117  *
118  * Function         HID_DevAddRecord
119  *
120  * Description      Creates SDP record for HID device
121  *
122  * Returns          tHID_STATUS
123  *
124  ******************************************************************************/
125 extern tHID_STATUS HID_DevAddRecord(uint32_t handle, char* p_name,
126                                     char* p_description, char* p_provider,
127                                     uint16_t subclass, uint16_t desc_len,
128                                     uint8_t* p_desc_data);
129 
130 /*******************************************************************************
131  *
132  * Function         HID_DevSendReport
133  *
134  * Description      Sends report
135  *
136  * Returns          tHID_STATUS
137  *
138  ******************************************************************************/
139 extern tHID_STATUS HID_DevSendReport(uint8_t channel, uint8_t type, uint8_t id,
140                                      uint16_t len, uint8_t* p_data);
141 
142 /*******************************************************************************
143  *
144  * Function         HID_DevVirtualCableUnplug
145  *
146  * Description      Sends Virtual Cable Unplug
147  *
148  * Returns          tHID_STATUS
149  *
150  ******************************************************************************/
151 extern tHID_STATUS HID_DevVirtualCableUnplug(void);
152 
153 /*******************************************************************************
154  *
155  * Function         HID_DevPlugDevice
156  *
157  * Description      Establishes virtual cable to given host
158  *
159  * Returns          tHID_STATUS
160  *
161  ******************************************************************************/
162 extern tHID_STATUS HID_DevPlugDevice(BD_ADDR addr);
163 
164 /*******************************************************************************
165  *
166  * Function         HID_DevUnplugDevice
167  *
168  * Description      Unplugs virtual cable from given host
169  *
170  * Returns          tHID_STATUS
171  *
172  ******************************************************************************/
173 extern tHID_STATUS HID_DevUnplugDevice(BD_ADDR addr);
174 
175 /*******************************************************************************
176  *
177  * Function         HID_DevConnect
178  *
179  * Description      Connects to device
180  *
181  * Returns          tHID_STATUS
182  *
183  ******************************************************************************/
184 extern tHID_STATUS HID_DevConnect(void);
185 
186 /*******************************************************************************
187  *
188  * Function         HID_DevDisconnect
189  *
190  * Description      Disconnects from device
191  *
192  * Returns          tHID_STATUS
193  *
194  ******************************************************************************/
195 extern tHID_STATUS HID_DevDisconnect(void);
196 
197 /*******************************************************************************
198  *
199  * Function         HID_DevSetIncomingPolicy
200  *
201  * Description      Sets policy for incoming connections (allowed/disallowed)
202  *
203  * Returns          tHID_STATUS
204  *
205  ******************************************************************************/
206 extern tHID_STATUS HID_DevSetIncomingPolicy(bool allow);
207 
208 /*******************************************************************************
209  *
210  * Function         HID_DevReportError
211  *
212  * Description      Reports error for Set Report via HANDSHAKE
213  *
214  * Returns          tHID_STATUS
215  *
216  ******************************************************************************/
217 extern tHID_STATUS HID_DevReportError(uint8_t error);
218 
219 /*******************************************************************************
220  *
221  * Function         HID_DevGetDevice
222  *
223  * Description      Returns the BD Address of virtually cabled device
224  *
225  * Returns          tHID_STATUS
226  *
227  ******************************************************************************/
228 extern tHID_STATUS HID_DevGetDevice(BD_ADDR* addr);
229 
230 /*******************************************************************************
231  *
232  * Function         HID_DevSetIncomingQos
233  *
234  * Description      Sets Incoming QoS values for Interrupt L2CAP Channel
235  *
236  * Returns          tHID_STATUS
237  *
238  ******************************************************************************/
239 extern tHID_STATUS HID_DevSetIncomingQos(
240     uint8_t service_type, uint32_t token_rate, uint32_t token_bucket_size,
241     uint32_t peak_bandwidth, uint32_t latency, uint32_t delay_variation);
242 
243 /*******************************************************************************
244  *
245  * Function         HID_DevSetOutgoingQos
246  *
247  * Description      Sets Outgoing QoS values for Interrupt L2CAP Channel
248  *
249  * Returns          tHID_STATUS
250  *
251  ******************************************************************************/
252 extern tHID_STATUS HID_DevSetOutgoingQos(
253     uint8_t service_type, uint32_t token_rate, uint32_t token_bucket_size,
254     uint32_t peak_bandwidth, uint32_t latency, uint32_t delay_variation);
255 
256 /*******************************************************************************
257  *
258  * Function         HID_DevSetTraceLevel
259  *
260  * Description      This function sets the trace level for HID Dev. If called
261  *                  with a value of 0xFF, it simply reads the current trace level.
262  *
263  * Returns          the new (current) trace level
264  *
265  ******************************************************************************/
266 extern uint8_t HID_DevSetTraceLevel(uint8_t new_level);
267 
268 #ifdef __cplusplus
269 }
270 #endif
271 
272 #endif
273 #endif /* HIDD_API_H */
274