More IGMP logic

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2780 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2010-07-10 01:20:34 +00:00
parent 1aac40d813
commit 9086653ed4
10 changed files with 284 additions and 51 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ endif
ifeq ($(CONFIG_NET_ICMP),y)
UIP_CSRCS += uip_icmpinput.c
UIP_CSRCS += uip_icmpinput.c uip_igmppoll.c
ifeq ($(CONFIG_NET_ICMP_PING),y)
ifneq ($(CONFIG_DISABLE_CLOCK),y)
+1 -2
View File
@@ -1,10 +1,9 @@
/****************************************************************************
* net/uip/uip_chksum.c
*
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
+1 -1
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* net/uip/uip_icmpping.c
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2008-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
+2 -1
View File
@@ -51,6 +51,7 @@
#include <arch/irq.h>
#include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
#include <net/uip/uip.h>
#include <net/uip/uip-igmp.h>
@@ -284,7 +285,7 @@ void uip_grpfree(FAR struct uip_driver_s *dev, FAR struct igmp_group_s *group)
else
{
irqrestore(flags);
free(group);
sched_free(group);
}
}
+2 -1
View File
@@ -44,6 +44,8 @@
#include <nuttx/config.h>
#include <wdog.h>
#include <assert.h>
#include <debug.h>
#include <net/uip/uip.h>
@@ -110,7 +112,6 @@ void uip_igmpdevinit(struct uip_driver_s *dev)
/* Add the all systems address to the group */
group = uip_grpalloc(dev, &g_allsystems);
group->state = IGMP_IDLE_MEMBER;
/* Initialize the group timer (but don't start it yet) */
+161
View File
@@ -0,0 +1,161 @@
/****************************************************************************
* net/uip/uip-igmp.h
* The definitions in this header file are intended only for internal use
* by the NuttX port of the uIP stack.
*
* 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
****************************************************************************/
#define IGMPBUF ((struct uip_igmphdr_s *)&dev->d_buf[UIP_LLH_LEN])
/****************************************************************************
* 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;
/* IGMP header + IP header + 8 bytes of data */
if (group->msgid == IGMPv2_MEMBERSHIP_REPORT)
{
nllvdbg("Send IGMPv2_MEMBERSHIP_REPORT\n");
dest = &group->grpaddr;
IGMP_STATINCR(uip_stat.igmp.report_sched);
uiphdr_ipaddr_copy(IGMPBUF->grpaddr, &group->grpaddr);
SET_LASTREPORT(group->flags); /* Remember we were the last to report */
}
else
{
nllvdbg("Send IGMP_LEAVE_GROUP\n");
DEBUGASSERT(group->msgid == IGMP_LEAVE_GROUP);
dest = &g_allrouters;
IGMP_STATINCR(uip_stat.igmp.leave_sched);
uiphdr_ipaddr_copy(IGMPBUF->grpaddr, &group->grpaddr);
}
uip_igmpsend(dev, dest);
}
/****************************************************************************
* 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;
/* 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 */
+9 -1
View File
@@ -230,7 +230,15 @@ EXTERN FAR struct igmp_group_s *uip_grpallocfind(FAR struct uip_driver_s *dev,
EXTERN void uip_grpfree(FAR struct uip_driver_s *dev,
FAR struct igmp_group_s *group);
/* Defined in TBD */
/* Defined in uip_igmppoll.c *************************************************/
EXTERN void uip_igmppoll(FAR struct uip_driver_s *dev);
/* Defined in up_igmpsend.c **************************************************/
EXTERN void uip_igmpsend(FAR struct uip_driver_s *dev, uip_ipaddr_t *dest);
/* Defined in TBD ************************************************************/
EXTERN void uip_igmpmac(struct uip_driver_s *dev, uip_ipaddr_t *ip, bool on);
+63 -22
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* net/uip/uip_poll.c
*
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -57,7 +57,7 @@
****************************************************************************/
/****************************************************************************
* Function: uip_polludpconnections
* Function: uip_pollicmp
*
* Description:
* Poll all UDP connections for available packets to send.
@@ -79,7 +79,32 @@ static inline int uip_pollicmp(struct uip_driver_s *dev, uip_poll_callback_t cal
return callback(dev);
}
#endif /* CONFIG_NET_UDP */
#endif /* CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING */
/****************************************************************************
* Function: uip_polligmp
*
* Description:
* Poll all UDP connections for available packets to send.
*
* Assumptions:
* This function is called from the CAN device driver and may be called from
* the timer interrupt/watchdog handle level.
*
****************************************************************************/
#ifdef CONFIG_NET_IGMP
static inline int uip_polligmp(struct uip_driver_s *dev, uip_poll_callback_t callback)
{
/* Perform the UDP TX poll */
uip_igmppoll(dev);
/* Call back into the driver */
return callback(dev);
}
#endif /* CONFIG_NET_IGMP */
/****************************************************************************
* Function: uip_polludpconnections
@@ -226,25 +251,33 @@ int uip_poll(struct uip_driver_s *dev, uip_poll_callback_t callback)
{
int bstop;
/* Traverse all of the active TCP connections and perform the poll action */
/* Check for pendig IGMP messages */
bstop = uip_polltcpconnections(dev, callback);
#ifdef CONFIG_NET_IGMP
bstop = uip_polligmp(dev, callback);
if (!bstop)
#endif
{
#ifdef CONFIG_NET_UDP
/* Traverse all of the allocated UDP connections and perform the poll action */
/* Traverse all of the active TCP connections and perform the poll action */
bstop = uip_polludpconnections(dev, callback);
bstop = uip_polltcpconnections(dev, callback);
if (!bstop)
#endif
{
#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING)
/* Traverse all of the tasks waiting to send an ICMP ECHO request */
#ifdef CONFIG_NET_UDP
/* Traverse all of the allocated UDP connections and perform the poll action */
bstop = uip_pollicmp(dev, callback);
bstop = uip_polludpconnections(dev, callback);
if (!bstop)
#endif
{
#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING)
/* Traverse all of the tasks waiting to send an ICMP ECHO request */
bstop = uip_pollicmp(dev, callback);
#endif
}
}
}
}
return bstop;
}
@@ -254,7 +287,7 @@ int uip_poll(struct uip_driver_s *dev, uip_poll_callback_t callback)
*
* Description:
* These function will traverse each active uIP connection structure and
* perform TCP timer operations (and UDP polling operations). The CAN
* perform TCP timer operations (and UDP polling operations). The Ethernet
* driver MUST implement logic to periodically call uip_timer().
*
* This function will call the provided callback function for every active
@@ -286,23 +319,31 @@ int uip_timer(struct uip_driver_s *dev, uip_poll_callback_t callback, int hsec)
}
#endif /* UIP_REASSEMBLY */
/* Traverse all of the active TCP connections and perform the timer action */
/* Check for pendig IGMP messages */
bstop = uip_polltcptimer(dev, callback, hsec);
#ifdef CONFIG_NET_IGMP
bstop = uip_polligmp(dev, callback);
if (!bstop)
#endif
{
/* Traverse all of the allocated UDP connections and perform the poll action */
/* Traverse all of the active TCP connections and perform the timer action */
bstop = uip_polltcptimer(dev, callback, hsec);
if (!bstop)
{
/* Traverse all of the allocated UDP connections and perform the poll action */
#ifdef CONFIG_NET_UDP
bstop = uip_polludpconnections(dev, callback);
if (!bstop)
bstop = uip_polludpconnections(dev, callback);
if (!bstop)
#endif
{
{
#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING)
/* Traverse all of the tasks waiting to send an ICMP ECHO request */
/* Traverse all of the tasks waiting to send an ICMP ECHO request */
bstop = uip_pollicmp(dev, callback);
bstop = uip_pollicmp(dev, callback);
#endif
}
}
}