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, uint32_t data,
55                                      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, char* p_provider,
107                              uint16_t subclass, uint16_t desc_len, uint8_t* p_desc_data);
108 
109 /*******************************************************************************
110  *
111  * Function         HID_DevSendReport
112  *
113  * Description      Sends report
114  *
115  * Returns          tHID_STATUS
116  *
117  ******************************************************************************/
118 tHID_STATUS HID_DevSendReport(uint8_t channel, uint8_t type, uint8_t id, uint16_t len,
119                               uint8_t* p_data);
120 
121 /*******************************************************************************
122  *
123  * Function         HID_DevVirtualCableUnplug
124  *
125  * Description      Sends Virtual Cable Unplug
126  *
127  * Returns          tHID_STATUS
128  *
129  ******************************************************************************/
130 tHID_STATUS HID_DevVirtualCableUnplug(void);
131 
132 /*******************************************************************************
133  *
134  * Function         HID_DevPlugDevice
135  *
136  * Description      Establishes virtual cable to given host
137  *
138  * Returns          tHID_STATUS
139  *
140  ******************************************************************************/
141 tHID_STATUS HID_DevPlugDevice(const RawAddress& addr);
142 
143 /*******************************************************************************
144  *
145  * Function         HID_DevUnplugDevice
146  *
147  * Description      Unplugs virtual cable from given host
148  *
149  * Returns          tHID_STATUS
150  *
151  ******************************************************************************/
152 tHID_STATUS HID_DevUnplugDevice(const RawAddress& addr);
153 
154 /*******************************************************************************
155  *
156  * Function         HID_DevConnect
157  *
158  * Description      Connects to device
159  *
160  * Returns          tHID_STATUS
161  *
162  ******************************************************************************/
163 tHID_STATUS HID_DevConnect(void);
164 
165 /*******************************************************************************
166  *
167  * Function         HID_DevDisconnect
168  *
169  * Description      Disconnects from device
170  *
171  * Returns          tHID_STATUS
172  *
173  ******************************************************************************/
174 tHID_STATUS HID_DevDisconnect(void);
175 
176 /*******************************************************************************
177  *
178  * Function         HID_DevSetIncomingPolicy
179  *
180  * Description      Sets policy for incoming connections (allowed/disallowed)
181  *
182  * Returns          tHID_STATUS
183  *
184  ******************************************************************************/
185 tHID_STATUS HID_DevSetIncomingPolicy(bool allow);
186 
187 /*******************************************************************************
188  *
189  * Function         HID_DevReportError
190  *
191  * Description      Reports error for Set Report via HANDSHAKE
192  *
193  * Returns          tHID_STATUS
194  *
195  ******************************************************************************/
196 tHID_STATUS HID_DevReportError(uint8_t error);
197 
198 /*******************************************************************************
199  *
200  * Function         HID_DevGetDevice
201  *
202  * Description      Returns the BD Address of virtually cabled device
203  *
204  * Returns          tHID_STATUS
205  *
206  ******************************************************************************/
207 tHID_STATUS HID_DevGetDevice(RawAddress* addr);
208 
209 /*******************************************************************************
210  *
211  * Function         HID_DevSetIncomingQos
212  *
213  * Description      Sets Incoming QoS values for Interrupt L2CAP Channel
214  *
215  * Returns          tHID_STATUS
216  *
217  ******************************************************************************/
218 tHID_STATUS HID_DevSetIncomingQos(uint8_t service_type, uint32_t token_rate,
219                                   uint32_t token_bucket_size, uint32_t peak_bandwidth,
220                                   uint32_t latency, uint32_t delay_variation);
221 
222 /*******************************************************************************
223  *
224  * Function         HID_DevSetOutgoingQos
225  *
226  * Description      Sets Outgoing QoS values for Interrupt L2CAP Channel
227  *
228  * Returns          tHID_STATUS
229  *
230  ******************************************************************************/
231 tHID_STATUS HID_DevSetOutgoingQos(uint8_t service_type, uint32_t token_rate,
232                                   uint32_t token_bucket_size, uint32_t peak_bandwidth,
233                                   uint32_t latency, uint32_t delay_variation);
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 
239 #endif /* HIDD_API_H */
240