2016-11-15 07:56:15 -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 <string.h>
|
2017-03-17 07:16:52 -04:00
|
|
|
#include "esp_bt_device.h"
|
2017-01-10 22:04:41 -05:00
|
|
|
#include "esp_bt_main.h"
|
2016-11-15 07:56:15 -05:00
|
|
|
#include "esp_gap_ble_api.h"
|
|
|
|
#include "bta_api.h"
|
|
|
|
#include "bt_trace.h"
|
|
|
|
#include "btc_manage.h"
|
|
|
|
#include "btc_gap_ble.h"
|
2017-08-28 05:14:49 -04:00
|
|
|
#include "btc_ble_storage.h"
|
2016-11-15 07:56:15 -05:00
|
|
|
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_profile_cb_set(BTC_PID_GAP_BLE, callback) == 0 ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (adv_data == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (adv_data->service_uuid_len & 0xf) { //not 16*n
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2016-11-21 09:38:00 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_CFG_ADV_DATA;
|
|
|
|
memcpy(&arg.cfg_adv_data.adv_data, adv_data, sizeof(esp_ble_adv_data_t));
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (scan_params == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_SET_SCAN_PARAM;
|
|
|
|
memcpy(&arg.set_scan_param.scan_params, scan_params, sizeof(esp_ble_scan_params_t));
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_start_scanning(uint32_t duration)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_START_SCAN;
|
|
|
|
arg.start_scan.duration = duration;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
2016-11-19 09:56:36 -05:00
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_stop_scanning(void)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
2017-01-11 00:36:48 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_STOP_SCAN;
|
|
|
|
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-19 09:56:36 -05:00
|
|
|
}
|
|
|
|
|
2016-11-15 07:56:15 -05:00
|
|
|
esp_err_t esp_ble_gap_start_advertising(esp_ble_adv_params_t *adv_params)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_START_ADV;
|
|
|
|
memcpy(&arg.start_adv.adv_params, adv_params, sizeof(esp_ble_adv_params_t));
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_stop_advertising(void)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_STOP_ADV;
|
2016-11-15 07:56:15 -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-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM;
|
|
|
|
memcpy(&arg.conn_update_params.conn_params, params, sizeof(esp_ble_conn_update_params_t));
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
2017-01-11 00:36:48 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN;
|
|
|
|
arg.set_pkt_data_len.tx_data_length = tx_data_length;
|
|
|
|
memcpy(arg.set_pkt_data_len.remote_device, remote_device, ESP_BD_ADDR_LEN);
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
2017-01-11 00:36:48 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_SET_RAND_ADDRESS;
|
|
|
|
memcpy(arg.set_rand_addr.rand_addr, rand_addr, ESP_BD_ADDR_LEN);
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY;
|
|
|
|
arg.cfg_local_privacy.privacy_enable = privacy_enable;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
2017-08-14 23:24:36 -04:00
|
|
|
esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
|
|
|
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
2017-09-27 03:29:42 -04:00
|
|
|
if (!remote_bda){
|
|
|
|
return ESP_ERR_INVALID_SIZE;
|
|
|
|
}
|
2017-08-14 23:24:36 -04:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST;
|
|
|
|
arg.update_white_list.add_remove = add_remove;
|
|
|
|
memcpy(arg.update_white_list.remote_bda, remote_bda, sizeof(esp_bd_addr_t));
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_get_whitelist_size(uint16_t *length)
|
|
|
|
{
|
|
|
|
if (length == NULL) {
|
|
|
|
return ESP_FAIL;
|
|
|
|
}
|
|
|
|
btc_get_whitelist_size(length);
|
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr,
|
|
|
|
uint16_t min_conn_int, uint16_t max_conn_int,
|
|
|
|
uint16_t slave_latency, uint16_t supervision_tout)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
|
|
|
|
|
|
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ESP_BLE_IS_VALID_PARAM(min_conn_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
|
|
|
|
ESP_BLE_IS_VALID_PARAM(max_conn_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
|
|
|
|
ESP_BLE_IS_VALID_PARAM(supervision_tout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) &&
|
2018-03-08 07:08:33 -05:00
|
|
|
(slave_latency <= ESP_BLE_CONN_LATENCY_MAX || slave_latency == ESP_BLE_CONN_PARAM_UNDEF) &&
|
|
|
|
((supervision_tout * 10) >= ((1 + slave_latency) * ((max_conn_int * 5) >> 1))) && min_conn_int <= max_conn_int) {
|
2017-08-14 23:24:36 -04:00
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_SET_CONN_PARAMS;
|
|
|
|
arg.set_conn_params.min_conn_int = min_conn_int;
|
|
|
|
arg.set_conn_params.max_conn_int = max_conn_int;
|
|
|
|
arg.set_conn_params.slave_latency = slave_latency;
|
|
|
|
arg.set_conn_params.supervision_tout = supervision_tout;
|
|
|
|
memcpy(arg.set_conn_params.bd_addr, bd_addr, sizeof(esp_bd_addr_t));
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
} else {
|
|
|
|
LOG_ERROR("%s,invalid connection params:min_int = %d, max_int = %d, latency = %d, timeout = %d",\
|
|
|
|
__func__, min_conn_int, max_conn_int, slave_latency, supervision_tout);
|
|
|
|
return ESP_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 01:58:30 -05:00
|
|
|
esp_err_t esp_ble_gap_set_device_name(const char *name)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2017-03-17 07:16:52 -04:00
|
|
|
return esp_bt_dev_set_device_name(name);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
2016-11-28 09:40:30 -05:00
|
|
|
uint8_t *esp_ble_resolve_adv_data( uint8_t *adv_data, uint8_t type, uint8_t *length)
|
2016-11-18 03:43:51 -05:00
|
|
|
{
|
2016-11-18 05:00:47 -05:00
|
|
|
if (((type < ESP_BLE_AD_TYPE_FLAG) || (type > ESP_BLE_AD_TYPE_128SERVICE_DATA)) &&
|
2016-11-24 13:10:15 -05:00
|
|
|
(type != ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE)) {
|
|
|
|
LOG_ERROR("the eir type not define, type = %x\n", type);
|
|
|
|
return NULL;
|
2016-11-18 03:43:51 -05:00
|
|
|
}
|
|
|
|
|
2016-11-28 09:40:30 -05:00
|
|
|
if (adv_data == NULL) {
|
2016-11-24 13:10:15 -05:00
|
|
|
LOG_ERROR("Invalid p_eir data.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-11-18 03:43:51 -05:00
|
|
|
|
2016-11-28 09:40:30 -05:00
|
|
|
return (BTM_CheckAdvData( adv_data, type, length));
|
2016-11-18 03:43:51 -05:00
|
|
|
}
|
|
|
|
|
2017-01-18 22:49:59 -05:00
|
|
|
esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_len)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-01-18 22:49:59 -05:00
|
|
|
|
|
|
|
if (raw_data == NULL
|
|
|
|
|| (raw_data_len <= 0 || raw_data_len > ESP_BLE_ADV_DATA_LEN_MAX)) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW;
|
|
|
|
arg.cfg_adv_data_raw.raw_adv = raw_data;
|
|
|
|
arg.cfg_adv_data_raw.raw_adv_len = raw_data_len;
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-14 23:24:36 -04:00
|
|
|
esp_err_t esp_ble_gap_read_rssi(esp_bd_addr_t remote_addr)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_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_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_READ_RSSI;
|
|
|
|
memcpy(arg.read_rssi.remote_addr, remote_addr, sizeof(esp_bd_addr_t));
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
|
|
|
|
2017-01-18 22:49:59 -05:00
|
|
|
esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-01-18 22:49:59 -05:00
|
|
|
|
|
|
|
if (raw_data == NULL
|
|
|
|
|| (raw_data_len <= 0 || raw_data_len > ESP_BLE_SCAN_RSP_DATA_LEN_MAX)) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW;
|
|
|
|
arg.cfg_scan_rsp_data_raw.raw_scan_rsp = raw_data;
|
|
|
|
arg.cfg_scan_rsp_data_raw.raw_scan_rsp_len = raw_data_len;
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
|
|
|
|
}
|
2017-04-13 10:14:28 -04:00
|
|
|
|
2017-09-14 09:01:12 -04:00
|
|
|
#if (SMP_INCLUDED == TRUE)
|
2017-04-13 10:14:28 -04:00
|
|
|
esp_err_t esp_ble_gap_set_security_param(esp_ble_sm_param_t param_type,
|
|
|
|
void *value, uint8_t len)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2017-04-13 10:14:28 -04:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_SET_SECURITY_PARAM_EVT;
|
|
|
|
arg.set_security_param.param_type = param_type;
|
|
|
|
arg.set_security_param.len = len;
|
|
|
|
arg.set_security_param.value = value;
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_set_encryption(esp_bd_addr_t bd_addr, esp_ble_sec_act_t sec_act)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2017-04-13 10:14:28 -04:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_SET_ENCRYPTION_EVT;
|
|
|
|
arg.set_encryption.sec_act = sec_act;
|
|
|
|
memcpy(arg.set_encryption.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gap_security_rsp(esp_bd_addr_t bd_addr, bool accept)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2017-04-13 10:14:28 -04:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_SECURITY_RSP_EVT;
|
|
|
|
arg.sec_rsp.accept = accept;
|
|
|
|
memcpy(arg.sec_rsp.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_passkey_reply(esp_bd_addr_t bd_addr, bool accept, uint32_t passkey)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2017-04-13 10:14:28 -04:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_PASSKEY_REPLY_EVT;
|
|
|
|
arg.enc_passkey_replay.accept = accept;
|
|
|
|
arg.enc_passkey_replay.passkey = passkey;
|
|
|
|
memcpy(arg.enc_passkey_replay.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_confirm_reply(esp_bd_addr_t bd_addr, bool accept)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-07-24 02:50:23 -04:00
|
|
|
|
2017-04-13 10:14:28 -04:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_CONFIRM_REPLY_EVT;
|
|
|
|
arg.enc_comfirm_replay.accept = accept;
|
|
|
|
memcpy(arg.enc_comfirm_replay.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
|
|
|
|
2017-08-09 04:46:49 -04:00
|
|
|
esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_REMOVE_BOND_DEV_EVT;
|
|
|
|
memcpy(arg.remove_bond_device.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
|
|
|
|
2017-08-28 05:14:49 -04:00
|
|
|
int esp_ble_get_bond_device_num(void)
|
2017-08-09 04:46:49 -04:00
|
|
|
{
|
2017-08-28 05:14:49 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-08-09 04:46:49 -04:00
|
|
|
|
2017-08-28 05:14:49 -04:00
|
|
|
return btc_storage_get_num_ble_bond_devices();
|
2017-08-09 04:46:49 -04:00
|
|
|
}
|
|
|
|
|
2017-08-28 05:14:49 -04:00
|
|
|
esp_err_t esp_ble_get_bond_device_list(int *dev_num, esp_ble_bond_dev_t *dev_list)
|
2017-08-09 04:46:49 -04:00
|
|
|
{
|
2017-08-28 05:14:49 -04:00
|
|
|
int ret;
|
|
|
|
int dev_num_total;
|
2017-08-09 04:46:49 -04:00
|
|
|
|
2017-08-28 05:14:49 -04:00
|
|
|
if (dev_num == NULL || dev_list == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
|
|
|
|
|
|
|
dev_num_total = btc_storage_get_num_ble_bond_devices();
|
|
|
|
if (*dev_num > dev_num_total) {
|
|
|
|
*dev_num = dev_num_total;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = btc_storage_get_bonded_ble_devices_list(dev_list, *dev_num);
|
|
|
|
|
|
|
|
return (ret == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2017-08-09 04:46:49 -04:00
|
|
|
}
|
2017-09-14 09:01:12 -04:00
|
|
|
#endif /* #if (SMP_INCLUDED == TRUE) */
|
2017-08-09 04:46:49 -04:00
|
|
|
|
2017-06-01 03:56:36 -04:00
|
|
|
esp_err_t esp_ble_gap_disconnect(esp_bd_addr_t remote_device)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gap_args_t arg;
|
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-06-01 03:56:36 -04:00
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GAP_BLE;
|
|
|
|
msg.act = BTC_GAP_BLE_DISCONNECT_EVT;
|
|
|
|
memcpy(arg.disconnect.remote_device, remote_device, ESP_BD_ADDR_LEN);
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-13 10:14:28 -04:00
|
|
|
|
|
|
|
|