2016-11-16 09:11:59 -05:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
|
|
#include "esp_blufi_api.h"
|
|
|
|
#include "esp_bt_defs.h"
|
|
|
|
#include "esp_bt_main.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "btc/btc_task.h"
|
2016-11-16 09:11:59 -05:00
|
|
|
#include "btc_blufi_prf.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "btc/btc_manage.h"
|
|
|
|
#include "btc/btc_main.h"
|
|
|
|
#include "osi/future.h"
|
2017-04-20 23:04:53 -04:00
|
|
|
#include "btc_gatts.h"
|
2017-12-25 05:04:07 -05:00
|
|
|
#include "btc_gatt_util.h"
|
2020-08-07 03:02:53 -04:00
|
|
|
#include "common/bt_target.h"
|
|
|
|
#if (BLUFI_INCLUDED == TRUE)
|
2016-12-27 23:02:43 -05:00
|
|
|
esp_err_t esp_blufi_register_callbacks(esp_blufi_callbacks_t *callbacks)
|
2016-11-16 09:11:59 -05:00
|
|
|
{
|
2017-01-11 00:36:48 -05:00
|
|
|
if (esp_bluedroid_get_status() == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
|
2016-12-23 11:28:47 -05:00
|
|
|
return ESP_ERR_INVALID_STATE;
|
2017-01-10 22:04:41 -05:00
|
|
|
}
|
2017-01-12 01:44:26 -05:00
|
|
|
|
2016-12-27 23:02:43 -05:00
|
|
|
if (callbacks == NULL) {
|
|
|
|
return ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
btc_blufi_set_callbacks(callbacks);
|
|
|
|
return (btc_profile_cb_set(BTC_PID_BLUFI, callbacks->event_cb) == 0 ? ESP_OK : ESP_FAIL);
|
2016-11-16 09:11:59 -05:00
|
|
|
}
|
|
|
|
|
2016-12-27 23:02:43 -05:00
|
|
|
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)
|
2016-11-16 09:11:59 -05:00
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_blufi_args_t arg;
|
2016-11-16 09:11:59 -05:00
|
|
|
|
2017-01-11 00:36:48 -05:00
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
2016-12-23 11:28:47 -05:00
|
|
|
return ESP_ERR_INVALID_STATE;
|
2017-01-10 22:04:41 -05:00
|
|
|
}
|
2017-01-12 01:44:26 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_BLUFI;
|
2016-12-27 23:02:43 -05:00
|
|
|
msg.act = BTC_BLUFI_ACT_SEND_CFG_REPORT;
|
|
|
|
arg.wifi_conn_report.opmode = opmode;
|
|
|
|
arg.wifi_conn_report.sta_conn_state = sta_conn_state;
|
|
|
|
arg.wifi_conn_report.softap_conn_num = softap_conn_num;
|
|
|
|
arg.wifi_conn_report.extra_info = extra_info;
|
2016-11-16 09:11:59 -05:00
|
|
|
|
2016-12-27 23:02:43 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-16 09:11:59 -05:00
|
|
|
}
|
|
|
|
|
2017-12-25 05:04:07 -05:00
|
|
|
esp_err_t esp_blufi_send_wifi_list(uint16_t apCount, esp_blufi_ap_record_t *list)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_blufi_args_t arg;
|
|
|
|
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_BLUFI;
|
|
|
|
msg.act = BTC_BLUFI_ACT_SEND_WIFI_LIST;
|
|
|
|
arg.wifi_list.apCount = apCount;
|
|
|
|
arg.wifi_list.list = list;
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
2016-11-16 09:11:59 -05:00
|
|
|
|
|
|
|
esp_err_t esp_blufi_profile_init(void)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
2016-11-16 09:11:59 -05:00
|
|
|
|
2017-01-11 00:36:48 -05:00
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
2016-12-23 11:28:47 -05:00
|
|
|
return ESP_ERR_INVALID_STATE;
|
2017-01-10 22:04:41 -05:00
|
|
|
}
|
2017-01-12 01:44:26 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_BLUFI;
|
|
|
|
msg.act = BTC_BLUFI_ACT_INIT;
|
2016-11-16 09:11:59 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-16 09:11:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_blufi_profile_deinit(void)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
2016-11-16 09:11:59 -05:00
|
|
|
|
2017-01-11 00:36:48 -05:00
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
2016-12-23 11:28:47 -05:00
|
|
|
return ESP_ERR_INVALID_STATE;
|
2017-01-10 22:04:41 -05:00
|
|
|
}
|
2017-01-12 01:44:26 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_BLUFI;
|
|
|
|
msg.act = BTC_BLUFI_ACT_DEINIT;
|
2016-11-16 09:11:59 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-16 09:11:59 -05:00
|
|
|
}
|
|
|
|
|
2017-01-06 04:40:46 -05:00
|
|
|
uint16_t esp_blufi_get_version(void)
|
|
|
|
{
|
|
|
|
return btc_blufi_get_version();
|
|
|
|
}
|
2016-11-16 09:11:59 -05:00
|
|
|
|
2017-04-20 23:04:53 -04:00
|
|
|
esp_err_t esp_blufi_close(esp_gatt_if_t gatts_if, uint16_t conn_id)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_CLOSE;
|
2017-12-25 05:04:07 -05:00
|
|
|
arg.close.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
|
2017-04-20 23:04:53 -04:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
2017-12-22 02:02:33 -05:00
|
|
|
|
|
|
|
esp_err_t esp_blufi_send_error_info(esp_blufi_error_state_t state)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_blufi_args_t arg;
|
|
|
|
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_BLUFI;
|
|
|
|
msg.act = BTC_BLUFI_ACT_SEND_ERR_INFO;
|
|
|
|
arg.blufi_err_infor.state = state;
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
2018-03-06 03:18:38 -05:00
|
|
|
|
|
|
|
esp_err_t esp_blufi_send_custom_data(uint8_t *data, uint32_t data_len)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_blufi_args_t arg;
|
|
|
|
if(data == NULL || data_len == 0) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_BLUFI;
|
|
|
|
msg.act = BTC_BLUFI_ACT_SEND_CUSTOM_DATA;
|
|
|
|
arg.custom_data.data = data;
|
|
|
|
arg.custom_data.data_len = data_len;
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
2020-08-07 03:02:53 -04:00
|
|
|
#endif ///BLUFI_INCLUDED == TRUE
|