Skip to content

Commit

Permalink
Revert "[ICD] Store UserActiveModeTriggerHint and instruction into IC…
Browse files Browse the repository at this point in the history
…D storage (project-chip#30770)"

This reverts commit d809f32.
  • Loading branch information
yunhanw-google committed Dec 6, 2023
1 parent f6ae79d commit c48baa0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 74 deletions.
32 changes: 2 additions & 30 deletions src/app/icd/client/DefaultICDClientStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,27 +258,8 @@ CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vector<IC
ReturnErrorOnFailure(reader.Next(TLV::ContextTag(ClientInfoTag::kMonitoredSubject)));
ReturnErrorOnFailure(reader.Get(clientInfo.monitored_subject));

// UserActiveModeTriggerHint
ReturnErrorOnFailure(reader.Next(TLV::ContextTag(ClientInfoTag::kUserActiveModeTriggerHint)));
ReturnErrorOnFailure(reader.Get(clientInfo.user_active_mode_trigger_hint));

// UserActiveModeTriggerInstruction
ReturnErrorOnFailure(reader.Next());
err = reader.Expect(TLV::ContextTag(ClientInfoTag::kUserActiveModeTriggerInstruction));
if (err == CHIP_NO_ERROR)
{
ReturnErrorOnFailure(
reader.GetString(clientInfo.user_active_mode_trigger_instruction, kUserActiveModeTriggerInstructionSize));
clientInfo.has_instruction = true;
// Shared key
ReturnErrorOnFailure(reader.Next(TLV::ContextTag(ClientInfoTag::kSharedKey)));
}
else if (err == CHIP_ERROR_UNEXPECTED_TLV_ELEMENT)
{
err = reader.Expect(TLV::ContextTag(ClientInfoTag::kSharedKey));
}
ReturnErrorOnFailure(err);

// Shared key
ReturnErrorOnFailure(reader.Next(TLV::ContextTag(ClientInfoTag::kSharedKey)));
ByteSpan buf;
ReturnErrorOnFailure(reader.Get(buf));
VerifyOrReturnError(buf.size() == sizeof(Crypto::Symmetric128BitsKeyByteArray), CHIP_ERROR_INTERNAL);
Expand Down Expand Up @@ -325,15 +306,6 @@ CHIP_ERROR DefaultICDClientStorage::SerializeToTlv(TLV::TLVWriter & writer, cons
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kStartICDCounter), clientInfo.start_icd_counter));
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kOffset), clientInfo.offset));
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kMonitoredSubject), clientInfo.monitored_subject));
ReturnErrorOnFailure(
writer.Put(TLV::ContextTag(ClientInfoTag::kUserActiveModeTriggerHint), clientInfo.user_active_mode_trigger_hint));
if (clientInfo.has_instruction)
{
ReturnErrorOnFailure(writer.PutString(TLV::ContextTag(ClientInfoTag::kUserActiveModeTriggerInstruction),
clientInfo.user_active_mode_trigger_instruction,
static_cast<uint32_t>(strlen(clientInfo.user_active_mode_trigger_instruction))));
}

ByteSpan buf(clientInfo.shared_key.As<Crypto::Symmetric128BitsKeyByteArray>());
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kSharedKey), buf));
ReturnErrorOnFailure(writer.EndContainer(ICDClientInfoContainerType));
Expand Down
17 changes: 7 additions & 10 deletions src/app/icd/client/DefaultICDClientStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,12 @@ class DefaultICDClientStorage : public ICDClientStorage
protected:
enum class ClientInfoTag : uint8_t
{
kPeerNodeId = 1,
kFabricIndex = 2,
kStartICDCounter = 3,
kOffset = 4,
kMonitoredSubject = 5,
kUserActiveModeTriggerHint = 6,
kUserActiveModeTriggerInstruction = 7,
kSharedKey = 8
kPeerNodeId = 1,
kFabricIndex = 2,
kStartICDCounter = 3,
kOffset = 4,
kMonitoredSubject = 5,
kSharedKey = 6
};

enum class CounterTag : uint8_t
Expand Down Expand Up @@ -106,8 +104,7 @@ class DefaultICDClientStorage : public ICDClientStorage
{
// All the fields added together
return TLV::EstimateStructOverhead(sizeof(NodeId), sizeof(FabricIndex), sizeof(uint32_t), sizeof(uint32_t),
sizeof(uint64_t), sizeof(uint32_t), kUserActiveModeTriggerInstructionSize,
sizeof(Crypto::Symmetric128BitsKeyByteArray));
sizeof(uint64_t), sizeof(Crypto::Symmetric128BitsKeyByteArray));
}

