Skip to content

Commit

Permalink
RPC: Restart commissioning after setting SpakeInfo (#23276)
Browse files Browse the repository at this point in the history
The CommissioningWindowManager now caches the CommssionableDataProvider
and therefore needs to be restarted after changing the SpakeInfo using
the RPC for testing.
  • Loading branch information
rgoliver authored Oct 26, 2022
1 parent 3fe8d91 commit a95dd6f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/common/pigweed/rpc_services/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <platform/CommissionableDataProvider.h>

#include "app/clusters/ota-requestor/OTARequestorInterface.h"
#include "app/server/CommissioningWindowManager.h"
#include "app/server/OnboardingCodesUtil.h"
#include "app/server/Server.h"
#include "credentials/FabricTable.h"
Expand Down Expand Up @@ -418,6 +419,41 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>
{
mCommissionableDataProvider.SetSpake2pVerifier(ByteSpan(request.verifier.bytes, request.verifier.size));
}

if (Server::GetInstance().GetCommissioningWindowManager().IsCommissioningWindowOpen() &&
Server::GetInstance().GetCommissioningWindowManager().CommissioningWindowStatusForCluster() !=
app::Clusters::AdministratorCommissioning::CommissioningWindowStatus::kEnhancedWindowOpen)
{
// Cache values before closing to restore them after restart.
app::DataModel::Nullable<VendorId> vendorId = Server::GetInstance().GetCommissioningWindowManager().GetOpenerVendorId();
app::DataModel::Nullable<FabricIndex> fabricIndex =
Server::GetInstance().GetCommissioningWindowManager().GetOpenerFabricIndex();

// Restart commissioning window to recache the spakeInfo values:
{
DeviceLayer::StackLock lock;
Server::GetInstance().GetCommissioningWindowManager().CloseCommissioningWindow();
}
// Let other tasks possibly work since Commissioning window close/open are "heavy"
if (Server::GetInstance().GetCommissioningWindowManager().CommissioningWindowStatusForCluster() !=
app::Clusters::AdministratorCommissioning::CommissioningWindowStatus::kWindowNotOpen &&
!vendorId.IsNull() && !fabricIndex.IsNull())
{
DeviceLayer::StackLock lock;
System::Clock::Seconds16 commissioningTimeout =
System::Clock::Seconds16(CHIP_DEVICE_CONFIG_DISCOVERY_TIMEOUT_SECS); // Use default for timeout for now.
Server::GetInstance()
.GetCommissioningWindowManager()
.OpenBasicCommissioningWindowForAdministratorCommissioningCluster(commissioningTimeout, fabricIndex.Value(),
vendorId.Value());
}
else
{
DeviceLayer::StackLock lock;
Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow();
}
}

return pw::OkStatus();
}

Expand Down

0 comments on commit a95dd6f

Please sign in to comment.