esp_blufi_api.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 "btc/btc_task.h"
  15. #include "btc_blufi_prf.h"
  16. #include "btc/btc_manage.h"
  17. #include "osi/future.h"
  18. #if (BLUFI_INCLUDED == TRUE)
  19. esp_err_t esp_blufi_register_callbacks(esp_blufi_callbacks_t *callbacks)
  20. {
  21. ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
  22. if (callbacks == NULL) {
  23. return ESP_FAIL;
  24. }
  25. btc_blufi_set_callbacks(callbacks);
  26. return (btc_profile_cb_set(BTC_PID_BLUFI, callbacks->event_cb) == 0 ? ESP_OK : ESP_FAIL);
  27. }
  28. 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)
  29. {
  30. btc_msg_t msg;
  31. btc_blufi_args_t arg;
  32. ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
  33. msg.sig = BTC_SIG_API_CALL;
  34. msg.pid = BTC_PID_BLUFI;
  35. msg.act = BTC_BLUFI_ACT_SEND_CFG_REPORT;
  36. arg.wifi_conn_report.opmode = opmode;
  37. arg.wifi_conn_report.sta_conn_state = sta_conn_state;
  38. arg.wifi_conn_report.softap_conn_num = softap_conn_num;
  39. arg.wifi_conn_report.extra_info = extra_info;
  40. return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  41. }
  42. esp_err_t esp_blufi_send_wifi_list(uint16_t apCount, esp_blufi_ap_record_t *list)
  43. {
  44. btc_msg_t msg;
  45. btc_blufi_args_t arg;
  46. ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
  47. msg.sig = BTC_SIG_API_CALL;
  48. msg.pid = BTC_PID_BLUFI;
  49. msg.act = BTC_BLUFI_ACT_SEND_WIFI_LIST;
  50. arg.wifi_list.apCount = apCount;
  51. arg.wifi_list.list = list;
  52. return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  53. }
  54. esp_err_t esp_blufi_profile_init(void)
  55. {
  56. btc_msg_t msg;
  57. ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
  58. msg.sig = BTC_SIG_API_CALL;
  59. msg.pid = BTC_PID_BLUFI;
  60. msg.act = BTC_BLUFI_ACT_INIT;
  61. return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  62. }
  63. esp_err_t esp_blufi_profile_deinit(void)
  64. {
  65. btc_msg_t msg;
  66. ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
  67. msg.sig = BTC_SIG_API_CALL;
  68. msg.pid = BTC_PID_BLUFI;
  69. msg.act = BTC_BLUFI_ACT_DEINIT;
  70. return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  71. }
  72. uint16_t esp_blufi_get_version(void)
  73. {
  74. return btc_blufi_get_version();
  75. }
  76. esp_err_t esp_blufi_send_error_info(esp_blufi_error_state_t state)
  77. {
  78. btc_msg_t msg;
  79. btc_blufi_args_t arg;
  80. ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
  81. msg.sig = BTC_SIG_API_CALL;
  82. msg.pid = BTC_PID_BLUFI;
  83. msg.act = BTC_BLUFI_ACT_SEND_ERR_INFO;
  84. arg.blufi_err_infor.state = state;
  85. return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  86. }
  87. esp_err_t esp_blufi_send_custom_data(uint8_t *data, uint32_t data_len)
  88. {
  89. btc_msg_t msg;
  90. btc_blufi_args_t arg;
  91. if(data == NULL || data_len == 0) {
  92. return ESP_ERR_INVALID_ARG;
  93. }
  94. ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
  95. msg.sig = BTC_SIG_API_CALL;
  96. msg.pid = BTC_PID_BLUFI;
  97. msg.act = BTC_BLUFI_ACT_SEND_CUSTOM_DATA;
  98. arg.custom_data.data = data;
  99. arg.custom_data.data_len = data_len;
  100. return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  101. }
  102. #endif ///BLUFI_INCLUDED == TRUE