From eb8b94667c63302583ff42175a0a5956548d0480 Mon Sep 17 00:00:00 2001 From: Cecille Freeman Date: Wed, 26 Jan 2022 15:52:56 -0500 Subject: [PATCH] Read basic cluster information during commissioning. --- src/controller/AutoCommissioner.cpp | 15 +++++++ src/controller/AutoCommissioner.h | 3 ++ src/controller/CHIPDeviceController.cpp | 57 ++++++++++++++++++++++--- src/controller/CommissioningDelegate.h | 23 +++++++++- 4 files changed, 92 insertions(+), 6 deletions(-) diff --git a/src/controller/AutoCommissioner.cpp b/src/controller/AutoCommissioner.cpp index 29f049bd314680..36107e02bc4ef5 100644 --- a/src/controller/AutoCommissioner.cpp +++ b/src/controller/AutoCommissioner.cpp @@ -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; @@ -274,6 +280,15 @@ CHIP_ERROR AutoCommissioner::CommissioningStepFinished(CHIP_ERROR err, Commissio { switch (report.stageCompleted) { + case CommissioningStage::kReadVendorId: + mVendorId = report.Get().vendorId; + break; + case CommissioningStage::kReadProductId: + mProductId = report.Get().productId; + break; + case CommissioningStage::kReadSoftwareVersion: + mSoftwareVersion = report.Get().softwareVersion; + break; case CommissioningStage::kGetPartsList: mAllEndpoints = report.Get(); break; diff --git a/src/controller/AutoCommissioner.h b/src/controller/AutoCommissioner.h index f0ec9bb306eeec..dde5d253fa802d 100644 --- a/src/controller/AutoCommissioner.h +++ b/src/controller/AutoCommissioner.h @@ -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]; diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 7e7bfb6b9cc463..f4a0311ca4219d 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -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(context); + CommissioningDelegate::CommissioningReport report; + report.Set(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(context); + CommissioningDelegate::CommissioningReport report; + report.Set(productId); + commissioner->CommissioningStageComplete(CHIP_NO_ERROR, report); +} + +void BasicSoftwareCallback(void * context, uint32_t softwareVersion) +{ + DeviceCommissioner * commissioner = static_cast(context); + CommissioningDelegate::CommissioningReport report; + report.Set(softwareVersion); + commissioner->CommissioningStageComplete(CHIP_NO_ERROR, report); +} + +void AttributeReadFailure(void * context, CHIP_ERROR status) +{ + DeviceCommissioner * commissioner = static_cast(context); + commissioner->CommissioningStageComplete(status); } void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, CommissioningStage step, CommissioningParameters & params, @@ -1658,12 +1680,37 @@ 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(this, BasicVendorCallback, + AttributeReadFailure); + } + break; + case CommissioningStage::kReadProductId: { + ChipLogProgress(Controller, "Reading product ID"); + BasicCluster basic; + SetupCluster(basic, proxy, endpoint, timeout); + basic.ReadAttribute(this, BasicProductCallback, + AttributeReadFailure); + } + break; + case CommissioningStage::kReadSoftwareVersion: { + ChipLogProgress(Controller, "Reading software version"); + BasicCluster basic; + SetupCluster(basic, proxy, endpoint, timeout); + basic.ReadAttribute(this, BasicSoftwareCallback, + AttributeReadFailure); + } + break; + case CommissioningStage::kGetPartsList: { ChipLogProgress(Controller, "Reading descriptor cluster parts list"); DescriptorCluster desc; SetupCluster(desc, proxy, endpoint, timeout); desc.ReadAttribute(this, DescriptorClusterPartsCallback, - DescriptorClusterFailure); + AttributeReadFailure); } break; case CommissioningStage::kCheckEndpointIsCommissionable: { @@ -1671,7 +1718,7 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio DescriptorCluster desc; SetupCluster(desc, proxy, endpoint, timeout); desc.ReadAttribute(this, DescriptorClusterServerCallback, - DescriptorClusterFailure); + AttributeReadFailure); } break; case CommissioningStage::kArmFailsafe: { diff --git a/src/controller/CommissioningDelegate.h b/src/controller/CommissioningDelegate.h index 3960aed03e3c5f..788687021c5ad6 100644 --- a/src/controller/CommissioningDelegate.h +++ b/src/controller/CommissioningDelegate.h @@ -28,6 +28,9 @@ enum CommissioningStage : uint8_t { kError, kSecurePairing, + kReadVendorId, + kReadProductId, + kReadSoftwareVersion, kGetPartsList, kCheckEndpointIsCommissionable, kArmFailsafe, @@ -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 + EndpointParts, EndpointCommissioningInfo, BasicVendor, BasicProduct, BasicSoftware> { CommissioningReport() : stageCompleted(CommissioningStage::kError) {} CommissioningStage stageCompleted;