[cli] add cli commands to set unsecure port and link security (#5349)

This commit is contained in:
Zhanglong Xia
2020-08-11 09:28:55 -07:00
committed by GitHub
parent ecd9436427
commit 9af8fe8cc5
8 changed files with 252 additions and 10 deletions
+40 -10
View File
@@ -45,12 +45,17 @@ using ot::Encoding::BigEndian::HostSwap16;
namespace ot {
namespace Cli {
const struct UdpExample::Command UdpExample::sCommands[] = {
{"help", &UdpExample::ProcessHelp}, {"bind", &UdpExample::ProcessBind}, {"close", &UdpExample::ProcessClose},
{"connect", &UdpExample::ProcessConnect}, {"open", &UdpExample::ProcessOpen}, {"send", &UdpExample::ProcessSend}};
const struct UdpExample::Command UdpExample::sCommands[] = {{"help", &UdpExample::ProcessHelp},
{"bind", &UdpExample::ProcessBind},
{"close", &UdpExample::ProcessClose},
{"connect", &UdpExample::ProcessConnect},
{"linksecurity", &UdpExample::ProcessLinkSecurity},
{"open", &UdpExample::ProcessOpen},
{"send", &UdpExample::ProcessSend}};
UdpExample::UdpExample(Interpreter &aInterpreter)
: mInterpreter(aInterpreter)
, mLinkSecurityEnabled(true)
{
memset(&mSocket, 0, sizeof(mSocket));
}
@@ -134,12 +139,13 @@ otError UdpExample::ProcessOpen(uint8_t aArgsLength, char *aArgs[])
otError UdpExample::ProcessSend(uint8_t aArgsLength, char *aArgs[])
{
otError error = OT_ERROR_NONE;
otMessageInfo messageInfo;
otMessage * message = nullptr;
uint8_t curArg = 0;
uint16_t payloadLength = 0;
PayloadType payloadType = kTypeText;
otError error = OT_ERROR_NONE;
otMessageInfo messageInfo;
otMessage * message = nullptr;
uint8_t curArg = 0;
uint16_t payloadLength = 0;
PayloadType payloadType = kTypeText;
otMessageSettings messageSettings = {mLinkSecurityEnabled, OT_MESSAGE_PRIORITY_NORMAL};
memset(&messageInfo, 0, sizeof(messageInfo));
@@ -179,7 +185,7 @@ otError UdpExample::ProcessSend(uint8_t aArgsLength, char *aArgs[])
}
}
message = otUdpNewMessage(mInterpreter.mInstance, nullptr);
message = otUdpNewMessage(mInterpreter.mInstance, &messageSettings);
VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS);
switch (payloadType)
@@ -230,6 +236,30 @@ exit:
return error;
}
otError UdpExample::ProcessLinkSecurity(uint8_t aArgsLength, char *aArgs[])
{
otError error = OT_ERROR_NONE;
if (aArgsLength == 0)
{
mInterpreter.mServer->OutputFormat("%s\r\n", mLinkSecurityEnabled ? "Enabled" : "Disabled");
}
else if (strcmp(aArgs[0], "enable") == 0)
{
mLinkSecurityEnabled = true;
}
else if (strcmp(aArgs[0], "disable") == 0)
{
mLinkSecurityEnabled = false;
}
else
{
error = OT_ERROR_INVALID_COMMAND;
}
return error;
}
otError UdpExample::WriteCharToBuffer(otMessage *aMessage, uint16_t aMessageSize)
{
otError error = OT_ERROR_NONE;