Skip to content

Commit

Permalink
Provision: Si917 GFW: DEBUG IN PROGRESS.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcasallas-silabs committed May 20, 2024
1 parent 24e1a5c commit bdfd380
Show file tree
Hide file tree
Showing 32 changed files with 3,881 additions and 3,943 deletions.
3 changes: 3 additions & 0 deletions examples/platform/silabs/provision/ProvisionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ CHIP_ERROR Manager::Init()
// Disable provision mode for next boot
mStore.SetProvisionRequest(false);
}

mProtocol1.SetStore(&mStore);
mProtocol2.SetStore(&mStore);
return CHIP_NO_ERROR;
}

Expand Down
4 changes: 2 additions & 2 deletions examples/platform/silabs/provision/ProvisionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class Manager
public:
Manager():
#ifdef SILABS_PROVISION_PROTOCOL_V1
mProtocol1(mStore),
mProtocol1(&mStore),
#endif
mProtocol2(mStore) {}
mProtocol2(&mStore) {}

CHIP_ERROR Init();
bool Step();
Expand Down
9 changes: 5 additions & 4 deletions examples/platform/silabs/provision/ProvisionProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ class Protocol
/**
* Must hold the header plus complete argument value
*/
Protocol(Storage & store): mStore(store) {}
Protocol(Storage * store): mStore(store) {}
virtual ~Protocol() = default;
virtual bool Execute(ByteSpan & request, MutableByteSpan & response) = 0;
void SetStore(Storage * store) { mStore = store; }

protected:
Storage & mStore;
Storage * mStore = nullptr;
};

//------------------------------------------------------------------------------
Expand All @@ -39,7 +40,7 @@ class Protocol1: public Protocol
public:
static constexpr size_t kVersion = 1;

Protocol1(Storage & store): Protocol(store) {}
Protocol1(Storage * store): Protocol(store) {}
virtual bool Execute(ByteSpan & request, MutableByteSpan & response);
private:
CHIP_ERROR Init(Encoding::Buffer &in, Encoding::Buffer &out);
Expand Down Expand Up @@ -80,7 +81,7 @@ class Protocol2: public Protocol
static constexpr size_t kResponseHeaderSize = 8; // version(1) + command(1) + count(1) + error(4) + size(1)
static_assert(kPackageSizeMax > (kResponseHeaderSize + kChecksumSize));

Protocol2(Storage & store): Protocol(store) {}
Protocol2(Storage * store): Protocol(store) {}
virtual bool Execute(ByteSpan & request, MutableByteSpan & response);
};

Expand Down
74 changes: 37 additions & 37 deletions examples/platform/silabs/provision/ProvisionProtocolV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ CHIP_ERROR Protocol1::Init(Encoding::Buffer &in, Encoding::Buffer &out)
ReturnErrorOnFailure(Encoding::Version1::Decode(in, flash_size));

// Execute
ReturnErrorOnFailure(mStore.Initialize(flash_addr, flash_size));
ReturnErrorOnFailure(mStore.Commit());
ReturnErrorOnFailure(mStore.GetBaseAddress(creds_base_addr));
ReturnErrorOnFailure(mStore->Initialize(flash_addr, flash_size));
ReturnErrorOnFailure(mStore->Commit());
ReturnErrorOnFailure(mStore->GetBaseAddress(creds_base_addr));

// Encode response
Encoding::Version1::Encode(out, (uint32_t)creds_base_addr);
Expand All @@ -126,7 +126,7 @@ CHIP_ERROR Protocol1::GenerateCSR(Encoding::Buffer &in, Encoding::Buffer &out)
// Execute
MutableCharSpan span(csr, sizeof(csr));
CharSpan cn(common_name, common_name_len);
ReturnErrorOnFailure(mStore.GetDeviceAttestationCSR(vendor_id, product_id, cn, span));
ReturnErrorOnFailure(mStore->GetDeviceAttestationCSR(vendor_id, product_id, cn, span));

// Encode response
Encoding::Version1::Encode(out, key_id);
Expand Down Expand Up @@ -159,27 +159,27 @@ CHIP_ERROR Protocol1::Import(Encoding::Buffer &in, Encoding::Buffer &out)
switch(file_id)
{
case kFile_Key:
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kDacKey, data, size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kDacKey, data, size));
break;

case kFile_DAC:
{
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kDacCert, data, size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kDacCert, data, size));
break;
}
case kFile_PAI:
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kPaiCert, data, size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kPaiCert, data, size));
break;

case kFile_CD:
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kCertification, data, size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kCertification, data, size));
break;;

