From 9be0120d94240ff0526059d2dcf0ed8ec60b92ce Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 26 Oct 2020 14:23:35 +0800 Subject: [PATCH] ble_mesh: stack: Optimize handling received mesh adv packets --- .../bluedroid_host/mesh_bearer_adapt.c | 20 +++++-------------- .../mesh_core/nimble_host/mesh_bearer_adapt.c | 16 ++++++--------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c index dc1c19b139..b2f0b6aad2 100644 --- a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c @@ -284,31 +284,21 @@ static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window, static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data) { + struct net_buf_simple buf = {0}; bt_mesh_addr_t addr = {0}; - uint8_t adv_type = 0U; - int8_t rssi = 0; BT_DBG("%s, event %d", __func__, event); if (event == BTA_DM_INQ_RES_EVT) { - /* TODO: How to process scan response here? */ + /* TODO: How to process scan response here? PS: p_data->inq_res.scan_rsp_len */ addr.type = p_data->inq_res.ble_addr_type; memcpy(addr.val, p_data->inq_res.bd_addr, BLE_MESH_ADDR_LEN); - rssi = p_data->inq_res.rssi; - adv_type = p_data->inq_res.ble_evt_type; - /* scan rsp len: p_data->inq_res.scan_rsp_len */ - struct net_buf_simple *buf = bt_mesh_alloc_buf(p_data->inq_res.adv_data_len); - if (!buf) { - BT_ERR("%s, Out of memory", __func__); - return; - } - net_buf_simple_add_mem(buf, p_data->inq_res.p_eir, p_data->inq_res.adv_data_len); + net_buf_simple_init_with_data(&buf, p_data->inq_res.p_eir, p_data->inq_res.adv_data_len); - if (bt_mesh_scan_dev_found_cb != NULL) { - bt_mesh_scan_dev_found_cb(&addr, rssi, adv_type, buf); + if (bt_mesh_scan_dev_found_cb) { + bt_mesh_scan_dev_found_cb(&addr, p_data->inq_res.rssi, p_data->inq_res.ble_evt_type, &buf); } - bt_mesh_free(buf); } else if (event == BTA_DM_INQ_CMPL_EVT) { BT_INFO("Scan completed, number of scan response %d", p_data->inq_cmpl.num_resps); } else { diff --git a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c index 80389ce792..56b761e41f 100644 --- a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c @@ -387,21 +387,17 @@ static int disc_cb(struct ble_gap_event *event, void *arg) #endif switch (event->type) { - case BLE_GAP_EVENT_DISC: - desc = &event->disc; + case BLE_GAP_EVENT_DISC: { + struct net_buf_simple buf = {0}; - struct net_buf_simple *buf = bt_mesh_alloc_buf(desc->length_data); - if (!buf) { - BT_ERR("%s, Out of memory", __func__); - return 0; - } - net_buf_simple_add_mem(buf, desc->data, desc->length_data); + desc = &event->disc; + net_buf_simple_init_with_data(&buf, desc->data, desc->length_data); if (bt_mesh_scan_dev_found_cb) { - bt_mesh_scan_dev_found_cb((bt_mesh_addr_t *)&desc->addr, desc->rssi, desc->event_type, buf); + bt_mesh_scan_dev_found_cb((bt_mesh_addr_t *)&desc->addr, desc->rssi, desc->event_type, &buf); } - bt_mesh_free(buf); break; + } #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_CLIENT case BLE_GAP_EVENT_CONNECT: