Skip to content

Commit

Permalink
The printing of onboarding code spec compliant (#15506)
Browse files Browse the repository at this point in the history
* Generating the long manual pairing code

* Address review comments

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Oct 6, 2023
1 parent f268b7b commit 1703538
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 43 deletions.
8 changes: 8 additions & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ int ChipLinuxAppInit(int argc, char ** argv, OptionSet * customOptions)

PrintOnboardingCodes(LinuxDeviceOptions::GetInstance().payload);

// For testing of manual pairing code with custom commissioning flow
err = GetSetupPayload(LinuxDeviceOptions::GetInstance().payload, rendezvousFlags);
SuccessOrExit(err);

LinuxDeviceOptions::GetInstance().payload.commissioningFlow = chip::CommissioningFlow::kCustom;

PrintOnboardingCodes(LinuxDeviceOptions::GetInstance().payload);

#if defined(PW_RPC_ENABLED)
rpc::Init();
ChipLogProgress(NotSpecified, "PW_RPC initialized.");
Expand Down
39 changes: 0 additions & 39 deletions src/app/server/OnboardingCodesUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@ void PrintOnboardingCodes(const chip::SetupPayload & payload)
{
ChipLogError(AppServer, "Getting manual pairing code failed!");
}

// Hand a copy of the payload to GetLongManualPairingCode.
if (GetLongManualPairingCode(manualPairingCode, chip::SetupPayload(payload)) == CHIP_NO_ERROR)
{
ChipLogProgress(AppServer, "Long manual pairing code: [%s]", manualPairingCode.c_str());
}
else
{
ChipLogError(AppServer, "Getting long manual pairing code failed!");
}
}

#if CHIP_DEVICE_CONFIG_ENABLE_NFC
Expand Down Expand Up @@ -193,35 +183,6 @@ CHIP_ERROR GetManualPairingCode(std::string & aManualPairingCode, chip::Rendezvo
return GetManualPairingCode(aManualPairingCode, payload);
}

CHIP_ERROR GetLongManualPairingCode(std::string & aLongManualPairingCode, chip::RendezvousInformationFlags aRendezvousFlags)
{
chip::SetupPayload payload;

CHIP_ERROR err = GetSetupPayload(payload, aRendezvousFlags);
if (err != CHIP_NO_ERROR)
{
ChipLogProgress(AppServer, "GetSetupPayload() failed: %s", chip::ErrorStr(err));
return err;
}
return GetLongManualPairingCode(aLongManualPairingCode, std::move(payload));
}

CHIP_ERROR GetLongManualPairingCode(std::string & aLongManualPairingCode, chip::SetupPayload && payload)
{
// To get payloadDecimalStringRepresentation to produce a long manual
// pairing code, the commissioning flow in the payload needs to be kCustom.
payload.commissioningFlow = chip::CommissioningFlow::kCustom;

CHIP_ERROR err = chip::ManualSetupPayloadGenerator(payload).payloadDecimalStringRepresentation(aLongManualPairingCode);
if (err != CHIP_NO_ERROR)
{
ChipLogProgress(AppServer, "Generating long manual pairing code failed: %s", chip::ErrorStr(err));
return err;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR GetManualPairingCode(std::string & aManualPairingCode, const chip::SetupPayload & payload)
{
CHIP_ERROR err = chip::ManualSetupPayloadGenerator(payload).payloadDecimalStringRepresentation(aManualPairingCode);
Expand Down
2 changes: 0 additions & 2 deletions src/app/server/OnboardingCodesUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ CHIP_ERROR GetQRCode(std::string & aQRCode, chip::RendezvousInformationFlags aRe
CHIP_ERROR GetQRCode(std::string & aQRCode, const chip::SetupPayload & payload);
CHIP_ERROR GetQRCodeUrl(char * aQRCodeUrl, size_t aUrlMaxSize, const std::string & aQRCode);
CHIP_ERROR GetManualPairingCode(std::string & aManualPairingCode, chip::RendezvousInformationFlags aRendezvousFlags);
CHIP_ERROR GetLongManualPairingCode(std::string & aLongManualPairingCode, chip::RendezvousInformationFlags aRendezvousFlags);
CHIP_ERROR GetLongManualPairingCode(std::string & aLongManualPairingCode, chip::SetupPayload && payload);
CHIP_ERROR GetManualPairingCode(std::string & aManualPairingCode, const chip::SetupPayload & payload);
CHIP_ERROR GetSetupPayload(chip::SetupPayload & aSetupPayload, chip::RendezvousInformationFlags aRendezvousFlags);

Expand Down
4 changes: 2 additions & 2 deletions src/setup_payload/ManualSetupPayloadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static uint32_t chunk1PayloadRepresentation(const PayloadContents & payload)
"Discriminator won't fit");

uint32_t discriminatorChunk = (payload.discriminator >> kDiscriminatorShift) & kDiscriminatorMask;
uint32_t vidPidPresentFlag = payload.commissioningFlow == CommissioningFlow::kCustom ? 1 : 0;
uint32_t vidPidPresentFlag = payload.commissioningFlow != CommissioningFlow::kStandard ? 1 : 0;

uint32_t result = (discriminatorChunk << kManualSetupChunk1DiscriminatorMsbitsPos) |
(vidPidPresentFlag << kManualSetupChunk1VidPidPresentBitPos);
Expand Down Expand Up @@ -115,7 +115,7 @@ CHIP_ERROR ManualSetupPayloadGenerator::payloadDecimalStringRepresentation(Mutab
return CHIP_ERROR_INVALID_ARGUMENT;
}

bool useLongCode = (mPayloadContents.commissioningFlow == CommissioningFlow::kCustom);
bool useLongCode = (mPayloadContents.commissioningFlow != CommissioningFlow::kStandard);

// Add two for the check digit and null terminator.
if ((useLongCode && outBuffer.size() < kManualSetupLongCodeCharLength + 2) ||
Expand Down

0 comments on commit 1703538

Please sign in to comment.