Skip to content

Commit

Permalink
Address Rotating ID issues (#18514)
Browse files Browse the repository at this point in the history
* 4224 Rotating ID issues

* fix CI build when rotating id disabled

* missed comment cleanup

* incorporate feedback
  • Loading branch information
chrisdecenzo authored and pull[bot] committed Feb 14, 2024
1 parent 2326ac8 commit 537538a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CastingServer

private:
static CastingServer * castingServer_;
CastingServer() {}
CastingServer();

bool mInited = false;
TargetVideoPlayerInfo mTargetVideoPlayerInfo;
Expand Down
15 changes: 15 additions & 0 deletions examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ using namespace chip::app::Clusters::ContentLauncher::Commands;

CastingServer * CastingServer::castingServer_ = nullptr;

CastingServer::CastingServer()
{
#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID)
// generate and set a random uniqueId for generating rotatingId
uint8_t rotatingDeviceIdUniqueId[chip::DeviceLayer::ConfigurationManager::kRotatingDeviceIDUniqueIDLength];
for (size_t i = 0; i < sizeof(rotatingDeviceIdUniqueId); i++)
{
rotatingDeviceIdUniqueId[i] = chip::Crypto::GetRandU8();
}

ByteSpan rotatingDeviceIdUniqueIdSpan(rotatingDeviceIdUniqueId);
chip::DeviceLayer::ConfigurationMgr().SetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan);
#endif // CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID)
}

CastingServer * CastingServer::GetInstance()
{
if (castingServer_ == nullptr)
Expand Down
9 changes: 7 additions & 2 deletions src/controller/CommissionerDiscoveryController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
#include <controller/CommissionerDiscoveryController.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/AdditionalDataPayloadGenerator.h>

#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY

Expand All @@ -52,11 +53,15 @@ void CommissionerDiscoveryController::OnUserDirectedCommissioningRequest(UDCClie
mReady = false;
strncpy(mCurrentInstance, state.GetInstanceName(), sizeof(mCurrentInstance));
mPendingConsent = true;
char rotatingDeviceIdHexBuffer[RotatingDeviceId::kHexMaxLength];
Encoding::BytesToUppercaseHexString(state.GetRotatingId(), state.GetRotatingIdLength(), rotatingDeviceIdHexBuffer,
RotatingDeviceId::kHexMaxLength);

ChipLogDetail(Controller,
"------PROMPT USER: %s is requesting permission to cast to this TV, approve? [" ChipLogFormatMEI
"," ChipLogFormatMEI ",%s]",
"," ChipLogFormatMEI ",%s,%s]",
state.GetDeviceName(), ChipLogValueMEI(state.GetVendorId()), ChipLogValueMEI(state.GetProductId()),
state.GetInstanceName());
state.GetInstanceName(), rotatingDeviceIdHexBuffer);
if (mUserPrompter != nullptr)
{
mUserPrompter->PromptForCommissionOKPermission(state.GetVendorId(), state.GetProductId(), state.GetDeviceName());
Expand Down
1 change: 1 addition & 0 deletions src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class ConfigurationManager
// Unique ID is identifier utilized for the rotating device ID calculation purpose as an input key. It is separate identifier
// from the Basic cluster unique ID.
virtual CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) = 0;
virtual CHIP_ERROR SetRotatingDeviceIdUniqueId(const ByteSpan & uniqueIdSpan) = 0;
#endif
virtual CHIP_ERROR GetRegulatoryLocation(uint8_t & location) = 0;
virtual CHIP_ERROR GetCountryCode(char * buf, size_t bufSize, size_t & codeLen) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
CHIP_ERROR GetLifetimeCounter(uint16_t & lifetimeCounter) override;
CHIP_ERROR IncrementLifetimeCounter() override;
CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) override;
CHIP_ERROR SetRotatingDeviceIdUniqueId(const ByteSpan & uniqueIdSpan) override;
#endif
CHIP_ERROR GetFailSafeArmed(bool & val) override;
CHIP_ERROR SetFailSafeArmed(bool val) override;
Expand Down Expand Up @@ -123,6 +124,7 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
protected:
#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID)
chip::LifetimePersistedCounter<uint32_t> mLifetimePersistedCounter;
uint8_t mRotatingDeviceIdUniqueId[kRotatingDeviceIDUniqueIDLength] = CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID;
#endif

#if CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER
Expand Down
18 changes: 12 additions & 6 deletions src/include/platform/internal/GenericConfigurationManagerImpl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -638,17 +638,23 @@ CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::IncrementLifetimeCounte
return mLifetimePersistedCounter.Advance();
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::SetRotatingDeviceIdUniqueId(const ByteSpan & uniqueIdSpan)
{
ReturnErrorCodeIf(uniqueIdSpan.size() != kRotatingDeviceIDUniqueIDLength, CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(mRotatingDeviceIdUniqueId, uniqueIdSpan.data(), kRotatingDeviceIDUniqueIDLength);
return CHIP_NO_ERROR;
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan)
{
static_assert(kRotatingDeviceIDUniqueIDLength >= kMinRotatingDeviceIDUniqueIDLength,
"Length of unique ID for rotating device ID is smaller than minimum.");
constexpr uint8_t uniqueId[] = CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID;

ReturnErrorCodeIf(sizeof(uniqueId) > uniqueIdSpan.size(), CHIP_ERROR_BUFFER_TOO_SMALL);
ReturnErrorCodeIf(sizeof(uniqueId) != kRotatingDeviceIDUniqueIDLength, CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(uniqueIdSpan.data(), uniqueId, sizeof(uniqueId));
uniqueIdSpan = uniqueIdSpan.SubSpan(0, sizeof(uniqueId));
ReturnErrorCodeIf(sizeof(mRotatingDeviceIdUniqueId) > uniqueIdSpan.size(), CHIP_ERROR_BUFFER_TOO_SMALL);
ReturnErrorCodeIf(sizeof(mRotatingDeviceIdUniqueId) != kRotatingDeviceIDUniqueIDLength, CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(uniqueIdSpan.data(), mRotatingDeviceIdUniqueId, sizeof(mRotatingDeviceIdUniqueId));
uniqueIdSpan = uniqueIdSpan.SubSpan(0, sizeof(mRotatingDeviceIdUniqueId));
return CHIP_NO_ERROR;
}
#endif // CHIP_ENABLE_ROTATING_DEVICE_ID
Expand Down

0 comments on commit 537538a

Please sign in to comment.