Skip to content

Commit 30f8451

Browse files
authored
Merge branch 'master' into bugfix/fix_for_thermostat
2 parents 546f3a0 + fbc0d21 commit 30f8451

23 files changed

+286
-139
lines changed

.github/workflows/darwin.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
framework:
3737
name: Build framework
3838
if: github.actor != 'restyled-io[bot]'
39-
runs-on: macos-13
39+
runs-on: macos-14
4040
strategy:
4141
matrix:
4242
options: # We don't need a full matrix
@@ -73,7 +73,7 @@ jobs:
7373
name: Run framework tests
7474
if: github.actor != 'restyled-io[bot]'
7575
needs: [framework] # serialize to avoid running to many parallel macos runners
76-
runs-on: macos-13
76+
runs-on: macos-14
7777
strategy:
7878
matrix:
7979
options: # We don't need a full matrix

.github/workflows/example-tv-casting-darwin.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
tv-casting-bridge:
3737
name: Build TV Casting Bridge example
3838
if: github.actor != 'restyled-io[bot]'
39-
runs-on: macos-13
39+
runs-on: macos-14
4040
steps:
4141
- name: Checkout
4242
uses: actions/checkout@v4

examples/platform/silabs/provision/ProvisionStorageDefault.cpp

+47-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "AttestationKey.h"
1818
#include "ProvisionStorage.h"
1919
#include <credentials/examples/DeviceAttestationCredsExample.h>
20+
#include <em_device.h>
2021
#include <lib/support/BytesToHex.h>
2122
#include <lib/support/CHIPMemString.h>
2223
#include <lib/support/CodeUtils.h>
@@ -34,7 +35,13 @@
3435
#ifdef SLI_SI91X_MCU_INTERFACE
3536
#include <sl_si91x_common_flash_intf.h>
3637
#else
38+
#ifdef _SILICON_LABS_32B_SERIES_2
3739
#include <em_msc.h>
40+
#elif defined(_SILICON_LABS_32B_SERIES_3)
41+
#include "sl_se_manager.h"
42+
#include "sl_se_manager_types.h"
43+
#include <sl_se_manager_extmem.h>
44+
#endif // _SILICON_LABS_32B_SERIES_2
3845
#include <psa/crypto.h>
3946
#endif
4047

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

54+
#if defined(_SILICON_LABS_32B_SERIES_3)
55+
// To remove any ambiguities regarding the Flash aliases, use the below macro to ignore the 8 MSB.
56+
#define FLASH_GENERIC_MASK 0x00FFFFFF
57+
#define GENERIC_ADDRESS(addr) ((addr) &FLASH_GENERIC_MASK)
58+
59+
// Transforms any address into an address using the same alias as FLASH_BASE from the CMSIS.
60+
#define CMSIS_CONVERTED_ADDRESS(addr) (GENERIC_ADDRESS(addr) | FLASH_BASE)
61+
sl_se_command_context_t cmd_ctx;
62+
#endif // _SILICON_LABS_32B_SERIES_3
63+
4764
extern uint8_t linker_nvm_end[];
4865

