Skip to content

Commit

Permalink
Merge branch 'master' into granbery/power_topology_all_clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
robszewczyk authored Feb 15, 2024
2 parents d1d6787 + 274719d commit 9f23012
Show file tree
Hide file tree
Showing 27 changed files with 2,326 additions and 807 deletions.
62 changes: 44 additions & 18 deletions src/app/clusters/network-commissioning/network-commissioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <lib/support/SortUtils.h>
#include <lib/support/ThreadOperationalDataset.h>
#include <platform/CHIPDeviceConfig.h>
#include <platform/ConnectivityManager.h>
#include <platform/DeviceControlServer.h>
#include <platform/PlatformManager.h>
#include <platform/internal/DeviceNetworkInfo.h>
Expand Down Expand Up @@ -135,6 +136,26 @@ void Instance::Shutdown()
mpBaseDriver->Shutdown();
}

#if !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
void Instance::SendNonConcurrentConnectNetworkResponse()
{
auto commandHandleRef = std::move(mAsyncCommandHandle);
auto commandHandle = commandHandleRef.Get();
if (commandHandle == nullptr)
{
return;
}

#if CONFIG_NETWORK_LAYER_BLE
DeviceLayer::ConnectivityMgr().GetBleLayer()->IndicateBleClosing();
#endif // CONFIG_NETWORK_LAYER_BLE
ChipLogProgress(NetworkProvisioning, "Non-concurrent mode. Send ConnectNetworkResponse(Success)");
Commands::ConnectNetworkResponse::Type response;
response.networkingStatus = NetworkCommissioning::Status::kSuccess;
commandHandle->AddResponse(mPath, response);
}
#endif // CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION

