esp_hf_ag_api.c 20 KB

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