Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/InteractionModelEngine.h>
#include <app/clusters/basic-information/DeviceLayerBasicInformationDelegate.h>
#include <app/clusters/groupcast/GroupcastCluster.h>
#include <app/clusters/groupcast/GroupcastContext.h>
#include <lib/support/CHIPMem.h>
Expand Down Expand Up @@ -48,14 +49,13 @@ CHIP_ERROR RootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelPr
.Set<BasicInformation::Attributes::LocalConfigDisabled::Id>()
.Set<BasicInformation::Attributes::Reachable::Id>();

mBasicInformationCluster.Create(
optionalAttributeSet,
BasicInformationCluster::Context{
.deviceInstanceInfoProvider = mContext.deviceInstanceInfoProvider,
.configurationManager = mContext.configurationManager,
.platformManager = mContext.platformManager,
.subscriptionsPerFabric = InteractionModelEngine::GetInstance()->GetMinGuaranteedSubscriptionsPerFabric(),
});
static chip::app::Clusters::BasicInformation::DeviceLayerBasicInformationDelegate delegate({
.deviceInstanceInfoProvider = mContext.deviceInstanceInfoProvider,
.configurationManager = mContext.configurationManager,
.platformManager = mContext.platformManager,
.subscriptionsPerFabric = InteractionModelEngine::GetInstance()->GetMinGuaranteedSubscriptionsPerFabric(),
});
mBasicInformationCluster.Create(optionalAttributeSet, &delegate, mContext.platformManager);