void Instance::InvokeCommand(HandlerContext & ctxt)
{
if (mAsyncCommandHandle.Get() != nullptr)
Expand Down Expand Up @@ -177,12 +198,7 @@ void Instance::InvokeCommand(HandlerContext & ctxt)

case Commands::ConnectNetwork::Id: {
VerifyOrReturn(mFeatureFlags.Has(Feature::kWiFiNetworkInterface) || mFeatureFlags.Has(Feature::kThreadNetworkInterface));
#if CONFIG_NETWORK_LAYER_BLE && !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
// If commissionee does not support Concurrent Connections, request the BLE to be stopped.
// Start the ConnectNetwork, but this will not complete until the BLE is off.
ChipLogProgress(NetworkProvisioning, "Closing BLE connections due to non-concurrent mode");
DeviceLayer::DeviceControlServer::DeviceControlSvr().PostCloseAllBLEConnectionsToOperationalNetworkEvent();
#endif

HandleCommand<Commands::ConnectNetwork::DecodableType>(
ctxt, [this](HandlerContext & ctx, const auto & req) { HandleConnectNetwork(ctx, req); });
return;
Expand Down Expand Up @@ -708,18 +724,22 @@ void Instance::HandleConnectNetwork(HandlerContext & ctx, const Commands::Connec
mAsyncCommandHandle = CommandHandler::Handle(&ctx.mCommandHandler);
mCurrentOperationBreadcrumb = req.breadcrumb;

// In Non-concurrent mode postpone the final execution of ConnectNetwork until the operational
// network has been fully brought up and kWiFiDeviceAvailable is delivered.
// mConnectingNetworkIDLen and mConnectingNetworkID contains the received SSID
#if CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
mpWirelessDriver->ConnectNetwork(req.networkID, this);
#else
// In Non-concurrent mode postpone the final execution of ConnectNetwork until the operational
// network has been fully brought up and kOperationalNetworkStarted is delivered.
// mConnectingNetworkIDLen and mConnectingNetworkID contain the received SSID
// As per spec, send the ConnectNetworkResponse(Success) prior to releasing the commissioning channel
SendNonConcurrentConnectNetworkResponse();
#endif
}

void Instance::HandleNonConcurrentConnectNetwork()
{
ByteSpan nonConcurrentNetworkID = ByteSpan(mConnectingNetworkID, mConnectingNetworkIDLen);
ChipLogProgress(NetworkProvisioning, "HandleNonConcurrentConnectNetwork() SSID=%s", mConnectingNetworkID);
ChipLogProgress(NetworkProvisioning, "Non-concurrent mode, Connect to Network SSID=%.*s", mConnectingNetworkIDLen,
mConnectingNetworkID);
mpWirelessDriver->ConnectNetwork(nonConcurrentNetworkID, this);
}

Expand Down Expand Up @@ -826,13 +846,19 @@ void Instance::HandleQueryIdentity(HandlerContext & ctx, const Commands::QueryId
void Instance::OnResult(Status commissioningError, CharSpan debugText, int32_t interfaceStatus)
{
auto commandHandleRef = std::move(mAsyncCommandHandle);
auto commandHandle = commandHandleRef.Get();

// In Non-concurrent mode the commandHandle will be null here, the ConnectNetworkResponse
// has already been sent and the BLE will have been stopped, however the other functionality
// is still required
#if CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
auto commandHandle = commandHandleRef.Get();
if (commandHandle == nullptr)
{
// When the platform shutted down, interaction model engine will invalidate all commandHandle to avoid dangling references.
// We may receive the callback after it and should make it noop.
return;
}
#endif // CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION

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

#if CONFIG_NETWORK_LAYER_BLE && !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
ChipLogProgress(NetworkProvisioning, "Non-concurrent mode, ConnectNetworkResponse will NOT be sent");
// Do not send the ConnectNetworkResponse if in non-concurrent mode
// Issue #30576 raised to modify CommandHandler to notify it if no response required
#else
#if CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
commandHandle->AddResponse(mPath, response);
#endif
#endif // CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION

if (commissioningError == Status::kSuccess)
{
CommitSavedBreadcrumb();
Expand Down Expand Up @@ -1063,8 +1086,11 @@ void Instance::OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event
{
this_->OnFailSafeTimerExpired();
}
else if (event->Type == DeviceLayer::DeviceEventType::kWiFiDeviceAvailable)
else if ((event->Type == DeviceLayer::DeviceEventType::kWiFiDeviceAvailable) ||
(event->Type == DeviceLayer::DeviceEventType::kOperationalNetworkStarted))

{
// In Non-Concurrent mode connect the operational channel, as BLE has been stopped
this_->HandleNonConcurrentConnectNetwork();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class Instance : public CommandHandlerInterface,
void OnCommissioningComplete();
void OnFailSafeTimerExpired();

#if !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
void SendNonConcurrentConnectNetworkResponse();
#endif
const BitFlags<Feature> mFeatureFlags;

DeviceLayer::NetworkCommissioning::Internal::WirelessDriver * const mpWirelessDriver;
Expand Down
49 changes: 29 additions & 20 deletions src/app/clusters/scenes-server/scenes-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ CHIP_ERROR AddResponseOnError(CommandHandlerInterface::HandlerContext & ctx, Res
{
resp.status = to_underlying(Protocols::InteractionModel::Status::NotFound);
}
else if (CHIP_ERROR_NO_MEMORY == err)
{
resp.status = to_underlying(Protocols::InteractionModel::Status::ResourceExhausted);
}
else
{
resp.status = to_underlying(StatusIB(err).mStatus);
Expand Down Expand Up @@ -168,7 +172,6 @@ CHIP_ERROR UpdateFabricSceneInfo(EndpointId endpoint, FabricIndex fabric, Option

/// @brief Gets the SceneInfoStruct array associated to an endpoint
/// @param endpoint target endpoint
/// @param fabric target fabric
/// @return Optional with no value not found, Span of SceneInfoStruct
Span<Structs::SceneInfoStruct::Type> ScenesServer::FabricSceneInfo::GetFabricSceneInfo(EndpointId endpoint)
{
Expand Down Expand Up @@ -675,13 +678,21 @@ void ScenesServer::InvokeCommand(HandlerContext & ctxt)
// AttributeAccessInterface
CHIP_ERROR ScenesServer::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
uint16_t endpointTableSize = 0;
ReturnErrorOnFailure(StatusIB(Attributes::SceneTableSize::Get(aPath.mEndpointId, &endpointTableSize)).ToChipError());

// Get Scene Table Instance
SceneTable * sceneTable = scenes::GetSceneTableImpl(aPath.mEndpointId, endpointTableSize);

switch (aPath.mAttributeId)
{
case Attributes::FabricSceneInfo::Id: {
return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR {
return aEncoder.EncodeList([&, sceneTable](const auto & encoder) -> CHIP_ERROR {
Span<Structs::SceneInfoStruct::Type> fabricSceneInfoSpan = mFabricSceneInfo.GetFabricSceneInfo(aPath.mEndpointId);
for (auto & info : fabricSceneInfoSpan)
{
// Update the SceneInfoStruct's Capacity in case it's capacity was limited by other fabrics
sceneTable->GetRemainingCapacity(info.fabricIndex, info.remainingCapacity);
ReturnErrorOnFailure(encoder.Encode(info));
}
return CHIP_NO_ERROR;
Expand Down Expand Up @@ -918,12 +929,10 @@ void ScenesServer::HandleStoreScene(HandlerContext & ctx, const Commands::StoreS
CHIP_ERROR err = StoreSceneParse(ctx.mCommandHandler.GetAccessingFabricIndex(), ctx.mRequestPath.mEndpointId, req.groupID,
req.sceneID, mGroupProvider);

if (CHIP_NO_ERROR == err)
{
ReturnOnFailure(UpdateLastConfiguredBy(ctx, response));
}
ReturnOnFailure(AddResponseOnError(ctx, response, err));

response.status = to_underlying(StatusIB(err).mStatus);
ReturnOnFailure(UpdateLastConfiguredBy(ctx, response));
response.status = to_underlying(Protocols::InteractionModel::Status::Success);
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
}

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

if (0 == capacity)
{
response.status = to_underlying(Protocols::InteractionModel::Status::ResourceExhausted);
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
return;
}

// Checks if we copy a single scene or all of them
if (req.mode.GetField(app::Clusters::ScenesManagement::CopyModeBitmap::kCopyAllScenes))
{
Expand All @@ -1043,13 +1059,6 @@ void ScenesServer::HandleCopyScene(HandlerContext & ctx, const Commands::CopySce
ctx, response,
sceneTable->GetAllSceneIdsInGroup(ctx.mCommandHandler.GetAccessingFabricIndex(), req.groupIdentifierFrom, sceneList)));

if (0 == capacity)
{
response.status = to_underlying(Protocols::InteractionModel::Status::ResourceExhausted);
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
return;
}

for (auto & sceneId : sceneList)
{
SceneTableEntry scene(SceneStorageId(sceneId, req.groupIdentifierFrom));
Expand All @@ -1062,13 +1071,13 @@ void ScenesServer::HandleCopyScene(HandlerContext & ctx, const Commands::CopySce

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

// Update SceneInfoStruct Attributes
ReturnOnFailure(
AddResponseOnError(ctx, response,
UpdateFabricSceneInfo(ctx.mRequestPath.mEndpointId, ctx.mCommandHandler.GetAccessingFabricIndex(),
Optional<GroupId>(), Optional<SceneId>(), Optional<bool>())));
// Update SceneInfoStruct Attributes after each insert in case we hit max capacity in the middle of the loop
ReturnOnFailure(AddResponseOnError(
ctx, response,
UpdateFabricSceneInfo(ctx.mRequestPath.mEndpointId, ctx.mCommandHandler.GetAccessingFabricIndex(),
Optional<GroupId>(), Optional<SceneId>(), Optional<bool>() /* = sceneValid*/)));
}

ReturnOnFailure(UpdateLastConfiguredBy(ctx, response));

Expand Down
4 changes: 2 additions & 2 deletions src/app/server/CommissioningWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ void CommissioningWindowManager::OnPlatformEvent(const DeviceLayer::ChipDeviceEv
#if CONFIG_NETWORK_LAYER_BLE
else if (event->Type == DeviceLayer::DeviceEventType::kCloseAllBleConnections)
{
ChipLogProgress(AppServer, "Received kCloseAllBleConnections");
mServer->GetBleLayerObject()->CloseAllBleConnections();
ChipLogProgress(AppServer, "Received kCloseAllBleConnections:%d", static_cast<int>(event->Type));
mServer->GetBleLayerObject()->Shutdown();
}
#endif
}
Expand Down
Loading

0 comments on commit 9f23012

Please sign in to comment.