Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-commissioner: remove primary network config if failed in commissioning SecondaryNetworkInterface #35255

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/controller/AutoCommissioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,16 @@ CommissioningStage AutoCommissioner::GetNextCommissioningStageInternal(Commissio
case CommissioningStage::kEvictPreviousCaseSessions:
return CommissioningStage::kFindOperationalForStayActive;
case CommissioningStage::kPrimaryOperationalNetworkFailed:
return CommissioningStage::kDisablePrimaryNetworkInterface;
case CommissioningStage::kDisablePrimaryNetworkInterface:
if (mDeviceCommissioningInfo.network.wifi.endpoint == kRootEndpointId)
{
return CommissioningStage::kRemoveWiFiNetworkConfig;
}
else
{
return CommissioningStage::kRemoveThreadNetworkConfig;
}
case CommissioningStage::kRemoveWiFiNetworkConfig:
case CommissioningStage::kRemoveThreadNetworkConfig:
return GetNextCommissioningStageNetworkSetup(currentStage, lastErr);
case CommissioningStage::kFindOperationalForStayActive:
return CommissioningStage::kICDSendStayActive;
Expand Down Expand Up @@ -567,7 +575,8 @@ EndpointId AutoCommissioner::GetEndpoint(const CommissioningStage & stage) const
case CommissioningStage::kThreadNetworkSetup:
case CommissioningStage::kThreadNetworkEnable:
return mDeviceCommissioningInfo.network.thread.endpoint;
case CommissioningStage::kDisablePrimaryNetworkInterface:
case CommissioningStage::kRemoveWiFiNetworkConfig:
case CommissioningStage::kRemoveThreadNetworkConfig:
return kRootEndpointId;
default:
return kRootEndpointId;
Expand Down
46 changes: 32 additions & 14 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1878,12 +1878,6 @@ void DeviceCommissioner::OnBasicSuccess(void * context, const chip::app::DataMod
commissioner->CommissioningStageComplete(CHIP_NO_ERROR);
}

void DeviceCommissioner::OnInterfaceEnableWriteSuccessResponse(void * context)
{
DeviceCommissioner * commissioner = static_cast<DeviceCommissioner *>(context);
commissioner->CommissioningStageComplete(CHIP_NO_ERROR);
}

void DeviceCommissioner::OnBasicFailure(void * context, CHIP_ERROR error)
{
ChipLogProgress(Controller, "Received failure response %s\n", chip::ErrorStr(error));
Expand Down Expand Up @@ -3536,19 +3530,43 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio
}
break;
case CommissioningStage::kPrimaryOperationalNetworkFailed: {
// nothing to do. This stage indicates that the primary operational network failed and the network interface should be
// disabled later.
// nothing to do. This stage indicates that the primary operational network failed and the network config should be
// removed later.
break;
}
case CommissioningStage::kDisablePrimaryNetworkInterface: {
NetworkCommissioning::Attributes::InterfaceEnabled::TypeInfo::Type request = false;
CHIP_ERROR err = SendCommissioningWriteRequest(proxy, endpoint, NetworkCommissioning::Id,
NetworkCommissioning::Attributes::InterfaceEnabled::Id, request,
OnInterfaceEnableWriteSuccessResponse, OnBasicFailure);
case CommissioningStage::kRemoveWiFiNetworkConfig: {
NetworkCommissioning::Commands::RemoveNetwork::Type request;
request.networkID = params.GetWiFiCredentials().Value().ssid;
DejinChen marked this conversation as resolved.
Show resolved Hide resolved
request.breadcrumb.Emplace(breadcrumb);
CHIP_ERROR err = SendCommissioningCommand(proxy, request, OnNetworkConfigResponse, OnBasicFailure, endpoint, timeout);
if (err != CHIP_NO_ERROR)
{
// We won't get any async callbacks here, so just complete our stage.
ChipLogError(Controller, "Failed to send RemoveNetwork command: %" CHIP_ERROR_FORMAT, err.Format());
CommissioningStageComplete(err);
return;
}
break;
}
case CommissioningStage::kRemoveThreadNetworkConfig: {
ByteSpan extendedPanId;
chip::Thread::OperationalDataset operationalDataset;
if (!params.GetThreadOperationalDataset().HasValue() ||
operationalDataset.Init(params.GetThreadOperationalDataset().Value()) != CHIP_NO_ERROR ||
operationalDataset.GetExtendedPanIdAsByteSpan(extendedPanId) != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Unable to get extended pan ID for thread operational dataset\n");
CommissioningStageComplete(CHIP_ERROR_INVALID_ARGUMENT);
return;
}
NetworkCommissioning::Commands::RemoveNetwork::Type request;
request.networkID = extendedPanId;
request.breadcrumb.Emplace(breadcrumb);
CHIP_ERROR err = SendCommissioningCommand(proxy, request, OnNetworkConfigResponse, OnBasicFailure, endpoint, timeout);
if (err != CHIP_NO_ERROR)
{
// We won't get any async callbacks here, so just complete our stage.
ChipLogError(Controller, "Failed to send InterfaceEnabled write request: %" CHIP_ERROR_FORMAT, err.Format());
ChipLogError(Controller, "Failed to send RemoveNetwork command: %" CHIP_ERROR_FORMAT, err.Format());
CommissioningStageComplete(err);
return;
}
Expand Down
2 changes: 0 additions & 2 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,6 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
OnICDManagementStayActiveResponse(void * context,
const app::Clusters::IcdManagement::Commands::StayActiveResponse::DecodableType & data);

static void OnInterfaceEnableWriteSuccessResponse(void * context);

/**
* @brief
* This function processes the CSR sent by the device.
Expand Down
7 changes: 5 additions & 2 deletions src/controller/CommissioningDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ const char * StageToString(CommissioningStage stage)
case kPrimaryOperationalNetworkFailed:
return "PrimaryOperationalNetworkFailed";

case kDisablePrimaryNetworkInterface:
return "DisablePrimaryNetworkInterface";
case kRemoveWiFiNetworkConfig:
return "RemoveWiFiNetworkConfig";

case kRemoveThreadNetworkConfig:
return "RemoveThreadNetworkConfig";

default:
return "???";
Expand Down
7 changes: 4 additions & 3 deletions src/controller/CommissioningDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ enum CommissioningStage : uint8_t
/// Call CHIPDeviceController::NetworkCredentialsReady() when CommissioningParameters is populated with
/// network credentials to use in kWiFiNetworkSetup or kThreadNetworkSetup steps.
kNeedsNetworkCreds,
kPrimaryOperationalNetworkFailed, ///< Indicate that the primary operational network (on root endpoint) failed, should disable
///< the primary network interface later.
kDisablePrimaryNetworkInterface, ///< Send InterfaceEnabled write request to the device to disable network interface.
kPrimaryOperationalNetworkFailed, ///< Indicate that the primary operational network (on root endpoint) failed, should remove
///< the primary network config later.
kRemoveWiFiNetworkConfig, ///< Remove Wi-Fi network config.
kRemoveThreadNetworkConfig ///< Remove Thread network config.
};

enum class ICDRegistrationStrategy : uint8_t
Expand Down
Loading