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