Skip to content

Commit

Permalink
Fix code-wifi-thread command and reset trying secondary network flag
Browse files Browse the repository at this point in the history
  • Loading branch information
DejinChen committed Jun 12, 2024
1 parent 1b066b7 commit 1e3c634
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
18 changes: 9 additions & 9 deletions examples/chip-tool/commands/pairing/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ class PairCodeThread : public PairingCommand
{}
};

class PairCodeWiFiThread : public PairingCommand
{
public:
PairCodeWiFiThread(CredentialIssuerCommands * credsIssuerConfig) :
PairingCommand("code-wifi-thread", PairingMode::Code, PairingNetworkType::WiFiOrThread, credsIssuerConfig)
{}
};

class PairOnNetwork : public PairingCommand
{
public:
Expand Down Expand Up @@ -165,14 +173,6 @@ class PairBleThread : public PairingCommand
{}
};

class PairBleWiFiOrThread : public PairingCommand
{
public:
PairBleWiFiOrThread(CredentialIssuerCommands * credsIssuerConfig) :
PairingCommand("ble-wifi-thread", PairingMode::Ble, PairingNetworkType::WiFiOrThread, credsIssuerConfig)
{}
};

class PairSoftAP : public PairingCommand
{
public:
Expand Down Expand Up @@ -239,9 +239,9 @@ void registerCommandsPairing(Commands & commands, CredentialIssuerCommands * cre
make_unique<PairCodePase>(credsIssuerConfig),
make_unique<PairCodeWifi>(credsIssuerConfig),
make_unique<PairCodeThread>(credsIssuerConfig),
make_unique<PairCodeWiFiThread>(credsIssuerConfig),
make_unique<PairBleWiFi>(credsIssuerConfig),
make_unique<PairBleThread>(credsIssuerConfig),
make_unique<PairBleWiFiOrThread>(credsIssuerConfig),
make_unique<PairSoftAP>(credsIssuerConfig),
make_unique<PairAlreadyDiscovered>(credsIssuerConfig),
make_unique<PairAlreadyDiscoveredByIndex>(credsIssuerConfig),
Expand Down
10 changes: 7 additions & 3 deletions src/controller/AutoCommissioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ CommissioningStage AutoCommissioner::GetNextCommissioningStageNetworkSetup(Commi
{
if (IsSecondaryNetworkSupported())
{
if (IsTriedSecondaryNetwork())
if (TryingSecondaryNetwork())
{
// Try secondary network interface.
return mDeviceCommissioningInfo.network.wifi.endpoint == kRootEndpointId ? CommissioningStage::kThreadNetworkSetup
Expand Down Expand Up @@ -729,12 +729,12 @@ CHIP_ERROR AutoCommissioner::CommissioningStepFinished(CHIP_ERROR err, Commissio
}
}

if (err != CHIP_NO_ERROR && IsSecondaryNetworkSupported() && !IsTriedSecondaryNetwork() &&
if (err != CHIP_NO_ERROR && IsSecondaryNetworkSupported() && !TryingSecondaryNetwork() &&
completionStatus.failedStage.HasValue() && completionStatus.failedStage.Value() >= kWiFiNetworkSetup &&
completionStatus.failedStage.Value() <= kICDSendStayActive)
{
// Primary network failed, disable primary network interface and try secondary network interface.
SetTrySecondaryNetwork();
TrySecondaryNetwork();
err = CHIP_NO_ERROR;
report.stageCompleted = CommissioningStage::kPrimaryOperationalNetworkFailed;
}
Expand Down Expand Up @@ -856,6 +856,10 @@ CHIP_ERROR AutoCommissioner::CommissioningStepFinished(CHIP_ERROR err, Commissio
mOperationalDeviceProxy = report.Get<OperationalNodeFoundData>().operationalProxy;
break;
case CommissioningStage::kCleanup:
if (IsSecondaryNetworkSupported() && TryingSecondaryNetwork())
{
ResetTryingSecondaryNetwork();
}
ReleasePAI();
ReleaseDAC();
mCommissioneeDeviceProxy = nullptr;
Expand Down
7 changes: 4 additions & 3 deletions src/controller/AutoCommissioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ class AutoCommissioner : public CommissioningDelegate
mDeviceCommissioningInfo.network.thread.endpoint != kInvalidEndpointId);
}

void SetTrySecondaryNetwork() { mAttemptedSecondaryNetwork = true; }
bool IsTriedSecondaryNetwork() const { return mAttemptedSecondaryNetwork; }
bool mAttemptedSecondaryNetwork = false;
void TrySecondaryNetwork() { mTryingSecondaryNetwork = true; }
bool TryingSecondaryNetwork() const { return mTryingSecondaryNetwork; }
void ResetTryingSecondaryNetwork() { mTryingSecondaryNetwork = false; }
bool mTryingSecondaryNetwork = false;

bool mStopCommissioning = false;

Expand Down
11 changes: 5 additions & 6 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2756,7 +2756,7 @@ CHIP_ERROR DeviceCommissioner::SendCommissioningWriteRequest(DeviceProxy * devic
auto onSuccessCb = [this, successCb](const app::ConcreteAttributePath & aPath) { successCb(this); };
auto onFailureCb = [this, failureCb](const app::ConcreteAttributePath * aPath, CHIP_ERROR aError) { failureCb(this, aError); };
return WriteAttribute(device->GetSecureSession().Value(), endpoint, cluster, attribute, requestData, onSuccessCb, onFailureCb,
NullOptional, nullptr, NullOptional);
/* aTimedWriteTimeoutMs = */ NullOptional, /* onDoneCb = */ nullptr, /* aDataVersion = */ NullOptional);
}

void DeviceCommissioner::SendCommissioningReadRequest(DeviceProxy * proxy, Optional<System::Clock::Timeout> timeout,
Expand Down Expand Up @@ -3444,16 +3444,15 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio
}
break;
case CommissioningStage::kPrimaryOperationalNetworkFailed: {
// nothing to do. This stage indicates that the primary operation network failed and the network interface should be
// nothing to do. This stage indicates that the primary operational network failed and the network interface should be
// disabled later.
break;
}
case CommissioningStage::kDisablePrimaryNetworkInterface: {
NetworkCommissioning::Attributes::InterfaceEnabled::TypeInfo::Type request = false;
CHIP_ERROR err = SendCommissioningWriteRequest(
proxy, endpoint, NetworkCommissioning::Attributes::InterfaceEnabled::TypeInfo::GetClusterId(),
NetworkCommissioning::Attributes::InterfaceEnabled::TypeInfo::GetAttributeId(), request,
OnInterfaceEnableWriteSuccessResponse, OnBasicFailure);
CHIP_ERROR err = SendCommissioningWriteRequest(proxy, endpoint, NetworkCommissioning::Id,
NetworkCommissioning::Attributes::InterfaceEnabled::Id, request,
OnInterfaceEnableWriteSuccessResponse, OnBasicFailure);
if (err != CHIP_NO_ERROR)
{
// We won't get any async callbacks here, so just complete our stage.
Expand Down
4 changes: 2 additions & 2 deletions src/controller/CommissioningDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ const char * StageToString(CommissioningStage stage)
return "NeedsNetworkCreds";

case kPrimaryOperationalNetworkFailed:
return "kPrimaryOperationalNetworkFailed";
return "PrimaryOperationalNetworkFailed";

case kDisablePrimaryNetworkInterface:
return "kDisablePrimaryNetworkInterface";
return "DisablePrimaryNetworkInterface";

default:
return "???";
Expand Down

0 comments on commit 1e3c634

Please sign in to comment.