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