1*cd7411deSMatthias Ringwald #define BTSTACK_FILE__ "gatt_whitelist.c"
2*cd7411deSMatthias Ringwald
3*cd7411deSMatthias Ringwald #include <stdint.h>
4*cd7411deSMatthias Ringwald #include <stdio.h>
5*cd7411deSMatthias Ringwald #include "btstack.h"
6*cd7411deSMatthias Ringwald
7*cd7411deSMatthias Ringwald #define HEARTBEAT_PERIOD_MS 2000
8*cd7411deSMatthias Ringwald
9*cd7411deSMatthias Ringwald static btstack_timer_source_t heartbeat;
10*cd7411deSMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration;
11*cd7411deSMatthias Ringwald static bd_addr_t addr;
12*cd7411deSMatthias Ringwald
heartbeat_handler(struct btstack_timer_source * ts)13*cd7411deSMatthias Ringwald static void heartbeat_handler(struct btstack_timer_source *ts){
14*cd7411deSMatthias Ringwald addr[5]++;
15*cd7411deSMatthias Ringwald addr[4]++;
16*cd7411deSMatthias Ringwald gap_whitelist_add(BD_ADDR_TYPE_LE_PUBLIC, addr);
17*cd7411deSMatthias Ringwald printf("Add %s to Whitelist\n", bd_addr_to_str(addr));
18*cd7411deSMatthias Ringwald
19*cd7411deSMatthias Ringwald btstack_run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS);
20*cd7411deSMatthias Ringwald btstack_run_loop_add_timer(ts);
21*cd7411deSMatthias Ringwald }
22*cd7411deSMatthias Ringwald
packet_handler(uint8_t packet_type,uint16_t channel,uint8_t * packet,uint16_t size)23*cd7411deSMatthias Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
24*cd7411deSMatthias Ringwald UNUSED(channel);
25*cd7411deSMatthias Ringwald UNUSED(size);
26*cd7411deSMatthias Ringwald if (packet_type != HCI_EVENT_PACKET) return;
27*cd7411deSMatthias Ringwald switch (hci_event_packet_get_type(packet)) {
28*cd7411deSMatthias Ringwald case BTSTACK_EVENT_STATE:
29*cd7411deSMatthias Ringwald if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return;
30*cd7411deSMatthias Ringwald // started
31*cd7411deSMatthias Ringwald printf("GAP Connect with Whitelist\n");
32*cd7411deSMatthias Ringwald gap_connect_with_whitelist();
33*cd7411deSMatthias Ringwald // set one-shot timer
34*cd7411deSMatthias Ringwald heartbeat.process = &heartbeat_handler;
35*cd7411deSMatthias Ringwald btstack_run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
36*cd7411deSMatthias Ringwald btstack_run_loop_add_timer(&heartbeat);
37*cd7411deSMatthias Ringwald break;
38*cd7411deSMatthias Ringwald default:
39*cd7411deSMatthias Ringwald break;
40*cd7411deSMatthias Ringwald }
41*cd7411deSMatthias Ringwald }
42*cd7411deSMatthias Ringwald
43*cd7411deSMatthias Ringwald int btstack_main(void);
btstack_main(void)44*cd7411deSMatthias Ringwald int btstack_main(void)
45*cd7411deSMatthias Ringwald {
46*cd7411deSMatthias Ringwald // register for HCI events
47*cd7411deSMatthias Ringwald hci_event_callback_registration.callback = &packet_handler;
48*cd7411deSMatthias Ringwald hci_add_event_handler(&hci_event_callback_registration);
49*cd7411deSMatthias Ringwald
50*cd7411deSMatthias Ringwald hci_power_control(HCI_POWER_ON);
51*cd7411deSMatthias Ringwald return 0;
52*cd7411deSMatthias Ringwald }
53*cd7411deSMatthias Ringwald /* EXAMPLE_END */
54