• 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 #define BTA_HF_CLIENT_AT_CMD_ANDROID 18
176 
177 typedef uint8_t tBTA_HF_CLIENT_AT_CMD_TYPE;
178 
179 /* data associated with BTA_HF_CLIENT_REGISTER_EVT */
180 typedef struct {
181   RawAddress bd_addr;
182   tBTA_HF_CLIENT_STATUS status;
183 } tBTA_HF_CLIENT_REGISTER;
184 
185 /* data associated with BTA_HF_CLIENT_OPEN_EVT */
186 typedef struct {
187   RawAddress bd_addr;
188   uint16_t handle;  // Handle for client control block
189   tBTA_HF_CLIENT_STATUS status;
190 } tBTA_HF_CLIENT_OPEN;
191 
192 /* data associated with BTA_HF_CLIENT_CONN_EVT */
193 typedef struct {
194   RawAddress bd_addr;
195   tBTA_HF_CLIENT_PEER_FEAT peer_feat;
196   tBTA_HF_CLIENT_CHLD_FEAT chld_feat;
197 } tBTA_HF_CLIENT_CONN;
198 
199 /* data associated with BTA_HF_CLIENT_IND_EVT event */
200 typedef struct {
201   RawAddress bd_addr;
202   tBTA_HF_CLIENT_IND_TYPE type;
203   uint16_t value;
204 } tBTA_HF_CLIENT_IND;
205 
206 /* data associated with BTA_HF_CLIENT_OPERATOR_NAME_EVT */
207 #define BTA_HF_CLIENT_OPERATOR_NAME_LEN 16
208 typedef struct {
209   RawAddress bd_addr;
210   char name[BTA_HF_CLIENT_OPERATOR_NAME_LEN + 1];
211 } tBTA_HF_CLIENT_OPERATOR_NAME;
212 
213 /* data associated with BTA_HF_CLIENT_CLIP_EVT  and BTA_HF_CLIENT_CCWA_EVT*/
214 #define BTA_HF_CLIENT_NUMBER_LEN 32
215 typedef struct {
216   RawAddress bd_addr;
217   char number[BTA_HF_CLIENT_NUMBER_LEN + 1];
218 } tBTA_HF_CLIENT_NUMBER;
219 
220 /* data associated with BTA_HF_CLIENT_AT_RESULT_EVT event */
221 typedef struct {
222   RawAddress bd_addr;
223   tBTA_HF_CLIENT_AT_RESULT_TYPE type;
224   uint16_t cme;
225 } tBTA_HF_CLIENT_AT_RESULT;
226 
227 /* data associated with BTA_HF_CLIENT_CLCC_EVT event */
228 typedef struct {
229   RawAddress bd_addr;
230   uint32_t idx;
231   bool inc;
232   uint8_t status;
233   bool mpty;
234   bool number_present;
235   char number[BTA_HF_CLIENT_NUMBER_LEN + 1];
236 } tBTA_HF_CLIENT_CLCC;
237 
238 /* data associated with BTA_HF_CLIENT_CNUM_EVT event */
239 typedef struct {
240   RawAddress bd_addr;
241   uint16_t service;
242   char number[BTA_HF_CLIENT_NUMBER_LEN + 1];
243 } tBTA_HF_CLIENT_CNUM;
244 
245 /* data associated with other events */
246 typedef struct {
247   RawAddress bd_addr;
248   uint16_t value;
249 } tBTA_HF_CLIENT_VAL;
250 
251 /* data associated with BTA_HF_CLIENT_UNKNOWN_EVT event */
252 #define BTA_HF_CLIENT_UNKOWN_EVENT_LEN 32
253 typedef struct {
254   RawAddress bd_addr;
255   char event_string[BTA_HF_CLIENT_UNKOWN_EVENT_LEN + 1];
256 } tBTA_HF_CLIENT_UNKNOWN;
257 
258 /* union of data associated with AG callback */
259 typedef union {
260   // Common BD ADDR field for all tyepdefs
261   RawAddress bd_addr;
262   tBTA_HF_CLIENT_REGISTER reg;
263   tBTA_HF_CLIENT_OPEN open;
264   tBTA_HF_CLIENT_CONN conn;
265   tBTA_HF_CLIENT_IND ind;
266   tBTA_HF_CLIENT_VAL val;
267   tBTA_HF_CLIENT_OPERATOR_NAME operator_name;
268   tBTA_HF_CLIENT_NUMBER number;
269   tBTA_HF_CLIENT_AT_RESULT result;
270   tBTA_HF_CLIENT_CLCC clcc;
271   tBTA_HF_CLIENT_CNUM cnum;
272   tBTA_HF_CLIENT_UNKNOWN unknown;
273 } tBTA_HF_CLIENT;
274 
275 typedef uint32_t tBTA_HF_CLIENT_FEAT;
276 
277 /* HF Client callback */
278 typedef void(tBTA_HF_CLIENT_CBACK)(tBTA_HF_CLIENT_EVT event,
279                                    tBTA_HF_CLIENT* p_data);
280 
281 /*****************************************************************************
282  *  External Function Declarations
283  ****************************************************************************/
284 
285 /*******************************************************************************
286  *
287  * Function         BTA_HfClientEnable
288  *
289  * Description      Enable the HF CLient service. When the enable
290  *                  operation is complete the callback function will be
291  *                  called with a BTA_HF_CLIENT_ENABLE_EVT. This function must
292  *                  be called before other function in the HF CLient API are
293  *                  called.
294  *
295  * Returns          BTA_SUCCESS if OK, BTA_FAILURE otherwise.
296  *
297  ******************************************************************************/
298 tBTA_STATUS BTA_HfClientEnable(tBTA_HF_CLIENT_CBACK* p_cback,
299                                tBTA_HF_CLIENT_FEAT features,
300                                const char* p_service_name);
301 
302 /*******************************************************************************
303  *
304  * Function         BTA_HfClientDisable
305  *
306  * Description      Disable the HF Client service.
307  *
308  * Returns          void
309  *
310  ******************************************************************************/
311 void BTA_HfClientDisable(void);
312 
313 /*******************************************************************************
314  *
315  * Function         BTA_HfClientOpen
316  *
317  * Description      Opens a connection to an audio gateway.
318  *                  When connection is open callback function is called
319  *                  with a BTA_HF_CLIENT_OPEN_EVT. Only the data connection is
320  *                  opened. The audio connection is not opened. The handle
321  *                  is stored in p_handle and should be used for subsequent
322  *                  calls to do any AT operations
323  *
324  *
325  * Returns          bt_status_t
326  *
327  ******************************************************************************/
328 bt_status_t BTA_HfClientOpen(const RawAddress& bd_addr, uint16_t* p_handle);
329 
330 /*******************************************************************************
331  *
332  * Function         BTA_HfClientClose
333  *
334  * Description      Close the current connection to an audio gateway.
335  *                  Any current audio connection will also be closed
336  *
337  *
338  * Returns          void
339  *
340  ******************************************************************************/
341 void BTA_HfClientClose(uint16_t handle);
342 
343 /*******************************************************************************
344  *
345  * Function         BTA_HfCllientAudioOpen
346  *
347  * Description      Opens an audio connection to the currently connected
348  *                 audio gateway
349  *
350  *
351  * Returns          void
352  *
353  ******************************************************************************/
354 void BTA_HfClientAudioOpen(uint16_t handle);
355 
356 /*******************************************************************************
357  *
358  * Function         BTA_HfClientAudioClose
359  *
360  * Description      Close the currently active audio connection to an audio
361  *                  gateway. The data connection remains open
362  *
363  *
364  * Returns          void
365  *
366  ******************************************************************************/
367 void BTA_HfClientAudioClose(uint16_t handle);
368 
369 /*******************************************************************************
370  *
371  * Function         BTA_HfClientSendAT
372  *
373  * Description      send AT command
374  *
375  *
376  * Returns          void
377  *
378  ******************************************************************************/
379 void BTA_HfClientSendAT(uint16_t handle, tBTA_HF_CLIENT_AT_CMD_TYPE at,
380                         uint32_t val1, uint32_t val2, const char* str);
381 
382 /*******************************************************************************
383  *
384  * Function         BTA_HfClientDumpStatistics
385  *
386  * Description      Dump statistics about the various control blocks
387  *                  and other relevant connection statistics
388  *
389  * Returns          Void
390  *
391  ******************************************************************************/
392 void BTA_HfClientDumpStatistics(int fd);
393 
394 /*******************************************************************************
395  *
396  * function         get_default_hf_client_features
397  *
398  * description      return the hf_client features.
399  *                  value can be override via system property
400  *
401  * returns          int
402  *
403  ******************************************************************************/
404 int get_default_hf_client_features();
405 #endif /* BTA_HF_CLIENT_API_H */
406