|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | #include <zephyr/settings/settings.h> |
| 9 | +#include <zephyr/sys/byteorder.h> |
9 | 10 |
|
10 | 11 | #include <zephyr/bluetooth/bluetooth.h> |
11 | 12 | #include <zephyr/bluetooth/hci_vs.h> |
@@ -204,9 +205,47 @@ static void le_rpa_invalidate(void) |
204 | 205 | } |
205 | 206 |
|
206 | 207 | #if defined(CONFIG_BT_PRIVACY) |
| 208 | + |
| 209 | +#if defined(CONFIG_BT_RPA_TIMEOUT_DYNAMIC) |
| 210 | +static void le_rpa_timeout_update(void) |
| 211 | +{ |
| 212 | + int err = 0; |
| 213 | + |
| 214 | + if (atomic_test_and_clear_bit(bt_dev.flags, BT_DEV_RPA_TIMEOUT_CHANGED)) { |
| 215 | + struct net_buf *buf; |
| 216 | + struct bt_hci_cp_le_set_rpa_timeout *cp; |
| 217 | + |
| 218 | + buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_RPA_TIMEOUT, |
| 219 | + sizeof(*cp)); |
| 220 | + if (!buf) { |
| 221 | + BT_ERR("Failed to create HCI RPA timeout command"); |
| 222 | + err = -ENOBUFS; |
| 223 | + goto submit; |
| 224 | + } |
| 225 | + |
| 226 | + cp = net_buf_add(buf, sizeof(*cp)); |
| 227 | + cp->rpa_timeout = sys_cpu_to_le16(bt_dev.rpa_timeout); |
| 228 | + err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_RPA_TIMEOUT, buf, NULL); |
| 229 | + if (err) { |
| 230 | + BT_ERR("Failed to send HCI RPA timeout command"); |
| 231 | + goto submit; |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | +submit: |
| 236 | + if (err) { |
| 237 | + atomic_set_bit(bt_dev.flags, BT_DEV_RPA_TIMEOUT_CHANGED); |
| 238 | + } |
| 239 | +} |
| 240 | +#endif |
| 241 | + |
207 | 242 | static void le_rpa_timeout_submit(void) |
208 | 243 | { |
209 | | - (void)k_work_schedule(&bt_dev.rpa_update, RPA_TIMEOUT); |
| 244 | +#if defined(CONFIG_BT_RPA_TIMEOUT_DYNAMIC) |
| 245 | + le_rpa_timeout_update(); |
| 246 | +#endif |
| 247 | + |
| 248 | + (void)k_work_schedule(&bt_dev.rpa_update, K_SECONDS(bt_dev.rpa_timeout)); |
210 | 249 | } |
211 | 250 |
|
212 | 251 | /* this function sets new RPA only if current one is no longer valid */ |
|
0 commit comments