20190831
以前写过一个小结关于LWIP的IGMP阶段性小结。这次呢,当然希望更深入一些。
(1)在lwipopts.h里面加上
#define LWIP_IGMP 1
#define LWIP_RAND lwip_rand
然后建立一个lwip_rand函数
(2)添加igmp_init函数
(3)添加
if ((localtime - IGMPTimer) >= IGMP_TMR_INTERVAL)
{
IGMPTimer = localtime;
igmp_tmr();
}
(4)在low_level_init函数里面添加
netif->flags |= NETIF_FLAG_IGMP;
(5)在ETH_MACDMA_Config函数里面把
ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect;改为
ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_None;
为什么要改?在文档AN3411里面有
在这里也有相关https://stackoverflow.com/questions/23259594/join-igmp-group-not-working-in-lightwight-ip-lwip
里面说到:
I'm new to lwip, and I want to create a multicast receiver with lwip. My steps are as follow: 1. Enable LWIP_IGMP; 2. Set NETIF_FLAG_IGMP in low_level_init(); 3. Join multicast group, create and bind pcb; 4. udp_connect to remote_ip (or multicast IP address? Both are tried but failed)
Joining group returns success, and everything looks fine when program executing this. However the multicast receiver doesn't work, no multicast data comes into network interface. Seems I don't actually join my receiver to the igmp group, although the joining process looks fine. Does any one know what I'm missing?
I found "netif->igmp_mac_filter != NULL" in igmp_joingroup(), but this callback is set as NULL and not implemented. Do I need to implement it by myself to set the MAC filter or it is OK just leave it as NULL?
Thanks a lot for your help!
Ryan
3 Answers
When you join a multicast group the netif->igmp_mac_filter callback is typically called to configure a MAC filter in your Ethernet controller to accept packets with the multicast MAC address corresponding to the group. So, depending on the Ethernet H/W that you are using you may need to implement the callback.
----------------------------------------------------------
The hardware needs to be configured to receive multcast MAC frames, otherwise it will simply discard all frames with multicast destination address. There is probably an option to accept all incoming multicast frames. Enable that in low_level_init() and you should be able to see the incoming multicast frames. You shouldn't need to implement any filter.
----------------------------------------------------------------------------------
I had the same problem. I solved it removing the ETH Multicast Frame filter in the init of the MAC interface. To test, you can also set the interface in promiscuous mode, check if the multicast packet are received an then remove the promiscuous mode and set an appropriate Multicast Frame Filtering mode according to your needs.