blob: 7dcb40a4b2484b32c06403e80790754e2dc1b7bd [file] [log] [blame]
Andre Eisenbach05f49542012-09-18 12:15:26 -07001/*
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
17#ifndef ANDROID_INCLUDE_BT_HF_H
18#define ANDROID_INCLUDE_BT_HF_H
19
20__BEGIN_DECLS
21
22/* AT response code - OK/Error */
23typedef enum {
24 BTHF_AT_RESPONSE_ERROR = 0,
25 BTHF_AT_RESPONSE_OK
26} bthf_at_response_t;
27
28typedef enum {
29 BTHF_CONNECTION_STATE_DISCONNECTED = 0,
30 BTHF_CONNECTION_STATE_CONNECTING,
31 BTHF_CONNECTION_STATE_CONNECTED,
32 BTHF_CONNECTION_STATE_SLC_CONNECTED,
33 BTHF_CONNECTION_STATE_DISCONNECTING
34} bthf_connection_state_t;
35
36typedef enum {
37 BTHF_AUDIO_STATE_DISCONNECTED = 0,
38 BTHF_AUDIO_STATE_CONNECTING,
39 BTHF_AUDIO_STATE_CONNECTED,
40 BTHF_AUDIO_STATE_DISCONNECTING
41} bthf_audio_state_t;
42
43typedef enum {
44 BTHF_VR_STATE_STOPPED = 0,
45 BTHF_VR_STATE_STARTED
46} bthf_vr_state_t;
47
48typedef enum {
49 BTHF_VOLUME_TYPE_SPK = 0,
50 BTHF_VOLUME_TYPE_MIC
51} bthf_volume_type_t;
52
53/* Noise Reduction and Echo Cancellation */
54typedef enum
55{
56 BTHF_NREC_STOP,
57 BTHF_NREC_START
58} bthf_nrec_t;
59
Mudumba Ananth3c4db4c2014-04-27 21:04:35 -070060/* WBS codec setting */
61typedef enum
62{
63 BTHF_WBS_NONE,
64 BTHF_WBS_NO,
65 BTHF_WBS_YES
66}bthf_wbs_config_t;
67
Andre Eisenbach05f49542012-09-18 12:15:26 -070068/* CHLD - Call held handling */
69typedef enum
70{
71 BTHF_CHLD_TYPE_RELEASEHELD, // Terminate all held or set UDUB("busy") to a waiting call
72 BTHF_CHLD_TYPE_RELEASEACTIVE_ACCEPTHELD, // Terminate all active calls and accepts a waiting/held call
73 BTHF_CHLD_TYPE_HOLDACTIVE_ACCEPTHELD, // Hold all active calls and accepts a waiting/held call
74 BTHF_CHLD_TYPE_ADDHELDTOCONF, // Add all held calls to a conference
75} bthf_chld_type_t;
76
77/** Callback for connection state change.
78 * state will have one of the values from BtHfConnectionState
79 */
80typedef void (* bthf_connection_state_callback)(bthf_connection_state_t state, bt_bdaddr_t *bd_addr);
81
82/** Callback for audio connection state change.
83 * state will have one of the values from BtHfAudioState
84 */
85typedef void (* bthf_audio_state_callback)(bthf_audio_state_t state, bt_bdaddr_t *bd_addr);
86
87/** Callback for VR connection state change.
88 * state will have one of the values from BtHfVRState
89 */
Sunny Kapdi6253b052014-03-14 18:21:58 -070090typedef void (* bthf_vr_cmd_callback)(bthf_vr_state_t state, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -070091
92/** Callback for answer incoming call (ATA)
93 */
Sunny Kapdi6253b052014-03-14 18:21:58 -070094typedef void (* bthf_answer_call_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -070095
96/** Callback for disconnect call (AT+CHUP)
97 */
Sunny Kapdi6253b052014-03-14 18:21:58 -070098typedef void (* bthf_hangup_call_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -070099
100/** Callback for disconnect call (AT+CHUP)
101 * type will denote Speaker/Mic gain (BtHfVolumeControl).
102 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700103typedef void (* bthf_volume_cmd_callback)(bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700104
105/** Callback for dialing an outgoing call
106 * If number is NULL, redial
107 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700108typedef void (* bthf_dial_call_cmd_callback)(char *number, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700109
110/** Callback for sending DTMF tones
111 * tone contains the dtmf character to be sent
112 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700113typedef void (* bthf_dtmf_cmd_callback)(char tone, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700114
115/** Callback for enabling/disabling noise reduction/echo cancellation
116 * value will be 1 to enable, 0 to disable
117 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700118typedef void (* bthf_nrec_cmd_callback)(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700119
Mudumba Ananth3c4db4c2014-04-27 21:04:35 -0700120/** Callback for AT+BCS and event from BAC
121 * WBS enable, WBS disable
122 */
123typedef void (* bthf_wbs_callback)(bthf_wbs_config_t wbs, bt_bdaddr_t *bd_addr);
124
Andre Eisenbach05f49542012-09-18 12:15:26 -0700125/** Callback for call hold handling (AT+CHLD)
126 * value will contain the call hold command (0, 1, 2, 3)
127 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700128typedef void (* bthf_chld_cmd_callback)(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700129
130/** Callback for CNUM (subscriber number)
131 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700132typedef void (* bthf_cnum_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700133
134/** Callback for indicators (CIND)
135 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700136typedef void (* bthf_cind_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700137
138/** Callback for operator selection (COPS)
139 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700140typedef void (* bthf_cops_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700141
142/** Callback for call list (AT+CLCC)
143 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700144typedef void (* bthf_clcc_cmd_callback) (bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700145
146/** Callback for unknown AT command recd from HF
147 * at_string will contain the unparsed AT string
148 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700149typedef void (* bthf_unknown_at_cmd_callback)(char *at_string, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700150
151/** Callback for keypressed (HSP) event.
152 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700153typedef void (* bthf_key_pressed_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700154
155/** BT-HF callback structure. */
156typedef struct {
157 /** set to sizeof(BtHfCallbacks) */
158 size_t size;
159 bthf_connection_state_callback connection_state_cb;
160 bthf_audio_state_callback audio_state_cb;
161 bthf_vr_cmd_callback vr_cmd_cb;
162 bthf_answer_call_cmd_callback answer_call_cmd_cb;
163 bthf_hangup_call_cmd_callback hangup_call_cmd_cb;
164 bthf_volume_cmd_callback volume_cmd_cb;
165 bthf_dial_call_cmd_callback dial_call_cmd_cb;
166 bthf_dtmf_cmd_callback dtmf_cmd_cb;
167 bthf_nrec_cmd_callback nrec_cmd_cb;
Mudumba Ananth3c4db4c2014-04-27 21:04:35 -0700168 bthf_wbs_callback wbs_cb;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700169 bthf_chld_cmd_callback chld_cmd_cb;
170 bthf_cnum_cmd_callback cnum_cmd_cb;
171 bthf_cind_cmd_callback cind_cmd_cb;
172 bthf_cops_cmd_callback cops_cmd_cb;
173 bthf_clcc_cmd_callback clcc_cmd_cb;
174 bthf_unknown_at_cmd_callback unknown_at_cmd_cb;
175 bthf_key_pressed_cmd_callback key_pressed_cmd_cb;
176} bthf_callbacks_t;
177
178/** Network Status */
179typedef enum
180{
181 BTHF_NETWORK_STATE_NOT_AVAILABLE = 0,
182 BTHF_NETWORK_STATE_AVAILABLE
183} bthf_network_state_t;
184
185/** Service type */
186typedef enum
187{
188 BTHF_SERVICE_TYPE_HOME = 0,
189 BTHF_SERVICE_TYPE_ROAMING
190} bthf_service_type_t;
191
192typedef enum {
193 BTHF_CALL_STATE_ACTIVE = 0,
194 BTHF_CALL_STATE_HELD,
195 BTHF_CALL_STATE_DIALING,
196 BTHF_CALL_STATE_ALERTING,
197 BTHF_CALL_STATE_INCOMING,
198 BTHF_CALL_STATE_WAITING,
199 BTHF_CALL_STATE_IDLE
200} bthf_call_state_t;
201
202typedef enum {
203 BTHF_CALL_DIRECTION_OUTGOING = 0,
204 BTHF_CALL_DIRECTION_INCOMING
205} bthf_call_direction_t;
206
207typedef enum {
208 BTHF_CALL_TYPE_VOICE = 0,
209 BTHF_CALL_TYPE_DATA,
210 BTHF_CALL_TYPE_FAX
211} bthf_call_mode_t;
212
213typedef enum {
214 BTHF_CALL_MPTY_TYPE_SINGLE = 0,
215 BTHF_CALL_MPTY_TYPE_MULTI
216} bthf_call_mpty_type_t;
217
218typedef enum {
219 BTHF_CALL_ADDRTYPE_UNKNOWN = 0x81,
220 BTHF_CALL_ADDRTYPE_INTERNATIONAL = 0x91
221} bthf_call_addrtype_t;
222/** Represents the standard BT-HF interface. */
223typedef struct {
224
225 /** set to sizeof(BtHfInterface) */
226 size_t size;
227 /**
228 * Register the BtHf callbacks
229 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700230 bt_status_t (*init)( bthf_callbacks_t* callbacks, int max_hf_clients);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700231
232 /** connect to headset */
233 bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
234
235 /** dis-connect from headset */
236 bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
237
238 /** create an audio connection */
239 bt_status_t (*connect_audio)( bt_bdaddr_t *bd_addr );
240
241 /** close the audio connection */
242 bt_status_t (*disconnect_audio)( bt_bdaddr_t *bd_addr );
243
244 /** start voice recognition */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700245 bt_status_t (*start_voice_recognition)( bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700246
247 /** stop voice recognition */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700248 bt_status_t (*stop_voice_recognition)( bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700249
250 /** volume control */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700251 bt_status_t (*volume_control) (bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700252
253 /** Combined device status change notification */
254 bt_status_t (*device_status_notification)(bthf_network_state_t ntk_state, bthf_service_type_t svc_type, int signal,
255 int batt_chg);
256
257 /** Response for COPS command */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700258 bt_status_t (*cops_response)(const char *cops, bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700259
260 /** Response for CIND command */
261 bt_status_t (*cind_response)(int svc, int num_active, int num_held, bthf_call_state_t call_setup_state,
Sunny Kapdi6253b052014-03-14 18:21:58 -0700262 int signal, int roam, int batt_chg, bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700263
264 /** Pre-formatted AT response, typically in response to unknown AT cmd */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700265 bt_status_t (*formatted_at_response)(const char *rsp, bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700266
267 /** ok/error response
268 * ERROR (0)
269 * OK (1)
270 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700271 bt_status_t (*at_response) (bthf_at_response_t response_code, int error_code, bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700272
273 /** response for CLCC command
274 * Can be iteratively called for each call index
275 * Call index of 0 will be treated as NULL termination (Completes response)
276 */
277 bt_status_t (*clcc_response) (int index, bthf_call_direction_t dir,
278 bthf_call_state_t state, bthf_call_mode_t mode,
279 bthf_call_mpty_type_t mpty, const char *number,
Sunny Kapdi6253b052014-03-14 18:21:58 -0700280 bthf_call_addrtype_t type, bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700281
282 /** notify of a call state change
283 * Each update notifies
284 * 1. Number of active/held/ringing calls
285 * 2. call_state: This denotes the state change that triggered this msg
286 * This will take one of the values from BtHfCallState
287 * 3. number & type: valid only for incoming & waiting call
288 */
289 bt_status_t (*phone_state_change) (int num_active, int num_held, bthf_call_state_t call_setup_state,
290 const char *number, bthf_call_addrtype_t type);
291
292 /** Closes the interface. */
293 void (*cleanup)( void );
Mudumba Ananth3c4db4c2014-04-27 21:04:35 -0700294
295 /** configureation for the SCO codec */
296 bt_status_t (*configure_wbs)( bt_bdaddr_t *bd_addr ,bthf_wbs_config_t config );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700297} bthf_interface_t;
298
299__END_DECLS
300
301#endif /* ANDROID_INCLUDE_BT_HF_H */