Skip to content

Commit

Permalink
[cli] support Thread Administrator Passcode configuration (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
librasungirl authored Apr 12, 2024
1 parent 9f1b740 commit 0d6cfcc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/app/cli/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ const std::map<std::string, Interpreter::Evaluator> &Interpreter::mEvaluatorMap
};

const std::map<std::string, std::string> &Interpreter::mUsageMap = *new std::map<std::string, std::string>{
{"config", "config get pskc\n"
{"config", "config get admincode\n"
"config set admincode <9-digits-thread-administrator-passcode>\n"
"config get pskc\n"
"config set pskc <pskc-hex-string>"},
{"start", "start <border-agent-addr> <border-agent-port>\n"
"start [ --nwk <network-alias-list | --dom <domain-alias>]"},
Expand Down Expand Up @@ -912,17 +914,33 @@ Interpreter::Value Interpreter::ProcessConfig(const Expression &aExpr)
Value value;

VerifyOrExit(aExpr.size() >= 3, value = ERROR_INVALID_ARGS(SYNTAX_FEW_ARGS));
VerifyOrExit(aExpr[2] == "pskc", value = ERROR_INVALID_ARGS("{} is not a valid property", aExpr[2]));
VerifyOrExit(aExpr[2] == "pskc" || aExpr[2] == "admincode",
value = ERROR_INVALID_ARGS("{} is not a valid property", aExpr[2]));
if (aExpr[1] == "get")
{
if (aExpr[2] == "admincode")
{
ExitNow(value = mThreadAdministratorPasscode);
}

value = mJobManager->GetDefaultConfigPSKc();
}
else if (aExpr[1] == "set")
{
ByteArray pskc;

VerifyOrExit(aExpr.size() >= 4, value = ERROR_INVALID_ARGS(SYNTAX_FEW_ARGS));
SuccessOrExit(value = utils::Hex(pskc, aExpr[3]));
if (aExpr[2] == "admincode")
{
mThreadAdministratorPasscode = aExpr[3];

// TODO(rongli@): add len and last digit check per SPEC-1216v11
pskc.assign(mThreadAdministratorPasscode.begin(), mThreadAdministratorPasscode.end());
}
else
{
SuccessOrExit(value = utils::Hex(pskc, aExpr[3]));
}
SuccessOrExit(value = mJobManager->UpdateDefaultConfigPSKc(pskc));
}
else
Expand Down
5 changes: 3 additions & 2 deletions src/app/cli/interpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ class Interpreter
static std::string BaAvailabilityToString(uint32_t aAvailability);

private:
std::shared_ptr<JobManager> mJobManager = nullptr;
std::shared_ptr<Registry> mRegistry = nullptr;
std::shared_ptr<JobManager> mJobManager = nullptr;
std::shared_ptr<Registry> mRegistry = nullptr;
std::string mThreadAdministratorPasscode = "";

bool mShouldExit = false;

Expand Down

0 comments on commit 0d6cfcc

Please sign in to comment.