OSDN Git Service

[automerger skipped] Disable sniff for faulty remotes am: 01fff3aa71 -s ours
[android-x86/system-bt.git] / bta / hh / bta_hh_int.h
1 /******************************************************************************
2  *
3  *  Copyright 2005-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
19 /******************************************************************************
20  *
21  *  This file contains BTA HID Host internal definitions
22  *
23  ******************************************************************************/
24
25 #ifndef BTA_HH_INT_H
26 #define BTA_HH_INT_H
27
28 #include "bta_hh_api.h"
29 #include "bta_sys.h"
30 #include "utl.h"
31
32 #include "bta_gatt_api.h"
33
34 /* can be moved to bta_api.h */
35 #define BTA_HH_MAX_RPT_CHARS 8
36
37 /* state machine events, these events are handled by the state machine */
38 enum {
39   BTA_HH_API_OPEN_EVT = BTA_SYS_EVT_START(BTA_ID_HH),
40   BTA_HH_API_CLOSE_EVT,
41   BTA_HH_INT_OPEN_EVT,
42   BTA_HH_INT_CLOSE_EVT,
43   BTA_HH_INT_DATA_EVT,
44   BTA_HH_INT_CTRL_DATA,
45   BTA_HH_INT_HANDSK_EVT,
46   BTA_HH_SDP_CMPL_EVT,
47   BTA_HH_API_WRITE_DEV_EVT,
48   BTA_HH_API_GET_DSCP_EVT,
49   BTA_HH_API_MAINT_DEV_EVT,
50   BTA_HH_OPEN_CMPL_EVT,
51   BTA_HH_GATT_CLOSE_EVT,
52   BTA_HH_GATT_OPEN_EVT,
53   BTA_HH_START_ENC_EVT,
54   BTA_HH_ENC_CMPL_EVT,
55   BTA_HH_GATT_ENC_CMPL_EVT,
56
57   /* not handled by execute state machine */
58   BTA_HH_API_ENABLE_EVT,
59   BTA_HH_API_DISABLE_EVT,
60   BTA_HH_DISC_CMPL_EVT
61 };
62 typedef uint16_t tBTA_HH_INT_EVT; /* HID host internal events */
63
64 #define BTA_HH_INVALID_EVT (BTA_HH_DISC_CMPL_EVT + 1)
65
66 /* event used to map between BTE event and BTA event */
67 #define BTA_HH_FST_TRANS_CB_EVT BTA_HH_GET_RPT_EVT
68 #define BTA_HH_FST_BTE_TRANS_EVT HID_TRANS_GET_REPORT
69
70 /* sub event code used for device maintainence API call */
71 #define BTA_HH_ADD_DEV 0
72 #define BTA_HH_REMOVE_DEV 1
73
74 /* state machine states */
75 enum {
76   BTA_HH_NULL_ST,
77   BTA_HH_IDLE_ST,
78   BTA_HH_W4_CONN_ST,
79   BTA_HH_CONN_ST,
80   BTA_HH_W4_SEC,
81   BTA_HH_INVALID_ST /* Used to check invalid states before executing SM function
82                      */
83
84 };
85 typedef uint8_t tBTA_HH_STATE;
86
87 /* data structure used to send a command/data to HID device */
88 typedef struct {
89   BT_HDR hdr;
90   uint8_t t_type;
91   uint8_t param;
92   uint8_t rpt_id;
93   uint8_t srvc_id;
94   uint16_t data;
95   BT_HDR* p_data;
96 } tBTA_HH_CMD_DATA;
97
98 /* data type for BTA_HH_API_ENABLE_EVT */
99 typedef struct {
100   BT_HDR hdr;
101   uint8_t service_name[BTA_SERVICE_NAME_LEN + 1];
102   tBTA_HH_CBACK* p_cback;
103 } tBTA_HH_API_ENABLE;
104
105 typedef struct {
106   BT_HDR hdr;
107   RawAddress bd_addr;
108   tBTA_HH_PROTO_MODE mode;
109 } tBTA_HH_API_CONN;
110
111 /* internal event data from BTE HID callback */
112 typedef struct {
113   BT_HDR hdr;
114   RawAddress addr;
115   uint32_t data;
116   BT_HDR* p_data;
117 } tBTA_HH_CBACK_DATA;
118
119 typedef struct {
120   BT_HDR hdr;
121   RawAddress bda;
122   uint16_t attr_mask;
123   uint16_t sub_event;
124   uint8_t sub_class;
125   uint8_t app_id;
126   tBTA_HH_DEV_DSCP_INFO dscp_info;
127 } tBTA_HH_MAINT_DEV;
128
129 typedef struct {
130   BT_HDR hdr;
131   uint16_t conn_id;
132   tBTA_GATT_REASON reason; /* disconnect reason code, not useful when connect
133                               event is reported */
134
135 } tBTA_HH_LE_CLOSE;
136
137 typedef struct {
138   BT_HDR hdr;
139   uint16_t scan_int;
140   uint16_t scan_win;
141 } tBTA_HH_SCPP_UPDATE;
142
143 /* union of all event data types */
144 typedef union {
145   BT_HDR hdr;
146   tBTA_HH_API_ENABLE api_enable;
147   tBTA_HH_API_CONN api_conn;
148   tBTA_HH_CMD_DATA api_sndcmd;
149   tBTA_HH_CBACK_DATA hid_cback;
150   tBTA_HH_STATUS status;
151   tBTA_HH_MAINT_DEV api_maintdev;
152   tBTA_HH_LE_CLOSE le_close;
153   tBTA_GATTC_OPEN le_open;
154   tBTA_HH_SCPP_UPDATE le_scpp_update;
155   tBTA_GATTC_ENC_CMPL_CB le_enc_cmpl;
156 } tBTA_HH_DATA;
157
158 typedef struct {
159   uint8_t index;
160   bool in_use;
161   uint8_t srvc_inst_id;
162   uint16_t char_inst_id;
163   tBTA_HH_RPT_TYPE rpt_type;
164   uint16_t uuid;
165   uint8_t rpt_id;
166   bool client_cfg_exist;
167   uint16_t client_cfg_value;
168 } tBTA_HH_LE_RPT;
169
170 #ifndef BTA_HH_LE_RPT_MAX
171 #define BTA_HH_LE_RPT_MAX 20
172 #endif
173
174 typedef struct {
175   bool in_use;
176   uint8_t srvc_inst_id;
177   tBTA_HH_LE_RPT report[BTA_HH_LE_RPT_MAX];
178
179   uint16_t proto_mode_handle;
180   uint8_t control_point_handle;
181
182   uint8_t
183       incl_srvc_inst; /* assuming only one included service : battery service */
184   uint8_t cur_expl_char_idx; /* currently discovering service index */
185   uint8_t* rpt_map;
186   uint16_t ext_rpt_ref;
187   tBTA_HH_DEV_DESCR descriptor;
188
189 } tBTA_HH_LE_HID_SRVC;
190
191 /* convert a HID handle to the LE CB index */
192 #define BTA_HH_GET_LE_CB_IDX(x) (((x) >> 4) - 1)
193 /* convert a GATT connection ID to HID device handle, it is the hi 4 bits of a
194  * uint8_t */
195 #define BTA_HH_GET_LE_DEV_HDL(x) (uint8_t)(((x) + 1) << 4)
196 /* check to see if th edevice handle is a LE device handle */
197 #define BTA_HH_IS_LE_DEV_HDL(x) ((x)&0xf0)
198 #define BTA_HH_IS_LE_DEV_HDL_VALID(x) (((x) >> 4) <= BTA_HH_LE_MAX_KNOWN)
199
200 /* device control block */
201 typedef struct {
202   tBTA_HH_DEV_DSCP_INFO dscp_info; /* report descriptor and DI information */
203   RawAddress addr;                 /* BD-Addr of the HID device */
204   uint16_t attr_mask;              /* attribute mask */
205   uint16_t w4_evt;                 /* W4_handshake event name */
206   uint8_t index;                   /* index number referenced to handle index */
207   uint8_t sub_class;               /* Cod sub class */
208   uint8_t app_id;                  /* application ID for this connection */
209   uint8_t hid_handle;          /* device handle : low 4 bits for regular HID:
210                                   HID_HOST_MAX_DEVICES can not exceed 15;
211                                                  high 4 bits for LE HID:
212                                   GATT_MAX_PHY_CHANNEL can not exceed 15 */
213   bool vp;                     /* virtually unplug flag */
214   bool in_use;                 /* control block currently in use */
215   bool incoming_conn;          /* is incoming connection? */
216   uint8_t incoming_hid_handle; /* temporary handle for incoming connection? */
217   bool opened; /* true if device successfully opened HID connection */
218   tBTA_HH_PROTO_MODE mode; /* protocol mode */
219   tBTA_HH_STATE state;     /* CB state */
220
221 #define BTA_HH_LE_DISC_NONE 0x00
222 #define BTA_HH_LE_DISC_HIDS 0x01
223 #define BTA_HH_LE_DISC_DIS 0x02
224 #define BTA_HH_LE_DISC_SCPS 0x04
225
226   uint8_t disc_active;
227   tBTA_HH_STATUS status;
228   tBTA_GATT_REASON reason;
229   bool is_le_device;
230   tBTA_HH_LE_HID_SRVC hid_srvc;
231   uint16_t conn_id;
232   bool in_bg_conn;
233   uint8_t clt_cfg_idx;
234   uint16_t scan_refresh_char_handle;
235   bool scps_supported;
236
237 #define BTA_HH_LE_SCPS_NOTIFY_NONE 0
238 #define BTA_HH_LE_SCPS_NOTIFY_SPT 0x01
239 #define BTA_HH_LE_SCPS_NOTIFY_ENB 0x02
240   uint8_t scps_notify; /* scan refresh supported/notification enabled */
241
242   bool security_pending;
243 } tBTA_HH_DEV_CB;
244
245 /* key board parsing control block */
246 typedef struct {
247   bool mod_key[4]; /* ctrl, shift(upper), Alt, GUI */
248   bool num_lock;
249   bool caps_lock;
250   uint8_t last_report[BTA_HH_MAX_RPT_CHARS];
251 } tBTA_HH_KB_CB;
252
253 /******************************************************************************
254  * Main Control Block
255  ******************************************************************************/
256 typedef struct {
257   tBTA_HH_KB_CB kb_cb;                    /* key board control block,
258                                              suppose BTA will connect
259                                              to only one keyboard at
260                                               the same time */
261   tBTA_HH_DEV_CB kdev[BTA_HH_MAX_DEVICE]; /* device control block */
262   tBTA_HH_DEV_CB* p_cur;                  /* current device control
263                                                  block idx, used in sdp */
264   uint8_t cb_index[BTA_HH_MAX_KNOWN];     /* maintain a CB index
265                                         map to dev handle */
266   uint8_t le_cb_index[BTA_HH_LE_MAX_KNOWN]; /* maintain a CB index map to LE dev
267                                              handle */
268   tGATT_IF gatt_if;
269   tBTA_HH_CBACK* p_cback; /* Application callbacks */
270   tSDP_DISCOVERY_DB* p_disc_db;
271   uint8_t trace_level; /* tracing level */
272   uint8_t cnt_num;     /* connected device number */
273   bool w4_disable;     /* w4 disable flag */
274 } tBTA_HH_CB;
275
276 extern tBTA_HH_CB bta_hh_cb;
277
278 /* from bta_hh_cfg.c */
279 extern tBTA_HH_CFG* p_bta_hh_cfg;
280
281 /*****************************************************************************
282  *  Function prototypes
283  ****************************************************************************/
284 extern bool bta_hh_hdl_event(BT_HDR* p_msg);
285 extern void bta_hh_sm_execute(tBTA_HH_DEV_CB* p_cb, uint16_t event,
286                               tBTA_HH_DATA* p_data);
287
288 /* action functions */
289 extern void bta_hh_api_disc_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
290 extern void bta_hh_open_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
291 extern void bta_hh_close_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
292 extern void bta_hh_data_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
293 extern void bta_hh_ctrl_dat_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
294 extern void bta_hh_start_sdp(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
295 extern void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
296 extern void bta_hh_write_dev_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
297 extern void bta_hh_get_dscp_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
298 extern void bta_hh_handsk_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
299 extern void bta_hh_maint_dev_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
300 extern void bta_hh_open_cmpl_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
301 extern void bta_hh_open_failure(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
302
303 /* utility functions */
304 extern uint8_t bta_hh_find_cb(const RawAddress& bda);
305 extern void bta_hh_parse_keybd_rpt(tBTA_HH_BOOT_RPT* p_kb_data,
306                                    uint8_t* p_report, uint16_t report_len);
307 extern void bta_hh_parse_mice_rpt(tBTA_HH_BOOT_RPT* p_kb_data,
308                                   uint8_t* p_report, uint16_t report_len);
309 extern bool bta_hh_tod_spt(tBTA_HH_DEV_CB* p_cb, uint8_t sub_class);
310 extern void bta_hh_clean_up_kdev(tBTA_HH_DEV_CB* p_cb);
311
312 extern void bta_hh_add_device_to_list(tBTA_HH_DEV_CB* p_cb, uint8_t handle,
313                                       uint16_t attr_mask,
314                                       tHID_DEV_DSCP_INFO* p_dscp_info,
315                                       uint8_t sub_class, uint16_t max_latency,
316                                       uint16_t min_tout, uint8_t app_id);
317 extern void bta_hh_update_di_info(tBTA_HH_DEV_CB* p_cb, uint16_t vendor_id,
318                                   uint16_t product_id, uint16_t version,
319                                   uint8_t flag);
320 extern void bta_hh_cleanup_disable(tBTA_HH_STATUS status);
321
322 extern uint8_t bta_hh_dev_handle_to_cb_idx(uint8_t dev_handle);
323
324 /* action functions used outside state machine */
325 extern void bta_hh_api_enable(tBTA_HH_DATA* p_data);
326 extern void bta_hh_api_disable(void);
327 extern void bta_hh_disc_cmpl(void);
328
329 extern tBTA_HH_STATUS bta_hh_read_ssr_param(const RawAddress& bd_addr,
330                                             uint16_t* p_max_ssr_lat,
331                                             uint16_t* p_min_ssr_tout);
332
333 /* functions for LE HID */
334 extern void bta_hh_le_enable(void);
335 extern bool bta_hh_le_is_hh_gatt_if(tGATT_IF client_if);
336 extern void bta_hh_le_deregister(void);
337 extern bool bta_hh_is_le_device(tBTA_HH_DEV_CB* p_cb,
338                                 const RawAddress& remote_bda);
339 extern void bta_hh_le_open_conn(tBTA_HH_DEV_CB* p_cb,
340                                 const RawAddress& remote_bda);
341 extern void bta_hh_le_api_disc_act(tBTA_HH_DEV_CB* p_cb);
342 extern void bta_hh_le_get_dscp_act(tBTA_HH_DEV_CB* p_cb);
343 extern void bta_hh_le_write_dev_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
344 extern uint8_t bta_hh_le_add_device(tBTA_HH_DEV_CB* p_cb,
345                                     tBTA_HH_MAINT_DEV* p_dev_info);
346 extern void bta_hh_le_remove_dev_bg_conn(tBTA_HH_DEV_CB* p_cb);
347 extern void bta_hh_le_open_fail(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
348 extern void bta_hh_gatt_open(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
349 extern void bta_hh_gatt_close(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data);
350 extern void bta_hh_start_security(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_buf);
351
352 extern void bta_hh_start_security(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_buf);
353 extern void bta_hh_security_cmpl(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_buf);
354 extern void bta_hh_le_notify_enc_cmpl(tBTA_HH_DEV_CB* p_cb,
355                                       tBTA_HH_DATA* p_data);
356
357 #if (BTA_HH_DEBUG == TRUE)
358 extern void bta_hh_trace_dev_db(void);
359 #endif
360
361 #endif