esp_blufi_api.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright 2015-2016 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 "esp_blufi_api.h"
  14. #include "esp_bt_defs.h"
  15. #include "esp_bt_main.h"
  16. #include "btc_task.h"
  17. #include "btc_blufi_prf.h"
  18. #include "btc_manage.h"
  19. #include "btc_main.h"
  20. #include "future.h"
  21. esp_err_t esp_blufi_register_callbacks(esp_blufi_callbacks_t *callbacks)
  22. {
  23. if (esp_bluedroid_get_status() == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
  24. return ESP_ERR_INVALID_STATE;
  25. }
  26. if (callbacks == NULL) {
  27. return ESP_FAIL;
  28. }
  29. btc_blufi_set_callbacks(callbacks);
  30. return (btc_profile_cb_set(BTC_PID_BLUFI, callbacks->event_cb) == 0 ? ESP_OK : ESP_FAIL);
  31. }
  32. esp_err_t esp_blufi_send_wifi_conn_report(wifi_mode_t opmode, esp_blufi_sta_conn_state_t sta_conn_state, uint8_t softap_conn_num, esp_blufi_extra_info_t *extra_info)
  33. {
  34. btc_msg_t msg;
  35. btc_blufi_args_t arg;
  36. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  37. return ESP_ERR_INVALID_STATE;
  38. }
  39. msg.sig = BTC_SIG_API_CALL;
  40. msg.pid = BTC_PID_BLUFI;
  41. msg.act = BTC_BLUFI_ACT_SEND_CFG_REPORT;
  42. arg.wifi_conn_report.opmode = opmode;
  43. arg.wifi_conn_report.sta_conn_state = sta_conn_state;
  44. arg.wifi_conn_report.softap_conn_num = softap_conn_num;
  45. arg.wifi_conn_report.extra_info = extra_info;
  46. return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  47. }
  48. esp_err_t esp_blufi_profile_init(void)
  49. {
  50. btc_msg_t msg;
  51. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  52. return ESP_ERR_INVALID_STATE;
  53. }
  54. msg.sig = BTC_SIG_API_CALL;
  55. msg.pid = BTC_PID_BLUFI;
  56. msg.act = BTC_BLUFI_ACT_INIT;
  57. return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  58. }
  59. esp_err_t esp_blufi_profile_deinit(void)
  60. {
  61. btc_msg_t msg;
  62. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  63. return ESP_ERR_INVALID_STATE;
  64. }
  65. msg.sig = BTC_SIG_API_CALL;
  66. msg.pid = BTC_PID_BLUFI;
  67. msg.act = BTC_BLUFI_ACT_DEINIT;
  68. return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  69. }
  70. uint16_t esp_blufi_get_version(void)
  71. {
  72. return btc_blufi_get_version();
  73. }