From db8bcc60f9382fc5e192847bd48bd8482aed1ce0 Mon Sep 17 00:00:00 2001 From: Geng Yu Chao Date: Wed, 18 Dec 2019 14:19:13 +0800 Subject: [PATCH] Bugfix/btdm fix doc and host bug backport v3.3 --- .../bt/bluedroid/btc/core/btc_ble_storage.c | 5 +++-- components/bt/bluedroid/btc/core/btc_dm.c | 8 ++++++-- .../btc/profile/esp/blufi/blufi_prf.c | 2 +- components/bt/bluedroid/osi/config.c | 20 +++++++++++++++++++ components/bt/bluedroid/stack/btm/btm_acl.c | 2 +- .../bt/bluedroid/stack/btm/btm_ble_privacy.c | 7 ++++++- components/bt/bluedroid/stack/gatt/gatt_db.c | 2 +- components/bt/bluedroid/stack/smp/smp_act.c | 4 ++-- .../Gatt_Client_Example_Walkthrough.md | 2 +- 9 files changed, 41 insertions(+), 11 deletions(-) diff --git a/components/bt/bluedroid/btc/core/btc_ble_storage.c b/components/bt/bluedroid/btc/core/btc_ble_storage.c index c8590ce80..df6c6e0cc 100644 --- a/components/bt/bluedroid/btc/core/btc_ble_storage.c +++ b/components/bt/bluedroid/btc/core/btc_ble_storage.c @@ -893,9 +893,10 @@ bt_status_t btc_storage_get_bonded_ble_devices_list(esp_ble_bond_dev_t *bond_dev if (_btc_storage_get_ble_bonding_key(&bd_addr, BTM_LE_KEY_PID, buffer, sizeof(tBTM_LE_PID_KEYS)) == BT_STATUS_SUCCESS) { bond_dev->bond_key.key_mask |= ESP_BLE_ID_KEY_MASK; tBTM_LE_PID_KEYS *pid_key = (tBTM_LE_PID_KEYS *) buffer; - memcpy(&bond_dev->bond_key.pid_key.irk, pid_key->irk, BT_OCTET16_LEN); + //Note: The memory size of the pid_key.addr_type in bond_key is different from that of (tBTM_LE_PID_KEYS) *pid_key. + memcpy(&bond_dev->bond_key.pid_key.irk, pid_key->irk, ESP_BT_OCTET16_LEN); bond_dev->bond_key.pid_key.addr_type = pid_key->addr_type; - memcpy(&bond_dev->bond_key.pid_key.static_addr, pid_key->static_addr, sizeof(BD_ADDR)); + memcpy(&bond_dev->bond_key.pid_key.static_addr, pid_key->static_addr, ESP_BD_ADDR_LEN); } //serch for the next bond device bond_dev++; diff --git a/components/bt/bluedroid/btc/core/btc_dm.c b/components/bt/bluedroid/btc/core/btc_dm.c index f3b9caeb4..fbf153b5e 100644 --- a/components/bt/bluedroid/btc/core/btc_dm.c +++ b/components/bt/bluedroid/btc/core/btc_dm.c @@ -706,8 +706,12 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) pairing_cb.ble.is_pid_key_rcvd = TRUE; memcpy(&pairing_cb.ble.pid_key, &p_data->ble_key.p_key_value->pid_key, sizeof(tBTM_LE_PID_KEYS)); - memcpy(¶m.ble_security.ble_key.p_key_value.pid_key, - &p_data->ble_key.p_key_value->pid_key, sizeof(tBTM_LE_PID_KEYS)); + //Note: The memory size of the addr_type in ble_security.ble_key.p_key_value.pid_key is different from that of p_data->ble_key.p_key_value->pid_key. + memcpy(¶m.ble_security.ble_key.p_key_value.pid_key.irk, + &p_data->ble_key.p_key_value->pid_key.irk, ESP_BT_OCTET16_LEN); + param.ble_security.ble_key.p_key_value.pid_key.addr_type = p_data->ble_key.p_key_value->pid_key.addr_type; + memcpy(¶m.ble_security.ble_key.p_key_value.pid_key.static_addr, + &p_data->ble_key.p_key_value->pid_key.static_addr, ESP_BD_ADDR_LEN); break; } case BTM_LE_KEY_PCSRK: { diff --git a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c index 45c220b3b..93722ec06 100644 --- a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c +++ b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c @@ -585,7 +585,7 @@ static void btc_blufi_wifi_conn_report(uint8_t opmode, uint8_t sta_conn_state, u *p++ = info->softap_max_conn_num; } if (info->softap_channel_set) { - *p++ = BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_MAX_CONN_NUM; + *p++ = BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_CHANNEL; *p++ = 1; *p++ = info->softap_channel; } diff --git a/components/bt/bluedroid/osi/config.c b/components/bt/bluedroid/osi/config.c index 55a3b3d4b..bd7307e8a 100644 --- a/components/bt/bluedroid/osi/config.c +++ b/components/bt/bluedroid/osi/config.c @@ -409,6 +409,16 @@ bool config_save(const config_t *config, const char *filename) for (const list_node_t *node = list_begin(config->sections); node != list_end(config->sections); node = list_next(node)) { const section_t *section = (const section_t *)list_node(node); w_cnt = snprintf(line, 1024, "[%s]\n", section->name); + if(w_cnt < 0) { + OSI_TRACE_ERROR("snprintf error w_cnt %d.",w_cnt); + err_code |= 0x10; + goto error; + } + if(w_cnt_total + w_cnt > config_size + 100) { + OSI_TRACE_ERROR("%s, memcpy size (w_cnt + w_cnt_total = %d) is larger than buffer size.", __func__, w_cnt + w_cnt_total); + err_code |= 0x20; + goto error; + } OSI_TRACE_DEBUG("section name: %s, w_cnt + w_cnt_total = %d\n", section->name, w_cnt + w_cnt_total); memcpy(buf + w_cnt_total, line, w_cnt); w_cnt_total += w_cnt; @@ -417,6 +427,16 @@ bool config_save(const config_t *config, const char *filename) const entry_t *entry = (const entry_t *)list_node(enode); OSI_TRACE_DEBUG("(key, val): (%s, %s)\n", entry->key, entry->value); w_cnt = snprintf(line, 1024, "%s = %s\n", entry->key, entry->value); + if(w_cnt < 0) { + OSI_TRACE_ERROR("snprintf error w_cnt %d.",w_cnt); + err_code |= 0x10; + goto error; + } + if(w_cnt_total + w_cnt > config_size + 100) { + OSI_TRACE_ERROR("%s, memcpy size (w_cnt + w_cnt_total = %d) is larger than buffer size.", __func__, w_cnt + w_cnt_total); + err_code |= 0x20; + goto error; + } OSI_TRACE_DEBUG("%s, w_cnt + w_cnt_total = %d", __func__, w_cnt + w_cnt_total); memcpy(buf + w_cnt_total, line, w_cnt); w_cnt_total += w_cnt; diff --git a/components/bt/bluedroid/stack/btm/btm_acl.c b/components/bt/bluedroid/stack/btm/btm_acl.c index e42724f23..8129e903a 100644 --- a/components/bt/bluedroid/stack/btm/btm_acl.c +++ b/components/bt/bluedroid/stack/btm/btm_acl.c @@ -2069,7 +2069,7 @@ void BTM_BleGetWhiteListSize(uint16_t *length) { tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; if (p_cb->white_list_avail_size == 0) { - BTM_TRACE_DEBUG("%s Whitelist full.", __func__); + BTM_TRACE_WARNING("%s Whitelist full.", __func__); } *length = p_cb->white_list_avail_size; return; diff --git a/components/bt/bluedroid/stack/btm/btm_ble_privacy.c b/components/bt/bluedroid/stack/btm/btm_ble_privacy.c index 71f06eb82..bbe9f4128 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_privacy.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_privacy.c @@ -292,8 +292,11 @@ void btm_ble_add_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len) } } else if (status == HCI_ERR_MEMORY_FULL) { /* BT_ERROR_CODE_MEMORY_CAPACITY_EXCEEDED */ btm_cb.ble_ctr_cb.resolving_list_avail_size = 0; - BTM_TRACE_DEBUG("%s Resolving list Full ", __func__); + BTM_TRACE_WARNING("%s Resolving list Full ", __func__); + } else { + BTM_TRACE_ERROR("%s Add resolving list error %d ", __func__, status); } + } /******************************************************************************* @@ -811,6 +814,8 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec) } else { btm_ble_enable_resolving_list(BTM_BLE_RL_INIT); } + } else { + BTM_TRACE_WARNING("%s Resolving list full ", __func__); } } else { BTM_TRACE_DEBUG("Device already in Resolving list\n"); diff --git a/components/bt/bluedroid/stack/gatt/gatt_db.c b/components/bt/bluedroid/stack/gatt/gatt_db.c index 8a0511748..e0ee0119c 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_db.c +++ b/components/bt/bluedroid/stack/gatt/gatt_db.c @@ -392,7 +392,7 @@ tGATT_STATUS gatts_db_read_attr_value_by_type (tGATT_TCB *p_tcb, p_rsp->len += (len + 2); *p_len -= (len + 2); } else { - GATT_TRACE_ERROR("format mismatch"); + GATT_TRACE_WARNING("format mismatch"); status = GATT_NO_RESOURCES; break; } diff --git a/components/bt/bluedroid/stack/smp/smp_act.c b/components/bt/bluedroid/stack/smp/smp_act.c index d11506e65..dafc04081 100644 --- a/components/bt/bluedroid/stack/smp/smp_act.c +++ b/components/bt/bluedroid/stack/smp/smp_act.c @@ -1715,13 +1715,13 @@ void smp_match_dhkey_checks(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) SMP_TRACE_DEBUG("%s\n", __func__); if (memcmp(p_data->key.p_data, p_cb->remote_dhkey_check, BT_OCTET16_LEN)) { - SMP_TRACE_WARNING ("dhkey chcks do no match\n"); + SMP_TRACE_WARNING ("dhkey checks do no match\n"); p_cb->failure = reason; smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); return; } - SMP_TRACE_EVENT ("dhkey chcks match\n"); + SMP_TRACE_EVENT ("dhkey checks match\n"); /* compare the max encryption key size, and save the smaller one for the link */ if (p_cb->peer_enc_size < p_cb->loc_enc_size) { diff --git a/examples/bluetooth/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md b/examples/bluetooth/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md index 2ed2c86b5..210601ed3 100644 --- a/examples/bluetooth/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md +++ b/examples/bluetooth/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md @@ -551,7 +551,7 @@ case ESP_GATTC_SEARCH_CMPL_EVT: ESP_LOGE(GATTC_TAG, "search service failed, error status = %x", p_data->search_cmpl.status); break; } - conn_id = p_data->search_cmpl.conn_id;h + conn_id = p_data->search_cmpl.conn_id; if (get_server){ uint16_t count = 0; esp_gatt_status_t status = esp_ble_gattc_get_attr_count( gattc_if,