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