diff --git a/lib/ble/ble_winrt.cpp b/lib/ble/ble_winrt.cpp index b0fcacf5..cafdda9e 100644 --- a/lib/ble/ble_winrt.cpp +++ b/lib/ble/ble_winrt.cpp @@ -329,6 +329,15 @@ struct WinState : std::enable_shared_from_this { } auto* l = s.incoming(session); if (!l) { if (response) request.RespondWithProtocolError(0x08); return; } + if (!l->opened) { + /* WriteRequested может обогнать posted SubscribedClientsChanged: перечитать реальные CCC. */ + auto id = l->id; s.subscriptions(); l = s.link(id); + if (!l || !l->opened) { + DEBUG_WARN(CAT, "BLE WinRT write before mandatory subscriptions link=%llu", (unsigned long long)id); + if (response) request.RespondWithProtocolError(0x08); + return; + } + } auto id = l->id; auto data = bytes(request.Value()); DEBUG_TRACE(CAT, "BLE WinRT RX write link=%llu bytes=%zu", (unsigned long long)id, data.size()); ble_backend_received(s.owner, id, channel, data.data(), data.size());