Merge branch 'bugfix/btdm_sec_config' into 'master'

component/bt : fix btc security storage bug

See merge request !1161
pull/783/merge
Jiang Jiang Jian 2017-09-13 11:46:34 +08:00
commit ea7a09c3e4
14 zmienionych plików z 978 dodań i 893 usunięć

Wyświetl plik

@ -20,6 +20,7 @@
#include "bt_trace.h"
#include "btc_manage.h"
#include "btc_gap_ble.h"
#include "btc_ble_storage.h"
esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback)
@ -364,26 +365,32 @@ esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_clear_bond_device_list(void)
int esp_ble_get_bond_device_num(void)
{
btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_CLEAR_BOND_DEV_EVT;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
return (btc_transfer_context(&msg, NULL, 0, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
return btc_storage_get_num_ble_bond_devices();
}
esp_err_t esp_ble_get_bond_device_list(void)
esp_err_t esp_ble_get_bond_device_list(int *dev_num, esp_ble_bond_dev_t *dev_list)
{
btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_GET_BOND_DEV_EVT;
int ret;
int dev_num_total;
return (btc_transfer_context(&msg, NULL, 0, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
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);
}
esp_err_t esp_ble_gap_disconnect(esp_bd_addr_t remote_device)

Wyświetl plik

@ -95,8 +95,6 @@ typedef enum {
ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT, /*!< When set pkt lenght complete, the event comes */
ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT, /*!< When Enable/disable privacy on the local device complete, the event comes */
ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT, /*!< When remove the bond device complete, the event comes */
ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT, /*!< When clear the bond device clear complete, the event comes */
ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT, /*!< When get the bond device list complete, the event comes */
ESP_GAP_BLE_EVT_MAX,
} esp_gap_ble_cb_event_t;
@ -577,20 +575,6 @@ typedef union {
esp_bt_status_t status; /*!< Indicate the remove bond device operation success status */
esp_bd_addr_t bd_addr; /*!< The device address which has been remove from the bond list */
}remove_bond_dev_cmpl; /*!< Event parameter of ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT
*/
struct ble_clear_bond_dev_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate the clear bond device operation success status */
}clear_bond_dev_cmpl; /*!< Event parameter of ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT */
/**
* @brief ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT
*/
struct ble_get_bond_dev_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate the get bond device operation success status */
uint8_t dev_num; /*!< Indicate the get number device in the bond list */
esp_ble_bond_dev_t *bond_dev; /*!< the pointer to the bond device Structure */
}get_bond_dev_cmpl; /*!< Event parameter of ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT */
} esp_ble_gap_cb_param_t;
/**
@ -879,24 +863,30 @@ esp_err_t esp_ble_confirm_reply(esp_bd_addr_t bd_addr, bool accept);
esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr);
/**
* @brief Removes all of the device from the security database list of
* peer device. It manages unpairing event while connected.
* @brief Get the device number from the security database list of peer device.
* It will return the device bonded number immediately.
*
* @return - ESP_OK : success
* - other : failed
* @return - >= 0 : bonded devices number.
* - < 0 : failed
*
*/
esp_err_t esp_ble_clear_bond_device_list(void);
int esp_ble_get_bond_device_num(void);
/**
* @brief Get the device from the security database list of peer device.
* It will return the device bonded information from the ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT event.
* It will return the device bonded information immediately.
* @param[inout] dev_num: Indicate the dev_list array(buffer) size as input.
* If dev_num is large enough, it means the actual number as output.
* Suggest that dev_num value equal to esp_ble_get_bond_device_num().
*
* @return - ESP_OK : success
* - other : failed
* @param[out] dev_list: an array(buffer) of `esp_ble_bond_dev_t` type. Use for storing the bonded devices address.
* The dev_list should be allocated by who call this API.
* @return - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_get_bond_device_list(void);
esp_err_t esp_ble_get_bond_device_list(int *dev_num, esp_ble_bond_dev_t *dev_list);
/**
* @brief This function is to disconnect the physical connection of the peer device

Wyświetl plik

@ -33,49 +33,6 @@ static const char *CONFIG_FILE_PATH = "bt_config.conf";
static const period_ms_t CONFIG_SETTLE_PERIOD_MS = 3000;
static void btc_key_value_to_string(uint8_t *key_vaule, char *value_str, int key_length);
// TODO(zachoverflow): Move these two functions out, because they are too specific for this file
// {grumpy-cat/no, monty-python/you-make-me-sad}
bool btc_get_device_type(const BD_ADDR bd_addr, int *p_device_type)
{
if (p_device_type == NULL) {
return FALSE;
}
bt_bdaddr_t bda;
bdcpy(bda.address, bd_addr);
bdstr_t bd_addr_str;
bdaddr_to_string(&bda, bd_addr_str, sizeof(bd_addr_str));
if (!btc_config_get_int(bd_addr_str, BTC_LE_DEV_TYPE, p_device_type)) {
return FALSE;
}
LOG_DEBUG("%s: Device [%s] type %d\n", __FUNCTION__, bd_addr_str, *p_device_type);
return TRUE;
}
bool btc_get_address_type(const BD_ADDR bd_addr, int *p_addr_type)
{
if (p_addr_type == NULL) {
return FALSE;
}
bt_bdaddr_t bda;
bdcpy(bda.address, bd_addr);
bdstr_t bd_addr_str;
bdaddr_to_string(&bda, bd_addr_str, sizeof(bd_addr_str));
if (!btc_config_get_int(bd_addr_str, "AddrType", p_addr_type)) {
return FALSE;
}
LOG_DEBUG("%s: Device [%s] address type %d\n", __FUNCTION__, bd_addr_str, *p_addr_type);
return TRUE;
}
static osi_mutex_t lock; // protects operations on |config|.
static config_t *config;
@ -88,11 +45,9 @@ bool btc_compare_address_key_value(const char *section, char *key_type, void *ke
return false;
}
btc_key_value_to_string((uint8_t *)key_value, value_str, key_length);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
if ((status = config_has_key_in_section(config, key_type, value_str)) == true) {
config_remove_section(config, section);
}
osi_mutex_unlock(&lock);
return status;
}
@ -160,11 +115,7 @@ bool btc_config_has_section(const char *section)
assert(config != NULL);
assert(section != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
bool ret = config_has_section(config, section);
osi_mutex_unlock(&lock);
return ret;
return config_has_section(config, section);
}
bool btc_config_exist(const char *section, const char *key)
@ -173,11 +124,7 @@ bool btc_config_exist(const char *section, const char *key)
assert(section != NULL);
assert(key != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
bool ret = config_has_key(config, section, key);
osi_mutex_unlock(&lock);
return ret;
return config_has_key(config, section, key);
}
bool btc_config_get_int(const char *section, const char *key, int *value)
@ -187,12 +134,10 @@ bool btc_config_get_int(const char *section, const char *key, int *value)
assert(key != NULL);
assert(value != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
bool ret = config_has_key(config, section, key);
if (ret) {
*value = config_get_int(config, section, key, *value);
}
osi_mutex_unlock(&lock);
return ret;
}
@ -203,9 +148,7 @@ bool btc_config_set_int(const char *section, const char *key, int value)
assert(section != NULL);
assert(key != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
config_set_int(config, section, key, value);
osi_mutex_unlock(&lock);
return true;
}
@ -218,9 +161,7 @@ bool btc_config_get_str(const char *section, const char *key, char *value, int *
assert(value != NULL);
assert(size_bytes != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
const char *stored_value = config_get_string(config, section, key, NULL);
osi_mutex_unlock(&lock);
if (!stored_value) {
return false;
@ -239,9 +180,7 @@ bool btc_config_set_str(const char *section, const char *key, const char *value)
assert(key != NULL);
assert(value != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
config_set_string(config, section, key, value, false);
osi_mutex_unlock(&lock);
return true;
}
@ -254,9 +193,7 @@ bool btc_config_get_bin(const char *section, const char *key, uint8_t *value, si
assert(value != NULL);
assert(length != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
const char *value_str = config_get_string(config, section, key, NULL);
osi_mutex_unlock(&lock);
if (!value_str) {
return false;
@ -287,9 +224,7 @@ size_t btc_config_get_bin_length(const char *section, const char *key)
assert(section != NULL);
assert(key != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
const char *value_str = config_get_string(config, section, key, NULL);
osi_mutex_unlock(&lock);
if (!value_str) {
return 0;
@ -321,9 +256,7 @@ bool btc_config_set_bin(const char *section, const char *key, const uint8_t *val
str[(i * 2) + 1] = lookup[value[i] & 0x0F];
}
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
config_set_string(config, section, key, str, false);
osi_mutex_unlock(&lock);
osi_free(str);
return true;
@ -355,17 +288,15 @@ const char *btc_config_section_name(const btc_config_section_iter_t *section)
return config_section_name((const config_section_node_t *)section);
}
bool btc_config_remove(const char *section, const char *key)
{
assert(config != NULL);
assert(section != NULL);
assert(key != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
bool ret = config_remove_key(config, section, key);
osi_mutex_unlock(&lock);
return ret;
return config_remove_key(config, section, key);
}
bool btc_config_remove_section(const char *section)
@ -373,81 +304,37 @@ bool btc_config_remove_section(const char *section)
assert(config != NULL);
assert(section != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
bool ret = config_remove_section(config, section);
osi_mutex_unlock(&lock);
return ret;
}
void btc_config_save(void)
{
assert(config != NULL);
// Garbage collection process: the config file accumulates
// cached information about remote devices during regular
// inquiry scans. We remove some of these junk entries
// so the file doesn't grow indefinitely. We have to take care
// to make sure we don't remove information about bonded
// devices (hence the check for link keys).
static const size_t CACHE_MAX = 256;
const char *keys[CACHE_MAX];
size_t num_keys = 0;
size_t total_candidates = 0;
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
for (const config_section_node_t *snode = config_section_begin(config); snode != config_section_end(config); snode = config_section_next(snode)) {
const char *section = config_section_name(snode);
if (!string_is_bdaddr(section)) {
continue;
}
if (config_has_key(config, section, "LinkKey") ||
config_has_key(config, section, "LE_KEY_PENC") ||
config_has_key(config, section, "LE_KEY_PID") ||
config_has_key(config, section, "LE_KEY_PCSRK") ||
config_has_key(config, section, "LE_KEY_LENC") ||
config_has_key(config, section, "LE_KEY_LCSRK")) {
continue;
}
if (num_keys < CACHE_MAX) {
keys[num_keys++] = section;
}
++total_candidates;
}
if (total_candidates > CACHE_MAX * 2)
while (num_keys > 0) {
config_remove_section(config, keys[--num_keys]);
}
config_save(config, CONFIG_FILE_PATH);
osi_mutex_unlock(&lock);
return config_remove_section(config, section);
}
void btc_config_flush(void)
{
assert(config != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
config_save(config, CONFIG_FILE_PATH);
osi_mutex_unlock(&lock);
}
int btc_config_clear(void)
{
assert(config != NULL);
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
config_free(config);
config = config_new_empty();
if (config == NULL) {
osi_mutex_unlock(&lock);
return false;
}
int ret = config_save(config, CONFIG_FILE_PATH);
osi_mutex_unlock(&lock);
return ret;
}
void btc_config_lock(void)
{
osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
}
void btc_config_unlock(void)
{
osi_mutex_unlock(&lock);
}

Wyświetl plik

@ -38,6 +38,11 @@
** Static variables
******************************************************************************/
static tBTA_SERVICE_MASK btc_enabled_services = 0;
#if (SMP_INCLUDED == TRUE)
static btc_dm_pairing_cb_t pairing_cb;
static btc_dm_local_key_cb_t ble_local_key_cb;
#endif
/******************************************************************************
** Static functions
******************************************************************************/
@ -117,6 +122,110 @@ static void btc_disable_bluetooth_evt(void)
}
#if (SMP_INCLUDED == TRUE)
void btc_dm_load_ble_local_keys(void)
{
memset(&ble_local_key_cb, 0, sizeof(btc_dm_local_key_cb_t));
if (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS) {
ble_local_key_cb.is_er_rcvd = TRUE;
LOG_DEBUG("%s BLE ER key loaded",__func__ );
}
if ((btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&&
(btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&&
(btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0],
BT_OCTET16_LEN)== BT_STATUS_SUCCESS)) {
ble_local_key_cb.is_id_keys_rcvd = TRUE;
LOG_DEBUG("%s BLE ID keys loaded", __func__);
}
}
void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
{
if (ble_local_key_cb.is_er_rcvd ) {
memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16));
*p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
}
if (ble_local_key_cb.is_id_keys_rcvd) {
memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
*p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
}
LOG_DEBUG("%s *p_key_mask=0x%02x",__func__, *p_key_mask);
}
static void btc_dm_remove_ble_bonding_keys(void)
{
bt_bdaddr_t bd_addr;
LOG_DEBUG("%s\n",__func__);
bdcpy(bd_addr.address, pairing_cb.bd_addr);
btc_storage_remove_remote_addr_type(&bd_addr, false);
btc_storage_remove_ble_dev_type(&bd_addr, false);
btc_storage_remove_ble_bonding_keys(&bd_addr);
}
static void btc_dm_save_ble_bonding_keys(void)
{
bt_bdaddr_t bd_addr;
bdcpy(bd_addr.address, pairing_cb.bd_addr);
btc_storage_set_ble_dev_type(&bd_addr, false);
LOG_DEBUG("%s, penc = %d, pid = %d", __func__, pairing_cb.ble.is_penc_key_rcvd, pairing_cb.ble.is_pid_key_rcvd);
if (pairing_cb.ble.is_penc_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.penc_key,
BTM_LE_KEY_PENC,
sizeof(tBTM_LE_PENC_KEYS));
}
if (pairing_cb.ble.is_pid_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.pid_key,
BTM_LE_KEY_PID,
sizeof(tBTM_LE_PID_KEYS));
}
if (pairing_cb.ble.is_pcsrk_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.pcsrk_key,
BTM_LE_KEY_PCSRK,
sizeof(tBTM_LE_PCSRK_KEYS));
}
if (pairing_cb.ble.is_lenc_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.lenc_key,
BTM_LE_KEY_LENC,
sizeof(tBTM_LE_LENC_KEYS));
}
if (pairing_cb.ble.is_lcsrk_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
(char *) &pairing_cb.ble.lcsrk_key,
BTM_LE_KEY_LCSRK,
sizeof(tBTM_LE_LCSRK_KEYS));
}
if (pairing_cb.ble.is_lidk_key_rcvd) {
btc_storage_add_ble_bonding_key(&bd_addr,
NULL,
BTM_LE_KEY_LID,
0);
}
}
static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
{
/* Save link key, if not temporary */
@ -136,7 +245,7 @@ static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
(pairing_cb.bd_addr[0] << 24) + (pairing_cb.bd_addr[1] << 16) + (pairing_cb.bd_addr[2] << 8) + pairing_cb.bd_addr[3],
(pairing_cb.bd_addr[4] << 8) + pairing_cb.bd_addr[5]);
if (btc_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS) {
btc_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type);
btc_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type, true);
}
/* check the irk has been save in the flash or not, if the irk has already save, means that the peer device has bonding
before. */
@ -144,7 +253,7 @@ static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
btc_storage_compare_address_key_value(&bdaddr, BTM_LE_KEY_PID,
(void *)&pairing_cb.ble.pid_key, sizeof(tBTM_LE_PID_KEYS));
}
btc_save_ble_bonding_keys();
btc_dm_save_ble_bonding_keys();
} else {
/*Map the HCI fail reason to bt status */
switch (p_auth_cmpl->fail_reason) {
@ -358,7 +467,9 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
memcpy(bd_addr.address, p_data->link_down.bd_addr, sizeof(BD_ADDR));
btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
//remove the bonded key in the config and nvs flash.
//btc_storage_remove_ble_bonding_keys(&bd_addr);
btc_storage_remove_ble_dev_type(&bd_addr, false);
btc_storage_remove_remote_addr_type(&bd_addr, false);
btc_storage_remove_ble_bonding_keys(&bd_addr);
ble_msg.act = ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT;
param.remove_bond_dev_cmpl.status = (p_data->link_down.status == HCI_SUCCESS) ? ESP_BT_STATUS_SUCCESS : ESP_BT_STATUS_FAIL;
memcpy(param.remove_bond_dev_cmpl.bd_addr, p_data->link_down.bd_addr, sizeof(BD_ADDR));

Wyświetl plik

@ -43,11 +43,14 @@ bt_status_t btc_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
LOG_DEBUG("add to storage: Remote device:%s\n", bdstr);
int ret = btc_config_set_int(bdstr, "LinkKeyType", (int)key_type);
ret &= btc_config_set_int(bdstr, "PinLength", (int)pin_length);
ret &= btc_config_set_bin(bdstr, "LinkKey", link_key, sizeof(LINK_KEY));
btc_config_lock();
int ret = btc_config_set_int(bdstr, BTC_STORAGE_LINK_KEY_TYPE_STR, (int)key_type);
ret &= btc_config_set_int(bdstr, BTC_STORAGE_PIN_LENGTH_STR, (int)pin_length);
ret &= btc_config_set_bin(bdstr, BTC_STORAGE_LINK_KEY_STR, link_key, sizeof(LINK_KEY));
/* write bonded info immediately */
btc_config_flush();
btc_config_unlock();
LOG_DEBUG("Storage add rslt %d\n", ret);
return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
}
@ -66,6 +69,7 @@ static bt_status_t btc_in_fetch_bonded_devices(int add)
{
BOOLEAN bt_linkkey_file_found = FALSE;
btc_config_lock();
for (const btc_config_section_iter_t *iter = btc_config_section_begin(); iter != btc_config_section_end(); iter = btc_config_section_next(iter)) {
const char *name = btc_config_section_name(iter);
if (!string_is_bdaddr(name)) {
@ -75,21 +79,19 @@ static bt_status_t btc_in_fetch_bonded_devices(int add)
LOG_DEBUG("Remote device:%s\n", name);
LINK_KEY link_key;
size_t size = sizeof(link_key);
if (btc_config_get_bin(name, "LinkKey", link_key, &size)) {
if (btc_config_get_bin(name, BTC_STORAGE_LINK_KEY_STR, link_key, &size)) {
int linkkey_type;
if (btc_config_get_int(name, "LinkKeyType", &linkkey_type)) {
//int pin_len;
//btc_config_get_int(name, "PinLength", &pin_len))
if (btc_config_get_int(name, BTC_STORAGE_LINK_KEY_TYPE_STR, &linkkey_type)) {
bt_bdaddr_t bd_addr;
string_to_bdaddr(name, &bd_addr);
if (add) {
DEV_CLASS dev_class = {0, 0, 0};
int cod;
int pin_length = 0;
if (btc_config_get_int(name, "DevClass", &cod)) {
if (btc_config_get_int(name, BTC_STORAGE_DEV_CLASS_STR, &cod)) {
uint2devclass((UINT32)cod, dev_class);
}
btc_config_get_int(name, "PinLength", &pin_length);
btc_config_get_int(name, BTC_STORAGE_PIN_LENGTH_STR, &pin_length);
#if (SMP_INCLUDED == TRUE)
BTA_DmAddDevice(bd_addr.address, dev_class, link_key, 0, 0,
(UINT8)linkkey_type, 0, pin_length);
@ -104,6 +106,8 @@ static bt_status_t btc_in_fetch_bonded_devices(int add)
LOG_DEBUG("Remote device:%s, no link key\n", name);
}
}
btc_config_unlock();
return BT_STATUS_SUCCESS;
}
@ -142,19 +146,22 @@ bt_status_t btc_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr)
{
bdstr_t bdstr;
bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
int ret = 1;
LOG_DEBUG("Add to storage: Remote device:%s\n", bdstr);
int ret = 1;
if (btc_config_exist(bdstr, "LinkKeyType")) {
ret &= btc_config_remove(bdstr, "LinkKeyType");
btc_config_lock();
if (btc_config_exist(bdstr, BTC_STORAGE_LINK_KEY_TYPE_STR)) {
ret &= btc_config_remove(bdstr, BTC_STORAGE_LINK_KEY_TYPE_STR);
}
if (btc_config_exist(bdstr, "PinLength")) {
ret &= btc_config_remove(bdstr, "PinLength");
if (btc_config_exist(bdstr, BTC_STORAGE_PIN_LENGTH_STR)) {
ret &= btc_config_remove(bdstr, BTC_STORAGE_PIN_LENGTH_STR);
}
if (btc_config_exist(bdstr, "LinkKey")) {
ret &= btc_config_remove(bdstr, "LinkKey");
if (btc_config_exist(bdstr, BTC_STORAGE_LINK_KEY_STR)) {
ret &= btc_config_remove(bdstr, BTC_STORAGE_LINK_KEY_STR);
}
/* write bonded info immediately */
btc_config_flush();
btc_config_unlock();
return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
}

Wyświetl plik

@ -23,52 +23,25 @@
#define BTC_LE_LOCAL_KEY_DHK (1<<2)
#define BTC_LE_LOCAL_KEY_ER (1<<3)
#define BTC_BLE_STORAGE_DEV_TYPE_STR "DevType"
#define BTC_BLE_STORAGE_ADDR_TYPE_STR "AddrType"
#define BTC_BLE_STORAGE_LINK_KEY_STR "LinkKey"
#define BTC_BLE_STORAGE_LE_KEY_PENC_STR "LE_KEY_PENC"
#define BTC_BLE_STORAGE_LE_KEY_PID_STR "LE_KEY_PID"
#define BTC_BLE_STORAGE_LE_KEY_PCSRK_STR "LE_KEY_PCSRK"
#define BTC_BLE_STORAGE_LE_KEY_LENC_STR "LE_KEY_LENC"
#define BTC_BLE_STORAGE_LE_KEY_LID_STR "LE_KEY_LID"
#define BTC_BLE_STORAGE_LE_KEY_LCSRK_STR "LE_KEY_LCSRK"
#define BTC_BLE_STORAGE_LOCAL_ADAPTER_STR "Adapter"
#define BTC_BLE_STORAGE_LE_LOCAL_KEY_IR_STR "LE_LOCAL_KEY_IR"
#define BTC_BLE_STORAGE_LE_LOCAL_KEY_IRK_STR "LE_LOCAL_KEY_IRK"
#define BTC_BLE_STORAGE_LE_LOCAL_KEY_DHK_STR "LE_LOCAL_KEY_DHK"
#define BTC_BLE_STORAGE_LE_LOCAL_KEY_ER_STR "LE_LOCAL_KEY_ER"
/************************************************************************************
** Local type definitions
************************************************************************************/
typedef struct
{
uint32_t num_devices;
bt_bdaddr_t devices[BTM_SEC_MAX_DEVICE_RECORDS];
} btc_bonded_devices_t;
typedef struct
{
bool is_penc_key_rcvd;
tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */
bool is_pcsrk_key_rcvd;
tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */
bool is_pid_key_rcvd;
tBTM_LE_PID_KEYS pid_key; /* peer device ID key */
bool is_lenc_key_rcvd;
tBTM_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
bool is_lcsrk_key_rcvd;
tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
bool is_lidk_key_rcvd; /* local identity key received */
} btc_dm_ble_cb_t;
typedef struct
{
bt_bdaddr_t static_bdaddr;
BD_ADDR bd_addr;
btc_dm_ble_cb_t ble;
} btc_dm_pairing_cb_t;
typedef struct
{
uint8_t ir[BT_OCTET16_LEN];
uint8_t irk[BT_OCTET16_LEN];
uint8_t dhk[BT_OCTET16_LEN];
}btc_dm_local_key_id_t;
typedef struct
{
bool is_er_rcvd;
uint8_t er[BT_OCTET16_LEN];
bool is_id_keys_rcvd;
btc_dm_local_key_id_t id_keys; /* ID kyes */
}btc_dm_local_key_cb_t;
typedef struct
{
BT_OCTET16 sp_c;
@ -77,63 +50,37 @@ typedef struct
} btc_dm_oob_cb_t;
extern btc_dm_pairing_cb_t pairing_cb;
extern btc_dm_local_key_cb_t ble_local_key_cb;
extern btc_bonded_devices_t bonded_devices;
void btc_storage_save(void);
bt_status_t btc_storage_load_bonded_ble_devices(void);
bt_status_t btc_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr, char *key, uint8_t key_type, uint8_t key_length);
bt_status_t btc_get_bonded_ble_devices_list(esp_ble_bond_dev_t *bond_dev);
bt_status_t btc_in_fetch_bonded_ble_devices(int add);
void btc_dm_remove_ble_bonding_keys(void);
bt_status_t btc_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr,
char *key,
uint8_t key_type,
uint8_t key_length);
bool btc_compare_le_key_value(const uint8_t key_type, const size_t key_len, const tBTA_LE_KEY_VALUE *key_vaule,
bt_bdaddr_t bd_addr);
void btc_save_ble_bonding_keys(void);
bt_status_t btc_in_fetch_bonded_ble_device(const char *remote_bd_addr, int add,
btc_bonded_devices_t *p_bonded_devices);
bt_status_t btc_storage_get_ble_bonding_key(bt_bdaddr_t *remote_bd_addr,
uint8_t key_type,
char *key_value,
int key_length);
bool btc_storage_compare_address_key_value(bt_bdaddr_t *remote_bd_addr,
uint8_t key_type, void *key_value, int key_length);
bt_status_t btc_storage_add_ble_local_key(char *key,
uint8_t key_type,
uint8_t key_length);
bt_status_t btc_storage_get_ble_bonding_key(bt_bdaddr_t *remote_bd_addr, uint8_t key_type, char *key_value, int key_length);
bt_status_t btc_storage_remove_ble_bonding_keys(bt_bdaddr_t *remote_bd_addr);
bt_status_t btc_storage_clear_bond_devices(void);
bool btc_storage_compare_address_key_value(bt_bdaddr_t *remote_bd_addr, uint8_t key_type, void *key_value, int key_length);
bt_status_t btc_storage_add_ble_local_key(char *key, uint8_t key_type, uint8_t key_length);
bt_status_t btc_storage_remove_ble_local_keys(void);
bt_status_t btc_storage_get_ble_local_key(uint8_t key_type,
char *key_value,
int key_len);
bt_status_t btc_storage_get_ble_local_key(uint8_t key_type, char *key_value, int key_len);
bt_status_t btc_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr,
int *addr_type);
bt_status_t btc_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr, int *addr_type);
bt_status_t btc_storage_set_remote_addr_type(bt_bdaddr_t *remote_bd_addr, uint8_t addr_type, bool flush);
bt_status_t btc_storage_remove_remote_addr_type(bt_bdaddr_t *remote_bd_addr, bool flush);
bt_status_t btc_storage_set_ble_dev_type(bt_bdaddr_t *bd_addr, bool flush);
bt_status_t btc_storage_remove_ble_dev_type(bt_bdaddr_t *remote_bd_addr, bool flush);
bt_status_t btc_storage_load_bonded_ble_devices(void);
bt_status_t btc_storage_get_bonded_ble_devices_list(esp_ble_bond_dev_t *bond_dev, int dev_num);
int btc_storage_get_num_ble_bond_devices(void);
bt_status_t btc_storage_set_remote_addr_type(bt_bdaddr_t *remote_bd_addr,
uint8_t addr_type);
void btc_dm_load_ble_local_keys(void);
void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
tBTA_BLE_LOCAL_ID_KEYS *p_id_keys);
#endif ///SMP_INCLUDED == TRUE
#endif ///__BTC_BLE_STORAGE_H__
#endif ///__BTC_BLE_STORAGE_H__

Wyświetl plik

@ -20,8 +20,6 @@
#include "bt_types.h"
#define BTC_LE_DEV_TYPE "DevType"
typedef struct btc_config_section_iter_t btc_config_section_iter_t;
bool btc_config_init(void);
@ -46,7 +44,6 @@ const btc_config_section_iter_t *btc_config_section_end(void);
const btc_config_section_iter_t *btc_config_section_next(const btc_config_section_iter_t *section);
const char *btc_config_section_name(const btc_config_section_iter_t *section);
void btc_config_save(void);
void btc_config_flush(void);
int btc_config_clear(void);
@ -55,4 +52,7 @@ bool btc_get_address_type(const BD_ADDR bd_addr, int *p_addr_type);
bool btc_compare_address_key_value(const char *section, char *key_type, void *key_value, int key_length);
bool btc_get_device_type(const BD_ADDR bd_addr, int *p_device_type);
void btc_config_lock(void);
void btc_config_unlock(void);
#endif

Wyświetl plik

@ -29,6 +29,45 @@ typedef union {
tBTA_DM_SEC sec;
} btc_dm_sec_args_t;
typedef struct
{
bool is_penc_key_rcvd;
tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */
bool is_pcsrk_key_rcvd;
tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */
bool is_pid_key_rcvd;
tBTM_LE_PID_KEYS pid_key; /* peer device ID key */
bool is_lenc_key_rcvd;
tBTM_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
bool is_lcsrk_key_rcvd;
tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
bool is_lidk_key_rcvd; /* local identity key received */
} btc_dm_ble_cb_t;
typedef struct
{
bt_bdaddr_t static_bdaddr;
BD_ADDR bd_addr;
btc_dm_ble_cb_t ble;
} btc_dm_pairing_cb_t;
typedef struct
{
uint8_t ir[BT_OCTET16_LEN];
uint8_t irk[BT_OCTET16_LEN];
uint8_t dhk[BT_OCTET16_LEN];
} btc_dm_local_key_id_t;
typedef struct
{
bool is_er_rcvd;
uint8_t er[BT_OCTET16_LEN];
bool is_id_keys_rcvd;
btc_dm_local_key_id_t id_keys; /* ID kyes */
} btc_dm_local_key_cb_t;
// void btc_dm_call_handler(btc_msg_t *msg);
void btc_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *data);
void btc_dm_sec_cb_handler(btc_msg_t *msg);
@ -37,4 +76,11 @@ void btc_dm_sec_arg_deep_copy(btc_msg_t *msg, void *dst, void *src);
bt_status_t btc_dm_enable_service(tBTA_SERVICE_ID service_id);
bt_status_t btc_dm_disable_service(tBTA_SERVICE_ID service_id);
#if (SMP_INCLUDED == TRUE)
void btc_dm_load_ble_local_keys(void);
void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
tBTA_BLE_LOCAL_ID_KEYS *p_id_keys);
#endif
#endif /* __BTC_DM_H__ */

Wyświetl plik

@ -19,6 +19,12 @@
#include "bt_defs.h"
#include "bt_types.h"
#define BTC_STORAGE_DEV_CLASS_STR "DevClass"
#define BTC_STORAGE_LINK_KEY_STR "LinkKey" /* same as the ble */
#define BTC_STORAGE_LINK_KEY_TYPE_STR "LinkKeyType"
#define BTC_STORAGE_PIN_LENGTH_STR "PinLength"
/*******************************************************************************
**
** Function btc_storage_add_bonded_device

Wyświetl plik

@ -26,6 +26,7 @@
#include "esp_bt_defs.h"
#include "esp_gap_ble_api.h"
#include "btc_ble_storage.h"
#include "btc_dm.h"
static tBTA_BLE_ADV_DATA gl_bta_adv_data;
static tBTA_BLE_ADV_DATA gl_bta_scan_rsp_data;
@ -793,71 +794,6 @@ static void btc_ble_set_rand_addr (BD_ADDR rand_addr)
}
}
#if (SMP_INCLUDED)
static void btc_ble_remove_bond_device(esp_bt_status_t status)
{
int ret;
esp_ble_gap_cb_param_t param;
btc_msg_t msg;
param.remove_bond_dev_cmpl.status = status;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed", __func__);
}
}
static void btc_ble_clear_bond_device(void)
{
int ret;
esp_ble_gap_cb_param_t param;
btc_msg_t msg;
ret = btc_storage_clear_bond_devices();
param.clear_bond_dev_cmpl.status = ret;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed", __func__);
}
}
static void btc_ble_get_bond_device_list(void)
{
int ret;
esp_ble_gap_cb_param_t param;
esp_ble_bond_dev_t *bond_dev;
btc_msg_t msg;
int num_dev = btc_storage_get_num_ble_bond_devices();
bond_dev = (esp_ble_bond_dev_t *)osi_malloc(sizeof(esp_ble_bond_dev_t)*num_dev);
param.get_bond_dev_cmpl.status = btc_get_bonded_ble_devices_list(bond_dev);
param.get_bond_dev_cmpl.dev_num = num_dev;
param.get_bond_dev_cmpl.bond_dev = bond_dev;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT;
ret = btc_transfer_context(&msg, &param, sizeof(esp_ble_gap_cb_param_t), btc_gap_ble_cb_deep_copy);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed", __func__);
}
// release the buffer after used.
osi_free(bond_dev);
}
#endif /* #if (SMP_INCLUDED) */
static void btc_ble_config_local_privacy(bool privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback)
{
BTA_DmBleConfigLocalPrivacy(privacy_enable, set_local_privacy_cback);
@ -954,21 +890,6 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
void btc_gap_ble_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
switch (msg->act) {
case ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT: {
esp_ble_gap_cb_param_t *src = (esp_ble_gap_cb_param_t *)p_src;
esp_ble_gap_cb_param_t *dst = (esp_ble_gap_cb_param_t *)p_dest;
uint16_t length = 0;
if (src->get_bond_dev_cmpl.bond_dev) {
length = (src->get_bond_dev_cmpl.dev_num)*sizeof(esp_ble_bond_dev_t);
dst->get_bond_dev_cmpl.bond_dev = (esp_ble_bond_dev_t *)osi_malloc(length);
if (dst->get_bond_dev_cmpl.bond_dev != NULL) {
memcpy(dst->get_bond_dev_cmpl.bond_dev, src->get_bond_dev_cmpl.bond_dev, length);
} else {
LOG_ERROR("%s %d no mem", __func__, msg->act);
}
}
break;
}
default:
LOG_ERROR("%s, Unhandled deep copy %d\n", __func__, msg->act);
break;
@ -1018,13 +939,6 @@ void btc_gap_ble_cb_deep_free(btc_msg_t *msg)
{
LOG_DEBUG("%s", __func__);
switch (msg->act) {
case ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT: {
esp_ble_bond_dev_t *bond_dev = ((esp_ble_gap_cb_param_t *)msg->arg)->get_bond_dev_cmpl.bond_dev;
if (bond_dev) {
osi_free(bond_dev);
}
break;
}
default:
LOG_DEBUG("Unhandled deep free %d", msg->act);
break;
@ -1158,24 +1072,10 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
}
case BTC_GAP_BLE_REMOVE_BOND_DEV_EVT: {
BD_ADDR bd_addr;
bt_bdaddr_t bt_addr;
memcpy(bd_addr, arg->remove_bond_device.bd_addr, sizeof(BD_ADDR));
memcpy(bt_addr.address, arg->remove_bond_device.bd_addr, sizeof(bt_bdaddr_t));
LOG_DEBUG("BTC_GAP_BLE_REMOVE_BOND_DEV_EVT");
if (btc_storage_remove_ble_bonding_keys(&bt_addr) == BT_STATUS_SUCCESS) {
BTA_DmRemoveDevice(bd_addr);
} else {
LOG_ERROR("remove device failed: the address[%x:%x:%x:%x:%x:%x] didn't in the bonding list", bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]);
btc_ble_remove_bond_device(ESP_BT_STATUS_FAIL);
}
BTA_DmRemoveDevice(bd_addr);
break;
}
case BTC_GAP_BLE_CLEAR_BOND_DEV_EVT:
btc_ble_clear_bond_device();
break;
case BTC_GAP_BLE_GET_BOND_DEV_EVT:
btc_ble_get_bond_device_list();
break;
#endif ///SMP_INCLUDED == TRUE
case BTC_GAP_BLE_DISCONNECT_EVT:
btc_ble_disconnect(arg->disconnect.remote_device);

Wyświetl plik

@ -41,8 +41,6 @@ typedef enum {
BTC_GAP_BLE_CONFIRM_REPLY_EVT,
BTC_GAP_BLE_DISCONNECT_EVT,
BTC_GAP_BLE_REMOVE_BOND_DEV_EVT,
BTC_GAP_BLE_CLEAR_BOND_DEV_EVT,
BTC_GAP_BLE_GET_BOND_DEV_EVT,
} btc_gap_ble_act_t;
/* btc_ble_gap_args_t */

Wyświetl plik

@ -22,7 +22,7 @@
#include "bta_sys.h"
#include "bta_dm_co.h"
#include "bta_dm_ci.h"
#include "btc_ble_storage.h"
#include "btc_dm.h"
#if (defined(BTIF_INCLUDED) && BTIF_INCLUDED == TRUE)
#include "bt_utils.h"
#if (BTM_OOB_INCLUDED == TRUE)

Wyświetl plik

@ -233,6 +233,35 @@ static char *esp_key_type_to_str(esp_ble_key_type_t key_type)
return key_str;
}
static void show_bonded_devices(void)
{
int dev_num = esp_ble_get_bond_device_num();
esp_ble_bond_dev_t *dev_list = (esp_ble_bond_dev_t *)malloc(sizeof(esp_ble_bond_dev_t) * dev_num);
esp_ble_get_bond_device_list(&dev_num, dev_list);
ESP_LOGI(GATTS_TABLE_TAG, "Bonded devices number : %d\n", dev_num);
ESP_LOGI(GATTS_TABLE_TAG, "Bonded devices list : %d\n", dev_num);
for (int i = 0; i < dev_num; i++) {
esp_log_buffer_hex(GATTS_TABLE_TAG, (void *)dev_list[i].bd_addr, sizeof(esp_bd_addr_t));
}
free(dev_list);
}
static void __attribute__((unused)) remove_all_bonded_devices(void)
{
int dev_num = esp_ble_get_bond_device_num();
esp_ble_bond_dev_t *dev_list = (esp_ble_bond_dev_t *)malloc(sizeof(esp_ble_bond_dev_t) * dev_num);
esp_ble_get_bond_device_list(&dev_num, dev_list);
for (int i = 0; i < dev_num; i++) {
esp_ble_remove_bond_device(dev_list[i].bd_addr);
}
free(dev_list);
}
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
{
ESP_LOGV(GATTS_TABLE_TAG, "GAP_EVT, event %d\n", event);
@ -279,23 +308,15 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
(bd_addr[4] << 8) + bd_addr[5]);
ESP_LOGI(GATTS_TABLE_TAG, "address type = %d", param->ble_security.auth_cmpl.addr_type);
ESP_LOGI(GATTS_TABLE_TAG, "pair status = %s",param->ble_security.auth_cmpl.success ? "success" : "fail");
show_bonded_devices();
break;
}
case ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT: {
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT status = %d", param->remove_bond_dev_cmpl.status);
break;
}
case ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT: {
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT status = %d", param->clear_bond_dev_cmpl.status);
break;
}
case ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT: {
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT status = %d, num = %d", param->get_bond_dev_cmpl.status, param->get_bond_dev_cmpl.dev_num);
esp_ble_bond_dev_t *bond_dev = param->get_bond_dev_cmpl.bond_dev;
for(int i = 0; i < param->get_bond_dev_cmpl.dev_num; i++) {
ESP_LOGI(GATTS_TABLE_TAG, "mask = %x", bond_dev[i].bond_key.key_mask);
esp_log_buffer_hex(GATTS_TABLE_TAG, (void *)bond_dev[i].bd_addr, sizeof(esp_bd_addr_t));
}
ESP_LOGD(GATTS_TABLE_TAG, "ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT status = %d", param->remove_bond_dev_cmpl.status);
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_REMOVE_BOND_DEV");
ESP_LOGI(GATTS_TABLE_TAG, "-----ESP_GAP_BLE_REMOVE_BOND_DEV----");
esp_log_buffer_hex(GATTS_TABLE_TAG, (void *)param->remove_bond_dev_cmpl.bd_addr, sizeof(esp_bd_addr_t));
ESP_LOGI(GATTS_TABLE_TAG, "------------------------------------");
break;
}
case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT:
@ -493,6 +514,12 @@ void app_main()
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &init_key, sizeof(uint8_t));
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &rsp_key, sizeof(uint8_t));
/* Just show how to clear all the bonded devices
* Delay 30s, clear all the bonded devices
*
* vTaskDelay(30000 / portTICK_PERIOD_MS);
* remove_all_bonded_devices();
*/
}