summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nuttx/net/uip/Make.defs5
-rwxr-xr-xnuttx/net/uip/uip_igmppoll.c6
-rwxr-xr-xnuttx/net/uip/uip_igmpsend.c164
-rw-r--r--nuttx/net/uip/uip_internal.h4
4 files changed, 171 insertions, 8 deletions
diff --git a/nuttx/net/uip/Make.defs b/nuttx/net/uip/Make.defs
index ec0b06fb8..3c7e2ac23 100644
--- a/nuttx/net/uip/Make.defs
+++ b/nuttx/net/uip/Make.defs
@@ -81,8 +81,9 @@ endif
# IGMP source files
ifeq ($(CONFIG_NET_IGMP),y)
-UIP_CSRCS += uip_igmpinit.c uip_igmpgroup.c uip_igmpinput.c uip_igmpjoin.c \
- uip_igmpleave.c uip_igmpmsg.c uip_igmptimer.c uip_mcastmac.c
+UIP_CSRCS += uip_igmpgroup.c uip_igmpinit.c uip_igmpinput.c uip_igmpjoin.c \
+ uip_igmpleave.c uip_igmpmsg.c uip_igmpsend.c uip_igmptimer.c \
+ uip_mcastmac.c
endif
endif
diff --git a/nuttx/net/uip/uip_igmppoll.c b/nuttx/net/uip/uip_igmppoll.c
index 5d74732fa..9cc9a4384 100755
--- a/nuttx/net/uip/uip_igmppoll.c
+++ b/nuttx/net/uip/uip_igmppoll.c
@@ -58,8 +58,6 @@
* Pre-processor Definitions
****************************************************************************/
-#define IGMPBUF ((struct uip_igmphdr_s *)&dev->d_buf[UIP_LLH_LEN])
-
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -92,7 +90,6 @@ static inline void uip_schedsend(FAR struct uip_driver_s *dev, FAR struct igmp_g
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
@@ -101,12 +98,11 @@ static inline void uip_schedsend(FAR struct uip_driver_s *dev, FAR struct igmp_g
DEBUGASSERT(group->msgid == IGMP_LEAVE_GROUP);
dest = &g_allrouters;
IGMP_STATINCR(uip_stat.igmp.leave_sched);
- uiphdr_ipaddr_copy(IGMPBUF->grpaddr, &group->grpaddr);
}
/* Send the message */
- uip_igmpsend(dev, dest);
+ uip_igmpsend(dev, group, dest);
/* Indicate that the message has been sent */
diff --git a/nuttx/net/uip/uip_igmpsend.c b/nuttx/net/uip/uip_igmpsend.c
new file mode 100755
index 000000000..c815882a4
--- /dev/null
+++ b/nuttx/net/uip/uip_igmpsend.c
@@ -0,0 +1,164 @@
+/****************************************************************************
+ * net/uip/uip_igmpsend.c
+ *
+ * Copyright (C) 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. 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>
+
+#include <net/uip/uipopt.h>
+#include <net/uip/uip.h>
+#include <net/uip/uip-arch.h>
+#include <net/uip/uip-igmp.h>
+
+#include "uip_internal.h"
+
+#ifdef CONFIG_NET_IGMP
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define RASIZE (8)
+#define ROUTERALERT ((uint16_t*)&dev->d_buf[UIP_LLH_LEN])
+#define IGMPBUF ((struct uip_igmphdr_s *)&dev->d_buf[UIP_LLH_LEN + RASIZE])
+#define IGMPPAYLOAD (&dev->d_buf[UIP_LLH_LEN + RASIZE + UIP_IPH_LEN])
+
+/****************************************************************************
+ * Public Variables
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Variables
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static uint16_t uip_igmpchksum(FAR uint8_t *buffer, int buflen)
+{
+ uint16_t sum = uip_chksum((FAR uint16_t*)buffer, buflen);
+ return sum ? sum : 0xffff;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: uip_igmpsend
+ *
+ * Description:
+ * Sends an IGMP IP packet on a network interface. This function constructs
+ * the IP header and calculates the IP header checksum.
+ *
+ * Parameters:
+ * dev - The device driver structure to use in the send operation.
+ * group - Describes the multicast group member and identifies the message
+ * to be sent.
+ * destipaddr - The IP address of the recipient of the message
+ *
+ * Return:
+ * None
+ *
+ * Assumptions:
+ * Called from the interrupt level or with interrupts disabled.
+ *
+ ****************************************************************************/
+
+void uip_igmpsend(FAR struct uip_driver_s *dev, FAR struct igmp_group_s *group,
+ FAR uip_ipaddr_t *destipaddr)
+{
+ /* The total length to send is the size of the IP and IGMP headers and 8
+ * bytes for the ROUTER ALERT (and, eventually, the ethernet header)
+ */
+
+ dev->d_len = UIP_IPIGMPH_LEN + RASIZE;
+
+ /* The total size of the data is the size of the IGMP header */
+
+ dev->d_sndlen = UIP_IGMPH_LEN;
+
+ /* Add the router alert option */
+
+ ROUTERALERT[0] = HTONS(0x9404);
+ ROUTERALERT[1] = 0;
+
+ /* Initialize the IPv4 header */
+
+ IGMPBUF->vhl = 0x45;
+ 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;
+ IGMPBUF->ipoffset[0] = UIP_TCPFLAG_DONTFRAG >> 8;
+ IGMPBUF->ipoffset[1] = UIP_TCPFLAG_DONTFRAG & 0xff;
+ IGMPBUF->ttl = IGMP_TTL;
+ IGMPBUF->proto = UIP_PROTO_IGMP;
+
+ uiphdr_ipaddr_copy(IGMPBUF->srcipaddr, &dev->d_ipaddr);
+ uiphdr_ipaddr_copy(IGMPBUF->destipaddr, destipaddr);
+
+ /* Calculate IP checksum. */
+
+ IGMPBUF->ipchksum = 0;
+ IGMPBUF->ipchksum = ~uip_igmpchksum((FAR uint8_t *)ROUTERALERT, UIP_IPH_LEN + RASIZE);
+
+ /* Set up the IGMP message */
+
+ IGMPBUF->type = group->msgid;
+ IGMPBUF->maxresp = 0;
+ uiphdr_ipaddr_copy(IGMPBUF->grpaddr, &group->grpaddr);
+
+ /* Calculate the IGMP checksum. */
+
+ IGMPBUF->chksum = 0;
+ IGMPBUF->chksum = ~uip_igmpchksum(IGMPPAYLOAD, UIP_IPIGMPH_LEN);
+
+ IGMP_STATINCR(uip_stats.igmp.poll_send);
+ IGMP_STATINCR(uip_stats.ip.sent);
+
+ nllvdbg("Outgoing IGMP packet length: %d (%d)\n",
+ dev->d_len, (IGMPBUF->len[0] << 8) | IGMPBUF->len[1]);
+
+}
+
+#endif /* CONFIG_NET_IGMP */
diff --git a/nuttx/net/uip/uip_internal.h b/nuttx/net/uip/uip_internal.h
index cfa9da85d..02f2d50ec 100644
--- a/nuttx/net/uip/uip_internal.h
+++ b/nuttx/net/uip/uip_internal.h
@@ -241,7 +241,9 @@ 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);
+EXTERN void uip_igmpsend(FAR struct uip_driver_s *dev,
+ FAR struct igmp_group_s *group,
+ FAR uip_ipaddr_t *dest);
/* Defined in uip_igmptimer.c ************************************************/