From 654f83aef6ae0fe091043a89d4551bda2a56f9bb Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Tue, 16 Jan 2024 15:38:18 -0500 Subject: [PATCH] Add supportedThreadFeatures, threadVersion and SupportedWiFiBands attributes to some reference apps (#31328) * Update zap file of some reference apps to enable supportedThreadFeatures, threadVersion and SupportedWiFiBands attributes of the network commissioning cluster * regen all * Revert change to examples other than all-clusters apps * Gate the encoding base on the Network type define enablement define. Return UnsupportedAttribute otherwise. * fix conflicts * fixup * Rework condition logic to fix CI issue with linux all-cluster-app * Fix Clang-tidy validation --- .../all-clusters-app.matter | 3 + .../all-clusters-common/all-clusters-app.zap | 48 ++++++++++ .../all-clusters-minimal-app.matter | 3 + .../all-clusters-minimal-app.zap | 52 ++++++++++- .../data_model/lighting-wifi-app.matter | 1 + .../silabs/data_model/lighting-wifi-app.zap | 16 ++++ .../network-commissioning.cpp | 91 +++++++++++++------ 7 files changed, 185 insertions(+), 29 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index 99eb91c4e43fba..b12b11b747b92e 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -6873,6 +6873,9 @@ endpoint 0 { ram attribute lastNetworkingStatus; ram attribute lastNetworkID; ram attribute lastConnectErrorValue; + callback attribute supportedWiFiBands; + callback attribute supportedThreadFeatures; + callback attribute threadVersion; callback attribute generatedCommandList; callback attribute acceptedCommandList; callback attribute eventList; diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index 5948b880a8d5c1..a24d3db39a2b65 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -2562,6 +2562,54 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "SupportedWiFiBands", + "code": 8, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "SupportedThreadFeatures", + "code": 9, + "mfgCode": null, + "side": "server", + "type": "ThreadCapabilitiesBitmap", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ThreadVersion", + "code": 10, + "mfgCode": null, + "side": "server", + "type": "int16u", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "GeneratedCommandList", "code": 65528, diff --git a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter index 831048dc7d014f..dd01a2fb356f22 100644 --- a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter +++ b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter @@ -6060,6 +6060,9 @@ endpoint 0 { ram attribute lastNetworkingStatus; ram attribute lastNetworkID; ram attribute lastConnectErrorValue; + callback attribute supportedWiFiBands; + callback attribute supportedThreadFeatures; + callback attribute threadVersion; callback attribute generatedCommandList; callback attribute acceptedCommandList; callback attribute eventList; diff --git a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.zap b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.zap index 395e0c9f302e71..5aff52c41cca6b 100644 --- a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.zap +++ b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.zap @@ -2235,6 +2235,54 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "SupportedWiFiBands", + "code": 8, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "SupportedThreadFeatures", + "code": 9, + "mfgCode": null, + "side": "server", + "type": "ThreadCapabilitiesBitmap", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ThreadVersion", + "code": 10, + "mfgCode": null, + "side": "server", + "type": "int16u", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "GeneratedCommandList", "code": 65528, @@ -6851,7 +6899,7 @@ "code": 0, "mfgCode": null, "side": "server", - "type": "int16s", + "type": "temperature", "included": 1, "storageOption": "RAM", "singleton": 0, @@ -6899,7 +6947,7 @@ "code": 28, "mfgCode": null, "side": "server", - "type": "enum8", + "type": "SystemModeEnum", "included": 1, "storageOption": "RAM", "singleton": 0, diff --git a/examples/lighting-app/silabs/data_model/lighting-wifi-app.matter b/examples/lighting-app/silabs/data_model/lighting-wifi-app.matter index 3a2db86eaf0bb6..41e79a344f7d9b 100644 --- a/examples/lighting-app/silabs/data_model/lighting-wifi-app.matter +++ b/examples/lighting-app/silabs/data_model/lighting-wifi-app.matter @@ -2438,6 +2438,7 @@ endpoint 0 { ram attribute lastNetworkingStatus; ram attribute lastNetworkID; ram attribute lastConnectErrorValue; + callback attribute supportedWiFiBands; ram attribute featureMap default = 2; ram attribute clusterRevision default = 1; diff --git a/examples/lighting-app/silabs/data_model/lighting-wifi-app.zap b/examples/lighting-app/silabs/data_model/lighting-wifi-app.zap index 02ff0033007921..82940a361a1ecd 100644 --- a/examples/lighting-app/silabs/data_model/lighting-wifi-app.zap +++ b/examples/lighting-app/silabs/data_model/lighting-wifi-app.zap @@ -1428,6 +1428,22 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "SupportedWiFiBands", + "code": 8, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "FeatureMap", "code": 65532, diff --git a/src/app/clusters/network-commissioning/network-commissioning.cpp b/src/app/clusters/network-commissioning/network-commissioning.cpp index 87edf85f5c06c9..6776897efce6fb 100644 --- a/src/app/clusters/network-commissioning/network-commissioning.cpp +++ b/src/app/clusters/network-commissioning/network-commissioning.cpp @@ -273,39 +273,76 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu case Attributes::ClusterRevision::Id: return aEncoder.Encode(kCurrentClusterRevision); - case Attributes::SupportedWiFiBands::Id: -#if (!CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION && !CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP) - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); -#else - VerifyOrReturnError(mFeatureFlags.Has(Feature::kWiFiNetworkInterface), CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute)); - - return aEncoder.EncodeList([this](const auto & encoder) { - uint32_t bands = mpDriver.Get()->GetSupportedWiFiBandsMask(); + case Attributes::SupportedWiFiBands::Id: { +#if (CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION || CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP) + // TODO https://github.com/project-chip/connectedhomeip/issues/31431 + // This is a case of shared zap config where mandatory wifi attributes are enabled for a thread platform (e.g + // all-cluster-app). Real world product must only enable the attributes tied to the network technology supported by their + // product. Temporarily return an list of 1 element of value 0 when wifi is not supported or WiFiNetworkInterface is not + // enabled until a solution is implemented with the attribute list. + // Final implementation will return UnsupportedAttribute if we get here without the needed WiFi support . + // VerifyOrReturnError(mFeatureFlags.Has(Feature::kWiFiNetworkInterface), CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute)); + if (mFeatureFlags.Has(Feature::kWiFiNetworkInterface)) + { + return aEncoder.EncodeList([this](const auto & encoder) { + uint32_t bands = mpDriver.Get()->GetSupportedWiFiBandsMask(); - // Extract every band from the bitmap of supported bands, starting positionally on the right. - for (uint32_t band_bit_pos = 0; band_bit_pos < std::numeric_limits::digits; ++band_bit_pos) - { - uint32_t band_mask = static_cast(1UL << band_bit_pos); - if ((bands & band_mask) != 0) + // Extract every band from the bitmap of supported bands, starting positionally on the right. + for (uint32_t band_bit_pos = 0; band_bit_pos < std::numeric_limits::digits; ++band_bit_pos) { - ReturnErrorOnFailure(encoder.Encode(static_cast(band_bit_pos))); + uint32_t band_mask = static_cast(1UL << band_bit_pos); + if ((bands & band_mask) != 0) + { + ReturnErrorOnFailure(encoder.Encode(static_cast(band_bit_pos))); + } } - } + return CHIP_NO_ERROR; + }); + } +#endif + return aEncoder.EncodeList([](const auto & encoder) { + WiFiBandEnum bands = WiFiBandEnum::k2g4; + ReturnErrorOnFailure(encoder.Encode(bands)); return CHIP_NO_ERROR; }); + } + break; + case Attributes::SupportedThreadFeatures::Id: { + // TODO https://github.com/project-chip/connectedhomeip/issues/31431 + BitMask ThreadCapabilities = 0; +#if (CHIP_DEVICE_CONFIG_ENABLE_THREAD) + // This is a case of shared zap config where mandatory thread attributes are enabled for a wifi platform (e.g + // all-cluster-app). Real world product must only enable the attributes tied to the network technology supported by their + // product. Temporarily encode a value of 0 reflecting no thread capabilities hen CHIP_DEVICE_CONFIG_ENABLE_THREAD or + // ThreadNetworkInterface are not enabled until a solution is implemented with the attribute list. + // Final implementation will return UnsupportedAttribute if we get here without the needed thread support + // VerifyOrReturnError(mFeatureFlags.Has(Feature::kThreadNetworkInterface), CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute)); + if (mFeatureFlags.Has(Feature::kThreadNetworkInterface)) + { + ThreadCapabilities = mpDriver.Get()->GetSupportedThreadFeatures(); + } #endif - break; - - case Attributes::SupportedThreadFeatures::Id: - VerifyOrReturnError(mFeatureFlags.Has(Feature::kThreadNetworkInterface), CHIP_NO_ERROR); - VerifyOrReturnError(mpDriver.Valid(), CHIP_NO_ERROR); - return aEncoder.Encode(mpDriver.Get()->GetSupportedThreadFeatures()); - - case Attributes::ThreadVersion::Id: - VerifyOrReturnError(mFeatureFlags.Has(Feature::kThreadNetworkInterface), CHIP_NO_ERROR); - VerifyOrReturnError(mpDriver.Valid(), CHIP_NO_ERROR); - return aEncoder.Encode(mpDriver.Get()->GetThreadVersion()); - + return aEncoder.Encode(ThreadCapabilities); + } + break; + case Attributes::ThreadVersion::Id: { + // TODO https://github.com/project-chip/connectedhomeip/issues/31431ß + uint16_t threadVersion = 0; +#if (CHIP_DEVICE_CONFIG_ENABLE_THREAD) + // This is a case of shared zap config where mandatory thread attributes are enabled for a wifi platform (e.g + // all-cluster-app) Real world product must only enable the attributes tied to the network technology supported by their + // product. Temporarily encode a value of 0 reflecting no thread version when CHIP_DEVICE_CONFIG_ENABLE_THREAD or + // ThreadNetworkInterface are not enabled until a solution is implemented with the attribute list. + // Final implementation will return UnsupportedAttribute if we get here without the needed thread support + // VerifyOrReturnError(mFeatureFlags.Has(Feature::kThreadNetworkInterface), CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute)); + if (mFeatureFlags.Has(Feature::kThreadNetworkInterface)) + { + threadVersion = mpDriver.Get()->GetThreadVersion(); + } +#endif + return aEncoder.Encode(threadVersion); + } + break; default: return CHIP_NO_ERROR; }