1 /******************************************************************************
2  *
3  *  Copyright 2003-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This is the public interface file for the audio gateway (AG) subsystem
22  *  of BTA, Broadcom's Bluetooth application layer for mobile phones.
23  *
24  ******************************************************************************/
25 #ifndef BTA_AG_API_H
26 #define BTA_AG_API_H
27 
28 #include <bluetooth/log.h>
29 
30 #include <string>
31 #include <vector>
32 
33 #include "bta/include/bta_api.h"
34 #include "bta_api.h"
35 #include "internal_include/bt_target.h"
36 #include "macros.h"
37 #include "types/raw_address.h"
38 
39 /*****************************************************************************
40  *  Constants and data types
41  ****************************************************************************/
42 /* Number of SCBs (AG service instances that can be registered) */
43 #define BTA_AG_MAX_NUM_CLIENTS 6
44 
45 /* AG feature masks */
46 #define BTA_AG_FEAT_3WAY 0x00000001   /* Three-way calling */
47 #define BTA_AG_FEAT_ECNR 0x00000002   /* Echo cancellation/noise reduction */
48 #define BTA_AG_FEAT_VREC 0x00000004   /* Voice recognition */
49 #define BTA_AG_FEAT_INBAND 0x00000008 /* In-band ring tone */
50 #define BTA_AG_FEAT_VTAG 0x00000010   /* Attach a phone number to a voice tag */
51 #define BTA_AG_FEAT_REJECT 0x00000020 /* Ability to reject incoming call */
52 #define BTA_AG_FEAT_ECS 0x00000040    /* Enhanced Call Status */
53 #define BTA_AG_FEAT_ECC 0x00000080    /* Enhanced Call Control */
54 #define BTA_AG_FEAT_EXTERR 0x00000100 /* Extended error codes */
55 #define BTA_AG_FEAT_CODEC 0x00000200  /* Codec Negotiation */
56 #define BTA_AG_FEAT_SWB 0x00001000    /* Super Wide Band */
57 
58 /* AG SDP feature masks */
59 #define BTA_AG_FEAT_WBS_SUPPORT 0x0020 /* Supports WBS */
60 #define BTA_AG_FEAT_SWB_SUPPORT 0x0100 /* Supports SWB */
61 
62 /* Only SDP feature bits 0 to 4 matches BRSF feature bits */
63 #define HFP_SDP_BRSF_FEATURES_MASK 0x001F
64 
65 /* Valid feature bit mask for HFP 1.6 (and below) */
66 #define HFP_1_6_FEAT_MASK 0x000003FF
67 
68 /* HFP 1.7+ */
69 #define BTA_AG_FEAT_HF_IND 0x00000400  /* HF Indicators */
70 #define BTA_AG_FEAT_ESCO_S4 0x00000800 /* eSCO S4 setting supported */
71 
72 /* Proprietary features: using 31 ~ 16 bits */
73 #define BTA_AG_FEAT_BTRH 0x00010000    /* CCAP incoming call hold */
74 #define BTA_AG_FEAT_UNAT 0x00020000    /* Pass unknown AT commands to app */
75 #define BTA_AG_FEAT_NOSCO 0x00040000   /* No SCO control performed by BTA AG */
76 #define BTA_AG_FEAT_NO_ESCO 0x00080000 /* Do not allow or use eSCO */
77 #define BTA_AG_FEAT_VOIP 0x00100000    /* VoIP call */
78 
79 typedef uint32_t tBTA_AG_FEAT;
80 
81 /* AG open status */
82 #define BTA_AG_SUCCESS 0        /* Connection successfully opened */
83 #define BTA_AG_FAIL_SDP 1       /* Open failed due to SDP */
84 #define BTA_AG_FAIL_RFCOMM 2    /* Open failed due to RFCOMM */
85 #define BTA_AG_FAIL_RESOURCES 3 /* out of resources failure */
86 
87 /* Status to disallow passing AT Events after BTIF */
88 #define BTA_AG_DISALLOW_AT 5
89 
90 typedef uint8_t tBTA_AG_STATUS;
91 
92 /* handle values used with BTA_AgResult */
93 #define BTA_AG_HANDLE_NONE 0
94 #define BTA_AG_HANDLE_ALL 0xFFFF
95 /* It is safe to use the same value as BTA_AG_HANDLE_ALL
96  * HANDLE_ALL is used for delivering indication
97  * SCO_NO_CHANGE is used for changing sco behavior
98  * They donot interfere with each other
99  */
100 
101 /* Number of supported HF indicators, there is one HF indicator so far i.e.
102                                                    enhanced driver status. */
103 /* Number of supported HF indicators,
104    1 for Enhanced Safety Status
105    2 for Battery Level Status */
106 #ifndef BTA_AG_NUM_LOCAL_HF_IND
107 #define BTA_AG_NUM_LOCAL_HF_IND 2
108 #endif
109 
110 #define BTA_AG_HANDLE_SCO_NO_CHANGE 0xFFFF
111 
112 typedef enum : uint8_t {
113   /* AG result codes used with BTA_AgResult */
114   BTA_AG_SPK_RES = 0,            /* Update speaker volume */
115   BTA_AG_MIC_RES = 1,            /* Update microphone volume */
116   BTA_AG_INBAND_RING_RES = 2,    /* Update inband ring state */
117   BTA_AG_CIND_RES = 3,           /* Send indicator response for AT+CIND */
118   BTA_AG_BINP_RES = 4,           /* Send phone number for voice tag for AT+BINP */
119   BTA_AG_IND_RES = 5,            /* Update an indicator value */
120   BTA_AG_BVRA_RES = 6,           /* Update voice recognition state */
121   BTA_AG_CNUM_RES = 7,           /* Send subscriber number response for AT+CNUM */
122   BTA_AG_BTRH_RES = 8,           /* Send CCAP incoming call hold */
123   BTA_AG_CLCC_RES = 9,           /* Query list of calls */
124   BTA_AG_COPS_RES = 10,          /* Read network operator */
125   BTA_AG_IN_CALL_RES = 11,       /* Indicate incoming phone call */
126   BTA_AG_IN_CALL_CONN_RES = 12,  /* Incoming phone call connected */
127   BTA_AG_CALL_WAIT_RES = 13,     /* Call waiting notification */
128   BTA_AG_OUT_CALL_ORIG_RES = 14, /* Outgoing phone call origination */
129 
130   /* Outgoing phone call alerting remote party */
131   BTA_AG_OUT_CALL_ALERT_RES = 15,
132   BTA_AG_OUT_CALL_CONN_RES = 16, /* Outgoing phone call connected */
133 
134   /* Incoming/outgoing =  3,-way canceled before connected */
135   BTA_AG_CALL_CANCEL_RES = 17,
136   BTA_AG_END_CALL_RES = 18,      /* End call */
137   BTA_AG_IN_CALL_HELD_RES = 19,  /* Incoming call held */
138   BTA_AG_UNAT_RES = 20,          /* Response to unknown AT command event */
139   BTA_AG_MULTI_CALL_RES = 21,    /* SLC at three way call */
140   BTA_AG_BIND_RES = 22,          /* Activate/Deactivate HF indicator */
141   BTA_AG_IND_RES_ON_DEMAND = 33, /* Update an indicator value forcible */
142   BTA_AG_UNKNOWN = 0xff,         // Should be unset
143 } tBTA_AG_RES;
144 
bta_ag_result_text(const tBTA_AG_RES & result)145 inline std::string bta_ag_result_text(const tBTA_AG_RES& result) {
146   switch (result) {
147     CASE_RETURN_TEXT(BTA_AG_SPK_RES);
148     CASE_RETURN_TEXT(BTA_AG_MIC_RES);
149     CASE_RETURN_TEXT(BTA_AG_INBAND_RING_RES);
150     CASE_RETURN_TEXT(BTA_AG_CIND_RES);
151     CASE_RETURN_TEXT(BTA_AG_BINP_RES);
152     CASE_RETURN_TEXT(BTA_AG_IND_RES);
153     CASE_RETURN_TEXT(BTA_AG_BVRA_RES);
154     CASE_RETURN_TEXT(BTA_AG_CNUM_RES);
155     CASE_RETURN_TEXT(BTA_AG_BTRH_RES);
156     CASE_RETURN_TEXT(BTA_AG_CLCC_RES);
157     CASE_RETURN_TEXT(BTA_AG_COPS_RES);
158     CASE_RETURN_TEXT(BTA_AG_IN_CALL_RES);
159     CASE_RETURN_TEXT(BTA_AG_IN_CALL_CONN_RES);
160     CASE_RETURN_TEXT(BTA_AG_CALL_WAIT_RES);
161     CASE_RETURN_TEXT(BTA_AG_OUT_CALL_ORIG_RES);
162     CASE_RETURN_TEXT(BTA_AG_OUT_CALL_ALERT_RES);
163     CASE_RETURN_TEXT(BTA_AG_OUT_CALL_CONN_RES);
164     CASE_RETURN_TEXT(BTA_AG_CALL_CANCEL_RES);
165     CASE_RETURN_TEXT(BTA_AG_END_CALL_RES);
166     CASE_RETURN_TEXT(BTA_AG_IN_CALL_HELD_RES);
167     CASE_RETURN_TEXT(BTA_AG_UNAT_RES);
168     CASE_RETURN_TEXT(BTA_AG_MULTI_CALL_RES);
169     CASE_RETURN_TEXT(BTA_AG_BIND_RES);
170     CASE_RETURN_TEXT(BTA_AG_IND_RES_ON_DEMAND);
171     CASE_RETURN_TEXT(BTA_AG_UNKNOWN);
172     default:
173       return std::string("UNKNOWN");
174   }
175 }
176 
177 /* HFP peer features */
178 #define BTA_AG_PEER_FEAT_ECNR 0x0001    /* Echo cancellation/noise reduction */
179 #define BTA_AG_PEER_FEAT_3WAY 0x0002    /* Call waiting and three-way calling */
180 #define BTA_AG_PEER_FEAT_CLI 0x0004     /* Caller ID presentation capability */
181 #define BTA_AG_PEER_FEAT_VREC 0x0008    /* Voice recognition activation */
182 #define BTA_AG_PEER_FEAT_VOL 0x0010     /* Remote volume control */
183 #define BTA_AG_PEER_FEAT_ECS 0x0020     /* Enhanced Call Status */
184 #define BTA_AG_PEER_FEAT_ECC 0x0040     /* Enhanced Call Control */
185 #define BTA_AG_PEER_FEAT_CODEC 0x0080   /* Codec Negotiation */
186 #define BTA_AG_PEER_FEAT_HF_IND 0x0100  /* HF Indicators */
187 #define BTA_AG_PEER_FEAT_ESCO_S4 0x0200 /* eSCO S4 setting supported */
188 
189 /* Proprietary features: using bits after 12 */
190 
191 /* Pass unknown AT command responses to application */
192 #define BTA_AG_PEER_FEAT_UNAT 0x1000
193 #define BTA_AG_PEER_FEAT_VOIP 0x2000 /* VoIP call */
194 
195 typedef uint16_t tBTA_AG_PEER_FEAT;
196 
197 /* HFP peer supported codec masks */
198 typedef uint16_t tBTA_AG_PEER_CODEC;
199 
200 /* HFP errcode - Set when BTA_AG_OK_ERROR is returned in 'ok_flag' */
201 #define BTA_AG_ERR_PHONE_FAILURE 0     /* Phone Failure */
202 #define BTA_AG_ERR_NO_CONN_PHONE 1     /* No connection to phone */
203 #define BTA_AG_ERR_OP_NOT_ALLOWED 3    /* Operation not allowed */
204 #define BTA_AG_ERR_OP_NOT_SUPPORTED 4  /* Operation not supported */
205 #define BTA_AG_ERR_PHSIM_PIN_REQ 5     /* PH-SIM PIN required */
206 #define BTA_AG_ERR_SIM_NOT_INSERTED 10 /* SIM not inserted */
207 #define BTA_AG_ERR_SIM_PIN_REQ 11      /* SIM PIN required */
208 #define BTA_AG_ERR_SIM_PUK_REQ 12      /* SIM PUK required */
209 #define BTA_AG_ERR_SIM_FAILURE 13      /* SIM failure */
210 #define BTA_AG_ERR_SIM_BUSY 14         /* SIM busy */
211 #define BTA_AG_ERR_INCORRECT_PWD 16    /* Incorrect password */
212 #define BTA_AG_ERR_SIM_PIN2_REQ 17     /* SIM PIN2 required */
213 #define BTA_AG_ERR_SIM_PUK2_REQ 18     /* SIM PUK2 required */
214 #define BTA_AG_ERR_MEMORY_FULL 20      /* Memory full */
215 #define BTA_AG_ERR_INVALID_INDEX 21    /* Invalid index */
216 #define BTA_AG_ERR_MEMORY_FAILURE 23   /* Memory failure */
217 #define BTA_AG_ERR_TEXT_TOO_LONG 24    /* Text string too long */
218 #define BTA_AG_ERR_INV_CHAR_IN_TSTR 25 /* Invalid characters in text string */
219 #define BTA_AG_ERR_DSTR_TOO_LONG 26    /* Dial string too long */
220 #define BTA_AG_ERR_INV_CHAR_IN_DSTR 27 /* Invalid characters in dial string */
221 #define BTA_AG_ERR_NO_NETWORK_SERV 30  /* No network service */
222 #define BTA_AG_ERR_NETWORK_TIME_OUT 31 /* Network timeout */
223 /* Network not allowed - emergency service only */
224 #define BTA_AG_ERR_NO_NET_EMG_ONLY 32
225 /* AG cannot create simultaneous VoIP and CS calls */
226 #define BTA_AG_ERR_VOIP_CS_CALLS 33
227 #define BTA_AG_ERR_NOT_FOR_VOIP 34  /* Not supported on this call type(VoIP) */
228 #define BTA_AG_ERR_SIP_RESP_CODE 35 /* SIP 3 digit response code */
229 
230 #if 0                                 /* Not Used in Bluetooth HFP 1.5 Specification */
231 #define BTA_AG_ERR_PHADAP_LNK_RES 2   /* Phone-adapter link reserved */
232 #define BTA_AG_ERR_PHFSIM_PIN_REQ 6   /* PH-FSIM PIN required */
233 #define BTA_AG_ERR_PHFSIM_PUK_REQ 7   /* PH-FSIM PUK required */
234 #define BTA_AG_ERR_SIM_WRONG 15       /* SIM wrong */
235 #define BTA_AG_ERR_NOT_FOUND 22       /* Not found */
236 #define BTA_AG_ERR_NETWORK_TIMEOUT 31 /* Network timeout */
237 #define BTA_AG_ERR_NET_PIN_REQ 40     /* Network personalization PIN required */
238 #define BTA_AG_ERR_NET_PUK_REQ 41     /* Network personalization PUK required */
239 /* Network subset personalization PIN required */
240 #define BTA_AG_ERR_SUBSET_PIN_REQ 42
241 /* Network subset personalization PUK required */
242 #define BTA_AG_ERR_SUBSET_PUK_REQ 43
243 /* Service provider personalization PIN required */
244 #define BTA_AG_ERR_SERVPRO_PIN_REQ 44
245 /* Service provider personalization PUK required */
246 #define BTA_AG_ERR_SERVPRO_PUK_REQ 45
247 /* Corporate personalization PIN required */
248 #define BTA_AG_ERR_CORP_PIN_REQ 46
249 /* Corporate personalization PUK required */
250 #define BTA_AG_ERR_CORP_PUK_REQ 47
251 #define BTA_AG_ERR_UNKNOWN 100          /* Unknown error */
252 
253 /* GPRS-related errors */
254 #define BTA_AG_ERR_ILL_MS 103           /* Illegal MS (#3) */
255 #define BTA_AG_ERR_ILL_ME 106           /* Illegal ME (#6) */
256 #define BTA_AG_ERR_GPRS_NOT_ALLOWED 107 /* GPRS services not allowed (#7) */
257 #define BTA_AG_ERR_PLMN_NOT_ALLOWED 111 /* PLMN services not allowed (#11) */
258 #define BTA_AG_ERR_LOC_NOT_ALLOWED 112  /* Location area not allowed (#12) */
259 /* Roaming not allowed in this location area (#13) */
260 #define BTA_AG_ERR_ROAM_NOT_ALLOWED 113
261 /* Errors related to a failure to Activate a Context */
262 #define BTA_AG_ERR_OPT_NOT_SUPP 132 /* Service option not supported (#32) */
263 /* Requested service option not subscribed (#33) */
264 #define BTA_AG_ERR_OPT_NOT_SUBSCR 133
265 /* Service option temporarily out of order (#34) */
266 #define BTA_AG_ERR_OPT_OUT_OF_ORDER 134
267 #define BTA_AG_ERR_PDP_AUTH_FAILURE 149 /* PDP authentication failure */
268 /* Other GPRS errors */
269 #define BTA_AG_ERR_INV_MOBILE_CLASS 150 /* Invalid mobile class */
270 #define BTA_AG_ERR_UNSPEC_GPRS_ERR 148  /* Unspecified GPRS error */
271 #endif                                  /* Unused error codes */
272 
273 /* HFP result data 'ok_flag' */
274 #define BTA_AG_OK_CONTINUE 0 /* Send out response (more responses coming) */
275 #define BTA_AG_OK_DONE 1     /* Send out response followed by OK (finished) */
276 #define BTA_AG_OK_ERROR 2    /* Error response */
277 
278 /* BTRH values */
279 #define BTA_AG_BTRH_SET_HOLD 0 /* Put incoming call on hold */
280 #define BTA_AG_BTRH_SET_ACC 1  /* Accept incoming call on hold */
281 #define BTA_AG_BTRH_SET_REJ 2  /* Reject incoming call on hold */
282 #define BTA_AG_BTRH_READ 3     /* Read the current value */
283 #define BTA_AG_BTRH_NO_RESP 4  /* Not in RH States (reply to read) */
284 
285 /* clip type constants */
286 #define BTA_AG_CLIP_TYPE_MIN 128
287 #define BTA_AG_CLIP_TYPE_MAX 175
288 #define BTA_AG_CLIP_TYPE_DEFAULT 129
289 #define BTA_AG_CLIP_TYPE_VOIP 255
290 
291 /* ASCII character string of arguments to the AT command or result */
292 #ifndef BTA_AG_AT_MAX_LEN
293 #define BTA_AG_AT_MAX_LEN 256
294 #endif
295 
296 namespace hfp {
297 
298 // Define hfp offload config structure
299 struct offload_config {
300   tBTA_AG_UUID_CODEC sco_codec;
301   int32_t connection_handle;
302   bool is_controller_codec;
303   bool is_nrec;
304 };
305 
306 // Define hfp pcm config structure
307 struct pcm_config {
308   int sample_rate_hz;
309   // The below fields are always fixed
310   // int channel_mode = ChannelMode::MONO;
311   // uint8_t bits_per_sample = 16;
312   // int data_interval_us = 7500;
313 };
314 
315 struct sco_config {
316   int inputDataPath;
317   int outputDataPath;
318   bool useControllerCodec;
319 };
320 
321 }  // namespace hfp
322 /* data associated with BTA_AG_IND_RES */
323 typedef struct {
324   uint16_t id;
325   uint16_t value;
326   bool on_demand;
327 } tBTA_AG_IND;
328 
329 /* data type for BTA_AgResult() */
330 struct tBTA_AG_RES_DATA {
331   char str[BTA_AG_AT_MAX_LEN + 1];
332   tBTA_AG_IND ind;
333   uint16_t num;
334   uint16_t audio_handle;
335   uint16_t errcode; /* Valid only if 'ok_flag' is set to BTA_AG_OK_ERROR */
336   uint8_t ok_flag;  /* Indicates if response is finished, and if error occurred */
337   bool state;
338   static const tBTA_AG_RES_DATA kEmpty;
339 };
340 
341 typedef enum : uint8_t {
342   /* AG callback events */
343   BTA_AG_ENABLE_EVT = 0,      /* AG enabled */
344   BTA_AG_REGISTER_EVT = 1,    /* AG registered */
345   BTA_AG_OPEN_EVT = 2,        /* AG connection open */
346   BTA_AG_CLOSE_EVT = 3,       /* AG connection closed */
347   BTA_AG_CONN_EVT = 4,        /* Service level connection opened */
348   BTA_AG_AUDIO_OPEN_EVT = 5,  /* Audio connection open */
349   BTA_AG_AUDIO_CLOSE_EVT = 6, /* Audio connection closed */
350   BTA_AG_SPK_EVT = 7,         /* Speaker volume changed */
351   BTA_AG_MIC_EVT = 8,         /* Microphone volume changed */
352   BTA_AG_AT_CKPD_EVT = 9,     /* CKPD from the HS */
353   BTA_AG_DISABLE_EVT = 30,    /* AG disabled */
354   BTA_AG_CODEC_EVT = 31,      /* SCO codec info */
355   /* Values below are for HFP only */
356   BTA_AG_AT_A_EVT = 10,    /* Answer a call */
357   BTA_AG_AT_D_EVT = 11,    /* Place a call using number or memory dial */
358   BTA_AG_AT_CHLD_EVT = 12, /* Call hold */
359   BTA_AG_AT_CHUP_EVT = 13, /* Hang up a call */
360   BTA_AG_AT_CIND_EVT = 14, /* Read indicator settings */
361   BTA_AG_AT_VTS_EVT = 15,  /* Transmit DTMF tone */
362   BTA_AG_AT_BINP_EVT = 16, /* Retrieve number from voice tag */
363   BTA_AG_AT_BLDN_EVT = 17, /* Place call to last dialed number */
364   BTA_AG_AT_BVRA_EVT = 18, /* Enable/disable voice recognition */
365   BTA_AG_AT_NREC_EVT = 19, /* Disable echo canceling */
366   BTA_AG_AT_CNUM_EVT = 20, /* Retrieve subscriber number */
367   BTA_AG_AT_BTRH_EVT = 21, /* CCAP-style incoming call hold */
368   BTA_AG_AT_CLCC_EVT = 22, /* Query list of current calls */
369   BTA_AG_AT_COPS_EVT = 23, /* Query list of current calls */
370   BTA_AG_AT_UNAT_EVT = 24, /* Unknown AT command */
371   BTA_AG_AT_CBC_EVT = 25,  /* Battery Level report from HF */
372   BTA_AG_AT_BAC_EVT = 26,  /* avablable codec */
373   BTA_AG_AT_BCS_EVT = 27,  /* Codec select */
374   BTA_AG_AT_BIND_EVT = 28, /* HF indicator */
375   BTA_AG_AT_BIEV_EVT = 29, /* HF indicator updates from peer */
376   BTA_AG_AT_BIA_EVT = 32,  /* AG indicator activation event from peer */
377 } tBTA_AG_EVT;
378 
379 /* data associated with most non-AT events */
380 typedef struct {
381   uint16_t handle;
382   uint8_t app_id;
383   tBTA_AG_STATUS status;
384 } tBTA_AG_HDR;
385 
386 /* data associated with BTA_AG_REGISTER_EVT */
387 typedef struct {
388   tBTA_AG_HDR hdr;
389   tBTA_AG_STATUS status;
390 } tBTA_AG_REGISTER;
391 
392 /* data associated with BTA_AG_OPEN_EVT */
393 typedef struct {
394   tBTA_AG_HDR hdr;
395   RawAddress bd_addr;
396   tBTA_SERVICE_ID service_id;
397   tBTA_AG_STATUS status;
398 } tBTA_AG_OPEN;
399 
400 /* data associated with BTA_AG_CLOSE_EVT */
401 typedef struct {
402   tBTA_AG_HDR hdr;
403   RawAddress bd_addr;
404 } tBTA_AG_CLOSE;
405 
406 /* data associated with BTA_AG_CONN_EVT */
407 typedef struct {
408   tBTA_AG_HDR hdr;
409   tBTA_AG_PEER_FEAT peer_feat;
410   RawAddress bd_addr;
411   tBTA_AG_PEER_CODEC peer_codec;
412 } tBTA_AG_CONN;
413 
414 /* data associated with AT command event */
415 typedef struct {
416   tBTA_AG_HDR hdr;
417   RawAddress bd_addr;
418   char str[BTA_AG_AT_MAX_LEN + 1];
419   uint32_t num;
420   uint8_t idx;   /* call number used by CLCC and CHLD */
421   uint16_t lidx; /* long index, ex, HF indicator */
422 } tBTA_AG_VAL;
423 
424 /* union of data associated with AG callback */
425 typedef union {
426   tBTA_AG_HDR hdr;
427   tBTA_AG_REGISTER reg;
428   tBTA_AG_OPEN open;
429   tBTA_AG_CLOSE close;
430   tBTA_AG_CONN conn;
431   tBTA_AG_VAL val;
432 } tBTA_AG;
433 
434 /* AG callback */
435 typedef void(tBTA_AG_CBACK)(tBTA_AG_EVT event, tBTA_AG* p_data);
436 
437 /* indicator constants HFP 1.1 and later */
438 #define BTA_AG_IND_CALL 1      /* position of call indicator */
439 #define BTA_AG_IND_CALLSETUP 2 /* position of callsetup indicator */
440 #define BTA_AG_IND_SERVICE 3   /* position of service indicator */
441 
442 /* indicator constants HFP 1.5 and later */
443 #define BTA_AG_IND_SIGNAL 4   /* position of signal strength indicator */
444 #define BTA_AG_IND_ROAM 5     /* position of roaming indicator */
445 #define BTA_AG_IND_BATTCHG 6  /* position of battery charge indicator */
446 #define BTA_AG_IND_CALLHELD 7 /* position of callheld indicator */
447 #define BTA_AG_IND_BEARER 8   /* position of bearer indicator */
448 
449 /* call indicator values */
450 #define BTA_AG_CALL_INACTIVE 0 /* Phone call inactive */
451 #define BTA_AG_CALL_ACTIVE 1   /* Phone call active */
452 
453 /* callsetup indicator values */
454 #define BTA_AG_CALLSETUP_NONE 0     /* Not currently in call set up */
455 #define BTA_AG_CALLSETUP_INCOMING 1 /* Incoming call process ongoing */
456 #define BTA_AG_CALLSETUP_OUTGOING 2 /* Outgoing call set up is ongoing */
457 /* Remote party being alerted in an outgoing call */
458 #define BTA_AG_CALLSETUP_ALERTING 3
459 
460 /* service indicator values */
461 #define BTA_AG_SERVICE_NONE 0    /* Neither CS nor VoIP service is available */
462 #define BTA_AG_SERVICE_CS 1      /* Only CS service is available */
463 #define BTA_AG_SERVICE_VOIP 2    /* Only VoIP service is available */
464 #define BTA_AG_SERVICE_CS_VOIP 3 /* Both CS and VoIP services available */
465 
466 /* callheld indicator values */
467 #define BTA_AG_CALLHELD_INACTIVE 0 /* No held calls */
468 #define BTA_AG_CALLHELD_ACTIVE 1   /* Call held and call active */
469 #define BTA_AG_CALLHELD_NOACTIVE 2 /* Call held and no call active */
470 
471 /* signal strength indicator values */
472 #define BTA_AG_ROAMING_INACTIVE 0 /* Phone call inactive */
473 #define BTA_AG_ROAMING_ACTIVE 1   /* Phone call active */
474 
475 /* bearer indicator values */
476 #define BTA_AG_BEARER_WLAN 0      /* WLAN         */
477 #define BTA_AG_BEARER_BLUETOOTH 1 /* Bluetooth    */
478 #define BTA_AG_BEARER_WIRED 2     /* Wired        */
479 #define BTA_AG_BEARER_2G3G 3      /* 2G 3G        */
480 #define BTA_AG_BEARER_WIMAX 4     /* WIMAX        */
481 #define BTA_AG_BEARER_RES1 5      /* Reserved     */
482 #define BTA_AG_BEARER_RES2 6      /* Reserved     */
483 #define BTA_AG_BEARER_RES3 7      /* Reserved     */
484 
485 /* type for HF indicator */
486 typedef struct {
487   uint16_t ind_id;
488   bool is_supported;
489   bool is_enable;
490   uint32_t ind_min_val;
491   uint32_t ind_max_val;
492 } tBTA_AG_HF_IND;
493 
494 /* AG configuration structure */
495 typedef struct {
496   const char* cind_info;
497   const char* bind_info;
498   uint8_t num_local_hf_ind;
499   int32_t conn_tout;
500   uint16_t sco_pkt_types;
501   const char* chld_val_ecc;
502   const char* chld_val;
503 } tBTA_AG_CFG;
504 
505 /*****************************************************************************
506  *  External Function Declarations
507  ****************************************************************************/
508 
509 /*******************************************************************************
510  *
511  * Function         BTA_AgEnable
512  *
513  * Description      Enable the audio gateway service. When the enable
514  *                  operation is complete the callback function will be
515  *                  called with a BTA_AG_ENABLE_EVT. This function must
516  *                  be called before other function in the AG API are
517  *                  called.
518  *
519  * Returns          BTA_SUCCESS if OK, BTA_FAILURE otherwise.
520  *
521  ******************************************************************************/
522 tBTA_STATUS BTA_AgEnable(tBTA_AG_CBACK* p_cback);
523 
524 /*******************************************************************************
525  *
526  * Function         BTA_AgDisable
527  *
528  * Description      Disable the audio gateway service
529  *
530  *
531  * Returns          void
532  *
533  ******************************************************************************/
534 void BTA_AgDisable();
535 
536 /*******************************************************************************
537  *
538  * Function         BTA_AgRegister
539  *
540  * Description      Register an Audio Gateway service.
541  *
542  *
543  * Returns          void
544  *
545  ******************************************************************************/
546 void BTA_AgRegister(tBTA_SERVICE_MASK services, tBTA_AG_FEAT features,
547                     const std::vector<std::string>& service_names, uint8_t app_id);
548 
549 /*******************************************************************************
550  *
551  * Function         BTA_AgDeregister
552  *
553  * Description      Deregister an audio gateway service.
554  *
555  *
556  * Returns          void
557  *
558  ******************************************************************************/
559 void BTA_AgDeregister(uint16_t handle);
560 
561 /*******************************************************************************
562  *
563  * Function         BTA_AgOpen
564  *
565  * Description      Opens a connection to a headset or hands-free device.
566  *                  When connection is open callback function is called
567  *                  with a BTA_AG_OPEN_EVT. Only the data connection is
568  *                  opened. The audio connection is not opened.
569  *
570  *
571  * Returns          void
572  *
573  ******************************************************************************/
574 void BTA_AgOpen(uint16_t handle, const RawAddress& bd_addr);
575 
576 /*******************************************************************************
577  *
578  * Function         BTA_AgClose
579  *
580  * Description      Close the current connection to a headset or a handsfree
581  *                  Any current audio connection will also be closed
582  *
583  *
584  * Returns          void
585  *
586  ******************************************************************************/
587 void BTA_AgClose(uint16_t handle);
588 
589 /*******************************************************************************
590  *
591  * Function         BTA_AgAudioOpen
592  *
593  * Description      Opens an audio connection to the currently connected
594  *                  headset or handsfree. Specify `disabled_codecs` to
595  *                  force the stack to avoid using certain codecs.
596  *
597  *                  Note that CVSD is a mandatory codec and cannot be disabled.
598  *
599  *
600  * Returns          void
601  *
602  ******************************************************************************/
603 void BTA_AgAudioOpen(uint16_t handle, tBTA_AG_PEER_CODEC disabled_codecs);
604 
605 /*******************************************************************************
606  *
607  * Function         BTA_AgAudioClose
608  *
609  * Description      Close the currently active audio connection to a headset
610  *                  or hnadsfree. The data connection remains open
611  *
612  *
613  * Returns          void
614  *
615  ******************************************************************************/
616 void BTA_AgAudioClose(uint16_t handle);
617 
618 /*******************************************************************************
619  *
620  * Function         BTA_AgResult
621  *
622  * Description      Send an AT result code to a headset or hands-free device.
623  *
624  *
625  * Returns          void
626  *
627  ******************************************************************************/
628 void BTA_AgResult(uint16_t handle, tBTA_AG_RES result, const tBTA_AG_RES_DATA& data);
629 
630 /*******************************************************************************
631  *
632  * Function         BTA_AgSetCodec
633  *
634  * Description      Specify the codec type to be used for the subsequent
635  *                  audio connection.
636  *
637  *
638  *
639  * Returns          void
640  *
641  ******************************************************************************/
642 void BTA_AgSetCodec(uint16_t handle, tBTA_AG_PEER_CODEC codec);
643 
644 void BTA_AgSetScoOffloadEnabled(bool value);
645 
646 void BTA_AgSetScoAllowed(bool value);
647 
648 void BTA_AgSetActiveDevice(const RawAddress& active_device_addr);
649 
650 namespace std {
651 template <>
652 struct formatter<tBTA_AG_RES> : enum_formatter<tBTA_AG_RES> {};
653 }  // namespace std
654 
655 #endif /* BTA_AG_API_H */
656