1 /******************************************************************************
2  *
3  *  Copyright (c) 2014 The Android Open Source Project
4  *  Copyright 2003-2012 Broadcom Corporation
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at:
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  ******************************************************************************/
19 
20 /******************************************************************************
21  *
22  *  This is the public interface file for the handsfree (HF role) subsystem
23  *
24  ******************************************************************************/
25 #ifndef BTA_HF_CLIENT_API_H
26 #define BTA_HF_CLIENT_API_H
27 
28 #include <cstdint>
29 
30 #include "bta_api.h"
31 #include "bta_hfp_api.h"
32 #include "types/raw_address.h"
33 
34 /*****************************************************************************
35  *  Constants and data types
36  ****************************************************************************/
37 
38 /* HFP peer (AG) features*/
39 #define BTA_HF_CLIENT_PEER_FEAT_3WAY 0x00000001 /* Three-way calling */
40 #define BTA_HF_CLIENT_PEER_FEAT_ECNR 0x00000002 /* Echo cancellation and/or noise reduction */
41 #define BTA_HF_CLIENT_PEER_FEAT_VREC 0x00000004 /* Voice recognition */
42 #define BTA_HF_CLIENT_PEER_INBAND 0x00000008    /* In-band ring tone */
43 #define BTA_HF_CLIENT_PEER_VTAG 0x00000010      /* Attach a phone number to a voice tag */
44 #define BTA_HF_CLIENT_PEER_REJECT 0x00000020    /* Ability to reject incoming call */
45 #define BTA_HF_CLIENT_PEER_ECS 0x00000040       /* Enhanced Call Status */
46 #define BTA_HF_CLIENT_PEER_ECC 0x00000080       /* Enhanced Call Control */
47 #define BTA_HF_CLIENT_PEER_EXTERR 0x00000100    /* Extended error codes */
48 #define BTA_HF_CLIENT_PEER_CODEC 0x00000200     /* Codec Negotiation */
49 #define BTA_HF_CLIENT_PEER_HF_IND 0x00000400    /* HF Indicators */
50 #define BTA_HF_CLIENT_PEER_ESCO_S4 0x00000800   /* ESCO S4 link setting */
51 
52 typedef uint16_t tBTA_HF_CLIENT_PEER_FEAT;
53 
54 /* HFP HF features */
55 #define BTA_HF_CLIENT_FEAT_ECNR 0x00000001    /* Echo cancellation and/or noise reduction */
56 #define BTA_HF_CLIENT_FEAT_3WAY 0x00000002    /* Call waiting and three-way calling */
57 #define BTA_HF_CLIENT_FEAT_CLI 0x00000004     /* Caller ID presentation capability */
58 #define BTA_HF_CLIENT_FEAT_VREC 0x00000008    /* Voice recognition activation */
59 #define BTA_HF_CLIENT_FEAT_VOL 0x00000010     /* Remote volume control */
60 #define BTA_HF_CLIENT_FEAT_ECS 0x00000020     /* Enhanced Call Status */
61 #define BTA_HF_CLIENT_FEAT_ECC 0x00000040     /* Enhanced Call Control */
62 #define BTA_HF_CLIENT_FEAT_CODEC 0x00000080   /* Codec Negotiation */
63 #define BTA_HF_CLIENT_FEAT_HF_IND 0x00000100  /* HF Indicators */
64 #define BTA_HF_CLIENT_FEAT_ESCO_S4 0x00000200 /* ESCO S4 link setting */
65 #define BTA_HF_CLIENT_FEAT_SWB 0x00000400     /* SWB feature (HFP 1.9) */
66 
67 /* FP SDP feature masks */
68 #define BTA_HF_CLIENT_WBS_SUPPORT 0x0020      /* Supports WBS */
69 #define BTA_HF_CLIENT_FEAT_SWB_SUPPORT 0x0100 /* Supports SWB */
70 
71 /* HFP HF extended call handling - masks not related to any spec */
72 #define BTA_HF_CLIENT_CHLD_REL 0x00000001 /* 0  Release waiting call or held calls */
73 #define BTA_HF_CLIENT_CHLD_REL_ACC                                             \
74   0x00000002 /* 1  Release active calls and accept other (waiting or held) cal \
75               */
76 #define BTA_HF_CLIENT_CHLD_REL_X 0x00000004    /* 1x Release x call*/
77 #define BTA_HF_CLIENT_CHLD_HOLD_ACC 0x00000008 /* 2  Active calls on hold and accept other call */
78 #define BTA_HF_CLIENT_CHLD_PRIV_X 0x00000010   /* 2x Active multiparty call on hold except call x */
79 #define BTA_HF_CLIENT_CHLD_MERGE                                                     \
80   0x00000020                                       /* 3  Add held call to multiparty \
81                                                     */
82 #define BTA_HF_CLIENT_CHLD_MERGE_DETACH 0x00000040 /* 4  Add held call to multiparty */
83 
84 typedef uint16_t tBTA_HF_CLIENT_CHLD_FEAT;
85 
86 /* HFP AG errors ot OK sent to HF Unit */
87 #define BTA_HF_CLIENT_AT_RESULT_OK 0
88 #define BTA_HF_CLIENT_AT_RESULT_ERROR 1
89 #define BTA_HF_CLIENT_AT_RESULT_NO_CARRIER 2
90 #define BTA_HF_CLIENT_AT_RESULT_BUSY 3
91 #define BTA_HF_CLIENT_AT_RESULT_NO_ANSWER 4
92 #define BTA_HF_CLIENT_AT_RESULT_DELAY 5
93 #define BTA_HF_CLIENT_AT_RESULT_REJECTLISTED 6
94 #define BTA_HF_CLIENT_AT_RESULT_CME 7
95 
96 typedef uint8_t tBTA_HF_CLIENT_AT_RESULT_TYPE;
97 
98 /* HF Client callback events */
99 #define BTA_HF_CLIENT_ENABLE_EVT 0          /* HF Client enabled */
100 #define BTA_HF_CLIENT_REGISTER_EVT 1        /* HF Client registered */
101 #define BTA_HF_CLIENT_OPEN_EVT 2            /* HF Client connection open */
102 #define BTA_HF_CLIENT_CLOSE_EVT 3           /* HF Client connection closed */
103 #define BTA_HF_CLIENT_CONN_EVT 4            /* Service level connection opened */
104 #define BTA_HF_CLIENT_AUDIO_OPEN_EVT 5      /* Audio connection open */
105 #define BTA_HF_CLIENT_AUDIO_MSBC_OPEN_EVT 6 /* Audio connection with mSBC codec open */
106 #define BTA_HF_CLIENT_AUDIO_CLOSE_EVT 7     /* Audio connection closed */
107 #define BTA_HF_CLIENT_SPK_EVT 8             /* Speaker volume changed */
108 #define BTA_HF_CLIENT_MIC_EVT 9             /* Microphone volume changed */
109 #define BTA_HF_CLIENT_IND_EVT 10            /* Indicator */
110 #define BTA_HF_CLIENT_VOICE_REC_EVT 11      /* AG changed voice recognition setting */
111 #define BTA_HF_CLIENT_OPERATOR_NAME_EVT 12  /* Operator name acquired */
112 #define BTA_HF_CLIENT_CLIP_EVT 13           /* Calling line identification event */
113 #define BTA_HF_CLIENT_CCWA_EVT 14           /* Call waiting notification */
114 #define BTA_HF_CLIENT_AT_RESULT_EVT 15      /* Call waiting notification */
115 #define BTA_HF_CLIENT_CLCC_EVT 16           /* current call event */
116 #define BTA_HF_CLIENT_CNUM_EVT 17           /* subscriber information event */
117 #define BTA_HF_CLIENT_BTRH_EVT 18           /* bluetooth response and hold event */
118 #define BTA_HF_CLIENT_BSIR_EVT                                                      \
119   19                                     /* in-band ring tone setting changed event \
120                                           */
121 #define BTA_HF_CLIENT_BINP_EVT 20        /* binp number event */
122 #define BTA_HF_CLIENT_RING_INDICATION 21 /* HF Client ring indication */
123 
124 #define BTA_HF_CLIENT_UNKNOWN_EVT 22        /* Unknown or vendor specific Event */
125 #define BTA_HF_CLIENT_AUDIO_LC3_OPEN_EVT 23 /* Audio connection with LC3 codec open */
126 #define BTA_HF_CLIENT_DISABLE_EVT 30        /* HF Client disabled */
127 
128 typedef uint8_t tBTA_HF_CLIENT_EVT;
129 
130 /* HF Client open status */
131 #define BTA_HF_CLIENT_SUCCESS 0        /* Connection successfully opened */
132 #define BTA_HF_CLIENT_FAIL_SDP 1       /* Open failed due to SDP */
133 #define BTA_HF_CLIENT_FAIL_RFCOMM 2    /* Open failed due to RFCOMM */
134 #define BTA_HF_CLIENT_FAIL_RESOURCES 3 /* out of resources failure  */
135 
136 typedef uint8_t tBTA_HF_CLIENT_STATUS;
137 
138 /* indicator type */
139 #define BTA_HF_CLIENT_IND_BATTCH 0    /* Battery charge indicator */
140 #define BTA_HF_CLIENT_IND_SIGNAL 1    /* Signal Strength indicator */
141 #define BTA_HF_CLIENT_IND_SERVICE 2   /* Service availability indicator */
142 #define BTA_HF_CLIENT_IND_CALL 3      /* Standard call status indicator*/
143 #define BTA_HF_CLIENT_IND_ROAM 4      /* Roaming status indicator */
144 #define BTA_HF_CLIENT_IND_CALLSETUP 5 /* Call setup status indicator */
145 #define BTA_HF_CLIENT_IND_CALLHELD 6  /* Call hold status indicator */
146 
147 typedef uint8_t tBTA_HF_CLIENT_IND_TYPE;
148 
149 /* AT commands */
150 #define BTA_HF_CLIENT_AT_CMD_VTS 0
151 #define BTA_HF_CLIENT_AT_CMD_BTRH 1
152 #define BTA_HF_CLIENT_AT_CMD_CHUP 2
153 #define BTA_HF_CLIENT_AT_CMD_CHLD 3
154 #define BTA_HF_CLIENT_AT_CMD_BCC 4
155 #define BTA_HF_CLIENT_AT_CMD_CNUM 5
156 #define BTA_HF_CLIENT_AT_CMD_ATA 6
157 #define BTA_HF_CLIENT_AT_CMD_COPS 7
158 #define BTA_HF_CLIENT_AT_CMD_ATD 8
159 #define BTA_HF_CLIENT_AT_CMD_VGM 9
160 #define BTA_HF_CLIENT_AT_CMD_VGS 10
161 #define BTA_HF_CLIENT_AT_CMD_BVRA 11
162 #define BTA_HF_CLIENT_AT_CMD_CLCC 12
163 #define BTA_HF_CLIENT_AT_CMD_BINP 13
164 #define BTA_HF_CLIENT_AT_CMD_BLDN 14
165 #define BTA_HF_CLIENT_AT_CMD_NREC 15
166 #define BTA_HF_CLIENT_AT_CMD_VENDOR_SPECIFIC_CMD 16
167 #define BTA_HF_CLIENT_AT_CMD_BIEV 17
168 #define BTA_HF_CLIENT_AT_CMD_ANDROID 18
169 
170 typedef uint8_t tBTA_HF_CLIENT_AT_CMD_TYPE;
171 
172 /* data associated with BTA_HF_CLIENT_REGISTER_EVT */
173 typedef struct {
174   RawAddress bd_addr;
175   tBTA_HF_CLIENT_STATUS status;
176 } tBTA_HF_CLIENT_REGISTER;
177 
178 /* data associated with BTA_HF_CLIENT_OPEN_EVT */
179 typedef struct {
180   RawAddress bd_addr;
181   uint16_t handle;  // Handle for client control block
182   tBTA_HF_CLIENT_STATUS status;
183 } tBTA_HF_CLIENT_OPEN;
184 
185 /* data associated with BTA_HF_CLIENT_CONN_EVT */
186 typedef struct {
187   RawAddress bd_addr;
188   tBTA_HF_CLIENT_PEER_FEAT peer_feat;
189   tBTA_HF_CLIENT_CHLD_FEAT chld_feat;
190 } tBTA_HF_CLIENT_CONN;
191 
192 /* data associated with BTA_HF_CLIENT_IND_EVT event */
193 typedef struct {
194   RawAddress bd_addr;
195   tBTA_HF_CLIENT_IND_TYPE type;
196   uint16_t value;
197 } tBTA_HF_CLIENT_IND;
198 
199 /* data associated with BTA_HF_CLIENT_OPERATOR_NAME_EVT */
200 #define BTA_HF_CLIENT_OPERATOR_NAME_LEN 16
201 typedef struct {
202   RawAddress bd_addr;
203   char name[BTA_HF_CLIENT_OPERATOR_NAME_LEN + 1];
204 } tBTA_HF_CLIENT_OPERATOR_NAME;
205 
206 /* data associated with BTA_HF_CLIENT_CLIP_EVT  and BTA_HF_CLIENT_CCWA_EVT*/
207 #define BTA_HF_CLIENT_NUMBER_LEN 32
208 typedef struct {
209   RawAddress bd_addr;
210   char number[BTA_HF_CLIENT_NUMBER_LEN + 1];
211 } tBTA_HF_CLIENT_NUMBER;
212 
213 /* data associated with BTA_HF_CLIENT_AT_RESULT_EVT event */
214 typedef struct {
215   RawAddress bd_addr;
216   tBTA_HF_CLIENT_AT_RESULT_TYPE type;
217   uint16_t cme;
218 } tBTA_HF_CLIENT_AT_RESULT;
219 
220 /* data associated with BTA_HF_CLIENT_CLCC_EVT event */
221 typedef struct {
222   RawAddress bd_addr;
223   uint32_t idx;
224   bool inc;
225   uint8_t status;
226   bool mpty;
227   bool number_present;
228   char number[BTA_HF_CLIENT_NUMBER_LEN + 1];
229 } tBTA_HF_CLIENT_CLCC;
230 
231 /* data associated with BTA_HF_CLIENT_CNUM_EVT event */
232 typedef struct {
233   RawAddress bd_addr;
234   uint16_t service;
235   char number[BTA_HF_CLIENT_NUMBER_LEN + 1];
236 } tBTA_HF_CLIENT_CNUM;
237 
238 /* data associated with other events */
239 typedef struct {
240   RawAddress bd_addr;
241   uint16_t value;
242 } tBTA_HF_CLIENT_VAL;
243 
244 /* data associated with BTA_HF_CLIENT_UNKNOWN_EVT event */
245 #define BTA_HF_CLIENT_UNKNOWN_EVENT_LEN 32
246 typedef struct {
247   RawAddress bd_addr;
248   char event_string[BTA_HF_CLIENT_UNKNOWN_EVENT_LEN + 1];
249 } tBTA_HF_CLIENT_UNKNOWN;
250 
251 /* union of data associated with AG callback */
252 typedef union {
253   // Common BD ADDR field for all tyepdefs
254   RawAddress bd_addr;
255   tBTA_HF_CLIENT_REGISTER reg;
256   tBTA_HF_CLIENT_OPEN open;
257   tBTA_HF_CLIENT_CONN conn;
258   tBTA_HF_CLIENT_IND ind;
259   tBTA_HF_CLIENT_VAL val;
260   tBTA_HF_CLIENT_OPERATOR_NAME operator_name;
261   tBTA_HF_CLIENT_NUMBER number;
262   tBTA_HF_CLIENT_AT_RESULT result;
263   tBTA_HF_CLIENT_CLCC clcc;
264   tBTA_HF_CLIENT_CNUM cnum;
265   tBTA_HF_CLIENT_UNKNOWN unknown;
266 } tBTA_HF_CLIENT;
267 
268 typedef uint32_t tBTA_HF_CLIENT_FEAT;
269 
270 /* HF Client callback */
271 typedef void(tBTA_HF_CLIENT_CBACK)(tBTA_HF_CLIENT_EVT event, tBTA_HF_CLIENT* p_data);
272 
273 /*****************************************************************************
274  *  External Function Declarations
275  ****************************************************************************/
276 
277 /*******************************************************************************
278  *
279  * Function         BTA_HfClientEnable
280  *
281  * Description      Enable the HF CLient service. When the enable
282  *                  operation is complete the callback function will be
283  *                  called with a BTA_HF_CLIENT_ENABLE_EVT. This function must
284  *                  be called before other function in the HF CLient API are
285  *                  called.
286  *
287  * Returns          BTA_SUCCESS if OK, BTA_FAILURE otherwise.
288  *
289  ******************************************************************************/
290 tBTA_STATUS BTA_HfClientEnable(tBTA_HF_CLIENT_CBACK* p_cback, tBTA_HF_CLIENT_FEAT features,
291                                const char* p_service_name);
292 
293 /*******************************************************************************
294  *
295  * Function         BTA_HfClientDisable
296  *
297  * Description      Disable the HF Client service.
298  *
299  * Returns          void
300  *
301  ******************************************************************************/
302 void BTA_HfClientDisable(void);
303 
304 /*******************************************************************************
305  *
306  * Function         BTA_HfClientOpen
307  *
308  * Description      Opens a connection to an audio gateway.
309  *                  When connection is open callback function is called
310  *                  with a BTA_HF_CLIENT_OPEN_EVT. Only the data connection is
311  *                  opened. The audio connection is not opened. The handle
312  *                  is stored in p_handle and should be used for subsequent
313  *                  calls to do any AT operations
314  *
315  *
316  * Returns          bt_status_t
317  *
318  ******************************************************************************/
319 bt_status_t BTA_HfClientOpen(const RawAddress& bd_addr, uint16_t* p_handle);
320 
321 /*******************************************************************************
322  *
323  * Function         BTA_HfClientClose
324  *
325  * Description      Close the current connection to an audio gateway.
326  *                  Any current audio connection will also be closed
327  *
328  *
329  * Returns          void
330  *
331  ******************************************************************************/
332 void BTA_HfClientClose(uint16_t handle);
333 
334 /*******************************************************************************
335  *
336  * Function         BTA_HfCllientAudioOpen
337  *
338  * Description      Opens an audio connection to the currently connected
339  *                 audio gateway
340  *
341  *
342  * Returns          void
343  *
344  ******************************************************************************/
345 void BTA_HfClientAudioOpen(uint16_t handle);
346 
347 /*******************************************************************************
348  *
349  * Function         BTA_HfClientAudioClose
350  *
351  * Description      Close the currently active audio connection to an audio
352  *                  gateway. The data connection remains open
353  *
354  *
355  * Returns          void
356  *
357  ******************************************************************************/
358 void BTA_HfClientAudioClose(uint16_t handle);
359 
360 /*******************************************************************************
361  *
362  * Function         BTA_HfClientSendAT
363  *
364  * Description      send AT command
365  *
366  *
367  * Returns          void
368  *
369  ******************************************************************************/
370 void BTA_HfClientSendAT(uint16_t handle, tBTA_HF_CLIENT_AT_CMD_TYPE at, uint32_t val1,
371                         uint32_t val2, const char* str);
372 
373 /*******************************************************************************
374  *
375  * Function         BTA_HfClientDumpStatistics
376  *
377  * Description      Dump statistics about the various control blocks
378  *                  and other relevant connection statistics
379  *
380  * Returns          Void
381  *
382  ******************************************************************************/
383 void BTA_HfClientDumpStatistics(int fd);
384 
385 /*******************************************************************************
386  *
387  * function         get_default_hf_client_features
388  *
389  * description      return the hf_client features.
390  *                  value can be override via system property
391  *
392  * returns          int
393  *
394  ******************************************************************************/
395 int get_default_hf_client_features();
396 #endif /* BTA_HF_CLIENT_API_H */
397