Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs committed Jul 28, 2022
1 parent fb9cd5c commit 4882361
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/system/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ buildconfig_header("system_buildconfig") {
} else {
defines += [ "CHIP_SYSTEM_LAYER_IMPL_CONFIG_FILE=<system/SystemLayerImpl${chip_system_config_event_loop}.h>" ]
}

if (chip_system_config_use_sockets && current_os != "zephyr") {
defines += [
"CHIP_SYSTEM_CONFIG_MULTICAST_HOMING=${chip_system_config_use_sockets} ",
]
} else {
defines += [ "CHIP_SYSTEM_CONFIG_MULTICAST_HOMING=0 " ]
}
}

config("system_config") {
Expand Down
8 changes: 8 additions & 0 deletions src/system/SystemConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@
"FORBIDDEN: CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT && ( CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK || CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_LWIP )"
#endif

#if CHIP_SYSTEM_CONFIG_MULTICAST_HOMING && !CHIP_SYSTEM_CONFIG_USE_SOCKETS
#error "FORBIDDEN: CHIP_SYSTEM_CONFIG_MULTICAST_HOMING CAN ONLY BE USED WITH SOCKET IMPL"
#endif

#if CHIP_SYSTEM_CONFIG_MULTICAST_HOMING && CHIP_SYSTEM_CONFIG_USE_SOCKETS && __ZEPHYR__
#error "FORBIDDEN: CHIP_SYSTEM_CONFIG_MULTICAST_HOMING WAS NOT TESTED WITH ZEPHYR"
#endif

// clang-format off

/**
Expand Down
44 changes: 44 additions & 0 deletions src/transport/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,50 @@ CHIP_ERROR SessionManager::SendPreparedMessage(const SessionHandle & sessionHand
VerifyOrReturnError(!msgBuf.IsNull(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!msgBuf->HasChainedBuffer(), CHIP_ERROR_INVALID_MESSAGE_LENGTH);

#if CHIP_SYSTEM_CONFIG_MULTICAST_HOMING
if (sessionHandle->GetSessionType() == Transport::Session::SessionType::kGroupOutgoing)
{
chip::Inet::InterfaceIterator interfaceIt;
chip::Inet::InterfaceId interfaceId = chip::Inet::InterfaceId::Null();
chip::Inet::IPAddress addr;

chip::Inet::UDPEndPoint * sendUdp;
DeviceLayer::UDPEndPointManager()->NewEndPoint(&sendUdp);
sendUdp->Bind(chip::Inet::IPAddressType::kIPv6, chip::Inet::IPAddress::Any, 5540, interfaceId);

while (interfaceIt.Next())
{
char name[255];
interfaceIt.GetInterfaceName(name, 255);
if (interfaceIt.SupportsMulticast() && interfaceIt.IsUp())
{
interfaceId = interfaceIt.GetInterfaceId();
if (CHIP_NO_ERROR == interfaceId.GetLinkLocalAddr(&addr))
{
char address_string[255];
addr.ToString(address_string, 255);
ChipLogDetail(Inet, "Interface %s has a link local address : %s", name, address_string);

sendUdp->SendTo(destination->GetIPAddress(), 5540, std::move(msgBuf), interfaceId);
}
}
}

DeviceLayer::UDPEndPointManager()->DeleteEndPoint(sendUdp);
return CHIP_NO_ERROR;
}
else
{
#endif // CHIP_SYSTEM_CONFIG_MULTICAST_HOMING
if (mTransportMgr != nullptr)
{
CHIP_TRACE_PREPARED_MESSAGE_SENT(destination, &msgBuf);
return mTransportMgr->SendMessage(*destination, std::move(msgBuf));
}
#if CHIP_SYSTEM_CONFIG_MULTICAST_HOMING
}
#endif // CHIP_SYSTEM_CONFIG_MULTICAST_HOMING

if (mTransportMgr != nullptr)
{
CHIP_TRACE_PREPARED_MESSAGE_SENT(destination, &msgBuf);
Expand Down

0 comments on commit 4882361

Please sign in to comment.