summaryrefslogtreecommitdiff
path: root/nuttx/net
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-07-10 19:47:37 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-07-10 19:47:37 +0000
commit4f007a4360e1bf2879e39de021e81cb013c50466 (patch)
tree502477ef2ef13ee5af457368fd5a6b473067b228 /nuttx/net
parentc4680a4704fd377f4c89e0b8f6149f3aec8b39fb (diff)
downloadpx4-nuttx-4f007a4360e1bf2879e39de021e81cb013c50466.tar.gz
px4-nuttx-4f007a4360e1bf2879e39de021e81cb013c50466.tar.bz2
px4-nuttx-4f007a4360e1bf2879e39de021e81cb013c50466.zip
Add IGMP timer logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2782 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net')
-rw-r--r--nuttx/net/uip/Make.defs13
-rwxr-xr-xnuttx/net/uip/uip_igmpgroup.c2
-rwxr-xr-xnuttx/net/uip/uip_igmpinit.c2
-rwxr-xr-xnuttx/net/uip/uip_igmpleave.c12
-rwxr-xr-xnuttx/net/uip/uip_igmptimer.c208
-rw-r--r--nuttx/net/uip/uip_internal.h5
6 files changed, 233 insertions, 9 deletions
diff --git a/nuttx/net/uip/Make.defs b/nuttx/net/uip/Make.defs
index e51b46457..f3686dfd2 100644
--- a/nuttx/net/uip/Make.defs
+++ b/nuttx/net/uip/Make.defs
@@ -52,8 +52,8 @@ endif
ifeq ($(CONFIG_NET_TCP),y)
UIP_CSRCS += uip_tcpconn.c uip_tcpseqno.c uip_tcppoll.c uip_tcptimer.c uip_tcpsend.c \
- uip_tcpinput.c uip_tcpappsend.c uip_listen.c uip_tcpcallback.c \
- uip_tcpreadahead.c uip_tcpbacklog.c
+ uip_tcpinput.c uip_tcpappsend.c uip_listen.c uip_tcpcallback.c \
+ uip_tcpreadahead.c uip_tcpbacklog.c
endif
@@ -62,11 +62,11 @@ endif
ifeq ($(CONFIG_NET_UDP),y)
UIP_CSRCS += uip_udpconn.c uip_udppoll.c uip_udpsend.c uip_udpinput.c \
- uip_udpcallback.c
+ uip_udpcallback.c
endif
-#ICMP source files
+# ICMP source files
ifeq ($(CONFIG_NET_ICMP),y)
@@ -78,8 +78,11 @@ UIP_CSRCS += uip_icmpping.c uip_icmppoll.c uip_icmpsend.c
endif
endif
+# IGMP source files
+
ifeq ($(CONFIG_NET_IGMP),y)
-UIP_CSRCS += uip_igmpinit.c uip_igmpgroup.c uip_igmpjoin.c uip_igmpleave.c uip_igmpmsg.c
+UIP_CSRCS += uip_igmpinit.c uip_igmpgroup.c uip_igmpjoin.c uip_igmpleave.c \
+ uip_igmpmsg.c uip_igmptimer.c
endif
endif
diff --git a/nuttx/net/uip/uip_igmpgroup.c b/nuttx/net/uip/uip_igmpgroup.c
index 62d3a7a5d..9a75fd8d0 100755
--- a/nuttx/net/uip/uip_igmpgroup.c
+++ b/nuttx/net/uip/uip_igmpgroup.c
@@ -277,7 +277,7 @@ void uip_grpfree(FAR struct uip_driver_s *dev, FAR struct igmp_group_s *group)
*/
irqstate_t flags = irqsave();
- DEBUGASSERT(sq_rem((FAR sq_entry_t*)group, &dev->grplist) != NULL);
+ sq_rem((FAR sq_entry_t*)group, &dev->grplist);
/* Destroy the wait semapore */
diff --git a/nuttx/net/uip/uip_igmpinit.c b/nuttx/net/uip/uip_igmpinit.c
index 87c0d4e78..5c1dbdc68 100755
--- a/nuttx/net/uip/uip_igmpinit.c
+++ b/nuttx/net/uip/uip_igmpinit.c
@@ -107,7 +107,7 @@ void uip_igmpdevinit(struct uip_driver_s *dev)
struct igmp_group_s *group;
nvdbg("IGMP initializing dev %p\n", dev);
- DEBUGASSERT(dev->grplist == NULL);
+ DEBUGASSERT(dev->grplist.head == NULL);
/* Add the all systems address to the group */
diff --git a/nuttx/net/uip/uip_igmpleave.c b/nuttx/net/uip/uip_igmpleave.c
index 22775ede8..a220662fd 100755
--- a/nuttx/net/uip/uip_igmpleave.c
+++ b/nuttx/net/uip/uip_igmpleave.c
@@ -130,15 +130,25 @@
void igmp_leavegroup(struct uip_driver_s *dev, uip_ipaddr_t *grpaddr)
{
struct igmp_group_s *group;
+ irqstate_t flags;
/* Find the entry corresponding to the address leaving the group */
group = uip_grpfind(dev, grpaddr);
if (group)
{
- /* Cancel the timer */
+ /* 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 */
diff --git a/nuttx/net/uip/uip_igmptimer.c b/nuttx/net/uip/uip_igmptimer.c
new file mode 100755
index 000000000..2e2c3cbb1
--- /dev/null
+++ b/nuttx/net/uip/uip_igmptimer.c
@@ -0,0 +1,208 @@
+/****************************************************************************
+ * 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
+ ****************************************************************************/
+
+/****************************************************************************
+ * 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 */
+
+ nvdbg("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);
+ }
+}
+
+/****************************************************************************
+ * 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)
+{
+ /* Start the timer */
+
+ wd_start(group->wdog, ticks, uip_igmptimeout, 1, (uint32_t)group);
+}
+
+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
+ */
+
+ 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.
+ */
+
+ 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 */
diff --git a/nuttx/net/uip/uip_internal.h b/nuttx/net/uip/uip_internal.h
index 9148a4ab2..49ab4ea24 100644
--- a/nuttx/net/uip/uip_internal.h
+++ b/nuttx/net/uip/uip_internal.h
@@ -245,7 +245,10 @@ EXTERN void uip_igmpsend(FAR struct uip_driver_s *dev, uip_ipaddr_t *dest);
/* Defined in uip_igmptimer.c ************************************************/
-EXTERN void uip_igmpstarttimer(struct igmp_group_s *group, uint8_t decisecs);
+EXTERN int uip_decisec2tick(int decisecs);
+EXTERN void uip_igmpstartticks(FAR struct igmp_group_s *group, int ticks);
+EXTERN void uip_igmpstarttimer(FAR struct igmp_group_s *group, uint8_t decisecs);
+EXTERN bool uip_igmpcmptimer(FAR struct igmp_group_s *group, int maxticks);
/* Defined in TBD ************************************************************/