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
29 #include "bta_hf_client_api.h"
30 #include "bta_hf_client_int.h"
31 #include "osi/include/compat.h"
32
33 /*****************************************************************************
34 * External Function Declarations
35 ****************************************************************************/
36
37 /*******************************************************************************
38 *
39 * Function BTA_HfClientEnable
40 *
41 * Description Enable the HF CLient service. It does the following:
42 * 1. Sets the state to initialized (control blocks)
43 * 2. Starts the SDP for the client role (HF)
44 * 3. Starts the RFCOMM server to accept incoming connections
45 * The function is synchronous and returns with an error code
46 * if anything went wrong. This should be the first call to the
47 * API before doing an BTA_HfClientOpen
48 *
49 * Returns BTA_SUCCESS if OK, BTA_FAILURE otherwise.
50 *
51 ******************************************************************************/
BTA_HfClientEnable(tBTA_HF_CLIENT_CBACK * p_cback,tBTA_SEC sec_mask,tBTA_HF_CLIENT_FEAT features,const char * p_service_name)52 tBTA_STATUS BTA_HfClientEnable(tBTA_HF_CLIENT_CBACK* p_cback, tBTA_SEC sec_mask,
53 tBTA_HF_CLIENT_FEAT features,
54 const char* p_service_name) {
55 return bta_hf_client_api_enable(p_cback, sec_mask, features, p_service_name);
56 }
57
58 /*******************************************************************************
59 *
60 * Function BTA_HfClientDisable
61 *
62 * Description Disable the HF Client service
63 *
64 * Returns void
65 *
66 ******************************************************************************/
BTA_HfClientDisable(void)67 void BTA_HfClientDisable(void) { bta_hf_client_api_disable(); }
68
69 /*******************************************************************************
70 *
71 * Function BTA_HfClientOpen
72 *
73 * Description Opens up a RF connection to the remote device and
74 * subsequently set it up for a HF SLC
75 *
76 * Returns void
77 *
78 ******************************************************************************/
BTA_HfClientOpen(BD_ADDR bd_addr,tBTA_SEC sec_mask,uint16_t * p_handle)79 void BTA_HfClientOpen(BD_ADDR bd_addr, tBTA_SEC sec_mask, uint16_t* p_handle) {
80 APPL_TRACE_DEBUG("%s", __func__);
81 tBTA_HF_CLIENT_API_OPEN* p_buf =
82 (tBTA_HF_CLIENT_API_OPEN*)osi_malloc(sizeof(tBTA_HF_CLIENT_API_OPEN));
83
84 if (!bta_hf_client_allocate_handle(bd_addr, p_handle)) {
85 APPL_TRACE_ERROR("%s: could not allocate handle", __func__);
86 return;
87 }
88
89 p_buf->hdr.event = BTA_HF_CLIENT_API_OPEN_EVT;
90 p_buf->hdr.layer_specific = *p_handle;
91 bdcpy(p_buf->bd_addr, bd_addr);
92 p_buf->sec_mask = sec_mask;
93
94 bta_sys_sendmsg(p_buf);
95 }
96
97 /*******************************************************************************
98 *
99 * Function BTA_HfClientClose
100 *
101 * Description Close the current connection to an audio gateway.
102 * Any current audio connection will also be closed
103 *
104 *
105 * Returns void
106 *
107 ******************************************************************************/
BTA_HfClientClose(uint16_t handle)108 void BTA_HfClientClose(uint16_t handle) {
109 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
110
111 p_buf->event = BTA_HF_CLIENT_API_CLOSE_EVT;
112 p_buf->layer_specific = handle;
113
114 bta_sys_sendmsg(p_buf);
115 }
116
117 /*******************************************************************************
118 *
119 * Function BTA_HfCllientAudioOpen
120 *
121 * Description Opens an audio connection to the currently connected
122 * audio gateway
123 *
124 *
125 * Returns void
126 *
127 ******************************************************************************/
BTA_HfClientAudioOpen(uint16_t handle)128 void BTA_HfClientAudioOpen(uint16_t handle) {
129 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
130
131 p_buf->event = BTA_HF_CLIENT_API_AUDIO_OPEN_EVT;
132 p_buf->layer_specific = handle;
133
134 bta_sys_sendmsg(p_buf);
135 }
136
137 /*******************************************************************************
138 *
139 * Function BTA_HfClientAudioClose
140 *
141 * Description Close the currently active audio connection to an audio
142 * gateway. The data connection remains open
143 *
144 *
145 * Returns void
146 *
147 ******************************************************************************/
BTA_HfClientAudioClose(uint16_t handle)148 void BTA_HfClientAudioClose(uint16_t handle) {
149 BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
150
151 p_buf->event = BTA_HF_CLIENT_API_AUDIO_CLOSE_EVT;
152 p_buf->layer_specific = handle;
153
154 bta_sys_sendmsg(p_buf);
155 }
156
157 /*******************************************************************************
158 *
159 * Function BTA_HfClientSendAT
160 *
161 * Description send AT command
162 *
163 *
164 * Returns void
165 *
166 ******************************************************************************/
BTA_HfClientSendAT(uint16_t handle,tBTA_HF_CLIENT_AT_CMD_TYPE at,uint32_t val1,uint32_t val2,const char * str)167 void BTA_HfClientSendAT(uint16_t handle, tBTA_HF_CLIENT_AT_CMD_TYPE at,
168 uint32_t val1, uint32_t val2, const char* str) {
169 tBTA_HF_CLIENT_DATA_VAL* p_buf =
170 (tBTA_HF_CLIENT_DATA_VAL*)osi_malloc(sizeof(tBTA_HF_CLIENT_DATA_VAL));
171
172 p_buf->hdr.event = BTA_HF_CLIENT_SEND_AT_CMD_EVT;
173 p_buf->uint8_val = at;
174 p_buf->uint32_val1 = val1;
175 p_buf->uint32_val2 = val2;
176
177 if (str) {
178 strlcpy(p_buf->str, str, BTA_HF_CLIENT_NUMBER_LEN + 1);
179 p_buf->str[BTA_HF_CLIENT_NUMBER_LEN] = '\0';
180 } else {
181 p_buf->str[0] = '\0';
182 }
183
184 p_buf->hdr.layer_specific = handle;
185
186 bta_sys_sendmsg(p_buf);
187 }
188
189 /*******************************************************************************
190 *
191 * Function BTA_HfClientDumpStatistics
192 *
193 * Description Dump statistics about the various control blocks
194 * and other relevant connection statistics
195 *
196 * Returns Void
197 *
198 ******************************************************************************/
BTA_HfClientDumpStatistics(int fd)199 void BTA_HfClientDumpStatistics(int fd) { bta_hf_client_dump_statistics(fd); }
200