1 /******************************************************************************
2  *
3  *  Copyright 2002-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 #ifndef HIDH_API_H
19 #define HIDH_API_H
20 
21 #include <cstdint>
22 
23 #include "stack/include/bt_hdr.h"
24 #include "stack/include/hiddefs.h"
25 #include "stack/include/sdp_status.h"
26 #include "types/raw_address.h"
27 
28 /*****************************************************************************
29  *  Constants
30  ****************************************************************************/
31 
32 /* Attributes mask values to be used in HID_HostAddDev API */
33 #define HID_VIRTUAL_CABLE 0x0001
34 #define HID_NORMALLY_CONNECTABLE 0x0002
35 #define HID_RECONN_INIT 0x0004
36 #define HID_SDP_DISABLE 0x0008
37 #define HID_BATTERY_POWER 0x0010
38 #define HID_REMOTE_WAKE 0x0020
39 #define HID_SUP_TOUT_AVLBL 0x0040
40 #define HID_SSR_MAX_LATENCY 0x0080
41 #define HID_SSR_MIN_TOUT 0x0100
42 
43 #define HID_SEC_REQUIRED 0x8000
44 #define HID_ATTR_MASK_IGNORE 0
45 
46 /*****************************************************************************
47  *  Type Definitions
48  ****************************************************************************/
49 
50 typedef void(tHID_HOST_SDP_CALLBACK)(const RawAddress& bd_add, tSDP_STATUS result,
51                                      uint16_t attr_mask, tHID_DEV_SDP_INFO* sdp_rec);
52 
53 /* HID-HOST returns the events in the following table to the application via
54  * tHID_HOST_DEV_CALLBACK
55  * HID_HDEV_EVT_OPEN  Connected to device with Interrupt and Control Channels
56  *                    in OPEN state.
57  *                                                      Data = NA
58  * HID_HDEV_EVT_CLOSE Connection with device is closed. Data = reason code.
59  * HID_HDEV_EVT_RETRYING   Lost connection is being re-connected.
60  *                                                      Data = Retrial number
61  * HID_HDEV_EVT_IN_REPORT  Device sent an input report  Data = Report Type
62  *                                                      pdata = pointer to
63  *                                                              BT_HDR
64  *                                                      (GKI buffer with report
65  *                                                       data.)
66  * HID_HDEV_EVT_HANDSHAKE  Device sent SET_REPORT       Data = Result-code
67  *                                                      pdata = NA.
68  * HID_HDEV_EVT_VC_UNPLUG  Device sent Virtual Unplug   Data = NA. pdata = NA.
69  */
70 
71 enum {
72   HID_HDEV_EVT_OPEN,
73   HID_HDEV_EVT_CLOSE,
74   HID_HDEV_EVT_RETRYING,
75   HID_HDEV_EVT_INTR_DATA,
76   HID_HDEV_EVT_INTR_DATC,
77   HID_HDEV_EVT_CTRL_DATA,
78   HID_HDEV_EVT_CTRL_DATC,
79   HID_HDEV_EVT_HANDSHAKE,
80   HID_HDEV_EVT_VC_UNPLUG
81 };
82 typedef void(tHID_HOST_DEV_CALLBACK)(uint8_t dev_handle, const RawAddress& addr,
83                                      uint8_t event,  /* Event from HID-DEVICE. */
84                                      uint32_t data,  /* Integer data corresponding to the event.*/
85                                      BT_HDR* p_buf); /* Pointer data corresponding to the event. */
86 
87 /*****************************************************************************
88  *  External Function Declarations
89  ****************************************************************************/
90 
91 /*******************************************************************************
92  *
93  * Function         HID_HostGetSDPRecord
94  *
95  * Description      This function reads the device SDP record.
96  *
97  * Returns          tHID_STATUS
98  *
99  ******************************************************************************/
100 tHID_STATUS HID_HostGetSDPRecord(const RawAddress& addr, tSDP_DISCOVERY_DB* p_db, uint32_t db_len,
101                                  tHID_HOST_SDP_CALLBACK* sdp_cback);
102 
103 /*******************************************************************************
104  *
105  * Function         HID_HostRegister
106  *
107  * Description      This function registers HID-Host with lower layers.
108  *
109  * Returns          tHID_STATUS
110  *
111  ******************************************************************************/
112 tHID_STATUS HID_HostRegister(tHID_HOST_DEV_CALLBACK* dev_cback);
113 
114 /*******************************************************************************
115  *
116  * Function         HID_HostDeregister
117  *
118  * Description      This function is called when the host is about power down.
119  *
120  * Returns          tHID_STATUS
121  *
122  ******************************************************************************/
123 tHID_STATUS HID_HostDeregister(void);
124 
125 /*******************************************************************************
126  *
127  * Function         HID_HostSDPDisable
128  *
129  * Description      This is called to check if the device has the HIDSDPDisable
130  *                  attribute.
131  *
132  * Returns          bool
133  *
134  ******************************************************************************/
135 bool HID_HostSDPDisable(const RawAddress& addr);
136 
137 /*******************************************************************************
138  *
139  * Function         HID_HostAddDev
140  *
141  * Description      This is called so HID-host may manage this device.
142  *
143  * Returns          tHID_STATUS
144  *
145  ******************************************************************************/
146 tHID_STATUS HID_HostAddDev(const RawAddress& addr, uint16_t attr_mask, uint8_t* handle);
147 
148 /*******************************************************************************
149  *
150  * Function         HID_HostRemoveDev
151  *
152  * Description      Removes the device from the list of devices that the host
153  *                  has to manage.
154  *
155  * Returns          tHID_STATUS
156  *
157  ******************************************************************************/
158 tHID_STATUS HID_HostRemoveDev(uint8_t dev_handle);
159 
160 /*******************************************************************************
161  *
162  * Function         HID_HostOpenDev
163  *
164  * Description      This function is called when the user wants to initiate a
165  *                  connection attempt to a device.
166  *
167  * Returns          void
168  *
169  ******************************************************************************/
170 tHID_STATUS HID_HostOpenDev(uint8_t dev_handle);
171 
172 /*******************************************************************************
173  *
174  * Function         HID_HostWriteDev
175  *
176  * Description      This function is called when the host has a report to send.
177  *
178  * Returns          void
179  *
180  ******************************************************************************/
181 tHID_STATUS HID_HostWriteDev(uint8_t dev_handle, uint8_t t_type, uint8_t param, uint16_t data,
182                              uint8_t report_id, BT_HDR* pbuf);
183 
184 /*******************************************************************************
185  *
186  * Function         HID_HostCloseDev
187  *
188  * Description      This function disconnects the device.
189  *
190  * Returns          void
191  *
192  ******************************************************************************/
193 tHID_STATUS HID_HostCloseDev(uint8_t dev_handle);
194 
195 /*******************************************************************************
196  * Function         HID_HostInit
197  *
198  * Description      Initialize the control block and trace variable
199  *
200  * Returns          void
201  ******************************************************************************/
202 void HID_HostInit(void);
203 
204 #endif /* HIDH_API_H */
205