4966
using namespace chip::Credentials;
@@ -66,8 +83,18 @@ CHIP_ERROR ErasePage(uint32_t addr)
6683
{
6784
#ifdef SLI_SI91X_MCU_INTERFACE
6885
rsi_flash_erase_sector((uint32_t *) addr);
69-
#else
86+
#elif defined(_SILICON_LABS_32B_SERIES_2)
7087
MSC_ErasePage((uint32_t *) addr);
88+
#elif defined(_SILICON_LABS_32B_SERIES_3)
89+
sl_status_t status;
90+
uint32_t * data_start = NULL;
91+
size_t data_size;
92+
93+
status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
94+
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
95+
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
96+
status = sl_se_data_region_erase(&cmd_ctx, (void *) addr, 1); // Erase one page
97+
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
7198
#endif
7299
return CHIP_NO_ERROR;
73100
}
@@ -76,8 +103,18 @@ CHIP_ERROR WritePage(uint32_t addr, const uint8_t * data, size_t size)
76103
{
77104
#ifdef SLI_SI91X_MCU_INTERFACE
78105
rsi_flash_write((uint32_t *) addr, (unsigned char *) data, size);
79-
#else
106+
#elif defined(_SILICON_LABS_32B_SERIES_2)
80107
MSC_WriteWord((uint32_t *) addr, data, size);
108+
#elif defined(_SILICON_LABS_32B_SERIES_3)
109+
sl_status_t status;
110+
uint32_t * data_start = NULL;
111+
size_t data_size;
112+
113+
status = sl_se_data_region_get_location(&cmd_ctx, (void **) &data_start, &data_size);
114+
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
115+
VerifyOrReturnError(GENERIC_ADDRESS(addr) > GENERIC_ADDRESS((uint32_t) data_start), CHIP_ERROR_INVALID_ADDRESS);
116+
status = sl_se_data_region_write(&cmd_ctx, (void *) addr, data, size);
117+
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR(status));
81118
#endif
82119
return CHIP_NO_ERROR;
83120
}
@@ -161,7 +198,15 @@ CHIP_ERROR Storage::Initialize(uint32_t flash_addr, uint32_t flash_size)
161198
{
162199
#ifndef SLI_SI91X_MCU_INTERFACE
163200
base_addr = (flash_addr + flash_size - FLASH_PAGE_SIZE);
201+
202+
#ifdef _SILICON_LABS_32B_SERIES_2
164203
MSC_Init();
204+
#elif defined(_SILICON_LABS_32B_SERIES_3)
205+
sl_status_t status;
206+
status = sl_se_init();
207+
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
208+
status = sl_se_init_command_context(&cmd_ctx);
209+
#endif // _SILICON_LABS_32B_SERIES
165210
#endif // SLI_SI91X_MCU_INTERFACE
166211
#ifdef SL_PROVISION_GENERATOR
167212
setNvm3End(base_addr);

src/app/icd/server/ICDMonitoringTable.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ CHIP_ERROR ICDMonitoringEntry::Serialize(TLV::TLVWriter & writer) const
5353
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(Fields::kClientType), clientType));
5454

5555
ReturnErrorOnFailure(writer.EndContainer(outer));
56+
ReturnErrorOnFailure(writer.Finalize());
5657
return CHIP_NO_ERROR;
5758
}
5859

src/app/icd/server/ICDMonitoringTable.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,24 @@ using SymmetricKeystore = SessionKeystore;
3434

