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