• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 implementation of the API for the handsfree (HF role)
23  *  subsystem of BTA
24  *
25  ******************************************************************************/
26 
27 #include <string.h>
28 #include "bta_hf_client_api.h"
29 #include "bta_hf_client_int.h"
30 #include "bd.h"
31 
32 /*****************************************************************************
33 **  Constants and data types
34 *****************************************************************************/
35 static const tBTA_SYS_REG bta_hf_client_reg =
36 {
37     bta_hf_client_hdl_event,
38     BTA_HfClientDisable
39 };
40 
41 
42 /*****************************************************************************
43 **  External Function Declarations
44 *****************************************************************************/
45 
46 /*******************************************************************************
47 **
48 ** Function         BTA_HfClientEnable
49 **
50 ** Description      Enable the HF CLient service. When the enable
51 **                  operation is complete the callback function will be
52 **                  called with a BTA_HF_CLIENT_ENABLE_EVT. This function must
53 **                  be called before other function in the HF CLient API are
54 **                  called.
55 **
56 ** Returns          BTA_SUCCESS if OK, BTA_FAILURE otherwise.
57 **
58 *******************************************************************************/
BTA_HfClientEnable(tBTA_HF_CLIENT_CBACK * p_cback)59 BTA_API tBTA_STATUS BTA_HfClientEnable(tBTA_HF_CLIENT_CBACK *p_cback)
60 {
61     tBTA_HF_CLIENT_API_ENABLE  *p_buf;
62     UINT8       idx;
63 
64     if (bta_sys_is_register (BTA_ID_HS))
65     {
66         APPL_TRACE_ERROR("BTA HF Client is already enabled, ignoring ...");
67         return BTA_FAILURE;
68     }
69 
70     /* register with BTA system manager */
71     bta_sys_register(BTA_ID_HS, &bta_hf_client_reg);
72 
73     if ((p_buf = (tBTA_HF_CLIENT_API_ENABLE *) GKI_getbuf(sizeof(tBTA_HF_CLIENT_API_ENABLE))) != NULL)
74     {
75         p_buf->hdr.event = BTA_HF_CLIENT_API_ENABLE_EVT;
76         p_buf->p_cback = p_cback;
77         bta_sys_sendmsg(p_buf);
78     }
79 
80     return BTA_SUCCESS;
81 }
82 
83 /*******************************************************************************
84 **
85 ** Function         BTA_HfClientDisable
86 **
87 ** Description      Disable the HF Client service
88 **
89 **
90 ** Returns          void
91 **
92 *******************************************************************************/
BTA_HfClientDisable(void)93 BTA_API void BTA_HfClientDisable(void)
94 {
95     BT_HDR  *p_buf;
96 
97     if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
98     {
99         p_buf->event = BTA_HF_CLIENT_API_DISABLE_EVT;
100         bta_sys_sendmsg(p_buf);
101     }
102 }
103 
104 /*******************************************************************************
105 **
106 ** Function         BTA_HfClientRegister
107 **
108 ** Description      Register an HF Client service.
109 **
110 **
111 ** Returns          void
112 **
113 *******************************************************************************/
BTA_HfClientRegister(tBTA_SEC sec_mask,tBTA_HF_CLIENT_FEAT features,char * p_service_name)114 BTA_API void BTA_HfClientRegister(tBTA_SEC sec_mask, tBTA_HF_CLIENT_FEAT features,
115                                                         char *p_service_name)
116 {
117     tBTA_HF_CLIENT_API_REGISTER    *p_buf;
118 
119     if ((p_buf = (tBTA_HF_CLIENT_API_REGISTER *) GKI_getbuf(sizeof(tBTA_HF_CLIENT_API_REGISTER))) != NULL)
120     {
121         p_buf->hdr.event = BTA_HF_CLIENT_API_REGISTER_EVT;
122         p_buf->features = features;
123         p_buf->sec_mask = sec_mask;
124         if(p_service_name)
125         {
126             BCM_STRNCPY_S(p_buf->name, BTA_SERVICE_NAME_LEN+1, p_service_name, BTA_SERVICE_NAME_LEN);
127             p_buf->name[BTA_SERVICE_NAME_LEN] = 0;
128         }
129         else
130         {
131             p_buf->name[0] = '\0';
132         }
133         bta_sys_sendmsg(p_buf);
134     }
135 }
136 
137 /*******************************************************************************
138 **
139 ** Function         BTA_HfClientDeregister
140 **
141 ** Description      Deregister an HF Client service.
142 **
143 **
144 ** Returns          void
145 **
146 *******************************************************************************/
BTA_HfClientDeregister(UINT16 handle)147 BTA_API void BTA_HfClientDeregister(UINT16 handle)
148 {
149     BT_HDR  *p_buf;
150 
151      if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
152      {
153          p_buf->event = BTA_HF_CLIENT_API_DEREGISTER_EVT;
154          p_buf->layer_specific = handle;
155          bta_sys_sendmsg(p_buf);
156      }
157 }
158 
159 /*******************************************************************************
160 **
161 ** Function         BTA_HfClientOpen
162 **
163 ** Description      Opens a connection to an audio gateway.
164 **                  When connection is open callback function is called
165 **                  with a BTA_AG_OPEN_EVT. Only the data connection is
166 **                  opened. The audio connection is not opened.
167 **
168 **
169 ** Returns          void
170 **
171 *******************************************************************************/
BTA_HfClientOpen(UINT16 handle,BD_ADDR bd_addr,tBTA_SEC sec_mask)172 BTA_API void BTA_HfClientOpen(UINT16 handle, BD_ADDR bd_addr, tBTA_SEC sec_mask)
173 {
174     tBTA_HF_CLIENT_API_OPEN  *p_buf;
175 
176     if ((p_buf = (tBTA_HF_CLIENT_API_OPEN *) GKI_getbuf(sizeof(tBTA_HF_CLIENT_API_OPEN))) != NULL)
177     {
178         p_buf->hdr.event = BTA_HF_CLIENT_API_OPEN_EVT;
179         p_buf->hdr.layer_specific = handle;
180         bdcpy(p_buf->bd_addr, bd_addr);
181         p_buf->sec_mask = sec_mask;
182         bta_sys_sendmsg(p_buf);
183     }
184 }
185 
186 /*******************************************************************************
187 **
188 ** Function         BTA_HfClientClose
189 **
190 ** Description      Close the current connection to an audio gateway.
191 **                  Any current audio connection will also be closed
192 **
193 **
194 ** Returns          void
195 **
196 *******************************************************************************/
BTA_HfClientClose(UINT16 handle)197 BTA_API void BTA_HfClientClose(UINT16 handle)
198 {
199     BT_HDR  *p_buf;
200 
201     if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
202     {
203         p_buf->event = BTA_HF_CLIENT_API_CLOSE_EVT;
204         p_buf->layer_specific = handle;
205         bta_sys_sendmsg(p_buf);
206     }
207 }
208 
209 /*******************************************************************************
210 **
211 ** Function         BTA_HfCllientAudioOpen
212 **
213 ** Description      Opens an audio connection to the currently connected
214 **                 audio gateway
215 **
216 **
217 ** Returns          void
218 **
219 *******************************************************************************/
BTA_HfClientAudioOpen(UINT16 handle)220 BTA_API void BTA_HfClientAudioOpen(UINT16 handle)
221 {
222     BT_HDR  *p_buf;
223 
224     if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
225     {
226         p_buf->event = BTA_HF_CLIENT_API_AUDIO_OPEN_EVT;
227         p_buf->layer_specific = handle;
228         bta_sys_sendmsg(p_buf);
229     }
230 }
231 
232 /*******************************************************************************
233 **
234 ** Function         BTA_HfClientAudioClose
235 **
236 ** Description      Close the currently active audio connection to an audio
237 **                  gateway. The data connection remains open
238 **
239 **
240 ** Returns          void
241 **
242 *******************************************************************************/
BTA_HfClientAudioClose(UINT16 handle)243 BTA_API void BTA_HfClientAudioClose(UINT16 handle)
244 {
245     BT_HDR  *p_buf;
246 
247     if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
248     {
249         p_buf->event = BTA_HF_CLIENT_API_AUDIO_CLOSE_EVT;
250         p_buf->layer_specific = handle;
251         bta_sys_sendmsg(p_buf);
252     }
253 }
254 
255 /*******************************************************************************
256 **
257 ** Function         BTA_HfClientSendAT
258 **
259 ** Description      send AT command
260 **
261 **
262 ** Returns          void
263 **
264 *******************************************************************************/
BTA_HfClientSendAT(UINT16 handle,tBTA_HF_CLIENT_AT_CMD_TYPE at,UINT32 val1,UINT32 val2,const char * str)265 BTA_API void BTA_HfClientSendAT(UINT16 handle, tBTA_HF_CLIENT_AT_CMD_TYPE at, UINT32 val1, UINT32 val2, const char *str)
266 {
267     tBTA_HF_CLIENT_DATA_VAL  *p_buf;
268 
269     if ((p_buf = (tBTA_HF_CLIENT_DATA_VAL *) GKI_getbuf(sizeof(tBTA_HF_CLIENT_DATA_VAL))) != NULL)
270     {
271         p_buf->hdr.event = BTA_HF_CLIENT_SEND_AT_CMD_EVT;
272         p_buf->uint8_val = at;
273         p_buf->uint32_val1 = val1;
274         p_buf->uint32_val2 = val2;
275 
276         if (str)
277         {
278             strlcpy(p_buf->str, str, BTA_HF_CLIENT_NUMBER_LEN + 1);
279             p_buf->str[BTA_HF_CLIENT_NUMBER_LEN] = '\0';
280         }
281         else
282         {
283             p_buf->str[0] = '\0';
284         }
285 
286         p_buf->hdr.layer_specific = handle;
287         bta_sys_sendmsg(p_buf);
288     }
289 }
290