1 /******************************************************************************
2  *
3  *  Copyright (c) 2014 The Android Open Source Project
4  *  Copyright (C) 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 #include "bta_hfp_defs.h"
30 
31 #if (BTA_HF_INCLUDED == TRUE)
32 /*****************************************************************************
33 **  Constants and data types
34 *****************************************************************************/
35 
36 /* Hands-Free unit(HF) version */
37 #define HFP_HF_VERSION_1_6             0x0106       /* v1.6 */
38 #define HFP_HF_VERSION_1_7             0x0107       /* v1.7 */
39 
40 /* HFP peer (AG) features*/
41 #define BTA_HF_CLIENT_PEER_FEAT_3WAY   0x00000001  /* Three-way calling */
42 #define BTA_HF_CLIENT_PEER_FEAT_ECNR   0x00000002  /* Echo cancellation and/or noise reduction */
43 #define BTA_HF_CLIENT_PEER_FEAT_VREC   0x00000004  /* Voice recognition */
44 #define BTA_HF_CLIENT_PEER_INBAND      0x00000008  /* In-band ring tone */
45 #define BTA_HF_CLIENT_PEER_VTAG        0x00000010  /* Attach a phone number to a voice tag */
46 #define BTA_HF_CLIENT_PEER_REJECT      0x00000020  /* Ability to reject incoming call */
47 #define BTA_HF_CLIENT_PEER_ECS         0x00000040  /* Enhanced Call Status */
48 #define BTA_HF_CLIENT_PEER_ECC         0x00000080  /* Enhanced Call Control */
49 #define BTA_HF_CLIENT_PEER_EXTERR      0x00000100  /* Extended error codes */
50 #define BTA_HF_CLIENT_PEER_CODEC       0x00000200  /* Codec Negotiation */
51 /* HFP 1.7+ */
52 #define BTA_HF_CLIENT_PEER_HF_IND      0x00000400  /* HF Indicators */
53 #define BTA_HF_CLIENT_PEER_ESCO_S4     0x00000800  /* eSCO S4 Setting Supported */
54 
55 typedef UINT16 tBTA_HF_CLIENT_PEER_FEAT;
56 
57 /* HFP HF features */
58 #define BTA_HF_CLIENT_FEAT_ECNR        0x00000001  /* Echo cancellation and/or noise reduction */
59 #define BTA_HF_CLIENT_FEAT_3WAY        0x00000002  /* Call waiting and three-way calling */
60 #define BTA_HF_CLIENT_FEAT_CLI         0x00000004  /* Caller ID presentation capability */
61 #define BTA_HF_CLIENT_FEAT_VREC        0x00000008  /* Voice recognition activation */
62 #define BTA_HF_CLIENT_FEAT_VOL         0x00000010  /* Remote volume control */
63 #define BTA_HF_CLIENT_FEAT_ECS         0x00000020  /* Enhanced Call Status */
64 #define BTA_HF_CLIENT_FEAT_ECC         0x00000040  /* Enhanced Call Control */
65 #define BTA_HF_CLIENT_FEAT_CODEC       0x00000080  /* Codec Negotiation */
66 #define BTA_HF_CLIENT_FEAT_HF_IND      0x00000100  /* HF indicators */
67 #define BTA_HF_CLIENT_FEAT_ESCO_S4     0x00000200  /* eSCO S4 Setting Supported */
68 
69 /* HFP HF extended call handling - masks not related to any spec */
70 #define BTA_HF_CLIENT_CHLD_REL          0x00000001  /* 0  Release waiting call or held calls */
71 #define BTA_HF_CLIENT_CHLD_REL_ACC      0x00000002  /* 1  Release active calls and accept other (waiting or held) cal */
72 #define BTA_HF_CLIENT_CHLD_REL_X        0x00000004  /* 1x Release x call*/
73 #define BTA_HF_CLIENT_CHLD_HOLD_ACC     0x00000008  /* 2  Active calls on hold and accept other call */
74 #define BTA_HF_CLIENT_CHLD_PRIV_X       0x00000010  /* 2x Active multiparty call on hold except call x */
75 #define BTA_HF_CLIENT_CHLD_MERGE        0x00000020  /* 3  Add held call to multiparty */
76 #define BTA_HF_CLIENT_CHLD_MERGE_DETACH 0x00000040  /* 4  Add held call to multiparty */
77 
78 typedef UINT16 tBTA_HF_CLIENT_CHLD_FEAT;
79 
80 /* HFP AG errors ot OK sent to HF Unit */
81 #define BTA_HF_CLIENT_AT_RESULT_OK            0
82 #define BTA_HF_CLIENT_AT_RESULT_ERROR         1
83 #define BTA_HF_CLIENT_AT_RESULT_NO_CARRIER    2
84 #define BTA_HF_CLIENT_AT_RESULT_BUSY          3
85 #define BTA_HF_CLIENT_AT_RESULT_NO_ANSWER     4
86 #define BTA_HF_CLIENT_AT_RESULT_DELAY         5
87 #define BTA_HF_CLIENT_AT_RESULT_BLACKLISTED   6
88 #define BTA_HF_CLIENT_AT_RESULT_CME           7
89 
90 typedef UINT8 tBTA_HF_CLIENT_AT_RESULT_TYPE;
91 
92 /* HF Client callback events */
93 #define BTA_HF_CLIENT_ENABLE_EVT            0  /* HF Client enabled */
94 #define BTA_HF_CLIENT_REGISTER_EVT          1  /* HF Client registered */
95 #define BTA_HF_CLIENT_OPEN_EVT              2  /* HF Client connection open */
96 #define BTA_HF_CLIENT_CLOSE_EVT             3  /* HF Client connection closed */
97 #define BTA_HF_CLIENT_CONN_EVT              4  /* Service level connection opened */
98 #define BTA_HF_CLIENT_AUDIO_OPEN_EVT        5  /* Audio connection open */
99 #define BTA_HF_CLIENT_AUDIO_MSBC_OPEN_EVT   6  /* Audio connection with mSBC codec open */
100 #define BTA_HF_CLIENT_AUDIO_CLOSE_EVT       7  /* Audio connection closed */
101 #define BTA_HF_CLIENT_SPK_EVT               8  /* Speaker volume changed */
102 #define BTA_HF_CLIENT_MIC_EVT               9  /* Microphone volume changed */
103 #define BTA_HF_CLIENT_IND_EVT               10 /* Indicator */
104 #define BTA_HF_CLIENT_VOICE_REC_EVT         11 /* AG changed voice recognition setting */
105 #define BTA_HF_CLIENT_OPERATOR_NAME_EVT     12 /* Operator name acquired */
106 #define BTA_HF_CLIENT_CLIP_EVT              13 /* Calling line identification event */
107 #define BTA_HF_CLIENT_CCWA_EVT              14 /* Call waiting notification */
108 #define BTA_HF_CLIENT_AT_RESULT_EVT         15 /* Call waiting notification */
109 #define BTA_HF_CLIENT_CLCC_EVT              16 /* current call event */
110 #define BTA_HF_CLIENT_CNUM_EVT              17 /* subscriber information event */
111 #define BTA_HF_CLIENT_BTRH_EVT              18 /* bluetooth response and hold event */
112 #define BTA_HF_CLIENT_BSIR_EVT              19 /* in-band ring tone setting changed event */
113 #define BTA_HF_CLIENT_BINP_EVT              20 /* binp number event */
114 #define BTA_HF_CLIENT_RING_INDICATION       21 /* HF Client ring indication */
115 #define BTA_HF_CLIENT_DISABLE_EVT           22 /* HF Client disabled */
116 #define BTA_HF_CLIENT_PKT_STAT_NUMS_GET_EVT 23 /* HF Client packet status nums */
117 
118 typedef UINT8 tBTA_HF_CLIENT_EVT;
119 
120 /* HF Client open status */
121 #define BTA_HF_CLIENT_SUCCESS          0 /* Connection successfully opened */
122 #define BTA_HF_CLIENT_FAIL_SDP         1 /* Open failed due to SDP */
123 #define BTA_HF_CLIENT_FAIL_RFCOMM      2 /* Open failed due to RFCOMM */
124 #define BTA_HF_CLIENT_FAIL_RESOURCES   3 /* out of resources failure  */
125 
126 typedef UINT8 tBTA_HF_CLIENT_STATUS;
127 
128 /* indicator constants HFP 1.1 and later */
129 #define BTA_HF_CLIENT_IND_CALL             0   /* position of call indicator */
130 #define BTA_HF_CLIENT_IND_CALLSETUP        1   /* position of callsetup indicator */
131 #define BTA_HF_CLIENT_IND_SERVICE          2   /* position of service indicator */
132 /* indicator constants HFP 1.5 and later */
133 #define BTA_HF_CLIENT_IND_SIGNAL           3   /* position of signal strength indicator */
134 #define BTA_HF_CLIENT_IND_ROAM             4   /* position of roaming indicator */
135 #define BTA_HF_CLIENT_IND_BATTCH           5   /* position of battery charge indicator */
136 #define BTA_HF_CLIENT_IND_CALLHELD         6   /* position of callheld indicator */
137 #define BTA_HF_CLIENT_IND_BEARER           7   /* position of bearer indicator */
138 typedef UINT8 tBTA_HF_CLIENT_IND_TYPE;
139 
140 /* AT commands */
141 #define BTA_HF_CLIENT_AT_CMD_VTS    0
142 #define BTA_HF_CLIENT_AT_CMD_BTRH   1
143 #define BTA_HF_CLIENT_AT_CMD_CHUP   2
144 #define BTA_HF_CLIENT_AT_CMD_CHLD   3
145 #define BTA_HF_CLIENT_AT_CMD_BCC    4
146 #define BTA_HF_CLIENT_AT_CMD_CNUM   5
147 #define BTA_HF_CLIENT_AT_CMD_ATA    6
148 #define BTA_HF_CLIENT_AT_CMD_COPS   7
149 #define BTA_HF_CLIENT_AT_CMD_ATD    8
150 #define BTA_HF_CLIENT_AT_CMD_VGM    9
151 #define BTA_HF_CLIENT_AT_CMD_VGS    10
152 #define BTA_HF_CLIENT_AT_CMD_BVRA   11
153 #define BTA_HF_CLIENT_AT_CMD_CLCC   12
154 #define BTA_HF_CLIENT_AT_CMD_BINP   13
155 #define BTA_HF_CLIENT_AT_CMD_BLDN   14
156 #define BTA_HF_CLIENT_AT_CMD_NREC   15
157 #define BTA_HF_CLIENT_AT_CMD_XAPL   16
158 #define BTA_HF_CLIENT_AT_CMD_IPHONEACCEV   17
159 
160 typedef UINT8 tBTA_HF_CLIENT_AT_CMD_TYPE;
161 
162 #define BTA_HF_CLIENT_MAX_LEN 32
163 
164 /* data associated with most non-AT events */
165 /* placeholder, if not needed should be removed*/
166 typedef struct {
167     UINT16       sync_conn_handle;
168 } tBTA_HF_CLIENT_HDR;
169 
170 /* data associated with BTA_HF_CLIENT_REGISTER_EVT */
171 typedef struct {
172     tBTA_HF_CLIENT_HDR      hdr;
173     UINT16                  handle;
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     tBTA_HF_CLIENT_HDR      hdr;
180     BD_ADDR                 bd_addr;
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     tBTA_HF_CLIENT_HDR         hdr;
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     tBTA_HF_CLIENT_HDR         hdr;
194     tBTA_HF_CLIENT_IND_TYPE    type;
195     UINT16                     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     char                       name[BTA_HF_CLIENT_OPERATOR_NAME_LEN + 1];
202 } tBTA_HF_CLIENT_OPERATOR_NAME;
203 
204 /* data associated with BTA_HF_CLIENT_CLIP_EVT  and BTA_HF_CLIENT_CCWA_EVT*/
205 #define BTA_HF_CLIENT_NUMBER_LEN 32
206 typedef struct {
207     char                       number[BTA_HF_CLIENT_NUMBER_LEN + 1];
208 } tBTA_HF_CLIENT_NUMBER;
209 
210 /* data associated with BTA_HF_CLIENT_AT_RESULT_EVT event */
211 typedef struct {
212     tBTA_HF_CLIENT_AT_RESULT_TYPE    type;
213     UINT16                           cme;
214 } tBTA_HF_CLIENT_AT_RESULT;
215 
216 /* data associated with BTA_HF_CLIENT_CLCC_EVT event */
217 typedef struct {
218     UINT32                     idx;
219     BOOLEAN                    inc;
220     UINT8                      status;
221     BOOLEAN                    mpty;
222     BOOLEAN                    number_present;
223     char                       number[BTA_HF_CLIENT_NUMBER_LEN + 1];
224 } tBTA_HF_CLIENT_CLCC;
225 
226 /* data associated with BTA_HF_CLIENT_CNUM_EVT event */
227 typedef struct {
228     UINT16                     service;
229     char                       number[BTA_HF_CLIENT_NUMBER_LEN + 1];
230 } tBTA_HF_CLIENT_CNUM;
231 
232 /* data associated with other events */
233 typedef struct {
234     UINT16                     value;
235 } tBTA_HF_CLIENT_VAL;
236 
237 /* data associated with BTA_HF_CLIENT_PKT_STAT_NUMS_GET_EVT */
238 typedef struct {
239     UINT32 rx_total;
240     UINT32 rx_correct;
241     UINT32 rx_err;
242     UINT32 rx_none;
243     UINT32 rx_lost;
244     UINT32 tx_total;
245     UINT32 tx_discarded;
246 } tBTA_SCO_PKT_STAT_NUMS;
247 
248 /* union of data associated with AG callback */
249 typedef union {
250     tBTA_HF_CLIENT_HDR              hdr;
251     tBTA_HF_CLIENT_REGISTER         reg;
252     tBTA_HF_CLIENT_OPEN             open;
253     tBTA_HF_CLIENT_CONN             conn;
254     tBTA_HF_CLIENT_IND              ind;
255     tBTA_HF_CLIENT_VAL              val;
256     tBTA_HF_CLIENT_OPERATOR_NAME    operator;
257     tBTA_HF_CLIENT_NUMBER           number;
258     tBTA_HF_CLIENT_AT_RESULT        result;
259     tBTA_HF_CLIENT_CLCC             clcc;
260     tBTA_HF_CLIENT_CNUM             cnum;
261     tBTA_SCO_PKT_STAT_NUMS          pkt_num;
262 } tBTA_HF_CLIENT;
263 
264 typedef UINT32 tBTA_HF_CLIENT_FEAT;
265 
266 /* HF Client callback */
267 typedef void (tBTA_HF_CLIENT_CBACK)(tBTA_HF_CLIENT_EVT event, void *p_data);
268 
269 #ifdef __cplusplus
270 extern "C"
271 {
272 #endif
273 
274 /*****************************************************************************
275 **  External Function Declarations
276 *****************************************************************************/
277 
278 /*******************************************************************************
279 **
280 ** Function         BTA_HfClientEnable
281 **
282 ** Description      Enable the HF CLient service. When the enable
283 **                  operation is complete the callback function will be
284 **                  called with a BTA_HF_CLIENT_ENABLE_EVT. This function must
285 **                  be called before other function in the HF CLient API are
286 **                  called.
287 **
288 ** Returns          BTA_SUCCESS if OK, BTA_FAILURE otherwise.
289 **
290 *******************************************************************************/
291 tBTA_STATUS BTA_HfClientEnable(tBTA_HF_CLIENT_CBACK *p_cback);
292 
293 /*******************************************************************************
294 **
295 ** Function         BTA_HfClientDisable
296 **
297 ** Description      Disable the HF Client service
298 **
299 **
300 ** Returns          void
301 **
302 *******************************************************************************/
303 void BTA_HfClientDisable(void);
304 
305 /*******************************************************************************
306 **
307 ** Function         BTA_HfClientRegister
308 **
309 ** Description      Register an HF Client service.
310 **
311 **
312 ** Returns          void
313 **
314 *******************************************************************************/
315 void BTA_HfClientRegister(tBTA_SEC sec_mask, tBTA_HF_CLIENT_FEAT features,
316                           char *p_service_name);
317 
318 /*******************************************************************************
319 **
320 ** Function         BTA_HfClientDeregister
321 **
322 ** Description      Deregister an HF Client service.
323 **
324 **
325 ** Returns          void
326 **
327 *******************************************************************************/
328 void BTA_HfClientDeregister(UINT16 handle);
329 
330 /*******************************************************************************
331 **
332 ** Function         BTA_HfClientOpen
333 **
334 ** Description      Opens a connection to an audio gateway.
335 **                  When connection is open callback function is called
336 **                  with a BTA_HF_CLIENT_OPEN_EVT. Only the data connection is
337 **                  opened. The audio connection is not opened.
338 **
339 **
340 ** Returns          void
341 **
342 *******************************************************************************/
343 void BTA_HfClientOpen(UINT16 handle, BD_ADDR bd_addr, tBTA_SEC sec_mask);
344 
345 /*******************************************************************************
346 **
347 ** Function         BTA_HfClientClose
348 **
349 ** Description      Close the current connection to an audio gateway.
350 **                  Any current audio connection will also be closed
351 **
352 **
353 ** Returns          void
354 **
355 *******************************************************************************/
356 void BTA_HfClientClose(UINT16 handle);
357 
358 /*******************************************************************************
359 **
360 ** Function         BTA_HfCllientAudioOpen
361 **
362 ** Description      Opens an audio connection to the currently connected
363 **                 audio gateway
364 **
365 **
366 ** Returns          void
367 **
368 *******************************************************************************/
369 void BTA_HfClientAudioOpen(UINT16 handle);
370 
371 /*******************************************************************************
372 **
373 ** Function         BTA_HfClientAudioClose
374 **
375 ** Description      Close the currently active audio connection to an audio
376 **                  gateway. The data connection remains open
377 **
378 **
379 ** Returns          void
380 **
381 *******************************************************************************/
382 void BTA_HfClientAudioClose(UINT16 handle);
383 
384 /*******************************************************************************
385 **
386 ** Function         BTA_HfClientSendAT
387 **
388 ** Description      send AT command
389 **
390 **
391 ** Returns          void
392 **
393 *******************************************************************************/
394 void BTA_HfClientSendAT(UINT16 handle, tBTA_HF_CLIENT_AT_CMD_TYPE at, UINT32 val1, UINT32 val2, const char *str);
395 
396 #if (BTM_SCO_HCI_INCLUDED == TRUE )
397 /*******************************************************************************
398 **
399 ** Function         BTA_HfClientPktStatsNumsGet
400 **
401 ** Description      Get the Number of packets status received and send
402 **
403 **
404 ** Returns          void
405 **
406 *******************************************************************************/
407 void BTA_HfClientPktStatsNumsGet(UINT16 sync_conn_handle);
408 
409 void BTA_HfClientCiData(void);
410 #endif /*#if (BTM_SCO_HCI_INCLUDED == TRUE ) */
411 
412 int BTA_HfClientGetCbDataSize(tBTA_HF_CLIENT_EVT event);
413 
414 #ifdef __cplusplus
415 }
416 #endif
417 #endif /* #if (BTA_HF_INCLUDED == TRUE) */
418 #endif /* BTA_HF_CLIENT_API_H */
419