Skip to content

Commit

Permalink
Merge branch 'bugfix/add_clear_bond_complete_evt_4_2' into 'release/v…
Browse files Browse the repository at this point in the history
…4.2'

componenet_bt/bugfix: add remove bond device complete event 4.2

See merge request espressif/esp-idf!10651
  • Loading branch information
jack0c committed Sep 29, 2020
2 parents 61e6e71 + 2d90885 commit 17fca62
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 34 deletions.
37 changes: 37 additions & 0 deletions components/bt/common/btc/core/btc_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ static bt_status_t btc_task_post(btc_msg_t *msg, uint32_t timeout)
return BT_STATUS_SUCCESS;
}

/**
* transfer an message to another module in the different task.
* @param msg message
* @param arg paramter
* @param arg_len length of paramter
* @param copy_func deep copy function
* @return BT_STATUS_SUCCESS: success
* others: fail
*/
bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func)
{
btc_msg_t lmsg;
Expand Down Expand Up @@ -214,6 +223,34 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg

}

/**
* transfer an message to another module in tha same task.
* @param msg message
* @param arg paramter
* @return BT_STATUS_SUCCESS: success
* others: fail
*/
bt_status_t btc_inter_profile_call(btc_msg_t *msg, void *arg)
{
if (msg == NULL) {
return BT_STATUS_PARM_INVALID;
}

msg->arg = arg;
switch (msg->sig) {
case BTC_SIG_API_CALL:
profile_tab[msg->pid].btc_call(msg);
break;
case BTC_SIG_API_CB:
profile_tab[msg->pid].btc_cb(msg);
break;
default:
break;
}
return BT_STATUS_SUCCESS;
}


#if BTC_DYNAMIC_MEMORY

static void btc_deinit_mem(void) {
Expand Down
18 changes: 18 additions & 0 deletions components/bt/common/btc/include/btc/btc_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,26 @@ typedef struct {

typedef void (* btc_arg_deep_copy_t)(btc_msg_t *msg, void *dst, void *src);

/**
* transfer an message to another module in the different task.
* @param msg message
* @param arg paramter
* @param arg_len length of paramter
* @param copy_func deep copy function
* @return BT_STATUS_SUCCESS: success
* others: fail
*/
bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func);

/**
* transfer an message to another module in tha same task.
* @param msg message
* @param arg paramter
* @return BT_STATUS_SUCCESS: success
* others: fail
*/
bt_status_t btc_inter_profile_call(btc_msg_t *msg, void *arg);

bt_status_t btc_init(void);
void btc_deinit(void);
bool btc_check_queue_is_congest(void);
Expand Down
9 changes: 9 additions & 0 deletions components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ typedef enum {
ESP_BT_GAP_CONFIG_EIR_DATA_EVT, /*!< config EIR data event */
ESP_BT_GAP_SET_AFH_CHANNELS_EVT, /*!< set AFH channels event */
ESP_BT_GAP_READ_REMOTE_NAME_EVT, /*!< read Remote Name event */
ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT, /*!< remove bond device complete event */
ESP_BT_GAP_EVT_MAX,
} esp_bt_gap_cb_event_t;

Expand Down Expand Up @@ -336,6 +337,14 @@ typedef union {
uint8_t rmt_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1]; /*!< Remote device name */
} read_rmt_name; /*!< read Remote Name parameter struct */

/**
* @brief ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT
*/
struct bt_remove_bond_dev_cmpl_evt_param {
esp_bd_addr_t bda; /*!< remote bluetooth device address*/
esp_bt_status_t status; /*!< Indicate the remove bond device operation success status */
}remove_bond_dev_cmpl; /*!< Event parameter of ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT */

} esp_bt_gap_cb_param_t;

