summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-07-10 01:20:34 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-07-10 01:20:34 +0000
commita87d861c4e0a60e1dc163f58c1b51eec13ababf3 (patch)
tree1af27a7970d534e9f1ea8eda093db55d33b4e5a8
parenta69ce203b81d4903167141ee1c60a643b10fcce4 (diff)
downloadnuttx-a87d861c4e0a60e1dc163f58c1b51eec13ababf3.tar.gz
nuttx-a87d861c4e0a60e1dc163f58c1b51eec13ababf3.tar.bz2
nuttx-a87d861c4e0a60e1dc163f58c1b51eec13ababf3.zip
More IGMP logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2780 42af7a65-404d-4744-a932-0658087f49c3
-rwxr-xr-xnuttx/include/net/uip/uip-igmp.h47
-rw-r--r--nuttx/include/net/uip/uip.h19
-rw-r--r--nuttx/net/uip/Make.defs2
-rw-r--r--nuttx/net/uip/uip_chksum.c3
-rw-r--r--nuttx/net/uip/uip_icmpping.c2
-rwxr-xr-xnuttx/net/uip/uip_igmpgroup.c3
-rwxr-xr-xnuttx/net/uip/uip_igmpinit.c3
-rwxr-xr-xnuttx/net/uip/uip_igmppoll.c161
-rw-r--r--nuttx/net/uip/uip_internal.h10
-rw-r--r--nuttx/net/uip/uip_poll.c83
10 files changed, 283 insertions, 50 deletions
diff --git a/nuttx/include/net/uip/uip-igmp.h b/nuttx/include/net/uip/uip-igmp.h
index 4b7db8fc1..dd540d903 100755
--- a/nuttx/include/net/uip/uip-igmp.h
+++ b/nuttx/include/net/uip/uip-igmp.h
@@ -50,7 +50,6 @@
#include <stdint.h>
#include <stdbool.h>
-#include <wdog.h>
#include <netinet/in.h>
@@ -84,25 +83,29 @@
#define UIP_IGMPH_LEN 8
#define UIP_IPIGMPH_LEN (UIP_IGMPH_LEN + UIP_IPH_LEN)
-/* Group membership states */
-
-#define IGMP_NON_MEMBER 0
-#define IGMP_DELAYING_MEMBER 1
-#define IGMP_IDLE_MEMBER 2
-
/* Group flags */
-#define IGMP_PREALLOCATED 1
-#define IGMP_LASTREPORT 2
+#define IGMP_PREALLOCATED (1 << 0)
+#define IGMP_LASTREPORT (1 << 1)
+#define IGMP_IDLEMEMBER (1 << 2)
+#define IGMP_SCHEDMSG (1 << 3)
#define SET_PREALLOCATED(f) do { (f) |= IGMP_PREALLOCATED; } while (0)
#define SET_LASTREPORT(f) do { (f) |= IGMP_LASTREPORT; } while (0)
+#define SET_IDLEMEMBER(f) do { (f) |= IGMP_IDLEMEMBER; } while (0)
+#define SET_SCHEDMSG(f) do { (f) |= IGMP_IDLEMEMBER; } while (0)
#define CLR_PREALLOCATED(f) do { (f) &= ~IGMP_PREALLOCATED; } while (0)
#define CLR_LASTREPORT(f) do { (f) &= ~IGMP_LASTREPORT; } while (0)
+#define CLR_IDLEMEMBER(f) do { (f) &= ~IGMP_LASTREPORT; } while (0)
+#define CLR_SCHEDMSG(f) do { (f) &= ~IGMP_LASTREPORT; } while (0)
#define IS_PREALLOCATED(f) (((f) & IGMP_PREALLOCATED) != 0)
#define IS_LASTREPORT(f) (((f) & IGMP_LASTREPORT) != 0)
+#define IS_IDLEMEMBER(f) (((f) & IGMP_LASTREPORT) != 0)
+#define IS_SCHEDMSG(f) (((f) & IGMP_LASTREPORT) != 0)
+
+#define IGMP_TTL 1
/****************************************************************************
* Public Types
@@ -148,7 +151,16 @@ struct uip_igmphdr_s
#endif /* CONFIG_NET_IPv6 */
- /* IGMP header */
+ /* IGMP header:
+ *
+ * 0 1 2 3
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Type | Max Resp Time | Checksum |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Group Address |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
uint8_t type; /* 8-bit IGMP packet type */
uint8_t maxresp; /* 8-bit Max response time */
@@ -156,16 +168,17 @@ struct uip_igmphdr_s
uint16_t grpaddr[2]; /* 32-bit Group address */
};
-#ifdef CONFIG_NET_IGMP_STATS
-struct igmp_stats_s
+#ifdef CONFIG_NET_STATISTICS
+struct uip_igmp_stats_s
{
uint32_t length_errors;
uint32_t chksum_errors;
uint32_t v1_received;
uint32_t joins;
- uint32_t leave_sent;
+ uint32_t leave_sched;
+ uint32_t report_sched;
+ uint32_t poll_send;
uint32_t ucast_query;
- uint32_t report_sent;
uint32_t query_received;
uint32_t report_received;
};
@@ -183,13 +196,13 @@ struct igmp_stats_s
* from all the other groups
*/
+typedef FAR struct wdog_s *WDOG_ID;
struct igmp_group_s
{
struct igmp_group_s *next; /* Implements a singly-linked list */
uip_ipaddr_t grpaddr; /* Group IP address */
WDOG_ID wdog; /* WDOG used to detect timeouts */
uint8_t flags; /* See IGMP_ flags definitions */
- uint8_t state; /* State of the group */
uint8_t msgid; /* Pending message ID (if non-zero) */
};
@@ -205,10 +218,6 @@ extern "C" {
#define EXTERN extern
#endif
-#ifdef CONFIG_NET_IGMP_STATS
-struct igmp_stats_s g_igmpstats;
-#endif
-
extern uip_ipaddr_t g_allsystems;
extern uip_ipaddr_t g_allrouters;
diff --git a/nuttx/include/net/uip/uip.h b/nuttx/include/net/uip/uip.h
index 4589838a0..3633a42a8 100644
--- a/nuttx/include/net/uip/uip.h
+++ b/nuttx/include/net/uip/uip.h
@@ -222,9 +222,18 @@ struct uip_callback_s
/* Protocol-specific support */
-#include <net/uip/uip-tcp.h>
-#include <net/uip/uip-udp.h>
-#include <net/uip/uip-icmp.h>
+#ifdef CONFIG_NET_TCP
+# include <net/uip/uip-tcp.h>
+#endif
+#ifdef CONFIG_NET_UDP
+# include <net/uip/uip-udp.h>
+#endif
+#ifdef CONFIG_NET_ICMP
+# include <net/uip/uip-icmp.h>
+#endif
+#ifdef CONFIG_NET_IGMP
+# include <net/uip/uip-igmp.h>
+#endif
/* The structure holding the uIP statistics that are gathered if
* CONFIG_NET_STATISTICS is defined.
@@ -258,6 +267,10 @@ struct uip_stats
struct uip_icmp_stats_s icmp; /* ICMP statistics */
#endif
+#ifdef CONFIG_NET_IGMP
+ struct uip_igmp_stats_s igmp; /* IGMP statistics */
+#endif
+
#ifdef CONFIG_NET_TCP
struct uip_tcp_stats_s tcp; /* TCP statistics */
#endif
diff --git a/nuttx/net/uip/Make.defs b/nuttx/net/uip/Make.defs
index 4f94b4eab..422107318 100644
--- a/nuttx/net/uip/Make.defs
+++ b/nuttx/net/uip/Make.defs
@@ -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)
diff --git a/nuttx/net/uip/uip_chksum.c b/nuttx/net/uip/uip_chksum.c
index 538e56a04..4bddf3fbc 100644
--- a/nuttx/net/uip/uip_chksum.c
+++ b/nuttx/net/uip/uip_chksum.c
@@ -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:
diff --git a/nuttx/net/uip/uip_icmpping.c b/nuttx/net/uip/uip_icmpping.c
index b235edf09..b83b8b106 100644
--- a/nuttx/net/uip/uip_icmpping.c
+++ b/nuttx/net/uip/uip_icmpping.c
@@ -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
diff --git a/nuttx/net/uip/uip_igmpgroup.c b/nuttx/net/uip/uip_igmpgroup.c
index 295800941..f51b8d542 100755
--- a/nuttx/net/uip/uip_igmpgroup.c
+++ b/nuttx/net/uip/uip_igmpgroup.c
@@ -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);
}
}
diff --git a/nuttx/net/uip/uip_igmpinit.c b/nuttx/net/uip/uip_igmpinit.c
index 9dceb0134..87c0d4e78 100755
--- a/nuttx/net/uip/uip_igmpinit.c
+++ b/nuttx/net/uip/uip_igmpinit.c
@@ -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) */
diff --git a/nuttx/net/uip/uip_igmppoll.c b/nuttx/net/uip/uip_igmppoll.c
new file mode 100755
index 000000000..7ba4b50a0
--- /dev/null
+++ b/nuttx/net/uip/uip_igmppoll.c
@@ -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 */
diff --git a/nuttx/net/uip/uip_internal.h b/nuttx/net/uip/uip_internal.h
index 8570fba5b..43f1771b1 100644
--- a/nuttx/net/uip/uip_internal.h
+++ b/nuttx/net/uip/uip_internal.h
@@ -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);
diff --git a/nuttx/net/uip/uip_poll.c b/nuttx/net/uip/uip_poll.c
index 21b8a0df0..bb45cb943 100644
--- a/nuttx/net/uip/uip_poll.c
+++ b/nuttx/net/uip/uip_poll.c
@@ -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
{
+#ifdef CONFIG_NET_UDP
+ /* Traverse all of the allocated UDP connections and perform the poll action */
+
+ 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
+ }
}
- }
+ }
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 */
-#ifdef CONFIG_NET_UDP
- bstop = uip_polludpconnections(dev, callback);
+ bstop = uip_polltcptimer(dev, callback, hsec);
if (!bstop)
-#endif
{
+ /* Traverse all of the allocated UDP connections and perform the poll action */
+
+#ifdef CONFIG_NET_UDP
+ 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
+ }
}
}