esp_blufi_api.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include "btc_gatts.h"
  22. esp_err_t esp_blufi_register_callbacks(esp_blufi_callbacks_t *callbacks)
  23. {
  24. if (esp_bluedroid_get_status() == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
  25. return ESP_ERR_INVALID_STATE;
  26. }
  27. if (callbacks == NULL) {
  28. return ESP_FAIL;
  29. }
  30. btc_blufi_set_callbacks(callbacks);
  31. return (btc_profile_cb_set(BTC_PID_BLUFI, callbacks->event_cb) == 0 ? ESP_OK : ESP_FAIL);
  32. }
  33. 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)
  34. {
  35. btc_msg_t msg;
  36. btc_blufi_args_t arg;
  37. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  38. return ESP_ERR_INVALID_STATE;
  39. }
  40. msg.sig = BTC_SIG_API_CALL;
  41. msg.pid = BTC_PID_BLUFI;
  42. msg.act = BTC_BLUFI_ACT_SEND_CFG_REPORT;
  43. arg.wifi_conn_report.opmode = opmode;
  44. arg.wifi_conn_report.sta_conn_state = sta_conn_state;
  45. arg.wifi_conn_report.softap_conn_num = softap_conn_num;
  46. arg.wifi_conn_report.extra_info = extra_info;
  47. return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  48. }
  49. esp_err_t esp_blufi_profile_init(void)
  50. {
  51. btc_msg_t msg;
  52. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  53. return ESP_ERR_INVALID_STATE;
  54. }
  55. msg.sig = BTC_SIG_API_CALL;
  56. msg.pid = BTC_PID_BLUFI;
  57. msg.act = BTC_BLUFI_ACT_INIT;
  58. return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  59. }
  60. esp_err_t esp_blufi_profile_deinit(void)
  61. {
  62. btc_msg_t msg;
  63. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  64. return ESP_ERR_INVALID_STATE;
  65. }
  66. msg.sig = BTC_SIG_API_CALL;
  67. msg.pid = BTC_PID_BLUFI;
  68. msg.act = BTC_BLUFI_ACT_DEINIT;
  69. return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  70. }
  71. uint16_t esp_blufi_get_version(void)
  72. {
  73. return btc_blufi_get_version();
  74. }
  75. esp_err_t esp_blufi_close(esp_gatt_if_t gatts_if, uint16_t conn_id)
  76. {
  77. btc_msg_t msg;
  78. btc_ble_gatts_args_t arg;
  79. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  80. return ESP_ERR_INVALID_STATE;
  81. }
  82. msg.sig = BTC_SIG_API_CALL;
  83. msg.pid = BTC_PID_GATTS;
  84. msg.act = BTC_GATTS_ACT_CLOSE;
  85. arg.close.conn_id = conn_id;
  86. return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL)
  87. == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  88. }