From cd7411deb4e98dc578ea7a141559755989399124 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 31 Oct 2023 17:07:55 +0100 Subject: [PATCH] hci: fix restart connect with whitelist after whitelist modification --- CHANGELOG.md | 1 + src/hci.c | 1 - test/gap/gap_whitelist.c | 53 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 test/gap/gap_whitelist.c diff --git a/CHANGELOG.md b/CHANGELOG.md index 904705db8..3eaa7ed7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - HCI: fix remove le device from whitelist +- HCI: fix restart connect with whitelist after whitelist modification - L2CAP: make l2cap_get_remote_mtu_for_local_cid available to LE-only builds - HFP: use 'don't care' to accept SCO connections, fixes issue on ESP32 - HFP: fix LC3-WB init diff --git a/src/hci.c b/src/hci.c index 0eb5bd06c..563221152 100644 --- a/src/hci.c +++ b/src/hci.c @@ -3290,7 +3290,6 @@ static void event_handle_le_connection_complete(const uint8_t * packet){ if (status == ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER){ // reset state hci_stack->le_connecting_state = LE_CONNECTING_IDLE; - hci_stack->le_connecting_request = LE_CONNECTING_IDLE; // get outgoing connection conn struct for direct connect conn = gap_get_outgoing_connection(); } diff --git a/test/gap/gap_whitelist.c b/test/gap/gap_whitelist.c new file mode 100644 index 000000000..2d6cfa476 --- /dev/null +++ b/test/gap/gap_whitelist.c @@ -0,0 +1,53 @@ +#define BTSTACK_FILE__ "gatt_whitelist.c" + +#include +#include +#include "btstack.h" + +#define HEARTBEAT_PERIOD_MS 2000 + +static btstack_timer_source_t heartbeat; +static btstack_packet_callback_registration_t hci_event_callback_registration; +static bd_addr_t addr; + +static void heartbeat_handler(struct btstack_timer_source *ts){ + addr[5]++; + addr[4]++; + gap_whitelist_add(BD_ADDR_TYPE_LE_PUBLIC, addr); + printf("Add %s to Whitelist\n", bd_addr_to_str(addr)); + + btstack_run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS); + btstack_run_loop_add_timer(ts); +} + +static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ + UNUSED(channel); + UNUSED(size); + if (packet_type != HCI_EVENT_PACKET) return; + switch (hci_event_packet_get_type(packet)) { + case BTSTACK_EVENT_STATE: + if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return; + // started + printf("GAP Connect with Whitelist\n"); + gap_connect_with_whitelist(); + // set one-shot timer + heartbeat.process = &heartbeat_handler; + btstack_run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS); + btstack_run_loop_add_timer(&heartbeat); + break; + default: + break; + } +} + +int btstack_main(void); +int btstack_main(void) +{ + // register for HCI events + hci_event_callback_registration.callback = &packet_handler; + hci_add_event_handler(&hci_event_callback_registration); + + hci_power_control(HCI_POWER_ON); + return 0; +} +/* EXAMPLE_END */