static constexpr size_t MaxICDCounterSize()
Expand Down
30 changes: 8 additions & 22 deletions src/app/icd/client/ICDClientInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,26 @@
#include <lib/support/CodeUtils.h>
#include <stddef.h>

namespace {
constexpr size_t kUserActiveModeTriggerInstructionSize = 128;
} // namespace

namespace chip {
namespace app {

struct ICDClientInfo
{
ScopedNodeId peer_node;
uint32_t start_icd_counter = 0;
uint32_t offset = 0;
uint64_t monitored_subject = static_cast<uint64_t>(0);
uint32_t user_active_mode_trigger_hint = 0;
char user_active_mode_trigger_instruction[kUserActiveModeTriggerInstructionSize] = { 0 };
bool has_instruction = false;
Crypto::Aes128BitsKeyHandle shared_key = Crypto::Aes128BitsKeyHandle();
uint32_t start_icd_counter = 0;
uint32_t offset = 0;
uint64_t monitored_subject = static_cast<uint64_t>(0);
Crypto::Aes128BitsKeyHandle shared_key = Crypto::Aes128BitsKeyHandle();

ICDClientInfo() {}
ICDClientInfo(const ICDClientInfo & other) { *this = other; }

ICDClientInfo & operator=(const ICDClientInfo & other)
{
peer_node = other.peer_node;
start_icd_counter = other.start_icd_counter;
offset = other.offset;
monitored_subject = other.monitored_subject;
user_active_mode_trigger_hint = other.user_active_mode_trigger_hint;
if (other.has_instruction)
{
memcpy(user_active_mode_trigger_instruction, other.user_active_mode_trigger_instruction,
kUserActiveModeTriggerInstructionSize);
}
has_instruction = other.has_instruction;
peer_node = other.peer_node;
start_icd_counter = other.start_icd_counter;
offset = other.offset;
monitored_subject = other.monitored_subject;
ByteSpan buf(other.shared_key.As<Crypto::Symmetric128BitsKeyByteArray>());
memcpy(shared_key.AsMutable<Crypto::Symmetric128BitsKeyByteArray>(), buf.data(),
sizeof(Crypto::Symmetric128BitsKeyByteArray));
Expand Down
16 changes: 4 additions & 12 deletions src/app/tests/TestDefaultICDClientStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,11 @@ void TestClientInfoCount(nlTestSuite * apSuite, void * apContext)
// Write some ClientInfos and see the counts are correct
ICDClientInfo clientInfo1;
clientInfo1.peer_node = ScopedNodeId(nodeId1, fabricId);
char val[5] = "test";
ICDClientInfo clientInfo2;
clientInfo2.peer_node = ScopedNodeId(nodeId2, fabricId);
clientInfo2.user_active_mode_trigger_hint = 1;
memcpy(clientInfo2.user_active_mode_trigger_instruction, val, sizeof(val));
clientInfo2.has_instruction = true;
clientInfo2.peer_node = ScopedNodeId(nodeId2, fabricId);
ICDClientInfo clientInfo3;
clientInfo3.peer_node = ScopedNodeId(nodeId1, fabricId);
clientInfo3.user_active_mode_trigger_hint = 2;
err = manager.SetKey(clientInfo1, ByteSpan(kKeyBuffer1));
clientInfo3.peer_node = ScopedNodeId(nodeId1, fabricId);
err = manager.SetKey(clientInfo1, ByteSpan(kKeyBuffer1));
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
err = manager.StoreEntry(clientInfo1);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
Expand All @@ -105,12 +100,9 @@ void TestClientInfoCount(nlTestSuite * apSuite, void * apContext)

NL_TEST_ASSERT(apSuite, iterator->Next(clientInfo));
NL_TEST_ASSERT(apSuite, clientInfo.peer_node.GetNodeId() == nodeId2);
NL_TEST_ASSERT(apSuite, clientInfo.has_instruction);
NL_TEST_ASSERT(apSuite, strcmp(clientInfo.user_active_mode_trigger_instruction, val) == 0);
NL_TEST_ASSERT(apSuite, iterator->Next(clientInfo));
NL_TEST_ASSERT(apSuite, clientInfo.peer_node.GetNodeId() == nodeId1);
NL_TEST_ASSERT(apSuite, clientInfo.user_active_mode_trigger_hint == 2);
NL_TEST_ASSERT(apSuite, !clientInfo.has_instruction);

iterator->Release();

// Delete all and verify iterator counts 0
Expand Down

0 comments on commit c48baa0

Please sign in to comment.