esp_hf_ag_api.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdint.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <assert.h>
  11. #include "bt_common.h"
  12. #include "btc/btc_common.h"
  13. #include "btc/btc_dm.h"
  14. #include "btc_hf_ag.h"
  15. #include "btc/btc_profile_queue.h"
  16. #include "btc/btc_manage.h"
  17. #include "btc/btc_util.h"
  18. #include "bta/bta_ag_api.h"
  19. #include "bta/bta_api.h"
  20. #include "common/bt_target.h"
  21. #include "common/bt_defs.h"
  22. #include "device/bdaddr.h"
  23. #include "esp_bt.h"
  24. #include "esp_hf_ag_api.h"
  25. #include "esp_err.h"
  26. #include "esp_bt_main.h"
  27. #include "osi/allocator.h"
  28. #if (BTC_HF_INCLUDED == TRUE)
  29. esp_err_t esp_hf_ag_register_callback(esp_hf_cb_t callback)
  30. {
  31. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  32. return ESP_ERR_INVALID_STATE;
  33. }
  34. if (callback == NULL) {
  35. return ESP_FAIL;
  36. }
  37. btc_profile_cb_set(BTC_PID_HF, callback);
  38. return ESP_OK;
  39. }
  40. esp_err_t esp_hf_ag_init(void)
  41. {
  42. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  43. return ESP_ERR_INVALID_STATE;
  44. }
  45. btc_msg_t msg;
  46. msg.sig = BTC_SIG_API_CALL;
  47. msg.pid = BTC_PID_HF;
  48. msg.act = BTC_HF_INIT_EVT;
  49. /* Switch to BTC context */
  50. bt_status_t status = btc_transfer_context(&msg, NULL, sizeof(btc_hf_args_t), NULL);
  51. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  52. }
  53. esp_err_t esp_hf_ag_deinit(void)
  54. {
  55. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  56. return ESP_ERR_INVALID_STATE;
  57. }
  58. btc_msg_t msg;
  59. msg.sig = BTC_SIG_API_CALL;
  60. msg.pid = BTC_PID_HF;
  61. msg.act = BTC_HF_DEINIT_EVT;
  62. /* Switch to BTC context */
  63. bt_status_t status = btc_transfer_context(&msg, NULL, sizeof(btc_hf_args_t), NULL);
  64. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  65. }
  66. esp_err_t esp_hf_ag_slc_connect(esp_bd_addr_t remote_addr)
  67. {
  68. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  69. return ESP_ERR_INVALID_STATE;
  70. }
  71. btc_msg_t msg;
  72. msg.sig = BTC_SIG_API_CALL;
  73. msg.pid = BTC_PID_HF;
  74. msg.act = BTC_HF_CONNECT_EVT;
  75. btc_hf_args_t arg;
  76. memset(&arg, 0, sizeof(btc_hf_args_t));
  77. memcpy(&(arg.connect), remote_addr, sizeof(esp_bd_addr_t));
  78. /* Switch to BTC context */
  79. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
  80. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  81. }
  82. esp_err_t esp_hf_ag_slc_disconnect(esp_bd_addr_t remote_addr)
  83. {
  84. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  85. return ESP_ERR_INVALID_STATE;
  86. }
  87. btc_msg_t msg;
  88. msg.sig = BTC_SIG_API_CALL;
  89. msg.pid = BTC_PID_HF;
  90. msg.act = BTC_HF_DISCONNECT_EVT;
  91. btc_hf_args_t arg;
  92. memset(&arg, 0, sizeof(btc_hf_args_t));
  93. memcpy(&(arg.disconnect), remote_addr, sizeof(esp_bd_addr_t));
  94. /* Switch to BTC context */
  95. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
  96. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  97. }
  98. esp_err_t esp_hf_ag_audio_connect(esp_bd_addr_t remote_addr)
  99. {
  100. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  101. return ESP_ERR_INVALID_STATE;
  102. }
  103. btc_msg_t msg;
  104. msg.sig = BTC_SIG_API_CALL;
  105. msg.pid = BTC_PID_HF;
  106. msg.act = BTC_HF_CONNECT_AUDIO_EVT;
  107. btc_hf_args_t arg;
  108. memset(&arg, 0, sizeof(btc_hf_args_t));
  109. memcpy(&(arg.connect_audio), remote_addr, sizeof(esp_bd_addr_t));
  110. /* Switch to BTC context */
  111. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
  112. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  113. }
  114. esp_err_t esp_hf_ag_audio_disconnect(esp_bd_addr_t remote_addr)
  115. {
  116. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  117. return ESP_ERR_INVALID_STATE;
  118. }
  119. btc_msg_t msg;
  120. msg.sig = BTC_SIG_API_CALL;
  121. msg.pid = BTC_PID_HF;
  122. msg.act = BTC_HF_DISCONNECT_AUDIO_EVT;
  123. btc_hf_args_t arg;
  124. memset(&arg, 0, sizeof(btc_hf_args_t));
  125. memcpy(&(arg.disconnect_audio), remote_addr, sizeof(esp_bd_addr_t));
  126. /* Switch to BTC context */
  127. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
  128. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  129. }
  130. esp_err_t esp_hf_ag_vra_control(esp_bd_addr_t remote_addr, esp_hf_vr_state_t value)
  131. {
  132. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  133. return ESP_ERR_INVALID_STATE;
  134. }
  135. btc_msg_t msg;
  136. msg.sig = BTC_SIG_API_CALL;
  137. msg.pid = BTC_PID_HF;
  138. msg.act = BTC_HF_VRA_EVT;
  139. btc_hf_args_t arg;
  140. memset(&arg, 0, sizeof(btc_hf_args_t));
  141. arg.vra_rep.value = value;
  142. memcpy(&(arg.volcon.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  143. /* Switch to BTC context */
  144. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
  145. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  146. }
  147. esp_err_t esp_hf_ag_volume_control(esp_bd_addr_t remote_addr, esp_hf_volume_control_target_t type, int volume)
  148. {
  149. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  150. return ESP_ERR_INVALID_STATE;
  151. }
  152. btc_msg_t msg;
  153. msg.sig = BTC_SIG_API_CALL;
  154. msg.pid = BTC_PID_HF;
  155. msg.act = BTC_HF_VOLUME_CONTROL_EVT;
  156. btc_hf_args_t arg;
  157. memset(&arg, 0, sizeof(btc_hf_args_t));
  158. arg.volcon.target_type = type;
  159. arg.volcon.volume = volume;
  160. memcpy(&(arg.volcon.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  161. /* Switch to BTC context */
  162. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
  163. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  164. }
  165. esp_err_t esp_hf_ag_unknown_at_send(esp_bd_addr_t remote_addr, char *unat)
  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_UNAT_RESPONSE_EVT;
  174. btc_hf_args_t arg;
  175. memset(&arg, 0, sizeof(btc_hf_args_t));
  176. arg.unat_rep.unat = unat;
  177. memcpy(&(arg.unat_rep.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  178. /* Switch to BTC context */
  179. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
  180. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  181. }
  182. esp_err_t esp_hf_ag_cmee_send(esp_bd_addr_t remote_addr, esp_hf_at_response_code_t response_code, esp_hf_cme_err_t error_code)
  183. {
  184. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  185. return ESP_ERR_INVALID_STATE;
  186. }
  187. btc_msg_t msg;
  188. msg.sig = BTC_SIG_API_CALL;
  189. msg.pid = BTC_PID_HF;
  190. msg.act = BTC_HF_CME_ERR_EVT;
  191. btc_hf_args_t arg;
  192. memset(&arg, 0, sizeof(btc_hf_args_t));
  193. arg.ext_at.response_code = response_code;
  194. arg.ext_at.error_code = error_code;
  195. memcpy(&(arg.ext_at.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  196. /* Switch to BTC context */
  197. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
  198. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  199. }
  200. esp_err_t esp_hf_ag_devices_status_indchange(esp_bd_addr_t remote_addr,
  201. esp_hf_call_status_t call_state,
  202. esp_hf_call_setup_status_t call_setup_state,
  203. esp_hf_network_state_t ntk_state, int signal)
  204. {
  205. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  206. return ESP_ERR_INVALID_STATE;
  207. }
  208. btc_msg_t msg;
  209. msg.sig = BTC_SIG_API_CALL;
  210. msg.pid = BTC_PID_HF;
  211. msg.act = BTC_HF_IND_NOTIFICATION_EVT;
  212. btc_hf_args_t arg;
  213. memset(&arg, 0, sizeof(btc_hf_args_t));
  214. memcpy(&(arg.ind_change.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  215. arg.ind_change.call_state = call_state;
  216. arg.ind_change.call_setup_state = call_setup_state;
  217. arg.ind_change.ntk_state = ntk_state;
  218. arg.ind_change.signal = signal;
  219. /* Switch to BTC context */
  220. bt_status_t state = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
  221. return (state == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  222. }
  223. esp_err_t esp_hf_ag_cind_response(esp_bd_addr_t remote_addr,
  224. esp_hf_call_status_t call_state,
  225. esp_hf_call_setup_status_t call_setup_state,
  226. esp_hf_network_state_t ntk_state, int signal, esp_hf_roaming_status_t roam, int batt_lev,
  227. esp_hf_call_held_status_t call_held_status)
  228. {
  229. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  230. return ESP_ERR_INVALID_STATE;
  231. }
  232. btc_msg_t msg;
  233. msg.sig = BTC_SIG_API_CALL;
  234. msg.pid = BTC_PID_HF;
  235. msg.act = BTC_HF_CIND_RESPONSE_EVT;
  236. btc_hf_args_t arg;
  237. memset(&arg, 0, sizeof(btc_hf_args_t));
  238. memcpy(&(arg.cind_rep.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  239. arg.cind_rep.call_state = call_state;
  240. arg.cind_rep.call_setup_state = call_setup_state;
  241. arg.cind_rep.ntk_state = ntk_state;
  242. arg.cind_rep.signal = signal;
  243. arg.cind_rep.roam = roam;
  244. arg.cind_rep.batt_lev = batt_lev;
  245. arg.cind_rep.call_held_state = call_held_status;
  246. /* Switch to BTC context */
  247. bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
  248. return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  249. }
  250. esp_err_t esp_hf_ag_cops_response(esp_bd_addr_t remote_addr, char *name)
  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_COPS_RESPONSE_EVT;
  259. btc_hf_args_t arg;
  260. memset(&arg, 0, sizeof(btc_hf_args_t));
  261. memcpy(&(arg.cops_rep.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  262. arg.cops_rep.name = name; //deep_copy
  263. /* Switch to BTC context */
  264. bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
  265. return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  266. }
  267. esp_err_t esp_hf_ag_clcc_response(esp_bd_addr_t remote_addr, int index, esp_hf_current_call_direction_t dir,
  268. esp_hf_current_call_status_t current_call_state, esp_hf_current_call_mode_t mode,
  269. esp_hf_current_call_mpty_type_t mpty, char *number, esp_hf_call_addr_type_t type)
  270. {
  271. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  272. return ESP_ERR_INVALID_STATE;
  273. }
  274. btc_msg_t msg;
  275. msg.sig = BTC_SIG_API_CALL;
  276. msg.pid = BTC_PID_HF;
  277. msg.act = BTC_HF_CLCC_RESPONSE_EVT;
  278. btc_hf_args_t arg;
  279. memset(&arg, 0, sizeof(btc_hf_args_t));
  280. memcpy(&(arg.clcc_rep.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  281. //mandatory args
  282. arg.clcc_rep.index = index;
  283. arg.clcc_rep.dir = dir;
  284. arg.clcc_rep.current_call_state = current_call_state;
  285. arg.clcc_rep.mode = mode;
  286. arg.clcc_rep.mpty = mpty;
  287. // option args
  288. arg.clcc_rep.number = number; //deep_copy
  289. arg.clcc_rep.type = type;
  290. /* Switch to BTC context */
  291. bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
  292. return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  293. }
  294. esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, esp_hf_subscriber_service_type_t type)
  295. {
  296. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  297. return ESP_ERR_INVALID_STATE;
  298. }
  299. btc_msg_t msg;
  300. msg.sig = BTC_SIG_API_CALL;
  301. msg.pid = BTC_PID_HF;
  302. msg.act = BTC_HF_CNUM_RESPONSE_EVT;
  303. btc_hf_args_t arg;
  304. memset(&arg, 0, sizeof(btc_hf_args_t));
  305. memcpy(&(arg.cnum_rep), remote_addr, sizeof(esp_bd_addr_t));
  306. arg.cnum_rep.number = number; //deep_copy
  307. arg.cnum_rep.type = type;
  308. /* Switch to BTC context */
  309. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
  310. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  311. }
  312. esp_err_t esp_hf_ag_bsir(esp_bd_addr_t remote_addr, esp_hf_in_band_ring_state_t state)
  313. {
  314. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  315. return ESP_ERR_INVALID_STATE;
  316. }
  317. btc_msg_t msg;
  318. msg.sig = BTC_SIG_API_CALL;
  319. msg.pid = BTC_PID_HF;
  320. msg.act = BTC_HF_INBAND_RING_EVT;
  321. btc_hf_args_t arg;
  322. memset(&arg, 0, sizeof(btc_hf_args_t));
  323. memcpy(&(arg.bsir.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  324. arg.bsir.state = state;
  325. /* Switch to BTC context */
  326. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
  327. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  328. }
  329. esp_err_t esp_hf_ag_answer_call(esp_bd_addr_t remote_addr, int num_active, int num_held,
  330. esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state,
  331. char *number, esp_hf_call_addr_type_t call_addr_type)
  332. {
  333. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  334. return ESP_ERR_INVALID_STATE;
  335. }
  336. btc_msg_t msg;
  337. msg.sig = BTC_SIG_API_CALL;
  338. msg.pid = BTC_PID_HF;
  339. msg.act = BTC_HF_AC_INCALL_EVT;
  340. btc_hf_args_t arg;
  341. memset(&arg, 0, sizeof(btc_hf_args_t));
  342. memcpy(&(arg.phone.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  343. arg.phone.num_active = num_active;
  344. arg.phone.num_held = num_held;
  345. arg.phone.call_state = call_state;
  346. arg.phone.call_setup_state = call_setup_state;
  347. arg.phone.number = number; //deep_copy
  348. arg.phone.call_addr_type = call_addr_type;
  349. /* Switch to BTC context */
  350. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
  351. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  352. }
  353. esp_err_t esp_hf_ag_reject_call(esp_bd_addr_t remote_addr, int num_active, int num_held,
  354. esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state,
  355. char *number, esp_hf_call_addr_type_t call_addr_type)
  356. {
  357. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  358. return ESP_ERR_INVALID_STATE;
  359. }
  360. btc_msg_t msg;
  361. msg.sig = BTC_SIG_API_CALL;
  362. msg.pid = BTC_PID_HF;
  363. msg.act = BTC_HF_RJ_INCALL_EVT;
  364. btc_hf_args_t arg;
  365. memset(&arg, 0, sizeof(btc_hf_args_t));
  366. memcpy(&(arg.phone.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  367. arg.phone.num_active = num_active;
  368. arg.phone.num_held = num_held;
  369. arg.phone.call_state = call_state;
  370. arg.phone.call_setup_state = call_setup_state;
  371. arg.phone.number = number; //deep_copy
  372. arg.phone.call_addr_type = call_addr_type;
  373. /* Switch to BTC context */
  374. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
  375. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  376. }
  377. esp_err_t esp_hf_ag_end_call(esp_bd_addr_t remote_addr, int num_active, int num_held,
  378. esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state,
  379. char *number, esp_hf_call_addr_type_t call_addr_type)
  380. {
  381. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  382. return ESP_ERR_INVALID_STATE;
  383. }
  384. btc_msg_t msg;
  385. msg.sig = BTC_SIG_API_CALL;
  386. msg.pid = BTC_PID_HF;
  387. msg.act = BTC_HF_END_CALL_EVT;
  388. btc_hf_args_t arg;
  389. memset(&arg, 0, sizeof(btc_hf_args_t));
  390. memcpy(&(arg.phone.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  391. arg.phone.num_active = num_active;
  392. arg.phone.num_held = num_held;
  393. arg.phone.call_state = call_state;
  394. arg.phone.call_setup_state = call_setup_state;
  395. arg.phone.number = number; //deep_copy
  396. arg.phone.call_addr_type = call_addr_type;
  397. /* Switch to BTC context */
  398. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
  399. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  400. }
  401. esp_err_t esp_hf_ag_out_call(esp_bd_addr_t remote_addr, int num_active, int num_held,
  402. esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state,
  403. char *number, esp_hf_call_addr_type_t call_addr_type)
  404. {
  405. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  406. return ESP_ERR_INVALID_STATE;
  407. }
  408. btc_msg_t msg;
  409. msg.sig = BTC_SIG_API_CALL;
  410. msg.pid = BTC_PID_HF;
  411. msg.act = BTC_HF_OUT_CALL_EVT;
  412. btc_hf_args_t arg;
  413. memset(&arg, 0, sizeof(btc_hf_args_t));
  414. memcpy(&(arg.phone.remote_addr), remote_addr, sizeof(esp_bd_addr_t));
  415. arg.phone.num_active = num_active;
  416. arg.phone.num_held = num_held;
  417. arg.phone.call_state = call_state;
  418. arg.phone.call_setup_state = call_setup_state;
  419. arg.phone.number = number; //deep_copy
  420. arg.phone.call_addr_type = call_addr_type;
  421. /* Switch to BTC context */
  422. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), btc_hf_arg_deep_copy);
  423. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  424. }
  425. esp_err_t esp_hf_ag_register_data_callback(esp_hf_incoming_data_cb_t recv, esp_hf_outgoing_data_cb_t send)
  426. {
  427. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  428. return ESP_ERR_INVALID_STATE;
  429. }
  430. btc_msg_t msg;
  431. msg.sig = BTC_SIG_API_CALL;
  432. msg.pid = BTC_PID_HF;
  433. msg.act = BTC_HF_REGISTER_DATA_CALLBACK_EVT;
  434. btc_hf_args_t arg;
  435. memset(&arg, 0, sizeof(btc_hf_args_t));
  436. arg.reg_data_cb.recv = recv;
  437. arg.reg_data_cb.send = send;
  438. /* Switch to BTC context */
  439. bt_status_t status = btc_transfer_context(&msg, &arg, sizeof(btc_hf_args_t), NULL);
  440. return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  441. }
  442. #if (BTM_SCO_HCI_INCLUDED == TRUE)
  443. void esp_hf_ag_outgoing_data_ready(void)
  444. {
  445. btc_hf_ci_sco_data();
  446. }
  447. #endif /* #if (BTM_SCO_HCI_INCLUDED == TRUE ) */
  448. #endif // BTC_HF_INCLUDED