ReturnErrorOnFailure(provider.AddCluster(mBasicInformationCluster.Registration()));
mGeneralCommissioningCluster.Create(
Expand Down
3 changes: 3 additions & 0 deletions src/app/clusters/basic-information/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ source_set("basic-information") {
sources = [
"BasicInformationCluster.cpp",
"BasicInformationCluster.h",
"BasicInformationDelegate.h",
"DeviceLayerBasicInformationDelegate.cpp",
"DeviceLayerBasicInformationDelegate.h",
]
public_deps = [
"${chip_root}/src/app:constants",
Expand Down
196 changes: 62 additions & 134 deletions src/app/clusters/basic-information/BasicInformationCluster.cpp

Large diffs are not rendered by default.

23 changes: 8 additions & 15 deletions src/app/clusters/basic-information/BasicInformationCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
*/
#pragma once

#include <app/clusters/basic-information/BasicInformationDelegate.h>
#include <app/persistence/String.h>
#include <app/server-cluster/DefaultServerCluster.h>
#include <app/server-cluster/OptionalAttributeSet.h>
#include <clusters/BasicInformation/AttributeIds.h>
#include <clusters/BasicInformation/ClusterId.h>
#include <lib/core/DataModelTypes.h>
#include <platform/ConfigurationManager.h>
#include <platform/DeviceInstanceInfoProvider.h>
#include <platform/PlatformManager.h>

namespace chip {
Expand All @@ -38,15 +37,6 @@ namespace Clusters {
class BasicInformationCluster : public DefaultServerCluster, public DeviceLayer::PlatformManagerDelegate
{
public:
// Define the Context struct with References
struct Context
{
DeviceLayer::DeviceInstanceInfoProvider & deviceInstanceInfoProvider;
DeviceLayer::ConfigurationManager & configurationManager;
DeviceLayer::PlatformManager & platformManager;
uint16_t subscriptionsPerFabric;
};

using OptionalAttributesSet = chip::app::OptionalAttributeSet< //
BasicInformation::Attributes::ManufacturingDate::Id, //
BasicInformation::Attributes::PartNumber::Id, //
Expand All @@ -62,9 +52,11 @@ class BasicInformationCluster : public DefaultServerCluster, public DeviceLayer:
BasicInformation::Attributes::UniqueID::Id //
>;

BasicInformationCluster(OptionalAttributesSet optionalAttributeSet, Context ctx) :
DefaultServerCluster({ kRootEndpointId, BasicInformation::Id }), mEnabledOptionalAttributes(optionalAttributeSet),
mClusterContext(ctx)
BasicInformationCluster(OptionalAttributesSet optionalAttributeSet, BasicInformation::BasicInformationDelegate * delegate,
DeviceLayer::PlatformManager & platformManager) :
DefaultServerCluster({ kRootEndpointId, BasicInformation::Id }),
mEnabledOptionalAttributes(optionalAttributeSet), mDelegate(delegate), mPlatformManager(platformManager)

{
mEnabledOptionalAttributes
.Set<BasicInformation::Attributes::UniqueID::Id>(); // Unless told otherwise, unique id is mandatory
Expand Down Expand Up @@ -109,7 +101,8 @@ class BasicInformationCluster : public DefaultServerCluster, public DeviceLayer:
OptionalAttributesSet mEnabledOptionalAttributes;

Storage::String<32> mNodeLabel;
Context mClusterContext;
BasicInformation::BasicInformationDelegate * mDelegate;
DeviceLayer::PlatformManager & mPlatformManager;
};

} // namespace Clusters
Expand Down
66 changes: 66 additions & 0 deletions src/app/clusters/basic-information/BasicInformationDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2026 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 <cstddef>
#include <cstdint>

#include <clusters/BasicInformation/Enums.h>
#include <lib/core/CHIPError.h>
#include <lib/core/DataModelTypes.h>
#include <lib/support/Span.h>
#include <platform/DeviceInstanceInfoProvider.h>

namespace chip {
namespace app {
namespace Clusters {
namespace BasicInformation {

class BasicInformationDelegate
{
public:
virtual ~BasicInformationDelegate() = default;

// String Getters
virtual CHIP_ERROR GetStringAttribute(chip::AttributeId attributeId, MutableCharSpan & buffer) = 0;
virtual CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) = 0;
virtual CHIP_ERROR GetManufacturingDateSuffix(MutableCharSpan & suffixBuffer) = 0;

// Value Getters
virtual CHIP_ERROR GetVendorId(uint16_t & vendorId) = 0;
virtual CHIP_ERROR GetProductId(uint16_t & productId) = 0;
virtual CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) = 0;
virtual CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVersion) = 0;
virtual CHIP_ERROR GetProductFinish(ProductFinishEnum * finish) = 0;
virtual CHIP_ERROR GetProductPrimaryColor(ColorEnum * primaryColor) = 0;
virtual CHIP_ERROR GetLocalConfigDisabled(bool & localConfigDisabled) = 0;
virtual CHIP_ERROR GetConfigurationVersion(uint32_t & configurationVersion) = 0;
virtual DeviceLayer::DeviceInstanceInfoProvider::DeviceInfoCapabilityMinimas GetSupportedCapabilityMinimaValues() = 0;

// Setters
virtual CHIP_ERROR SetLocalConfigDisabled(bool localConfigDisabled) = 0;
virtual CHIP_ERROR StoreConfigurationVersion(uint32_t configurationVersion) = 0;
virtual CHIP_ERROR StoreLocation(const CharSpan & code) = 0;

// Misc
virtual uint16_t GetSubscriptionsPerFabric() const = 0;
};

} // namespace BasicInformation
} // namespace Clusters
} // namespace app
} // namespace chip
14 changes: 7 additions & 7 deletions src/app/clusters/basic-information/CodegenIntegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/InteractionModelEngine.h>
#include <app/clusters/basic-information/BasicInformationCluster.h>
#include <app/clusters/basic-information/DeviceLayerBasicInformationDelegate.h>
#include <app/static-cluster-config/BasicInformation.h>
#include <app/util/attribute-storage.h>
#include <app/util/endpoint-config-api.h>
Expand Down Expand Up @@ -63,13 +64,12 @@ class IntegrationDelegate : public CodegenClusterIntegration::Delegate
DeviceLayer::DeviceInstanceInfoProvider * provider = DeviceLayer::GetDeviceInstanceInfoProvider();
VerifyOrDie(provider != nullptr);

BasicInformationCluster::Context context = {
.deviceInstanceInfoProvider = *provider,
.configurationManager = DeviceLayer::ConfigurationMgr(),
.platformManager = DeviceLayer::PlatformMgr(),
.subscriptionsPerFabric = InteractionModelEngine::GetInstance()->GetMinGuaranteedSubscriptionsPerFabric()
};
gServer.Create(optionalAttributeSet, context);
static chip::app::Clusters::BasicInformation::DeviceLayerBasicInformationDelegate delegate(
{ .deviceInstanceInfoProvider = *provider,
.configurationManager = DeviceLayer::ConfigurationMgr(),
.platformManager = DeviceLayer::PlatformMgr(),
.subscriptionsPerFabric = InteractionModelEngine::GetInstance()->GetMinGuaranteedSubscriptionsPerFabric() });
gServer.Create(optionalAttributeSet, &delegate, DeviceLayer::PlatformMgr());

// This disabling of the unique id attribute is here only for test purposes. The uniqe id attribute
// is mandatory, but was optional in previous versions. It is forced to be enabled in the basic information
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
* Copyright (c) 2026 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 "lib/core/CHIPError.h"
#include "lib/support/Span.h"
#include <app/clusters/basic-information/DeviceLayerBasicInformationDelegate.h>
#include <clusters/BasicInformation/Attributes.h>
#include <clusters/BasicInformation/Enums.h>
#include <platform/CHIPDeviceError.h>

namespace chip {
namespace app {
namespace Clusters {
namespace BasicInformation {

using namespace DeviceLayer;

CHIP_ERROR DeviceLayerBasicInformationDelegate::GetStringAttribute(chip::AttributeId attributeId, MutableCharSpan & buffer)
{
using namespace Attributes;

CHIP_ERROR err = CHIP_NO_ERROR;
size_t dataLen = 0;

switch (attributeId)
{
case VendorName::Id:
err = mContext.deviceInstanceInfoProvider.GetVendorName(buffer.data(), buffer.size());
break;
case ProductName::Id:
err = mContext.deviceInstanceInfoProvider.GetProductName(buffer.data(), buffer.size());
break;
case PartNumber::Id:
err = mContext.deviceInstanceInfoProvider.GetPartNumber(buffer.data(), buffer.size());
break;
case ProductURL::Id:
err = mContext.deviceInstanceInfoProvider.GetProductURL(buffer.data(), buffer.size());
break;
case ProductLabel::Id:
err = mContext.deviceInstanceInfoProvider.GetProductLabel(buffer.data(), buffer.size());
break;
case SerialNumber::Id:
err = mContext.deviceInstanceInfoProvider.GetSerialNumber(buffer.data(), buffer.size());
break;
case HardwareVersionString::Id:
err = mContext.deviceInstanceInfoProvider.GetHardwareVersionString(buffer.data(), buffer.size());
break;
case SoftwareVersionString::Id:
err = mContext.configurationManager.GetSoftwareVersionString(buffer.data(), buffer.size());
break;
case UniqueID::Id:
err = mContext.configurationManager.GetUniqueId(buffer.data(), buffer.size());
break;
case Location::Id: {
constexpr size_t kExpectedFixedLocationLength = 2;
err = mContext.configurationManager.GetCountryCode(buffer.data(), buffer.size(), dataLen);
if ((err != CHIP_NO_ERROR) || (dataLen != kExpectedFixedLocationLength))
{
// Fallback that was here historically
return CopyCharSpanToMutableCharSpan("XX"_span, buffer);
}

buffer.reduce_size(dataLen);
return err;
}
default:
return CHIP_ERROR_INVALID_ARGUMENT;
}

if (err == CHIP_NO_ERROR)
{
buffer.reduce_size(strlen(buffer.data()));
}
else if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
{
// If the config is not found or the feature is unsupported, return an empty string.
buffer.reduce_size(0);
err = CHIP_NO_ERROR;
}

return err;
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day)
{
return mContext.deviceInstanceInfoProvider.GetManufacturingDate(year, month, day);
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::GetManufacturingDateSuffix(MutableCharSpan & suffixBuffer)
{
return mContext.deviceInstanceInfoProvider.GetManufacturingDateSuffix(suffixBuffer);
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::GetVendorId(uint16_t & vendorId)
{
return mContext.deviceInstanceInfoProvider.GetVendorId(vendorId);
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::GetProductId(uint16_t & productId)
{
return mContext.deviceInstanceInfoProvider.GetProductId(productId);
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::GetHardwareVersion(uint16_t & hardwareVersion)
{
return mContext.deviceInstanceInfoProvider.GetHardwareVersion(hardwareVersion);
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::GetSoftwareVersion(uint32_t & softwareVersion)
{
return mContext.configurationManager.GetSoftwareVersion(softwareVersion);
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::GetProductFinish(ProductFinishEnum * finish)
{
return mContext.deviceInstanceInfoProvider.GetProductFinish(finish);
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::GetProductPrimaryColor(ColorEnum * primaryColor)
{
return mContext.deviceInstanceInfoProvider.GetProductPrimaryColor(primaryColor);
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::GetLocalConfigDisabled(bool & localConfigDisabled)
{
return mContext.deviceInstanceInfoProvider.GetLocalConfigDisabled(localConfigDisabled);
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::GetConfigurationVersion(uint32_t & configurationVersion)
{
return mContext.configurationManager.GetConfigurationVersion(configurationVersion);
}

DeviceInstanceInfoProvider::DeviceInfoCapabilityMinimas DeviceLayerBasicInformationDelegate::GetSupportedCapabilityMinimaValues()
{
return mContext.deviceInstanceInfoProvider.GetSupportedCapabilityMinimaValues();
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::SetLocalConfigDisabled(bool localConfigDisabled)
{
return mContext.deviceInstanceInfoProvider.SetLocalConfigDisabled(localConfigDisabled);
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::StoreConfigurationVersion(uint32_t configurationVersion)
{
return mContext.configurationManager.StoreConfigurationVersion(configurationVersion);
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::StoreLocation(const CharSpan & code)
{
return mContext.configurationManager.StoreCountryCode(code.data(), code.size());
}

uint16_t DeviceLayerBasicInformationDelegate::GetSubscriptionsPerFabric() const
{
return mContext.subscriptionsPerFabric;
}

CHIP_ERROR DeviceLayerBasicInformationDelegate::IgnoreUnimplemented(CHIP_ERROR status, char * buf, size_t bufSize)
{
if (status == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || status == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
{
if (bufSize > 0)
{
buf[0] = 0;
}
return CHIP_NO_ERROR;
}
return status;
}

} // namespace BasicInformation
} // namespace Clusters
} // namespace app
} // namespace chip
Loading
Loading