btif_hfp.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2016 Actions Semi Co., Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief bt srv hfp api interface
  9. */
  10. #define SYS_LOG_DOMAIN "btif_hfp"
  11. #include "btsrv_os_common.h"
  12. #include "btsrv_inner.h"
  13. int btif_hfp_register_processer(void)
  14. {
  15. int ret = 0;
  16. ret |= btsrv_register_msg_processer(MSG_BTSRV_HFP, &btsrv_hfp_process);
  17. ret |= btsrv_register_msg_processer(MSG_BTSRV_SCO, &btsrv_sco_process);
  18. return ret;
  19. }
  20. int btif_hfp_start(btsrv_hfp_callback cb)
  21. {
  22. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_START, cb);
  23. }
  24. int btif_hfp_stop(void)
  25. {
  26. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_STOP, NULL);
  27. }
  28. int btif_sco_start(btsrv_sco_callback cb)
  29. {
  30. return btsrv_function_call(MSG_BTSRV_SCO, MSG_BTSRV_SCO_START, cb);
  31. }
  32. int btif_sco_stop(void)
  33. {
  34. return btsrv_function_call(MSG_BTSRV_SCO, MSG_BTSRV_SCO_STOP, NULL);
  35. }
  36. int btif_hfp_hf_dial_number(uint8_t *number)
  37. {
  38. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_DIAL_NUM, number);
  39. }
  40. int btif_hfp_hf_dial_last_number(void)
  41. {
  42. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_DIAL_LAST_NUM, NULL);
  43. }
  44. int btif_hfp_hf_switch_sound_source(void)
  45. {
  46. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_SWITCH_SOUND_SOURCE, NULL);
  47. }
  48. int btif_hfp_hf_dial_memory(int location)
  49. {
  50. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_DIAL_MEMORY, (void *)location);
  51. }
  52. int btif_hfp_hf_volume_control(uint8_t type, uint8_t volume)
  53. {
  54. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_VOLUME_CONTROL, (void *)((type << 16) | volume));
  55. }
  56. int btif_hfp_hf_accept_call(void)
  57. {
  58. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_ACCEPT_CALL, NULL);
  59. }
  60. int btif_hfp_hf_reject_call(void)
  61. {
  62. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_REJECT_CALL, NULL);
  63. }
  64. int btif_hfp_hf_hangup_call(void)
  65. {
  66. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_HANGUP_CALL, NULL);
  67. }
  68. int btif_hfp_hf_battery_report(uint8_t mode, uint8_t bat_val)
  69. {
  70. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_BATTERY_REPORT, (void *)((mode << 16) | bat_val));
  71. }
  72. int btif_hfp_hf_battery_hprec_report(uint8_t bat_val)
  73. {
  74. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_BATTERY_HPREC_REPORT, (void *)(0xFF & bat_val));
  75. }
  76. int btif_hfp_hf_hangup_another_call(void)
  77. {
  78. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_HANGUP_ANOTHER_CALL, NULL);
  79. }
  80. int btif_hfp_hf_holdcur_answer_call(void)
  81. {
  82. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_HOLDCUR_ANSWER_CALL, NULL);
  83. }
  84. int btif_hfp_hf_hangupcur_answer_call(void)
  85. {
  86. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_HANGUPCUR_ANSWER_CALL, NULL);
  87. }
  88. int btif_hfp_hf_voice_recognition_start(void)
  89. {
  90. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_VOICE_RECOGNITION_START, NULL);
  91. }
  92. int btif_hfp_hf_voice_recognition_stop(void)
  93. {
  94. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_VOICE_RECOGNITION_STOP, NULL);
  95. }
  96. int btif_hfp_hf_send_at_command(uint8_t *command,uint8_t active_call)
  97. {
  98. return btsrv_function_call_malloc(MSG_BTSRV_HFP, MSG_BTSRV_HFP_HF_VOICE_SEND_AT_COMMAND, command,strlen(command),active_call);
  99. }
  100. int btif_hfp_hf_get_time()
  101. {
  102. return btsrv_function_call(MSG_BTSRV_HFP, MSG_BTSRV_HFP_GET_TIME, NULL);
  103. }
  104. int btif_hfp_hf_get_call_state(uint8_t active_call,uint8_t *call_state)
  105. {
  106. int state, flags;
  107. flags = btsrv_set_negative_prio();
  108. state = btsrv_hfp_get_call_state(active_call,call_state);
  109. btsrv_revert_prio(flags);
  110. return state;
  111. }
  112. void btif_hfp_get_active_mac(bd_address_t *addr)
  113. {
  114. int flags;
  115. flags = btsrv_set_negative_prio();
  116. btsrv_rdm_get_hfp_acitve_mac(addr);
  117. btsrv_revert_prio(flags);
  118. }
  119. bool btif_hfp_active_phone_service_ready(void)
  120. {
  121. int flags;
  122. uint8_t service;
  123. flags = btsrv_set_negative_prio();
  124. service = btsrv_rdm_get_hfp_service();
  125. btsrv_revert_prio(flags);
  126. return service ? true : false;
  127. }