xref: /btstack/src/classic/hfp_ag.h (revision 3b261e460e54b6a99db8e440edc54119d070688f)
1 /*
2  * Copyright (C) 2014 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 // *****************************************************************************
39 //
40 // HFP Audio Gateway (AG) unit
41 //
42 // *****************************************************************************
43 
44 
45 #ifndef btstack_hfp_ag_h
46 #define btstack_hfp_ag_h
47 
48 #include "hci.h"
49 #include "classic/sdp_client_rfcomm.h"
50 #include "classic/hfp.h"
51 #include "classic/hfp_gsm_model.h"
52 
53 #if defined __cplusplus
54 extern "C" {
55 #endif
56 
57 /* API_START */
58 typedef struct {
59     uint8_t type;
60     const char * number;
61 } hfp_phone_number_t;
62 
63 /**
64  * @brief Create HFP Audio Gateway (AG) SDP service record.
65  * @param service
66  * @param rfcomm_channel_nr
67  * @param name
68  * @param ability_to_reject_call
69  * @param suported_features 32-bit bitmap, see HFP_AGSF_* values in hfp.h
70  * @param wide_band_speech supported
71  */
72 void hfp_ag_create_sdp_record(uint8_t * service, uint32_t service_record_handle, int rfcomm_channel_nr, const char * name, uint8_t ability_to_reject_call, uint16_t supported_features, int wide_band_speech);
73 
74 /**
75  * @brief Set up HFP Audio Gateway (AG) device without additional supported features.
76  * @param rfcomm_channel_nr
77  */
78 void hfp_ag_init(uint16_t rfcomm_channel_nr);
79 
80 /**
81  * @brief Set codecs.
82  * @param codecs_nr
83  * @param codecs
84  */
85 void hfp_ag_init_codecs(int codecs_nr, const uint8_t * codecs);
86 
87 /**
88  * @brief Set supported features.
89  * @param supported_features 32-bit bitmap, see HFP_AGSF_* values in hfp.h
90  */
91 void hfp_ag_init_supported_features(uint32_t supported_features);
92 
93 /**
94  * @brief Set AG indicators.
95  * @param indicators_nr
96  * @param indicators
97  */
98 void hfp_ag_init_ag_indicators(int ag_indicators_nr, const hfp_ag_indicator_t * ag_indicators);
99 
100 /**
101  * @brief Set HF indicators.
102  * @param indicators_nr
103  * @param indicators
104  */
105 void hfp_ag_init_hf_indicators(int hf_indicators_nr, const hfp_generic_status_indicator_t * hf_indicators);
106 
107 /**
108  * @brief Set Call Hold services.
109  * @param indicators_nr
110  * @param indicators
111  */
112 void hfp_ag_init_call_hold_services(int call_hold_services_nr, const char * call_hold_services[]);
113 
114 
115 /**
116  * @brief Register callback for the HFP Audio Gateway (AG) client.
117  * @param callback
118  */
119 void hfp_ag_register_packet_handler(btstack_packet_handler_t callback);
120 
121 /**
122  * @brief Enable in-band ring tone.
123  * @param use_in_band_ring_tone
124  */
125 void hfp_ag_set_use_in_band_ring_tone(int use_in_band_ring_tone);
126 
127 
128 // actions used by local device / user
129 
130 /**
131  * @brief Establish RFCOMM connection, and perform service level connection agreement:
132  * - exchange of supported features
133  * - report Audio Gateway (AG) indicators and their status
134  * - enable indicator status update in the AG
135  * - accept the information about available codecs in the Hands-Free (HF), if sent
136  * - report own information describing the call hold and multiparty services, if possible
137  * - report which HF indicators are enabled on the AG, if possible
138  * The status of SLC connection establishment is reported via
139  * HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED.
140  *
141  * @param bd_addr Bluetooth address of the HF
142  */
143 void hfp_ag_establish_service_level_connection(bd_addr_t bd_addr);
144 
145 /**
146  * @brief Release the RFCOMM channel and the audio connection between the HF and the AG.
147  * If the audio connection exists, it will be released.
148  * The status of releasing the SLC connection is reported via
149  * HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED.
150  *
151  * @param bd_addr Bluetooth address of the HF
152  */
153 void hfp_ag_release_service_level_connection(hci_con_handle_t acl_handle);
154 
155 /**
156  * @brief Establish audio connection.
157  * The status of Audio connection establishment is reported via is reported via
158  * HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE.
159  * @param bd_addr Bluetooth address of the HF
160  */
161 void hfp_ag_establish_audio_connection(hci_con_handle_t acl_handle);
162 
163 /**
164  * @brief Release audio connection.
165  * The status of releasing the Audio connection is reported via is reported via
166  * HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE.
167  * @param bd_addr Bluetooth address of the HF
168  */
169 void hfp_ag_release_audio_connection(hci_con_handle_t acl_handle);
170 
171 /**
172  * @brief Put the current call on hold, if it exists, and accept incoming call.
173  */
174 void hfp_ag_answer_incoming_call(void);
175 
176 /**
177  * @brief Join held call with active call.
178  */
179 void hfp_ag_join_held_call(void);
180 
181 /**
182  * @brief Reject incoming call, if exists, or terminate active call.
183  */
184 void hfp_ag_terminate_call(void);
185 
186 /*
187  * @brief Put incoming call on hold.
188  */
189 void hfp_ag_hold_incoming_call(void);
190 
191 /*
192  * @brief Accept the held incoming call.
193  */
194 void hfp_ag_accept_held_incoming_call(void);
195 
196 /*
197  * @brief Reject the held incoming call.
198  */
199 void hfp_ag_reject_held_incoming_call(void);
200 
201 /*
202  * @brief Set microphone gain.
203  * @param bd_addr Bluetooth address of the HF
204  * @param gain Valid range: [0,15]
205  */
206 void hfp_ag_set_microphone_gain(hci_con_handle_t acl_handle, int gain);
207 
208 /*
209  * @brief Set speaker gain.
210  * @param bd_addr Bluetooth address of the HF
211  * @param gain Valid range: [0,15]
212  */
213 void hfp_ag_set_speaker_gain(hci_con_handle_t acl_handle, int gain);
214 
215 /*
216  * @brief Set battery level.
217  * @param level Valid range: [0,5]
218  */
219 void hfp_ag_set_battery_level(int level);
220 
221 /*
222  * @brief Clear last dialed number.
223  */
224 void hfp_ag_clear_last_dialed_number(void);
225 
226 /*
227  * @brief Set last dialed number.
228  */
229 void hfp_ag_set_last_dialed_number(const char * number);
230 
231 /*
232  * @brief Notify the HF that an incoming call is waiting
233  * during an ongoing call. The notification will be sent only if the HF has
234  * has previously enabled the "Call Waiting notification" in the AG.
235  * @param bd_addr Bluetooth address of the HF
236  */
237 void hfp_ag_notify_incoming_call_waiting(hci_con_handle_t acl_handle);
238 
239 // Voice Recognition
240 
241 /*
242  * @brief Activate voice recognition.
243  * @param bd_addr Bluetooth address of the HF
244  * @param activate
245  */
246 void hfp_ag_activate_voice_recognition(hci_con_handle_t acl_handle, int activate);
247 
248 void hfp_ag_enhanced_voice_recognition_activate(hci_con_handle_t acl_handle);
249 
250 void hfp_ag_enhanced_voice_recognition_status(hci_con_handle_t acl_handle, hfp_voice_recognition_state_t state);
251 void hfp_ag_enhanced_voice_recognition_starting_sound(hci_con_handle_t acl_handle);
252 void hfp_ag_enhanced_voice_recognition_ready_for_input(hci_con_handle_t acl_handle);
253 void hfp_ag_enhanced_voice_recognition_processing_input(hci_con_handle_t acl_handle);
254 
255 void hfp_ag_enhanced_voice_recognition_message(hci_con_handle_t acl_handle, hfp_voice_recognition_state_t state, hfp_voice_recognition_message_t msg);
256 void hfp_ag_enhanced_voice_recognition_deactivate(hci_con_handle_t acl_handle);
257 
258 /*
259  * @brief Send a phone number back to the HF.
260  * @param bd_addr Bluetooth address of the HF
261  * @param phone_number
262  */
263 void hfp_ag_send_phone_number_for_voice_tag(hci_con_handle_t acl_handle, const char * phone_number);
264 
265 /*
266  * @brief Reject sending a phone number to the HF.
267  * @param bd_addr Bluetooth address of the HF
268  */
269 void hfp_ag_reject_phone_number_for_voice_tag(hci_con_handle_t acl_handle);
270 
271 /**
272  * @brief Store phone number with initiated call.
273  * @param type
274  * @param number
275  */
276 void hfp_ag_set_clip(uint8_t type, const char * number);
277 
278 
279 // Cellular Actions
280 
281 /**
282  * @brief Pass the accept incoming call event to the AG.
283  */
284 void hfp_ag_incoming_call(void);
285 
286 /**
287  * @brief Outgoing call initiated
288  */
289 void hfp_ag_outgoing_call_initiated(const char * number);
290 
291 /**
292  * @brief Pass the reject outgoing call event to the AG.
293  */
294 void hfp_ag_outgoing_call_rejected(void);
295 
296 /**
297  * @brief Pass the accept outgoing call event to the AG.
298  */
299 void hfp_ag_outgoing_call_accepted(void);
300 
301 /**
302  * @brief Pass the outgoing call ringing event to the AG.
303  */
304 void hfp_ag_outgoing_call_ringing(void);
305 
306 /**
307  * @brief Pass the outgoing call established event to the AG.
308  */
309 void hfp_ag_outgoing_call_established(void);
310 
311 /**
312  * @brief Pass the call droped event to the AG.
313  */
314 void hfp_ag_call_dropped(void);
315 
316 /*
317  * @brief Set network registration status.
318  * @param status 0 - not registered, 1 - registered
319  */
320 void hfp_ag_set_registration_status(int status);
321 
322 /*
323  * @brief Set network signal strength.
324  * @param strength [0-5]
325  */
326 void hfp_ag_set_signal_strength(int strength);
327 
328 /*
329  * @brief Set roaming status.
330  * @param status 0 - no roaming, 1 - roaming active
331  */
332 void hfp_ag_set_roaming_status(int status);
333 
334 /*
335  * @brief Set subcriber number information, e.g. the phone number
336  * @param numbers
337  * @param numbers_count
338  */
339 void hfp_ag_set_subcriber_number_information(hfp_phone_number_t * numbers, int numbers_count);
340 
341 /*
342  * @brief Called by cellular unit after a DTMF code was transmitted, so that the next one can be emitted.
343  * @param bd_addr Bluetooth address of the HF
344  */
345 void hfp_ag_send_dtmf_code_done(hci_con_handle_t acl_handle);
346 
347 /**
348  * @brief Report Extended Audio Gateway Error result codes in the AG.
349  * Whenever there is an error relating to the functionality of the AG as a
350  * result of AT command, the AG shall send +CME ERROR:
351  * - +CME ERROR: 0  - AG failure
352  * - +CME ERROR: 1  - no connection to phone
353  * - +CME ERROR: 3  - operation not allowed
354  * - +CME ERROR: 4  - operation not supported
355  * - +CME ERROR: 5  - PH-SIM PIN required
356  * - +CME ERROR: 10 - SIM not inserted
357  * - +CME ERROR: 11 - SIM PIN required
358  * - +CME ERROR: 12 - SIM PUK required
359  * - +CME ERROR: 13 - SIM failure
360  * - +CME ERROR: 14 - SIM busy
361  * - +CME ERROR: 16 - incorrect password
362  * - +CME ERROR: 17 - SIM PIN2 required
363  * - +CME ERROR: 18 - SIM PUK2 required
364  * - +CME ERROR: 20 - memory full
365  * - +CME ERROR: 21 - invalid index
366  * - +CME ERROR: 23 - memory failure
367  * - +CME ERROR: 24 - text string too long
368  * - +CME ERROR: 25 - invalid characters in text string
369  * - +CME ERROR: 26 - dial string too long
370  * - +CME ERROR: 27 - invalid characters in dial string
371  * - +CME ERROR: 30 - no network service
372  * - +CME ERROR: 31 - network Timeout.
373  * - +CME ERROR: 32 - network not allowed – Emergency calls only
374  *
375  * @param bd_addr Bluetooth address of the HF
376  * @param error
377  */
378 void hfp_ag_report_extended_audio_gateway_error_result_code(hci_con_handle_t acl_handle, hfp_cme_error_t error);
379 
380 /**
381  * @brief De-Init HFP AG
382  */
383 void hfp_ag_deinit(void);
384 
385 /* API_END */
386 
387 // testing
388 hfp_ag_indicator_t * hfp_ag_get_ag_indicators(hfp_connection_t * hfp_connection);
389 
390 #if defined __cplusplus
391 }
392 #endif
393 
394 #endif
395