blob: 15c26e90df05dcec25ea87b6d65cca575d691ff0 [file] [log] [blame]
Nitin Srivastava2948eec2013-06-13 11:47:21 +05301/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2 * Not a Contribution.
3 *
Andre Eisenbach05f49542012-09-18 12:15:26 -07004 * Copyright (C) 2012 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef ANDROID_INCLUDE_BT_HF_H
20#define ANDROID_INCLUDE_BT_HF_H
21
22__BEGIN_DECLS
23
24/* AT response code - OK/Error */
25typedef enum {
26 BTHF_AT_RESPONSE_ERROR = 0,
27 BTHF_AT_RESPONSE_OK
28} bthf_at_response_t;
29
30typedef enum {
31 BTHF_CONNECTION_STATE_DISCONNECTED = 0,
32 BTHF_CONNECTION_STATE_CONNECTING,
33 BTHF_CONNECTION_STATE_CONNECTED,
34 BTHF_CONNECTION_STATE_SLC_CONNECTED,
35 BTHF_CONNECTION_STATE_DISCONNECTING
36} bthf_connection_state_t;
37
38typedef enum {
39 BTHF_AUDIO_STATE_DISCONNECTED = 0,
40 BTHF_AUDIO_STATE_CONNECTING,
41 BTHF_AUDIO_STATE_CONNECTED,
42 BTHF_AUDIO_STATE_DISCONNECTING
43} bthf_audio_state_t;
44
45typedef enum {
46 BTHF_VR_STATE_STOPPED = 0,
47 BTHF_VR_STATE_STARTED
48} bthf_vr_state_t;
49
50typedef enum {
51 BTHF_VOLUME_TYPE_SPK = 0,
52 BTHF_VOLUME_TYPE_MIC
53} bthf_volume_type_t;
54
55/* Noise Reduction and Echo Cancellation */
56typedef enum
57{
58 BTHF_NREC_STOP,
59 BTHF_NREC_START
60} bthf_nrec_t;
61
Mudumba Ananth3c4db4c2014-04-27 21:04:35 -070062/* WBS codec setting */
63typedef enum
64{
65 BTHF_WBS_NONE,
66 BTHF_WBS_NO,
67 BTHF_WBS_YES
68}bthf_wbs_config_t;
69
Andre Eisenbach05f49542012-09-18 12:15:26 -070070/* CHLD - Call held handling */
71typedef enum
72{
73 BTHF_CHLD_TYPE_RELEASEHELD, // Terminate all held or set UDUB("busy") to a waiting call
74 BTHF_CHLD_TYPE_RELEASEACTIVE_ACCEPTHELD, // Terminate all active calls and accepts a waiting/held call
75 BTHF_CHLD_TYPE_HOLDACTIVE_ACCEPTHELD, // Hold all active calls and accepts a waiting/held call
76 BTHF_CHLD_TYPE_ADDHELDTOCONF, // Add all held calls to a conference
77} bthf_chld_type_t;
78
79/** Callback for connection state change.
80 * state will have one of the values from BtHfConnectionState
81 */
82typedef void (* bthf_connection_state_callback)(bthf_connection_state_t state, bt_bdaddr_t *bd_addr);
83
84/** Callback for audio connection state change.
85 * state will have one of the values from BtHfAudioState
86 */
87typedef void (* bthf_audio_state_callback)(bthf_audio_state_t state, bt_bdaddr_t *bd_addr);
88
89/** Callback for VR connection state change.
90 * state will have one of the values from BtHfVRState
91 */
Sunny Kapdi6253b052014-03-14 18:21:58 -070092typedef void (* bthf_vr_cmd_callback)(bthf_vr_state_t state, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -070093
94/** Callback for answer incoming call (ATA)
95 */
Sunny Kapdi6253b052014-03-14 18:21:58 -070096typedef void (* bthf_answer_call_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -070097
98/** Callback for disconnect call (AT+CHUP)
99 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700100typedef void (* bthf_hangup_call_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700101
102/** Callback for disconnect call (AT+CHUP)
103 * type will denote Speaker/Mic gain (BtHfVolumeControl).
104 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700105typedef void (* bthf_volume_cmd_callback)(bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700106
107/** Callback for dialing an outgoing call
108 * If number is NULL, redial
109 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700110typedef void (* bthf_dial_call_cmd_callback)(char *number, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700111
112/** Callback for sending DTMF tones
113 * tone contains the dtmf character to be sent
114 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700115typedef void (* bthf_dtmf_cmd_callback)(char tone, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700116
117/** Callback for enabling/disabling noise reduction/echo cancellation
118 * value will be 1 to enable, 0 to disable
119 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700120typedef void (* bthf_nrec_cmd_callback)(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700121
Mudumba Ananth3c4db4c2014-04-27 21:04:35 -0700122/** Callback for AT+BCS and event from BAC
123 * WBS enable, WBS disable
124 */
125typedef void (* bthf_wbs_callback)(bthf_wbs_config_t wbs, bt_bdaddr_t *bd_addr);
126
Andre Eisenbach05f49542012-09-18 12:15:26 -0700127/** Callback for call hold handling (AT+CHLD)
128 * value will contain the call hold command (0, 1, 2, 3)
129 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700130typedef void (* bthf_chld_cmd_callback)(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700131
132/** Callback for CNUM (subscriber number)
133 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700134typedef void (* bthf_cnum_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700135
136/** Callback for indicators (CIND)
137 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700138typedef void (* bthf_cind_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700139
140/** Callback for operator selection (COPS)
141 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700142typedef void (* bthf_cops_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700143
144/** Callback for call list (AT+CLCC)
145 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700146typedef void (* bthf_clcc_cmd_callback) (bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700147
148/** Callback for unknown AT command recd from HF
149 * at_string will contain the unparsed AT string
150 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700151typedef void (* bthf_unknown_at_cmd_callback)(char *at_string, bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700152
153/** Callback for keypressed (HSP) event.
154 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700155typedef void (* bthf_key_pressed_cmd_callback)(bt_bdaddr_t *bd_addr);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700156
157/** BT-HF callback structure. */
158typedef struct {
159 /** set to sizeof(BtHfCallbacks) */
160 size_t size;
161 bthf_connection_state_callback connection_state_cb;
162 bthf_audio_state_callback audio_state_cb;
163 bthf_vr_cmd_callback vr_cmd_cb;
164 bthf_answer_call_cmd_callback answer_call_cmd_cb;
165 bthf_hangup_call_cmd_callback hangup_call_cmd_cb;
166 bthf_volume_cmd_callback volume_cmd_cb;
167 bthf_dial_call_cmd_callback dial_call_cmd_cb;
168 bthf_dtmf_cmd_callback dtmf_cmd_cb;
169 bthf_nrec_cmd_callback nrec_cmd_cb;
Mudumba Ananth3c4db4c2014-04-27 21:04:35 -0700170 bthf_wbs_callback wbs_cb;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700171 bthf_chld_cmd_callback chld_cmd_cb;
172 bthf_cnum_cmd_callback cnum_cmd_cb;
173 bthf_cind_cmd_callback cind_cmd_cb;
174 bthf_cops_cmd_callback cops_cmd_cb;
175 bthf_clcc_cmd_callback clcc_cmd_cb;
176 bthf_unknown_at_cmd_callback unknown_at_cmd_cb;
177 bthf_key_pressed_cmd_callback key_pressed_cmd_cb;
178} bthf_callbacks_t;
179
180/** Network Status */
181typedef enum
182{
183 BTHF_NETWORK_STATE_NOT_AVAILABLE = 0,
184 BTHF_NETWORK_STATE_AVAILABLE
185} bthf_network_state_t;
186
187/** Service type */
188typedef enum
189{
190 BTHF_SERVICE_TYPE_HOME = 0,
191 BTHF_SERVICE_TYPE_ROAMING
192} bthf_service_type_t;
193
194typedef enum {
195 BTHF_CALL_STATE_ACTIVE = 0,
196 BTHF_CALL_STATE_HELD,
197 BTHF_CALL_STATE_DIALING,
198 BTHF_CALL_STATE_ALERTING,
199 BTHF_CALL_STATE_INCOMING,
200 BTHF_CALL_STATE_WAITING,
201 BTHF_CALL_STATE_IDLE
202} bthf_call_state_t;
203
204typedef enum {
205 BTHF_CALL_DIRECTION_OUTGOING = 0,
206 BTHF_CALL_DIRECTION_INCOMING
207} bthf_call_direction_t;
208
209typedef enum {
210 BTHF_CALL_TYPE_VOICE = 0,
211 BTHF_CALL_TYPE_DATA,
212 BTHF_CALL_TYPE_FAX
213} bthf_call_mode_t;
214
215typedef enum {
216 BTHF_CALL_MPTY_TYPE_SINGLE = 0,
217 BTHF_CALL_MPTY_TYPE_MULTI
218} bthf_call_mpty_type_t;
219
220typedef enum {
221 BTHF_CALL_ADDRTYPE_UNKNOWN = 0x81,
222 BTHF_CALL_ADDRTYPE_INTERNATIONAL = 0x91
223} bthf_call_addrtype_t;
224/** Represents the standard BT-HF interface. */
225typedef struct {
226
227 /** set to sizeof(BtHfInterface) */
228 size_t size;
229 /**
230 * Register the BtHf callbacks
231 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700232 bt_status_t (*init)( bthf_callbacks_t* callbacks, int max_hf_clients);
Andre Eisenbach05f49542012-09-18 12:15:26 -0700233
Nitin Srivastava2948eec2013-06-13 11:47:21 +0530234 /** Set the feature bitmask */
235 bt_status_t (*init_features)( int feature_bitmask );
236
Andre Eisenbach05f49542012-09-18 12:15:26 -0700237 /** connect to headset */
238 bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
239
240 /** dis-connect from headset */
241 bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
242
243 /** create an audio connection */
244 bt_status_t (*connect_audio)( bt_bdaddr_t *bd_addr );
245
246 /** close the audio connection */
247 bt_status_t (*disconnect_audio)( bt_bdaddr_t *bd_addr );
248
249 /** start voice recognition */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700250 bt_status_t (*start_voice_recognition)( bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700251
252 /** stop voice recognition */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700253 bt_status_t (*stop_voice_recognition)( bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700254
255 /** volume control */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700256 bt_status_t (*volume_control) (bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700257
258 /** Combined device status change notification */
259 bt_status_t (*device_status_notification)(bthf_network_state_t ntk_state, bthf_service_type_t svc_type, int signal,
260 int batt_chg);
261
262 /** Response for COPS command */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700263 bt_status_t (*cops_response)(const char *cops, bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700264
265 /** Response for CIND command */
266 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 -0700267 int signal, int roam, int batt_chg, bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700268
269 /** Pre-formatted AT response, typically in response to unknown AT cmd */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700270 bt_status_t (*formatted_at_response)(const char *rsp, bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700271
272 /** ok/error response
273 * ERROR (0)
274 * OK (1)
275 */
Sunny Kapdi6253b052014-03-14 18:21:58 -0700276 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 -0700277
278 /** response for CLCC command
279 * Can be iteratively called for each call index
280 * Call index of 0 will be treated as NULL termination (Completes response)
281 */
282 bt_status_t (*clcc_response) (int index, bthf_call_direction_t dir,
283 bthf_call_state_t state, bthf_call_mode_t mode,
284 bthf_call_mpty_type_t mpty, const char *number,
Sunny Kapdi6253b052014-03-14 18:21:58 -0700285 bthf_call_addrtype_t type, bt_bdaddr_t *bd_addr );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700286
287 /** notify of a call state change
288 * Each update notifies
289 * 1. Number of active/held/ringing calls
290 * 2. call_state: This denotes the state change that triggered this msg
291 * This will take one of the values from BtHfCallState
292 * 3. number & type: valid only for incoming & waiting call
293 */
294 bt_status_t (*phone_state_change) (int num_active, int num_held, bthf_call_state_t call_setup_state,
295 const char *number, bthf_call_addrtype_t type);
296
Nitin Srivastavaee5df9f2013-06-13 11:47:21 +0530297 /** get remote supported features */
298 int (*get_remote_features)(bt_bdaddr_t *bd_addr);
299
Andre Eisenbach05f49542012-09-18 12:15:26 -0700300 /** Closes the interface. */
301 void (*cleanup)( void );
Mudumba Ananth3c4db4c2014-04-27 21:04:35 -0700302
303 /** configureation for the SCO codec */
304 bt_status_t (*configure_wbs)( bt_bdaddr_t *bd_addr ,bthf_wbs_config_t config );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700305} bthf_interface_t;
306
307__END_DECLS
308
309#endif /* ANDROID_INCLUDE_BT_HF_H */