/**
Expand Down
11 changes: 7 additions & 4 deletions components/bt/host/bluedroid/bta/dm/bta_dm_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,11 +990,14 @@ void bta_dm_remove_device(tBTA_DM_MSG *p_data)
/* Take the link down first, and mark the device for removal when disconnected */
for (int i = 0; i < bta_dm_cb.device_list.count; i++) {
if (!bdcmp(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_dev->bd_addr)
&& bta_dm_cb.device_list.peer_device[i].transport == transport) {
#if BLE_INCLUDED == TRUE
&& bta_dm_cb.device_list.peer_device[i].transport == transport
#endif
) {

bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING;
btm_remove_acl( p_dev->bd_addr, bta_dm_cb.device_list.peer_device[i].transport);
APPL_TRACE_DEBUG("%s:transport = %d", __func__,
bta_dm_cb.device_list.peer_device[i].transport);
btm_remove_acl( p_dev->bd_addr, transport);
APPL_TRACE_DEBUG("%s:transport = %d", __func__, transport);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/bt/host/bluedroid/bta/include/bta/bta_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ typedef union {
tBTA_DM_PIN_REQ pin_req; /* PIN request. */
tBTA_DM_AUTH_CMPL auth_cmpl; /* Authentication complete indication. */
tBTA_DM_AUTHORIZE authorize; /* Authorization request. */
tBTA_DM_LINK_UP link_up; /* ACL connection down event */
tBTA_DM_LINK_UP link_up; /* ACL connection up event */
tBTA_DM_LINK_DOWN link_down; /* ACL connection down event */
tBTA_DM_BUSY_LEVEL busy_level; /* System busy level */
tBTA_DM_SP_CFM_REQ cfm_req; /* user confirm request */
Expand Down
71 changes: 42 additions & 29 deletions components/bt/host/bluedroid/btc/core/btc_dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "common/bt_target.h"
#include "btc/btc_storage.h"
#include "btc/btc_ble_storage.h"
#include "esp_gap_ble_api.h"
#include "btc_gap_ble.h"
#include "btm_int.h"
#include "bta/bta_api.h"
#include "bta/bta_gatt_api.h"
Expand Down Expand Up @@ -408,11 +408,10 @@ static void btc_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
memcpy(param.auth_cmpl.bda, p_auth_cmpl->bd_addr, ESP_BD_ADDR_LEN);
memcpy(param.auth_cmpl.device_name, p_auth_cmpl->bd_name, ESP_BT_GAP_MAX_BDNAME_LEN + 1);

ret = btc_transfer_context(&msg, &param,
sizeof(esp_bt_gap_cb_param_t), NULL);
ret = btc_inter_profile_call(&msg, &param);

if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
}

#endif /// BTC_GAP_BT_INCLUDED == TRUE
Expand All @@ -431,11 +430,10 @@ static void btc_dm_pin_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
param.pin_req.min_16_digit = p_pin_req->min_16_digit;
memcpy(param.pin_req.bda, p_pin_req->bd_addr, ESP_BD_ADDR_LEN);

ret = btc_transfer_context(&msg, &param,
sizeof(esp_bt_gap_cb_param_t), NULL);
ret = btc_inter_profile_call(&msg, &param);

if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
}
#endif /// BTC_GAP_BT_INCLUDED == TRUE
}
Expand All @@ -459,11 +457,10 @@ static void btc_dm_sp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_cfm_req)
param.cfm_req.num_val = p_cfm_req->num_val;
memcpy(param.cfm_req.bda, p_cfm_req->bd_addr, ESP_BD_ADDR_LEN);

ret = btc_transfer_context(&msg, &param,
sizeof(esp_bt_gap_cb_param_t), NULL);
ret = btc_inter_profile_call(&msg, &param);

if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
}
#endif /// BTC_GAP_BT_INCLUDED == TRUE
}
Expand All @@ -480,11 +477,10 @@ static void btc_dm_sp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_key_notif)
param.key_notif.passkey = p_key_notif->passkey;
memcpy(param.key_notif.bda, p_key_notif->bd_addr, ESP_BD_ADDR_LEN);

ret = btc_transfer_context(&msg, &param,
sizeof(esp_bt_gap_cb_param_t), NULL);
ret = btc_inter_profile_call(&msg, &param);

if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
}
#endif /// BTC_GAP_BT_INCLUDED == TRUE
}
Expand All @@ -500,16 +496,43 @@ static void btc_dm_sp_key_req_evt(tBTA_DM_SP_KEY_REQ *p_key_req)
msg.act = BTC_GAP_BT_KEY_REQ_EVT;
memcpy(param.key_req.bda, p_key_req->bd_addr, ESP_BD_ADDR_LEN);

