bt_hh.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* SPDX-License-Identifier: Apache-2.0 */
  2. /*
  3. * Copyright (C) 2012 The Android Open Source Project
  4. *
  5. */
  6. #ifndef ANDROID_INCLUDE_BT_HH_H
  7. #define ANDROID_INCLUDE_BT_HH_H
  8. #include <stdint.h>
  9. __BEGIN_DECLS
  10. #define BTHH_MAX_DSC_LEN 884
  11. /* HH connection states */
  12. typedef enum
  13. {
  14. BTHH_CONN_STATE_CONNECTED = 0,
  15. BTHH_CONN_STATE_CONNECTING,
  16. BTHH_CONN_STATE_DISCONNECTED,
  17. BTHH_CONN_STATE_DISCONNECTING,
  18. BTHH_CONN_STATE_FAILED_MOUSE_FROM_HOST,
  19. BTHH_CONN_STATE_FAILED_KBD_FROM_HOST,
  20. BTHH_CONN_STATE_FAILED_TOO_MANY_DEVICES,
  21. BTHH_CONN_STATE_FAILED_NO_BTHID_DRIVER,
  22. BTHH_CONN_STATE_FAILED_GENERIC,
  23. BTHH_CONN_STATE_UNKNOWN
  24. } bthh_connection_state_t;
  25. typedef enum
  26. {
  27. BTHH_OK = 0,
  28. BTHH_HS_HID_NOT_READY, /* handshake error : device not ready */
  29. BTHH_HS_INVALID_RPT_ID, /* handshake error : invalid report ID */
  30. BTHH_HS_TRANS_NOT_SPT, /* handshake error : transaction not spt */
  31. BTHH_HS_INVALID_PARAM, /* handshake error : invalid paremter */
  32. BTHH_HS_ERROR, /* handshake error : unspecified HS error */
  33. BTHH_ERR, /* general BTA HH error */
  34. BTHH_ERR_SDP, /* SDP error */
  35. BTHH_ERR_PROTO, /* SET_Protocol error,
  36. only used in BTA_HH_OPEN_EVT callback */
  37. BTHH_ERR_DB_FULL, /* device database full error, used */
  38. BTHH_ERR_TOD_UNSPT, /* type of device not supported */
  39. BTHH_ERR_NO_RES, /* out of system resources */
  40. BTHH_ERR_AUTH_FAILED, /* authentication fail */
  41. BTHH_ERR_HDL
  42. }bthh_status_t;
  43. /* Protocol modes */
  44. typedef enum {
  45. BTHH_REPORT_MODE = 0x00,
  46. BTHH_BOOT_MODE = 0x01,
  47. BTHH_UNSUPPORTED_MODE = 0xff
  48. }bthh_protocol_mode_t;
  49. /* Report types */
  50. typedef enum {
  51. BTHH_INPUT_REPORT = 1,
  52. BTHH_OUTPUT_REPORT,
  53. BTHH_FEATURE_REPORT
  54. }bthh_report_type_t;
  55. typedef struct
  56. {
  57. int attr_mask;
  58. uint8_t sub_class;
  59. uint8_t app_id;
  60. int vendor_id;
  61. int product_id;
  62. int version;
  63. uint8_t ctry_code;
  64. int dl_len;
  65. uint8_t dsc_list[BTHH_MAX_DSC_LEN];
  66. } bthh_hid_info_t;
  67. /** Callback for connection state change.
  68. * state will have one of the values from bthh_connection_state_t
  69. */
  70. typedef void (* bthh_connection_state_callback)(bt_bdaddr_t *bd_addr, bthh_connection_state_t state);
  71. /** Callback for vitual unplug api.
  72. * the status of the vitual unplug
  73. */
  74. typedef void (* bthh_virtual_unplug_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status);
  75. /** Callback for get hid info
  76. * hid_info will contain attr_mask, sub_class, app_id, vendor_id, product_id, version, ctry_code, len
  77. */
  78. typedef void (* bthh_hid_info_callback)(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info);
  79. /** Callback for get protocol api.
  80. * the protocol mode is one of the value from bthh_protocol_mode_t
  81. */
  82. typedef void (* bthh_protocol_mode_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, bthh_protocol_mode_t mode);
  83. /** Callback for get/set_idle_time api.
  84. */
  85. typedef void (* bthh_idle_time_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, int idle_rate);
  86. /** Callback for get report api.
  87. * if staus is ok rpt_data contains the report data
  88. */
  89. typedef void (* bthh_get_report_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, uint8_t* rpt_data, int rpt_size);
  90. /** Callback for set_report/set_protocol api and if error
  91. * occurs for get_report/get_protocol api.
  92. */
  93. typedef void (* bthh_handshake_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status);
  94. /** BT-HH callback structure. */
  95. typedef struct {
  96. /** set to sizeof(BtHfCallbacks) */
  97. size_t size;
  98. bthh_connection_state_callback connection_state_cb;
  99. bthh_hid_info_callback hid_info_cb;
  100. bthh_protocol_mode_callback protocol_mode_cb;
  101. bthh_idle_time_callback idle_time_cb;
  102. bthh_get_report_callback get_report_cb;
  103. bthh_virtual_unplug_callback virtual_unplug_cb;
  104. bthh_handshake_callback handshake_cb;
  105. } bthh_callbacks_t;
  106. /** Represents the standard BT-HH interface. */
  107. typedef struct {
  108. /** set to sizeof(BtHhInterface) */
  109. size_t size;
  110. /**
  111. * Register the BtHh callbacks
  112. */
  113. bt_status_t (*init)( bthh_callbacks_t* callbacks );
  114. /** connect to hid device */
  115. bt_status_t (*connect)( bt_bdaddr_t *bd_addr);
  116. /** dis-connect from hid device */
  117. bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
  118. /** Virtual UnPlug (VUP) the specified HID device */
  119. bt_status_t (*virtual_unplug)(bt_bdaddr_t *bd_addr);
  120. /** Set the HID device descriptor for the specified HID device. */
  121. bt_status_t (*set_info)(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info );
  122. /** Get the HID proto mode. */
  123. bt_status_t (*get_protocol) (bt_bdaddr_t *bd_addr, bthh_protocol_mode_t protocolMode);
  124. /** Set the HID proto mode. */
  125. bt_status_t (*set_protocol)(bt_bdaddr_t *bd_addr, bthh_protocol_mode_t protocolMode);
  126. /** Send a GET_REPORT to HID device. */
  127. bt_status_t (*get_report)(bt_bdaddr_t *bd_addr, bthh_report_type_t reportType, uint8_t reportId, int bufferSize);
  128. /** Send a SET_REPORT to HID device. */
  129. bt_status_t (*set_report)(bt_bdaddr_t *bd_addr, bthh_report_type_t reportType, char* report);
  130. /** Send data to HID device. */
  131. bt_status_t (*send_data)(bt_bdaddr_t *bd_addr, char* data);
  132. /** Closes the interface. */
  133. void (*cleanup)( void );
  134. } bthh_interface_t;
  135. __END_DECLS
  136. #endif /* ANDROID_INCLUDE_BT_HH_H */