Skip to content

Commit

Permalink
Run commissioning from external class.
Browse files Browse the repository at this point in the history
Adding a (soon to be) optional auto-commissioner to maintain
current functionality as-is.
  • Loading branch information
cecille committed Dec 6, 2021
1 parent 675d9f5 commit 27032a1
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 110 deletions.
96 changes: 96 additions & 0 deletions src/controller/AutoCommissioner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <controller/AutoCommissioner.h>

#include <controller/CHIPDeviceController.h>

namespace chip {
namespace Controller {

CommissioningStage AutoCommissioner::GetNextCommissioningStage(CommissioningStage currentStage)
{
switch (currentStage)
{
case CommissioningStage::kSecurePairing:
return CommissioningStage::kArmFailsafe;
case CommissioningStage::kArmFailsafe:
return CommissioningStage::kConfigRegulatory;
case CommissioningStage::kConfigRegulatory:
return CommissioningStage::kDeviceAttestation;
case CommissioningStage::kDeviceAttestation:
// TODO(cecille): device attestation casues operational cert provisioinging to happen, This should be a separate stage.
// For thread and wifi, this should go to network setup then enable. For on-network we can skip right to finding the
// operational network because the provisioning of certificates will trigger the device to start operational advertising.
#if CHIP_DEVICE_CONFIG_ENABLE_DNSSD
return CommissioningStage::kFindOperational; // TODO : once case is working, need to add stages to find and reconnect
// here.
#else
return CommissioningStage::kSendComplete;
#endif
case CommissioningStage::kFindOperational:
return CommissioningStage::kSendComplete;
case CommissioningStage::kSendComplete:
return CommissioningStage::kCleanup;

// Currently unimplemented.
case CommissioningStage::kConfigACL:
case CommissioningStage::kNetworkSetup:
case CommissioningStage::kNetworkEnable:
case CommissioningStage::kScanNetworks:
case CommissioningStage::kCheckCertificates:
return CommissioningStage::kError;
// Neither of these have a next stage so return kError;
case CommissioningStage::kCleanup:
case CommissioningStage::kError:
return CommissioningStage::kError;
}
return CommissioningStage::kError;
}

void AutoCommissioner::StartCommissioning(CommissioneeDeviceProxy * proxy)
{
// TODO: check that there is no commissioning in progress currently.
mCommissioneeDeviceProxy = proxy;
mCommissioner->PerformCommissioningStep(mCommissioneeDeviceProxy, CommissioningStage::kArmFailsafe, mParams, this);
}

void AutoCommissioner::CommissioningStepFinished(CHIP_ERROR err, CommissioningDelegate::CommissioningReport report)
{

if (report.stageCompleted == CommissioningStage::kFindOperational)
{
mOperationalDeviceProxy = report.OperationalNodeFoundData.operationalProxy;
}
CommissioningStage nextStage = GetNextCommissioningStage(report.stageCompleted);
DeviceProxy * proxy = mCommissioneeDeviceProxy;
if (nextStage == CommissioningStage::kSendComplete || nextStage == CommissioningStage::kCleanup)
{
proxy = mOperationalDeviceProxy;
}

if (proxy == nullptr)
{
ChipLogError(Controller, "Invalid device for commissioning");
return;
}
mCommissioner->PerformCommissioningStep(proxy, nextStage, mParams, this);
}

} // namespace Controller
} // namespace chip
46 changes: 46 additions & 0 deletions src/controller/AutoCommissioner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <controller/CommissioneeDeviceProxy.h>
#include <controller/CommissioningDelegate.h>
#include <protocols/secure_channel/RendezvousParameters.h>

namespace chip {
namespace Controller {

class DeviceCommissioner;

class AutoCommissioner : public CommissioningDelegate
{
public:
AutoCommissioner(DeviceCommissioner * commissioner) : mCommissioner(commissioner) {}
void SetCommissioningParameters(CommissioningParameters & params) { mParams = params; }
void StartCommissioning(CommissioneeDeviceProxy * proxy);

void CommissioningStepFinished(CHIP_ERROR err, CommissioningDelegate::CommissioningReport report) override;

private:
CommissioningStage GetNextCommissioningStage(CommissioningStage currentStage);
DeviceCommissioner * mCommissioner;
CommissioneeDeviceProxy * mCommissioneeDeviceProxy = nullptr;
OperationalDeviceProxy * mOperationalDeviceProxy = nullptr;
CommissioningParameters mParams = CommissioningParameters();
};

} // namespace Controller
} // namespace chip
2 changes: 2 additions & 0 deletions src/controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ static_library("controller") {
if (chip_controller) {
sources += [
"AbstractDnssdDiscoveryController.cpp",
"AutoCommissioner.cpp",
"AutoCommissioner.h",
"CHIPCommissionableNodeController.cpp",
"CHIPCommissionableNodeController.h",
"CHIPDeviceController.cpp",
Expand Down
Loading

0 comments on commit 27032a1

Please sign in to comment.