1 // Copyright 2019 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <stdint.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <stdlib.h>
19 #include <assert.h>
20 #include "bt_common.h"
21 #include "btc/btc_common.h"
22 #include "btc/btc_dm.h"
23 #include "btc_hf_ag.h"
24 #include "btc/btc_profile_queue.h"
25 #include "btc/btc_manage.h"
26 #include "btc/btc_util.h"
27 #include "bta/bta_ag_api.h"
28 #include "bta/bta_api.h"
29 #include "common/bt_target.h"
30 #include "common/bt_defs.h"
31 #include "device/bdaddr.h"
32 #include "esp_bt.h"
33 #include "esp_hf_ag_api.h"
34 #include "esp_err.h"
35 #include "esp_bt_main.h"
36 #include "osi/allocator.h"
37
38 #if (BTC_HF_INCLUDED == TRUE)
esp_bt_hf_register_callback(esp_hf_cb_t callback)39 esp_err_t esp_bt_hf_register_callback(esp_hf_cb_t callback)
40 {
41 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
42 return ESP_ERR_INVALID_STATE;
43 }
44 if (callback == NULL) {
45 return ESP_FAIL;
46 }
47 btc_profile_cb_set(BTC_PID_HF, callback);
48 return ESP_OK;
49 }
50
esp_bt_hf_init(esp_bd_addr_t remote_addr)51 esp_err_t esp_bt_hf_init(esp_bd_addr_t remote_addr)
52 {
53 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
54 return ESP_ERR_INVALID_STATE;
55 }
56 btc_msg_t msg;
57 msg.sig = BTC_SIG_API_CALL;
58 msg.pid = BTC_PID_HF;
59 msg.act = BTC_HF_INIT_EVT;
60
61 btc_hf_args_t arg;
62 memset(&arg, 0, sizeof(btc_hf_args_t));
63 memcpy(&(arg.init), remote_addr, sizeof(esp_bd_addr_t));
64
65 /* Switch to BTC context */
66 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
67 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
68 }
69
esp_bt_hf_deinit(esp_bd_addr_t remote_addr)70 esp_err_t esp_bt_hf_deinit(esp_bd_addr_t remote_addr)
71 {
72 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
73 return ESP_ERR_INVALID_STATE;
74 }
75 btc_msg_t msg;
76 msg.sig = BTC_SIG_API_CALL;
77 msg.pid = BTC_PID_HF;
78 msg.act = BTC_HF_DEINIT_EVT;
79
80 btc_hf_args_t arg;
81 memset(&arg, 0, sizeof(btc_hf_args_t));
82 memcpy(&(arg.deinit), remote_addr, sizeof(esp_bd_addr_t));
83
84 /* Switch to BTC context */
85 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
86 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
87 }
88
esp_bt_hf_connect(esp_bd_addr_t remote_addr)89 esp_err_t esp_bt_hf_connect(esp_bd_addr_t remote_addr)
90 {
91 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
92 return ESP_ERR_INVALID_STATE;
93 }
94 btc_msg_t msg;
95 msg.sig = BTC_SIG_API_CALL;
96 msg.pid = BTC_PID_HF;
97 msg.act = BTC_HF_CONNECT_EVT;
98
99 btc_hf_args_t arg;
100 memset(&arg, 0, sizeof(btc_hf_args_t));
101 memcpy(&(arg.connect), remote_addr, sizeof(esp_bd_addr_t));
102
103 /* Switch to BTC context */
104 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
105 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
106 }
107
esp_bt_hf_disconnect(esp_bd_addr_t remote_addr)108 esp_err_t esp_bt_hf_disconnect(esp_bd_addr_t remote_addr)
109 {
110 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
111 return ESP_ERR_INVALID_STATE;
112 }
113 btc_msg_t msg;
114 msg.sig = BTC_SIG_API_CALL;
115 msg.pid = BTC_PID_HF;
116 msg.act = BTC_HF_DISCONNECT_EVT;
117
118 btc_hf_args_t arg;
119 memset(&arg, 0, sizeof(btc_hf_args_t));
120 memcpy(&(arg.disconnect), remote_addr, sizeof(esp_bd_addr_t));
121
122 /* Switch to BTC context */
123 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
124 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
125 }
126
esp_bt_hf_connect_audio(esp_bd_addr_t remote_addr)127 esp_err_t esp_bt_hf_connect_audio(esp_bd_addr_t remote_addr)
128 {
129 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
130 return ESP_ERR_INVALID_STATE;
131 }
132 btc_msg_t msg;
133 msg.sig = BTC_SIG_API_CALL;
134 msg.pid = BTC_PID_HF;
135 msg.act = BTC_HF_CONNECT_AUDIO_EVT;
136
137 btc_hf_args_t arg;
138 memset(&arg, 0, sizeof(btc_hf_args_t));
139 memcpy(&(arg.connect_audio), remote_addr, sizeof(esp_bd_addr_t));
140
141 /* Switch to BTC context */
142 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
143 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
144 }
145
esp_bt_hf_disconnect_audio(esp_bd_addr_t remote_addr)146 esp_err_t esp_bt_hf_disconnect_audio(esp_bd_addr_t remote_addr)
147 {
148 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
149 return ESP_ERR_INVALID_STATE;
150 }
151 btc_msg_t msg;
152 msg.sig = BTC_SIG_API_CALL;
153 msg.pid = BTC_PID_HF;
154 msg.act = BTC_HF_DISCONNECT_AUDIO_EVT;
155
156 btc_hf_args_t arg;
157 memset(&arg, 0, sizeof(btc_hf_args_t));
158 memcpy(&(arg.disconnect_audio), remote_addr, sizeof(esp_bd_addr_t));
159
160 /* Switch to BTC context */
161 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
162 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
163 }
164
esp_bt_hf_vra(esp_bd_addr_t remote_addr,esp_hf_vr_state_t value)165 esp_err_t esp_bt_hf_vra(esp_bd_addr_t remote_addr, esp_hf_vr_state_t value)
166 {
167 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
168 return ESP_ERR_INVALID_STATE;
169 }
170 btc_msg_t msg;
171 msg.sig = BTC_SIG_API_CALL;
172 msg.pid = BTC_PID_HF;
173 msg.act = BTC_HF_VRA_EVT;
174
175 btc_hf_args_t arg;
176 memset(&arg, 0, sizeof(btc_hf_args_t));
177 arg.vra_rep.value = value;
178 memcpy(&(arg.volcon.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
179
180 /* Switch to BTC context */
181 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
182 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
183 }
184
esp_bt_hf_volume_control(esp_bd_addr_t remote_addr,esp_hf_volume_control_target_t type,int volume)185 esp_err_t esp_bt_hf_volume_control(esp_bd_addr_t remote_addr, esp_hf_volume_control_target_t type, int volume)
186 {
187 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
188 return ESP_ERR_INVALID_STATE;
189 }
190 btc_msg_t msg;
191 msg.sig = BTC_SIG_API_CALL;
192 msg.pid = BTC_PID_HF;
193 msg.act = BTC_HF_VOLUME_CONTROL_EVT;
194
195 btc_hf_args_t arg;
196 memset(&arg, 0, sizeof(btc_hf_args_t));
197 arg.volcon.target_type = type;
198 arg.volcon.volume = volume;
199 memcpy(&(arg.volcon.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
200
201 /* Switch to BTC context */
202 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
203 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
204 }
205
esp_hf_unat_response(esp_bd_addr_t remote_addr,char * unat)206 esp_err_t esp_hf_unat_response(esp_bd_addr_t remote_addr, char *unat)
207 {
208 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
209 return ESP_ERR_INVALID_STATE;
210 }
211 btc_msg_t msg;
212 msg.sig = BTC_SIG_API_CALL;
213 msg.pid = BTC_PID_HF;
214 msg.act = BTC_HF_UNAT_RESPONSE_EVT;
215
216 btc_hf_args_t arg;
217 memset(&arg, 0, sizeof(btc_hf_args_t));
218 arg.unat_rep.unat = unat;
219 memcpy(&(arg.unat_rep.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
220
221 /* Switch to BTC context */
222 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
223 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
224 }
225
esp_bt_hf_cmee_response(esp_bd_addr_t remote_addr,esp_hf_at_response_code_t response_code,esp_hf_cme_err_t error_code)226 esp_err_t esp_bt_hf_cmee_response(esp_bd_addr_t remote_addr, esp_hf_at_response_code_t response_code, esp_hf_cme_err_t error_code)
227 {
228 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
229 return ESP_ERR_INVALID_STATE;
230 }
231 btc_msg_t msg;
232 msg.sig = BTC_SIG_API_CALL;
233 msg.pid = BTC_PID_HF;
234 msg.act = BTC_HF_CME_ERR_EVT;
235
236 btc_hf_args_t arg;
237 memset(&arg, 0, sizeof(btc_hf_args_t));
238 arg.ext_at.response_code = response_code;
239 arg.ext_at.error_code = error_code;
240 memcpy(&(arg.ext_at.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
241
242 /* Switch to BTC context */
243 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
244 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
245 }
246
esp_bt_hf_indchange_notification(esp_bd_addr_t remote_addr,esp_hf_call_status_t call_state,esp_hf_call_setup_status_t call_setup_state,esp_hf_network_state_t ntk_state,int signal)247 esp_err_t esp_bt_hf_indchange_notification(esp_bd_addr_t remote_addr,
248 esp_hf_call_status_t call_state,
249 esp_hf_call_setup_status_t call_setup_state,
250 esp_hf_network_state_t ntk_state, int signal)
251 {
252 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
253 return ESP_ERR_INVALID_STATE;
254 }
255 btc_msg_t msg;
256 msg.sig = BTC_SIG_API_CALL;
257 msg.pid = BTC_PID_HF;
258 msg.act = BTC_HF_IND_NOTIFICATION_EVT;
259
260 btc_hf_args_t arg;
261 memset(&arg, 0, sizeof(btc_hf_args_t));
262 memcpy(&(arg.ind_change.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
263 arg.ind_change.call_state = call_state;
264 arg.ind_change.call_setup_state = call_setup_state;
265 arg.ind_change.ntk_state = ntk_state;
266 arg.ind_change.signal = signal;
267
268 /* Switch to BTC context */
269 bt_status_t state = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
270 return (state == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
271 }
272
esp_bt_hf_cind_response(esp_bd_addr_t remote_addr,esp_hf_call_status_t call_state,esp_hf_call_setup_status_t call_setup_state,esp_hf_network_state_t ntk_state,int signal,esp_hf_roaming_status_t roam,int batt_lev,esp_hf_call_held_status_t call_held_status)273 esp_err_t esp_bt_hf_cind_response(esp_bd_addr_t remote_addr,
274 esp_hf_call_status_t call_state,
275 esp_hf_call_setup_status_t call_setup_state,
276 esp_hf_network_state_t ntk_state, int signal, esp_hf_roaming_status_t roam, int batt_lev,
277 esp_hf_call_held_status_t call_held_status)
278 {
279 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
280 return ESP_ERR_INVALID_STATE;
281 }
282 btc_msg_t msg;
283 msg.sig = BTC_SIG_API_CALL;
284 msg.pid = BTC_PID_HF;
285 msg.act = BTC_HF_CIND_RESPONSE_EVT;
286
287 btc_hf_args_t arg;
288 memset(&arg, 0, sizeof(btc_hf_args_t));
289 memcpy(&(arg.cind_rep.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
290 arg.cind_rep.call_state = call_state;
291 arg.cind_rep.call_setup_state = call_setup_state;
292 arg.cind_rep.ntk_state = ntk_state;
293 arg.cind_rep.signal = signal;
294 arg.cind_rep.roam = roam;
295 arg.cind_rep.batt_lev = batt_lev;
296 arg.cind_rep.call_held_state = call_held_status;
297
298 /* Switch to BTC context */
299 bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
300 return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
301 }
302
esp_bt_hf_cops_response(esp_bd_addr_t remote_addr,char * name)303 esp_err_t esp_bt_hf_cops_response(esp_bd_addr_t remote_addr, char *name)
304 {
305 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
306 return ESP_ERR_INVALID_STATE;
307 }
308 btc_msg_t msg;
309 msg.sig = BTC_SIG_API_CALL;
310 msg.pid = BTC_PID_HF;
311 msg.act = BTC_HF_COPS_RESPONSE_EVT;
312
313 btc_hf_args_t arg;
314 memset(&arg, 0, sizeof(btc_hf_args_t));
315 memcpy(&(arg.cops_rep.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
316 arg.cops_rep.name = name; //deep_copy
317
318 /* Switch to BTC context */
319 bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
320 return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
321 }
322
esp_bt_hf_clcc_response(esp_bd_addr_t remote_addr,int index,esp_hf_current_call_direction_t dir,esp_hf_current_call_status_t current_call_state,esp_hf_current_call_mode_t mode,esp_hf_current_call_mpty_type_t mpty,char * number,esp_hf_call_addr_type_t type)323 esp_err_t esp_bt_hf_clcc_response(esp_bd_addr_t remote_addr, int index, esp_hf_current_call_direction_t dir,
324 esp_hf_current_call_status_t current_call_state, esp_hf_current_call_mode_t mode,
325 esp_hf_current_call_mpty_type_t mpty, char *number, esp_hf_call_addr_type_t type)
326 {
327 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
328 return ESP_ERR_INVALID_STATE;
329 }
330 btc_msg_t msg;
331 msg.sig = BTC_SIG_API_CALL;
332 msg.pid = BTC_PID_HF;
333 msg.act = BTC_HF_CLCC_RESPONSE_EVT;
334
335 btc_hf_args_t arg;
336 memset(&arg, 0, sizeof(btc_hf_args_t));
337 memcpy(&(arg.clcc_rep.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
338 //mandatory args
339 arg.clcc_rep.index = index;
340 arg.clcc_rep.dir = dir;
341 arg.clcc_rep.current_call_state = current_call_state;
342 arg.clcc_rep.mode = mode;
343 arg.clcc_rep.mpty = mpty;
344 // option args
345 arg.clcc_rep.number = number; //deep_copy
346 arg.clcc_rep.type = type;
347
348 /* Switch to BTC context */
349 bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
350 return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
351 }
352
esp_bt_hf_cnum_response(esp_bd_addr_t remote_addr,char * number,esp_hf_subscriber_service_type_t type)353 esp_err_t esp_bt_hf_cnum_response(esp_bd_addr_t remote_addr, char *number, esp_hf_subscriber_service_type_t type)
354 {
355 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
356 return ESP_ERR_INVALID_STATE;
357 }
358 btc_msg_t msg;
359 msg.sig = BTC_SIG_API_CALL;
360 msg.pid = BTC_PID_HF;
361 msg.act = BTC_HF_CNUM_RESPONSE_EVT;
362
363 btc_hf_args_t arg;
364 memset(&arg, 0, sizeof(btc_hf_args_t));
365 memcpy(&(arg.cnum_rep), remote_addr, sizeof(esp_bd_addr_t));
366 arg.cnum_rep.number = number; //deep_copy
367 arg.cnum_rep.type = type;
368
369 /* Switch to BTC context */
370 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
371 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
372 }
373
esp_bt_hf_bsir(esp_bd_addr_t remote_addr,esp_hf_in_band_ring_state_t state)374 esp_err_t esp_bt_hf_bsir(esp_bd_addr_t remote_addr, esp_hf_in_band_ring_state_t state)
375 {
376 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
377 return ESP_ERR_INVALID_STATE;
378 }
379 btc_msg_t msg;
380 msg.sig = BTC_SIG_API_CALL;
381 msg.pid = BTC_PID_HF;
382 msg.act = BTC_HF_INBAND_RING_EVT;
383
384 btc_hf_args_t arg;
385 memset(&arg, 0, sizeof(btc_hf_args_t));
386 memcpy(&(arg.bsir.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
387 arg.bsir.state = state;
388
389 /* Switch to BTC context */
390 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
391 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
392 }
393
esp_bt_hf_answer_call(esp_bd_addr_t remote_addr,int num_active,int num_held,esp_hf_call_status_t call_state,esp_hf_call_setup_status_t call_setup_state,char * number,esp_hf_call_addr_type_t call_addr_type)394 esp_err_t esp_bt_hf_answer_call(esp_bd_addr_t remote_addr, int num_active, int num_held,
395 esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state,
396 char *number, esp_hf_call_addr_type_t call_addr_type)
397 {
398 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
399 return ESP_ERR_INVALID_STATE;
400 }
401 btc_msg_t msg;
402 msg.sig = BTC_SIG_API_CALL;
403 msg.pid = BTC_PID_HF;
404 msg.act = BTC_HF_AC_INCALL_EVT;
405
406 btc_hf_args_t arg;
407 memset(&arg, 0, sizeof(btc_hf_args_t));
408 memcpy(&(arg.phone.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
409 arg.phone.num_active = num_active;
410 arg.phone.num_held = num_held;
411 arg.phone.call_state = call_state;
412 arg.phone.call_setup_state = call_setup_state;
413 arg.phone.number = number; //deep_copy
414 arg.phone.call_addr_type = call_addr_type;
415
416 /* Switch to BTC context */
417 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
418 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
419 }
420
esp_bt_hf_reject_call(esp_bd_addr_t remote_addr,int num_active,int num_held,esp_hf_call_status_t call_state,esp_hf_call_setup_status_t call_setup_state,char * number,esp_hf_call_addr_type_t call_addr_type)421 esp_err_t esp_bt_hf_reject_call(esp_bd_addr_t remote_addr, int num_active, int num_held,
422 esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state,
423 char *number, esp_hf_call_addr_type_t call_addr_type)
424 {
425 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
426 return ESP_ERR_INVALID_STATE;
427 }
428 btc_msg_t msg;
429 msg.sig = BTC_SIG_API_CALL;
430 msg.pid = BTC_PID_HF;
431 msg.act = BTC_HF_RJ_INCALL_EVT;
432
433 btc_hf_args_t arg;
434 memset(&arg, 0, sizeof(btc_hf_args_t));
435 memcpy(&(arg.phone.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
436 arg.phone.num_active = num_active;
437 arg.phone.num_held = num_held;
438 arg.phone.call_state = call_state;
439 arg.phone.call_setup_state = call_setup_state;
440 arg.phone.number = number; //deep_copy
441 arg.phone.call_addr_type = call_addr_type;
442
443 /* Switch to BTC context */
444 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
445 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
446 }
447
esp_bt_hf_end_call(esp_bd_addr_t remote_addr,int num_active,int num_held,esp_hf_call_status_t call_state,esp_hf_call_setup_status_t call_setup_state,char * number,esp_hf_call_addr_type_t call_addr_type)448 esp_err_t esp_bt_hf_end_call(esp_bd_addr_t remote_addr, int num_active, int num_held,
449 esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state,
450 char *number, esp_hf_call_addr_type_t call_addr_type)
451 {
452 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
453 return ESP_ERR_INVALID_STATE;
454 }
455 btc_msg_t msg;
456 msg.sig = BTC_SIG_API_CALL;
457 msg.pid = BTC_PID_HF;
458 msg.act = BTC_HF_END_CALL_EVT;
459
460 btc_hf_args_t arg;
461 memset(&arg, 0, sizeof(btc_hf_args_t));
462 memcpy(&(arg.phone.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
463 arg.phone.num_active = num_active;
464 arg.phone.num_held = num_held;
465 arg.phone.call_state = call_state;
466 arg.phone.call_setup_state = call_setup_state;
467 arg.phone.number = number; //deep_copy
468 arg.phone.call_addr_type = call_addr_type;
469
470 /* Switch to BTC context */
471 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
472 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
473 }
474
esp_bt_hf_out_call(esp_bd_addr_t remote_addr,int num_active,int num_held,esp_hf_call_status_t call_state,esp_hf_call_setup_status_t call_setup_state,char * number,esp_hf_call_addr_type_t call_addr_type)475 esp_err_t esp_bt_hf_out_call(esp_bd_addr_t remote_addr, int num_active, int num_held,
476 esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state,
477 char *number, esp_hf_call_addr_type_t call_addr_type)
478 {
479 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
480 return ESP_ERR_INVALID_STATE;
481 }
482 btc_msg_t msg;
483 msg.sig = BTC_SIG_API_CALL;
484 msg.pid = BTC_PID_HF;
485 msg.act = BTC_HF_OUT_CALL_EVT;
486
487 btc_hf_args_t arg;
488 memset(&arg, 0, sizeof(btc_hf_args_t));
489 memcpy(&(arg.phone.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
490 arg.phone.num_active = num_active;
491 arg.phone.num_held = num_held;
492 arg.phone.call_state = call_state;
493 arg.phone.call_setup_state = call_setup_state;
494 arg.phone.number = number; //deep_copy
495 arg.phone.call_addr_type = call_addr_type;
496
497 /* Switch to BTC context */
498 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
499 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
500 }
501
esp_bt_hf_register_data_callback(esp_hf_incoming_data_cb_t recv,esp_hf_outgoing_data_cb_t send)502 esp_err_t esp_bt_hf_register_data_callback(esp_hf_incoming_data_cb_t recv, esp_hf_outgoing_data_cb_t send)
503 {
504 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
505 return ESP_ERR_INVALID_STATE;
506 }
507 btc_msg_t msg;
508 msg.sig = BTC_SIG_API_CALL;
509 msg.pid = BTC_PID_HF;
510 msg.act = BTC_HF_REGISTER_DATA_CALLBACK_EVT;
511
512 btc_hf_args_t arg;
513 memset(&arg, 0, sizeof(btc_hf_args_t));
514 arg.reg_data_cb.recv = recv;
515 arg.reg_data_cb.send = send;
516
517 /* Switch to BTC context */
518 bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
519 return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
520 }
521
522 #if (BTM_SCO_HCI_INCLUDED == TRUE)
esp_hf_outgoing_data_ready(void)523 void esp_hf_outgoing_data_ready(void)
524 {
525 btc_hf_ci_sco_data();
526 }
527 #endif /* #if (BTM_SCO_HCI_INCLUDED == TRUE ) */
528
529 #endif // BTC_HF_INCLUDED
530