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