1 // Copyright 2018 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef __ESP_HF_DEFS_H__
16 #define __ESP_HF_DEFS_H__
17 
18 #include "esp_bt_defs.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #define ESP_BT_HF_NUMBER_LEN           (32)
25 #define ESP_BT_HF_OPERATOR_NAME_LEN    (16)
26 
27 #ifndef BTC_HSAG_SERVICE_NAME
28 #define BTC_HSAG_SERVICE_NAME ("Headset Gateway")
29 #endif
30 
31 #ifndef BTC_HFAG_SERVICE_NAME
32 #define BTC_HFAG_SERVICE_NAME ("Handsfree Gateway")
33 #endif
34 
35 #ifndef BTC_HF_SERVICES
36 #define BTC_HF_SERVICES    (BTA_HSP_SERVICE_MASK | BTA_HFP_SERVICE_MASK )
37 #endif
38 
39 #ifndef BTC_HF_SERVICE_NAMES
40 #define BTC_HF_SERVICE_NAMES {BTC_HSAG_SERVICE_NAME , BTC_HFAG_SERVICE_NAME}
41 #endif
42 
43 #ifndef BTC_HF_SECURITY
44 #define BTC_HF_SECURITY    (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)
45 #endif
46 
47 #define BTC_HF_CALL_END_TIMEOUT       6
48 
49 #define BTC_HF_INVALID_IDX       -1
50 
51 /// in-band ring tone state
52 typedef enum {
53     ESP_HF_IN_BAND_RINGTONE_NOT_PROVIDED = 0,
54     ESP_HF_IN_BAND_RINGTONE_PROVIDED,
55 } esp_hf_in_band_ring_state_t;
56 
57 /// voice recognition state
58 typedef enum {
59     ESP_HF_VR_STATE_DISABLED = 0,           /*!< voice recognition disabled */
60     ESP_HF_VR_STATE_ENABLED,                /*!< voice recognition enabled */
61 } esp_hf_vr_state_t;
62 
63 /// Bluetooth HFP audio volume control target
64 typedef enum {
65     ESP_HF_VOLUME_CONTROL_TARGET_SPK = 0,             /*!< speaker */
66     ESP_HF_VOLUME_CONTROL_TARGET_MIC,                 /*!< microphone */
67 } esp_hf_volume_control_target_t;
68 
69 /// Bluetooth HFP audio connection status
70 typedef enum {
71     ESP_HF_AUDIO_STATE_DISCONNECTED = 0,          /*!< audio connection released */
72     ESP_HF_AUDIO_STATE_CONNECTING,                /*!< audio connection has been initiated */
73     ESP_HF_AUDIO_STATE_CONNECTED,                 /*!< audio connection is established */
74     ESP_HF_AUDIO_STATE_CONNECTED_MSBC,            /*!< mSBC audio connection is established */
75 } esp_hf_audio_state_t;
76 
77 typedef enum {
78     ESP_HF_VOLUME_TYPE_SPK = 0,
79     ESP_HF_VOLUME_TYPE_MIC
80 } esp_hf_volume_type_t;
81 
82 /// +CIND network service availability status
83 typedef enum
84 {
85     ESP_HF_NETWORK_STATE_NOT_AVAILABLE = 0,
86     ESP_HF_NETWORK_STATE_AVAILABLE
87 } esp_hf_network_state_t;
88 
89 /** +CIEV Service type */
90 typedef enum
91 {
92     ESP_HF_SERVICE_TYPE_HOME = 0,
93     ESP_HF_SERVICE_TYPE_ROAMING
94 } esp_hf_service_type_t;
95 
96 /// +CIND call status indicator values
97 typedef enum {
98     ESP_HF_CALL_STATUS_NO_CALLS = 0,                  /*!< no call in progress  */
99     ESP_HF_CALL_STATUS_CALL_IN_PROGRESS = 1,          /*!< call is present(active or held) */
100 } esp_hf_call_status_t;
101 
102 /// +CIND call setup status indicator values
103 typedef enum {
104     ESP_HF_CALL_SETUP_STATUS_IDLE = 0,                /*!< no call setup in progress */
105     ESP_HF_CALL_SETUP_STATUS_INCOMING = 1,            /*!< incoming call setup in progress */
106     ESP_HF_CALL_SETUP_STATUS_OUTGOING_DIALING = 2,    /*!< outgoing call setup in dialing state */
107     ESP_HF_CALL_SETUP_STATUS_OUTGOING_ALERTING = 3,   /*!< outgoing call setup in alerting state */
108 } esp_hf_call_setup_status_t;
109 
110 /// +CIND roaming status indicator values
111 typedef enum {
112     ESP_HF_ROAMING_STATUS_INACTIVE = 0,               /*!< roaming is not active */
113     ESP_HF_ROAMING_STATUS_ACTIVE,                     /*!< a roaming is active */
114 } esp_hf_roaming_status_t;
115 
116 /// +CIND call held indicator values
117 typedef enum {
118     ESP_HF_CALL_HELD_STATUS_NONE = 0,                 /*!< no calls held */
119     ESP_HF_CALL_HELD_STATUS_HELD_AND_ACTIVE = 1,      /*!< both active and held call */
120     ESP_HF_CALL_HELD_STATUS_HELD = 2,                 /*!< call on hold, no active call*/
121 } esp_hf_call_held_status_t;
122 
123 /// +CLCC status of the call
124 typedef enum {
125     ESP_HF_CURRENT_CALL_STATUS_ACTIVE = 0,            /*!< active */
126     ESP_HF_CURRENT_CALL_STATUS_HELD = 1,              /*!< held */
127     ESP_HF_CURRENT_CALL_STATUS_DIALING = 2,           /*!< dialing (outgoing calls only) */
128     ESP_HF_CURRENT_CALL_STATUS_ALERTING = 3,          /*!< alerting (outgoing calls only) */
129     ESP_HF_CURRENT_CALL_STATUS_INCOMING = 4,          /*!< incoming (incoming calls only) */
130     ESP_HF_CURRENT_CALL_STATUS_WAITING = 5,           /*!< waiting (incoming calls only) */
131     ESP_HF_CURRENT_CALL_STATUS_HELD_BY_RESP_HOLD = 6, /*!< call held by response and hold */
132 } esp_hf_current_call_status_t;
133 
134 /// +CLCC direction of the call
135 typedef enum {
136     ESP_HF_CURRENT_CALL_DIRECTION_OUTGOING = 0,       /*!< outgoing */
137     ESP_HF_CURRENT_CALL_DIRECTION_INCOMING = 1,       /*!< incoming */
138 } esp_hf_current_call_direction_t;
139 
140 /// +CLCC multi-party call flag
141 typedef enum {
142     ESP_HF_CURRENT_CALL_MPTY_TYPE_SINGLE = 0,         /*!< not a member of a multi-party call */
143     ESP_HF_CURRENT_CALL_MPTY_TYPE_MULTI = 1,          /*!< member of a multi-party call */
144 } esp_hf_current_call_mpty_type_t;
145 
146 /// +CLCC call mode
147 typedef enum {
148     ESP_HF_CURRENT_CALL_MODE_VOICE = 0,
149     ESP_HF_CURRENT_CALL_MODE_DATA = 1,
150     ESP_HF_CURRENT_CALL_MODE_FAX = 2,
151 } esp_hf_current_call_mode_t;
152 
153 /// +CLCC address type
154 typedef enum {
155     ESP_HF_CALL_ADDR_TYPE_UNKNOWN = 0x81,            /*!< unkown address type */
156     ESP_HF_CALL_ADDR_TYPE_INTERNATIONAL = 0x91,      /*!< international address */
157 } esp_hf_call_addr_type_t;
158 
159 /// +CNUM service type of the phone number
160 typedef enum {
161     ESP_HF_SUBSCRIBER_SERVICE_TYPE_UNKNOWN = 0,      /*!< unknown */
162     ESP_HF_SUBSCRIBER_SERVICE_TYPE_VOICE,            /*!< voice service */
163     ESP_HF_SUBSCRIBER_SERVICE_TYPE_FAX,              /*!< fax service */
164 } esp_hf_subscriber_service_type_t;
165 
166 /// +BTRH response and hold result code
167 typedef enum {
168     ESP_HF_BTRH_STATUS_HELD = 0,       /*!< incoming call is put on held in AG */
169     ESP_HF_BTRH_STATUS_ACCEPTED,       /*!< held incoming call is accepted in AG */
170     ESP_HF_BTRH_STATUS_REJECTED,       /*!< held incoming call is rejected in AG */
171 } esp_hf_btrh_status_t;
172 
173 /// AT+BTRH response and hold action code
174 typedef enum {
175     ESP_HF_BTRH_CMD_HOLD = 0,          /*!< put the incoming call on hold */
176     ESP_HF_BTRH_CMD_ACCEPT = 1,        /*!< accept a held incoming call */
177     ESP_HF_BTRH_CMD_REJECT = 2,        /*!< reject a held incoming call */
178 } esp_hf_btrh_cmd_t;
179 
180 /* +NREC */
181 typedef enum
182 {
183     ESP_HF_NREC_STOP = 0,
184     ESP_HF_NREC_START
185 } esp_hf_nrec_t;
186 
187 ///+CCWA resposne status
188 typedef enum {
189     ESP_HF_CALL_WAITING_INACTIVE,
190     ESP_HF_CALL_WAITING_ACTIVE,
191 } esp_hf_call_waiting_status_t;
192 
193 /* WBS codec setting */
194 typedef enum
195 {
196    ESP_HF_WBS_NONE,
197    ESP_HF_WBS_NO,
198    ESP_HF_WBS_YES
199 }esp_hf_wbs_config_t;
200 
201 /// Bluetooth HFP RFCOMM connection and service level connection status
202 typedef enum {
203     ESP_HF_CONNECTION_STATE_DISCONNECTED = 0,     /*!< RFCOMM data link channel released */
204     ESP_HF_CONNECTION_STATE_CONNECTING,           /*!< connecting remote device on the RFCOMM data link*/
205     ESP_HF_CONNECTION_STATE_CONNECTED,            /*!< RFCOMM connection established */
206     ESP_HF_CONNECTION_STATE_SLC_CONNECTED,        /*!< service level connection established */
207     ESP_HF_CONNECTION_STATE_DISCONNECTING,        /*!< disconnecting with remote device on the RFCOMM data link*/
208 } esp_hf_connection_state_t;
209 
210 /// AT+CHLD command values
211 typedef enum {
212     ESP_HF_CHLD_TYPE_REL = 0,               /*!< <0>, Terminate all held or set UDUB("busy") to a waiting call */
213     ESP_HF_CHLD_TYPE_REL_ACC,               /*!< <1>, Terminate all active calls and accepts a waiting/held call */
214     ESP_HF_CHLD_TYPE_HOLD_ACC,              /*!< <2>, Hold all active calls and accepts a waiting/held call */
215     ESP_HF_CHLD_TYPE_MERGE,                 /*!< <3>, Add all held calls to a conference */
216     ESP_HF_CHLD_TYPE_MERGE_DETACH,          /*!< <4>, connect the two calls and disconnects the subscriber from both calls */
217     ESP_HF_CHLD_TYPE_REL_X,                 /*!< <1x>, releases specified calls only */
218     ESP_HF_CHLD_TYPE_PRIV_X,                /*!< <2x>, request private consultation mode with specified call */
219 } esp_hf_chld_type_t;
220 
221 /* AT response code - OK/Error */
222 typedef enum {
223     ESP_HF_AT_RESPONSE_CODE_OK = 0,         /*!< acknowledges execution of a command line */
224     ESP_HF_AT_RESPONSE_CODE_ERR,            /*!< command not accepted */
225     ESP_HF_AT_RESPONSE_CODE_NO_CARRIER,     /*!< connection terminated */
226     ESP_HF_AT_RESPONSE_CODE_BUSY,           /*!< busy signal detected */
227     ESP_HF_AT_RESPONSE_CODE_NO_ANSWER,      /*!< connection completion timeout */
228     ESP_HF_AT_RESPONSE_CODE_DELAYED,        /*!< delayed */
229     ESP_HF_AT_RESPONSE_CODE_BLACKLISTED,    /*!< blacklisted */
230     ESP_HF_AT_RESPONSE_CODE_CME,            /*!< CME error */
231 } esp_hf_at_response_code_t;
232 
233 /* AT response code - OK/Error */
234 typedef enum {
235     ESP_HF_AT_RESPONSE_ERROR = 0,
236     ESP_HF_AT_RESPONSE_OK
237 } esp_hf_at_response_t;
238 
239 /// Extended Audio Gateway Error Result Code Response
240 typedef enum {
241     ESP_HF_CME_AG_FAILURE = 0,                    /*!< ag failure */
242     ESP_HF_CME_NO_CONNECTION_TO_PHONE = 1,        /*!< no connection to phone */
243     ESP_HF_CME_OPERATION_NOT_ALLOWED = 3,         /*!< operation not allowed */
244     ESP_HF_CME_OPERATION_NOT_SUPPORTED = 4,       /*!< operation not supported */
245     ESP_HF_CME_PH_SIM_PIN_REQUIRED = 5,           /*!< PH-SIM PIN Required */
246     ESP_HF_CME_SIM_NOT_INSERTED = 10,             /*!< SIM not inserted */
247     ESP_HF_CME_SIM_PIN_REQUIRED = 11,             /*!< SIM PIN required */
248     ESP_HF_CME_SIM_PUK_REQUIRED = 12,             /*!< SIM PUK required */
249     ESP_HF_CME_SIM_FAILURE = 13,                  /*!< SIM failure */
250     ESP_HF_CME_SIM_BUSY = 14,                     /*!< SIM busy */
251     ESP_HF_CME_INCORRECT_PASSWORD = 16,           /*!< incorrect password */
252     ESP_HF_CME_SIM_PIN2_REQUIRED = 17,            /*!< SIM PIN2 required */
253     ESP_HF_CME_SIM_PUK2_REQUIRED = 18,            /*!< SIM PUK2 required */
254     ESP_HF_CME_MEMEORY_FULL = 20,                 /*!< memory full */
255     ESP_HF_CME_INVALID_INDEX = 21,                /*!< invalid index */
256     ESP_HF_CME_MEMEORY_FAILURE = 23,              /*!< memory failure */
257     ESP_HF_CME_TEXT_STRING_TOO_LONG = 24,         /*!< test string too long */
258     ESP_HF_CME_INVALID_CHARACTERS_IN_TEXT_STRING = 25,  /*!< invalid characters in text string */
259     ESP_HF_CME_DIAL_STRING_TOO_LONG = 26,         /*!< dial string too long*/
260     ESP_HF_CME_INVALID_CHARACTERS_IN_DIAL_STRING = 27,  /*!< invalid characters in dial string */
261     ESP_HF_CME_NO_NETWORK_SERVICE = 30,           /*!< no network service */
262     ESP_HF_CME_NETWORK_TIMEOUT = 31,              /*!< network timeout */
263     ESP_HF_CME_NETWORK_NOT_ALLOWED = 32,          /*!< network not allowed --emergency calls only */
264 } esp_hf_cme_err_t;
265 
266 /** Callback for connection state change.
267  *  state will have one of the values from BtHfConnectionState
268  */
269 typedef void (* esp_hf_connection_state_callback)(esp_hf_connection_state_t state, esp_bd_addr_t *bd_addr);
270 
271 /** Callback for audio connection state change.
272  *  state will have one of the values from BtHfAudioState
273  */
274 typedef void (* esp_hf_audio_state_callback)(esp_hf_audio_state_t state, esp_bd_addr_t *bd_addr);
275 
276 /** Callback for VR connection state change.
277  *  state will have one of the values from BtHfVRState
278  */
279 typedef void (* esp_hf_vr_cmd_callback)(esp_hf_vr_state_t state, esp_bd_addr_t *bd_addr);
280 
281 /** Callback for answer incoming call (ATA)
282  */
283 typedef void (* esp_hf_answer_call_cmd_callback)(esp_bd_addr_t *bd_addr);
284 
285 /** Callback for disconnect call (AT+CHUP)
286  */
287 typedef void (* esp_hf_hangup_call_cmd_callback)(esp_bd_addr_t *bd_addr);
288 
289 /** Callback for disconnect call (AT+CHUP)
290  *  type will denote Speaker/Mic gain (BtHfVolumeControl).
291  */
292 typedef void (* esp_hf_volume_cmd_callback)(esp_hf_volume_control_target_t type, int volume, esp_bd_addr_t *bd_addr);
293 
294 /** Callback for dialing an outgoing call
295  *  If number is NULL, redial
296  */
297 typedef void (* esp_hf_dial_call_cmd_callback)(char *number, esp_bd_addr_t *bd_addr);
298 
299 /** Callback for sending DTMF tones
300  *  tone contains the dtmf character to be sent
301  */
302 typedef void (* esp_hf_dtmf_cmd_callback)(char tone, esp_bd_addr_t *bd_addr);
303 
304 /** Callback for enabling/disabling noise reduction/echo cancellation
305  *  value will be 1 to enable, 0 to disable
306  */
307 typedef void (* esp_hf_nrec_cmd_callback)(esp_hf_nrec_t nrec, esp_bd_addr_t *bd_addr);
308 
309 /** Callback for AT+BCS and event from BAC
310  *  WBS enable, WBS disable
311  */
312 typedef void (* esp_hf_wbs_callback)(esp_hf_wbs_config_t wbs, esp_bd_addr_t *bd_addr);
313 
314 /** Callback for call hold handling (AT+CHLD)
315  *  value will contain the call hold command (0, 1, 2, 3)
316  */
317 typedef void (* esp_hf_chld_cmd_callback)(esp_hf_chld_type_t chld, esp_bd_addr_t *bd_addr);
318 
319 /** Callback for CNUM (subscriber number)
320  */
321 typedef void (* esp_hf_cnum_cmd_callback)(esp_bd_addr_t *bd_addr);
322 
323 /** Callback for indicators (CIND)
324  */
325 typedef void (* esp_hf_cind_cmd_callback)(esp_bd_addr_t *bd_addr);
326 
327 /** Callback for operator selection (COPS)
328  */
329 typedef void (* esp_hf_cops_cmd_callback)(esp_bd_addr_t *bd_addr);
330 
331 /** Callback for call list (AT+CLCC)
332  */
333 typedef void (* esp_hf_clcc_cmd_callback) (esp_bd_addr_t *bd_addr);
334 
335 /** Callback for unknown AT command recd from AG
336  *  at_string will contain the unparsed AT string
337  */
338 typedef void (* esp_hf_unknown_at_cmd_callback)(char *at_string, esp_bd_addr_t *bd_addr);
339 
340 /** Callback for keypressed (HSP) event.
341  */
342 typedef void (* esp_hf_key_pressed_cmd_callback)(esp_bd_addr_t *bd_addr);
343 
344 #ifdef __cplusplus
345 }
346 #endif
347 
348 #endif /* __ESP_HF_DEFS_H__ */
349