Skip to content

Commit

Permalink
Read basic cluster information during commissioning.
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille committed Jan 27, 2022
1 parent 9e8f49a commit eb8b946
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/controller/AutoCommissioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ CommissioningStage AutoCommissioner::GetNextCommissioningStage(CommissioningStag
switch (currentStage)
{
case CommissioningStage::kSecurePairing:
return CommissioningStage::kReadVendorId;
case CommissioningStage::kReadVendorId:
return CommissioningStage::kReadProductId;
case CommissioningStage::kReadProductId:
return CommissioningStage::kReadSoftwareVersion;
case CommissioningStage::kReadSoftwareVersion:
return CommissioningStage::kGetPartsList;
case CommissioningStage::kGetPartsList:
return CommissioningStage::kCheckEndpointIsCommissionable;
Expand Down Expand Up @@ -274,6 +280,15 @@ CHIP_ERROR AutoCommissioner::CommissioningStepFinished(CHIP_ERROR err, Commissio
{
switch (report.stageCompleted)
{
case CommissioningStage::kReadVendorId:
mVendorId = report.Get<BasicVendor>().vendorId;
break;
case CommissioningStage::kReadProductId:
mProductId = report.Get<BasicProduct>().productId;
break;
case CommissioningStage::kReadSoftwareVersion:
mSoftwareVersion = report.Get<BasicSoftware>().softwareVersion;
break;
case CommissioningStage::kGetPartsList:
mAllEndpoints = report.Get<EndpointParts>();
break;
Expand Down
3 changes: 3 additions & 0 deletions src/controller/AutoCommissioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class AutoCommissioner : public CommissioningDelegate
EndpointParts mAllEndpoints;
EndpointParts mNetworkEndpoints;
EndpointId mEndpoint;
VendorId mVendorId;
uint16_t mProductId;
uint32_t mSoftwareVersion;
// Memory space for the commisisoning parameters that come in as ByteSpans - the caller is not guaranteed to retain this memory
uint8_t mSsid[CommissioningParameters::kMaxSsidLen];
uint8_t mCredentials[CommissioningParameters::kMaxCredentialsLen];
Expand Down
57 changes: 52 additions & 5 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,12 +1632,34 @@ void DescriptorClusterServerCallback(void * context, const chip::app::DataModel:
commissioner->CommissioningStageComplete(CHIP_NO_ERROR, report);
}

void DescriptorClusterFailure(void * context, EmberAfStatus status)
void BasicVendorCallback(void * context, VendorId vendorId)
{
DeviceCommissioner * commissioner = static_cast<DeviceCommissioner *>(context);
CommissioningDelegate::CommissioningReport report;
report.Set<BasicVendor>(vendorId);
commissioner->CommissioningStageComplete(CHIP_NO_ERROR, report);
}

// TODO: Do we have a function to convert from ember status to chip status?
commissioner->CommissioningStageComplete(CHIP_ERROR_INTERNAL);
void BasicProductCallback(void * context, uint16_t productId)
{
DeviceCommissioner * commissioner = static_cast<DeviceCommissioner *>(context);
CommissioningDelegate::CommissioningReport report;
report.Set<BasicProduct>(productId);
commissioner->CommissioningStageComplete(CHIP_NO_ERROR, report);
}

void BasicSoftwareCallback(void * context, uint32_t softwareVersion)
{
DeviceCommissioner * commissioner = static_cast<DeviceCommissioner *>(context);
CommissioningDelegate::CommissioningReport report;
report.Set<BasicSoftware>(softwareVersion);
commissioner->CommissioningStageComplete(CHIP_NO_ERROR, report);
}

void AttributeReadFailure(void * context, CHIP_ERROR status)
{
DeviceCommissioner * commissioner = static_cast<DeviceCommissioner *>(context);
commissioner->CommissioningStageComplete(status);
}

void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, CommissioningStage step, CommissioningParameters & params,
Expand All @@ -1658,20 +1680,45 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio

switch (step)
{
case CommissioningStage::kReadVendorId: {
ChipLogProgress(Controller, "Reading vendor ID");
BasicCluster basic;
SetupCluster(basic, proxy, endpoint, timeout);
basic.ReadAttribute<chip::app::Clusters::Basic::Attributes::VendorID::TypeInfo>(this, BasicVendorCallback,
AttributeReadFailure);
}
break;
case CommissioningStage::kReadProductId: {
ChipLogProgress(Controller, "Reading product ID");
BasicCluster basic;
SetupCluster(basic, proxy, endpoint, timeout);
basic.ReadAttribute<chip::app::Clusters::Basic::Attributes::ProductID::TypeInfo>(this, BasicProductCallback,
AttributeReadFailure);
}
break;
case CommissioningStage::kReadSoftwareVersion: {
ChipLogProgress(Controller, "Reading software version");
BasicCluster basic;
SetupCluster(basic, proxy, endpoint, timeout);
basic.ReadAttribute<chip::app::Clusters::Basic::Attributes::SoftwareVersion::TypeInfo>(this, BasicSoftwareCallback,
AttributeReadFailure);
}
break;

case CommissioningStage::kGetPartsList: {
ChipLogProgress(Controller, "Reading descriptor cluster parts list");
DescriptorCluster desc;
SetupCluster(desc, proxy, endpoint, timeout);
desc.ReadAttribute<chip::app::Clusters::Descriptor::Attributes::PartsList::TypeInfo>(this, DescriptorClusterPartsCallback,
DescriptorClusterFailure);
AttributeReadFailure);
}
break;
case CommissioningStage::kCheckEndpointIsCommissionable: {
ChipLogProgress(Controller, "Reading descriptor cluster server list for endpoint %u", endpoint);
DescriptorCluster desc;
SetupCluster(desc, proxy, endpoint, timeout);
desc.ReadAttribute<chip::app::Clusters::Descriptor::Attributes::ServerList::TypeInfo>(this, DescriptorClusterServerCallback,
DescriptorClusterFailure);
AttributeReadFailure);
}
break;
case CommissioningStage::kArmFailsafe: {
Expand Down
23 changes: 22 additions & 1 deletion src/controller/CommissioningDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ enum CommissioningStage : uint8_t
{
kError,
kSecurePairing,
kReadVendorId,
kReadProductId,
kReadSoftwareVersion,
kGetPartsList,
kCheckEndpointIsCommissionable,
kArmFailsafe,
Expand Down Expand Up @@ -251,12 +254,30 @@ struct EndpointCommissioningInfo
bool hasNetworkCluster = false;
};

struct BasicVendor
{
BasicVendor(VendorId id) : vendorId(id) {}
VendorId vendorId;
};

struct BasicProduct
{
BasicProduct(uint16_t id) : productId(id) {}
uint16_t productId;
};

struct BasicSoftware
{
BasicSoftware(uint32_t version) : softwareVersion(version) {}
uint32_t softwareVersion;
};

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

0 comments on commit eb8b946

Please sign in to comment.