From 916b9e1e629c9f42136e3e34729ced12d226fab7 Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Tue, 17 Aug 2021 11:28:07 +1000 Subject: [PATCH 1/2] aioble/server: Log warning on out-of-order indication. --- micropython/bluetooth/aioble/aioble/server.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/micropython/bluetooth/aioble/aioble/server.py b/micropython/bluetooth/aioble/aioble/server.py index 5d5d7399b..7f30396f5 100644 --- a/micropython/bluetooth/aioble/aioble/server.py +++ b/micropython/bluetooth/aioble/aioble/server.py @@ -284,10 +284,11 @@ def _indicate_done(conn_handle, value_handle, status): # Timeout. return # See TODO in __init__ to support multiple concurrent indications. - assert connection == characteristic._indicate_connection - characteristic._indicate_status = status - characteristic._indicate_event.set() - + if connection == characteristic._indicate_connection: + characteristic._indicate_status = status + characteristic._indicate_event.set() + else: + log_warn("Received indication for unexpected connection") class BufferedCharacteristic(Characteristic): def __init__(self, *args, max_len=20, append=False, **kwargs): From b9e7febd084cc8c7c0d66584ccc866a5935ff89c Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Wed, 25 Mar 2026 11:00:04 +1100 Subject: [PATCH 2/2] aioble/server: Guard _indicate_done against non-indicate characteristics Early-return with a warning if the BLE stack fires an indication-done callback for a characteristic that doesn't have the indicate flag set. --- micropython/bluetooth/aioble/aioble/server.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/micropython/bluetooth/aioble/aioble/server.py b/micropython/bluetooth/aioble/aioble/server.py index 7f30396f5..834f8d751 100644 --- a/micropython/bluetooth/aioble/aioble/server.py +++ b/micropython/bluetooth/aioble/aioble/server.py @@ -279,6 +279,9 @@ async def indicate(self, connection, data=None, timeout_ms=1000): def _indicate_done(conn_handle, value_handle, status): if characteristic := _registered_characteristics.get(value_handle, None): + if not (characteristic.flags & _FLAG_INDICATE): + log_warn("Received indication on unexpected characteristic:", value_handle) + return if connection := DeviceConnection._connected.get(conn_handle, None): if not characteristic._indicate_connection: # Timeout.