xref: /btstack/src/classic/hfp_ag.h (revision 8257e5f9e1a9f15ac2fe1e69adc5d2eeeadf3fff)
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_query_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  */
66 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);;
67 
68 /**
69  * @brief Intialize HFP Audio Gateway (AG) device.
70  * TODO:  move optional params into setters
71  */
72 void hfp_ag_init(uint16_t rfcomm_channel_nr, uint32_t supported_features,
73     uint8_t * codecs, int codecs_nr,
74     hfp_ag_indicator_t * ag_indicators, int ag_indicators_nr,
75     hfp_generic_status_indicator_t * hf_indicators, int hf_indicators_nr,
76     const char *call_hold_services[], int call_hold_services_nr);
77 
78 /**
79  * @brief Register callback for the HFP Audio Gateway (AG) client.
80  */
81 void hfp_ag_register_packet_handler(hfp_callback_t callback);
82 
83 /**
84  * @brief Enable in-band ring tone
85  */
86 void hfp_ag_set_use_in_band_ring_tone(int use_in_band_ring_tone);
87 
88 
89 // actions used by local device / user
90 
91 /**
92  * @brief Establish RFCOMM connection, and perform service level connection agreement:
93  * - exchange of supported features
94  * - report Audio Gateway (AG) indicators and their status
95  * - enable indicator status update in the AG
96  * - accept the information about available codecs in the Hands-Free (HF), if sent
97  * - report own information describing the call hold and multiparty services, if possible
98  * - report which HF indicators are enabled on the AG, if possible
99  */
100 void hfp_ag_establish_service_level_connection(bd_addr_t bd_addr);
101 
102 /**
103  * @brief Release the RFCOMM channel and the audio connection between the HF and the AG.
104  * TODO: trigger release of the audio connection ??
105  */
106 void hfp_ag_release_service_level_connection(bd_addr_t bd_addr);
107 
108 /**
109  * @brief
110  */
111 void hfp_ag_establish_audio_connection(bd_addr_t bd_addr);
112 
113 /**
114  * @brief
115  */
116 void hfp_ag_release_audio_connection(bd_addr_t bd_addr);
117 
118 /**
119  * @brief
120  */
121 void hfp_ag_answer_incoming_call(void);
122 
123 /**
124  * @brief
125  */
126 void hfp_ag_join_held_call(void);
127 
128 /**
129  * @brief
130  */
131 void hfp_ag_terminate_call(void);
132 
133 /*
134  * @brief
135  */
136 void hfp_ag_hold_incoming_call(void);
137 
138 /*
139  * @brief
140  */
141 void hfp_ag_accept_held_incoming_call(void);
142 
143 /*
144  * @brief
145  */
146 void hfp_ag_reject_held_incoming_call(void);
147 
148 /*
149  * @brief
150  */
151 void hfp_ag_set_microphone_gain(bd_addr_t bd_addr, int gain);
152 
153 /*
154  * @brief
155  */
156 void hfp_ag_set_speaker_gain(bd_addr_t bd_addr, int gain);
157 
158 /*
159  * @brief
160  */
161 void hfp_ag_set_battery_level(int level);
162 
163 /*
164  * @brief
165  */
166 void hfp_ag_clear_last_dialed_number(void);
167 
168 
169 // Voice Recognition
170 
171 /*
172  * @brief
173  */
174 void hfp_ag_activate_voice_recognition(bd_addr_t bd_addr, int activate);
175 
176 /*
177  * @brief
178  */
179 void hfp_ag_send_phone_number_for_voice_tag(bd_addr_t bd_addr, const char * number);
180 
181 /*
182  * @brief
183  */
184 void hfp_ag_reject_phone_number_for_voice_tag(bd_addr_t bd_addr);
185 
186 
187 // Cellular Actions
188 
189 /**
190  * @brief
191  */
192 void hfp_ag_incoming_call(void);
193 
194 /**
195  * @brief number is stored.
196  */
197 void hfp_ag_set_clip(uint8_t type, const char * number);
198 
199 /**
200  * @brief
201  */
202 void hfp_ag_outgoing_call_rejected(void);
203 
204 /**
205  * @brief
206  */
207 void hfp_ag_outgoing_call_accepted(void);
208 
209 /**
210  * @brief
211  */
212 void hfp_ag_outgoing_call_ringing(void);
213 
214 /**
215  * @brief
216  */
217 void hfp_ag_outgoing_call_established(void);
218 
219 /**
220  * @brief
221  */
222 void hfp_ag_call_dropped(void);
223 /*
224  * @brief
225  */
226 void hfp_ag_set_registration_status(int status);
227 
228 /*
229  * @brief
230  */
231 void hfp_ag_set_signal_strength(int strength);
232 
233 /*
234  * @brief
235  */
236 void hfp_ag_set_roaming_status(int status);
237 
238 /*
239  * @brief
240  */
241 void hfp_ag_set_subcriber_number_information(hfp_phone_number_t * numbers, int numbers_count);
242 
243 /*
244  * @brief Called by cellular unit after a DTMF code was transmitted, so that the next one can be emitted
245  */
246 void hfp_ag_send_dtmf_code_done(bd_addr_t bd_addr);
247 
248 /**
249  * @brief Report Extended Audio Gateway Error result codes in the AG.
250  * Whenever there is an error relating to the functionality of the AG as a
251  * result of AT command, the AG shall send +CME ERROR:
252  * - +CME ERROR: 0  - AG failure
253  * - +CME ERROR: 1  - no connection to phone
254  * - +CME ERROR: 3  - operation not allowed
255  * - +CME ERROR: 4  - operation not supported
256  * - +CME ERROR: 5  - PH-SIM PIN required
257  * - +CME ERROR: 10 - SIM not inserted
258  * - +CME ERROR: 11 - SIM PIN required
259  * - +CME ERROR: 12 - SIM PUK required
260  * - +CME ERROR: 13 - SIM failure
261  * - +CME ERROR: 14 - SIM busy
262  * - +CME ERROR: 16 - incorrect password
263  * - +CME ERROR: 17 - SIM PIN2 required
264  * - +CME ERROR: 18 - SIM PUK2 required
265  * - +CME ERROR: 20 - memory full
266  * - +CME ERROR: 21 - invalid index
267  * - +CME ERROR: 23 - memory failure
268  * - +CME ERROR: 24 - text string too long
269  * - +CME ERROR: 25 - invalid characters in text string
270  * - +CME ERROR: 26 - dial string too long
271  * - +CME ERROR: 27 - invalid characters in dial string
272  * - +CME ERROR: 30 - no network service
273  * - +CME ERROR: 31 - network Timeout.
274  * - +CME ERROR: 32 - network not allowed – Emergency calls only
275  */
276 void hfp_ag_report_extended_audio_gateway_error_result_code(bd_addr_t bd_addr, hfp_cme_error_t error);
277 
278 /* API_END */
279 
280 
281 #if defined __cplusplus
282 }
283 #endif
284 
285 #endif