Fix the issue that can not send device event
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / hardware / bt_hf.h
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
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 */
23 typedef enum {
24         BTHF_AT_RESPONSE_ERROR = 0,
25         BTHF_AT_RESPONSE_OK
26 } bthf_at_response_t;
27
28 typedef 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
36 typedef 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
43 typedef enum {
44         BTHF_VR_STATE_STOPPED = 0,
45         BTHF_VR_STATE_STARTED
46 } bthf_vr_state_t;
47
48 typedef enum {
49         BTHF_VOLUME_TYPE_SPK = 0,
50         BTHF_VOLUME_TYPE_MIC
51 } bthf_volume_type_t;
52
53 /* Noise Reduction and Echo Cancellation */
54 typedef enum {
55         BTHF_NREC_STOP,
56         BTHF_NREC_START
57 } bthf_nrec_t;
58
59 /* WBS codec setting */
60 typedef enum {
61         BTHF_WBS_NONE,
62         BTHF_WBS_NO,
63         BTHF_WBS_YES
64 } bthf_wbs_config_t;
65
66 /* CHLD - Call held handling */
67 typedef enum {
68         BTHF_CHLD_TYPE_RELEASEHELD,              // Terminate all held or set UDUB("busy") to a waiting call
69         BTHF_CHLD_TYPE_RELEASEACTIVE_ACCEPTHELD, // Terminate all active calls and accepts a waiting/held call
70         BTHF_CHLD_TYPE_HOLDACTIVE_ACCEPTHELD,    // Hold all active calls and accepts a waiting/held call
71         BTHF_CHLD_TYPE_ADDHELDTOCONF,            // Add all held calls to a conference
72 } bthf_chld_type_t;
73
74 /** Callback for connection state change.
75  *  state will have one of the values from BtHfConnectionState
76  */
77 typedef void (*bthf_connection_state_callback)(bthf_connection_state_t state, bt_bdaddr_t *bd_addr);
78
79 /** Callback for audio connection state change.
80  *  state will have one of the values from BtHfAudioState
81  */
82 typedef void (*bthf_audio_state_callback)(bthf_audio_state_t state, bt_bdaddr_t *bd_addr);
83
84 /** Callback for VR connection state change.
85  *  state will have one of the values from BtHfVRState
86  */
87 typedef void (*bthf_vr_cmd_callback)(bthf_vr_state_t state, bt_bdaddr_t *bd_addr);
88
89 /** Callback for answer incoming call (ATA)
90  */
91 typedef void (*bthf_answer_call_cmd_callback)(bt_bdaddr_t *bd_addr);
92
93 /** Callback for disconnect call (AT+CHUP)
94  */
95 typedef void (*bthf_hangup_call_cmd_callback)(bt_bdaddr_t *bd_addr);
96
97 /** Callback for disconnect call (AT+CHUP)
98  *  type will denote Speaker/Mic gain (BtHfVolumeControl).
99  */
100 typedef void (*bthf_volume_cmd_callback)(bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr);
101
102 /** Callback for dialing an outgoing call
103  *  If number is NULL, redial
104  */
105 typedef void (*bthf_dial_call_cmd_callback)(char *number, bt_bdaddr_t *bd_addr);
106
107 /** Callback for sending DTMF tones
108  *  tone contains the dtmf character to be sent
109  */
110 typedef void (*bthf_dtmf_cmd_callback)(char tone, bt_bdaddr_t *bd_addr);
111
112 /** Callback for enabling/disabling noise reduction/echo cancellation
113  *  value will be 1 to enable, 0 to disable
114  */
115 typedef void (*bthf_nrec_cmd_callback)(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr);
116
117 /** Callback for AT+BCS and event from BAC
118  *  WBS enable, WBS disable
119  */
120 typedef void (*bthf_wbs_callback)(bthf_wbs_config_t wbs, bt_bdaddr_t *bd_addr);
121
122 /** Callback for call hold handling (AT+CHLD)
123  *  value will contain the call hold command (0, 1, 2, 3)
124  */
125 typedef void (*bthf_chld_cmd_callback)(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr);
126
127 /** Callback for CNUM (subscriber number)
128  */
129 typedef void (*bthf_cnum_cmd_callback)(bt_bdaddr_t *bd_addr);
130
131 /** Callback for indicators (CIND)
132  */
133 typedef void (*bthf_cind_cmd_callback)(bt_bdaddr_t *bd_addr);
134
135 /** Callback for operator selection (COPS)
136  */
137 typedef void (*bthf_cops_cmd_callback)(bt_bdaddr_t *bd_addr);
138
139 /** Callback for call list (AT+CLCC)
140  */
141 typedef void (*bthf_clcc_cmd_callback) (bt_bdaddr_t *bd_addr);
142
143 /** Callback for unknown AT command recd from HF
144  *  at_string will contain the unparsed AT string
145  */
146 typedef void (*bthf_unknown_at_cmd_callback)(char *at_string, bt_bdaddr_t *bd_addr);
147
148 /** Callback for keypressed (HSP) event.
149  */
150 typedef void (*bthf_key_pressed_cmd_callback)(bt_bdaddr_t *bd_addr);
151
152 /** BT-HF callback structure. */
153 typedef struct {
154         /** set to sizeof(BtHfCallbacks) */
155         size_t      size;
156         bthf_connection_state_callback  connection_state_cb;
157         bthf_audio_state_callback       audio_state_cb;
158         bthf_vr_cmd_callback            vr_cmd_cb;
159         bthf_answer_call_cmd_callback   answer_call_cmd_cb;
160         bthf_hangup_call_cmd_callback   hangup_call_cmd_cb;
161         bthf_volume_cmd_callback        volume_cmd_cb;
162         bthf_dial_call_cmd_callback     dial_call_cmd_cb;
163         bthf_dtmf_cmd_callback          dtmf_cmd_cb;
164         bthf_nrec_cmd_callback          nrec_cmd_cb;
165         bthf_wbs_callback               wbs_cb;
166         bthf_chld_cmd_callback          chld_cmd_cb;
167         bthf_cnum_cmd_callback          cnum_cmd_cb;
168         bthf_cind_cmd_callback          cind_cmd_cb;
169         bthf_cops_cmd_callback          cops_cmd_cb;
170         bthf_clcc_cmd_callback          clcc_cmd_cb;
171         bthf_unknown_at_cmd_callback    unknown_at_cmd_cb;
172         bthf_key_pressed_cmd_callback   key_pressed_cmd_cb;
173 } bthf_callbacks_t;
174
175 /** Network Status */
176 typedef enum {
177         BTHF_NETWORK_STATE_NOT_AVAILABLE = 0,
178         BTHF_NETWORK_STATE_AVAILABLE
179 } bthf_network_state_t;
180
181 /** Service type */
182 typedef enum {
183         BTHF_SERVICE_TYPE_HOME = 0,
184         BTHF_SERVICE_TYPE_ROAMING
185 } bthf_service_type_t;
186
187 typedef enum {
188         BTHF_CALL_STATE_ACTIVE = 0,
189         BTHF_CALL_STATE_HELD,
190         BTHF_CALL_STATE_DIALING,
191         BTHF_CALL_STATE_ALERTING,
192         BTHF_CALL_STATE_INCOMING,
193         BTHF_CALL_STATE_WAITING,
194         BTHF_CALL_STATE_IDLE
195 } bthf_call_state_t;
196
197 typedef enum {
198         BTHF_CALL_DIRECTION_OUTGOING = 0,
199         BTHF_CALL_DIRECTION_INCOMING
200 } bthf_call_direction_t;
201
202 typedef enum {
203         BTHF_CALL_TYPE_VOICE = 0,
204         BTHF_CALL_TYPE_DATA,
205         BTHF_CALL_TYPE_FAX
206 } bthf_call_mode_t;
207
208 typedef enum {
209         BTHF_CALL_MPTY_TYPE_SINGLE = 0,
210         BTHF_CALL_MPTY_TYPE_MULTI
211 } bthf_call_mpty_type_t;
212
213 typedef enum {
214         BTHF_CALL_ADDRTYPE_UNKNOWN = 0x81,
215         BTHF_CALL_ADDRTYPE_INTERNATIONAL = 0x91
216 } bthf_call_addrtype_t;
217
218 /** Represents the standard BT-HF interface. */
219 typedef struct {
220
221         /** set to sizeof(BtHfInterface) */
222         size_t          size;
223         /**
224          * Register the BtHf callbacks
225          */
226         bt_status_t (*init)(bthf_callbacks_t* callbacks, int max_hf_clients);
227
228         /** connect to headset */
229         bt_status_t (*connect)(bt_bdaddr_t *bd_addr);
230
231         /** dis-connect from headset */
232         bt_status_t (*disconnect)(bt_bdaddr_t *bd_addr);
233
234         /** create an audio connection */
235         bt_status_t (*connect_audio)(bt_bdaddr_t *bd_addr);
236
237         /** close the audio connection */
238         bt_status_t (*disconnect_audio)(bt_bdaddr_t *bd_addr);
239
240         /** start voice recognition */
241         bt_status_t (*start_voice_recognition)(bt_bdaddr_t *bd_addr);
242
243         /** stop voice recognition */
244         bt_status_t (*stop_voice_recognition)(bt_bdaddr_t *bd_addr);
245
246         /** volume control */
247         bt_status_t (*volume_control) (bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr);
248
249         /** Combined device status change notification */
250         bt_status_t (*device_status_notification)(bthf_network_state_t ntk_state, bthf_service_type_t svc_type, int signal,
251                         int batt_chg);
252
253         /** Response for COPS command */
254         bt_status_t (*cops_response)(const char *cops, bt_bdaddr_t *bd_addr);
255
256         /** Response for CIND command */
257         bt_status_t (*cind_response)(int svc, int num_active, int num_held, bthf_call_state_t call_setup_state,
258                         int signal, int roam, int batt_chg, bt_bdaddr_t *bd_addr);
259
260         /** Pre-formatted AT response, typically in response to unknown AT cmd */
261         bt_status_t (*formatted_at_response)(const char *rsp, bt_bdaddr_t *bd_addr);
262
263         /** ok/error response
264          *  ERROR (0)
265          *  OK    (1)
266          */
267         bt_status_t (*at_response) (bthf_at_response_t response_code, int error_code, bt_bdaddr_t *bd_addr);
268
269         /** response for CLCC command
270          *  Can be iteratively called for each call index
271          *  Call index of 0 will be treated as NULL termination (Completes response)
272          */
273         bt_status_t (*clcc_response) (int index, bthf_call_direction_t dir,
274                         bthf_call_state_t state, bthf_call_mode_t mode,
275                         bthf_call_mpty_type_t mpty, const char *number,
276                         bthf_call_addrtype_t type, bt_bdaddr_t *bd_addr);
277
278         /** notify of a call state change
279          *  Each update notifies
280          *    1. Number of active/held/ringing calls
281          *    2. call_state: This denotes the state change that triggered this msg
282          *                  This will take one of the values from BtHfCallState
283          *    3. number & type: valid only for incoming & waiting call
284          */
285         bt_status_t (*phone_state_change) (int num_active, int num_held, bthf_call_state_t call_setup_state,
286                         const char *number, bthf_call_addrtype_t type);
287
288         /** Closes the interface. */
289         void  (*cleanup)(void);
290
291         /** configureation for the SCO codec */
292         bt_status_t (*configure_wbs)(bt_bdaddr_t *bd_addr , bthf_wbs_config_t config);
293 } bthf_interface_t;
294
295 __END_DECLS
296
297 #endif /* ANDROID_INCLUDE_BT_HF_H */