3535
namespace chip {
3636

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

3953
struct ICDMonitoringEntry : public PersistentData<kICDMonitoringBufferSize>
4054
{
41-
4255
ICDMonitoringEntry(FabricIndex fabric = kUndefinedFabricIndex, NodeId nodeId = kUndefinedNodeId)
4356
{
4457
this->fabricIndex = fabric;

src/app/icd/server/tests/TestICDMonitoringTable.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ constexpr uint64_t kClientNodeId13 = 0x100003;
4343
constexpr uint64_t kClientNodeId21 = 0x200001;
4444
constexpr uint64_t kClientNodeId22 = 0x200002;
4545

46+
constexpr uint64_t kClientNodeMaxValue = std::numeric_limits<uint64_t>::max();
47+
4648
constexpr uint8_t kKeyBuffer0a[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
4749
constexpr uint8_t kKeyBuffer0b[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
4850
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@@ -98,6 +100,20 @@ TEST(TestICDMonitoringTable, TestEntryAssignationOverload)
98100
EXPECT_TRUE(entry2.IsKeyEquivalent(ByteSpan(kKeyBuffer1a)));
99101
}
100102

103+
TEST(TestICDMonitoringTable, TestEntryMaximumSize)
104+
{
105+
TestPersistentStorageDelegate storage;
106+
TestSessionKeystoreImpl keystore;
107+
ICDMonitoringTable table(storage, kTestFabricIndex1, kMaxTestClients1, &keystore);
108+
109+
ICDMonitoringEntry entry(&keystore);
110+
entry.checkInNodeID = kClientNodeMaxValue;
111+
entry.monitoredSubject = kClientNodeMaxValue;
112+
entry.clientType = ClientTypeEnum::kPermanent;
113+
EXPECT_EQ(CHIP_NO_ERROR, entry.SetKey(ByteSpan(kKeyBuffer1a)));
114+
EXPECT_EQ(CHIP_NO_ERROR, table.Set(0, entry));
115+
}
116+
101117
TEST(TestICDMonitoringTable, TestEntryKeyFunctions)
102118
{
103119
TestSessionKeystoreImpl keystore;

src/app/util/attribute-metadata.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818

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

21+
bool EmberAfAttributeMetadata::IsBoolean() const
22+
{
23+
return attributeType == ZCL_BOOLEAN_ATTRIBUTE_TYPE;
24+
}
25+
26+
bool EmberAfAttributeMetadata::IsSignedIntegerAttribute() const
27+
{
28+
return chip::app::IsSignedAttributeType(attributeType);
29+
}
30+
2131
bool emberAfIsStringAttributeType(EmberAfAttributeType attributeType)
2232
{
2333
return (attributeType == ZCL_OCTET_STRING_ATTRIBUTE_TYPE || attributeType == ZCL_CHAR_STRING_ATTRIBUTE_TYPE);

src/app/util/attribute-metadata.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#pragma once
1919

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

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

166165
/**
167166
* Check wether this attribute is signed based on its type according to the spec.
168167
*/
169-
bool IsSignedIntegerAttribute() const { return chip::app::IsSignedAttributeType(attributeType); }
168+
bool IsSignedIntegerAttribute() const;
170169

171170
/**
172171
* Check whether this attribute has a define min and max.

src/darwin/Framework/CHIP/MTRDeviceController.mm

-44
Original file line numberDiff line numberDiff line change
@@ -320,20 +320,6 @@ - (void)_controllerResumed
320320
// Subclass hook; nothing to do.
321321
}
322322

323-
- (BOOL)matchesPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate
324-
{
325-
// TODO: Once the factory knows it's dealing with MTRDeviceController_Concrete, this can be removed, and its
326-
// declaration moved to MTRDeviceController_Concrete.
327-
return NO;
328-
}
329-
330-
- (void)clearPendingShutdown
331-
{
332-
// TODO: Once the factory knows it's dealing with MTRDeviceController_Concrete, this can be removed, and its
333-
// declaration moved to MTRDeviceController_Concrete.
334-
MTR_ABSTRACT_METHOD();
335-
}
336-
337323
- (void)shutdown
338324
{
339325
MTR_ABSTRACT_METHOD();
@@ -1085,36 +1071,6 @@ - (nullable NSNumber *)compressedFabricID
10851071
return storedValue.has_value() ? @(storedValue.value()) : nil;
10861072
}
10871073

1088-
- (CHIP_ERROR)isRunningOnFabric:(chip::FabricTable *)fabricTable
1089-
fabricIndex:(chip::FabricIndex)fabricIndex
1090-
isRunning:(BOOL *)isRunning
1091-
{
1092-
assertChipStackLockedByCurrentThread();
1093-
1094-
if (![self isRunning]) {
1095-
*isRunning = NO;
1096-
return CHIP_NO_ERROR;
1097-
}
1098-
1099-
const chip::FabricInfo * otherFabric = fabricTable->FindFabricWithIndex(fabricIndex);
1100-
if (!otherFabric) {
1101-
// Should not happen...
1102-
return CHIP_ERROR_INCORRECT_STATE;
1103-
}
1104-
1105-
if (_cppCommissioner->GetFabricId() != otherFabric->GetFabricId()) {
1106-
*isRunning = NO;
1107-
return CHIP_NO_ERROR;
1108-
}
1109-
1110-
chip::Crypto::P256PublicKey ourRootPublicKey, otherRootPublicKey;
1111-
ReturnErrorOnFailure(_cppCommissioner->GetRootPublicKey(ourRootPublicKey));
1112-
ReturnErrorOnFailure(fabricTable->FetchRootPubkey(otherFabric->GetFabricIndex(), otherRootPublicKey));
1113-
1114-
*isRunning = (ourRootPublicKey.Matches(otherRootPublicKey));
1115-
return CHIP_NO_ERROR;
1116-
}
1117-
11181074
- (void)invalidateCASESessionForNode:(chip::NodeId)nodeID;
11191075
{
11201076
auto block = ^{

src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm

+4-4
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,9 @@ - (void)controllerShuttingDown:(MTRDeviceController_Concrete *)controller
975975
return [_controllers copy];
976976
}
977977

978-
- (nullable MTRDeviceController *)runningControllerForFabricIndex:(FabricIndex)fabricIndex
979-
includeControllerStartingUp:(BOOL)includeControllerStartingUp
980-
includeControllerShuttingDown:(BOOL)includeControllerShuttingDown
978+
- (nullable MTRDeviceController_Concrete *)runningControllerForFabricIndex:(FabricIndex)fabricIndex
979+
includeControllerStartingUp:(BOOL)includeControllerStartingUp
980+
includeControllerShuttingDown:(BOOL)includeControllerShuttingDown
981981
{
982982
assertChipStackLockedByCurrentThread();
983983

@@ -1006,7 +1006,7 @@ - (nullable MTRDeviceController *)runningControllerForFabricIndex:(FabricIndex)f
10061006
return nil;
10071007
}
10081008

1009-
- (nullable MTRDeviceController *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex
1009+
- (nullable MTRDeviceController_Concrete *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex
10101010
{
10111011
return [self runningControllerForFabricIndex:fabricIndex includeControllerStartingUp:YES includeControllerShuttingDown:YES];
10121012
}

src/darwin/Framework/CHIP/MTRDeviceControllerFactory_Internal.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ MTR_DIRECT_MEMBERS
5757
* Get the list of running controllers. This will include controllers that are
5858
* in the middle of starting up or shutting down.
5959
*/
60-
- (NSArray<MTRDeviceController *> *)getRunningControllers;
60+
- (NSArray<MTRDeviceController_Concrete *> *)getRunningControllers;
6161

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

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

7676
/**
7777
* Notify the controller factory that a new operational instance with the given

src/darwin/Framework/CHIP/MTRDeviceController_Concrete.h

+25
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ NS_ASSUME_NONNULL_BEGIN
7070
*/
7171
- (void)deinitFromFactory;
7272

73+
/**
74+
* Check whether this controller is running on the given fabric, as represented
75+
* by the provided FabricTable and fabric index. The provided fabric table may
76+
* not be the same as the fabric table this controller is using. This method
77+
* MUST be called from the Matter work queue.
78+
*
79+
* Might return failure, in which case we don't know whether it's running on the
80+
* given fabric. Otherwise it will set *isRunning to the right boolean value.
81+
*
82+
* Only MTRDeviceControllerFactory should be calling this.
83+
*/
84+
- (CHIP_ERROR)isRunningOnFabric:(chip::FabricTable *)fabricTable
85+
fabricIndex:(chip::FabricIndex)fabricIndex
86+
isRunning:(BOOL *)isRunning;
87+
7388
/**
7489
* Takes an assertion to keep the controller running. If `-[MTRDeviceController shutdown]` is called while an assertion
7590
* is held, the shutdown will be honored only after all assertions are released. Invoking this method multiple times increases
@@ -84,6 +99,16 @@ NS_ASSUME_NONNULL_BEGIN
8499
*/
85100
- (void)removeRunAssertion;
86101

102+
/**
103+
* This method returns TRUE if this controller matches the fabric reference and node ID as listed in the parameters.
104+
*/
105+
- (BOOL)matchesPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate;
106+
107+
/**
108+
* Clear any pending shutdown request.
109+
*/
110+
- (void)clearPendingShutdown;
111+
87112
@end
88113

89114
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)