Skip to content

Commit c576e5b

Browse files
alxelaxtmon-nordic
authored andcommitted
[nrf noup] Bluetooth: Mesh: zero randomization for friend's adv
Friend's replies on LPN's polls do not assume randomization in advertiser. Zero randomization will help to optimize time when LPN keeps receiving window open and save power. Signed-off-by: Aleksandr Khromykh <[email protected]>
1 parent 032f3de commit c576e5b

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

subsys/bluetooth/mesh/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ config BT_MESH_LPN_INIT_POLL_TIMEOUT
812812
config BT_MESH_LPN_SCAN_LATENCY
813813
int "Latency for enabling scanning"
814814
range 0 50
815-
default 15
815+
default 2
816816
help
817817
Latency in milliseconds that it takes to enable scanning. This
818818
is in practice how much time in advance before the Receive Window

subsys/bluetooth/mesh/adv_ext.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include <zephyr/bluetooth/bluetooth.h>
1414
#include <zephyr/bluetooth/hci.h>
1515
#include <zephyr/bluetooth/mesh.h>
16+
#if defined(CONFIG_BT_LL_SOFTDEVICE)
17+
#include <sdc_hci_vs.h>
18+
#endif
1619

1720
#include "common/bt_str.h"
1821

@@ -134,6 +137,28 @@ static inline struct bt_mesh_ext_adv *gatt_adv_get(void)
134137
#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */
135138
}
136139

140+
static int set_adv_randomness(uint8_t handle, int rand_us)
141+
{
142+
#if defined(CONFIG_BT_LL_SOFTDEVICE)
143+
struct net_buf *buf;
144+
sdc_hci_cmd_vs_set_adv_randomness_t *cmd_params;
145+
146+
buf = bt_hci_cmd_create(SDC_HCI_OPCODE_CMD_VS_SET_ADV_RANDOMNESS, sizeof(*cmd_params));
147+
if (!buf) {
148+
LOG_ERR("Could not allocate command buffer");
149+
return -ENOMEM;
150+
}
151+
152+
cmd_params = net_buf_add(buf, sizeof(*cmd_params));
153+
cmd_params->adv_handle = handle;
154+
cmd_params->rand_us = rand_us;
155+
156+
return bt_hci_cmd_send_sync(SDC_HCI_OPCODE_CMD_VS_SET_ADV_RANDOMNESS, buf, NULL);
157+
#else
158+
return 0;
159+
#endif /* defined(CONFIG_BT_LL_SOFTDEVICE) */
160+
}
161+
137162
static int adv_start(struct bt_mesh_ext_adv *adv,
138163
const struct bt_le_adv_param *param,
139164
struct bt_le_ext_adv_start_param *start,
@@ -456,6 +481,13 @@ int bt_mesh_adv_enable(void)
456481
if (err) {
457482
return err;
458483
}
484+
485+
if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE) && adv->tag & BT_MESH_FRIEND_ADV) {
486+
err = set_adv_randomness(adv->instance->handle, 0);
487+
if (err) {
488+
LOG_ERR("Failed to set zero randomness: %d", err);
489+
}
490+
}
459491
}
460492

461493
return 0;

0 commit comments

Comments
 (0)