bt_hh.h 6.3 KB

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