1 /*
2  * Copyright (C) 2012-2014 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 #pragma once
18 
19 #include <bluetooth/log.h>
20 
21 #include "types/raw_address.h"
22 
23 typedef enum {
24   BTHF_CLIENT_CONNECTION_STATE_DISCONNECTED = 0,
25   BTHF_CLIENT_CONNECTION_STATE_CONNECTING,
26   BTHF_CLIENT_CONNECTION_STATE_CONNECTED,
27   BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED,
28   BTHF_CLIENT_CONNECTION_STATE_DISCONNECTING
29 } bthf_client_connection_state_t;
30 
31 typedef enum {
32   BTHF_CLIENT_AUDIO_STATE_DISCONNECTED = 0,
33   BTHF_CLIENT_AUDIO_STATE_CONNECTING,
34   BTHF_CLIENT_AUDIO_STATE_CONNECTED,
35   BTHF_CLIENT_AUDIO_STATE_CONNECTED_MSBC,
36   BTHF_CLIENT_AUDIO_STATE_CONNECTED_LC3,
37 } bthf_client_audio_state_t;
38 
39 typedef enum {
40   BTHF_CLIENT_VR_STATE_STOPPED = 0,
41   BTHF_CLIENT_VR_STATE_STARTED
42 } bthf_client_vr_state_t;
43 
44 typedef enum {
45   BTHF_CLIENT_VOLUME_TYPE_SPK = 0,
46   BTHF_CLIENT_VOLUME_TYPE_MIC
47 } bthf_client_volume_type_t;
48 
49 typedef enum {
50   BTHF_CLIENT_NETWORK_STATE_NOT_AVAILABLE = 0,
51   BTHF_CLIENT_NETWORK_STATE_AVAILABLE
52 } bthf_client_network_state_t;
53 
54 typedef enum {
55   BTHF_CLIENT_SERVICE_TYPE_HOME = 0,
56   BTHF_CLIENT_SERVICE_TYPE_ROAMING
57 } bthf_client_service_type_t;
58 
59 typedef enum {
60   BTHF_CLIENT_CALL_STATE_ACTIVE = 0,
61   BTHF_CLIENT_CALL_STATE_HELD,
62   BTHF_CLIENT_CALL_STATE_DIALING,
63   BTHF_CLIENT_CALL_STATE_ALERTING,
64   BTHF_CLIENT_CALL_STATE_INCOMING,
65   BTHF_CLIENT_CALL_STATE_WAITING,
66   BTHF_CLIENT_CALL_STATE_HELD_BY_RESP_HOLD,
67 } bthf_client_call_state_t;
68 
69 typedef enum {
70   BTHF_CLIENT_CALL_NO_CALLS_IN_PROGRESS = 0,
71   BTHF_CLIENT_CALL_CALLS_IN_PROGRESS
72 } bthf_client_call_t;
73 
74 typedef enum {
75   BTHF_CLIENT_CALLSETUP_NONE = 0,
76   BTHF_CLIENT_CALLSETUP_INCOMING,
77   BTHF_CLIENT_CALLSETUP_OUTGOING,
78   BTHF_CLIENT_CALLSETUP_ALERTING
79 } bthf_client_callsetup_t;
80 
81 typedef enum {
82   BTHF_CLIENT_CALLHELD_NONE = 0,
83   BTHF_CLIENT_CALLHELD_HOLD_AND_ACTIVE,
84   BTHF_CLIENT_CALLHELD_HOLD,
85 } bthf_client_callheld_t;
86 
87 typedef enum {
88   BTHF_CLIENT_RESP_AND_HOLD_HELD = 0,
89   BTRH_CLIENT_RESP_AND_HOLD_ACCEPT,
90   BTRH_CLIENT_RESP_AND_HOLD_REJECT,
91 } bthf_client_resp_and_hold_t;
92 
93 typedef enum {
94   BTHF_CLIENT_CALL_DIRECTION_OUTGOING = 0,
95   BTHF_CLIENT_CALL_DIRECTION_INCOMING
96 } bthf_client_call_direction_t;
97 
98 typedef enum {
99   BTHF_CLIENT_CALL_MPTY_TYPE_SINGLE = 0,
100   BTHF_CLIENT_CALL_MPTY_TYPE_MULTI
101 } bthf_client_call_mpty_type_t;
102 
103 typedef enum {
104   BTHF_CLIENT_CMD_COMPLETE_OK = 0,
105   BTHF_CLIENT_CMD_COMPLETE_ERROR,
106   BTHF_CLIENT_CMD_COMPLETE_ERROR_NO_CARRIER,
107   BTHF_CLIENT_CMD_COMPLETE_ERROR_BUSY,
108   BTHF_CLIENT_CMD_COMPLETE_ERROR_NO_ANSWER,
109   BTHF_CLIENT_CMD_COMPLETE_ERROR_DELAYED,
110   BTHF_CLIENT_CMD_COMPLETE_ERROR_REJECTLISTED,
111   BTHF_CLIENT_CMD_COMPLETE_ERROR_CME
112 } bthf_client_cmd_complete_t;
113 
114 typedef enum {
115   BTHF_CLIENT_CALL_ACTION_CHLD_0 = 0,
116   BTHF_CLIENT_CALL_ACTION_CHLD_1,
117   BTHF_CLIENT_CALL_ACTION_CHLD_2,
118   BTHF_CLIENT_CALL_ACTION_CHLD_3,
119   BTHF_CLIENT_CALL_ACTION_CHLD_4,
120   BTHF_CLIENT_CALL_ACTION_CHLD_1x,
121   BTHF_CLIENT_CALL_ACTION_CHLD_2x,
122   BTHF_CLIENT_CALL_ACTION_ATA,
123   BTHF_CLIENT_CALL_ACTION_CHUP,
124   BTHF_CLIENT_CALL_ACTION_BTRH_0,
125   BTHF_CLIENT_CALL_ACTION_BTRH_1,
126   BTHF_CLIENT_CALL_ACTION_BTRH_2,
127 } bthf_client_call_action_t;
128 
129 typedef enum {
130   BTHF_CLIENT_SERVICE_UNKNOWN = 0,
131   BTHF_CLIENT_SERVICE_VOICE,
132   BTHF_CLIENT_SERVICE_FAX
133 } bthf_client_subscriber_service_type_t;
134 
135 typedef enum {
136   BTHF_CLIENT_IN_BAND_RINGTONE_NOT_PROVIDED = 0,
137   BTHF_CLIENT_IN_BAND_RINGTONE_PROVIDED,
138 } bthf_client_in_band_ring_state_t;
139 
140 /* Peer features masks */
141 #define BTHF_CLIENT_PEER_FEAT_3WAY 0x00000001   /* Three-way calling */
142 #define BTHF_CLIENT_PEER_FEAT_ECNR 0x00000002   /* Echo cancellation and/or noise reduction */
143 #define BTHF_CLIENT_PEER_FEAT_VREC 0x00000004   /* Voice recognition */
144 #define BTHF_CLIENT_PEER_FEAT_INBAND 0x00000008 /* In-band ring tone */
145 #define BTHF_CLIENT_PEER_FEAT_VTAG 0x00000010   /* Attach a phone number to a voice tag */
146 #define BTHF_CLIENT_PEER_FEAT_REJECT 0x00000020 /* Ability to reject incoming call */
147 #define BTHF_CLIENT_PEER_FEAT_ECS 0x00000040    /* Enhanced Call Status */
148 #define BTHF_CLIENT_PEER_FEAT_ECC 0x00000080    /* Enhanced Call Control */
149 #define BTHF_CLIENT_PEER_FEAT_EXTERR 0x00000100 /* Extended error codes */
150 #define BTHF_CLIENT_PEER_FEAT_CODEC 0x00000200  /* Codec Negotiation */
151 
152 /* Peer call handling features masks */
153 #define BTHF_CLIENT_CHLD_FEAT_REL 0x00000001 /* 0  Release waiting call or held calls */
154 #define BTHF_CLIENT_CHLD_FEAT_REL_ACC                                                      \
155   0x00000002                                   /* 1  Release active calls and accept other \
156                                                      (waiting or held) cal */
157 #define BTHF_CLIENT_CHLD_FEAT_REL_X 0x00000004 /* 1x Release specified active call only */
158 #define BTHF_CLIENT_CHLD_FEAT_HOLD_ACC                   \
159   0x00000008 /* 2  Active calls on hold and accept other \
160                    (waiting or held) call */
161 #define BTHF_CLIENT_CHLD_FEAT_PRIV_X                                                     \
162   0x00000010                                   /* 2x Request private mode with specified \
163                                                      call (put the rest on hold) */
164 #define BTHF_CLIENT_CHLD_FEAT_MERGE 0x00000020 /* 3  Add held call to multiparty */
165 #define BTHF_CLIENT_CHLD_FEAT_MERGE_DETACH     \
166   0x00000040 /* 4  Connect two calls and leave \
167                    (disconnect from) multiparty */
168 
169 /** Callback for connection state change.
170  *  state will have one of the values from BtHfConnectionState
171  *  peer/chld_features are valid only for
172  * BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED state
173  */
174 typedef void (*bthf_client_connection_state_callback)(const RawAddress* bd_addr,
175                                                       bthf_client_connection_state_t state,
176                                                       unsigned int peer_feat,
177                                                       unsigned int chld_feat);
178 
179 /** Callback for audio connection state change.
180  *  state will have one of the values from BtHfAudioState
181  */
182 typedef void (*bthf_client_audio_state_callback)(const RawAddress* bd_addr,
183                                                  bthf_client_audio_state_t state);
184 
185 /** Callback for VR connection state change.
186  *  state will have one of the values from BtHfVRState
187  */
188 typedef void (*bthf_client_vr_cmd_callback)(const RawAddress* bd_addr,
189                                             bthf_client_vr_state_t state);
190 
191 /** Callback for network state change
192  */
193 typedef void (*bthf_client_network_state_callback)(const RawAddress* bd_addr,
194                                                    bthf_client_network_state_t state);
195 
196 /** Callback for network roaming status change
197  */
198 typedef void (*bthf_client_network_roaming_callback)(const RawAddress* bd_addr,
199                                                      bthf_client_service_type_t type);
200 
201 /** Callback for signal strength indication
202  */
203 typedef void (*bthf_client_network_signal_callback)(const RawAddress* bd_addr, int signal_strength);
204 
205 /** Callback for battery level indication
206  */
207 typedef void (*bthf_client_battery_level_callback)(const RawAddress* bd_addr, int battery_level);
208 
209 /** Callback for current operator name
210  */
211 typedef void (*bthf_client_current_operator_callback)(const RawAddress* bd_addr, const char* name);
212 
213 /** Callback for call indicator
214  */
215 typedef void (*bthf_client_call_callback)(const RawAddress* bd_addr, bthf_client_call_t call);
216 
217 /** Callback for callsetup indicator
218  */
219 typedef void (*bthf_client_callsetup_callback)(const RawAddress* bd_addr,
220                                                bthf_client_callsetup_t callsetup);
221 
222 /** Callback for callheld indicator
223  */
224 typedef void (*bthf_client_callheld_callback)(const RawAddress* bd_addr,
225                                               bthf_client_callheld_t callheld);
226 
227 /** Callback for response and hold
228  */
229 typedef void (*bthf_client_resp_and_hold_callback)(const RawAddress* bd_addr,
230                                                    bthf_client_resp_and_hold_t resp_and_hold);
231 
232 /** Callback for Calling Line Identification notification
233  *  Will be called only when there is an incoming call and number is provided.
234  */
235 typedef void (*bthf_client_clip_callback)(const RawAddress* bd_addr, const char* number);
236 
237 /**
238  * Callback for Call Waiting notification
239  */
240 typedef void (*bthf_client_call_waiting_callback)(const RawAddress* bd_addr, const char* number);
241 
242 /**
243  *  Callback for listing current calls. Can be called multiple time.
244  *  If number is unknown NULL is passed.
245  */
246 typedef void (*bthf_client_current_calls)(const RawAddress* bd_addr, int index,
247                                           bthf_client_call_direction_t dir,
248                                           bthf_client_call_state_t state,
249                                           bthf_client_call_mpty_type_t mpty, const char* number);
250 
251 /** Callback for audio volume change
252  */
253 typedef void (*bthf_client_volume_change_callback)(const RawAddress* bd_addr,
254                                                    bthf_client_volume_type_t type, int volume);
255 
256 /** Callback for command complete event
257  *  cme is valid only for BTHF_CLIENT_CMD_COMPLETE_ERROR_CME type
258  */
259 typedef void (*bthf_client_cmd_complete_callback)(const RawAddress* bd_addr,
260                                                   bthf_client_cmd_complete_t type, int cme);
261 
262 /** Callback for subscriber information
263  */
264 typedef void (*bthf_client_subscriber_info_callback)(const RawAddress* bd_addr, const char* name,
265                                                      bthf_client_subscriber_service_type_t type);
266 
267 /** Callback for in-band ring tone settings
268  */
269 typedef void (*bthf_client_in_band_ring_tone_callback)(const RawAddress* bd_addr,
270                                                        bthf_client_in_band_ring_state_t state);
271 
272 /**
273  * Callback for requested number from AG
274  */
275 typedef void (*bthf_client_last_voice_tag_number_callback)(const RawAddress* bd_addr,
276                                                            const char* number);
277 
278 /**
279  * Callback for sending ring indication to app
280  */
281 typedef void (*bthf_client_ring_indication_callback)(const RawAddress* bd_addr);
282 
283 /**
284  * Callback for sending unknown (vendor specific) event
285  */
286 typedef void (*bthf_client_unknown_event_callback)(const RawAddress* bd_addr,
287                                                    const char* unknow_event);
288 
289 /** BT-HF callback structure. */
290 typedef struct {
291   /** set to sizeof(BtHfClientCallbacks) */
292   size_t size;
293   bthf_client_connection_state_callback connection_state_cb;
294   bthf_client_audio_state_callback audio_state_cb;
295   bthf_client_vr_cmd_callback vr_cmd_cb;
296   bthf_client_network_state_callback network_state_cb;
297   bthf_client_network_roaming_callback network_roaming_cb;
298   bthf_client_network_signal_callback network_signal_cb;
299   bthf_client_battery_level_callback battery_level_cb;
300   bthf_client_current_operator_callback current_operator_cb;
301   bthf_client_call_callback call_cb;
302   bthf_client_callsetup_callback callsetup_cb;
303   bthf_client_callheld_callback callheld_cb;
304   bthf_client_resp_and_hold_callback resp_and_hold_cb;
305   bthf_client_clip_callback clip_cb;
306   bthf_client_call_waiting_callback call_waiting_cb;
307   bthf_client_current_calls current_calls_cb;
308   bthf_client_volume_change_callback volume_change_cb;
309   bthf_client_cmd_complete_callback cmd_complete_cb;
310   bthf_client_subscriber_info_callback subscriber_info_cb;
311   bthf_client_in_band_ring_tone_callback in_band_ring_tone_cb;
312   bthf_client_last_voice_tag_number_callback last_voice_tag_number_callback;
313   bthf_client_ring_indication_callback ring_indication_cb;
314   bthf_client_unknown_event_callback unknown_event_cb;
315 } bthf_client_callbacks_t;
316 
317 /** Represents the standard BT-HF interface. */
318 typedef struct {
319   /** set to sizeof(BtHfClientInterface) */
320   size_t size;
321   /**
322    * Register the BtHf callbacks
323    */
324   bt_status_t (*init)(bthf_client_callbacks_t* callbacks);
325 
326   /** connect to audio gateway */
327   bt_status_t (*connect)(const RawAddress* bd_addr);
328 
329   /** disconnect from audio gateway */
330   bt_status_t (*disconnect)(const RawAddress* bd_addr);
331 
332   /** create an audio connection */
333   bt_status_t (*connect_audio)(const RawAddress* bd_addr);
334 
335   /** close the audio connection */
336   bt_status_t (*disconnect_audio)(const RawAddress* bd_addr);
337 
338   /** start voice recognition */
339   bt_status_t (*start_voice_recognition)(const RawAddress* bd_addr);
340 
341   /** stop voice recognition */
342   bt_status_t (*stop_voice_recognition)(const RawAddress* bd_addr);
343 
344   /** volume control */
345   bt_status_t (*volume_control)(const RawAddress* bd_addr, bthf_client_volume_type_t type,
346                                 int volume);
347 
348   /** place a call with number a number
349    * if number is NULL last called number is called (aka re-dial)*/
350   bt_status_t (*dial)(const RawAddress* bd_addr, const char* number);
351 
352   /** place a call with number specified by location (speed dial) */
353   bt_status_t (*dial_memory)(const RawAddress* bd_addr, int location);
354 
355   /** perform specified call related action
356    * idx is limited only for enhanced call control related action
357    */
358   bt_status_t (*handle_call_action)(const RawAddress* bd_addr, bthf_client_call_action_t action,
359                                     int idx);
360 
361   /** query list of current calls */
362   bt_status_t (*query_current_calls)(const RawAddress* bd_addr);
363 
364   /** query name of current selected operator */
365   bt_status_t (*query_current_operator_name)(const RawAddress* bd_addr);
366 
367   /** Retrieve subscriber information */
368   bt_status_t (*retrieve_subscriber_info)(const RawAddress* bd_addr);
369 
370   /** Send DTMF code*/
371   bt_status_t (*send_dtmf)(const RawAddress* bd_addr, char code);
372 
373   /** Request a phone number from AG corresponding to last voice tag recorded */
374   bt_status_t (*request_last_voice_tag_number)(const RawAddress* bd_addr);
375 
376   /** Closes the interface. */
377   void (*cleanup)(void);
378 
379   /** Send AT Command. */
380   bt_status_t (*send_at_cmd)(const RawAddress* bd_addr, int cmd, int val1, int val2,
381                              const char* arg);
382 
383   /** Send hfp audio policy to remote */
384   bt_status_t (*send_android_at)(const RawAddress* bd_addr, const char* arg);
385 } bthf_client_interface_t;
386 
387 namespace std {
388 template <>
389 struct formatter<bthf_client_connection_state_t> : enum_formatter<bthf_client_connection_state_t> {
390 };
391 }  // namespace std
392