bt_hf.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* SPDX-License-Identifier: Apache-2.0 */
  2. /*
  3. * Copyright (C) 2012 The Android Open Source Project
  4. *
  5. */
  6. #ifndef ANDROID_INCLUDE_BT_HF_H
  7. #define ANDROID_INCLUDE_BT_HF_H
  8. __BEGIN_DECLS
  9. /* AT response code - OK/Error */
  10. typedef enum {
  11. BTHF_AT_RESPONSE_ERROR = 0,
  12. BTHF_AT_RESPONSE_OK
  13. } bthf_at_response_t;
  14. typedef enum {
  15. BTHF_CONNECTION_STATE_DISCONNECTED = 0,
  16. BTHF_CONNECTION_STATE_CONNECTING,
  17. BTHF_CONNECTION_STATE_CONNECTED,
  18. BTHF_CONNECTION_STATE_SLC_CONNECTED,
  19. BTHF_CONNECTION_STATE_DISCONNECTING
  20. } bthf_connection_state_t;
  21. typedef enum {
  22. BTHF_AUDIO_STATE_DISCONNECTED = 0,
  23. BTHF_AUDIO_STATE_CONNECTING,
  24. BTHF_AUDIO_STATE_CONNECTED,
  25. BTHF_AUDIO_STATE_DISCONNECTING
  26. } bthf_audio_state_t;
  27. typedef enum {
  28. BTHF_VR_STATE_STOPPED = 0,
  29. BTHF_VR_STATE_STARTED
  30. } bthf_vr_state_t;
  31. typedef enum {
  32. BTHF_VOLUME_TYPE_SPK = 0,
  33. BTHF_VOLUME_TYPE_MIC
  34. } bthf_volume_type_t;
  35. /* Noise Reduction and Echo Cancellation */
  36. typedef enum
  37. {
  38. BTHF_NREC_STOP,
  39. BTHF_NREC_START
  40. } bthf_nrec_t;
  41. /* WBS codec setting */
  42. typedef enum
  43. {
  44. BTHF_WBS_NONE,
  45. BTHF_WBS_NO,
  46. BTHF_WBS_YES
  47. }bthf_wbs_config_t;
  48. /* CHLD - Call held handling */
  49. typedef enum
  50. {
  51. BTHF_CHLD_TYPE_RELEASEHELD, // Terminate all held or set UDUB("busy") to a waiting call
  52. BTHF_CHLD_TYPE_RELEASEACTIVE_ACCEPTHELD, // Terminate all active calls and accepts a waiting/held call
  53. BTHF_CHLD_TYPE_HOLDACTIVE_ACCEPTHELD, // Hold all active calls and accepts a waiting/held call
  54. BTHF_CHLD_TYPE_ADDHELDTOCONF, // Add all held calls to a conference
  55. } bthf_chld_type_t;
  56. /** Callback for connection state change.
  57. * state will have one of the values from BtHfConnectionState
  58. */
  59. typedef void (* bthf_connection_state_callback)(bthf_connection_state_t state, bt_bdaddr_t *bd_addr);
  60. /** Callback for audio connection state change.
  61. * state will have one of the values from BtHfAudioState
  62. */
  63. typedef void (* bthf_audio_state_callback)(bthf_audio_state_t state, bt_bdaddr_t *bd_addr);
  64. /** Callback for VR connection state change.
  65. * state will have one of the values from BtHfVRState
  66. */
  67. typedef void (* bthf_vr_cmd_callback)(bthf_vr_state_t state, bt_bdaddr_t *bd_addr);
  68. /** Callback for answer incoming call (ATA)
  69. */
  70. typedef void (* bthf_answer_call_cmd_callback)(bt_bdaddr_t *bd_addr);
  71. /** Callback for disconnect call (AT+CHUP)
  72. */
  73. typedef void (* bthf_hangup_call_cmd_callback)(bt_bdaddr_t *bd_addr);
  74. /** Callback for disconnect call (AT+CHUP)
  75. * type will denote Speaker/Mic gain (BtHfVolumeControl).
  76. */
  77. typedef void (* bthf_volume_cmd_callback)(bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr);
  78. /** Callback for dialing an outgoing call
  79. * If number is NULL, redial
  80. */
  81. typedef void (* bthf_dial_call_cmd_callback)(char *number, bt_bdaddr_t *bd_addr);
  82. /** Callback for sending DTMF tones
  83. * tone contains the dtmf character to be sent
  84. */
  85. typedef void (* bthf_dtmf_cmd_callback)(char tone, bt_bdaddr_t *bd_addr);
  86. /** Callback for enabling/disabling noise reduction/echo cancellation
  87. * value will be 1 to enable, 0 to disable
  88. */
  89. typedef void (* bthf_nrec_cmd_callback)(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr);
  90. /** Callback for AT+BCS and event from BAC
  91. * WBS enable, WBS disable
  92. */
  93. typedef void (* bthf_wbs_callback)(bthf_wbs_config_t wbs, bt_bdaddr_t *bd_addr);
  94. /** Callback for call hold handling (AT+CHLD)
  95. * value will contain the call hold command (0, 1, 2, 3)
  96. */
  97. typedef void (* bthf_chld_cmd_callback)(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr);
  98. /** Callback for CNUM (subscriber number)
  99. */
  100. typedef void (* bthf_cnum_cmd_callback)(bt_bdaddr_t *bd_addr);
  101. /** Callback for indicators (CIND)
  102. */
  103. typedef void (* bthf_cind_cmd_callback)(bt_bdaddr_t *bd_addr);
  104. /** Callback for operator selection (COPS)
  105. */
  106. typedef void (* bthf_cops_cmd_callback)(bt_bdaddr_t *bd_addr);
  107. /** Callback for call list (AT+CLCC)
  108. */
  109. typedef void (* bthf_clcc_cmd_callback) (bt_bdaddr_t *bd_addr);
  110. /** Callback for unknown AT command recd from HF
  111. * at_string will contain the unparsed AT string
  112. */
  113. typedef void (* bthf_unknown_at_cmd_callback)(char *at_string, bt_bdaddr_t *bd_addr);
  114. /** Callback for keypressed (HSP) event.
  115. */
  116. typedef void (* bthf_key_pressed_cmd_callback)(bt_bdaddr_t *bd_addr);
  117. /** BT-HF callback structure. */
  118. typedef struct {
  119. /** set to sizeof(BtHfCallbacks) */
  120. size_t size;
  121. bthf_connection_state_callback connection_state_cb;
  122. bthf_audio_state_callback audio_state_cb;
  123. bthf_vr_cmd_callback vr_cmd_cb;
  124. bthf_answer_call_cmd_callback answer_call_cmd_cb;
  125. bthf_hangup_call_cmd_callback hangup_call_cmd_cb;
  126. bthf_volume_cmd_callback volume_cmd_cb;
  127. bthf_dial_call_cmd_callback dial_call_cmd_cb;
  128. bthf_dtmf_cmd_callback dtmf_cmd_cb;
  129. bthf_nrec_cmd_callback nrec_cmd_cb;
  130. bthf_wbs_callback wbs_cb;
  131. bthf_chld_cmd_callback chld_cmd_cb;
  132. bthf_cnum_cmd_callback cnum_cmd_cb;
  133. bthf_cind_cmd_callback cind_cmd_cb;
  134. bthf_cops_cmd_callback cops_cmd_cb;
  135. bthf_clcc_cmd_callback clcc_cmd_cb;
  136. bthf_unknown_at_cmd_callback unknown_at_cmd_cb;
  137. bthf_key_pressed_cmd_callback key_pressed_cmd_cb;
  138. } bthf_callbacks_t;
  139. /** Network Status */
  140. typedef enum
  141. {
  142. BTHF_NETWORK_STATE_NOT_AVAILABLE = 0,
  143. BTHF_NETWORK_STATE_AVAILABLE
  144. } bthf_network_state_t;
  145. /** Service type */
  146. typedef enum
  147. {
  148. BTHF_SERVICE_TYPE_HOME = 0,
  149. BTHF_SERVICE_TYPE_ROAMING
  150. } bthf_service_type_t;
  151. typedef enum {
  152. BTHF_CALL_STATE_ACTIVE = 0,
  153. BTHF_CALL_STATE_HELD,
  154. BTHF_CALL_STATE_DIALING,
  155. BTHF_CALL_STATE_ALERTING,
  156. BTHF_CALL_STATE_INCOMING,
  157. BTHF_CALL_STATE_WAITING,
  158. BTHF_CALL_STATE_IDLE
  159. } bthf_call_state_t;
  160. typedef enum {
  161. BTHF_CALL_DIRECTION_OUTGOING = 0,
  162. BTHF_CALL_DIRECTION_INCOMING
  163. } bthf_call_direction_t;
  164. typedef enum {
  165. BTHF_CALL_TYPE_VOICE = 0,
  166. BTHF_CALL_TYPE_DATA,
  167. BTHF_CALL_TYPE_FAX
  168. } bthf_call_mode_t;
  169. typedef enum {
  170. BTHF_CALL_MPTY_TYPE_SINGLE = 0,
  171. BTHF_CALL_MPTY_TYPE_MULTI
  172. } bthf_call_mpty_type_t;
  173. typedef enum {
  174. BTHF_CALL_ADDRTYPE_UNKNOWN = 0x81,
  175. BTHF_CALL_ADDRTYPE_INTERNATIONAL = 0x91
  176. } bthf_call_addrtype_t;
  177. /** Represents the standard BT-HF interface. */
  178. typedef struct {
  179. /** set to sizeof(BtHfInterface) */
  180. size_t size;
  181. /**
  182. * Register the BtHf callbacks
  183. */
  184. bt_status_t (*init)( bthf_callbacks_t* callbacks, int max_hf_clients);
  185. /** connect to headset */
  186. bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
  187. /** dis-connect from headset */
  188. bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
  189. /** create an audio connection */
  190. bt_status_t (*connect_audio)( bt_bdaddr_t *bd_addr );
  191. /** close the audio connection */
  192. bt_status_t (*disconnect_audio)( bt_bdaddr_t *bd_addr );
  193. /** start voice recognition */
  194. bt_status_t (*start_voice_recognition)( bt_bdaddr_t *bd_addr );
  195. /** stop voice recognition */
  196. bt_status_t (*stop_voice_recognition)( bt_bdaddr_t *bd_addr );
  197. /** volume control */
  198. bt_status_t (*volume_control) (bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr );
  199. /** Combined device status change notification */
  200. bt_status_t (*device_status_notification)(bthf_network_state_t ntk_state, bthf_service_type_t svc_type, int signal,
  201. int batt_chg);
  202. /** Response for COPS command */
  203. bt_status_t (*cops_response)(const char *cops, bt_bdaddr_t *bd_addr );
  204. /** Response for CIND command */
  205. bt_status_t (*cind_response)(int svc, int num_active, int num_held, bthf_call_state_t call_setup_state,
  206. int signal, int roam, int batt_chg, bt_bdaddr_t *bd_addr );
  207. /** Pre-formatted AT response, typically in response to unknown AT cmd */
  208. bt_status_t (*formatted_at_response)(const char *rsp, bt_bdaddr_t *bd_addr );
  209. /** ok/error response
  210. * ERROR (0)
  211. * OK (1)
  212. */
  213. bt_status_t (*at_response) (bthf_at_response_t response_code, int error_code, bt_bdaddr_t *bd_addr );
  214. /** response for CLCC command
  215. * Can be iteratively called for each call index
  216. * Call index of 0 will be treated as NULL termination (Completes response)
  217. */
  218. bt_status_t (*clcc_response) (int index, bthf_call_direction_t dir,
  219. bthf_call_state_t state, bthf_call_mode_t mode,
  220. bthf_call_mpty_type_t mpty, const char *number,
  221. bthf_call_addrtype_t type, bt_bdaddr_t *bd_addr );
  222. /** notify of a call state change
  223. * Each update notifies
  224. * 1. Number of active/held/ringing calls
  225. * 2. call_state: This denotes the state change that triggered this msg
  226. * This will take one of the values from BtHfCallState
  227. * 3. number & type: valid only for incoming & waiting call
  228. */
  229. bt_status_t (*phone_state_change) (int num_active, int num_held, bthf_call_state_t call_setup_state,
  230. const char *number, bthf_call_addrtype_t type);
  231. /** Closes the interface. */
  232. void (*cleanup)( void );
  233. /** configureation for the SCO codec */
  234. bt_status_t (*configure_wbs)( bt_bdaddr_t *bd_addr ,bthf_wbs_config_t config );
  235. } bthf_interface_t;
  236. __END_DECLS
  237. #endif /* ANDROID_INCLUDE_BT_HF_H */