Bluetooth: Host: Discard advertising data if not explicit scanning
If the application is not explicitly scanning, then there is not really any need to parse advertising reports nor send them to the application. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
421f81a243
commit
f338bf6fae
2 changed files with 37 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <zephyr/sys/atomic.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/sys/check.h>
|
||||
|
||||
|
@ -609,6 +610,21 @@ void bt_hci_le_adv_ext_report(struct net_buf *buf)
|
|||
bool more_to_come;
|
||||
bool is_new_advertiser;
|
||||
|
||||
if (!atomic_test_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN)) {
|
||||
/* The application has not requested explicit scan, so it is not expecting
|
||||
* advertising reports. Discard, and reset the reassembler if not inactive
|
||||
* This is done in the loop as this flag can change between each iteration,
|
||||
* and it is not uncommon that scanning is disabled in the callback called
|
||||
* from le_adv_recv
|
||||
*/
|
||||
|
||||
if (reassembling_advertiser.state != FRAG_ADV_INACTIVE) {
|
||||
reset_reassembling_advertiser();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (buf->len < sizeof(*evt)) {
|
||||
LOG_ERR("Unexpected end of buffer");
|
||||
break;
|
||||
|
@ -1457,6 +1473,17 @@ void bt_hci_le_adv_report(struct net_buf *buf)
|
|||
while (num_reports--) {
|
||||
struct bt_le_scan_recv_info adv_info;
|
||||
|
||||
if (!atomic_test_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN)) {
|
||||
/* The application has not requested explicit scan, so it is not expecting
|
||||
* advertising reports. Discard.
|
||||
* This is done in the loop as this flag can change between each iteration,
|
||||
* and it is not uncommon that scanning is disabled in the callback called
|
||||
* from le_adv_recv
|
||||
*/
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (buf->len < sizeof(*evt)) {
|
||||
LOG_ERR("Unexpected end of buffer");
|
||||
break;
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
/* main.c - Host long advertising receive */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2021-2024 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <zephyr/bluetooth/hci_types.h>
|
||||
#include <zephyr/fff.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
@ -18,6 +21,7 @@
|
|||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/drivers/bluetooth.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/ztest_assert.h>
|
||||
|
||||
#define DT_DRV_COMPAT zephyr_bt_hci_test
|
||||
|
||||
|
@ -201,6 +205,7 @@ static void le_read_supp_states(struct net_buf *buf, struct net_buf **evt, uint8
|
|||
(void)memset(&rp->le_states, 0xFF, sizeof(rp->le_states));
|
||||
}
|
||||
|
||||
|
||||
/* Setup handlers needed for bt_enable to function. */
|
||||
static const struct cmd_handler cmds[] = {
|
||||
{ BT_HCI_OP_READ_LOCAL_VERSION_INFO, sizeof(struct bt_hci_rp_read_local_version_info),
|
||||
|
@ -219,6 +224,8 @@ static const struct cmd_handler cmds[] = {
|
|||
{ BT_HCI_OP_LE_RAND, sizeof(struct bt_hci_rp_le_rand), generic_success },
|
||||
{ BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(struct bt_hci_cp_le_set_random_address),
|
||||
generic_success },
|
||||
{ BT_HCI_OP_LE_SET_EXT_SCAN_PARAM, 0, generic_success },
|
||||
{ BT_HCI_OP_LE_SET_EXT_SCAN_ENABLE, 0, generic_success },
|
||||
{ BT_HCI_OP_RESET, 0, generic_success },
|
||||
};
|
||||
|
||||
|
@ -382,6 +389,8 @@ ZTEST(long_adv_rx_tests, test_host_long_adv_recv)
|
|||
static struct bt_le_scan_cb scan_callbacks = { .recv = scan_recv_cb,
|
||||
.timeout = scan_timeout_cb };
|
||||
bt_le_scan_cb_register(&scan_callbacks);
|
||||
zassert_true((bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL) == 0), "bt_le_scan_start failed");
|
||||
|
||||
bt_addr_le_t addr_a;
|
||||
bt_addr_le_t addr_b;
|
||||
bt_addr_le_t addr_c;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue