forked from seemoo-lab/openhaystack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
70 lines (57 loc) · 1.85 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* OpenHaystack – Tracking personal Bluetooth devices via Apple's Find My network
*
* Copyright © 2021 Secure Mobile Networking Lab (SEEMOO)
* Copyright © 2021 The Open Wireless Link Project
*
* SPDX-License-Identifier: MIT
*/
#include <stdint.h>
#include <string.h>
#include <blessed/bdaddr.h>
#include <blessed/evtloop.h>
#include "ll.h"
#define ADV_INTERVAL 2000000 /* 2 s */
/* don't make `const` so we can replace key in compiled binary image */
static char public_key[28] = "OFFLINEFINDINGPUBLICKEYHERE!";
static bdaddr_t addr = {
{ 0xFF, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF },
BDADDR_TYPE_RANDOM
};
static uint8_t offline_finding_adv_template[] = {
0x1e, /* Length (30) */
0xff, /* Manufacturer Specific Data (type 0xff) */
0x4c, 0x00, /* Company ID (Apple) */
0x12, 0x19, /* Offline Finding type and length */
0x00, /* State */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, /* First two bits */
0x00, /* Hint (0x00) */
};
void set_addr_from_key() {
/* copy first 6 bytes */
/* BLESSED seems to reorder address bytes, so we copy them in reverse order */
addr.addr[5] = public_key[0] | 0b11000000;
addr.addr[4] = public_key[1];
addr.addr[3] = public_key[2];
addr.addr[2] = public_key[3];
addr.addr[1] = public_key[4];
addr.addr[0] = public_key[5];
}
void fill_adv_template_from_key() {
/* copy last 22 bytes */
memcpy(&offline_finding_adv_template[7], &public_key[6], 22);
/* append two bits of public key */
offline_finding_adv_template[29] = public_key[0] >> 6;
}
int main(void) {
set_addr_from_key();
fill_adv_template_from_key();
ll_init(&addr);
ll_set_advertising_data(offline_finding_adv_template, sizeof(offline_finding_adv_template));
ll_advertise_start(LL_PDU_ADV_NONCONN_IND, ADV_INTERVAL, LL_ADV_CH_ALL);
evt_loop_run();
return 0;
}