diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-07-14 10:12:43 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-07-14 10:12:43 +0300 |
commit | 16148ac053acd33422c4e91dd09e4d5aefc2e80b (patch) | |
tree | 394ba5b5ed664a7bd5c714bf239066b259255045 | |
parent | f2813210021a755e5bf6147668b506b82861db7f (diff) |
Fixes to multicast
-rw-r--r-- | src/Hardware/SAME70/Ethernet/GmacInterface.cpp | 7 | ||||
-rw-r--r-- | src/Networking/MulticastResponder.cpp | 13 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/Hardware/SAME70/Ethernet/GmacInterface.cpp b/src/Hardware/SAME70/Ethernet/GmacInterface.cpp index 8099da8c..abf2e0a0 100644 --- a/src/Hardware/SAME70/Ethernet/GmacInterface.cpp +++ b/src/Hardware/SAME70/Ethernet/GmacInterface.cpp @@ -667,6 +667,13 @@ void ethernetif_hardware_init() noexcept gmac_enable_copy_all(GMAC, false); gmac_disable_broadcast(GMAC, false); +#if SUPPORT_MULTICAST_DISCOVERY + // Without this code, we don't receive any multicast packets + GMAC->GMAC_NCFGR |= GMAC_NCFGR_MTIHEN; // enable multicast hash reception + GMAC->GMAC_HRB = 0xFFFFFFFF; // enable reception of all multicast frames + GMAC->GMAC_HRT = 0xFFFFFFFF; +#endif + /* Set RX buffer size to 1536. */ gmac_set_rx_bufsize(GMAC, 0x18); diff --git a/src/Networking/MulticastResponder.cpp b/src/Networking/MulticastResponder.cpp index f39d120a..b040f1dd 100644 --- a/src/Networking/MulticastResponder.cpp +++ b/src/Networking/MulticastResponder.cpp @@ -11,6 +11,8 @@ extern "C" { #include "LwipEthernet/Lwip/src/include/lwip/udp.h" +#include "LwipEthernet/Lwip/src/include/lwip/igmp.h" +extern struct netif gs_net_if; } #if SUPPORT_MULTICAST_DISCOVERY @@ -23,6 +25,8 @@ static unsigned int messagesProcessed = 0; static bool active = false; +static constexpr ip_addr_t ourGroup = IPADDR4_INIT_BYTES(239, 255, 2, 3); + // Receive callback function extern "C" void rcvFunc(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) noexcept { @@ -50,7 +54,7 @@ void MulticastResponder::Spin() noexcept if (rxPbuf != nullptr) { debugPrintf("Rx UDP: addr %u.%u.%u.%u port %u data", - (unsigned int)((receivedIpAddr >> 24) & 0xFF), (unsigned int)((receivedIpAddr >> 16) & 0xFF), (unsigned int)((receivedIpAddr >> 8) & 0xFF), (unsigned int)(receivedIpAddr & 0xFF), receivedPort); + (unsigned int)(receivedIpAddr & 0xFF), (unsigned int)((receivedIpAddr >> 8) & 0xFF), (unsigned int)((receivedIpAddr >> 16) & 0xFF), (unsigned int)((receivedIpAddr >> 24) & 0xFF), receivedPort); for (size_t i = 0; i < rxPbuf->len; ++i) { debugPrintf(" %02x", ((const uint8_t*)(rxPbuf->payload))[i]); @@ -79,13 +83,16 @@ void MulticastResponder::Start(TcpPort port) noexcept else { udp_set_multicast_ttl(ourPcb, 255); - if (udp_bind(ourPcb, IP_ADDR_ANY, port) != ERR_OK) + if (igmp_joingroup_netif(&gs_net_if, ip_2_ip4(&ourGroup)) != ERR_OK) // without this call, multicast packets to this IP address get discarded + { + reprap.GetPlatform().Message(ErrorMessage, "igmp_joingroup failed\n"); + } + else if (udp_bind(ourPcb, &ourGroup, port) != ERR_OK) { reprap.GetPlatform().Message(ErrorMessage, "udp_bind call failed\n"); } else { - debugPrintf("udp_bind call succeeded\n"); udp_recv(ourPcb, rcvFunc, nullptr); } } |