esp_hf_ag_api.c 19 KB

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