1 /*
2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7
8 #include "esp_blufi_api.h"
9 #include "btc/btc_task.h"
10 #include "btc_blufi_prf.h"
11 #include "btc/btc_manage.h"
12 #include "osi/future.h"
13 #if (BLUFI_INCLUDED == TRUE)
esp_blufi_register_callbacks(esp_blufi_callbacks_t * callbacks)14 esp_err_t esp_blufi_register_callbacks(esp_blufi_callbacks_t *callbacks)
15 {
16 ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
17
18 if (callbacks == NULL) {
19 return ESP_FAIL;
20 }
21
22 btc_blufi_set_callbacks(callbacks);
23 return (btc_profile_cb_set(BTC_PID_BLUFI, callbacks->event_cb) == 0 ? ESP_OK : ESP_FAIL);
24 }
25
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)26 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)
27 {
28 btc_msg_t msg;
29 btc_blufi_args_t arg;
30
31 ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
32
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
41 return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy,
42 btc_blufi_call_deep_free) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
43 }
44
esp_blufi_send_wifi_list(uint16_t apCount,esp_blufi_ap_record_t * list)45 esp_err_t esp_blufi_send_wifi_list(uint16_t apCount, esp_blufi_ap_record_t *list)
46 {
47 btc_msg_t msg;
48 btc_blufi_args_t arg;
49
50 ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
51
52 msg.sig = BTC_SIG_API_CALL;
53 msg.pid = BTC_PID_BLUFI;
54 msg.act = BTC_BLUFI_ACT_SEND_WIFI_LIST;
55 arg.wifi_list.apCount = apCount;
56 arg.wifi_list.list = list;
57
58 return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy,
59 btc_blufi_call_deep_free) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
60 }
61
esp_blufi_profile_init(void)62 esp_err_t esp_blufi_profile_init(void)
63 {
64 btc_msg_t msg;
65
66 ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
67
68 msg.sig = BTC_SIG_API_CALL;
69 msg.pid = BTC_PID_BLUFI;
70 msg.act = BTC_BLUFI_ACT_INIT;
71
72 return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
73 }
74
esp_blufi_profile_deinit(void)75 esp_err_t esp_blufi_profile_deinit(void)
76 {
77 btc_msg_t msg;
78
79 ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
80
81 msg.sig = BTC_SIG_API_CALL;
82 msg.pid = BTC_PID_BLUFI;
83 msg.act = BTC_BLUFI_ACT_DEINIT;
84
85 return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
86 }
87
esp_blufi_get_version(void)88 uint16_t esp_blufi_get_version(void)
89 {
90 return btc_blufi_get_version();
91 }
92
esp_blufi_send_error_info(esp_blufi_error_state_t state)93 esp_err_t esp_blufi_send_error_info(esp_blufi_error_state_t state)
94 {
95 btc_msg_t msg;
96 btc_blufi_args_t arg;
97
98 ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
99
100 msg.sig = BTC_SIG_API_CALL;
101 msg.pid = BTC_PID_BLUFI;
102 msg.act = BTC_BLUFI_ACT_SEND_ERR_INFO;
103 arg.blufi_err_infor.state = state;
104
105 return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
106 }
107
esp_blufi_send_custom_data(uint8_t * data,uint32_t data_len)108 esp_err_t esp_blufi_send_custom_data(uint8_t *data, uint32_t data_len)
109 {
110 btc_msg_t msg;
111 btc_blufi_args_t arg;
112 if(data == NULL || data_len == 0) {
113 return ESP_ERR_INVALID_ARG;
114 }
115 ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
116
117 msg.sig = BTC_SIG_API_CALL;
118 msg.pid = BTC_PID_BLUFI;
119 msg.act = BTC_BLUFI_ACT_SEND_CUSTOM_DATA;
120 arg.custom_data.data = data;
121 arg.custom_data.data_len = data_len;
122
123 return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy,
124 btc_blufi_call_deep_free) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
125 }
126 #endif ///BLUFI_INCLUDED == TRUE
127