-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chip-tool] Add commands to generate/update onboarding payloads (#16704)
* [Payload] Add SetAllowInvalidPayload and SetForceShortCode methods to QRCodeSetupPayloadGenerator and ManualSetupPayloadGenerator * [chip-tool] Add a command to generate/update a qrcode and a command to generate/update a manual code
- Loading branch information
1 parent
1c03d9c
commit 6c692ab
Showing
8 changed files
with
222 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
examples/chip-tool/commands/payload/SetupPayloadGenerateCommand.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#include "SetupPayloadGenerateCommand.h" | ||
#include <setup_payload/ManualSetupPayloadGenerator.h> | ||
#include <setup_payload/ManualSetupPayloadParser.h> | ||
#include <setup_payload/QRCodeSetupPayloadGenerator.h> | ||
#include <setup_payload/QRCodeSetupPayloadParser.h> | ||
#include <setup_payload/SetupPayload.h> | ||
|
||
using namespace ::chip; | ||
|
||
void SetupPayloadGenerateCommand::ConfigurePayload(SetupPayload & payload) | ||
{ | ||
if (mDiscriminator.HasValue()) | ||
{ | ||
payload.discriminator = mDiscriminator.Value(); | ||
} | ||
|
||
if (mSetUpPINCode.HasValue()) | ||
{ | ||
payload.setUpPINCode = mSetUpPINCode.Value(); | ||
} | ||
|
||
if (mVersion.HasValue()) | ||
{ | ||
payload.version = mVersion.Value(); | ||
} | ||
|
||
if (mVendorId.HasValue()) | ||
{ | ||
payload.vendorID = mVendorId.Value(); | ||
} | ||
|
||
if (mProductId.HasValue()) | ||
{ | ||
payload.productID = mProductId.Value(); | ||
} | ||
|
||
if (mCommissioningMode.HasValue()) | ||
{ | ||
payload.commissioningFlow = static_cast<CommissioningFlow>(mCommissioningMode.Value()); | ||
} | ||
} | ||
|
||
CHIP_ERROR SetupPayloadGenerateQRCodeCommand::Run() | ||
{ | ||
SetupPayload payload; | ||
|
||
if (mPayload.HasValue()) | ||
{ | ||
QRCodeSetupPayloadParser(mPayload.Value()).populatePayload(payload); | ||
} | ||
|
||
ConfigurePayload(payload); | ||
|
||
if (mRendezvous.HasValue()) | ||
{ | ||
payload.rendezvousInformation.SetRaw(mRendezvous.Value()); | ||
} | ||
|
||
QRCodeSetupPayloadGenerator generator(payload); | ||
generator.SetAllowInvalidPayload(mAllowInvalidPayload.ValueOr(false)); | ||
|
||
std::string code; | ||
ReturnErrorOnFailure(generator.payloadBase38Representation(code)); | ||
ChipLogProgress(chipTool, "QR Code: %s", code.c_str()); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR SetupPayloadGenerateManualCodeCommand::Run() | ||
{ | ||
SetupPayload payload; | ||
|
||
if (mPayload.HasValue()) | ||
{ | ||
ManualSetupPayloadParser(mPayload.Value()).populatePayload(payload); | ||
} | ||
|
||
ConfigurePayload(payload); | ||
|
||
ManualSetupPayloadGenerator generator(payload); | ||
generator.SetAllowInvalidPayload(mAllowInvalidPayload.ValueOr(false)); | ||
generator.SetForceShortCode(mForceShortCode.ValueOr(false)); | ||
|
||
std::string code; | ||
ReturnErrorOnFailure(generator.payloadDecimalStringRepresentation(code)); | ||
ChipLogProgress(chipTool, "Manual Code: %s", code.c_str()); | ||
|
||
return CHIP_NO_ERROR; | ||
} |
76 changes: 76 additions & 0 deletions
76
examples/chip-tool/commands/payload/SetupPayloadGenerateCommand.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "../common/Command.h" | ||
#include <setup_payload/SetupPayload.h> | ||
|
||
class SetupPayloadGenerateCommand : public Command | ||
{ | ||
public: | ||
SetupPayloadGenerateCommand(const char * name) : Command(name) | ||
{ | ||
AddArgument("payload", &mPayload); | ||
AddArgument("discriminator", 0, UINT16_MAX, &mDiscriminator); | ||
AddArgument("setup-pin-code", 0, UINT32_MAX, &mSetUpPINCode); | ||
AddArgument("version", 0, UINT8_MAX, &mVersion); | ||
AddArgument("vendor-id", 0, UINT16_MAX, &mVendorId); | ||
AddArgument("product-id", 0, UINT16_MAX, &mProductId); | ||
AddArgument("commissioning-mode", 0, UINT8_MAX, &mCommissioningMode); | ||
AddArgument("allow-invalid-payload", 0, 1, &mAllowInvalidPayload); | ||
} | ||
|
||
protected: | ||
void ConfigurePayload(chip::SetupPayload & payload); | ||
|
||
chip::Optional<uint16_t> mDiscriminator; | ||
chip::Optional<uint32_t> mSetUpPINCode; | ||
chip::Optional<uint8_t> mVersion; | ||
chip::Optional<uint16_t> mVendorId; | ||
chip::Optional<uint16_t> mProductId; | ||
chip::Optional<char *> mPayload; | ||
chip::Optional<uint8_t> mCommissioningMode; | ||
chip::Optional<bool> mAllowInvalidPayload; | ||
}; | ||
|
||
class SetupPayloadGenerateQRCodeCommand : public SetupPayloadGenerateCommand | ||
{ | ||
public: | ||
SetupPayloadGenerateQRCodeCommand() : SetupPayloadGenerateCommand("generate-qrcode") | ||
{ | ||
AddArgument("rendezvous", 0, UINT8_MAX, &mRendezvous); | ||
} | ||
CHIP_ERROR Run() override; | ||
|
||
private: | ||
chip::Optional<uint8_t> mRendezvous; | ||
}; | ||
|
||
class SetupPayloadGenerateManualCodeCommand : public SetupPayloadGenerateCommand | ||
{ | ||
public: | ||
SetupPayloadGenerateManualCodeCommand() : SetupPayloadGenerateCommand("generate-manualcode") | ||
{ | ||
AddArgument("force-short-code", 0, 1, &mForceShortCode); | ||
} | ||
CHIP_ERROR Run() override; | ||
|
||
private: | ||
chip::Optional<bool> mForceShortCode; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters