2010-07-11 17:57:11 +02:00
|
|
|
/****************************************************************************
|
2014-05-30 21:05:19 +02:00
|
|
|
* net/igmp/igmp_send.c
|
2010-07-11 17:57:11 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
|
2012-09-13 20:32:24 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2010-07-11 17:57:11 +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 NuttX 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 THE COPYRIGHT HOLDERS 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 THE
|
|
|
|
* COPYRIGHT OWNER 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 <debug.h>
|
2010-07-13 04:29:09 +02:00
|
|
|
#include <arpa/inet.h>
|
2010-07-11 17:57:11 +02:00
|
|
|
|
2014-06-24 16:53:28 +02:00
|
|
|
#include <nuttx/net/netconfig.h>
|
2014-06-24 17:28:44 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
2014-06-26 17:32:39 +02:00
|
|
|
#include <nuttx/net/netstats.h>
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <nuttx/net/ip.h>
|
2014-07-05 00:44:53 +02:00
|
|
|
#include <nuttx/net/ipopt.h>
|
2014-07-06 20:34:27 +02:00
|
|
|
#include <nuttx/net/tcp.h>
|
2014-06-24 18:14:15 +02:00
|
|
|
#include <nuttx/net/igmp.h>
|
2010-07-11 17:57:11 +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"
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-07-13 04:29:09 +02:00
|
|
|
/* Debug */
|
|
|
|
|
|
|
|
#undef IGMP_DUMPPKT /* Define to enable packet dump */
|
|
|
|
|
|
|
|
#ifndef CONFIG_DEBUG_NET
|
|
|
|
# undef IGMP_DUMPPKT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IGMP_DUMPPKT
|
|
|
|
# define igmp_dumppkt(b,n) lib_dumpbuffer("IGMP", (FAR const uint8_t*)(b), (n))
|
|
|
|
#else
|
|
|
|
# define igmp_dumppkt(b,n)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Buffer layout */
|
|
|
|
|
|
|
|
#define RASIZE (4)
|
2014-11-15 20:13:23 +01:00
|
|
|
#define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Variables
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Variables
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2014-06-25 17:52:36 +02:00
|
|
|
static uint16_t igmp_chksum(FAR uint8_t *buffer, int buflen)
|
2010-07-11 17:57:11 +02:00
|
|
|
{
|
2014-06-28 01:51:32 +02:00
|
|
|
uint16_t sum = net_chksum((FAR uint16_t*)buffer, buflen);
|
2010-07-11 17:57:11 +02:00
|
|
|
return sum ? sum : 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-06-25 17:52:36 +02:00
|
|
|
* Name: igmp_send
|
2010-07-11 17:57:11 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Sends an IGMP IP packet on a network interface. This function constructs
|
|
|
|
* the IP header and calculates the IP header checksum.
|
|
|
|
*
|
|
|
|
* Parameters:
|
2014-04-12 20:13:01 +02:00
|
|
|
* dev - The device driver structure to use in the send operation.
|
|
|
|
* group - Describes the multicast group member and identifies the
|
|
|
|
* message to be sent.
|
2010-07-11 17:57:11 +02:00
|
|
|
* destipaddr - The IP address of the recipient of the message
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from the interrupt level or with interrupts disabled.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
void igmp_send(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group,
|
2014-06-29 20:22:50 +02:00
|
|
|
FAR net_ipaddr_t *destipaddr)
|
2010-07-11 17:57:11 +02:00
|
|
|
{
|
2010-07-13 05:43:06 +02:00
|
|
|
nllvdbg("msgid: %02x destipaddr: %08x\n", group->msgid, (int)*destipaddr);
|
2010-07-13 04:29:09 +02:00
|
|
|
|
2010-07-13 05:43:06 +02:00
|
|
|
/* The total length to send is the size of the IP and IGMP headers and 4
|
2014-04-12 20:13:01 +02:00
|
|
|
* bytes for the ROUTER ALERT (and, eventually, the Ethernet header)
|
2010-07-11 17:57:11 +02:00
|
|
|
*/
|
|
|
|
|
2014-07-05 21:04:48 +02:00
|
|
|
dev->d_len = IPIGMP_HDRLEN;
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
/* The total size of the data is the size of the IGMP header */
|
|
|
|
|
2014-07-05 21:04:48 +02:00
|
|
|
dev->d_sndlen = IGMP_HDRLEN;
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
/* Add the router alert option */
|
|
|
|
|
2010-07-14 03:57:00 +02:00
|
|
|
IGMPBUF->ra[0] = HTONS(IPOPT_RA >> 16);
|
|
|
|
IGMPBUF->ra[1] = HTONS(IPOPT_RA & 0xffff);
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
/* Initialize the IPv4 header */
|
|
|
|
|
2010-07-13 05:43:06 +02:00
|
|
|
IGMPBUF->vhl = 0x46; /* 4->IP; 6->24 bytes */
|
2010-07-11 17:57:11 +02:00
|
|
|
IGMPBUF->tos = 0;
|
|
|
|
IGMPBUF->len[0] = (dev->d_len >> 8);
|
|
|
|
IGMPBUF->len[1] = (dev->d_len & 0xff);
|
|
|
|
++g_ipid;
|
|
|
|
IGMPBUF->ipid[0] = g_ipid >> 8;
|
|
|
|
IGMPBUF->ipid[1] = g_ipid & 0xff;
|
2014-11-18 00:16:46 +01:00
|
|
|
IGMPBUF->ipoffset[0] = IP_FLAG_DONTFRAG >> 8;
|
|
|
|
IGMPBUF->ipoffset[1] = IP_FLAG_DONTFRAG & 0xff;
|
2010-07-11 17:57:11 +02:00
|
|
|
IGMPBUF->ttl = IGMP_TTL;
|
2014-07-05 03:13:08 +02:00
|
|
|
IGMPBUF->proto = IP_PROTO_IGMP;
|
2010-07-11 17:57:11 +02:00
|
|
|
|
2014-06-29 21:20:00 +02:00
|
|
|
net_ipaddr_hdrcopy(IGMPBUF->srcipaddr, &dev->d_ipaddr);
|
|
|
|
net_ipaddr_hdrcopy(IGMPBUF->destipaddr, destipaddr);
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
/* Calculate IP checksum. */
|
|
|
|
|
|
|
|
IGMPBUF->ipchksum = 0;
|
2014-07-05 21:04:48 +02:00
|
|
|
IGMPBUF->ipchksum = ~igmp_chksum((FAR uint8_t *)IGMPBUF, IP_HDRLEN + RASIZE);
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
/* Set up the IGMP message */
|
|
|
|
|
2010-07-14 19:09:45 +02:00
|
|
|
IGMPBUF->type = group->msgid;
|
|
|
|
IGMPBUF->maxresp = 0;
|
2014-06-29 21:20:00 +02:00
|
|
|
net_ipaddr_hdrcopy(IGMPBUF->grpaddr, &group->grpaddr);
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
/* Calculate the IGMP checksum. */
|
|
|
|
|
2010-07-14 19:09:45 +02:00
|
|
|
IGMPBUF->chksum = 0;
|
2014-07-05 21:04:48 +02:00
|
|
|
IGMPBUF->chksum = ~igmp_chksum(&IGMPBUF->type, IPIGMP_HDRLEN);
|
2010-07-11 17:57:11 +02:00
|
|
|
|
2014-06-26 17:32:39 +02:00
|
|
|
IGMP_STATINCR(g_netstats.igmp.poll_send);
|
|
|
|
IGMP_STATINCR(g_netstats.ip.sent);
|
2010-07-11 17:57:11 +02:00
|
|
|
|
|
|
|
nllvdbg("Outgoing IGMP packet length: %d (%d)\n",
|
|
|
|
dev->d_len, (IGMPBUF->len[0] << 8) | IGMPBUF->len[1]);
|
2014-07-05 21:04:48 +02:00
|
|
|
igmp_dumppkt(RA, IPIGMP_HDRLEN + RASIZE);
|
2010-07-11 17:57:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_IGMP */
|