ret = btc_transfer_context(&msg, &param,
sizeof(esp_bt_gap_cb_param_t), NULL);
ret = btc_inter_profile_call(&msg, &param);

if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
}
#endif /// BTC_GAP_BT_INCLUDED == TRUE
}
#endif /// BT_SSP_INCLUDED == TRUE

static void btc_dm_dev_unpaired_evt(tBTA_DM_LINK_DOWN *p_link_down)
{
esp_bt_gap_cb_param_t param;
BTC_TRACE_DEBUG("%s",__func__);
memcpy(param.remove_bond_dev_cmpl.bda, p_link_down->bd_addr, ESP_BD_ADDR_LEN);
btm_set_bond_type_dev(p_link_down->bd_addr, BOND_TYPE_UNKNOWN);
if (p_link_down->status == HCI_SUCCESS) {
//remove the bonded key in the config and nvs flash.
param.remove_bond_dev_cmpl.status = btc_storage_remove_bonded_device((bt_bdaddr_t *)param.remove_bond_dev_cmpl.bda);
} else {
param.remove_bond_dev_cmpl.status = ESP_BT_STATUS_FAIL;
}

#if (BTC_GAP_BT_INCLUDED == TRUE)
bt_status_t ret;
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BT;
msg.act = BTC_GAP_BT_REMOVE_BOND_DEV_COMPLETE_EVT;

ret = btc_inter_profile_call(&msg, &param);

if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
}
#endif /// BTC_GAP_BT_INCLUDED == TRUE
}

tBTA_SERVICE_MASK btc_get_enabled_services_mask(void)
{
return btc_dm_cb.btc_enabled_services;
Expand Down Expand Up @@ -654,16 +677,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
#endif ///BT_SSP_INCLUDED == TRUE

case BTA_DM_DEV_UNPAIRED_EVT: {
#if (SMP_INCLUDED == TRUE)
bt_bdaddr_t bd_addr;
BTC_TRACE_DEBUG("BTA_DM_DEV_UNPAIRED_EVT");
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);
if (p_data->link_down.status == HCI_SUCCESS) {
//remove the bonded key in the config and nvs flash.
btc_storage_remove_bonded_device(&bd_addr);
}
#endif /* #if (SMP_INCLUDED == TRUE) */
btc_dm_dev_unpaired_evt(&p_data->link_down);
break;
}
#if (BLE_INCLUDED == TRUE)
Expand Down Expand Up @@ -868,11 +882,10 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
}

if (rsp_app) {
ret = btc_transfer_context(&ble_msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
ret = btc_inter_profile_call(&ble_msg, &param);

if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
}
}
btc_dm_sec_arg_deep_free(msg);
Expand Down
5 changes: 5 additions & 0 deletions components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ void btc_gap_bt_cb_deep_free(btc_msg_t *msg)
case BTC_GAP_BT_PIN_REQ_EVT:
case BTC_GAP_BT_SET_AFH_CHANNELS_EVT:
case BTC_GAP_BT_READ_REMOTE_NAME_EVT:
case BTC_GAP_BT_REMOVE_BOND_DEV_COMPLETE_EVT:
#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_CFM_REQ_EVT:
case BTC_GAP_BT_KEY_NOTIF_EVT:
Expand Down Expand Up @@ -1042,6 +1043,10 @@ void btc_gap_bt_cb_handler(btc_msg_t *msg)
break;
}
#endif
case BTC_GAP_BT_REMOVE_BOND_DEV_COMPLETE_EVT:{
btc_gap_bt_cb_to_app(ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT,(esp_bt_gap_cb_param_t *)msg->arg);
break;
}
default:
BTC_TRACE_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef enum {
BTC_GAP_BT_CONFIG_EIR_DATA_EVT,
BTC_GAP_BT_SET_AFH_CHANNELS_EVT,
BTC_GAP_BT_READ_REMOTE_NAME_EVT,
BTC_GAP_BT_REMOVE_BOND_DEV_COMPLETE_EVT,
}btc_gap_bt_evt_t;

typedef enum {
Expand Down

0 comments on commit 17fca62

Please sign in to comment.