Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits authored and cecille committed Jan 29, 2022
1 parent fa799d9 commit 5d95e49
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 50 deletions.
32 changes: 18 additions & 14 deletions src/controller/AutoCommissioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ CommissioningStage AutoCommissioner::GetNextCommissioningStage(CommissioningStag
case CommissioningStage::kReadProductId:
return CommissioningStage::kReadSoftwareVersion;
case CommissioningStage::kReadSoftwareVersion:
if(mNeedsNetworkSetup) {
if (mNeedsNetworkSetup)
{
return CommissioningStage::kGetNetworkTechnology;
}
else
Expand Down Expand Up @@ -220,18 +221,20 @@ CommissioningStage AutoCommissioner::GetNextCommissioningStage(CommissioningStag
return CommissioningStage::kError;
}

EndpointId AutoCommissioner::GetEndpoint(const CommissioningStage & stage) {
switch(stage) {
case CommissioningStage::kWiFiNetworkSetup:
case CommissioningStage::kWiFiNetworkEnable:
return mNetworkEndpoints.wifi;
case CommissioningStage::kThreadNetworkSetup:
case CommissioningStage::kThreadNetworkEnable:
return mNetworkEndpoints.thread;
case CommissioningStage::kGetNetworkTechnology:
return kInvalidEndpointId;
default:
return 0;
EndpointId AutoCommissioner::GetEndpoint(const CommissioningStage & stage)
{
switch (stage)
{
case CommissioningStage::kWiFiNetworkSetup:
case CommissioningStage::kWiFiNetworkEnable:
return mNetworkEndpoints.wifi;
case CommissioningStage::kThreadNetworkSetup:
case CommissioningStage::kThreadNetworkEnable:
return mNetworkEndpoints.thread;
case CommissioningStage::kGetNetworkTechnology:
return kInvalidEndpointId;
default:
return 0;
}
}

Expand All @@ -250,7 +253,8 @@ void AutoCommissioner::StartCommissioning(CommissioneeDeviceProxy * proxy)
Transport::Type::kBle;
CHIP_ERROR err = CHIP_NO_ERROR;
CommissioningStage nextStage = GetNextCommissioningStage(CommissioningStage::kSecurePairing, err);
mCommissioner->PerformCommissioningStep(mCommissioneeDeviceProxy, nextStage, mParams, this, GetEndpoint(nextStage), GetCommandTimeout(nextStage));
mCommissioner->PerformCommissioningStep(mCommissioneeDeviceProxy, nextStage, mParams, this, GetEndpoint(nextStage),
GetCommandTimeout(nextStage));
}

Optional<System::Clock::Timeout> AutoCommissioner::GetCommandTimeout(CommissioningStage stage)
Expand Down
78 changes: 48 additions & 30 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,36 +1649,50 @@ void AttributeReadFailure(void * context, CHIP_ERROR status)
commissioner->CommissioningStageComplete(status);
}

void DeviceCommissioner::OnDone() {
void DeviceCommissioner::OnDone()
{
NetworkClusters clusters;

CHIP_ERROR err = mAttributeCache->ForEachAttribute(app::Clusters::NetworkCommissioning::Id, [this, &clusters](const app::ConcreteAttributePath & path) {
if (path.mAttributeId != app::Clusters::NetworkCommissioning::Attributes::FeatureMap::Id) {
return CHIP_NO_ERROR;
}
TLV::TLVReader reader;
if (this->mAttributeCache->Get(path, reader) == CHIP_NO_ERROR) {
uint32_t flags = 0;
BitFlags<app::Clusters::NetworkCommissioning::NetworkCommissioningFeature> features;
if (app::DataModel::Decode(reader, flags) == CHIP_NO_ERROR) {
features.SetRaw(flags);
if (features.Has(app::Clusters::NetworkCommissioning::NetworkCommissioningFeature::kWiFiNetworkInterface)) {
clusters.wifi = path.mEndpointId;
} else if (features.Has(app::Clusters::NetworkCommissioning::NetworkCommissioningFeature::kThreadNetworkInterface)) {
clusters.thread = path.mEndpointId;
} else if (features.Has(app::Clusters::NetworkCommissioning::NetworkCommissioningFeature::kEthernetNetworkInterface)) {
clusters.eth = path.mEndpointId;
}
else {
// TODO: Gross workaroud for the empty feature map on all clusters. Remove.
clusters.thread = path.mEndpointId;
CHIP_ERROR err = mAttributeCache->ForEachAttribute(
app::Clusters::NetworkCommissioning::Id, [this, &clusters](const app::ConcreteAttributePath & path) {
if (path.mAttributeId != app::Clusters::NetworkCommissioning::Attributes::FeatureMap::Id)
{
return CHIP_NO_ERROR;
}
TLV::TLVReader reader;
if (this->mAttributeCache->Get(path, reader) == CHIP_NO_ERROR)
{
uint32_t flags = 0;
BitFlags<app::Clusters::NetworkCommissioning::NetworkCommissioningFeature> features;
if (app::DataModel::Decode(reader, flags) == CHIP_NO_ERROR)
{
features.SetRaw(flags);
if (features.Has(app::Clusters::NetworkCommissioning::NetworkCommissioningFeature::kWiFiNetworkInterface))
{
clusters.wifi = path.mEndpointId;
}
else if (features.Has(
app::Clusters::NetworkCommissioning::NetworkCommissioningFeature::kThreadNetworkInterface))
{
clusters.thread = path.mEndpointId;
}
else if (features.Has(
app::Clusters::NetworkCommissioning::NetworkCommissioningFeature::kEthernetNetworkInterface))
{
clusters.eth = path.mEndpointId;
}
else
{
// TODO: Gross workaroud for the empty feature map on all clusters. Remove.
clusters.thread = path.mEndpointId;
}
}
}
}
return CHIP_NO_ERROR;
});
return CHIP_NO_ERROR;
});

if (err != CHIP_NO_ERROR) {
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Error parsing Network commissioning features");
}
CommissioningDelegate::CommissioningReport report;
Expand Down Expand Up @@ -1733,16 +1747,20 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio
app::InteractionModelEngine * engine = app::InteractionModelEngine::GetInstance();
app::ReadPrepareParams readParams(proxy->GetSecureSession().Value());
app::AttributePathParams paramList[1];
paramList[0] = app::AttributePathParams(endpoint, app::Clusters::NetworkCommissioning::Id, app::Clusters::NetworkCommissioning::Attributes::FeatureMap::Id);
readParams.mpAttributePathParamsList = paramList;
paramList[0] = app::AttributePathParams(endpoint, app::Clusters::NetworkCommissioning::Id,
app::Clusters::NetworkCommissioning::Attributes::FeatureMap::Id);
readParams.mpAttributePathParamsList = paramList;
readParams.mAttributePathParamsListSize = 1;
if (timeout.HasValue()) {
if (timeout.HasValue())
{
readParams.mTimeout = timeout.Value();
}
mAttributeCache = Platform::MakeUnique<app::AttributeCache>(*this);
mReadClient = chip::Platform::MakeUnique<app::ReadClient>(engine, proxy->GetExchangeManager(), mAttributeCache->GetBufferedCallback(), app::ReadClient::InteractionType::Read);
mReadClient = chip::Platform::MakeUnique<app::ReadClient>(
engine, proxy->GetExchangeManager(), mAttributeCache->GetBufferedCallback(), app::ReadClient::InteractionType::Read);
CHIP_ERROR err = mReadClient->SendRequest(readParams);
if (err != CHIP_NO_ERROR) {
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Failed to send read request for networking clusters");
CommissioningStageComplete(err);
return;
Expand Down
3 changes: 2 additions & 1 deletion src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY // make this commissioner discoverable
public Protocols::UserDirectedCommissioning::InstanceNameResolver,
#endif
public SessionEstablishmentDelegate, public app::AttributeCache::Callback
public SessionEstablishmentDelegate,
public app::AttributeCache::Callback
{
public:
DeviceCommissioner();
Expand Down
9 changes: 4 additions & 5 deletions src/controller/CommissioningDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,17 @@ struct BasicSoftware

struct NetworkClusters
{
EndpointId wifi = kInvalidEndpointId;
EndpointId wifi = kInvalidEndpointId;
EndpointId thread = kInvalidEndpointId;
EndpointId eth = kInvalidEndpointId;
EndpointId eth = kInvalidEndpointId;
};

class CommissioningDelegate
{
public:
virtual ~CommissioningDelegate(){};
struct CommissioningReport
: Variant<RequestedCertificate, AttestationResponse, NocChain, OperationalNodeFoundData,
BasicVendor, BasicProduct, BasicSoftware, NetworkClusters>
struct CommissioningReport : Variant<RequestedCertificate, AttestationResponse, NocChain, OperationalNodeFoundData, BasicVendor,
BasicProduct, BasicSoftware, NetworkClusters>
{
CommissioningReport() : stageCompleted(CommissioningStage::kError) {}
CommissioningStage stageCompleted;
Expand Down

0 comments on commit 5d95e49

Please sign in to comment.