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