Skip to content

Commit 4dbaa06

Browse files
Sync csa branch with main (#1269)
2 parents 9fcd3ab + becff2b commit 4dbaa06

49 files changed

Lines changed: 1151 additions & 191 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎config/esp32/components/chip/CMakeLists.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ if (IDF_VERSION_MAJOR GREATER_EQUAL 6)
8888
chip_gn_arg_append("chip_crypto" "\"psa\"")
8989
# keep using older mbedTLS APIs for spake2p, PSA driver for PSA_ALG_SPAKE2P_MATTER is not yet available in mbedtls v4.x
9090
chip_gn_arg_append("chip_crypto_spake2p" "\"mbedtls\"")
91-
chip_gn_arg_bool("chip_crypto_psa_aead_single_part" "true")
9291
endif()
9392

9493
# If ccache was enabled by IDF and the ccache executable was found,

‎examples/ota-provider-app/esp32/main/BdxOtaSender.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <messaging/ExchangeContext.h>
2424
#include <messaging/Flags.h>
2525
#include <protocols/bdx/BdxTransferSession.h>
26+
#include <transport/Session.h>
2627

2728
using chip::bdx::StatusCode;
2829
using chip::bdx::TransferControlFlags;
@@ -54,6 +55,25 @@ CHIP_ERROR BdxOtaSender::InitializeTransfer(chip::FabricIndex fabricIndex, chip:
5455
return CHIP_NO_ERROR;
5556
}
5657

58+
CHIP_ERROR BdxOtaSender::OnMessageReceived(chip::Messaging::ExchangeContext * ec, const chip::PayloadHeader & payloadHeader,
59+
chip::System::PacketBufferHandle && payload)
60+
{
61+
VerifyOrReturnError(ec != nullptr, CHIP_ERROR_INCORRECT_STATE);
62+
VerifyOrReturnError(mInitialized && mFabricIndex.HasValue() && mNodeId.HasValue(), CHIP_ERROR_INCORRECT_STATE);
63+
64+
// Only a unicast CASE/PASE session carries an authenticated peer identity. Reject group and
65+
// unauthenticated sessions, whose GetPeer() is the unauthenticated packet-header source node id.
66+
const auto & session = ec->GetSessionHandle();
67+
VerifyOrReturnError(session->IsSecureSession(), CHIP_ERROR_INVALID_DESTINATION_NODE_ID);
68+
69+
// Serve only the requester the transfer was armed for by its QueryImage. The exchange already
70+
// driving the transfer passes this by construction, so it is never rejected here.
71+
VerifyOrReturnError(session->GetFabricIndex() == mFabricIndex.Value() && session->GetPeer().GetNodeId() == mNodeId.Value(),
72+
CHIP_ERROR_INVALID_DESTINATION_NODE_ID);
73+
74+
return chip::bdx::TransferFacilitator::OnMessageReceived(ec, payloadHeader, std::move(payload));
75+
}
76+
5777
void BdxOtaSender::SetCallbacks(BdxOtaSenderCallbacks callbacks)
5878
{
5979
mOnBlockQueryCallback = callbacks.onBlockQuery;

‎examples/ota-provider-app/esp32/main/include/ota-provider-common/BdxOtaSender.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ class BdxOtaSender : public chip::bdx::Responder
108108
// No-op, ESP32's BdxOtaSender doesn't need to SetFileDesignatorMap since it uses a callback
109109
void SetFileDesignatorMap(const std::unordered_map<std::string, std::string> &) {}
110110

111+
protected:
112+
// Inherited from bdx::TransferFacilitator
113+
CHIP_ERROR OnMessageReceived(chip::Messaging::ExchangeContext * ec, const chip::PayloadHeader & payloadHeader,
114+
chip::System::PacketBufferHandle && payload) override final;
115+
111116
private:
112117
// Inherited from bdx::TransferFacilitator
113118
void HandleTransferSessionOutput(chip::bdx::TransferSession::OutputEvent & event) override;

‎examples/ota-provider-app/esp32/main/main.cpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "DeviceCallbacks.h"
1919
#include "esp_log.h"
20-
#include "esp_spi_flash.h"
2120
#include "esp_spiffs.h"
2221
#include "nvs_flash.h"
2322
#include <app/server/Server.h>
@@ -35,6 +34,12 @@
3534
#include <ota-provider-common/OTAProviderExample.h>
3635
#include <shell_extension/launch.h>
3736

37+
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
38+
#include "esp_spi_flash.h"
39+
#else
40+
#include "esp_flash.h"
41+
#endif
42+
3843
#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
3944
#include <platform/ESP32/ESP32FactoryDataProvider.h>
4045
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

‎examples/platform/silabs/provision/BUILD.gn‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ source_set("storage") {
8383
}
8484
}
8585

86-
defines =
87-
[ "SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS=${sl_use_example_credentials}" ]
86+
defines = [
87+
"SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS=${sl_use_example_credentials}",
88+
"SL_MATTER_USE_FLASH_STORE=${use_provision_flash_storage}",
89+
]
8890

8991
# Require the provision library when provision channel or flash storage is used
9092
if (sl_use_provision_channel || use_provision_flash_storage) {

‎examples/platform/silabs/provision/ProvisionCryptoMbed.cpp‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
#include <tinycrypt/ecc_dsa.h>
1818
#endif
1919

20+
#if SL_MATTER_USE_FLASH_STORE
21+
#include <headers/ProvisionStorage.h>
22+
#include <provision/flash/ProvisionStorageFlash.h>
23+
#endif // SL_MATTER_USE_FLASH_STORE
24+
2025
#include <cstdio>
2126
#include <cstring>
2227

@@ -64,10 +69,27 @@ CHIP_ERROR FormatMatterOidUtf8DerHex(char * destination, size_t destinationSize,
6469

6570
CHIP_ERROR ReadKey(MutableByteSpan & key)
6671
{
72+
#if SL_MATTER_USE_FLASH_STORE == 1
73+
size_t size = 0;
74+
CHIP_ERROR err = Flash::Get(Parameters::ID::kDacKey, key.data(), key.size(), size);
75+
ReturnErrorOnFailure(err);
76+
key.reduce_size(size);
77+
return err;
78+
#else
6779
size_t size = 0;
6880
ReturnErrorOnFailure(SilabsConfig::ReadConfigValueBin(SilabsConfig::kConfigKey_Creds_KeyId, key.data(), key.size(), size));
6981
key.reduce_size(size);
7082
return CHIP_NO_ERROR;
83+
#endif // SL_MATTER_USE_FLASH_STORE
84+
}
85+
86+
CHIP_ERROR WriteKey(ByteSpan key)
87+
{
88+
#if SL_MATTER_USE_FLASH_STORE == 1
89+
return Flash::Set(Parameters::ID::kDacKey, key.data(), key.size());
90+
#else
91+
return SilabsConfig::WriteConfigValueBin(SilabsConfig::kConfigKey_Creds_KeyId, key.data(), key.size());
92+
#endif // SL_MATTER_USE_FLASH_STORE
7193
}
7294

7395
#if defined(SLI_SI91X_MCU_INTERFACE) && defined(SL_MBEDTLS_USE_TINYCRYPT) && SL_MBEDTLS_USE_TINYCRYPT
@@ -146,7 +168,7 @@ CHIP_ERROR ProvisionCrypto::Hash256(const ByteSpan & input, MutableByteSpan & ou
146168
CHIP_ERROR ProvisionCrypto::ImportDeviceAttestationKey(const ByteSpan & key)
147169
{
148170
VerifyOrReturnError(!key.empty() && key.size() <= kDeviceAttestationKeySizeMax, CHIP_ERROR_INVALID_ARGUMENT);
149-
return SilabsConfig::WriteConfigValueBin(SilabsConfig::kConfigKey_Creds_KeyId, key.data(), key.size());
171+
return WriteKey(key);
150172
}
151173

152174
CHIP_ERROR ProvisionCrypto::GenerateDeviceAttestationCSR(uint16_t vid, uint16_t pid, const CharSpan & commonName,
@@ -201,8 +223,7 @@ CHIP_ERROR ProvisionCrypto::GenerateDeviceAttestationCSR(uint16_t vid, uint16_t
201223
uint8_t encodedKey[kDeviceAttestationKeySizeMax] = { 0 };
202224
const int encodedSize = mbedtls_pk_write_key_der(&key.context, encodedKey, sizeof(encodedKey));
203225
VerifyOrReturnError(encodedSize > 0 && static_cast<size_t>(encodedSize) <= sizeof(encodedKey), CHIP_ERROR_INTERNAL);
204-
return SilabsConfig::WriteConfigValueBin(SilabsConfig::kConfigKey_Creds_KeyId, encodedKey + sizeof(encodedKey) - encodedSize,
205-
encodedSize);
226+
return WriteKey(ByteSpan(encodedKey + sizeof(encodedKey) - encodedSize, static_cast<size_t>(encodedSize)));
206227
#endif
207228
}
208229

‎examples/platform/silabs/provision/default/ProvisionStorageReader.cpp‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,23 @@
2222
#include <platform/CHIPDeviceConfig.h>
2323
#include <platform/CHIPDeviceError.h>
2424
#include <platform/silabs/SilabsConfig.h>
25-
#include <platform/silabs/multi-ota/OtaTlvEncryptionKey.h>
2625
#include <provision/ProvisionCrypto.h>
2726
#include <provision/ProvisionStorageReader.h>
2827
#include <silabs_creds.h>
2928

29+
#if defined(SL_MATTER_ENABLE_OTA_ENCRYPTION) && SL_MATTER_ENABLE_OTA_ENCRYPTION
30+
#include <platform/silabs/multi-ota/OtaTlvEncryptionKey.h>
31+
#endif // SL_MATTER_ENABLE_OTA_ENCRYPTION && SL_MATTER_ENABLE_OTA_ENCRYPTION
32+
33+
#if !SL_MATTER_GN_BUILD
34+
#include <sl_matter_provision_config.h>
35+
3036
#ifndef NDEBUG
31-
#if defined(SL_MATTER_TEST_EVENT_TRIGGER_ENABLED) && (SL_MATTER_GN_BUILD == 0)
37+
#if defined(SL_MATTER_TEST_EVENT_TRIGGER_ENABLED)
3238
#include <sl_matter_test_event_trigger_config.h>
33-
#endif
34-
#endif
39+
#endif // defined(SL_MATTER_TEST_EVENT_TRIGGER_ENABLED)
40+
#endif // NDEBUG
41+
#endif // !SL_MATTER_GN_BUILD
3542

3643
#include <cstring>
3744

‎examples/platform/silabs/provision/default/ProvisionStorageWriter.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
#include <lib/support/logging/CHIPLogging.h>
2020
#include <platform/CHIPDeviceConfig.h>
2121
#include <platform/silabs/SilabsConfig.h>
22-
#include <platform/silabs/multi-ota/OtaTlvEncryptionKey.h>
2322
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
2423
#include <provision/ProvisionStorageWriter.h>
2524
#include <silabs_creds.h>
2625

2726
#include <cstring>
2827

28+
#if defined(SL_MATTER_ENABLE_OTA_ENCRYPTION) && SL_MATTER_ENABLE_OTA_ENCRYPTION
29+
#include <platform/silabs/multi-ota/OtaTlvEncryptionKey.h>
30+
#endif
31+
2932
using SilabsConfig = chip::DeviceLayer::Internal::SilabsConfig;
3033

3134
#if defined(SL_PROVISION_GENERATOR) && SL_PROVISION_GENERATOR

‎examples/platform/silabs/provision/flash/ProvisionStorageReader.cpp‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,21 @@
2525
#include <provision/ProvisionCrypto.h>
2626
#include <provision/ProvisionStorageReader.h>
2727
#include <provision/flash/ProvisionStorageFlash.h>
28+
2829
#if defined(SL_MATTER_ENABLE_OTA_ENCRYPTION) && SL_MATTER_ENABLE_OTA_ENCRYPTION
2930
#include <platform/silabs/multi-ota/OtaTlvEncryptionKey.h>
30-
#endif
31+
#endif // defined(SL_MATTER_ENABLE_OTA_ENCRYPTION) && SL_MATTER_ENABLE_OTA_ENCRYPTION
32+
33+
#if !SL_MATTER_GN_BUILD
34+
#include <sl_matter_provision_config.h>
35+
36+
#ifndef NDEBUG
37+
#if defined(SL_MATTER_TEST_EVENT_TRIGGER_ENABLED)
38+
#include <sl_matter_test_event_trigger_config.h>
39+
#endif // defined(SL_MATTER_TEST_EVENT_TRIGGER_ENABLED)
40+
#endif // NDEBUG
41+
#endif // !SL_MATTER_GN_BUILD
42+
3143
#include <cstring>
3244
using namespace chip::Credentials;
3345
namespace chip {

‎examples/platform/silabs/provision/flash/ProvisionStorageWriter.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
#include <lib/support/CodeUtils.h>
2020
#include <provision/ProvisionStorageWriter.h>
2121
#include <provision/flash/ProvisionStorageFlash.h>
22+
2223
#if defined(SL_MATTER_ENABLE_OTA_ENCRYPTION) && SL_MATTER_ENABLE_OTA_ENCRYPTION
2324
#include <platform/silabs/multi-ota/OtaTlvEncryptionKey.h>
2425
#endif
26+
2527
namespace chip {
2628
namespace DeviceLayer {
2729
namespace Silabs {

0 commit comments

Comments
 (0)