From 11934358019ac4c83403abc0caf3b4649440b2a9 Mon Sep 17 00:00:00 2001 From: chirag-silabs <100861685+chirag-silabs@users.noreply.github.com> Date: Wed, 22 Feb 2023 03:32:34 +0530 Subject: [PATCH] [Silabs][SiWx917] Factory data provider for SiWx917 (#24747) * Adding the temp logic for the factory device data provider for SiWx917 * Restyled by whitespace * Added some comments * restyling the PR * Added the device config for other applications * Restyled by clang-format * Addressed review comments * Setting the device config to default values and using static cast * Restyled by whitespace --------- Co-authored-by: Restyled.io --- .../light-switch-app/silabs/SiWx917/BUILD.gn | 7 + .../silabs/SiWx917/include/DeviceConfig.h | 40 ++++ examples/lighting-app/silabs/SiWx917/BUILD.gn | 7 + .../silabs/SiWx917/include/DeviceConfig.h | 40 ++++ examples/lock-app/silabs/SiWx917/BUILD.gn | 7 + .../silabs/SiWx917/include/DeviceConfig.h | 40 ++++ .../silabs/SiWx917/BaseApplication.cpp | 2 +- .../SiWx917/SiWx917DeviceDataProvider.cpp | 183 +++++++++++++++--- .../SiWx917/SiWx917DeviceDataProvider.h | 15 +- .../platform/silabs/SiWx917/matter_config.cpp | 13 +- examples/window-app/silabs/SiWx917/BUILD.gn | 7 + .../silabs/SiWx917/include/DeviceConfig.h | 40 ++++ scripts/examples/gn_efr32_example.sh | 2 + 13 files changed, 366 insertions(+), 37 deletions(-) create mode 100644 examples/light-switch-app/silabs/SiWx917/include/DeviceConfig.h create mode 100644 examples/lighting-app/silabs/SiWx917/include/DeviceConfig.h create mode 100644 examples/lock-app/silabs/SiWx917/include/DeviceConfig.h create mode 100644 examples/window-app/silabs/SiWx917/include/DeviceConfig.h diff --git a/examples/light-switch-app/silabs/SiWx917/BUILD.gn b/examples/light-switch-app/silabs/SiWx917/BUILD.gn index 793cf64f5f7c44..28c7ba6de5424b 100644 --- a/examples/light-switch-app/silabs/SiWx917/BUILD.gn +++ b/examples/light-switch-app/silabs/SiWx917/BUILD.gn @@ -58,6 +58,9 @@ declare_args() { # Argument to force enable WPA3 security rs91x_wpa3_only = false + # use commissionable data for SiWx917 + siwx917_commissionable_data = false + #default WiFi SSID chip_default_wifi_ssid = "" @@ -84,6 +87,10 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" || defines = [] +if (siwx917_commissionable_data) { + defines += [ "SIWX917_USE_COMISSIONABLE_DATA=1" ] +} + # WiFi settings if (chip_enable_wifi) { if (chip_default_wifi_ssid != "") { diff --git a/examples/light-switch-app/silabs/SiWx917/include/DeviceConfig.h b/examples/light-switch-app/silabs/SiWx917/include/DeviceConfig.h new file mode 100644 index 00000000000000..18af7b2c9c8415 --- /dev/null +++ b/examples/light-switch-app/silabs/SiWx917/include/DeviceConfig.h @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Google LLC. + * 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 + +#ifdef SIWX917_USE_COMISSIONABLE_DATA + +uint32_t discriminatorValue = 3840; +uint64_t passcode = 20202021; +uint32_t spake2Interation = 1000; +char spake2Salt[] = "U1BBS0UyUCBLZXkgU2FsdA=="; +char spake2Verifier[] = "uWFwqugDNGiEck/po7KHwwMwwqZgN10XuyBajPGuyzUEV/iree4lOrao5GuwnlQ65CJzbeUB49s31EH+NEkg0JVI5MGCQGMMT/" + "SRPFNRODm3wH/MBiehuFc6FJ/NH6Rmzw=="; +char genSpake2Path[] = ""; +uint32_t productId = 32773; +uint32_t vendorId = 65521; +char productName[] = ""; +char vendorName[] = ""; +char hwVersionString[] = ""; +uint32_t rotatingId; +uint32_t commissionableFlow = 1; +uint8_t rendezvousFlag = 2; + +#endif \ No newline at end of file diff --git a/examples/lighting-app/silabs/SiWx917/BUILD.gn b/examples/lighting-app/silabs/SiWx917/BUILD.gn index d04a6b6bbb6e59..6992933adc7c98 100644 --- a/examples/lighting-app/silabs/SiWx917/BUILD.gn +++ b/examples/lighting-app/silabs/SiWx917/BUILD.gn @@ -58,6 +58,9 @@ declare_args() { # Argument to force enable WPA3 security on rs91x rs91x_wpa3_only = false + # use commissionable data for SiWx917 + siwx917_commissionable_data = false + #default WiFi SSID chip_default_wifi_ssid = "" @@ -158,6 +161,10 @@ efr32_sdk("sdk") { ] } + if (siwx917_commissionable_data) { + defines += [ "SIWX917_USE_COMISSIONABLE_DATA=1" ] + } + # WiFi Settings if (chip_enable_wifi) { if (use_SiWx917) { diff --git a/examples/lighting-app/silabs/SiWx917/include/DeviceConfig.h b/examples/lighting-app/silabs/SiWx917/include/DeviceConfig.h new file mode 100644 index 00000000000000..18af7b2c9c8415 --- /dev/null +++ b/examples/lighting-app/silabs/SiWx917/include/DeviceConfig.h @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Google LLC. + * 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 + +#ifdef SIWX917_USE_COMISSIONABLE_DATA + +uint32_t discriminatorValue = 3840; +uint64_t passcode = 20202021; +uint32_t spake2Interation = 1000; +char spake2Salt[] = "U1BBS0UyUCBLZXkgU2FsdA=="; +char spake2Verifier[] = "uWFwqugDNGiEck/po7KHwwMwwqZgN10XuyBajPGuyzUEV/iree4lOrao5GuwnlQ65CJzbeUB49s31EH+NEkg0JVI5MGCQGMMT/" + "SRPFNRODm3wH/MBiehuFc6FJ/NH6Rmzw=="; +char genSpake2Path[] = ""; +uint32_t productId = 32773; +uint32_t vendorId = 65521; +char productName[] = ""; +char vendorName[] = ""; +char hwVersionString[] = ""; +uint32_t rotatingId; +uint32_t commissionableFlow = 1; +uint8_t rendezvousFlag = 2; + +#endif \ No newline at end of file diff --git a/examples/lock-app/silabs/SiWx917/BUILD.gn b/examples/lock-app/silabs/SiWx917/BUILD.gn index 1f9ecd55197c04..3c83b84fa19b1d 100644 --- a/examples/lock-app/silabs/SiWx917/BUILD.gn +++ b/examples/lock-app/silabs/SiWx917/BUILD.gn @@ -58,6 +58,9 @@ declare_args() { # Argument to force enable WPA3 security rs91x_wpa3_only = false + # use commissionable data for SiWx917 + siwx917_commissionable_data = false + #default WiFi SSID chip_default_wifi_ssid = "" @@ -84,6 +87,10 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" || defines = [] +if (siwx917_commissionable_data) { + defines += [ "SIWX917_USE_COMISSIONABLE_DATA=1" ] +} + # WiFi settings if (chip_enable_wifi) { if (chip_default_wifi_ssid != "") { diff --git a/examples/lock-app/silabs/SiWx917/include/DeviceConfig.h b/examples/lock-app/silabs/SiWx917/include/DeviceConfig.h new file mode 100644 index 00000000000000..18af7b2c9c8415 --- /dev/null +++ b/examples/lock-app/silabs/SiWx917/include/DeviceConfig.h @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Google LLC. + * 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 + +#ifdef SIWX917_USE_COMISSIONABLE_DATA + +uint32_t discriminatorValue = 3840; +uint64_t passcode = 20202021; +uint32_t spake2Interation = 1000; +char spake2Salt[] = "U1BBS0UyUCBLZXkgU2FsdA=="; +char spake2Verifier[] = "uWFwqugDNGiEck/po7KHwwMwwqZgN10XuyBajPGuyzUEV/iree4lOrao5GuwnlQ65CJzbeUB49s31EH+NEkg0JVI5MGCQGMMT/" + "SRPFNRODm3wH/MBiehuFc6FJ/NH6Rmzw=="; +char genSpake2Path[] = ""; +uint32_t productId = 32773; +uint32_t vendorId = 65521; +char productName[] = ""; +char vendorName[] = ""; +char hwVersionString[] = ""; +uint32_t rotatingId; +uint32_t commissionableFlow = 1; +uint8_t rendezvousFlag = 2; + +#endif \ No newline at end of file diff --git a/examples/platform/silabs/SiWx917/BaseApplication.cpp b/examples/platform/silabs/SiWx917/BaseApplication.cpp index 1a4e044a661102..c1d01571bee971 100644 --- a/examples/platform/silabs/SiWx917/BaseApplication.cpp +++ b/examples/platform/silabs/SiWx917/BaseApplication.cpp @@ -213,7 +213,7 @@ CHIP_ERROR BaseApplication::Init(Identify * identifyObj) char qrCodeBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1]; chip::MutableCharSpan QRCode(qrCodeBuffer); - if (EFR32::EFR32DeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(QRCode) == CHIP_NO_ERROR) + if (SIWx917::SIWx917DeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(QRCode) == CHIP_NO_ERROR) { // Print setup info on LCD if available #ifdef QR_CODE_ENABLED diff --git a/examples/platform/silabs/SiWx917/SiWx917DeviceDataProvider.cpp b/examples/platform/silabs/SiWx917/SiWx917DeviceDataProvider.cpp index 34ccdbd1b95199..bb19b3e17a6cd9 100644 --- a/examples/platform/silabs/SiWx917/SiWx917DeviceDataProvider.cpp +++ b/examples/platform/silabs/SiWx917/SiWx917DeviceDataProvider.cpp @@ -16,20 +16,158 @@ */ #include "SiWx917DeviceDataProvider.h" +#include "DeviceConfig.h" +#include "siwx917_utils.h" #include #include #include +#include #include +#include #include namespace chip { namespace DeviceLayer { -namespace EFR32 { - +namespace SIWx917 { +#include // using namespace chip::Credentials; using namespace chip::DeviceLayer::Internal; -CHIP_ERROR EFR32DeviceDataProvider::GetSetupDiscriminator(uint16_t & setupDiscriminator) +#ifdef SIWX917_USE_COMISSIONABLE_DATA +void SIWx917DeviceDataProvider::setupPayload(uint8_t * outBuf) +{ + SetupPayload payload; + std::string result; + ChipError err = CHIP_NO_ERROR; + payload.version = 0; + payload.discriminator.SetLongValue(discriminatorValue); + payload.setUpPINCode = passcode; + payload.rendezvousInformation.SetValue(static_cast(rendezvousFlag)); + payload.commissioningFlow = static_cast(commissionableFlow); + payload.vendorID = vendorId; + payload.productID = productId; + + QRCodeSetupPayloadGenerator generator(payload); + err = generator.payloadBase38Representation(result); + if (err != CHIP_NO_ERROR) + { + SILABS_LOG("Failed to get the payload: %d", err); + } + SILABS_LOG("Payload value in string format : %s", result.c_str()); + std::vector result1; + // skipping the MT: from the payload during decoding + err = base38Decode(result.substr(3), result1); + if (err == CHIP_NO_ERROR) + { + for (uint8_t i = 0; i < result1.size(); i++) + { + outBuf[i] = result1.at(i); + } + } +} + +// writing to the flash based on the value given in the DeviceConfig.h +CHIP_ERROR SIWx917DeviceDataProvider::FlashFactoryData() +{ + // flashing the value to the nvm3 section of the flash + // TODO: remove this once it is removed SiWx917 have the nvm3 simiplicity commander support + CHIP_ERROR err; + // Checking for the value of CM and flag + if ((commissionableFlow > 3) || (rendezvousFlag > 7)) + { + return CHIP_ERROR_INTERNAL; + } + if (discriminatorValue != 0) + { + err = SilabsConfig::WriteConfigValue(SilabsConfig::kConfigKey_SetupDiscriminator, discriminatorValue); + if (err != CHIP_NO_ERROR) + { + return err; + } + } + uint8_t payload[kTotalPayloadDataSizeInBytes]; + setupPayload(payload); + err = SilabsConfig::WriteConfigValueBin(SilabsConfig::kConfigKey_SetupPayloadBitSet, payload, kTotalPayloadDataSizeInBytes); + if (err != CHIP_NO_ERROR) + { + return err; + } + if (spake2Interation != 0) + { + err = SilabsConfig::WriteConfigValue(SilabsConfig::kConfigKey_Spake2pIterationCount, spake2Interation); + if (err != CHIP_NO_ERROR) + { + return err; + } + } + if (spake2Salt != NULL) + { + err = SilabsConfig::WriteConfigValueStr(SilabsConfig::kConfigKey_Spake2pSalt, spake2Salt); + if (err != CHIP_NO_ERROR) + { + return err; + } + } + if (spake2Verifier != NULL) + { + err = SilabsConfig::WriteConfigValueStr(SilabsConfig::kConfigKey_Spake2pVerifier, spake2Verifier); + if (err != CHIP_NO_ERROR) + { + return err; + } + } + if (productId != 0) + { + err = SilabsConfig::WriteConfigValue(SilabsConfig::kConfigKey_ProductId, productId); + if (err != CHIP_NO_ERROR) + { + return err; + } + } + if (vendorId != 0) + { + err = SilabsConfig::WriteConfigValue(SilabsConfig::kConfigKey_VendorId, vendorId); + if (err != CHIP_NO_ERROR) + { + return err; + } + } + if (strlen(productName) != 0) + { + err = SilabsConfig::WriteConfigValueStr(SilabsConfig::kConfigKey_ProductName, productName); + if (err != CHIP_NO_ERROR) + { + return err; + } + } + if (strlen(vendorName) != 0) + { + err = SilabsConfig::WriteConfigValueStr(SilabsConfig::kConfigKey_VendorName, vendorName); + if (err != CHIP_NO_ERROR) + { + return err; + } + } + if (strlen(hwVersionString) != 0) + { + err = SilabsConfig::WriteConfigValueStr(SilabsConfig::kConfigKey_HardwareVersionString, hwVersionString); + if (err != CHIP_NO_ERROR) + { + return err; + } + } + if (rotatingId != 0) + { + err = SilabsConfig::WriteConfigValue(SilabsConfig::kConfigKey_UniqueId, rotatingId); + if (err != CHIP_NO_ERROR) + { + return err; + } + } +} +#endif + +CHIP_ERROR SIWx917DeviceDataProvider::GetSetupDiscriminator(uint16_t & setupDiscriminator) { CHIP_ERROR err; uint32_t setupDiscriminator32; @@ -48,10 +186,9 @@ CHIP_ERROR EFR32DeviceDataProvider::GetSetupDiscriminator(uint16_t & setupDiscri return CHIP_NO_ERROR; } -CHIP_ERROR EFR32DeviceDataProvider::GetSpake2pIterationCount(uint32_t & iterationCount) +CHIP_ERROR SIWx917DeviceDataProvider::GetSpake2pIterationCount(uint32_t & iterationCount) { CHIP_ERROR err = SilabsConfig::ReadConfigValue(SilabsConfig::kConfigKey_Spake2pIterationCount, iterationCount); - #if defined(CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_ITERATION_COUNT) && CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_ITERATION_COUNT if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { @@ -62,7 +199,7 @@ CHIP_ERROR EFR32DeviceDataProvider::GetSpake2pIterationCount(uint32_t & iteratio return err; } -CHIP_ERROR EFR32DeviceDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf) +CHIP_ERROR SIWx917DeviceDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf) { static constexpr size_t kSpake2pSalt_MaxBase64Len = BASE64_ENCODED_LEN(chip::Crypto::kSpake2p_Max_PBKDF_Salt_Length) + 1; @@ -71,7 +208,6 @@ CHIP_ERROR EFR32DeviceDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf) size_t saltB64Len = 0; err = SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_Spake2pSalt, saltB64, sizeof(saltB64), saltB64Len); - #if defined(CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_SALT) if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { @@ -94,7 +230,7 @@ CHIP_ERROR EFR32DeviceDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf) return CHIP_NO_ERROR; } -CHIP_ERROR EFR32DeviceDataProvider::GetSpake2pVerifier(MutableByteSpan & verifierBuf, size_t & verifierLen) +CHIP_ERROR SIWx917DeviceDataProvider::GetSpake2pVerifier(MutableByteSpan & verifierBuf, size_t & verifierLen) { static constexpr size_t kSpake2pSerializedVerifier_MaxBase64Len = BASE64_ENCODED_LEN(chip::Crypto::kSpake2p_VerifierSerialized_Length) + 1; @@ -105,7 +241,6 @@ CHIP_ERROR EFR32DeviceDataProvider::GetSpake2pVerifier(MutableByteSpan & verifie err = SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_Spake2pVerifier, verifierB64, sizeof(verifierB64), verifierB64Len); - #if defined(CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_VERIFIER) if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { @@ -127,15 +262,13 @@ CHIP_ERROR EFR32DeviceDataProvider::GetSpake2pVerifier(MutableByteSpan & verifie return CHIP_NO_ERROR; } -CHIP_ERROR EFR32DeviceDataProvider::GetSetupPayload(MutableCharSpan & payloadBuf) +CHIP_ERROR SIWx917DeviceDataProvider::GetSetupPayload(MutableCharSpan & payloadBuf) { CHIP_ERROR err = CHIP_NO_ERROR; uint8_t payloadBitSet[kTotalPayloadDataSizeInBytes] = { 0 }; size_t bitSetLen = 0; - err = SilabsConfig::ReadConfigValueBin(SilabsConfig::kConfigKey_SetupPayloadBitSet, payloadBitSet, kTotalPayloadDataSizeInBytes, bitSetLen); - #if defined(CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE) && CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { @@ -167,19 +300,18 @@ CHIP_ERROR EFR32DeviceDataProvider::GetSetupPayload(MutableCharSpan & payloadBuf return err; } -CHIP_ERROR EFR32DeviceDataProvider::GetVendorName(char * buf, size_t bufSize) +CHIP_ERROR SIWx917DeviceDataProvider::GetVendorName(char * buf, size_t bufSize) { size_t vendorNameLen = 0; // without counting null-terminator return SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_VendorName, buf, bufSize, vendorNameLen); } -CHIP_ERROR EFR32DeviceDataProvider::GetVendorId(uint16_t & vendorId) +CHIP_ERROR SIWx917DeviceDataProvider::GetVendorId(uint16_t & vendorId) { ChipError err = CHIP_NO_ERROR; uint32_t vendorId32 = 0; err = SilabsConfig::ReadConfigValue(SilabsConfig::kConfigKey_VendorId, vendorId32); - #if defined(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID) && CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { @@ -193,19 +325,18 @@ CHIP_ERROR EFR32DeviceDataProvider::GetVendorId(uint16_t & vendorId) return err; } -CHIP_ERROR EFR32DeviceDataProvider::GetProductName(char * buf, size_t bufSize) +CHIP_ERROR SIWx917DeviceDataProvider::GetProductName(char * buf, size_t bufSize) { size_t productNameLen = 0; // without counting null-terminator return SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_ProductName, buf, bufSize, productNameLen); } -CHIP_ERROR EFR32DeviceDataProvider::GetProductId(uint16_t & productId) +CHIP_ERROR SIWx917DeviceDataProvider::GetProductId(uint16_t & productId) { ChipError err = CHIP_NO_ERROR; uint32_t productId32 = 0; err = SilabsConfig::ReadConfigValue(SilabsConfig::kConfigKey_ProductId, productId32); - #if defined(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID) && CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { @@ -219,7 +350,7 @@ CHIP_ERROR EFR32DeviceDataProvider::GetProductId(uint16_t & productId) return err; } -CHIP_ERROR EFR32DeviceDataProvider::GetHardwareVersionString(char * buf, size_t bufSize) +CHIP_ERROR SIWx917DeviceDataProvider::GetHardwareVersionString(char * buf, size_t bufSize) { size_t hardwareVersionStringLen = 0; // without counting null-terminator CHIP_ERROR err = @@ -234,7 +365,7 @@ CHIP_ERROR EFR32DeviceDataProvider::GetHardwareVersionString(char * buf, size_t return err; } -CHIP_ERROR EFR32DeviceDataProvider::GetHardwareVersion(uint16_t & hardwareVersion) +CHIP_ERROR SIWx917DeviceDataProvider::GetHardwareVersion(uint16_t & hardwareVersion) { CHIP_ERROR err; uint32_t hardwareVersion32; @@ -252,7 +383,7 @@ CHIP_ERROR EFR32DeviceDataProvider::GetHardwareVersion(uint16_t & hardwareVersio return err; } -CHIP_ERROR EFR32DeviceDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) +CHIP_ERROR SIWx917DeviceDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) { ChipError err = CHIP_ERROR_WRONG_KEY_TYPE; #if CHIP_ENABLE_ROTATING_DEVICE_ID @@ -280,13 +411,13 @@ CHIP_ERROR EFR32DeviceDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan return err; } -CHIP_ERROR EFR32DeviceDataProvider::GetSerialNumber(char * buf, size_t bufSize) +CHIP_ERROR SIWx917DeviceDataProvider::GetSerialNumber(char * buf, size_t bufSize) { size_t serialNumberLen = 0; // without counting null-terminator return SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_SerialNum, buf, bufSize, serialNumberLen); } -CHIP_ERROR EFR32DeviceDataProvider::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) +CHIP_ERROR SIWx917DeviceDataProvider::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) { CHIP_ERROR err; constexpr uint8_t kDateStringLength = 10; // YYYY-MM-DD @@ -324,12 +455,12 @@ CHIP_ERROR EFR32DeviceDataProvider::GetManufacturingDate(uint16_t & year, uint8_ return CHIP_ERROR_NOT_IMPLEMENTED; } -EFR32DeviceDataProvider & EFR32DeviceDataProvider::GetDeviceDataProvider() +SIWx917DeviceDataProvider & SIWx917DeviceDataProvider::GetDeviceDataProvider() { - static EFR32DeviceDataProvider sDataProvider; + static SIWx917DeviceDataProvider sDataProvider; return sDataProvider; } -} // namespace EFR32 +} // namespace SIWx917 } // namespace DeviceLayer } // namespace chip diff --git a/examples/platform/silabs/SiWx917/SiWx917DeviceDataProvider.h b/examples/platform/silabs/SiWx917/SiWx917DeviceDataProvider.h index e47a2fe915bfea..216a7529c62238 100644 --- a/examples/platform/silabs/SiWx917/SiWx917DeviceDataProvider.h +++ b/examples/platform/silabs/SiWx917/SiWx917DeviceDataProvider.h @@ -21,25 +21,26 @@ namespace chip { namespace DeviceLayer { -namespace EFR32 { +namespace SIWx917 { /** * @brief This class provides Commissionable data, Device Attestation Credentials, * and Device Instance Info. */ -class EFR32DeviceDataProvider : public CommissionableDataProvider, - public Internal::GenericDeviceInstanceInfoProvider +class SIWx917DeviceDataProvider : public CommissionableDataProvider, + public Internal::GenericDeviceInstanceInfoProvider { public: - EFR32DeviceDataProvider() : + SIWx917DeviceDataProvider() : CommissionableDataProvider(), Internal::GenericDeviceInstanceInfoProvider( ConfigurationManagerImpl::GetDefaultInstance()) {} - static EFR32DeviceDataProvider & GetDeviceDataProvider(); + static SIWx917DeviceDataProvider & GetDeviceDataProvider(); CHIP_ERROR GetSetupPayload(MutableCharSpan & payloadBuf); - + void setupPayload(uint8_t * outBuf); + CHIP_ERROR FlashFactoryData(); // ===== Members functions that implement the CommissionableDataProvider CHIP_ERROR GetSetupDiscriminator(uint16_t & setupDiscriminator) override; CHIP_ERROR SetSetupDiscriminator(uint16_t setupDiscriminator) override { return CHIP_ERROR_NOT_IMPLEMENTED; } @@ -62,6 +63,6 @@ class EFR32DeviceDataProvider : public CommissionableDataProvider, CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override; }; -} // namespace EFR32 +} // namespace SIWx917 } // namespace DeviceLayer } // namespace chip diff --git a/examples/platform/silabs/SiWx917/matter_config.cpp b/examples/platform/silabs/SiWx917/matter_config.cpp index 49339e64e33cb7..94d4dacfe512d9 100644 --- a/examples/platform/silabs/SiWx917/matter_config.cpp +++ b/examples/platform/silabs/SiWx917/matter_config.cpp @@ -96,7 +96,6 @@ CHIP_ERROR SI917MatterConfig::InitMatter(const char * appName) #ifdef HEAP_MONITORING MemMonitoring::startHeapMonitoring(); #endif - //============================================== // Init Matter Stack //============================================== @@ -113,9 +112,17 @@ CHIP_ERROR SI917MatterConfig::InitMatter(const char * appName) } ReturnErrorOnFailure(PlatformMgr().InitChipStack()); - SetDeviceInstanceInfoProvider(&EFR32::EFR32DeviceDataProvider::GetDeviceDataProvider()); - SetCommissionableDataProvider(&EFR32::EFR32DeviceDataProvider::GetDeviceDataProvider()); + SetDeviceInstanceInfoProvider(&SIWx917::SIWx917DeviceDataProvider::GetDeviceDataProvider()); + SetCommissionableDataProvider(&SIWx917::SIWx917DeviceDataProvider::GetDeviceDataProvider()); +#ifdef SIWX917_USE_COMISSIONABLE_DATA + err = SIWx917::SIWx917DeviceDataProvider::GetDeviceDataProvider().FlashFactoryData(); + if (err != CHIP_NO_ERROR) + { + SILABS_LOG("Flashing to the device failed"); + return err; + } +#endif chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName(appName); // Stop Matter event handling while setting up resources diff --git a/examples/window-app/silabs/SiWx917/BUILD.gn b/examples/window-app/silabs/SiWx917/BUILD.gn index db35f8de44dd35..b624fdf1947f1a 100644 --- a/examples/window-app/silabs/SiWx917/BUILD.gn +++ b/examples/window-app/silabs/SiWx917/BUILD.gn @@ -52,6 +52,9 @@ declare_args() { # Argument to force enable WPA3 security rs91x_wpa3_only = false + # use commissionable data for SiWx917 + siwx917_commissionable_data = false + #default WiFi SSID chip_default_wifi_ssid = "" @@ -78,6 +81,10 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" || defines = [] +if (siwx917_commissionable_data) { + defines += [ "SIWX917_USE_COMISSIONABLE_DATA=1" ] +} + # WiFi settings if (chip_enable_wifi) { # disabling LCD for MG24 for wifi diff --git a/examples/window-app/silabs/SiWx917/include/DeviceConfig.h b/examples/window-app/silabs/SiWx917/include/DeviceConfig.h new file mode 100644 index 00000000000000..18af7b2c9c8415 --- /dev/null +++ b/examples/window-app/silabs/SiWx917/include/DeviceConfig.h @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Google LLC. + * 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 + +#ifdef SIWX917_USE_COMISSIONABLE_DATA + +uint32_t discriminatorValue = 3840; +uint64_t passcode = 20202021; +uint32_t spake2Interation = 1000; +char spake2Salt[] = "U1BBS0UyUCBLZXkgU2FsdA=="; +char spake2Verifier[] = "uWFwqugDNGiEck/po7KHwwMwwqZgN10XuyBajPGuyzUEV/iree4lOrao5GuwnlQ65CJzbeUB49s31EH+NEkg0JVI5MGCQGMMT/" + "SRPFNRODm3wH/MBiehuFc6FJ/NH6Rmzw=="; +char genSpake2Path[] = ""; +uint32_t productId = 32773; +uint32_t vendorId = 65521; +char productName[] = ""; +char vendorName[] = ""; +char hwVersionString[] = ""; +uint32_t rotatingId; +uint32_t commissionableFlow = 1; +uint8_t rendezvousFlag = 2; + +#endif \ No newline at end of file diff --git a/scripts/examples/gn_efr32_example.sh b/scripts/examples/gn_efr32_example.sh index eb9afb4a9dbd79..09bdf90afb0312 100755 --- a/scripts/examples/gn_efr32_example.sh +++ b/scripts/examples/gn_efr32_example.sh @@ -98,6 +98,8 @@ if [ "$#" == "0" ]; then Periodic query timeout variable for OTA in seconds rs91x_wpa3_only Support for WPA3 only mode on RS91x + siwx917_commissionable_data + Build with the commissionable data given in DeviceConfig.h (only for SiWx917) Presets --sed enable sleepy end device, set thread mtd