2010-07-14 19:17:39 +02:00
|
|
|
/****************************************************************************
|
2014-05-30 21:05:19 +02:00
|
|
|
* net/igmp/igmp_timer.c
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
2018-11-04 14:43:51 +01:00
|
|
|
* Copyright (C) 2010-2011, 2014, 2018 Gregory Nutt. All rights reserved.
|
2012-09-13 20:32:24 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2014-04-13 22:32:20 +02:00
|
|
|
* 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.
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
2014-04-13 22:32:20 +02:00
|
|
|
* 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.
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2014-08-21 19:16:55 +02:00
|
|
|
#include <nuttx/wdog.h>
|
2017-09-02 18:27:03 +02:00
|
|
|
#include <nuttx/irq.h>
|
2018-11-04 14:43:51 +01:00
|
|
|
#include <nuttx/wqueue.h>
|
2014-06-24 16:53:28 +02:00
|
|
|
#include <nuttx/net/netconfig.h>
|
2014-07-05 00:38:51 +02:00
|
|
|
#include <nuttx/net/net.h>
|
2014-06-26 17:32:39 +02:00
|
|
|
#include <nuttx/net/netstats.h>
|
2014-06-24 18:14:15 +02:00
|
|
|
#include <nuttx/net/igmp.h>
|
2010-07-14 19:17:39 +02:00
|
|
|
|
2014-06-29 02:07:02 +02:00
|
|
|
#include "devif/devif.h"
|
2014-06-25 17:52:36 +02:00
|
|
|
#include "igmp/igmp.h"
|
2014-07-05 23:15:40 +02:00
|
|
|
#include "utils/utils.h"
|
2010-07-14 19:17:39 +02:00
|
|
|
|
|
|
|
#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
|
2016-06-11 23:50:49 +02:00
|
|
|
# define gtmrerr(format, ...) nerr(format, ##__VA_ARGS__)
|
2016-06-11 19:59:51 +02:00
|
|
|
# define gtmrinfo(format, ...) ninfo(format, ##__VA_ARGS__)
|
2010-07-14 19:17:39 +02:00
|
|
|
# else
|
2016-06-11 23:50:49 +02:00
|
|
|
# define gtmrerr(x...)
|
2016-06-11 19:59:51 +02:00
|
|
|
# define gtmrinfo(x...)
|
2010-07-14 19:17:39 +02:00
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# ifdef IGMP_GTMRDEBUG
|
2016-06-11 23:50:49 +02:00
|
|
|
# define gtmrerr nerr
|
2016-06-11 19:59:51 +02:00
|
|
|
# define gtmrinfo ninfo
|
2010-07-14 19:17:39 +02:00
|
|
|
# else
|
2016-06-11 23:50:49 +02:00
|
|
|
# define gtmrerr (void)
|
2016-06-11 19:59:51 +02:00
|
|
|
# define gtmrinfo (void)
|
2010-07-14 19:17:39 +02:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-11-04 14:43:51 +01:00
|
|
|
* Name: igmp_timeout_work
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-11-04 14:43:51 +01:00
|
|
|
* Timeout watchdog work.
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
* Assumptions:
|
2018-11-04 14:43:51 +01:00
|
|
|
* This function is called from a work queue thread.
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-11-04 14:43:51 +01:00
|
|
|
static void igmp_timeout_work(FAR void *arg)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
|
|
|
FAR struct igmp_group_s *group;
|
2018-11-04 14:43:51 +01:00
|
|
|
int ret;
|
2010-07-14 19:17:39 +02:00
|
|
|
|
|
|
|
/* If the state is DELAYING_MEMBER then we send a report for this group */
|
|
|
|
|
|
|
|
group = (FAR struct igmp_group_s *)arg;
|
2018-11-04 14:43:51 +01:00
|
|
|
DEBUGASSERT(group != NULL);
|
2010-07-14 19:17:39 +02:00
|
|
|
|
|
|
|
/* 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)
|
2014-04-12 20:13:01 +02:00
|
|
|
* the timer is cancelled before sending the IGMP_LEAVE_GROUP during a leave.
|
2010-07-14 19:17:39 +02:00
|
|
|
*/
|
|
|
|
|
2018-11-04 14:43:51 +01:00
|
|
|
net_lock();
|
2010-07-14 19:17:39 +02:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2014-06-26 17:32:39 +02:00
|
|
|
IGMP_STATINCR(g_netstats.igmp.report_sched);
|
2018-11-04 14:43:51 +01:00
|
|
|
ret = igmp_schedmsg(group, IGMPv2_MEMBERSHIP_REPORT);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to schedule message: %d\n", ret);
|
|
|
|
}
|
2010-07-14 19:17:39 +02:00
|
|
|
|
|
|
|
/* 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
|
2014-04-12 20:13:01 +02:00
|
|
|
* once or twice after short delays [Unsolicited Report Interval]..."
|
2010-07-14 19:17:39 +02:00
|
|
|
*/
|
|
|
|
}
|
2018-11-04 14:43:51 +01:00
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: igmp_timeout
|
|
|
|
*
|
|
|
|
* 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 igmp_timeout(int argc, uint32_t arg, ...)
|
|
|
|
{
|
|
|
|
FAR struct igmp_group_s *group;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ninfo("Timeout!\n");
|
|
|
|
|
|
|
|
/* Recover the reference to the group */
|
|
|
|
|
|
|
|
group = (FAR struct igmp_group_s *)arg;
|
|
|
|
DEBUGASSERT(argc == 1 && group != NULL);
|
|
|
|
|
|
|
|
/* Perform the timeout-related operations on (preferably) the low priority
|
|
|
|
* work queue.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = work_queue(LPWORK, &group->work, igmp_timeout_work, group, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to queue timeout work: %d\n", ret);
|
|
|
|
}
|
2010-07-14 19:17:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-06-25 17:52:36 +02:00
|
|
|
* Name: igmp_startticks and igmp_starttimer
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Start the IGMP timer with differing time units (ticks or deciseconds).
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from most any context.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-07-05 23:15:40 +02:00
|
|
|
void igmp_startticks(FAR struct igmp_group_s *group, unsigned int ticks)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Start the timer */
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
gtmrinfo("ticks: %d\n", ticks);
|
2014-04-12 20:13:01 +02:00
|
|
|
|
2014-06-25 17:52:36 +02:00
|
|
|
ret = wd_start(group->wdog, ticks, igmp_timeout, 1, (uint32_t)group);
|
2014-04-12 20:13:01 +02:00
|
|
|
|
2010-07-14 19:17:39 +02:00
|
|
|
DEBUGASSERT(ret == OK);
|
2014-04-12 20:13:01 +02:00
|
|
|
UNUSED(ret);
|
2010-07-14 19:17:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-25 17:52:36 +02:00
|
|
|
void igmp_starttimer(FAR struct igmp_group_s *group, uint8_t decisecs)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
|
|
|
/* Convert the decisec value to system clock ticks and start the timer.
|
|
|
|
* Important!! this should be a random timer from 0 to decisecs
|
|
|
|
*/
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2016-06-12 01:37:21 +02:00
|
|
|
gtmrinfo("decisecs: %d\n", decisecs);
|
2014-07-05 23:15:40 +02:00
|
|
|
igmp_startticks(group, net_dsec2tick(decisecs));
|
2010-07-14 19:17:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-06-25 17:52:36 +02:00
|
|
|
* Name: igmp_cmptimer
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
* 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:
|
2014-04-12 20:13:01 +02:00
|
|
|
* This function may be called from most any context. If true is returned
|
2014-06-25 17:52:36 +02:00
|
|
|
* then the caller must call igmp_startticks() to restart the timer
|
2010-07-14 19:17:39 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-25 17:52:36 +02:00
|
|
|
bool igmp_cmptimer(FAR struct igmp_group_s *group, int maxticks)
|
2010-07-14 19:17:39 +02:00
|
|
|
{
|
2017-09-02 18:27:03 +02:00
|
|
|
irqstate_t flags;
|
2010-07-14 19:17:39 +02:00
|
|
|
int remaining;
|
|
|
|
|
|
|
|
/* Disable interrupts so that there is no race condition with the actual
|
|
|
|
* timer expiration.
|
|
|
|
*/
|
|
|
|
|
2017-09-02 18:27:03 +02:00
|
|
|
flags = enter_critical_section();
|
2010-07-14 19:17:39 +02:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2016-06-12 01:37:21 +02:00
|
|
|
gtmrinfo("maxticks: %d remaining: %d\n", maxticks, remaining);
|
2010-07-14 19:17:39 +02:00
|
|
|
if (maxticks > remaining)
|
|
|
|
{
|
|
|
|
/* Cancel the watchdog timer and return true */
|
|
|
|
|
|
|
|
wd_cancel(group->wdog);
|
2017-09-02 18:27:03 +02:00
|
|
|
leave_critical_section(flags);
|
2010-07-14 19:17:39 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-02 18:27:03 +02:00
|
|
|
leave_critical_section(flags);
|
2010-07-14 19:17:39 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_IGMP */
|