1 /*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef ANDROID_INCLUDE_BT_HH_H
18 #define ANDROID_INCLUDE_BT_HH_H
19
20 #include <stdint.h>
21 #include <string>
22
23 __BEGIN_DECLS
24
25 #define BTHH_MAX_DSC_LEN 884
26
27 /* HH connection states */
28 typedef enum {
29 BTHH_CONN_STATE_CONNECTED = 0,
30 BTHH_CONN_STATE_CONNECTING = 1,
31 BTHH_CONN_STATE_DISCONNECTED = 2,
32 BTHH_CONN_STATE_DISCONNECTING = 3,
33 BTHH_CONN_STATE_UNKNOWN = 0xff,
34 } bthh_connection_state_t;
35
36 __END_DECLS
37 #define CASE_RETURN_TEXT(code) \
38 case code: \
39 return #code
40
bthh_connection_state_text(const bthh_connection_state_t & state)41 inline std::string bthh_connection_state_text(
42 const bthh_connection_state_t& state) {
43 switch (state) {
44 CASE_RETURN_TEXT(BTHH_CONN_STATE_CONNECTED);
45 CASE_RETURN_TEXT(BTHH_CONN_STATE_CONNECTING);
46 CASE_RETURN_TEXT(BTHH_CONN_STATE_DISCONNECTED);
47 CASE_RETURN_TEXT(BTHH_CONN_STATE_DISCONNECTING);
48 CASE_RETURN_TEXT(BTHH_CONN_STATE_UNKNOWN);
49 default:
50 return std::string("UNKNOWN[%u]", state);
51 }
52 }
53 #undef CASE_RETURN_TEXT
54 __BEGIN_DECLS
55
56 typedef enum {
57 BTHH_OK = 0,
58 BTHH_HS_HID_NOT_READY, /* handshake error : device not ready */
59 BTHH_HS_INVALID_RPT_ID, /* handshake error : invalid report ID */
60 BTHH_HS_TRANS_NOT_SPT, /* handshake error : transaction not spt */
61 BTHH_HS_INVALID_PARAM, /* handshake error : invalid paremter */
62 BTHH_HS_ERROR, /* handshake error : unspecified HS error */
63 BTHH_ERR, /* general BTA HH error */
64 BTHH_ERR_SDP, /* SDP error */
65 BTHH_ERR_PROTO, /* SET_Protocol error,
66 only used in BTA_HH_OPEN_EVT
67 callback */
68 BTHH_ERR_DB_FULL, /* device database full error, used */
69 BTHH_ERR_TOD_UNSPT, /* type of device not supported */
70 BTHH_ERR_NO_RES, /* out of system resources */
71 BTHH_ERR_AUTH_FAILED, /* authentication fail */
72 BTHH_ERR_HDL
73 } bthh_status_t;
74
75 /* Protocol modes */
76 typedef enum {
77 BTHH_REPORT_MODE = 0x00,
78 BTHH_BOOT_MODE = 0x01,
79 BTHH_UNSUPPORTED_MODE = 0xff
80 } bthh_protocol_mode_t;
81
82 /* Report types */
83 typedef enum {
84 BTHH_INPUT_REPORT = 1,
85 BTHH_OUTPUT_REPORT,
86 BTHH_FEATURE_REPORT
87 } bthh_report_type_t;
88
89 typedef struct {
90 int attr_mask;
91 uint8_t sub_class;
92 uint8_t app_id;
93 int vendor_id;
94 int product_id;
95 int version;
96 uint8_t ctry_code;
97 int dl_len;
98 uint8_t dsc_list[BTHH_MAX_DSC_LEN];
99 } bthh_hid_info_t;
100
101 /** Callback for connection state change.
102 * state will have one of the values from bthh_connection_state_t
103 */
104 typedef void (*bthh_connection_state_callback)(RawAddress* bd_addr,
105 bthh_connection_state_t state);
106
107 /** Callback for vitual unplug api.
108 * the status of the vitual unplug
109 */
110 typedef void (*bthh_virtual_unplug_callback)(RawAddress* bd_addr,
111 bthh_status_t hh_status);
112
113 /** Callback for get hid info
114 * hid_info will contain attr_mask, sub_class, app_id, vendor_id, product_id,
115 * version, ctry_code, len
116 */
117 typedef void (*bthh_hid_info_callback)(RawAddress* bd_addr,
118 bthh_hid_info_t hid_info);
119
120 /** Callback for get protocol api.
121 * the protocol mode is one of the value from bthh_protocol_mode_t
122 */
123 typedef void (*bthh_protocol_mode_callback)(RawAddress* bd_addr,
124 bthh_status_t hh_status,
125 bthh_protocol_mode_t mode);
126
127 /** Callback for get/set_idle_time api.
128 */
129 typedef void (*bthh_idle_time_callback)(RawAddress* bd_addr,
130 bthh_status_t hh_status, int idle_rate);
131
132 /** Callback for get report api.
133 * if staus is ok rpt_data contains the report data
134 */
135 typedef void (*bthh_get_report_callback)(RawAddress* bd_addr,
136 bthh_status_t hh_status,
137 uint8_t* rpt_data, int rpt_size);
138
139 /** Callback for set_report/set_protocol api and if error
140 * occurs for get_report/get_protocol api.
141 */
142 typedef void (*bthh_handshake_callback)(RawAddress* bd_addr,
143 bthh_status_t hh_status);
144
145 /** BT-HH callback structure. */
146 typedef struct {
147 /** set to sizeof(BtHfCallbacks) */
148 size_t size;
149 bthh_connection_state_callback connection_state_cb;
150 bthh_hid_info_callback hid_info_cb;
151 bthh_protocol_mode_callback protocol_mode_cb;
152 bthh_idle_time_callback idle_time_cb;
153 bthh_get_report_callback get_report_cb;
154 bthh_virtual_unplug_callback virtual_unplug_cb;
155 bthh_handshake_callback handshake_cb;
156
157 } bthh_callbacks_t;
158
159 /** Represents the standard BT-HH interface. */
160 typedef struct {
161 /** set to sizeof(BtHhInterface) */
162 size_t size;
163
164 /**
165 * Register the BtHh callbacks
166 */
167 bt_status_t (*init)(bthh_callbacks_t* callbacks);
168
169 /** connect to hid device */
170 bt_status_t (*connect)(RawAddress* bd_addr);
171
172 /** dis-connect from hid device */
173 bt_status_t (*disconnect)(RawAddress* bd_addr);
174
175 /** Virtual UnPlug (VUP) the specified HID device */
176 bt_status_t (*virtual_unplug)(RawAddress* bd_addr);
177
178 /** Set the HID device descriptor for the specified HID device. */
179 bt_status_t (*set_info)(RawAddress* bd_addr, bthh_hid_info_t hid_info);
180
181 /** Get the HID proto mode. */
182 bt_status_t (*get_protocol)(RawAddress* bd_addr,
183 bthh_protocol_mode_t protocolMode);
184
185 /** Set the HID proto mode. */
186 bt_status_t (*set_protocol)(RawAddress* bd_addr,
187 bthh_protocol_mode_t protocolMode);
188
189 /** Get the HID Idle Time */
190 bt_status_t (*get_idle_time)(RawAddress* bd_addr);
191
192 /** Set the HID Idle Time */
193 bt_status_t (*set_idle_time)(RawAddress* bd_addr, uint8_t idleTime);
194
195 /** Send a GET_REPORT to HID device. */
196 bt_status_t (*get_report)(RawAddress* bd_addr, bthh_report_type_t reportType,
197 uint8_t reportId, int bufferSize);
198
199 /** Send a SET_REPORT to HID device. */
200 bt_status_t (*set_report)(RawAddress* bd_addr, bthh_report_type_t reportType,
201 char* report);
202
203 /** Send data to HID device. */
204 bt_status_t (*send_data)(RawAddress* bd_addr, char* data);
205
206 /** Closes the interface. */
207 void (*cleanup)(void);
208
209 } bthh_interface_t;
210 __END_DECLS
211
212 #endif /* ANDROID_INCLUDE_BT_HH_H */
213