Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 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 BTA_HH_API_H
     19 #define BTA_HH_API_H
     20 
     21 #include "bta_api.h"
     22 #include "hidh_api.h"
     23 
     24 #if (BTA_HH_LE_INCLUDED == TRUE)
     25 #include "gatt_api.h"
     26 #endif
     27 
     28 /*****************************************************************************
     29  *  Constants and Type Definitions
     30  ****************************************************************************/
     31 #ifndef BTA_HH_DEBUG
     32 #define BTA_HH_DEBUG TRUE
     33 #endif
     34 
     35 #ifndef BTA_HH_SSR_MAX_LATENCY_DEF
     36 #define BTA_HH_SSR_MAX_LATENCY_DEF 800 /* 500 ms*/
     37 #endif
     38 
     39 #ifndef BTA_HH_SSR_MIN_TOUT_DEF
     40 #define BTA_HH_SSR_MIN_TOUT_DEF 2
     41 #endif
     42 
     43 /* BTA HID Host callback events */
     44 #define BTA_HH_ENABLE_EVT 0     /* HH enabled */
     45 #define BTA_HH_DISABLE_EVT 1    /* HH disabled */
     46 #define BTA_HH_OPEN_EVT 2       /* connection opened */
     47 #define BTA_HH_CLOSE_EVT 3      /* connection closed */
     48 #define BTA_HH_GET_RPT_EVT 4    /* BTA_HhGetReport callback */
     49 #define BTA_HH_SET_RPT_EVT 5    /* BTA_HhSetReport callback */
     50 #define BTA_HH_GET_PROTO_EVT 6  /* BTA_GetProtoMode callback */
     51 #define BTA_HH_SET_PROTO_EVT 7  /* BTA_HhSetProtoMode callback */
     52 #define BTA_HH_GET_IDLE_EVT 8   /* BTA_HhGetIdle comes callback */
     53 #define BTA_HH_SET_IDLE_EVT 9   /* BTA_HhSetIdle finish callback */
     54 #define BTA_HH_GET_DSCP_EVT 10  /* Get report descriptor */
     55 #define BTA_HH_ADD_DEV_EVT 11   /* Add Device callback */
     56 #define BTA_HH_RMV_DEV_EVT 12   /* remove device finished */
     57 #define BTA_HH_VC_UNPLUG_EVT 13 /* virtually unplugged */
     58 #define BTA_HH_DATA_EVT 15
     59 #define BTA_HH_API_ERR_EVT 16     /* API error is caught */
     60 #define BTA_HH_UPDATE_SCPP_EVT 17 /* update scan paramter complete */
     61 
     62 typedef uint16_t tBTA_HH_EVT;
     63 
     64 /* application ID(none-zero) for each type of device */
     65 #define BTA_HH_APP_ID_MI 1
     66 #define BTA_HH_APP_ID_KB 2
     67 #define BTA_HH_APP_ID_RMC 3
     68 #define BTA_HH_APP_ID_3DSG 4
     69 #define BTA_HH_APP_ID_JOY 5
     70 #define BTA_HH_APP_ID_GPAD 6
     71 #define BTA_HH_APP_ID_LE 0xff
     72 
     73 /* defined the minimum offset */
     74 #define BTA_HH_MIN_OFFSET (L2CAP_MIN_OFFSET + 1)
     75 
     76 /* HID_HOST_MAX_DEVICES can not exceed 15 for th design of BTA HH */
     77 #define BTA_HH_IDX_INVALID 0xff
     78 #define BTA_HH_MAX_KNOWN HID_HOST_MAX_DEVICES
     79 
     80 #if (BTA_HH_LE_INCLUDED == TRUE)
     81 /* GATT_MAX_PHY_CHANNEL can not exceed 14 for the design of BTA HH */
     82 #define BTA_HH_LE_MAX_KNOWN GATT_MAX_PHY_CHANNEL
     83 #define BTA_HH_MAX_DEVICE (HID_HOST_MAX_DEVICES + GATT_MAX_PHY_CHANNEL)
     84 #else
     85 #define BTA_HH_MAX_DEVICE HID_HOST_MAX_DEVICES
     86 #endif
     87 /* invalid device handle */
     88 #define BTA_HH_INVALID_HANDLE 0xff
     89 
     90 /* type of protocol mode */
     91 #define BTA_HH_PROTO_RPT_MODE (0x00)
     92 #define BTA_HH_PROTO_BOOT_MODE (0x01)
     93 #define BTA_HH_PROTO_UNKNOWN (0xff)
     94 typedef uint8_t tBTA_HH_PROTO_MODE;
     95 
     96 enum { BTA_HH_KEYBD_RPT_ID = 1, BTA_HH_MOUSE_RPT_ID };
     97 typedef uint8_t tBTA_HH_BOOT_RPT_ID;
     98 
     99 /* type of devices, bit mask */
    100 #define BTA_HH_DEVT_UNKNOWN 0x00
    101 #define BTA_HH_DEVT_JOS 0x01 /* joy stick */
    102 #define BTA_HH_DEVT_GPD 0x02 /* game pad */
    103 #define BTA_HH_DEVT_RMC 0x03 /* remote control */
    104 #define BTA_HH_DEVT_SED 0x04 /* sensing device */
    105 #define BTA_HH_DEVT_DGT 0x05 /* Digitizer tablet */
    106 #define BTA_HH_DEVT_CDR 0x06 /* card reader */
    107 #define BTA_HH_DEVT_KBD 0x10 /* keyboard */
    108 #define BTA_HH_DEVT_MIC 0x20 /* pointing device */
    109 #define BTA_HH_DEVT_COM 0x30 /* Combo keyboard/pointing */
    110 #define BTA_HH_DEVT_OTHER 0x80
    111 typedef uint8_t tBTA_HH_DEVT;
    112 
    113 enum {
    114   BTA_HH_OK,
    115   BTA_HH_HS_HID_NOT_READY,  /* handshake error : device not ready */
    116   BTA_HH_HS_INVALID_RPT_ID, /* handshake error : invalid report ID */
    117   BTA_HH_HS_TRANS_NOT_SPT,  /* handshake error : transaction not spt */
    118   BTA_HH_HS_INVALID_PARAM,  /* handshake error : invalid paremter */
    119   BTA_HH_HS_ERROR,          /* handshake error : unspecified HS error */
    120   BTA_HH_ERR,               /* general BTA HH error */
    121   BTA_HH_ERR_SDP,           /* SDP error */
    122   BTA_HH_ERR_PROTO,         /* SET_Protocol error,
    123                                 only used in BTA_HH_OPEN_EVT callback */
    124 
    125   BTA_HH_ERR_DB_FULL,     /* device database full error, used in
    126                              BTA_HH_OPEN_EVT/BTA_HH_ADD_DEV_EVT */
    127   BTA_HH_ERR_TOD_UNSPT,   /* type of device not supported */
    128   BTA_HH_ERR_NO_RES,      /* out of system resources */
    129   BTA_HH_ERR_AUTH_FAILED, /* authentication fail */
    130   BTA_HH_ERR_HDL,
    131   BTA_HH_ERR_SEC
    132 };
    133 typedef uint8_t tBTA_HH_STATUS;
    134 
    135 #define BTA_HH_VIRTUAL_CABLE HID_VIRTUAL_CABLE
    136 #define BTA_HH_NORMALLY_CONNECTABLE HID_NORMALLY_CONNECTABLE
    137 #define BTA_HH_RECONN_INIT HID_RECONN_INIT
    138 #define BTA_HH_SDP_DISABLE HID_SDP_DISABLE
    139 #define BTA_HH_BATTERY_POWER HID_BATTERY_POWER
    140 #define BTA_HH_REMOTE_WAKE HID_REMOTE_WAKE
    141 #define BTA_HH_SUP_TOUT_AVLBL HID_SUP_TOUT_AVLBL
    142 #define BTA_HH_SEC_REQUIRED HID_SEC_REQUIRED
    143 typedef uint16_t tBTA_HH_ATTR_MASK;
    144 
    145 /* supported type of device and corresponding application ID */
    146 typedef struct {
    147   tBTA_HH_DEVT tod; /* type of device               */
    148   uint8_t app_id;   /* corresponding application ID */
    149 } tBTA_HH_SPT_TOD;
    150 
    151 /* configuration struct */
    152 typedef struct {
    153   uint8_t max_devt_spt;         /* max number of types of devices spt */
    154   tBTA_HH_SPT_TOD* p_devt_list; /* supported types of device list     */
    155   uint16_t sdp_db_size;
    156 } tBTA_HH_CFG;
    157 
    158 enum {
    159   BTA_HH_RPTT_RESRV,  /* reserved         */
    160   BTA_HH_RPTT_INPUT,  /* input report     */
    161   BTA_HH_RPTT_OUTPUT, /* output report    */
    162   BTA_HH_RPTT_FEATURE /* feature report   */
    163 };
    164 typedef uint8_t tBTA_HH_RPT_TYPE;
    165 
    166 /* HID_CONTROL operation code used in BTA_HhSendCtrl()
    167 */
    168 enum {
    169   BTA_HH_CTRL_NOP = 0 + HID_PAR_CONTROL_NOP, /* mapping from BTE */
    170   BTA_HH_CTRL_HARD_RESET,                    /* hard reset       */
    171   BTA_HH_CTRL_SOFT_RESET,                    /* soft reset       */
    172   BTA_HH_CTRL_SUSPEND,                       /* enter suspend    */
    173   BTA_HH_CTRL_EXIT_SUSPEND,                  /* exit suspend     */
    174   BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG           /* virtual unplug   */
    175 };
    176 typedef uint8_t tBTA_HH_TRANS_CTRL_TYPE;
    177 
    178 typedef tHID_DEV_DSCP_INFO tBTA_HH_DEV_DESCR;
    179 
    180 #define BTA_HH_SSR_PARAM_INVALID HID_SSR_PARAM_INVALID
    181 
    182 /* id DI is not existing in remote device, vendor_id in tBTA_HH_DEV_DSCP_INFO
    183  * will be set to 0xffff */
    184 #define BTA_HH_VENDOR_ID_INVALID 0xffff
    185 
    186 /* report descriptor information */
    187 typedef struct {
    188   uint16_t vendor_id;       /* vendor ID */
    189   uint16_t product_id;      /* product ID */
    190   uint16_t version;         /* version */
    191   uint16_t ssr_max_latency; /* SSR max latency, BTA_HH_SSR_PARAM_INVALID if
    192                                unknown */
    193   uint16_t
    194       ssr_min_tout;  /* SSR min timeout, BTA_HH_SSR_PARAM_INVALID if unknown */
    195   uint8_t ctry_code; /*Country Code.*/
    196 #if (BTA_HH_LE_INCLUDED == TRUE)
    197 #define BTA_HH_LE_REMOTE_WAKE 0x01
    198 #define BTA_HH_LE_NORMAL_CONN 0x02
    199 
    200   uint8_t flag;
    201 #endif
    202   tBTA_HH_DEV_DESCR descriptor;
    203 } tBTA_HH_DEV_DSCP_INFO;
    204 
    205 /* callback event data for BTA_HH_OPEN_EVT */
    206 typedef struct {
    207   BD_ADDR bda;           /* HID device bd address    */
    208   tBTA_HH_STATUS status; /* operation status         */
    209   uint8_t handle;        /* device handle            */
    210 #if (BTA_HH_LE_INCLUDED == TRUE)
    211   bool le_hid;         /* is LE devices? */
    212   bool scps_supported; /* scan parameter service supported */
    213 #endif
    214 
    215 } tBTA_HH_CONN;
    216 
    217 typedef tBTA_HH_CONN tBTA_HH_DEV_INFO;
    218 
    219 /* callback event data */
    220 typedef struct {
    221   tBTA_HH_STATUS status; /* operation status         */
    222   uint8_t handle;        /* device handle            */
    223 } tBTA_HH_CBDATA;
    224 
    225 enum {
    226   BTA_HH_MOD_CTRL_KEY,
    227   BTA_HH_MOD_SHFT_KEY,
    228   BTA_HH_MOD_ALT_KEY,
    229   BTA_HH_MOD_GUI_KEY,
    230   BTA_HH_MOD_MAX_KEY
    231 };
    232 
    233 /* parsed boot mode keyboard report */
    234 typedef struct {
    235   uint8_t this_char[6]; /* virtual key code     */
    236   bool mod_key[BTA_HH_MOD_MAX_KEY];
    237   /* ctrl, shift, Alt, GUI */
    238   /* modifier key: is Shift key pressed */
    239   /* modifier key: is Ctrl key pressed  */
    240   /* modifier key: is Alt key pressed   */
    241   /* modifier key: GUI up/down */
    242   bool caps_lock; /* is caps locked       */
    243   bool num_lock;  /* is Num key pressed   */
    244 } tBTA_HH_KEYBD_RPT;
    245 
    246 /* parsed boot mode mouse report */
    247 typedef struct {
    248   uint8_t mouse_button; /* mouse button is clicked   */
    249   int8_t delta_x;       /* displacement x            */
    250   int8_t delta_y;       /* displacement y            */
    251 } tBTA_HH_MICE_RPT;
    252 
    253 /* parsed Boot report */
    254 typedef struct {
    255   tBTA_HH_BOOT_RPT_ID dev_type; /* type of device report */
    256   union {
    257     tBTA_HH_KEYBD_RPT keybd_rpt; /* keyboard report      */
    258     tBTA_HH_MICE_RPT mice_rpt;   /* mouse report         */
    259   } data_rpt;
    260 } tBTA_HH_BOOT_RPT;
    261 
    262 /* handshake data */
    263 typedef struct {
    264   tBTA_HH_STATUS status; /* handshake status */
    265   uint8_t handle;        /* device handle    */
    266   union {
    267     tBTA_HH_PROTO_MODE proto_mode; /* GET_PROTO_EVT :protocol mode */
    268     BT_HDR* p_rpt_data;            /* GET_RPT_EVT   : report data  */
    269     uint8_t idle_rate;             /* GET_IDLE_EVT  : idle rate    */
    270   } rsp_data;
    271 
    272 } tBTA_HH_HSDATA;
    273 
    274 /* union of data associated with HD callback */
    275 typedef union {
    276   tBTA_HH_DEV_INFO dev_info; /* BTA_HH_ADD_DEV_EVT, BTA_HH_RMV_DEV_EVT   */
    277   tBTA_HH_CONN conn;         /* BTA_HH_OPEN_EVT      */
    278   tBTA_HH_CBDATA dev_status; /* BTA_HH_CLOSE_EVT,
    279                                 BTA_HH_SET_PROTO_EVT
    280                                 BTA_HH_SET_RPT_EVT
    281                                 BTA_HH_SET_IDLE_EVT
    282                                 BTA_HH_UPDATE_SCPP_EVT */
    283 
    284   tBTA_HH_STATUS status;           /* BTA_HH_ENABLE_EVT */
    285   tBTA_HH_DEV_DSCP_INFO dscp_info; /* BTA_HH_GET_DSCP_EVT */
    286   tBTA_HH_HSDATA hs_data;          /* GET_ transaction callback
    287                                       BTA_HH_GET_RPT_EVT
    288                                       BTA_HH_GET_PROTO_EVT
    289                                       BTA_HH_GET_IDLE_EVT */
    290 } tBTA_HH;
    291 
    292 /* BTA HH callback function */
    293 typedef void(tBTA_HH_CBACK)(tBTA_HH_EVT event, tBTA_HH* p_data);
    294 
    295 /*****************************************************************************
    296  *  External Function Declarations
    297  ****************************************************************************/
    298 
    299 /*******************************************************************************
    300  *
    301  * Function         BTA_HhRegister
    302  *
    303  * Description      This function enable HID host and registers HID-Host with
    304  *                  lower layers.
    305  *
    306  * Returns          void
    307  *
    308  ******************************************************************************/
    309 extern void BTA_HhEnable(tBTA_SEC sec_mask, tBTA_HH_CBACK* p_cback);
    310 
    311 /*******************************************************************************
    312  *
    313  * Function         BTA_HhDeregister
    314  *
    315  * Description      This function is called when the host is about power down.
    316  *
    317  * Returns          void
    318  *
    319  ******************************************************************************/
    320 extern void BTA_HhDisable(void);
    321 
    322 /*******************************************************************************
    323  *
    324  * Function         BTA_HhOpen
    325  *
    326  * Description      This function is called to start an inquiry and read SDP
    327  *                  record of responding devices; connect to a device if only
    328  *                  one active HID device is found.
    329  *
    330  * Returns          void
    331  *
    332  ******************************************************************************/
    333 extern void BTA_HhOpen(BD_ADDR dev_bda, tBTA_HH_PROTO_MODE mode,
    334                        tBTA_SEC sec_mask);
    335 
    336 /*******************************************************************************
    337  *
    338  * Function         BTA_HhClose
    339  *
    340  * Description      This function disconnects the device.
    341  *
    342  * Returns          void
    343  *
    344  ******************************************************************************/
    345 extern void BTA_HhClose(uint8_t dev_handle);
    346 
    347 /*******************************************************************************
    348  *
    349  * Function         BTA_HhSetProtoMode
    350  *
    351  * Description      This function set the protocol mode at specified HID handle
    352  *
    353  * Returns          void
    354  *
    355  ******************************************************************************/
    356 extern void BTA_HhSetProtoMode(uint8_t handle, tBTA_HH_PROTO_MODE t_type);
    357 
    358 /*******************************************************************************
    359  *
    360  * Function         BTA_HhGetProtoMode
    361  *
    362  * Description      This function get the protocol mode of a specified HID
    363  *                  device.
    364  *
    365  * Returns          void
    366  *
    367  ******************************************************************************/
    368 extern void BTA_HhGetProtoMode(uint8_t dev_handle);
    369 /*******************************************************************************
    370  *
    371  * Function         BTA_HhSetReport
    372  *
    373  * Description      send SET_REPORT to device.
    374  *
    375  * Returns          void
    376  *
    377  ******************************************************************************/
    378 extern void BTA_HhSetReport(uint8_t dev_handle, tBTA_HH_RPT_TYPE r_type,
    379                             BT_HDR* p_data);
    380 
    381 /*******************************************************************************
    382  *
    383  * Function         BTA_HhGetReport
    384  *
    385  * Description      Send a GET_REPORT to HID device.
    386  *
    387  * Returns          void
    388  *
    389  ******************************************************************************/
    390 extern void BTA_HhGetReport(uint8_t dev_handle, tBTA_HH_RPT_TYPE r_type,
    391                             uint8_t rpt_id, uint16_t buf_size);
    392 /*******************************************************************************
    393  *
    394  * Function         BTA_HhSetIdle
    395  *
    396  * Description      send SET_IDLE to device.
    397  *
    398  * Returns          void
    399  *
    400  ******************************************************************************/
    401 extern void BTA_HhSetIdle(uint8_t dev_handle, uint16_t idle_rate);
    402 
    403 /*******************************************************************************
    404  *
    405  * Function         BTA_HhGetIdle
    406  *
    407  * Description      Send a GET_IDLE to HID device.
    408  *
    409  * Returns          void
    410  *
    411  ******************************************************************************/
    412 extern void BTA_HhGetIdle(uint8_t dev_handle);
    413 
    414 /*******************************************************************************
    415  *
    416  * Function         BTA_HhSendCtrl
    417  *
    418  * Description      Send HID_CONTROL request to a HID device.
    419  *
    420  * Returns          void
    421  *
    422  ******************************************************************************/
    423 extern void BTA_HhSendCtrl(uint8_t dev_handle, tBTA_HH_TRANS_CTRL_TYPE c_type);
    424 
    425 /*******************************************************************************
    426  *
    427  * Function         BTA_HhSetIdle
    428  *
    429  * Description      send SET_IDLE to device.
    430  *
    431  * Returns          void
    432  *
    433  ******************************************************************************/
    434 extern void BTA_HhSetIdle(uint8_t dev_handle, uint16_t idle_rate);
    435 
    436 /*******************************************************************************
    437  *
    438  * Function         BTA_HhGetIdle
    439  *
    440  * Description      Send a GET_IDLE from HID device.
    441  *
    442  * Returns          void
    443  *
    444  ******************************************************************************/
    445 extern void BTA_HhGetIdle(uint8_t dev_handle);
    446 
    447 /*******************************************************************************
    448  *
    449  * Function         BTA_HhSendData
    450  *
    451  * Description      Send DATA transaction to a HID device.
    452  *
    453  * Returns          void
    454  *
    455  ******************************************************************************/
    456 extern void BTA_HhSendData(uint8_t dev_handle, BD_ADDR dev_bda, BT_HDR* p_buf);
    457 
    458 /*******************************************************************************
    459  *
    460  * Function         BTA_HhGetDscpInfo
    461  *
    462  * Description      Get report descriptor of the device
    463  *
    464  * Returns          void
    465  *
    466  ******************************************************************************/
    467 extern void BTA_HhGetDscpInfo(uint8_t dev_handle);
    468 
    469 /*******************************************************************************
    470  * Function         BTA_HhAddDev
    471  *
    472  * Description      Add a virtually cabled device into HID-Host device list
    473  *                  to manage and assign a device handle for future API call,
    474  *                  host applciation call this API at start-up to initialize its
    475  *                  virtually cabled devices.
    476  *
    477  * Returns          void
    478  *
    479  ******************************************************************************/
    480 extern void BTA_HhAddDev(BD_ADDR bda, tBTA_HH_ATTR_MASK attr_mask,
    481                          uint8_t sub_class, uint8_t app_id,
    482                          tBTA_HH_DEV_DSCP_INFO dscp_info);
    483 /*******************************************************************************
    484  *
    485  * Function         BTA_HhRemoveDev
    486  *
    487  * Description      Remove a device from the HID host devices list.
    488  *
    489  * Returns          void
    490  *
    491  ******************************************************************************/
    492 extern void BTA_HhRemoveDev(uint8_t dev_handle);
    493 
    494 /*******************************************************************************
    495  *
    496  *              Parsing Utility Functions
    497  *
    498  ******************************************************************************/
    499 /*******************************************************************************
    500  *
    501  * Function         BTA_HhParseBootRpt
    502  *
    503  * Description      This utility function parse a boot mode report.
    504  *
    505  * Returns          void
    506  *
    507  ******************************************************************************/
    508 extern void BTA_HhParseBootRpt(tBTA_HH_BOOT_RPT* p_data, uint8_t* p_report,
    509                                uint16_t report_len);
    510 
    511 /* test commands */
    512 extern void bta_hh_le_hid_read_rpt_clt_cfg(BD_ADDR bd_addr, uint8_t rpt_id);
    513 
    514 #endif /* BTA_HH_API_H */
    515