default:
// Unknown file
return CHIP_ERROR_INVALID_ARGUMENT;
}
ReturnErrorOnFailure(mStore.Commit());
ReturnErrorOnFailure(mStore->Commit());

//
// Encode response
Expand Down Expand Up @@ -251,34 +251,34 @@ CHIP_ERROR Protocol1::Setup(Encoding::Buffer &in, Encoding::Buffer &out)
// Execute
//

ReturnErrorOnFailure(mStore.Set(Parameters::ID::kVendorId, (uint16_t*)&vendor_id));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kVendorName, (uint8_t*)vendor_name, vendor_name_size));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kProductId, (uint16_t*)&product_id));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kProductName, (uint8_t*)product_name, product_name_size));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kProductLabel, (uint8_t*)product_label, product_label_size));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kProductUrl, (uint8_t*)product_url, product_url_size));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kPartNumber, (uint8_t*)part_number, part_number_size));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kHwVersion, &hw_version));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kHwVersionStr, (uint8_t*)hw_version_string, hw_version_string_size));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kManufacturingDate, (uint8_t*)manufacturing_date, manufacturing_date_size));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kUniqueId, unique_id, unique_size));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kDiscriminator, discriminator > 0 ? &discriminator : nullptr));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kSpake2pVerifier, (uint8_t*)spake2p_verifier, spake2p_verifier_size));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kSpake2pPasscode, passcode > 0 ? &passcode : nullptr));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kCommissioningFlow, (uint8_t*)&commissioning_flow));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kRendezvousFlags, (uint8_t*)&rendezvous_flags));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kSpake2pIterations, &spake2p_iterations));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kSpake2pSalt, (uint8_t*)spake2p_salt, spake2p_salt_size));
ReturnErrorOnFailure(mStore.Set(Parameters::ID::kSetupPayload, nullptr, 0));
ReturnErrorOnFailure(mStore.Commit());
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kVendorId, (uint16_t*)&vendor_id));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kVendorName, (uint8_t*)vendor_name, vendor_name_size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kProductId, (uint16_t*)&product_id));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kProductName, (uint8_t*)product_name, product_name_size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kProductLabel, (uint8_t*)product_label, product_label_size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kProductUrl, (uint8_t*)product_url, product_url_size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kPartNumber, (uint8_t*)part_number, part_number_size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kHwVersion, &hw_version));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kHwVersionStr, (uint8_t*)hw_version_string, hw_version_string_size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kManufacturingDate, (uint8_t*)manufacturing_date, manufacturing_date_size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kUniqueId, unique_id, unique_size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kDiscriminator, discriminator > 0 ? &discriminator : nullptr));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kSpake2pVerifier, (uint8_t*)spake2p_verifier, spake2p_verifier_size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kSpake2pPasscode, passcode > 0 ? &passcode : nullptr));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kCommissioningFlow, (uint8_t*)&commissioning_flow));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kRendezvousFlags, (uint8_t*)&rendezvous_flags));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kSpake2pIterations, &spake2p_iterations));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kSpake2pSalt, (uint8_t*)spake2p_salt, spake2p_salt_size));
ReturnErrorOnFailure(mStore->Set(Parameters::ID::kSetupPayload, nullptr, 0));
ReturnErrorOnFailure(mStore->Commit());

