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