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