//
// Encode response
//
ReturnErrorOnFailure(mStore.Get(Parameters::ID::kSpake2pPasscode, passcode));
ReturnErrorOnFailure(mStore.Get(Parameters::ID::kDiscriminator, discriminator));
ReturnErrorOnFailure(mStore.Get(Parameters::ID::kUniqueId, unique_id, sizeof(unique_id), unique_size));
ReturnErrorOnFailure(mStore.Get(Parameters::ID::kSetupPayload, setup_payload, sizeof(setup_payload), setup_payload_size));
ReturnErrorOnFailure(mStore->Get(Parameters::ID::kSpake2pPasscode, passcode));
ReturnErrorOnFailure(mStore->Get(Parameters::ID::kDiscriminator, discriminator));
ReturnErrorOnFailure(mStore->Get(Parameters::ID::kUniqueId, unique_id, sizeof(unique_id), unique_size));
ReturnErrorOnFailure(mStore->Get(Parameters::ID::kSetupPayload, setup_payload, sizeof(setup_payload), setup_payload_size));
Encoding::Version1::Encode(out, passcode);
Encoding::Version1::Encode(out, discriminator);
Encoding::Version1::Encode(out, unique_id, unique_size);
Expand Down Expand Up @@ -308,23 +308,23 @@ CHIP_ERROR Protocol1::Read(Encoding::Buffer &in, Encoding::Buffer &out)
case Encoding::Version1::Type_Int8u:
{
uint8_t value = 0;
err = mStore.Get(id, value);
err = mStore->Get(id, value);
VerifyOrReturnError((CHIP_ERROR_NOT_FOUND == err) || (CHIP_NO_ERROR == err), err);
ReturnErrorOnFailure(Encoding::Version1::Encode(out, value));
break;
}
case Encoding::Version1::Type_Int16u:
{
uint16_t value = 0;
err = mStore.Get(id, value);
err = mStore->Get(id, value);
VerifyOrReturnError((CHIP_ERROR_NOT_FOUND == err) || (CHIP_NO_ERROR == err), err);
ReturnErrorOnFailure(Encoding::Version1::Encode(out, value));
break;
}
case Encoding::Version1::Type_Int32u:
{
uint32_t value = 0;
err = mStore.Get(id, value);
err = mStore->Get(id, value);
VerifyOrReturnError((CHIP_ERROR_NOT_FOUND == err) || (CHIP_NO_ERROR == err), err);
ReturnErrorOnFailure(Encoding::Version1::Encode(out, value));
break;
Expand All @@ -333,7 +333,7 @@ CHIP_ERROR Protocol1::Read(Encoding::Buffer &in, Encoding::Buffer &out)
{
uint8_t *value = Storage::aux_buffer;
size_t size = 0;
err = mStore.Get(id, value, Storage::kArgumentSizeMax, size);
err = mStore->Get(id, value, Storage::kArgumentSizeMax, size);
VerifyOrReturnError((CHIP_ERROR_NOT_FOUND == err) || (CHIP_NO_ERROR == err), err);
ReturnErrorOnFailure(Encoding::Version1::Encode(out, value, size));
break;
Expand Down
46 changes: 25 additions & 21 deletions examples/platform/silabs/provision/ProvisionProtocolV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ enum CommandIds: uint8_t

struct Command
{
Command(uint8_t id, Storage & store): mId(id), mStore(store) {}
Command(uint8_t id, Storage * store): mId(id), mStore(store) {}
virtual ~Command() = default;

CHIP_ERROR Execute(Encoding::Buffer & in, Encoding::Buffer & out)
Expand Down Expand Up @@ -180,15 +180,15 @@ struct Command

virtual CHIP_ERROR EncodeOutgoing(ReadEntry &arg, Argument &out)
{
GenericStorage &store = (arg.is_known ? (GenericStorage &)mStore : (GenericStorage &)mStore.mCustom);
GenericStorage *stx = (arg.is_known ? (GenericStorage *)mStore : (GenericStorage *)&mStore->mCustom);
CHIP_ERROR err = CHIP_NO_ERROR;

switch(arg.type)
{
case Type_Int8u:
{
uint8_t value = 0;
err = store.Get(arg.id, value);
err = mStore->Get(arg.id, value);
VerifyOrReturnError((CHIP_ERROR_NOT_FOUND == err) || (CHIP_NO_ERROR == err), err);
uint8_t *x = (CHIP_ERROR_NOT_FOUND == err) ? nullptr : &value;
ReturnErrorOnFailure(Encode(arg.id, x, out));
Expand All @@ -197,7 +197,7 @@ struct Command
case Type_Int16u:
{
uint16_t value = 0;
err = store.Get(arg.id, value);
err = mStore->Get(arg.id, value);
VerifyOrReturnError((CHIP_ERROR_NOT_FOUND == err) || (CHIP_NO_ERROR == err), err);
uint16_t *x = (CHIP_ERROR_NOT_FOUND == err) ? nullptr : &value;
ReturnErrorOnFailure(Encode(arg.id, x, out));
Expand All @@ -206,7 +206,7 @@ struct Command
case Type_Int32u:
{
uint32_t value = 0;
err = store.Get(arg.id, value);
err = mStore->Get(arg.id, value);
VerifyOrReturnError((CHIP_ERROR_NOT_FOUND == err) || (CHIP_NO_ERROR == err), err);
uint32_t *x = (CHIP_ERROR_NOT_FOUND == err) ? nullptr : &value;
ReturnErrorOnFailure(Encode(arg.id, x, out));
Expand All @@ -216,7 +216,7 @@ struct Command
{
uint8_t *value = Storage::aux_buffer;
size_t size = 0;
err = store.Get(arg.id, value, Storage::kArgumentSizeMax, size);
err = mStore->Get(arg.id, value, Storage::kArgumentSizeMax, size);
VerifyOrReturnError((CHIP_ERROR_NOT_FOUND == err) || (CHIP_NO_ERROR == err), err);
uint8_t *x = (CHIP_ERROR_NOT_FOUND == err) ? nullptr : value;
ReturnErrorOnFailure(Encode(arg.id, x, size, out));
Expand All @@ -230,12 +230,12 @@ struct Command
}

uint8_t mId;
Storage & mStore;
Storage * mStore;
};

struct InitCommand: public Command
{
InitCommand(Storage & store): Command(kCommand_Init, store)
InitCommand(Storage * store): Command(kCommand_Init, store)
{
_incoming.Init(rx_buffer, sizeof(rx_buffer));
_incoming.Reset();
Expand Down Expand Up @@ -277,7 +277,7 @@ struct InitCommand: public Command
case Parameters::kBaseAddress:
{
uint32_t creds_base_addr = 0;
ReturnErrorOnFailure(mStore.GetBaseAddress(creds_base_addr));
ReturnErrorOnFailure(mStore->GetBaseAddress(creds_base_addr));
ReturnErrorOnFailure(Encode(arg.id, &creds_base_addr, out));
break;
}
Expand All @@ -289,7 +289,7 @@ struct InitCommand: public Command

CHIP_ERROR OnPayloadDecoded() override
{
return mStore.Initialize(mFlashAddress, mFlashSize);
return mStore->Initialize(mFlashAddress, mFlashSize);
}

private:
Expand All @@ -299,7 +299,7 @@ struct InitCommand: public Command

struct CsrCommand: public Command
{
CsrCommand(Storage & store): Command(kCommand_Init, store)
CsrCommand(Storage * store): Command(kCommand_Init, store)
{
// Always return CSR file
_feedback_list.Add(Parameters::kCsrFile, Type_Binary);
Expand All @@ -311,24 +311,26 @@ struct CsrCommand: public Command
{
case Parameters::kVendorId:
case Parameters::kProductId:
return mStore.Set(arg.id, &arg.value.u16);
return mStore->Set(arg.id, &arg.value.u16);

case Parameters::kCommonName:
return mStore.Set(arg.id, arg.value.b, arg.size);
return mStore->Set(arg.id, arg.value.b, arg.size);

default:
return CHIP_ERROR_UNKNOWN_RESOURCE_ID;
}
}
};

static size_t _debug = 0;

struct WriteCommand: public Command
{
WriteCommand(Storage & store): Command(kCommand_Write, store) {}
WriteCommand(Storage * store): Command(kCommand_Write, store) {}

CHIP_ERROR ProcessIncoming(Argument &arg) override
{
GenericStorage &store = (arg.is_known ? (GenericStorage &)mStore : (GenericStorage &)mStore.mCustom);
GenericStorage *stx = (arg.is_known ? (GenericStorage *)mStore : (GenericStorage *)&mStore->mCustom);

if(arg.feedback)
{
Expand All @@ -339,17 +341,19 @@ struct WriteCommand: public Command
switch(arg.type)
{
case Type_Int8u:
return store.Set(arg.id, arg.is_null ? nullptr : &arg.value.u8);
return mStore->Set(arg.id, arg.is_null ? nullptr : &arg.value.u8);

case Type_Int16u:
return store.Set(arg.id, arg.is_null ? nullptr : &arg.value.u16);
return mStore->Set(arg.id, arg.is_null ? nullptr : &arg.value.u16);

case Type_Int32u:
return store.Set(arg.id, arg.is_null ? nullptr : &arg.value.u32);
return mStore->Set(arg.id, arg.is_null ? nullptr : &arg.value.u32);

case Type_Binary:
{
return store.Set(arg.id, arg.is_null ? nullptr : arg.value.b, arg.size);
// if(++_debug == 1) return CHIP_ERROR(0x2d000000 + arg.id);
return mStore->Set(arg.id, arg.is_null ? nullptr : arg.value.b, arg.size);
// return CHIP_ERROR(0x3d000000 + (e.AsInteger() & 0xffffff));
}

default:
Expand All @@ -360,15 +364,15 @@ struct WriteCommand: public Command

CHIP_ERROR OnPayloadDecoded() override
{
return this->mStore.Commit();
return this->mStore->Commit();
}

};


struct ReadCommand: public Command
{
ReadCommand(Storage & store): Command(kCommand_Read, store) {}
ReadCommand(Storage * store): Command(kCommand_Read, store) {}

CHIP_ERROR ProcessIncoming(Argument &arg) override
{
Expand Down
Loading

0 comments on commit bdfd380

Please sign in to comment.