Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/fix_for_thermostat
Browse files Browse the repository at this point in the history
  • Loading branch information
arun-silabs authored Sep 24, 2024
2 parents 546f3a0 + fbc0d21 commit 30f8451
Show file tree
Hide file tree
Showing 23 changed files with 286 additions and 139 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
framework:
name: Build framework
if: github.actor != 'restyled-io[bot]'
runs-on: macos-13
runs-on: macos-14
strategy:
matrix:
options: # We don't need a full matrix
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
name: Run framework tests
if: github.actor != 'restyled-io[bot]'
needs: [framework] # serialize to avoid running to many parallel macos runners
runs-on: macos-13
runs-on: macos-14
strategy:
matrix:
options: # We don't need a full matrix
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/example-tv-casting-darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
tv-casting-bridge:
name: Build TV Casting Bridge example
if: github.actor != 'restyled-io[bot]'
runs-on: macos-13
runs-on: macos-14
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
49 changes: 47 additions & 2 deletions examples/platform/silabs/provision/ProvisionStorageDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "AttestationKey.h"
#include "ProvisionStorage.h"
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <em_device.h>
#include <lib/support/BytesToHex.h>
#include <lib/support/CHIPMemString.h>
#include <lib/support/CodeUtils.h>
Expand All @@ -34,7 +35,13 @@
#ifdef SLI_SI91X_MCU_INTERFACE
#include <sl_si91x_common_flash_intf.h>
#else
#ifdef _SILICON_LABS_32B_SERIES_2
#include <em_msc.h>
#elif defined(_SILICON_LABS_32B_SERIES_3)
#include "sl_se_manager.h"
#include "sl_se_manager_types.h"
#include <sl_se_manager_extmem.h>
#endif // _SILICON_LABS_32B_SERIES_2
#include <psa/crypto.h>
#endif

Expand All @@ -44,6 +51,16 @@ extern void setNvm3End(uint32_t addr);
#include <sl_matter_provision_config.h>
#endif

#if defined(_SILICON_LABS_32B_SERIES_3)
// To remove any ambiguities regarding the Flash aliases, use the below macro to ignore the 8 MSB.
#define FLASH_GENERIC_MASK 0x00FFFFFF
#define GENERIC_ADDRESS(addr) ((addr) &FLASH_GENERIC_MASK)

// Transforms any address into an address using the same alias as FLASH_BASE from the CMSIS.
#define CMSIS_CONVERTED_ADDRESS(addr) (GENERIC_ADDRESS(addr) | FLASH_BASE)
sl_se_command_context_t cmd_ctx;
#endif // _SILICON_LABS_32B_SERIES_3

extern uint8_t linker_nvm_end[];

using namespace chip::Credentials;
Expand All @@ -66,8 +83,18 @@ CHIP_ERROR ErasePage(uint32_t addr)
{
#ifdef SLI_SI91X_MCU_INTERFACE
rsi_flash_erase_sector((uint32_t *) addr);
#else
#elif defined(_SILICON_LABS_32B_SERIES_2)
MSC_ErasePage((uint32_t *) addr);
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
uint32_t * data_start = NULL;
size_t data_size;

status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
status = sl_se_data_region_erase(&cmd_ctx, (void *) addr, 1); // Erase one page
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
#endif
return CHIP_NO_ERROR;
}
Expand All @@ -76,8 +103,18 @@ CHIP_ERROR WritePage(uint32_t addr, const uint8_t * data, size_t size)
{
#ifdef SLI_SI91X_MCU_INTERFACE
rsi_flash_write((uint32_t *) addr, (unsigned char *) data, size);
#else
#elif defined(_SILICON_LABS_32B_SERIES_2)
MSC_WriteWord((uint32_t *) addr, data, size);
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
uint32_t * data_start = NULL;
size_t data_size;

status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
status = sl_se_data_region_write(&cmd_ctx, (void *) addr, data, size);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
#endif
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -161,7 +198,15 @@ CHIP_ERROR Storage::Initialize(uint32_t flash_addr, uint32_t flash_size)
{
#ifndef SLI_SI91X_MCU_INTERFACE
base_addr = (flash_addr + flash_size - FLASH_PAGE_SIZE);

#ifdef _SILICON_LABS_32B_SERIES_2
MSC_Init();
#elif defined(_SILICON_LABS_32B_SERIES_3)
sl_status_t status;
status = sl_se_init();
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
status = sl_se_init_command_context(&cmd_ctx);
#endif // _SILICON_LABS_32B_SERIES
#endif // SLI_SI91X_MCU_INTERFACE
#ifdef SL_PROVISION_GENERATOR
setNvm3End(base_addr);
Expand Down
1 change: 1 addition & 0 deletions src/app/icd/server/ICDMonitoringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ CHIP_ERROR ICDMonitoringEntry::Serialize(TLV::TLVWriter & writer) const
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(Fields::kClientType), clientType));

ReturnErrorOnFailure(writer.EndContainer(outer));
ReturnErrorOnFailure(writer.Finalize());
return CHIP_NO_ERROR;
}

