diff --git a/CHANGELOG.md b/CHANGELOG.md index 11150979f..38ed095e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed +- Crypto: fix lockup when stack is shutdown while waiting for result of HCI Command, e.g. LE Read Local P256 Public Key + +## Changes December 2018 + ### Changed - L2CAP: provide channel mode (basic/ertm) and fcs option in L2CAP_EVENT_CHANNEL_OPENED - RFCOMM: support L2CAP ERTM. Callbacks passed to rfcomm_enable_l2cap_ertm() are used to manage ERTM buffers diff --git a/src/btstack_crypto.c b/src/btstack_crypto.c index 19a97d8e2..b0f680620 100644 --- a/src/btstack_crypto.c +++ b/src/btstack_crypto.c @@ -944,6 +944,14 @@ static void btstack_crypto_event_handler(uint8_t packet_type, uint16_t cid, uint if (packet_type != HCI_EVENT_PACKET) return; switch (hci_event_packet_get_type(packet)){ + case BTSTACK_EVENT_STATE: + log_info("BTSTACK_EVENT_STATE"); + if (btstack_event_state_get_state(packet) != HCI_STATE_HALTING) break; + if (!btstack_crypto_wait_for_hci_result) break; + // request stack to defer shutdown a bit + hci_halting_defer(); + break; + case HCI_EVENT_COMMAND_COMPLETE: if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_le_encrypt)){ if (hci_get_state() != HCI_STATE_WORKING) return;