Home | History | Annotate | Download | only in hh
      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 "bd.h"
     30 #include "utl.h"
     31 #include "bta_hh_api.h"
     32 
     33 /* can be moved to bta_api.h */
     34 #define BTA_HH_MAX_RPT_CHARS    8
     35 
     36 
     37 /* state machine events, these events are handled by the state machine */
     38 enum
     39 {
     40     BTA_HH_API_OPEN_EVT     = BTA_SYS_EVT_START(BTA_ID_HH),
     41     BTA_HH_API_CLOSE_EVT,
     42     BTA_HH_INT_OPEN_EVT,
     43     BTA_HH_INT_CLOSE_EVT,
     44     BTA_HH_INT_DATA_EVT,
     45     BTA_HH_INT_CTRL_DATA,
     46     BTA_HH_INT_HANDSK_EVT,
     47     BTA_HH_SDP_CMPL_EVT,
     48     BTA_HH_API_WRITE_DEV_EVT,
     49     BTA_HH_API_GET_DSCP_EVT,
     50     BTA_HH_API_MAINT_DEV_EVT,
     51     BTA_HH_OPEN_CMPL_EVT,
     52 
     53     /* not handled by execute state machine */
     54     BTA_HH_API_ENABLE_EVT,
     55     BTA_HH_API_DISABLE_EVT,
     56     BTA_HH_DISC_CMPL_EVT
     57 };
     58 typedef UINT16 tBTA_HH_INT_EVT;         /* HID host internal events */
     59 
     60 #define BTA_HH_INVALID_EVT      (BTA_HH_DISC_CMPL_EVT + 1)
     61 
     62 /* event used to map between BTE event and BTA event */
     63 #define BTA_HH_FST_TRANS_CB_EVT         BTA_HH_GET_RPT_EVT
     64 #define BTA_HH_FST_BTE_TRANS_EVT        HID_TRANS_GET_REPORT
     65 
     66 /* sub event code used for device maintainence API call */
     67 #define BTA_HH_ADD_DEV          0
     68 #define BTA_HH_REMOVE_DEV       1
     69 
     70 /* state machine states */
     71 enum
     72 {
     73     BTA_HH_NULL_ST,
     74     BTA_HH_IDLE_ST,
     75     BTA_HH_W4_CONN_ST,
     76     BTA_HH_CONN_ST
     77 };
     78 typedef UINT8 tBTA_HH_STATE;
     79 
     80 /* data structure used to send a command/data to HID device */
     81 typedef struct
     82 {
     83     BT_HDR           hdr;
     84     UINT8            t_type;
     85     UINT8            param;
     86     UINT8            rpt_id;
     87     UINT16           data;
     88     BT_HDR           *p_data;
     89 }tBTA_HH_CMD_DATA;
     90 
     91 /* data type for BTA_HH_API_ENABLE_EVT */
     92 typedef struct
     93 {
     94     BT_HDR              hdr;
     95     UINT8               sec_mask;
     96     UINT8               service_name[BTA_SERVICE_NAME_LEN+1];
     97     tBTA_HH_CBACK   *p_cback;
     98 } tBTA_HH_API_ENABLE;
     99 
    100 typedef struct
    101 {
    102     BT_HDR          hdr;
    103     BD_ADDR         bd_addr;
    104     UINT8           sec_mask;
    105     tBTA_HH_PROTO_MODE  mode;
    106 }tBTA_HH_API_CONN;
    107 
    108 /* internal event data from BTE HID callback */
    109 typedef struct
    110 {
    111     BT_HDR          hdr;
    112     UINT32          data;
    113     BT_HDR          *p_data;
    114 }tBTA_HH_CBACK_DATA;
    115 
    116 typedef struct
    117 {
    118     BT_HDR              hdr;
    119     BD_ADDR             bda;
    120     UINT16              attr_mask;
    121     UINT16              sub_event;
    122     UINT8               sub_class;
    123     UINT8               app_id;
    124     tBTA_HH_DEV_DSCP_INFO      dscp_info;
    125 }tBTA_HH_MAINT_DEV;
    126 
    127 /* union of all event data types */
    128 typedef union
    129 {
    130     BT_HDR                   hdr;
    131     tBTA_HH_API_ENABLE       api_enable;
    132     tBTA_HH_API_CONN         api_conn;
    133     tBTA_HH_CMD_DATA         api_sndcmd;
    134     tBTA_HH_CBACK_DATA       hid_cback;
    135     tBTA_HH_STATUS           status;
    136     tBTA_HH_MAINT_DEV        api_maintdev;
    137 } tBTA_HH_DATA;
    138 
    139 /* device control block */
    140 typedef struct
    141 {
    142     tBTA_HH_DEV_DSCP_INFO  dscp_info;      /* report descriptor and DI information */
    143     BD_ADDR             addr;           /* BD-Addr of the HID device */
    144     UINT16              attr_mask;      /* attribute mask */
    145     UINT16              w4_evt;         /* W4_handshake event name */
    146     UINT8               index;          /* index number referenced to handle index */
    147     UINT8               sub_class;      /* Cod sub class */
    148     UINT8               sec_mask;       /* security mask */
    149     UINT8               app_id;         /* application ID for this connection */
    150     UINT8               hid_handle;     /* device handle */
    151     BOOLEAN             vp;             /* virtually unplug flag */
    152     BOOLEAN             in_use;         /* control block currently in use */
    153     BOOLEAN             incoming_conn;  /* is incoming connection? */
    154     BOOLEAN             opened;         /* TRUE if device successfully opened HID connection */
    155     tBTA_HH_PROTO_MODE  mode;           /* protocol mode */
    156     tBTA_HH_STATE       state;          /* CB state */
    157 } tBTA_HH_DEV_CB;
    158 
    159 /* key board parsing control block */
    160 typedef struct
    161 {
    162     BOOLEAN             mod_key[4]; /* ctrl, shift(upper), Alt, GUI */
    163     BOOLEAN             num_lock;
    164     BOOLEAN             caps_lock;
    165     UINT8               last_report[BTA_HH_MAX_RPT_CHARS];
    166 } tBTA_HH_KB_CB;
    167 
    168 /******************************************************************************
    169 ** Main Control Block
    170 *******************************************************************************/
    171 typedef struct
    172 {
    173     tBTA_HH_KB_CB           kb_cb;                  /* key board control block,
    174                                                        suppose BTA will connect
    175                                                        to only one keyboard at
    176                                                         the same time */
    177     tBTA_HH_DEV_CB          kdev[BTA_HH_MAX_DEVICE]; /* device control block */
    178     tBTA_HH_DEV_CB*         p_cur;              /* current device control
    179                                                        block idx, used in sdp */
    180     UINT8                   cb_index[BTA_HH_MAX_KNOWN]; /* maintain a CB index
    181                                                         map to dev handle */
    182     tBTA_HH_CBACK       *p_cback;               /* Application callbacks */
    183     tSDP_DISCOVERY_DB*      p_disc_db;
    184     UINT8                   trace_level;            /* tracing level */
    185     UINT8                   cnt_num;                /* connected device number */
    186     BOOLEAN                 w4_disable;             /* w4 disable flag */
    187 }
    188 tBTA_HH_CB;
    189 
    190 #if BTA_DYNAMIC_MEMORY == FALSE
    191 extern tBTA_HH_CB  bta_hh_cb;
    192 #else
    193 extern tBTA_HH_CB *bta_hh_cb_ptr;
    194 #define bta_hh_cb (*bta_hh_cb_ptr)
    195 #endif
    196 
    197 /* from bta_hh_cfg.c */
    198 extern tBTA_HH_CFG *p_bta_hh_cfg;
    199 
    200 /*****************************************************************************
    201 **  Function prototypes
    202 *****************************************************************************/
    203 extern BOOLEAN bta_hh_hdl_event(BT_HDR *p_msg);
    204 extern void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event,
    205                               tBTA_HH_DATA *p_data);
    206 
    207 /* action functions */
    208 extern void bta_hh_api_disc_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
    209 extern void bta_hh_open_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
    210 extern void bta_hh_close_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
    211 extern void bta_hh_data_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data);
    212 extern void bta_hh_ctrl_dat_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data);
    213 extern void bta_hh_start_sdp(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
    214 extern void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
    215 extern void bta_hh_write_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
    216 extern void bta_hh_get_dscp_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
    217 extern void bta_hh_handsk_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
    218 extern void bta_hh_maint_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
    219 extern void bta_hh_open_cmpl_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
    220 
    221 /* utility functions */
    222 extern UINT8  bta_hh_find_cb(BD_ADDR bda);
    223 extern void bta_hh_parse_keybd_rpt(tBTA_HH_BOOT_RPT *p_kb_data,
    224              UINT8 *p_report, UINT16 report_len);
    225 extern void bta_hh_parse_mice_rpt(tBTA_HH_BOOT_RPT *p_kb_data,
    226                                   UINT8 *p_report, UINT16 report_len);
    227 extern BOOLEAN bta_hh_tod_spt(tBTA_HH_DEV_CB *p_cb,UINT8 sub_class);
    228 extern void bta_hh_clean_up_kdev(tBTA_HH_DEV_CB *p_cb);
    229 
    230 extern void bta_hh_add_device_to_list(tBTA_HH_DEV_CB *p_cb, UINT8 handle,
    231                                       UINT16 attr_mask,
    232                                       tHID_DEV_DSCP_INFO *p_dscp_info,
    233                                       UINT8 sub_class, UINT16 max_latency, UINT16 min_tout, UINT8 app_id);
    234 extern void bta_hh_update_di_info(tBTA_HH_DEV_CB *p_cb, UINT16 vendor_id, UINT16 product_id,
    235                            UINT16 version, UINT8 flag);
    236 extern void bta_hh_cleanup_disable(tBTA_HH_STATUS status);
    237 
    238 extern UINT8 bta_hh_dev_handle_to_cb_idx(UINT8 dev_handle);
    239 
    240 /* action functions used outside state machine */
    241 extern void bta_hh_api_enable(tBTA_HH_DATA *p_data);
    242 extern void bta_hh_api_disable(void);
    243 extern void bta_hh_disc_cmpl(void);
    244 
    245 extern tBTA_HH_STATUS bta_hh_read_ssr_param(BD_ADDR bd_addr, UINT16 *p_max_ssr_lat, UINT16 *p_min_ssr_tout);
    246 
    247 #if BTA_HH_DEBUG
    248 extern void bta_hh_trace_dev_db(void);
    249 #endif
    250 
    251 #endif
    252 
    253