From bd9eb5255de29bc5380c15492e103605d094d7a6 Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Tue, 11 Dec 2018 21:19:30 +0800 Subject: [PATCH] Component/bt: fix receive adv pkt when enable duplicate scan --- .../bt/bluedroid/stack/btm/btm_ble_gap.c | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index df6aaf42b..3664f03dd 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -3218,10 +3218,26 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; BOOLEAN update = TRUE; UINT8 result = 0; - + /* Event_Type: + 0x00 Connectable undirected advertising (ADV_IND). + 0x01 Connectable directed advertising (ADV_DIRECT_IND) + 0x02 Scannable undirected advertising (ADV_SCAN_IND) + 0x03 Non connectable undirected advertising (ADV_NONCONN_IND) + 0x04 Scan Response (SCAN_RSP) + 0x05-0xFF Reserved for future use + */ //if scan duplicate is enabled, the adv packet without scan response is allowed to report to upper layer if(p_le_inq_cb->scan_duplicate_filter == BTM_BLE_SCAN_DUPLICATE_ENABLE) { - if(memcmp(bda, p_le_inq_cb->adv_addr, BD_ADDR_LEN) != 0) { + /* + Bluedroid will put the advertising packet and scan response into a packet and send it to the higher layer. + If two advertising packets are not with the same address, or can't be combined into a packet, then the first advertising + packet will be discarded. So we added the following judgment: + 1. For different addresses, send the last advertising packet to higher layer + 2. For same address and same advertising type (not scan response), send the last advertising packet to higher layer + 3. For same address and scan response, do nothing + */ + int same_addr = memcmp(bda, p_le_inq_cb->adv_addr, BD_ADDR_LEN); + if (same_addr != 0 || (same_addr == 0 && evt_type != BTM_BLE_SCAN_RSP_EVT)) { btm_ble_process_last_adv_pkt(); } }