Expand Down
17 changes: 15 additions & 2 deletions src/app/icd/server/ICDMonitoringTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@ using SymmetricKeystore = SessionKeystore;

namespace chip {

inline constexpr size_t kICDMonitoringBufferSize = 60;
static constexpr size_t MaxICDMonitoringEntrySize()
{
// All the fields added together
return TLV::EstimateStructOverhead(sizeof(NodeId) /*checkInNodeID*/, sizeof(uint64_t) /*monitoredSubject*/,
sizeof(Crypto::Symmetric128BitsKeyByteArray) /*aes_key_handle*/,
sizeof(Crypto::Symmetric128BitsKeyByteArray) /*hmac_key_handle*/,
sizeof(uint8_t) /*client_type*/) *
// Provide 50% extra space to make a firmware upgrade that starts storing
// more data followed by a downgrade work easily and reliably.
// The 50% number is chosen fairly randomly; storage increases larger than that are
// possible but need to be staged carefully.
3 / 2;
}

inline constexpr size_t kICDMonitoringBufferSize = MaxICDMonitoringEntrySize();

struct ICDMonitoringEntry : public PersistentData<kICDMonitoringBufferSize>
{

ICDMonitoringEntry(FabricIndex fabric = kUndefinedFabricIndex, NodeId nodeId = kUndefinedNodeId)
{
this->fabricIndex = fabric;
Expand Down
16 changes: 16 additions & 0 deletions src/app/icd/server/tests/TestICDMonitoringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ constexpr uint64_t kClientNodeId13 = 0x100003;
constexpr uint64_t kClientNodeId21 = 0x200001;
constexpr uint64_t kClientNodeId22 = 0x200002;

constexpr uint64_t kClientNodeMaxValue = std::numeric_limits<uint64_t>::max();

constexpr uint8_t kKeyBuffer0a[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
constexpr uint8_t kKeyBuffer0b[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Expand Down Expand Up @@ -98,6 +100,20 @@ TEST(TestICDMonitoringTable, TestEntryAssignationOverload)
EXPECT_TRUE(entry2.IsKeyEquivalent(ByteSpan(kKeyBuffer1a)));
}

TEST(TestICDMonitoringTable, TestEntryMaximumSize)
{
TestPersistentStorageDelegate storage;
TestSessionKeystoreImpl keystore;
ICDMonitoringTable table(storage, kTestFabricIndex1, kMaxTestClients1, &keystore);

ICDMonitoringEntry entry(&keystore);
entry.checkInNodeID = kClientNodeMaxValue;
entry.monitoredSubject = kClientNodeMaxValue;
entry.clientType = ClientTypeEnum::kPermanent;
EXPECT_EQ(CHIP_NO_ERROR, entry.SetKey(ByteSpan(kKeyBuffer1a)));
EXPECT_EQ(CHIP_NO_ERROR, table.Set(0, entry));
}

TEST(TestICDMonitoringTable, TestEntryKeyFunctions)
{
TestSessionKeystoreImpl keystore;
Expand Down
10 changes: 10 additions & 0 deletions src/app/util/attribute-metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@

#include <app-common/zap-generated/attribute-type.h>

bool EmberAfAttributeMetadata::IsBoolean() const
{
return attributeType == ZCL_BOOLEAN_ATTRIBUTE_TYPE;
}

bool EmberAfAttributeMetadata::IsSignedIntegerAttribute() const
{
return chip::app::IsSignedAttributeType(attributeType);
}

bool emberAfIsStringAttributeType(EmberAfAttributeType attributeType)
{
return (attributeType == ZCL_OCTET_STRING_ATTRIBUTE_TYPE || attributeType == ZCL_CHAR_STRING_ATTRIBUTE_TYPE);
Expand Down
5 changes: 2 additions & 3 deletions src/app/util/attribute-metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#pragma once

#include <app-common/zap-generated/attribute-type.h>
#include <app/util/basic-types.h>
#include <cstdint>

Expand Down Expand Up @@ -161,12 +160,12 @@ struct EmberAfAttributeMetadata
/**
* Check wether this attribute is a boolean based on its type according to the spec.
*/
bool IsBoolean() const { return attributeType == ZCL_BOOLEAN_ATTRIBUTE_TYPE; }
bool IsBoolean() const;

/**
* Check wether this attribute is signed based on its type according to the spec.
*/
bool IsSignedIntegerAttribute() const { return chip::app::IsSignedAttributeType(attributeType); }
bool IsSignedIntegerAttribute() const;

/**
* Check whether this attribute has a define min and max.
Expand Down
44 changes: 0 additions & 44 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,6 @@ - (void)_controllerResumed
// Subclass hook; nothing to do.
}

- (BOOL)matchesPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate
{
// TODO: Once the factory knows it's dealing with MTRDeviceController_Concrete, this can be removed, and its
// declaration moved to MTRDeviceController_Concrete.
return NO;
}

- (void)clearPendingShutdown
{
// TODO: Once the factory knows it's dealing with MTRDeviceController_Concrete, this can be removed, and its
// declaration moved to MTRDeviceController_Concrete.
MTR_ABSTRACT_METHOD();
}

- (void)shutdown
{
MTR_ABSTRACT_METHOD();
Expand Down Expand Up @@ -1085,36 +1071,6 @@ - (nullable NSNumber *)compressedFabricID
return storedValue.has_value() ? @(storedValue.value()) : nil;
}

- (CHIP_ERROR)isRunningOnFabric:(chip::FabricTable *)fabricTable
fabricIndex:(chip::FabricIndex)fabricIndex
isRunning:(BOOL *)isRunning
{
assertChipStackLockedByCurrentThread();

if (![self isRunning]) {
*isRunning = NO;
return CHIP_NO_ERROR;
}

const chip::FabricInfo * otherFabric = fabricTable->FindFabricWithIndex(fabricIndex);
if (!otherFabric) {
// Should not happen...
return CHIP_ERROR_INCORRECT_STATE;
}

if (_cppCommissioner->GetFabricId() != otherFabric->GetFabricId()) {
*isRunning = NO;
return CHIP_NO_ERROR;
}

chip::Crypto::P256PublicKey ourRootPublicKey, otherRootPublicKey;
ReturnErrorOnFailure(_cppCommissioner->GetRootPublicKey(ourRootPublicKey));
ReturnErrorOnFailure(fabricTable->FetchRootPubkey(otherFabric->GetFabricIndex(), otherRootPublicKey));

*isRunning = (ourRootPublicKey.Matches(otherRootPublicKey));
return CHIP_NO_ERROR;
}

- (void)invalidateCASESessionForNode:(chip::NodeId)nodeID;
{
auto block = ^{
Expand Down
8 changes: 4 additions & 4 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,9 @@ - (void)controllerShuttingDown:(MTRDeviceController_Concrete *)controller
return [_controllers copy];
}

- (nullable MTRDeviceController *)runningControllerForFabricIndex:(FabricIndex)fabricIndex
includeControllerStartingUp:(BOOL)includeControllerStartingUp
includeControllerShuttingDown:(BOOL)includeControllerShuttingDown
- (nullable MTRDeviceController_Concrete *)runningControllerForFabricIndex:(FabricIndex)fabricIndex
includeControllerStartingUp:(BOOL)includeControllerStartingUp
includeControllerShuttingDown:(BOOL)includeControllerShuttingDown
{
assertChipStackLockedByCurrentThread();

Expand Down Expand Up @@ -1006,7 +1006,7 @@ - (nullable MTRDeviceController *)runningControllerForFabricIndex:(FabricIndex)f
return nil;
}

- (nullable MTRDeviceController *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex
- (nullable MTRDeviceController_Concrete *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex
{
return [self runningControllerForFabricIndex:fabricIndex includeControllerStartingUp:YES includeControllerShuttingDown:YES];
}
Expand Down
10 changes: 5 additions & 5 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ MTR_DIRECT_MEMBERS
* Get the list of running controllers. This will include controllers that are
* in the middle of starting up or shutting down.
*/
- (NSArray<MTRDeviceController *> *)getRunningControllers;
- (NSArray<MTRDeviceController_Concrete *> *)getRunningControllers;

/**
* Find a running controller, if any, for the given fabric index.
*/
- (nullable MTRDeviceController *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex;
- (nullable MTRDeviceController_Concrete *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex;

/**
* Find a running controller, if any, for the given fabric index. Allows
* controlling whether to include a controller that is in the middle of startup
* or shutdown.
*/
- (nullable MTRDeviceController *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex
includeControllerStartingUp:(BOOL)includeControllerStartingUp
includeControllerShuttingDown:(BOOL)includeControllerShuttingDown;
- (nullable MTRDeviceController_Concrete *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex
includeControllerStartingUp:(BOOL)includeControllerStartingUp
includeControllerShuttingDown:(BOOL)includeControllerShuttingDown;

/**
* Notify the controller factory that a new operational instance with the given
Expand Down
25 changes: 25 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)deinitFromFactory;

/**
* Check whether this controller is running on the given fabric, as represented
* by the provided FabricTable and fabric index. The provided fabric table may
* not be the same as the fabric table this controller is using. This method
* MUST be called from the Matter work queue.
*
* Might return failure, in which case we don't know whether it's running on the
* given fabric. Otherwise it will set *isRunning to the right boolean value.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (CHIP_ERROR)isRunningOnFabric:(chip::FabricTable *)fabricTable
fabricIndex:(chip::FabricIndex)fabricIndex
isRunning:(BOOL *)isRunning;

/**
* Takes an assertion to keep the controller running. If `-[MTRDeviceController shutdown]` is called while an assertion
* is held, the shutdown will be honored only after all assertions are released. Invoking this method multiple times increases
Expand All @@ -84,6 +99,16 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)removeRunAssertion;

/**
* This method returns TRUE if this controller matches the fabric reference and node ID as listed in the parameters.
*/
- (BOOL)matchesPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate;

/**
* Clear any pending shutdown request.
*/
- (void)clearPendingShutdown;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 30f8451

Please sign in to comment.