Skip to content

Commit 9f23012

Browse files
authored
Merge branch 'master' into granbery/power_topology_all_clusters
2 parents d1d6787 + 274719d commit 9f23012

27 files changed

+2326
-807
lines changed

src/app/clusters/network-commissioning/network-commissioning.cpp

+44-18
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <lib/support/SortUtils.h>
3535
#include <lib/support/ThreadOperationalDataset.h>
3636
#include <platform/CHIPDeviceConfig.h>
37+
#include <platform/ConnectivityManager.h>
3738
#include <platform/DeviceControlServer.h>
3839
#include <platform/PlatformManager.h>
3940
#include <platform/internal/DeviceNetworkInfo.h>
@@ -135,6 +136,26 @@ void Instance::Shutdown()
135136
mpBaseDriver->Shutdown();
136137
}
137138

139+
#if !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
140+
void Instance::SendNonConcurrentConnectNetworkResponse()
141+
{
142+
auto commandHandleRef = std::move(mAsyncCommandHandle);
143+
auto commandHandle = commandHandleRef.Get();
144+
if (commandHandle == nullptr)
145+
{
146+
return;
147+
}
148+
149+
#if CONFIG_NETWORK_LAYER_BLE
150+
DeviceLayer::ConnectivityMgr().GetBleLayer()->IndicateBleClosing();
151+
#endif // CONFIG_NETWORK_LAYER_BLE
152+
ChipLogProgress(NetworkProvisioning, "Non-concurrent mode. Send ConnectNetworkResponse(Success)");
153+
Commands::ConnectNetworkResponse::Type response;
154+
response.networkingStatus = NetworkCommissioning::Status::kSuccess;
155+
commandHandle->AddResponse(mPath, response);
156+
}
157+
#endif // CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
158+
138159
void Instance::InvokeCommand(HandlerContext & ctxt)
139160
{
140161
if (mAsyncCommandHandle.Get() != nullptr)
@@ -177,12 +198,7 @@ void Instance::InvokeCommand(HandlerContext & ctxt)
177198

178199
case Commands::ConnectNetwork::Id: {
179200
VerifyOrReturn(mFeatureFlags.Has(Feature::kWiFiNetworkInterface) || mFeatureFlags.Has(Feature::kThreadNetworkInterface));
180-
#if CONFIG_NETWORK_LAYER_BLE && !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
181-
// If commissionee does not support Concurrent Connections, request the BLE to be stopped.
182-
// Start the ConnectNetwork, but this will not complete until the BLE is off.
183-
ChipLogProgress(NetworkProvisioning, "Closing BLE connections due to non-concurrent mode");
184-
DeviceLayer::DeviceControlServer::DeviceControlSvr().PostCloseAllBLEConnectionsToOperationalNetworkEvent();
185-
#endif
201+
186202
HandleCommand<Commands::ConnectNetwork::DecodableType>(
187203
ctxt, [this](HandlerContext & ctx, const auto & req) { HandleConnectNetwork(ctx, req); });
188204
return;
@@ -708,18 +724,22 @@ void Instance::HandleConnectNetwork(HandlerContext & ctx, const Commands::Connec
708724
mAsyncCommandHandle = CommandHandler::Handle(&ctx.mCommandHandler);
709725
mCurrentOperationBreadcrumb = req.breadcrumb;
710726

711-
// In Non-concurrent mode postpone the final execution of ConnectNetwork until the operational
712-
// network has been fully brought up and kWiFiDeviceAvailable is delivered.
713-
// mConnectingNetworkIDLen and mConnectingNetworkID contains the received SSID
714727
#if CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
715728
mpWirelessDriver->ConnectNetwork(req.networkID, this);
729+
#else
730+
// In Non-concurrent mode postpone the final execution of ConnectNetwork until the operational
731+
// network has been fully brought up and kOperationalNetworkStarted is delivered.
732+
// mConnectingNetworkIDLen and mConnectingNetworkID contain the received SSID
733+
// As per spec, send the ConnectNetworkResponse(Success) prior to releasing the commissioning channel
734+
SendNonConcurrentConnectNetworkResponse();
716735
#endif
717736
}
718737

719738
void Instance::HandleNonConcurrentConnectNetwork()
720739
{
721740
ByteSpan nonConcurrentNetworkID = ByteSpan(mConnectingNetworkID, mConnectingNetworkIDLen);
722-
ChipLogProgress(NetworkProvisioning, "HandleNonConcurrentConnectNetwork() SSID=%s", mConnectingNetworkID);
741+
ChipLogProgress(NetworkProvisioning, "Non-concurrent mode, Connect to Network SSID=%.*s", mConnectingNetworkIDLen,
742+
mConnectingNetworkID);
723743
mpWirelessDriver->ConnectNetwork(nonConcurrentNetworkID, this);
724744
}
725745

@@ -826,13 +846,19 @@ void Instance::HandleQueryIdentity(HandlerContext & ctx, const Commands::QueryId
826846
void Instance::OnResult(Status commissioningError, CharSpan debugText, int32_t interfaceStatus)
827847
{
828848
auto commandHandleRef = std::move(mAsyncCommandHandle);
829-
auto commandHandle = commandHandleRef.Get();
849+
850+
// In Non-concurrent mode the commandHandle will be null here, the ConnectNetworkResponse
851+
// has already been sent and the BLE will have been stopped, however the other functionality
852+
// is still required
853+
#if CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
854+
auto commandHandle = commandHandleRef.Get();
830855
if (commandHandle == nullptr)
831856
{
832857
// When the platform shutted down, interaction model engine will invalidate all commandHandle to avoid dangling references.
833858
// We may receive the callback after it and should make it noop.
834859
return;
835860
}
861+
#endif // CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
836862

837863
Commands::ConnectNetworkResponse::Type response;
838864
response.networkingStatus = commissioningError;
@@ -856,13 +882,10 @@ void Instance::OnResult(Status commissioningError, CharSpan debugText, int32_t i
856882
memcpy(mLastNetworkID, mConnectingNetworkID, mLastNetworkIDLen);
857883
mLastNetworkingStatusValue.SetNonNull(commissioningError);
858884

859-
#if CONFIG_NETWORK_LAYER_BLE && !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
860-
ChipLogProgress(NetworkProvisioning, "Non-concurrent mode, ConnectNetworkResponse will NOT be sent");
861-
// Do not send the ConnectNetworkResponse if in non-concurrent mode
862-
// Issue #30576 raised to modify CommandHandler to notify it if no response required
863-
#else
885+
#if CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
864886
commandHandle->AddResponse(mPath, response);
865-
#endif
887+
#endif // CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
888+
866889
if (commissioningError == Status::kSuccess)
867890
{
868891
CommitSavedBreadcrumb();
@@ -1063,8 +1086,11 @@ void Instance::OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event
10631086
{
10641087
this_->OnFailSafeTimerExpired();
10651088
}
1066-
else if (event->Type == DeviceLayer::DeviceEventType::kWiFiDeviceAvailable)
1089+
else if ((event->Type == DeviceLayer::DeviceEventType::kWiFiDeviceAvailable) ||
1090+
(event->Type == DeviceLayer::DeviceEventType::kOperationalNetworkStarted))
1091+
10671092
{
1093+
// In Non-Concurrent mode connect the operational channel, as BLE has been stopped
10681094
this_->HandleNonConcurrentConnectNetwork();
10691095
}
10701096
}

src/app/clusters/network-commissioning/network-commissioning.h

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class Instance : public CommandHandlerInterface,
7878
void OnCommissioningComplete();
7979
void OnFailSafeTimerExpired();
8080

81+
#if !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
82+
void SendNonConcurrentConnectNetworkResponse();
83+
#endif
8184
const BitFlags<Feature> mFeatureFlags;
8285

8386
DeviceLayer::NetworkCommissioning::Internal::WirelessDriver * const mpWirelessDriver;

src/app/clusters/scenes-server/scenes-server.cpp

+29-20
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ CHIP_ERROR AddResponseOnError(CommandHandlerInterface::HandlerContext & ctx, Res
6666
{
6767
resp.status = to_underlying(Protocols::InteractionModel::Status::NotFound);
6868
}
69+
else if (CHIP_ERROR_NO_MEMORY == err)
70+
{
71+
resp.status = to_underlying(Protocols::InteractionModel::Status::ResourceExhausted);
72+
}
6973
else
7074
{
7175
resp.status = to_underlying(StatusIB(err).mStatus);
@@ -168,7 +172,6 @@ CHIP_ERROR UpdateFabricSceneInfo(EndpointId endpoint, FabricIndex fabric, Option
168172

169173
/// @brief Gets the SceneInfoStruct array associated to an endpoint
170174
/// @param endpoint target endpoint
171-
/// @param fabric target fabric
172175
/// @return Optional with no value not found, Span of SceneInfoStruct
173176
Span<Structs::SceneInfoStruct::Type> ScenesServer::FabricSceneInfo::GetFabricSceneInfo(EndpointId endpoint)
174177
{
@@ -675,13 +678,21 @@ void ScenesServer::InvokeCommand(HandlerContext & ctxt)
675678
// AttributeAccessInterface
676679
CHIP_ERROR ScenesServer::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
677680
{
681+
uint16_t endpointTableSize = 0;
682+
ReturnErrorOnFailure(StatusIB(Attributes::SceneTableSize::Get(aPath.mEndpointId, &endpointTableSize)).ToChipError());
683+
684+
// Get Scene Table Instance
685+
SceneTable * sceneTable = scenes::GetSceneTableImpl(aPath.mEndpointId, endpointTableSize);
686+
678687
switch (aPath.mAttributeId)
679688
{
680689
case Attributes::FabricSceneInfo::Id: {
681-
return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR {
690+
return aEncoder.EncodeList([&, sceneTable](const auto & encoder) -> CHIP_ERROR {
682691
Span<Structs::SceneInfoStruct::Type> fabricSceneInfoSpan = mFabricSceneInfo.GetFabricSceneInfo(aPath.mEndpointId);
683692
for (auto & info : fabricSceneInfoSpan)
684693
{
694+
// Update the SceneInfoStruct's Capacity in case it's capacity was limited by other fabrics
695+
sceneTable->GetRemainingCapacity(info.fabricIndex, info.remainingCapacity);
685696
ReturnErrorOnFailure(encoder.Encode(info));
686697
}
687698
return CHIP_NO_ERROR;
@@ -918,12 +929,10 @@ void ScenesServer::HandleStoreScene(HandlerContext & ctx, const Commands::StoreS
918929
CHIP_ERROR err = StoreSceneParse(ctx.mCommandHandler.GetAccessingFabricIndex(), ctx.mRequestPath.mEndpointId, req.groupID,
919930
req.sceneID, mGroupProvider);
920931

921-
if (CHIP_NO_ERROR == err)
922-
{
923-
ReturnOnFailure(UpdateLastConfiguredBy(ctx, response));
924-
}
932+
ReturnOnFailure(AddResponseOnError(ctx, response, err));
925933

926-
response.status = to_underlying(StatusIB(err).mStatus);
934+
ReturnOnFailure(UpdateLastConfiguredBy(ctx, response));
935+
response.status = to_underlying(Protocols::InteractionModel::Status::Success);
927936
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
928937
}
929938

@@ -1031,6 +1040,13 @@ void ScenesServer::HandleCopyScene(HandlerContext & ctx, const Commands::CopySce
10311040
ReturnOnFailure(AddResponseOnError(ctx, response,
10321041
sceneTable->GetRemainingCapacity(ctx.mCommandHandler.GetAccessingFabricIndex(), capacity)));
10331042

1043+
if (0 == capacity)
1044+
{
1045+
response.status = to_underlying(Protocols::InteractionModel::Status::ResourceExhausted);
1046+
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
1047+
return;
1048+
}
1049+
10341050
// Checks if we copy a single scene or all of them
10351051
if (req.mode.GetField(app::Clusters::ScenesManagement::CopyModeBitmap::kCopyAllScenes))
10361052
{
@@ -1043,13 +1059,6 @@ void ScenesServer::HandleCopyScene(HandlerContext & ctx, const Commands::CopySce
10431059
ctx, response,
10441060
sceneTable->GetAllSceneIdsInGroup(ctx.mCommandHandler.GetAccessingFabricIndex(), req.groupIdentifierFrom, sceneList)));
10451061

1046-
if (0 == capacity)
1047-
{
1048-
response.status = to_underlying(Protocols::InteractionModel::Status::ResourceExhausted);
1049-
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
1050-
return;
1051-
}
1052-
10531062
for (auto & sceneId : sceneList)
10541063
{
10551064
SceneTableEntry scene(SceneStorageId(sceneId, req.groupIdentifierFrom));
@@ -1062,13 +1071,13 @@ void ScenesServer::HandleCopyScene(HandlerContext & ctx, const Commands::CopySce
10621071

10631072
ReturnOnFailure(AddResponseOnError(
10641073
ctx, response, sceneTable->SetSceneTableEntry(ctx.mCommandHandler.GetAccessingFabricIndex(), scene)));
1065-
}
10661074

1067-
// Update SceneInfoStruct Attributes
1068-
ReturnOnFailure(
1069-
AddResponseOnError(ctx, response,
1070-
UpdateFabricSceneInfo(ctx.mRequestPath.mEndpointId, ctx.mCommandHandler.GetAccessingFabricIndex(),
1071-
Optional<GroupId>(), Optional<SceneId>(), Optional<bool>())));
1075+
// Update SceneInfoStruct Attributes after each insert in case we hit max capacity in the middle of the loop
1076+
ReturnOnFailure(AddResponseOnError(
1077+
ctx, response,
1078+
UpdateFabricSceneInfo(ctx.mRequestPath.mEndpointId, ctx.mCommandHandler.GetAccessingFabricIndex(),
1079+
Optional<GroupId>(), Optional<SceneId>(), Optional<bool>() /* = sceneValid*/)));
1080+
}
10721081

10731082
ReturnOnFailure(UpdateLastConfiguredBy(ctx, response));
10741083

src/app/server/CommissioningWindowManager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ void CommissioningWindowManager::OnPlatformEvent(const DeviceLayer::ChipDeviceEv
8989
#if CONFIG_NETWORK_LAYER_BLE
9090
else if (event->Type == DeviceLayer::DeviceEventType::kCloseAllBleConnections)
9191
{
92-
ChipLogProgress(AppServer, "Received kCloseAllBleConnections");
93-
mServer->GetBleLayerObject()->CloseAllBleConnections();
92+
ChipLogProgress(AppServer, "Received kCloseAllBleConnections:%d", static_cast<int>(event->Type));
93+
mServer->GetBleLayerObject()->Shutdown();
9494
}
9595
#endif
9696
}

0 commit comments

Comments
 (0)