mirror of
https://github.com/espressif/openthread.git
synced 2026-07-30 15:47:46 +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
@@ -25,6 +25,7 @@ OpenThread test scripts use the CLI to execute test cases.
|
||||
* [hashmacaddr](#hashmacaddr)
|
||||
* [ifconfig](#ifconfig)
|
||||
* [ipaddr](#ipaddr)
|
||||
* [ipmaddr](#ipmaddr)
|
||||
* [joiner](#joiner)
|
||||
* [keysequence](#keysequence)
|
||||
* [leaderpartitionid](#leaderpartitionid)
|
||||
@@ -789,6 +790,64 @@ Delete an IPv6 address from the Thread interface.
|
||||
Done
|
||||
```
|
||||
|
||||
### ipmaddr
|
||||
|
||||
List all IPv6 multicast addresses subscribed to the Thread interface.
|
||||
|
||||
```bash
|
||||
> ipmaddr
|
||||
ff05:0:0:0:0:0:0:1
|
||||
ff33:40:fdde:ad00:beef:0:0:1
|
||||
ff32:40:fdde:ad00:beef:0:0:1
|
||||
Done
|
||||
```
|
||||
|
||||
### ipmaddr add \<ipaddr\>
|
||||
|
||||
Subscribe the Thread interface to the IPv6 multicast address.
|
||||
|
||||
```bash
|
||||
> ipmaddr add ff05::1
|
||||
Done
|
||||
```
|
||||
|
||||
### ipmaddr del \<ipaddr\>
|
||||
|
||||
Unsubscribe the Thread interface to the IPv6 multicast address.
|
||||
|
||||
```bash
|
||||
> ipmaddr del ff05::1
|
||||
Done
|
||||
```
|
||||
|
||||
### ipmaddr promiscuous
|
||||
|
||||
Get multicast promiscuous mode.
|
||||
|
||||
```bash
|
||||
> ipmaddr promiscuous
|
||||
Disabled
|
||||
Done
|
||||
```
|
||||
|
||||
### ipmaddr promiscuous enable
|
||||
|
||||
Enable multicast promiscuous mode.
|
||||
|
||||
```bash
|
||||
> ipmaddr promiscuous enable
|
||||
Done
|
||||
```
|
||||
|
||||
### ipmaddr promiscuous disable
|
||||
|
||||
Disable multicast promiscuous mode.
|
||||
|
||||
```bash
|
||||
> ipmaddr promiscuous disable
|
||||
Done
|
||||
```
|
||||
|
||||
### joiner start \<pskd\> \<provisioningUrl\>
|
||||
|
||||
Start the Joiner role.
|
||||
|
||||
+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;
|
||||
|
||||
@@ -167,6 +167,10 @@ private:
|
||||
void ProcessIpAddr(int argc, char *argv[]);
|
||||
ThreadError ProcessIpAddrAdd(int argc, char *argv[]);
|
||||
ThreadError ProcessIpAddrDel(int argc, char *argv[]);
|
||||
void ProcessIpMulticastAddr(int argc, char *argv[]);
|
||||
ThreadError ProcessIpMulticastAddrAdd(int argc, char *argv[]);
|
||||
ThreadError ProcessIpMulticastAddrDel(int argc, char *argv[]);
|
||||
ThreadError ProcessMulticastPromiscuous(int argc, char *argv[]);
|
||||
#if OPENTHREAD_ENABLE_JOINER
|
||||
void ProcessJoiner(int argc, char *argv[]);
|
||||
#endif // OPENTHREAD_ENABLE_JOINER
|
||||
|
||||
Reference in New Issue
Block a user