bta_hh_api.h 18 KB

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