From 1031536fa2505e20b79eedb47229c7572a93e802 Mon Sep 17 00:00:00 2001 From: wendythewan <99999710+wendythewan@users.noreply.github.com> Date: Thu, 24 Mar 2022 05:47:29 -0700 Subject: [PATCH] Wrap usages of src/ble/... with CONFIG_NETWORK_LAYER_BLE (#16414) * Wrap usages of src/ble/BleLayer with CONFIG_NETWORK_LAYER_BLE * Restyle Server.cpp * Restyle CHIPDeviceControllerFactory * Restyle CASEServer.cpp * Update Server.cpp * Restyle change * Restyle change * Restyle * Restyle * Restyle * Remove whitespace --- src/app/server/Server.cpp | 9 ++++++++- src/controller/CHIPDeviceControllerFactory.cpp | 8 ++++++-- src/include/platform/CHIPDeviceLayer.h | 1 - src/include/platform/internal/BLEManager.h | 2 ++ src/protocols/secure_channel/CASEServer.cpp | 10 +++++++--- src/protocols/secure_channel/CASEServer.h | 11 +++++++++-- .../secure_channel/tests/TestCASESession.cpp | 5 ++++- 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 63af6a1a07d555..9967491c6dae24 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -25,7 +25,9 @@ #include #include +#if CONFIG_NETWORK_LAYER_BLE #include +#endif #include #include #include @@ -51,7 +53,9 @@ using chip::kMinValidFabricIndex; using chip::RendezvousInformationFlag; using chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr; using chip::Inet::IPAddressType; +#if CONFIG_NETWORK_LAYER_BLE using chip::Transport::BleListenParameters; +#endif using chip::Transport::PeerAddress; using chip::Transport::UdpListenParameters; @@ -239,7 +243,10 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint app::DnssdServer::Instance().StartServer(); #endif - err = mCASEServer.ListenForSessionEstablishment(&mExchangeMgr, &mTransports, chip::DeviceLayer::ConnectivityMgr().GetBleLayer(), + err = mCASEServer.ListenForSessionEstablishment(&mExchangeMgr, &mTransports, +#if CONFIG_NETWORK_LAYER_BLE + chip::DeviceLayer::ConnectivityMgr().GetBleLayer(), +#endif &mSessions, &mFabrics); SuccessOrExit(err); diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index d04f56e83123a4..92668b255a0d5a 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -178,8 +178,12 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params) // We pass in a nullptr for the BLELayer since we're not permitting usage of BLE in this server modality for the controller, // especially since it will interrupt other potential usages of BLE by the controller acting in a commissioning capacity. // - ReturnErrorOnFailure(stateParams.caseServer->ListenForSessionEstablishment( - stateParams.exchangeMgr, stateParams.transportMgr, nullptr, stateParams.sessionMgr, stateParams.fabricTable)); + ReturnErrorOnFailure( + stateParams.caseServer->ListenForSessionEstablishment(stateParams.exchangeMgr, stateParams.transportMgr, +#if CONFIG_NETWORK_LAYER_BLE + nullptr, +#endif + stateParams.sessionMgr, stateParams.fabricTable)); // // We need to advertise the port that we're listening to for unsolicited messages over UDP. However, we have both a IPv4 diff --git a/src/include/platform/CHIPDeviceLayer.h b/src/include/platform/CHIPDeviceLayer.h index 8d6fab3f7248c7..9e317b3d7ccb96 100644 --- a/src/include/platform/CHIPDeviceLayer.h +++ b/src/include/platform/CHIPDeviceLayer.h @@ -22,7 +22,6 @@ #if !CHIP_DEVICE_LAYER_NONE -#include #include #include #include diff --git a/src/include/platform/internal/BLEManager.h b/src/include/platform/internal/BLEManager.h index 3910822f1952ae..2bb3cd66ae872c 100644 --- a/src/include/platform/internal/BLEManager.h +++ b/src/include/platform/internal/BLEManager.h @@ -119,7 +119,9 @@ inline CHIP_ERROR BLEManager::Init() inline CHIP_ERROR BLEManager::Shutdown() { +#if CONFIG_NETWORK_LAYER_BLE ReturnErrorOnFailure(GetBleLayer()->Shutdown()); +#endif return static_cast(this)->_Shutdown(); } diff --git a/src/protocols/secure_channel/CASEServer.cpp b/src/protocols/secure_channel/CASEServer.cpp index e54362a100a19b..139e0079fcee86 100644 --- a/src/protocols/secure_channel/CASEServer.cpp +++ b/src/protocols/secure_channel/CASEServer.cpp @@ -30,15 +30,19 @@ using namespace ::chip::Credentials; namespace chip { CHIP_ERROR CASEServer::ListenForSessionEstablishment(Messaging::ExchangeManager * exchangeManager, TransportMgrBase * transportMgr, - Ble::BleLayer * bleLayer, SessionManager * sessionManager, - FabricTable * fabrics) +#if CONFIG_NETWORK_LAYER_BLE + Ble::BleLayer * bleLayer, +#endif + SessionManager * sessionManager, FabricTable * fabrics) { VerifyOrReturnError(transportMgr != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(exchangeManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(sessionManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(fabrics != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - mBleLayer = bleLayer; +#if CONFIG_NETWORK_LAYER_BLE + mBleLayer = bleLayer; +#endif mSessionManager = sessionManager; mFabrics = fabrics; mExchangeManager = exchangeManager; diff --git a/src/protocols/secure_channel/CASEServer.h b/src/protocols/secure_channel/CASEServer.h index 81597fbb3e5f59..0bb6e85f000cd1 100644 --- a/src/protocols/secure_channel/CASEServer.h +++ b/src/protocols/secure_channel/CASEServer.h @@ -17,7 +17,9 @@ #pragma once +#if CONFIG_NETWORK_LAYER_BLE #include +#endif #include #include #include @@ -38,7 +40,10 @@ class CASEServer : public SessionEstablishmentDelegate, public Messaging::Exchan } CHIP_ERROR ListenForSessionEstablishment(Messaging::ExchangeManager * exchangeManager, TransportMgrBase * transportMgr, - Ble::BleLayer * bleLayer, SessionManager * sessionManager, FabricTable * fabrics); +#if CONFIG_NETWORK_LAYER_BLE + Ble::BleLayer * bleLayer, +#endif + SessionManager * sessionManager, FabricTable * fabrics); //////////// SessionEstablishmentDelegate Implementation /////////////// void OnSessionEstablishmentError(CHIP_ERROR error) override; @@ -58,7 +63,9 @@ class CASEServer : public SessionEstablishmentDelegate, public Messaging::Exchan CASESession mPairingSession; uint16_t mSessionKeyId = 0; SessionManager * mSessionManager = nullptr; - Ble::BleLayer * mBleLayer = nullptr; +#if CONFIG_NETWORK_LAYER_BLE + Ble::BleLayer * mBleLayer = nullptr; +#endif FabricTable * mFabrics = nullptr; SessionIDAllocator mSessionIDAllocator; diff --git a/src/protocols/secure_channel/tests/TestCASESession.cpp b/src/protocols/secure_channel/tests/TestCASESession.cpp index 1c75010df24062..66f52f1e862678 100644 --- a/src/protocols/secure_channel/tests/TestCASESession.cpp +++ b/src/protocols/secure_channel/tests/TestCASESession.cpp @@ -374,7 +374,10 @@ void CASE_SecurePairingHandshakeServerTest(nlTestSuite * inSuite, void * inConte gLoopback.mSentMessageCount = 0; NL_TEST_ASSERT(inSuite, - gPairingServer.ListenForSessionEstablishment(&ctx.GetExchangeManager(), &ctx.GetTransportMgr(), nullptr, + gPairingServer.ListenForSessionEstablishment(&ctx.GetExchangeManager(), &ctx.GetTransportMgr(), +#if CONFIG_NETWORK_LAYER_BLE + nullptr, +#endif &ctx.GetSecureSessionManager(), &gDeviceFabrics) == CHIP_NO_ERROR); ExchangeContext * contextCommissioner = ctx.NewUnauthenticatedExchangeToBob(pairingCommissioner);