mirror of
https://github.com/espressif/openthread.git
synced 2026-07-26 22:09:05 +00:00
add cli promiscuous (#445)
This commit is contained in:
committed by
Jonathan Hui
parent
b5f97386ba
commit
20014c72bf
+102
@@ -81,6 +81,7 @@ const struct Command Interpreter::sCommands[] =
|
||||
{ "parent", &ProcessParent },
|
||||
{ "ping", &ProcessPing },
|
||||
{ "pollperiod", &ProcessPollPeriod },
|
||||
{ "promiscuous", &ProcessPromiscuous },
|
||||
{ "prefix", &ProcessPrefix },
|
||||
{ "releaserouterid", &ProcessReleaseRouterId },
|
||||
{ "reset", &ProcessReset },
|
||||
@@ -1058,6 +1059,107 @@ exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
|
||||
void Interpreter::ProcessPromiscuous(int argc, char *argv[])
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
if (otIsLinkPromiscuous() && otPlatRadioGetPromiscuous())
|
||||
{
|
||||
sServer->OutputFormat("Enabled\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sServer->OutputFormat("Disabled\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(argv[0], "enable") == 0)
|
||||
{
|
||||
otSetLinkPcapCallback(&HandleLinkPcapReceive, NULL);
|
||||
SuccessOrExit(error = otSetLinkPromiscuous(true));
|
||||
}
|
||||
else if (strcmp(argv[0], "disable") == 0)
|
||||
{
|
||||
otSetLinkPcapCallback(NULL, NULL);
|
||||
SuccessOrExit(error = otSetLinkPromiscuous(false));
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
|
||||
void Interpreter::HandleLinkPcapReceive(const RadioPacket *aFrame, void *aContext)
|
||||
{
|
||||
sServer->OutputFormat("\r\n");
|
||||
|
||||
for (size_t i = 0; i < 44; i++)
|
||||
{
|
||||
sServer->OutputFormat("=");
|
||||
}
|
||||
|
||||
sServer->OutputFormat("[len = %3u]", aFrame->mLength);
|
||||
|
||||
for (size_t i = 0; i < 28; i++)
|
||||
{
|
||||
sServer->OutputFormat("=");
|
||||
}
|
||||
|
||||
sServer->OutputFormat("\r\n");
|
||||
|
||||
for (size_t i = 0; i < aFrame->mLength; i += 16)
|
||||
{
|
||||
sServer->OutputFormat("|");
|
||||
|
||||
for (size_t j = 0; j < 16; j++)
|
||||
{
|
||||
if (i + j < aFrame->mLength)
|
||||
{
|
||||
sServer->OutputFormat(" %02X", aFrame->mPsdu[i + j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sServer->OutputFormat(" ..");
|
||||
}
|
||||
}
|
||||
|
||||
sServer->OutputFormat("|");
|
||||
|
||||
for (size_t j = 0; j < 16; j++)
|
||||
{
|
||||
if (i + j < aFrame->mLength)
|
||||
{
|
||||
if (31 < aFrame->mPsdu[i + j] && aFrame->mPsdu[i + j] < 127)
|
||||
{
|
||||
sServer->OutputFormat(" %c", aFrame->mPsdu[i + j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sServer->OutputFormat(" ?");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sServer->OutputFormat(" .");
|
||||
}
|
||||
}
|
||||
|
||||
sServer->OutputFormat("|\r\n");
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 83; i++)
|
||||
{
|
||||
sServer->OutputFormat("-");
|
||||
}
|
||||
|
||||
sServer->OutputFormat("\r\n");
|
||||
|
||||
(void) aContext;
|
||||
}
|
||||
|
||||
ThreadError Interpreter::ProcessPrefixAdd(int argc, char *argv[])
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
Reference in New Issue
Block a user