Skip to content

Commit

Permalink
[SVE][ICD] Bump MaxICDMonitoringEntrySize to reasonable size (project…
Browse files Browse the repository at this point in the history
…-chip#35737)

* Fix icd monitor entry size

* Restyled by whitespace

* Restyled by clang-format

* port test from pr 35734

* update documentation

* Update src/app/icd/server/ICDMonitoringTable.h

Co-authored-by: Boris Zbarsky <[email protected]>

---------

Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
3 people authored Sep 24, 2024
1 parent 8f80f98 commit f6e34f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
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

0 comments on commit f6e34f4

Please sign in to comment.