mirror of
https://github.com/espressif/openthread.git
synced 2026-07-08 13:20:25 +00:00
IP: Add API to subscribe/unsubscribe to multicast addresses. (#899)
* IP: Add API to subscribe/unsubscribe to multicast addresses. * CLI: Add commands to handle multicast addresses.
This commit is contained in:
committed by
Jonathan Hui
parent
30c9dfc0bc
commit
bb97cbee17
+103
@@ -92,6 +92,7 @@ const struct Command Interpreter::sCommands[] =
|
||||
{ "hashmacaddr", &Interpreter::ProcessHashMacAddress },
|
||||
{ "ifconfig", &Interpreter::ProcessIfconfig },
|
||||
{ "ipaddr", &Interpreter::ProcessIpAddr },
|
||||
{ "ipmaddr", &Interpreter::ProcessIpMulticastAddr },
|
||||
#if OPENTHREAD_ENABLE_JOINER
|
||||
{ "joiner", &Interpreter::ProcessJoiner },
|
||||
#endif
|
||||
@@ -770,6 +771,108 @@ exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
|
||||
ThreadError Interpreter::ProcessIpMulticastAddrAdd(int argc, char *argv[])
|
||||
{
|
||||
ThreadError error;
|
||||
struct otIp6Address address;
|
||||
|
||||
VerifyOrExit(argc > 0, error = kThreadError_Parse);
|
||||
|
||||
SuccessOrExit(error = otIp6AddressFromString(argv[0], &address));
|
||||
error = otSubscribeMulticastAddress(mInstance, &address);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError Interpreter::ProcessIpMulticastAddrDel(int argc, char *argv[])
|
||||
{
|
||||
ThreadError error;
|
||||
struct otIp6Address address;
|
||||
|
||||
VerifyOrExit(argc > 0, error = kThreadError_Parse);
|
||||
|
||||
SuccessOrExit(error = otIp6AddressFromString(argv[0], &address));
|
||||
error = otUnsubscribeMulticastAddress(mInstance, &address);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError Interpreter::ProcessMulticastPromiscuous(int argc, char *argv[])
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
if (otIsMulticastPromiscuousModeEnabled(mInstance))
|
||||
{
|
||||
sServer->OutputFormat("Enabled\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sServer->OutputFormat("Disabled\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(argv[0], "enable") == 0)
|
||||
{
|
||||
otEnableMulticastPromiscuousMode(mInstance);
|
||||
}
|
||||
else if (strcmp(argv[0], "disable") == 0)
|
||||
{
|
||||
otDisableMulticastPromiscuousMode(mInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitNow(error = kThreadError_Parse);
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Interpreter::ProcessIpMulticastAddr(int argc, char *argv[])
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
for (const otNetifMulticastAddress *addr = otGetMulticastAddresses(mInstance); addr; addr = addr->mNext)
|
||||
{
|
||||
sServer->OutputFormat("%x:%x:%x:%x:%x:%x:%x:%x\r\n",
|
||||
HostSwap16(addr->mAddress.mFields.m16[0]),
|
||||
HostSwap16(addr->mAddress.mFields.m16[1]),
|
||||
HostSwap16(addr->mAddress.mFields.m16[2]),
|
||||
HostSwap16(addr->mAddress.mFields.m16[3]),
|
||||
HostSwap16(addr->mAddress.mFields.m16[4]),
|
||||
HostSwap16(addr->mAddress.mFields.m16[5]),
|
||||
HostSwap16(addr->mAddress.mFields.m16[6]),
|
||||
HostSwap16(addr->mAddress.mFields.m16[7]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(argv[0], "add") == 0)
|
||||
{
|
||||
SuccessOrExit(error = ProcessIpMulticastAddrAdd(argc - 1, argv + 1));
|
||||
}
|
||||
else if (strcmp(argv[0], "del") == 0)
|
||||
{
|
||||
SuccessOrExit(error = ProcessIpMulticastAddrDel(argc - 1, argv + 1));
|
||||
}
|
||||
else if (strcmp(argv[0], "promiscuous") == 0)
|
||||
{
|
||||
SuccessOrExit(error = ProcessMulticastPromiscuous(argc - 1, argv + 1));
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
|
||||
void Interpreter::ProcessKeySequence(int argc, char *argv[])
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
Reference in New Issue
Block a user