diff --git a/components/bt/controller/lib_esp32c3_family b/components/bt/controller/lib_esp32c3_family index a17e093350f3..d7513ebe88d7 160000 --- a/components/bt/controller/lib_esp32c3_family +++ b/components/bt/controller/lib_esp32c3_family @@ -1 +1 @@ -Subproject commit a17e093350f31d09b8bcbfaad40b5b35535ea97b +Subproject commit d7513ebe88d7d207f6c062ce9381d347a0a70918 diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c index 9e936409b668..d51fa224687c 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -5102,7 +5102,7 @@ void bta_dm_ble_update_conn_params (tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_disconnect (tBTA_DM_MSG *p_data) { - L2CA_RemoveFixedChnl(L2CAP_ATT_CID, p_data->ble_disconnect.remote_bda); + L2CA_BleDisconnect(p_data->ble_disconnect.remote_bda); } /******************************************************************************* diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_co.c b/components/bt/host/bluedroid/bta/dm/bta_dm_co.c index 9e1a7b16d538..69e729ef440e 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_co.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_co.c @@ -389,7 +389,7 @@ void bta_dm_co_ble_set_init_key_req(UINT8 init_key) { #if (SMP_INCLUDED == TRUE) init_key &= 0x0f; // 4~7bit reservd, only used the 0~3bit - bte_appl_cfg.ble_init_key &= init_key; + bte_appl_cfg.ble_init_key = init_key; #endif ///SMP_INCLUDED == TRUE } @@ -397,7 +397,7 @@ void bta_dm_co_ble_set_rsp_key_req(UINT8 rsp_key) { #if (SMP_INCLUDED == TRUE) rsp_key &= 0x0f; // 4~7bit reservd, only used the 0~3bit - bte_appl_cfg.ble_resp_key &= rsp_key; + bte_appl_cfg.ble_resp_key = rsp_key; #endif ///SMP_INCLUDED == TRUE } diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c index d1131d39dad6..9ee45872da4d 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c @@ -302,21 +302,19 @@ tBTM_STATUS BTM_BleSetExtendedAdvRandaddr(UINT8 instance, BD_ADDR rand_addr) BD_ADDR invalid_rand_addr_a, invalid_rand_addr_b; memset(invalid_rand_addr_a, 0xff, sizeof(BD_ADDR)); memset(invalid_rand_addr_b, 0x00, sizeof(BD_ADDR)); - invalid_rand_addr_b[0] = invalid_rand_addr_b[0] | BT_STATIC_RAND_ADDR_MASK; - if((rand_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK - && memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0 - && memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0){ - // set random address - if((err = btsnd_hcic_ble_set_extend_rand_address(instance, rand_addr)) != HCI_SUCCESS) { - BTM_TRACE_ERROR("%s, fail to send the hci command, the error code = %s(0x%x)", - __func__, btm_ble_hci_status_to_str(err), err); + if((rand_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK) { + invalid_rand_addr_b[0] = invalid_rand_addr_b[0] | BT_STATIC_RAND_ADDR_MASK; + if (memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) == 0 + || memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) == 0) { status = BTM_ILLEGAL_VALUE; - } else { - // set random address success, update address infor - if(extend_adv_cb.inst[instance].configured && extend_adv_cb.inst[instance].connetable) { - BTM_BleSetStaticAddr(rand_addr); - BTM_UpdateAddrInfor(BLE_ADDR_RANDOM, rand_addr); - } + goto end; + } + } else if ((rand_addr[0] | BT_NON_RPA_MASK) == BT_NON_RPA_MASK) { + invalid_rand_addr_a[0] = invalid_rand_addr_a[0] & BT_NON_RPA_MASK; + if (memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) == 0 + || memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) == 0) { + status = BTM_ILLEGAL_VALUE; + goto end; } } else { BTM_TRACE_ERROR("%s invalid random address", __func__); @@ -324,6 +322,19 @@ tBTM_STATUS BTM_BleSetExtendedAdvRandaddr(UINT8 instance, BD_ADDR rand_addr) goto end; } + // set random address + if((err = btsnd_hcic_ble_set_extend_rand_address(instance, rand_addr)) != HCI_SUCCESS) { + BTM_TRACE_ERROR("%s, fail to send the hci command, the error code = %s(0x%x)", + __func__, btm_ble_hci_status_to_str(err), err); + status = BTM_ILLEGAL_VALUE; + } else { + // set random address success, update address infor + if(extend_adv_cb.inst[instance].configured && extend_adv_cb.inst[instance].connetable) { + BTM_BleSetStaticAddr(rand_addr); + BTM_UpdateAddrInfor(BLE_ADDR_RANDOM, rand_addr); + } + } + end: cb_params.status = status; diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c index 573751dbf777..8daf84bbcafe 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c @@ -2237,9 +2237,10 @@ UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst, #if BTM_MAX_LOC_BD_NAME_LEN > 0 if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_DEV_NAME) { if (strlen(btm_cb.cfg.bd_name) > (UINT16)(len - MIN_ADV_LENGTH)) { - *p++ = len - MIN_ADV_LENGTH + 1; + cp_len = (UINT16)(len - MIN_ADV_LENGTH); + *p++ = cp_len + 1; *p++ = BTM_BLE_AD_TYPE_NAME_SHORT; - ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, len - MIN_ADV_LENGTH); + ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, cp_len); } else { cp_len = (UINT16)strlen(btm_cb.cfg.bd_name); *p++ = cp_len + 1; diff --git a/components/bt/host/bluedroid/stack/include/stack/l2c_api.h b/components/bt/host/bluedroid/stack/include/stack/l2c_api.h index 807b523445e2..e0e4b035e6ef 100644 --- a/components/bt/host/bluedroid/stack/include/stack/l2c_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/l2c_api.h @@ -1215,6 +1215,19 @@ extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable); ** *******************************************************************************/ extern UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr); + +/******************************************************************************* +** +** Function L2CA_BleDisconnect +** +** Description This function use to disconnect LE connection. +** +** Parameters BD Address of remote +** +** Returns TRUE if disconnect successfully. +** +*******************************************************************************/ +extern BOOLEAN L2CA_BleDisconnect (BD_ADDR rem_bda); #endif /* (BLE_INCLUDED == TRUE) */ /******************************************************************************* diff --git a/components/bt/host/bluedroid/stack/l2cap/l2c_api.c b/components/bt/host/bluedroid/stack/l2cap/l2c_api.c index 52d8b45fda02..7c5e0e2ef84f 100644 --- a/components/bt/host/bluedroid/stack/l2cap/l2c_api.c +++ b/components/bt/host/bluedroid/stack/l2cap/l2c_api.c @@ -1949,6 +1949,36 @@ BOOLEAN L2CA_RemoveFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda) return (TRUE); } +#if BLE_INCLUDED == TRUE +BOOLEAN L2CA_BleDisconnect (BD_ADDR rem_bda) +{ + tL2C_LCB *p_lcb; + tGATT_TCB *p_tcb; + + p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_LE); + if (p_lcb == NULL) { + return FALSE; + } + + if (p_lcb->link_state != LST_CONNECTED) { + return FALSE; + } + + p_lcb->disc_reason = HCI_ERR_CONN_CAUSE_LOCAL_HOST; + p_lcb->link_state = LST_DISCONNECTING; + btsnd_hcic_disconnect (p_lcb->handle, HCI_ERR_PEER_USER); + + p_tcb = gatt_find_tcb_by_addr(rem_bda, BT_TRANSPORT_LE); + if (p_tcb == NULL) { + return FALSE; + } + + gatt_set_ch_state(p_tcb, GATT_CH_CLOSING); + + return TRUE; +} +#endif + /******************************************************************************* ** ** Function L2CA_SetFixedChannelTout