mirror of
https://github.com/espressif/openthread.git
synced 2026-09-05 16:50:05 +00:00
add cli promiscuous (#445)
This commit is contained in:
committed by
Jonathan Hui
parent
b5f97386ba
commit
20014c72bf
@@ -33,6 +33,7 @@ OpenThread test scripts use the CLI to execute test cases.
|
||||
* [ping](#ping)
|
||||
* [pollperiod](#pollperiod)
|
||||
* [prefix](#prefix)
|
||||
* [promiscuous](#promiscuous)
|
||||
* [releaserouterid](#releaserouterid)
|
||||
* [reset](#reset)
|
||||
* [rloc16](#rloc16)
|
||||
@@ -613,6 +614,34 @@ Invalidate a prefix in the Network Data.
|
||||
Done
|
||||
```
|
||||
|
||||
### promiscuous
|
||||
|
||||
Get radio promiscuous property.
|
||||
|
||||
```bash
|
||||
> promiscuous
|
||||
Disabled
|
||||
Done
|
||||
```
|
||||
|
||||
### promiscuous enable
|
||||
|
||||
Enable radio promiscuous operation and print raw packet content.
|
||||
|
||||
```bash
|
||||
> promiscuous enable
|
||||
Done
|
||||
```
|
||||
|
||||
### promiscuous disable
|
||||
|
||||
Disable radio promiscuous operation.
|
||||
|
||||
```bash
|
||||
> promiscuous disable
|
||||
Done
|
||||
```
|
||||
|
||||
### releaserouterid \<routerid\>
|
||||
Release a Router ID that has been allocated by the device in the Leader role.
|
||||
|
||||
|
||||
+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;
|
||||
|
||||
@@ -163,6 +163,7 @@ private:
|
||||
static ThreadError ProcessPrefixAdd(int argc, char *argv[]);
|
||||
static ThreadError ProcessPrefixRemove(int argc, char *argv[]);
|
||||
static ThreadError ProcessPrefixList(void);
|
||||
static void ProcessPromiscuous(int argc, char *argv[]);
|
||||
static void ProcessReleaseRouterId(int argc, char *argv[]);
|
||||
static void ProcessReset(int argc, char *argv[]);
|
||||
static void ProcessRoute(int argc, char *argv[]);
|
||||
@@ -187,6 +188,7 @@ private:
|
||||
static void HandlePingTimer(void *aContext);
|
||||
static void HandleActiveScanResult(otActiveScanResult *aResult, void *aContext);
|
||||
static void HandleNetifStateChanged(uint32_t aFlags, void *aContext);
|
||||
static void HandleLinkPcapReceive(const RadioPacket *aFrame, void *aContext);
|
||||
|
||||
static const struct Command sCommands[];
|
||||
static otNetifAddress sAddress;
|
||||
|
||||
@@ -79,7 +79,7 @@ private:
|
||||
enum
|
||||
{
|
||||
kRxBufferSize = 128,
|
||||
kTxBufferSize = 512,
|
||||
kTxBufferSize = 1024,
|
||||
kMaxLineLength = 128,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user