From 0f59872587d14768fa0b3d2b791dec5ff8e6e365 Mon Sep 17 00:00:00 2001 From: Janusz Sobczak Date: Thu, 8 Jun 2023 17:22:56 -0700 Subject: [PATCH] Reset ble peripheral with gatt server The ble_peripheral is invalid when gatt server is unregistered. PiperOrigin-RevId: 538932998 --- internal/platform/medium_environment.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/platform/medium_environment.cc b/internal/platform/medium_environment.cc index 72a5d62d..1a688443 100644 --- a/internal/platform/medium_environment.cc +++ b/internal/platform/medium_environment.cc @@ -1153,6 +1153,7 @@ void MediumEnvironment::UnregisterGattServer(api::ble_v2::BleMedium& medium) { } auto& context = it->second; context.gatt_server = nullptr; + context.ble_peripheral = nullptr; }); } @@ -1165,7 +1166,7 @@ Borrowable* MediumEnvironment::GetGattServer( const BleV2MediumContext& remote_context = medium_info.second; const api::ble_v2::BlePeripheral* ble_peripheral = remote_context.ble_peripheral; - if (ble_peripheral != nullptr && + if (remote_context.gatt_server != nullptr && ble_peripheral != nullptr && (ble_peripheral->GetAddress() == peripheral.GetAddress())) { if (remote_context.gatt_server == nullptr) { break;