summaryrefslogtreecommitdiff
path: root/emulator/le.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2015-07-14 22:19:39 +0200
committerMarcel Holtmann <marcel@holtmann.org>2015-07-14 22:19:39 +0200
commit8a4b1bd1bb7e34322d42c86a02734a5d09ad8be1 (patch)
tree808e89ac34f17497231973cb5db17b72fe6f56cf /emulator/le.c
parent33b447daaa3adfc04dfbc123538360d998e2d7d7 (diff)
downloadbluez-8a4b1bd1bb7e34322d42c86a02734a5d09ad8be1.tar.gz
emulator: Add support for using advertising delay values
Diffstat (limited to 'emulator/le.c')
-rw-r--r--emulator/le.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/emulator/le.c b/emulator/le.c
index dc51469ca..a0d902bef 100644
--- a/emulator/le.c
+++ b/emulator/le.c
@@ -33,6 +33,7 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/uio.h>
+#include <time.h>
#include "lib/bluetooth.h"
#include "lib/hci.h"
@@ -448,17 +449,28 @@ static void send_adv_pkt(struct bt_le *hci)
hci->le_scan_rsp_data, pkt.scan_rsp_len);
}
+static unsigned int get_adv_delay(void)
+{
+ /* The advertising delay is a pseudo-random value with a range
+ * of 0 ms to 10 ms generated for each advertising event.
+ */
+ srand(time(NULL));
+ return (rand() % 11);
+}
+
static void adv_timeout_callback(int id, void *user_data)
{
struct bt_le *hci = user_data;
- unsigned int min_msec, max_msec;
+ unsigned int msec, min_msec, max_msec;
send_adv_pkt(hci);
min_msec = (hci->le_adv_min_interval * 625) / 1000;
max_msec = (hci->le_adv_max_interval * 625) / 1000;
- if (mainloop_modify_timeout(id, (min_msec + max_msec) / 2) < 0) {
+ msec = ((min_msec + max_msec) / 2) + get_adv_delay();
+
+ if (mainloop_modify_timeout(id, msec) < 0) {
fprintf(stderr, "Setting advertising timeout failed\n");
hci->le_adv_enable = 0x00;
}
@@ -471,7 +483,7 @@ static bool start_adv(struct bt_le *hci)
if (hci->adv_timeout_id >= 0)
return false;
- msec = (hci->le_adv_min_interval * 625) / 1000;
+ msec = ((hci->le_adv_min_interval * 625) / 1000) + get_adv_delay();
hci->adv_timeout_id = mainloop_add_timeout(msec, adv_timeout_callback,
hci, NULL);