diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2010-07-14 17:17:39 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2010-07-14 17:17:39 +0000 |
commit | 8707a2078f34fc45b263f0256ef704f5ea3212d8 (patch) | |
tree | 891b5ea48104e43671b0a1ecf151f57f18d7cf3a /nuttx/net | |
parent | 2d00a7cfa8a9357a1b4a9d3118e70065431d98a2 (diff) | |
download | px4-nuttx-8707a2078f34fc45b263f0256ef704f5ea3212d8.tar.gz px4-nuttx-8707a2078f34fc45b263f0256ef704f5ea3212d8.tar.bz2 px4-nuttx-8707a2078f34fc45b263f0256ef704f5ea3212d8.zip |
More cosmetic clean-up
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2800 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net')
-rwxr-xr-x | nuttx/net/uip/uip_igmpinit.c | 242 | ||||
-rwxr-xr-x | nuttx/net/uip/uip_igmpinput.c | 560 | ||||
-rwxr-xr-x | nuttx/net/uip/uip_igmpjoin.c | 320 | ||||
-rwxr-xr-x | nuttx/net/uip/uip_igmpleave.c | 364 | ||||
-rwxr-xr-x | nuttx/net/uip/uip_igmpmsg.c | 278 | ||||
-rwxr-xr-x | nuttx/net/uip/uip_igmppoll.c | 352 | ||||
-rwxr-xr-x | nuttx/net/uip/uip_igmptimer.c | 514 |
7 files changed, 1315 insertions, 1315 deletions
diff --git a/nuttx/net/uip/uip_igmpinit.c b/nuttx/net/uip/uip_igmpinit.c index 8d2c05db8..1bdf34457 100755 --- a/nuttx/net/uip/uip_igmpinit.c +++ b/nuttx/net/uip/uip_igmpinit.c @@ -1,121 +1,121 @@ -/****************************************************************************
- * net/uip/uip_igmpinit.c
- * IGMP initialization logic
- *
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * The NuttX implementation of IGMP was inspired by the IGMP add-on for the
- * lwIP TCP/IP stack by Steve Reynolds:
- *
- * Copyright (c) 2002 CITEL Technologies Ltd.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <assert.h>
-#include <debug.h>
-
-#include <net/uip/uip.h>
-#include <net/uip/uip-igmp.h>
-
-#include "uip_internal.h"
-
-#ifdef CONFIG_NET_IGMP
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#ifdef CONFIG_NET_IPv6
-# error "IGMP for IPv6 not supported"
-#endif
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-uip_ipaddr_t g_allsystems;
-uip_ipaddr_t g_allrouters;
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: uip_igmpinit
- *
- * Description:
- * Perform one-time IGMP initialization.
- *
- ****************************************************************************/
-void uip_igmpinit(void)
-{
- nvdbg("IGMP initializing\n");
-
- uip_ipaddr(g_allrouters, 224, 0, 0, 2);
- uip_ipaddr(g_allsystems, 224, 0, 0, 1);
-
- /* Initialize the group allocation logic */
-
- uip_grpinit();
-}
-
-/****************************************************************************
- * Name: uip_igmpdevinit
- *
- * Description:
- * Called when a new network device is registered to configure that device
- * for IGMP support.
- *
- ****************************************************************************/
-
-void uip_igmpdevinit(struct uip_driver_s *dev)
-{
- struct igmp_group_s *group;
-
- nvdbg("IGMP initializing dev %p\n", dev);
- DEBUGASSERT(dev->grplist.head == NULL);
-
- /* Add the all systems address to the group */
-
- group = uip_grpalloc(dev, &g_allsystems);
-
- /* Allow the IGMP messages at the MAC level */
-
- uip_addmcastmac(dev, &g_allrouters);
- uip_addmcastmac(dev, &g_allsystems);
-}
-
-#endif /* CONFIG_NET_IGMP */
+/**************************************************************************** + * net/uip/uip_igmpinit.c + * IGMP initialization logic + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * The NuttX implementation of IGMP was inspired by the IGMP add-on for the + * lwIP TCP/IP stack by Steve Reynolds: + * + * Copyright (c) 2002 CITEL Technologies Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <debug.h> + +#include <net/uip/uip.h> +#include <net/uip/uip-igmp.h> + +#include "uip_internal.h" + +#ifdef CONFIG_NET_IGMP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +# error "IGMP for IPv6 not supported" +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +uip_ipaddr_t g_allsystems; +uip_ipaddr_t g_allrouters; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_igmpinit + * + * Description: + * Perform one-time IGMP initialization. + * + ****************************************************************************/ +void uip_igmpinit(void) +{ + nvdbg("IGMP initializing\n"); + + uip_ipaddr(g_allrouters, 224, 0, 0, 2); + uip_ipaddr(g_allsystems, 224, 0, 0, 1); + + /* Initialize the group allocation logic */ + + uip_grpinit(); +} + +/**************************************************************************** + * Name: uip_igmpdevinit + * + * Description: + * Called when a new network device is registered to configure that device + * for IGMP support. + * + ****************************************************************************/ + +void uip_igmpdevinit(struct uip_driver_s *dev) +{ + struct igmp_group_s *group; + + nvdbg("IGMP initializing dev %p\n", dev); + DEBUGASSERT(dev->grplist.head == NULL); + + /* Add the all systems address to the group */ + + group = uip_grpalloc(dev, &g_allsystems); + + /* Allow the IGMP messages at the MAC level */ + + uip_addmcastmac(dev, &g_allrouters); + uip_addmcastmac(dev, &g_allsystems); +} + +#endif /* CONFIG_NET_IGMP */ diff --git a/nuttx/net/uip/uip_igmpinput.c b/nuttx/net/uip/uip_igmpinput.c index 61803fcca..ba70af5bf 100755 --- a/nuttx/net/uip/uip_igmpinput.c +++ b/nuttx/net/uip/uip_igmpinput.c @@ -1,280 +1,280 @@ -/****************************************************************************
- * net/uip/uip_igminput.c
- *
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * The NuttX implementation of IGMP was inspired by the IGMP add-on for the
- * lwIP TCP/IP stack by Steve Reynolds:
- *
- * Copyright (c) 2002 CITEL Technologies Ltd.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <wdog.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <net/uip/uipopt.h>
-#include <net/uip/uip.h>
-#include <net/uip/uip-igmp.h>
-
-#include "uip_internal.h"
-
-#ifdef CONFIG_NET_IGMP
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define IGMPBUF ((struct uip_igmphdr_s *)&dev->d_buf[UIP_LLH_LEN])
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: uip_igmpinput
- *
- * Description:
- * An IGMP packet has been received.
- *
- * ________________
- * | |
- * | |
- * | |
- * | |
- * +--------->| Non-Member |<---------+
- * | | | |
- * | | | |
- * | | | |
- * | |________________| |
- * | | |
- * | leave group | join group | leave group
- * | (stop timer, |(send report, | (send leave
- * | send leave if | set flag, | if flag set)
- * | flag set) | start timer) |
- * ________|________ | ________|________
- * | |<---------+ | |
- * | | | |
- * | |<-------------------| |
- * | | query received | |
- * | Delaying Member | (start timer) | Idle Member |
- * +---->| |------------------->| |
- * | | | report received | |
- * | | | (stop timer, | |
- * | | | clear flag) | |
- * | |_________________|------------------->|_________________|
- * | query received | timer expired
- * | (reset timer if | (send report,
- * | Max Resp Time | set flag)
- * | < current timer) |
- * +-------------------+
- *
- * NOTE: This is most likely executing from an interrupt handler.
- *
- ****************************************************************************/
-
-void uip_igmpinput(struct uip_driver_s *dev)
-{
- FAR struct igmp_group_s *group;
- uip_ipaddr_t destipaddr;
- uip_ipaddr_t grpaddr;
- unsigned int ticks;
-
- nllvdbg("IGMP message: %04x%04x\n", IGMPBUF->destipaddr[1], IGMPBUF->destipaddr[0]);
-
- /* Verify the message length */
-
- if (dev->d_len < UIP_LLH_LEN+UIP_IPIGMPH_LEN)
- {
- IGMP_STATINCR(uip_stat.igmp.length_errors);
- nlldbg("Length error\n");
- return;
- }
-
- /* Calculate and check the IGMP checksum */
-
- if (uip_chksum((uint16_t*)&IGMPBUF->type, UIP_IGMPH_LEN) != 0)
- {
- IGMP_STATINCR(uip_stat.igmp.chksum_errors);
- nlldbg("Checksum error\n");
- return;
- }
-
- /* Find the group (or create a new one) using the incoming IP address*/
-
- destipaddr = uip_ip4addr_conv(IGMPBUF->destipaddr);
- group = uip_grpallocfind(dev, &destipaddr);
- if (!group)
- {
- nlldbg("Failed to allocate/find group: %08x\n", destipaddr);
- return;
- }
-
- /* Now handle the message based on the IGMP message type */
-
- switch (IGMPBUF->type)
- {
- case IGMP_MEMBERSHIP_QUERY:
- /* RFC 2236, 2.2. ax Response Time
- * "The Max Response Time field is meaningful only in Membership Query
- * messages, and specifies the maximum allowed time before sending a
- * responding report in units of 1/10 second. In all other messages, it
- * is set to zero by the sender and ignored by receivers.
- */
-
- /* Check if the query was sent to all systems */
-
- if (uip_ipaddr_cmp(destipaddr, g_allsystems))
- {
- /* Yes... Now check the if this this is a general or a group
- * specific query.
- *
- * RFC 2236, 2.1. Type
- * There are two sub-types of Membership Query messages:
- * - General Query, used to learn which groups have members on an
- * attached network.
- * - Group-Specific Query, used to learn if a particular group
- * has any members on an attached network.
- *
- * RFC 2236, 2.4. Group Address
- * "In a Membership Query message, the group address field is
- * set to zero when sending a General Query, and set to the
- * group address being queried when sending a Group-Specific
- * Query."
- */
-
- if (IGMPBUF->grpaddr == 0)
- {
- FAR struct igmp_group_s *member;
-
- /* This is the general query */
-
- nllvdbg("General multicast query\n");
- if (IGMPBUF->maxresp == 0)
- {
- IGMP_STATINCR(uip_stat.igmp.v1_received);
- IGMPBUF->maxresp = 10;
-
- nlldbg("V1 not implemented\n");
- }
-
- IGMP_STATINCR(uip_stat.igmp.query_received);
- for (member = (FAR struct igmp_group_s *)dev->grplist.head;
- member;
- member = member->next)
- {
- /* Skip over the all systems group entry */
-
- if (!uip_ipaddr_cmp(member->grpaddr, g_allsystems))
- {
- ticks = uip_decisec2tick((int)IGMPBUF->maxresp);
- if (IS_IDLEMEMBER(member->flags) ||
- uip_igmpcmptimer(member, ticks))
- {
- uip_igmpstartticks(member, ticks);
- CLR_IDLEMEMBER(member->flags);
- }
- }
- }
- }
- else /* if (IGMPBUF->grpaddr != 0) */
- {
- nllvdbg("Group-specific multicast queury\n");
-
- /* We first need to re-lookup the group since we used dest last time.
- * Use the incoming IPaddress!
- */
-
- IGMP_STATINCR(uip_stat.igmp.ucast_query);
- grpaddr = uip_ip4addr_conv(IGMPBUF->grpaddr);
- group = uip_grpallocfind(dev, &grpaddr);
- ticks = uip_decisec2tick((int)IGMPBUF->maxresp);
- if (IS_IDLEMEMBER(group->flags) || uip_igmpcmptimer(group, ticks))
- {
- uip_igmpstartticks(group, ticks);
- CLR_IDLEMEMBER(group->flags);
- }
- }
- }
-
- /* Not sent to all systems -- Unicast query */
-
- else if (group->grpaddr != 0)
- {
- nllvdbg("Unitcast queury\n");
- IGMP_STATINCR(uip_stat.igmp.ucast_query);
-
- nlldbg("Query to a specific group with the group address as destination\n");
-
- ticks = uip_decisec2tick((int)IGMPBUF->maxresp);
- if (IS_IDLEMEMBER(group->flags) || uip_igmpcmptimer(group, ticks))
- {
- uip_igmpstartticks(group, ticks);
- CLR_IDLEMEMBER(group->flags);
- }
- }
- break;
-
- case IGMPv2_MEMBERSHIP_REPORT:
- {
- nllvdbg("Membership report\n");
-
- IGMP_STATINCR(uip_stat.igmp.report_received);
- if (!IS_IDLEMEMBER(group->flags))
- {
- /* This is on a specific group we have already looked up */
-
- wd_cancel(group->wdog);
- SET_IDLEMEMBER(group->flags);
- CLR_LASTREPORT(group->flags);
- }
- }
- break;
-
- default:
- {
- nlldbg("Unexpected msg %02x\n", IGMPBUF->type);
- }
- break;
- }
-}
-
-#endif /* CONFIG_NET_IGMP */
+/**************************************************************************** + * net/uip/uip_igminput.c + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * The NuttX implementation of IGMP was inspired by the IGMP add-on for the + * lwIP TCP/IP stack by Steve Reynolds: + * + * Copyright (c) 2002 CITEL Technologies Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <wdog.h> +#include <assert.h> +#include <debug.h> + +#include <net/uip/uipopt.h> +#include <net/uip/uip.h> +#include <net/uip/uip-igmp.h> + +#include "uip_internal.h" + +#ifdef CONFIG_NET_IGMP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define IGMPBUF ((struct uip_igmphdr_s *)&dev->d_buf[UIP_LLH_LEN]) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_igmpinput + * + * Description: + * An IGMP packet has been received. + * + * ________________ + * | | + * | | + * | | + * | | + * +--------->| Non-Member |<---------+ + * | | | | + * | | | | + * | | | | + * | |________________| | + * | | | + * | leave group | join group | leave group + * | (stop timer, |(send report, | (send leave + * | send leave if | set flag, | if flag set) + * | flag set) | start timer) | + * ________|________ | ________|________ + * | |<---------+ | | + * | | | | + * | |<-------------------| | + * | | query received | | + * | Delaying Member | (start timer) | Idle Member | + * +---->| |------------------->| | + * | | | report received | | + * | | | (stop timer, | | + * | | | clear flag) | | + * | |_________________|------------------->|_________________| + * | query received | timer expired + * | (reset timer if | (send report, + * | Max Resp Time | set flag) + * | < current timer) | + * +-------------------+ + * + * NOTE: This is most likely executing from an interrupt handler. + * + ****************************************************************************/ + +void uip_igmpinput(struct uip_driver_s *dev) +{ + FAR struct igmp_group_s *group; + uip_ipaddr_t destipaddr; + uip_ipaddr_t grpaddr; + unsigned int ticks; + + nllvdbg("IGMP message: %04x%04x\n", IGMPBUF->destipaddr[1], IGMPBUF->destipaddr[0]); + + /* Verify the message length */ + + if (dev->d_len < UIP_LLH_LEN+UIP_IPIGMPH_LEN) + { + IGMP_STATINCR(uip_stat.igmp.length_errors); + nlldbg("Length error\n"); + return; + } + + /* Calculate and check the IGMP checksum */ + + if (uip_chksum((uint16_t*)&IGMPBUF->type, UIP_IGMPH_LEN) != 0) + { + IGMP_STATINCR(uip_stat.igmp.chksum_errors); + nlldbg("Checksum error\n"); + return; + } + + /* Find the group (or create a new one) using the incoming IP address*/ + + destipaddr = uip_ip4addr_conv(IGMPBUF->destipaddr); + group = uip_grpallocfind(dev, &destipaddr); + if (!group) + { + nlldbg("Failed to allocate/find group: %08x\n", destipaddr); + return; + } + + /* Now handle the message based on the IGMP message type */ + + switch (IGMPBUF->type) + { + case IGMP_MEMBERSHIP_QUERY: + /* RFC 2236, 2.2. ax Response Time + * "The Max Response Time field is meaningful only in Membership Query + * messages, and specifies the maximum allowed time before sending a + * responding report in units of 1/10 second. In all other messages, it + * is set to zero by the sender and ignored by receivers. + */ + + /* Check if the query was sent to all systems */ + + if (uip_ipaddr_cmp(destipaddr, g_allsystems)) + { + /* Yes... Now check the if this this is a general or a group + * specific query. + * + * RFC 2236, 2.1. Type + * There are two sub-types of Membership Query messages: + * - General Query, used to learn which groups have members on an + * attached network. + * - Group-Specific Query, used to learn if a particular group + * has any members on an attached network. + * + * RFC 2236, 2.4. Group Address + * "In a Membership Query message, the group address field is + * set to zero when sending a General Query, and set to the + * group address being queried when sending a Group-Specific + * Query." + */ + + if (IGMPBUF->grpaddr == 0) + { + FAR struct igmp_group_s *member; + + /* This is the general query */ + + nllvdbg("General multicast query\n"); + if (IGMPBUF->maxresp == 0) + { + IGMP_STATINCR(uip_stat.igmp.v1_received); + IGMPBUF->maxresp = 10; + + nlldbg("V1 not implemented\n"); + } + + IGMP_STATINCR(uip_stat.igmp.query_received); + for (member = (FAR struct igmp_group_s *)dev->grplist.head; + member; + member = member->next) + { + /* Skip over the all systems group entry */ + + if (!uip_ipaddr_cmp(member->grpaddr, g_allsystems)) + { + ticks = uip_decisec2tick((int)IGMPBUF->maxresp); + if (IS_IDLEMEMBER(member->flags) || + uip_igmpcmptimer(member, ticks)) + { + uip_igmpstartticks(member, ticks); + CLR_IDLEMEMBER(member->flags); + } + } + } + } + else /* if (IGMPBUF->grpaddr != 0) */ + { + nllvdbg("Group-specific multicast queury\n"); + + /* We first need to re-lookup the group since we used dest last time. + * Use the incoming IPaddress! + */ + + IGMP_STATINCR(uip_stat.igmp.ucast_query); + grpaddr = uip_ip4addr_conv(IGMPBUF->grpaddr); + group = uip_grpallocfind(dev, &grpaddr); + ticks = uip_decisec2tick((int)IGMPBUF->maxresp); + if (IS_IDLEMEMBER(group->flags) || uip_igmpcmptimer(group, ticks)) + { + uip_igmpstartticks(group, ticks); + CLR_IDLEMEMBER(group->flags); + } + } + } + + /* Not sent to all systems -- Unicast query */ + + else if (group->grpaddr != 0) + { + nllvdbg("Unitcast queury\n"); + IGMP_STATINCR(uip_stat.igmp.ucast_query); + + nlldbg("Query to a specific group with the group address as destination\n"); + + ticks = uip_decisec2tick((int)IGMPBUF->maxresp); + if (IS_IDLEMEMBER(group->flags) || uip_igmpcmptimer(group, ticks)) + { + uip_igmpstartticks(group, ticks); + CLR_IDLEMEMBER(group->flags); + } + } + break; + + case IGMPv2_MEMBERSHIP_REPORT: + { + nllvdbg("Membership report\n"); + + IGMP_STATINCR(uip_stat.igmp.report_received); + if (!IS_IDLEMEMBER(group->flags)) + { + /* This is on a specific group we have already looked up */ + + wd_cancel(group->wdog); + SET_IDLEMEMBER(group->flags); + CLR_LASTREPORT(group->flags); + } + } + break; + + default: + { + nlldbg("Unexpected msg %02x\n", IGMPBUF->type); + } + break; + } +} + +#endif /* CONFIG_NET_IGMP */ diff --git a/nuttx/net/uip/uip_igmpjoin.c b/nuttx/net/uip/uip_igmpjoin.c index 34f319ec3..a7118051a 100755 --- a/nuttx/net/uip/uip_igmpjoin.c +++ b/nuttx/net/uip/uip_igmpjoin.c @@ -1,160 +1,160 @@ -/****************************************************************************
- * net/uip/uip_igmpjoin.c
- *
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * The NuttX implementation of IGMP was inspired by the IGMP add-on for the
- * lwIP TCP/IP stack by Steve Reynolds:
- *
- * Copyright (c) 2002 CITEL Technologies Ltd.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <assert.h>
-#include <debug.h>
-
-#include <net/uip/uipopt.h>
-#include <net/uip/uip.h>
-#include <net/uip/uip-igmp.h>
-
-#include "uip_internal.h"
-
-#ifdef CONFIG_NET_IGMP
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: igmp_joingroup
- *
- * Description:
- * Add the specified group address to the group.
- *
- * RFC 2236, 3. Protocol Description:
- *
- * "When a host joins a multicast group, it should immediately transmit
- * an unsolicited Version 2 Membership Report for that group, in case it
- * is the first member of that group on the network. To cover the
- * possibility of the initial Membership Report being lost or damaged,
- * it is recommended that it be repeated once or twice after short
- * delays [Unsolicited Report Interval]. (A simple way to accomplish
- * this is to send the initial Version 2 Membership Report and then act
- * as if a Group-Specific Query was received for that group, and set a
- * timer appropriately)."
- * ________________
- * | |
- * | |
- * | |
- * | |
- * +--------->| Non-Member |<---------+
- * | | | |
- * | | | |
- * | | | |
- * | |________________| |
- * | | |
- * | leave group | join group | leave group
- * | (stop timer, |(send report, | (send leave
- * | send leave if | set flag, | if flag set)
- * | flag set) | start timer) |
- * ________|________ | ________|________
- * | |<---------+ | |
- * | | | |
- * | |<-------------------| |
- * | | query received | |
- * | Delaying Member | (start timer) | Idle Member |
- * +---->| |------------------->| |
- * | | | report received | |
- * | | | (stop timer, | |
- * | | | clear flag) | |
- * | |_________________|------------------->|_________________|
- * | query received | timer expired
- * | (reset timer if | (send report,
- * | Max Resp Time | set flag)
- * | < current timer) |
- * +-------------------+
- *
- * Assumptions:
- * This function cannot be called from interrupt handling logic!
- *
- ****************************************************************************/
-
-int igmp_joingroup(struct uip_driver_s *dev, FAR const struct in_addr *grpaddr)
-{
- struct igmp_group_s *group;
-
- DEBUGASSERT(dev && grpaddr);
-
- /* Check if a this address is already in the group */
-
- group = uip_grpfind(dev, &grpaddr->s_addr);
- if (!group)
- {
- /* No... allocate a new entry */
-
- nvdbg("Join to new group: %08x\n", grpaddr->s_addr);
- group = uip_grpalloc(dev, &grpaddr->s_addr);
- IGMP_STATINCR(uip_stat.igmp.joins);
-
- /* Send the Membership Report */
-
- IGMP_STATINCR(uip_stat.igmp.report_sched);
- uip_igmpwaitmsg(group, IGMPv2_MEMBERSHIP_REPORT);
-
- /* And start the timer at 10*100 msec */
-
- uip_igmpstarttimer(group, 10);
-
- /* Add the group (MAC) address to the ether drivers MAC filter list */
-
- uip_addmcastmac(dev, (FAR uip_ipaddr_t *)&grpaddr->s_addr);
- return OK;
- }
-
- /* Return EEXIST if the address is already a member of the group */
-
- return -EEXIST;
-}
-
-#endif /* CONFIG_NET_IGMP */
+/**************************************************************************** + * net/uip/uip_igmpjoin.c + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * The NuttX implementation of IGMP was inspired by the IGMP add-on for the + * lwIP TCP/IP stack by Steve Reynolds: + * + * Copyright (c) 2002 CITEL Technologies Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <debug.h> + +#include <net/uip/uipopt.h> +#include <net/uip/uip.h> +#include <net/uip/uip-igmp.h> + +#include "uip_internal.h" + +#ifdef CONFIG_NET_IGMP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: igmp_joingroup + * + * Description: + * Add the specified group address to the group. + * + * RFC 2236, 3. Protocol Description: + * + * "When a host joins a multicast group, it should immediately transmit + * an unsolicited Version 2 Membership Report for that group, in case it + * is the first member of that group on the network. To cover the + * possibility of the initial Membership Report being lost or damaged, + * it is recommended that it be repeated once or twice after short + * delays [Unsolicited Report Interval]. (A simple way to accomplish + * this is to send the initial Version 2 Membership Report and then act + * as if a Group-Specific Query was received for that group, and set a + * timer appropriately)." + * ________________ + * | | + * | | + * | | + * | | + * +--------->| Non-Member |<---------+ + * | | | | + * | | | | + * | | | | + * | |________________| | + * | | | + * | leave group | join group | leave group + * | (stop timer, |(send report, | (send leave + * | send leave if | set flag, | if flag set) + * | flag set) | start timer) | + * ________|________ | ________|________ + * | |<---------+ | | + * | | | | + * | |<-------------------| | + * | | query received | | + * | Delaying Member | (start timer) | Idle Member | + * +---->| |------------------->| | + * | | | report received | | + * | | | (stop timer, | | + * | | | clear flag) | | + * | |_________________|------------------->|_________________| + * | query received | timer expired + * | (reset timer if | (send report, + * | Max Resp Time | set flag) + * | < current timer) | + * +-------------------+ + * + * Assumptions: + * This function cannot be called from interrupt handling logic! + * + ****************************************************************************/ + +int igmp_joingroup(struct uip_driver_s *dev, FAR const struct in_addr *grpaddr) +{ + struct igmp_group_s *group; + + DEBUGASSERT(dev && grpaddr); + + /* Check if a this address is already in the group */ + + group = uip_grpfind(dev, &grpaddr->s_addr); + if (!group) + { + /* No... allocate a new entry */ + + nvdbg("Join to new group: %08x\n", grpaddr->s_addr); + group = uip_grpalloc(dev, &grpaddr->s_addr); + IGMP_STATINCR(uip_stat.igmp.joins); + + /* Send the Membership Report */ + + IGMP_STATINCR(uip_stat.igmp.report_sched); + uip_igmpwaitmsg(group, IGMPv2_MEMBERSHIP_REPORT); + + /* And start the timer at 10*100 msec */ + + uip_igmpstarttimer(group, 10); + + /* Add the group (MAC) address to the ether drivers MAC filter list */ + + uip_addmcastmac(dev, (FAR uip_ipaddr_t *)&grpaddr->s_addr); + return OK; + } + + /* Return EEXIST if the address is already a member of the group */ + + return -EEXIST; +} + +#endif /* CONFIG_NET_IGMP */ diff --git a/nuttx/net/uip/uip_igmpleave.c b/nuttx/net/uip/uip_igmpleave.c index 276622399..23067f70a 100755 --- a/nuttx/net/uip/uip_igmpleave.c +++ b/nuttx/net/uip/uip_igmpleave.c @@ -1,182 +1,182 @@ -/****************************************************************************
- * net/uip/uip_igmpleave.c
- *
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * The NuttX implementation of IGMP was inspired by the IGMP add-on for the
- * lwIP TCP/IP stack by Steve Reynolds:
- *
- * Copyright (c) 2002 CITEL Technologies Ltd.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <wdog.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <net/uip/uipopt.h>
-#include <net/uip/uip.h>
-#include <net/uip/uip-igmp.h>
-
-#include "uip_internal.h"
-
-#ifdef CONFIG_NET_IGMP
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: igmp_leavegroup
- *
- * Description:
- * Remove the specified group address to the group.
- *
- * RFC 2236, 3. Protocol Description:
- *
- * "When a host leaves a multicast group, if it was the last host to
- * reply to a Query with a Membership Report for that group, it SHOULD
- * send a Leave Group message to the all-routers multicast group
- * (224.0.0.2). If it was not the last host to reply to a Query, it MAY
- * send nothing as there must be another member on the subnet. This is
- * an optimization to reduce traffic; a host without sufficient storage
- * to remember whether or not it was the last host to reply MAY always
- * send a Leave Group message when it leaves a group. Routers SHOULD
- * accept a Leave Group message addressed to the group being left, in
- * order to accommodate implementations of an earlier version of this
- * standard. Leave Group messages are addressed to the all-routers
- * group because other group members have no need to know that a host
- * has left the group, but it does no harm to address the message to the
- * group."
- *
- * ________________
- * | |
- * | |
- * | |
- * | |
- * +--------->| Non-Member |<---------+
- * | | | |
- * | | | |
- * | | | |
- * | |________________| |
- * | | |
- * | leave group | join group | leave group
- * | (stop timer, |(send report, | (send leave
- * | send leave if | set flag, | if flag set)
- * | flag set) | start timer) |
- * ________|________ | ________|________
- * | |<---------+ | |
- * | | | |
- * | |<-------------------| |
- * | | query received | |
- * | Delaying Member | (start timer) | Idle Member |
- * +---->| |------------------->| |
- * | | | report received | |
- * | | | (stop timer, | |
- * | | | clear flag) | |
- * | |_________________|------------------->|_________________|
- * | query received | timer expired
- * | (reset timer if | (send report,
- * | Max Resp Time | set flag)
- * | < current timer) |
- * +-------------------+
- *
- * Assumptions:
- * This function cannot be called from interrupt handling logic!
- *
- ****************************************************************************/
-
-int igmp_leavegroup(struct uip_driver_s *dev, FAR const struct in_addr *grpaddr)
-{
- struct igmp_group_s *group;
- irqstate_t flags;
-
- DEBUGASSERT(dev && grpaddr);
-
- /* Find the entry corresponding to the address leaving the group */
-
- group = uip_grpfind(dev, &grpaddr->s_addr);
- ndbg("Leaving group: %p\n", group);
- if (group)
- {
- /* Cancel the timer and discard any queued Membership Reports. Canceling
- * the timer will prevent any new Membership Reports from being sent;
- * clearing the flags will discard any pending Membership Reports that
- * could interfere with the Leave Group.
- */
-
- flags = irqsave();
- wd_cancel(group->wdog);
- CLR_SCHEDMSG(group->flags);
- CLR_WAITMSG(group->flags);
- irqrestore(flags);
-
- IGMP_STATINCR(uip_stat.igmp.leaves);
-
- /* Send a leave if the flag is set according to the state diagram */
-
- if (IS_LASTREPORT(group->flags))
- {
- ndbg("Schedule Leave Group message\n");
- IGMP_STATINCR(uip_stat.igmp.leave_sched);
- uip_igmpwaitmsg(group, IGMP_LEAVE_GROUP);
- }
-
- /* Free the group structure (state is now Non-Member */
-
- uip_grpfree(dev, group);
-
- /* And remove the group address from the ethernet drivers MAC filter set */
-
- uip_removemcastmac(dev, (FAR uip_ipaddr_t *)&grpaddr->s_addr);
- return OK;
- }
-
- /* Return ENOENT if the address is not a member of the group */
-
- nvdbg("Return -ENOENT\n");
- return -ENOENT;
-}
-
-#endif /* CONFIG_NET_IGMP */
+/**************************************************************************** + * net/uip/uip_igmpleave.c + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * The NuttX implementation of IGMP was inspired by the IGMP add-on for the + * lwIP TCP/IP stack by Steve Reynolds: + * + * Copyright (c) 2002 CITEL Technologies Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <wdog.h> +#include <assert.h> +#include <debug.h> + +#include <net/uip/uipopt.h> +#include <net/uip/uip.h> +#include <net/uip/uip-igmp.h> + +#include "uip_internal.h" + +#ifdef CONFIG_NET_IGMP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: igmp_leavegroup + * + * Description: + * Remove the specified group address to the group. + * + * RFC 2236, 3. Protocol Description: + * + * "When a host leaves a multicast group, if it was the last host to + * reply to a Query with a Membership Report for that group, it SHOULD + * send a Leave Group message to the all-routers multicast group + * (224.0.0.2). If it was not the last host to reply to a Query, it MAY + * send nothing as there must be another member on the subnet. This is + * an optimization to reduce traffic; a host without sufficient storage + * to remember whether or not it was the last host to reply MAY always + * send a Leave Group message when it leaves a group. Routers SHOULD + * accept a Leave Group message addressed to the group being left, in + * order to accommodate implementations of an earlier version of this + * standard. Leave Group messages are addressed to the all-routers + * group because other group members have no need to know that a host + * has left the group, but it does no harm to address the message to the + * group." + * + * ________________ + * | | + * | | + * | | + * | | + * +--------->| Non-Member |<---------+ + * | | | | + * | | | | + * | | | | + * | |________________| | + * | | | + * | leave group | join group | leave group + * | (stop timer, |(send report, | (send leave + * | send leave if | set flag, | if flag set) + * | flag set) | start timer) | + * ________|________ | ________|________ + * | |<---------+ | | + * | | | | + * | |<-------------------| | + * | | query received | | + * | Delaying Member | (start timer) | Idle Member | + * +---->| |------------------->| | + * | | | report received | | + * | | | (stop timer, | | + * | | | clear flag) | | + * | |_________________|------------------->|_________________| + * | query received | timer expired + * | (reset timer if | (send report, + * | Max Resp Time | set flag) + * | < current timer) | + * +-------------------+ + * + * Assumptions: + * This function cannot be called from interrupt handling logic! + * + ****************************************************************************/ + +int igmp_leavegroup(struct uip_driver_s *dev, FAR const struct in_addr *grpaddr) +{ + struct igmp_group_s *group; + irqstate_t flags; + + DEBUGASSERT(dev && grpaddr); + + /* Find the entry corresponding to the address leaving the group */ + + group = uip_grpfind(dev, &grpaddr->s_addr); + ndbg("Leaving group: %p\n", group); + if (group) + { + /* Cancel the timer and discard any queued Membership Reports. Canceling + * the timer will prevent any new Membership Reports from being sent; + * clearing the flags will discard any pending Membership Reports that + * could interfere with the Leave Group. + */ + + flags = irqsave(); + wd_cancel(group->wdog); + CLR_SCHEDMSG(group->flags); + CLR_WAITMSG(group->flags); + irqrestore(flags); + + IGMP_STATINCR(uip_stat.igmp.leaves); + + /* Send a leave if the flag is set according to the state diagram */ + + if (IS_LASTREPORT(group->flags)) + { + ndbg("Schedule Leave Group message\n"); + IGMP_STATINCR(uip_stat.igmp.leave_sched); + uip_igmpwaitmsg(group, IGMP_LEAVE_GROUP); + } + + /* Free the group structure (state is now Non-Member */ + + uip_grpfree(dev, group); + + /* And remove the group address from the ethernet drivers MAC filter set */ + + uip_removemcastmac(dev, (FAR uip_ipaddr_t *)&grpaddr->s_addr); + return OK; + } + + /* Return ENOENT if the address is not a member of the group */ + + nvdbg("Return -ENOENT\n"); + return -ENOENT; +} + +#endif /* CONFIG_NET_IGMP */ diff --git a/nuttx/net/uip/uip_igmpmsg.c b/nuttx/net/uip/uip_igmpmsg.c index 44d0f2459..d9837d04a 100755 --- a/nuttx/net/uip/uip_igmpmsg.c +++ b/nuttx/net/uip/uip_igmpmsg.c @@ -1,139 +1,139 @@ -/****************************************************************************
- * net/uip/uip_igmpmgs.c
- *
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * The NuttX implementation of IGMP was inspired by the IGMP add-on for the
- * lwIP TCP/IP stack by Steve Reynolds:
- *
- * Copyright (c) 2002 CITEL Technologies Ltd.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <assert.h>
-#include <debug.h>
-
-#include <net/uip/uipopt.h>
-#include <net/uip/uip.h>
-#include <net/uip/uip-igmp.h>
-
-#include "uip_internal.h"
-
-#ifdef CONFIG_NET_IGMP
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: uip_igmpschedmsg
- *
- * Description:
- * Schedule a message to be send at the next driver polling interval.
- *
- * Assumptions:
- * This function may be called in most any context.
- *
- ****************************************************************************/
-
-void uip_igmpschedmsg(FAR struct igmp_group_s *group, uint8_t msgid)
-{
- irqstate_t flags = irqsave();
-
- /* The following should be atomic */
-
- flags = irqsave();
- DEBUGASSERT(!IS_SCHEDMSG(group->flags));
- group->msgid = msgid;
- SET_SCHEDMSG(group->flags);
- irqrestore(flags);
-}
-
-/****************************************************************************
- * Name: uip_igmpwaitmsg
- *
- * Description:
- * Schedule a message to be send at the next driver polling interval and
- * block, waiting for the message to be sent.
- *
- * Assumptions:
- * This function cannot be called from an interrupt handler (if you try it,
- * sem_wait will assert).
- *
- ****************************************************************************/
-
-void uip_igmpwaitmsg(FAR struct igmp_group_s *group, uint8_t msgid)
-{
- irqstate_t flags;
-
- /* Schedule to send the message */
-
- flags = irqsave();
- DEBUGASSERT(!IS_WAITMSG(group->flags));
- SET_WAITMSG(group->flags);
- uip_igmpschedmsg(group, msgid);
-
- /* Then wait for the message to be sent */
-
- while (IS_SCHEDMSG(group->flags))
- {
- /* Wait for the semaphore to be posted */
-
- while (sem_wait(&group->sem) != 0)
- {
- /* The only error that should occur from sem_wait() is if
- * the wait is awakened by a signal.
- */
-
- ASSERT(errno == EINTR);
- }
- }
-
- /* The message has been sent and we are no longer waiting */
-
- CLR_WAITMSG(group->flags);
- irqrestore(flags);
-}
-
-#endif /* CONFIG_NET_IGMP */
+/**************************************************************************** + * net/uip/uip_igmpmgs.c + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * The NuttX implementation of IGMP was inspired by the IGMP add-on for the + * lwIP TCP/IP stack by Steve Reynolds: + * + * Copyright (c) 2002 CITEL Technologies Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <debug.h> + +#include <net/uip/uipopt.h> +#include <net/uip/uip.h> +#include <net/uip/uip-igmp.h> + +#include "uip_internal.h" + +#ifdef CONFIG_NET_IGMP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_igmpschedmsg + * + * Description: + * Schedule a message to be send at the next driver polling interval. + * + * Assumptions: + * This function may be called in most any context. + * + ****************************************************************************/ + +void uip_igmpschedmsg(FAR struct igmp_group_s *group, uint8_t msgid) +{ + irqstate_t flags = irqsave(); + + /* The following should be atomic */ + + flags = irqsave(); + DEBUGASSERT(!IS_SCHEDMSG(group->flags)); + group->msgid = msgid; + SET_SCHEDMSG(group->flags); + irqrestore(flags); +} + +/**************************************************************************** + * Name: uip_igmpwaitmsg + * + * Description: + * Schedule a message to be send at the next driver polling interval and + * block, waiting for the message to be sent. + * + * Assumptions: + * This function cannot be called from an interrupt handler (if you try it, + * sem_wait will assert). + * + ****************************************************************************/ + +void uip_igmpwaitmsg(FAR struct igmp_group_s *group, uint8_t msgid) +{ + irqstate_t flags; + + /* Schedule to send the message */ + + flags = irqsave(); + DEBUGASSERT(!IS_WAITMSG(group->flags)); + SET_WAITMSG(group->flags); + uip_igmpschedmsg(group, msgid); + + /* Then wait for the message to be sent */ + + while (IS_SCHEDMSG(group->flags)) + { + /* Wait for the semaphore to be posted */ + + while (sem_wait(&group->sem) != 0) + { + /* The only error that should occur from sem_wait() is if + * the wait is awakened by a signal. + */ + + ASSERT(errno == EINTR); + } + } + + /* The message has been sent and we are no longer waiting */ + + CLR_WAITMSG(group->flags); + irqrestore(flags); +} + +#endif /* CONFIG_NET_IGMP */ diff --git a/nuttx/net/uip/uip_igmppoll.c b/nuttx/net/uip/uip_igmppoll.c index b31f2d82c..9ec96ed43 100755 --- a/nuttx/net/uip/uip_igmppoll.c +++ b/nuttx/net/uip/uip_igmppoll.c @@ -1,176 +1,176 @@ -/****************************************************************************
- * net/uip/uip_igmppoll.c
- *
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * The NuttX implementation of IGMP was inspired by the IGMP add-on for the
- * lwIP TCP/IP stack by Steve Reynolds:
- *
- * Copyright (c) 2002 CITEL Technologies Ltd.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <assert.h>
-#include <debug.h>
-
-#include <net/uip/uipopt.h>
-#include <net/uip/uip.h>
-#include <net/uip/uip-arch.h>
-
-#include "uip_internal.h"
-
-#ifdef CONFIG_NET_IGMP
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: uip_schedsend
- *
- * Description:
- * Construct the .
- *
- * Returned Value:
- * Returns a non-zero value if a IGP message is sent.
- *
- * Assumptions:
- * This function is called from the driver polling logic... probably within
- * an interrupt handler.
- *
- ****************************************************************************/
-
-static inline void uip_schedsend(FAR struct uip_driver_s *dev, FAR struct igmp_group_s *group)
-{
- uip_ipaddr_t *dest;
-
- /* Check what kind of messsage we need to send. There are only two
- * possibilities:
- */
-
- if (group->msgid == IGMPv2_MEMBERSHIP_REPORT)
- {
- dest = &group->grpaddr;
- nllvdbg("Send IGMPv2_MEMBERSHIP_REPORT, dest=%08x flags=%02x\n",
- *dest, group->flags);
- IGMP_STATINCR(uip_stat.igmp.report_sched);
- SET_LASTREPORT(group->flags); /* Remember we were the last to report */
- }
- else
- {
- DEBUGASSERT(group->msgid == IGMP_LEAVE_GROUP);
- dest = &g_allrouters;
- nllvdbg("Send IGMP_LEAVE_GROUP, dest=%08x flags=%02x\n",
- *dest, group->flags);
- IGMP_STATINCR(uip_stat.igmp.leave_sched);
- }
-
- /* Send the message */
-
- uip_igmpsend(dev, group, dest);
-
- /* Indicate that the message has been sent */
-
- CLR_SCHEDMSG(group->flags);
- group->msgid = 0;
-
- /* If there is a thread waiting fore the message to be sent, wake it up */
-
- if (IS_WAITMSG(group->flags))
- {
- nllvdbg("Awakening waiter\n");
- sem_post(&group->sem);
- }
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: uip_igmppoll
- *
- * Description:
- * Poll the groups associated with the device to see if any IGMP messages
- * are pending transfer.
- *
- * Returned Value:
- * Returns a non-zero value if a IGP message is sent.
- *
- * Assumptions:
- * This function is called from the driver polling logic... probably within
- * an interrupt handler.
- *
- ****************************************************************************/
-
-void uip_igmppoll(FAR struct uip_driver_s *dev)
-{
- FAR struct igmp_group_s *group;
-
- nllvdbg("Entry\n");
-
- /* Setup the poll operation */
-
- dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPIGMPH_LEN];
- dev->d_snddata = &dev->d_buf[UIP_LLH_LEN + UIP_IPIGMPH_LEN];
-
- dev->d_len = 0;
- dev->d_sndlen = 0;
-
- /* Check each member of the group */
-
- for (group = (FAR struct igmp_group_s *)dev->grplist.head; group; group = group->next)
- {
- /* Does this member have a pending outgoing message? */
-
- if (IS_SCHEDMSG(group->flags))
- {
- /* Yes, create the IGMP message in the driver buffer */
-
- uip_schedsend(dev, group);
-
- /* Mark the message as sent and break out */
-
- CLR_SCHEDMSG(group->flags);
- break;
- }
- }
-}
-#endif /* CONFIG_NET_IGMP */
+/**************************************************************************** + * net/uip/uip_igmppoll.c + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * The NuttX implementation of IGMP was inspired by the IGMP add-on for the + * lwIP TCP/IP stack by Steve Reynolds: + * + * Copyright (c) 2002 CITEL Technologies Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <debug.h> + +#include <net/uip/uipopt.h> +#include <net/uip/uip.h> +#include <net/uip/uip-arch.h> + +#include "uip_internal.h" + +#ifdef CONFIG_NET_IGMP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_schedsend + * + * Description: + * Construct the . + * + * Returned Value: + * Returns a non-zero value if a IGP message is sent. + * + * Assumptions: + * This function is called from the driver polling logic... probably within + * an interrupt handler. + * + ****************************************************************************/ + +static inline void uip_schedsend(FAR struct uip_driver_s *dev, FAR struct igmp_group_s *group) +{ + uip_ipaddr_t *dest; + + /* Check what kind of messsage we need to send. There are only two + * possibilities: + */ + + if (group->msgid == IGMPv2_MEMBERSHIP_REPORT) + { + dest = &group->grpaddr; + nllvdbg("Send IGMPv2_MEMBERSHIP_REPORT, dest=%08x flags=%02x\n", + *dest, group->flags); + IGMP_STATINCR(uip_stat.igmp.report_sched); + SET_LASTREPORT(group->flags); /* Remember we were the last to report */ + } + else + { + DEBUGASSERT(group->msgid == IGMP_LEAVE_GROUP); + dest = &g_allrouters; + nllvdbg("Send IGMP_LEAVE_GROUP, dest=%08x flags=%02x\n", + *dest, group->flags); + IGMP_STATINCR(uip_stat.igmp.leave_sched); + } + + /* Send the message */ + + uip_igmpsend(dev, group, dest); + + /* Indicate that the message has been sent */ + + CLR_SCHEDMSG(group->flags); + group->msgid = 0; + + /* If there is a thread waiting fore the message to be sent, wake it up */ + + if (IS_WAITMSG(group->flags)) + { + nllvdbg("Awakening waiter\n"); + sem_post(&group->sem); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_igmppoll + * + * Description: + * Poll the groups associated with the device to see if any IGMP messages + * are pending transfer. + * + * Returned Value: + * Returns a non-zero value if a IGP message is sent. + * + * Assumptions: + * This function is called from the driver polling logic... probably within + * an interrupt handler. + * + ****************************************************************************/ + +void uip_igmppoll(FAR struct uip_driver_s *dev) +{ + FAR struct igmp_group_s *group; + + nllvdbg("Entry\n"); + + /* Setup the poll operation */ + + dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPIGMPH_LEN]; + dev->d_snddata = &dev->d_buf[UIP_LLH_LEN + UIP_IPIGMPH_LEN]; + + dev->d_len = 0; + dev->d_sndlen = 0; + + /* Check each member of the group */ + + for (group = (FAR struct igmp_group_s *)dev->grplist.head; group; group = group->next) + { + /* Does this member have a pending outgoing message? */ + + if (IS_SCHEDMSG(group->flags)) + { + /* Yes, create the IGMP message in the driver buffer */ + + uip_schedsend(dev, group); + + /* Mark the message as sent and break out */ + + CLR_SCHEDMSG(group->flags); + break; + } + } +} +#endif /* CONFIG_NET_IGMP */ diff --git a/nuttx/net/uip/uip_igmptimer.c b/nuttx/net/uip/uip_igmptimer.c index 98d95479d..2ae844341 100755 --- a/nuttx/net/uip/uip_igmptimer.c +++ b/nuttx/net/uip/uip_igmptimer.c @@ -1,257 +1,257 @@ -/****************************************************************************
- * net/uip/uip_igmptimer.c
- *
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * The NuttX implementation of IGMP was inspired by the IGMP add-on for the
- * lwIP TCP/IP stack by Steve Reynolds:
- *
- * Copyright (c) 2002 CITEL Technologies Ltd.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-#include <nuttx/compiler.h>
-
-#include <wdog.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <net/uip/uipopt.h>
-#include <net/uip/uip.h>
-#include <net/uip/uip-igmp.h>
-
-#include "uip_internal.h"
-
-#ifdef CONFIG_NET_IGMP
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* Debug ********************************************************************/
-
-#undef IGMP_GTMRDEBUG /* Define to enable detailed IGMP group debug */
-
-#ifndef CONFIG_NET_IGMP
-# undef IGMP_GTMRDEBUG
-#endif
-
-#ifdef CONFIG_CPP_HAVE_VARARGS
-# ifdef IGMP_GTMRDEBUG
-# define gtmrdbg(format, arg...) ndbg(format, ##arg)
-# define gtmrlldbg(format, arg...) nlldbg(format, ##arg)
-# define gtmrvdbg(format, arg...) nvdbg(format, ##arg)
-# define gtmrllvdbg(format, arg...) nllvdbg(format, ##arg)
-# else
-# define gtmrdbg(x...)
-# define gtmrlldbg(x...)
-# define gtmrvdbg(x...)
-# define gtmrllvdbg(x...)
-# endif
-#else
-# ifdef IGMP_GTMRDEBUG
-# define gtmrdbg ndbg
-# define gtmrlldbg nlldbg
-# define gtmrvdbg nvdbg
-# define gtmrllvdbg nllvdbg
-# else
-# define gtmrdbg (void)
-# define gtmrlldbg (void)
-# define gtmrvdbg (void)
-# define gtmrllvdbg (void)
-# endif
-#endif
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: uip_igmptimeout
- *
- * Description:
- * Timeout watchdog handler.
- *
- * Assumptions:
- * This function is called from the wdog timer handler which runs in the
- * context of the timer interrupt handler.
- *
- ****************************************************************************/
-
-static void uip_igmptimeout(int argc, uint32_t arg, ...)
-{
- FAR struct igmp_group_s *group;
-
- /* If the state is DELAYING_MEMBER then we send a report for this group */
-
- nllvdbg("Timeout!\n");
- group = (FAR struct igmp_group_s *)arg;
- DEBUGASSERT(argc == 1 && group);
-
- /* If the group exists and is no an IDLE MEMBER, then it must be a DELAYING
- * member. Race conditions are avoided because (1) the timer is not started
- * until after the first IGMPv2_MEMBERSHIP_REPORT during the join, and (2)
- * the timer is canceled before sending the IGMP_LEAVE_GROUP during a leave.
- */
-
- if (!IS_IDLEMEMBER(group->flags))
- {
- /* Schedule (and forget) the Membership Report. NOTE:
- * Since we are executing from a timer interrupt, we cannot wait
- * for the message to be sent.
- */
-
- IGMP_STATINCR(uip_stat.igmp.report_sched);
- uip_igmpschedmsg(group, IGMPv2_MEMBERSHIP_REPORT);
-
- /* Also note: The Membership Report is sent at most two times becasue
- * the timer is not reset here. Hmm.. does this mean that the group
- * is stranded if both reports were lost? This is consistent with the
- * RFC that states: "To cover the possibility of the initial Membership
- * Report being lost or damaged, it is recommended that it be repeated
- * once or twice after shortdelays [Unsolicited Report Interval]..."
- */
- }
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: uip_igmpstarttimer
- *
- * Description:
- * Start the IGMP timer.
- *
- * Assumptions:
- * This function may be called from most any context.
- *
- ****************************************************************************/
-
-int uip_decisec2tick(int decisecs)
-{
- /* Convert the deci-second comparison value to clock ticks. The CLK_TCK
- * value is the number of clock ticks per second; decisecs argument is the
- * maximum delay in 100's of milliseconds. CLK_TCK/10 is then the number
- * of clock ticks in 100 milliseconds.
- */
-
- return CLK_TCK * decisecs / 10;
-}
-
-/****************************************************************************
- * Name: uip_igmpstartticks and uip_igmpstarttimer
- *
- * Description:
- * Start the IGMP timer with differing time units (ticks or deciseconds).
- *
- * Assumptions:
- * This function may be called from most any context.
- *
- ****************************************************************************/
-
-void uip_igmpstartticks(FAR struct igmp_group_s *group, int ticks)
-{
- int ret;
-
- /* Start the timer */
-
- gtmrlldbg("ticks: %d\n", ticks);
- ret = wd_start(group->wdog, ticks, uip_igmptimeout, 1, (uint32_t)group);
- DEBUGASSERT(ret == OK);
-}
-
-void uip_igmpstarttimer(FAR struct igmp_group_s *group, uint8_t decisecs)
-{
- /* Convert the decisec value to system clock ticks and start the timer.
- * Important!! this should be a random timer from 0 to decisecs
- */
-
- gtmrdbg("decisecs: %d\n", decisecs);
- uip_igmpstartticks(group, uip_decisec2tick(decisecs));
-}
-
-/****************************************************************************
- * Name: uip_igmpcmptimer
- *
- * Description:
- * Compare the timer remaining on the watching timer to the deci-second
- * value. If maxticks > ticks-remaining, then (1) cancel the timer (to
- * avoid race conditions) and return true.
- *
- * Assumptions:
- * This function may be called from most any context. If true is retuend
- * then the caller must call uip_igmpstartticks() to restart the timer
- *
- ****************************************************************************/
-
-bool uip_igmpcmptimer(FAR struct igmp_group_s *group, int maxticks)
-{
- irqstate_t flags;
- int remaining;
-
- /* Disable interrupts so that there is no race condition with the actual
- * timer expiration.
- */
-
- flags = irqsave();
-
- /* Get the timer remaining on the watchdog. A time of <= zero means that
- * the watchdog was never started.
- */
-
- remaining = wd_gettime(group->wdog);
-
- /* A remaining time of zero means that the watchdog was never started
- * or has already expired. That case should be covered in the following
- * test as well.
- */
-
- gtmrdbg("maxticks: %d remaining: %d\n", maxticks, remaining);
- if (maxticks > remaining)
- {
- /* Cancel the watchdog timer and return true */
-
- wd_cancel(group->wdog);
- irqrestore(flags);
- return true;
- }
-
- irqrestore(flags);
- return false;
-}
-
-#endif /* CONFIG_NET_IGMP */
+/**************************************************************************** + * net/uip/uip_igmptimer.c + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * The NuttX implementation of IGMP was inspired by the IGMP add-on for the + * lwIP TCP/IP stack by Steve Reynolds: + * + * Copyright (c) 2002 CITEL Technologies Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/compiler.h> + +#include <wdog.h> +#include <assert.h> +#include <debug.h> + +#include <net/uip/uipopt.h> +#include <net/uip/uip.h> +#include <net/uip/uip-igmp.h> + +#include "uip_internal.h" + +#ifdef CONFIG_NET_IGMP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Debug ********************************************************************/ + +#undef IGMP_GTMRDEBUG /* Define to enable detailed IGMP group debug */ + +#ifndef CONFIG_NET_IGMP +# undef IGMP_GTMRDEBUG +#endif + +#ifdef CONFIG_CPP_HAVE_VARARGS +# ifdef IGMP_GTMRDEBUG +# define gtmrdbg(format, arg...) ndbg(format, ##arg) +# define gtmrlldbg(format, arg...) nlldbg(format, ##arg) +# define gtmrvdbg(format, arg...) nvdbg(format, ##arg) +# define gtmrllvdbg(format, arg...) nllvdbg(format, ##arg) +# else +# define gtmrdbg(x...) +# define gtmrlldbg(x...) +# define gtmrvdbg(x...) +# define gtmrllvdbg(x...) +# endif +#else +# ifdef IGMP_GTMRDEBUG +# define gtmrdbg ndbg +# define gtmrlldbg nlldbg +# define gtmrvdbg nvdbg +# define gtmrllvdbg nllvdbg +# else +# define gtmrdbg (void) +# define gtmrlldbg (void) +# define gtmrvdbg (void) +# define gtmrllvdbg (void) +# endif +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_igmptimeout + * + * Description: + * Timeout watchdog handler. + * + * Assumptions: + * This function is called from the wdog timer handler which runs in the + * context of the timer interrupt handler. + * + ****************************************************************************/ + +static void uip_igmptimeout(int argc, uint32_t arg, ...) +{ + FAR struct igmp_group_s *group; + + /* If the state is DELAYING_MEMBER then we send a report for this group */ + + nllvdbg("Timeout!\n"); + group = (FAR struct igmp_group_s *)arg; + DEBUGASSERT(argc == 1 && group); + + /* If the group exists and is no an IDLE MEMBER, then it must be a DELAYING + * member. Race conditions are avoided because (1) the timer is not started + * until after the first IGMPv2_MEMBERSHIP_REPORT during the join, and (2) + * the timer is canceled before sending the IGMP_LEAVE_GROUP during a leave. + */ + + if (!IS_IDLEMEMBER(group->flags)) + { + /* Schedule (and forget) the Membership Report. NOTE: + * Since we are executing from a timer interrupt, we cannot wait + * for the message to be sent. + */ + + IGMP_STATINCR(uip_stat.igmp.report_sched); + uip_igmpschedmsg(group, IGMPv2_MEMBERSHIP_REPORT); + + /* Also note: The Membership Report is sent at most two times becasue + * the timer is not reset here. Hmm.. does this mean that the group + * is stranded if both reports were lost? This is consistent with the + * RFC that states: "To cover the possibility of the initial Membership + * Report being lost or damaged, it is recommended that it be repeated + * once or twice after shortdelays [Unsolicited Report Interval]..." + */ + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_igmpstarttimer + * + * Description: + * Start the IGMP timer. + * + * Assumptions: + * This function may be called from most any context. + * + ****************************************************************************/ + +int uip_decisec2tick(int decisecs) +{ + /* Convert the deci-second comparison value to clock ticks. The CLK_TCK + * value is the number of clock ticks per second; decisecs argument is the + * maximum delay in 100's of milliseconds. CLK_TCK/10 is then the number + * of clock ticks in 100 milliseconds. + */ + + return CLK_TCK * decisecs / 10; +} + +/**************************************************************************** + * Name: uip_igmpstartticks and uip_igmpstarttimer + * + * Description: + * Start the IGMP timer with differing time units (ticks or deciseconds). + * + * Assumptions: + * This function may be called from most any context. + * + ****************************************************************************/ + +void uip_igmpstartticks(FAR struct igmp_group_s *group, int ticks) +{ + int ret; + + /* Start the timer */ + + gtmrlldbg("ticks: %d\n", ticks); + ret = wd_start(group->wdog, ticks, uip_igmptimeout, 1, (uint32_t)group); + DEBUGASSERT(ret == OK); +} + +void uip_igmpstarttimer(FAR struct igmp_group_s *group, uint8_t decisecs) +{ + /* Convert the decisec value to system clock ticks and start the timer. + * Important!! this should be a random timer from 0 to decisecs + */ + + gtmrdbg("decisecs: %d\n", decisecs); + uip_igmpstartticks(group, uip_decisec2tick(decisecs)); +} + +/**************************************************************************** + * Name: uip_igmpcmptimer + * + * Description: + * Compare the timer remaining on the watching timer to the deci-second + * value. If maxticks > ticks-remaining, then (1) cancel the timer (to + * avoid race conditions) and return true. + * + * Assumptions: + * This function may be called from most any context. If true is retuend + * then the caller must call uip_igmpstartticks() to restart the timer + * + ****************************************************************************/ + +bool uip_igmpcmptimer(FAR struct igmp_group_s *group, int maxticks) +{ + irqstate_t flags; + int remaining; + + /* Disable interrupts so that there is no race condition with the actual + * timer expiration. + */ + + flags = irqsave(); + + /* Get the timer remaining on the watchdog. A time of <= zero means that + * the watchdog was never started. + */ + + remaining = wd_gettime(group->wdog); + + /* A remaining time of zero means that the watchdog was never started + * or has already expired. That case should be covered in the following + * test as well. + */ + + gtmrdbg("maxticks: %d remaining: %d\n", maxticks, remaining); + if (maxticks > remaining) + { + /* Cancel the watchdog timer and return true */ + + wd_cancel(group->wdog); + irqrestore(flags); + return true; + } + + irqrestore(flags); + return false; +} + +#endif /* CONFIG_NET_IGMP */ |