Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address Rotating ID issues #18514

Merged
merged 4 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 13 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,19 @@ using namespace chip::app::Clusters::ContentLauncher::Commands;

CastingServer * CastingServer::castingServer_ = nullptr;

CastingServer::CastingServer()
{
// 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();
}

MutableByteSpan rotatingDeviceIdUniqueIdSpan(rotatingDeviceIdUniqueId);
chrisdecenzo marked this conversation as resolved.
Show resolved Hide resolved
chip::DeviceLayer::ConfigurationMgr().SetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan);
}

CastingServer * CastingServer::GetInstance()
{
if (castingServer_ == nullptr)
Expand Down
10 changes: 8 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,16 @@ void CommissionerDiscoveryController::OnUserDirectedCommissioningRequest(UDCClie
mReady = false;
strncpy(mCurrentInstance, state.GetInstanceName(), sizeof(mCurrentInstance));
mPendingConsent = true;
// TODO: print rotating ID
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved
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(MutableByteSpan & 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(MutableByteSpan & 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(MutableByteSpan & uniqueIdSpan)
chrisdecenzo marked this conversation as resolved.
Show resolved Hide resolved
{
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