Skip to content

Commit 51c7419

Browse files
committed
Bluetooth: mesh: Account for scan window delaying adv events
New advertising started while scanning is already enabled would delay the first advertisement event until the end of the current overlapping scan window in the Zephyr native BLE controller implementation. Hence, consider this scan window duration when calculating the advertising stop. Relates to: zephyrproject-rtos#6083 Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent df76ccf commit 51c7419

File tree

1 file changed

+15
-11
lines changed
  • subsys/bluetooth/host/mesh

1 file changed

+15
-11
lines changed

subsys/bluetooth/host/mesh/adv.c

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* Bluetooth Mesh */
22

33
/*
4+
* Copyright (c) 2018 Nordic Semiconductor ASA
45
* Copyright (c) 2017 Intel Corporation
56
*
67
* SPDX-License-Identifier: Apache-2.0
@@ -28,18 +29,20 @@
2829
#include "prov.h"
2930
#include "proxy.h"
3031

31-
/* Window and Interval are equal for continuous scanning */
32-
#define MESH_SCAN_INTERVAL 0x10
33-
#define MESH_SCAN_WINDOW 0x10
34-
3532
/* Convert from ms to 0.625ms units */
36-
#define ADV_INT(_ms) ((_ms) * 8 / 5)
33+
#define ADV_SCAN_UNIT(_ms) ((_ms) * 8 / 5)
34+
35+
/* Window and Interval are equal for continuous scanning */
36+
#define MESH_SCAN_INTERVAL_MS 10
37+
#define MESH_SCAN_WINDOW_MS 10
38+
#define MESH_SCAN_INTERVAL ADV_SCAN_UNIT(MESH_SCAN_INTERVAL_MS)
39+
#define MESH_SCAN_WINDOW ADV_SCAN_UNIT(MESH_SCAN_WINDOW_MS)
3740

3841
/* Pre-5.0 controllers enforce a minimum interval of 100ms
3942
* whereas 5.0+ controllers can go down to 20ms.
4043
*/
41-
#define ADV_INT_DEFAULT K_MSEC(100)
42-
#define ADV_INT_FAST K_MSEC(20)
44+
#define ADV_INT_DEFAULT_MS 100
45+
#define ADV_INT_FAST_MS 20
4346

4447
/* TinyCrypt PRNG consumes a lot of stack space, so we need to have
4548
* an increased call stack whenever it's used.
@@ -91,7 +94,7 @@ static inline void adv_send_end(int err, const struct bt_mesh_send_cb *cb,
9194
static inline void adv_send(struct net_buf *buf)
9295
{
9396
const s32_t adv_int_min = ((bt_dev.hci_version >= BT_HCI_VERSION_5_0) ?
94-
ADV_INT_FAST : ADV_INT_DEFAULT);
97+
ADV_INT_FAST_MS : ADV_INT_DEFAULT_MS);
9598
const struct bt_mesh_send_cb *cb = BT_MESH_ADV(buf)->cb;
9699
void *cb_data = BT_MESH_ADV(buf)->cb_data;
97100
struct bt_le_adv_param param;
@@ -100,7 +103,8 @@ static inline void adv_send(struct net_buf *buf)
100103
int err;
101104

102105
adv_int = max(adv_int_min, BT_MESH_ADV(buf)->adv_int);
103-
duration = (BT_MESH_ADV(buf)->count + 1) * (adv_int + 10);
106+
duration = MESH_SCAN_WINDOW_MS +
107+
((BT_MESH_ADV(buf)->count + 1) * (adv_int + 10));
104108

105109
BT_DBG("type %u len %u: %s", BT_MESH_ADV(buf)->type,
106110
buf->len, bt_hex(buf->data, buf->len));
@@ -112,7 +116,7 @@ static inline void adv_send(struct net_buf *buf)
112116
ad.data = buf->data;
113117

114118
param.options = 0;
115-
param.interval_min = ADV_INT(adv_int);
119+
param.interval_min = ADV_SCAN_UNIT(adv_int);
116120
param.interval_max = param.interval_min;
117121
param.own_addr = NULL;
118122

@@ -126,7 +130,7 @@ static inline void adv_send(struct net_buf *buf)
126130

127131
BT_DBG("Advertising started. Sleeping %u ms", duration);
128132

129-
k_sleep(duration);
133+
k_sleep(K_MSEC(duration));
130134

131135
err = bt_le_adv_stop();
132136
adv_send_end(err, cb, cb_data);

0 commit comments

Comments
 (0)