summaryrefslogtreecommitdiff
path: root/nuttx/net/utils
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/net/utils')
-rw-r--r--nuttx/net/utils/Kconfig3
-rw-r--r--nuttx/net/utils/net_chksum.c49
2 files changed, 40 insertions, 12 deletions
diff --git a/nuttx/net/utils/Kconfig b/nuttx/net/utils/Kconfig
index 412ece03e..112b257e2 100644
--- a/nuttx/net/utils/Kconfig
+++ b/nuttx/net/utils/Kconfig
@@ -20,6 +20,7 @@ config NET_ARCH_CHKSUM
functions with the following prototypes:
uint16_t net_chksum(FAR uint16_t *data, uint16_t len)
- uint16_t ip_chksum(FAR struct net_driver_s *dev)
+ uint16_t ipv4_chksum(FAR struct net_driver_s *dev)
+ uint16_t ipv6_chksum(FAR struct net_driver_s *dev)
uint16_t tcp_chksum(FAR struct net_driver_s *dev);
uint16_t udp_chksum(FAR struct net_driver_s *dev);
diff --git a/nuttx/net/utils/net_chksum.c b/nuttx/net/utils/net_chksum.c
index 14ecc43a5..f2183665e 100644
--- a/nuttx/net/utils/net_chksum.c
+++ b/nuttx/net/utils/net_chksum.c
@@ -1,7 +1,7 @@
/****************************************************************************
* net/utils/net_chksum.c
*
- * Copyright (C) 2007-2010, 2012, 2014 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2010, 2012, 2014-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -123,7 +123,7 @@ static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
#ifdef CONFIG_NET_IPv6
upper_layer_len = (((uint16_t)(pbuf->len[0]) << 8) + pbuf->len[1]);
#else /* CONFIG_NET_IPv6 */
- upper_layer_len = (((uint16_t)(pbuf->len[0]) << 8) + pbuf->len[1]) - IP_HDRLEN;
+ upper_layer_len = (((uint16_t)(pbuf->len[0]) << 8) + pbuf->len[1]) - IPv4_HDRLEN;
#endif /* CONFIG_NET_IPv6 */
/* Verify some minimal assumptions */
@@ -145,7 +145,7 @@ static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
/* Sum TCP header and data. */
- sum = chksum(sum, &dev->d_buf[IP_HDRLEN + NET_LL_HDRLEN(dev)], upper_layer_len);
+ sum = chksum(sum, &dev->d_buf[IPv4_HDRLEN + NET_LL_HDRLEN(dev)], upper_layer_len);
return (sum == 0) ? 0xffff : htons(sum);
}
@@ -264,28 +264,55 @@ uint16_t net_chksum(FAR uint16_t *data, uint16_t len)
#endif /* CONFIG_NET_ARCH_CHKSUM */
/****************************************************************************
- * Name: ip_chksum
+ * Name: ipv4_chksum
*
* Description:
- * Calculate the IP header checksum of the packet header in d_buf.
+ * Calculate the IPv4 header checksum of the packet header in d_buf.
*
- * The IP header checksum is the Internet checksum of the 20 bytes of
- * the IP header.
+ * The IPv4 header checksum is the Internet checksum of the 20 bytes of
+ * the IPv4 header.
*
* If CONFIG_NET_ARCH_CHKSUM is defined, then this function must be
* provided by architecture-specific logic.
*
* Returned Value:
- * The IP header checksum of the IP header in the d_buf buffer.
+ * The IPv4 header checksum of the IPv4 header in the d_buf buffer.
*
****************************************************************************/
-#if !CONFIG_NET_ARCH_CHKSUM
-uint16_t ip_chksum(FAR struct net_driver_s *dev)
+#if defined(CONFIG_NET_IPv4) && !defined(CONFIG_NET_ARCH_CHKSUM)
+uint16_t ipv4_chksum(FAR struct net_driver_s *dev)
+{
+ uint16_t sum;
+
+ sum = chksum(0, &dev->d_buf[NET_LL_HDRLEN(dev)], IPv4_HDRLEN);
+ return (sum == 0) ? 0xffff : htons(sum);
+}
+#endif /* CONFIG_NET_ARCH_CHKSUM */
+
+/****************************************************************************
+ * Name: ipv6_chksum
+ *
+ * Description:
+ * Calculate the IPv6 header checksum of the packet header in d_buf.
+ *
+ * The IPv6 header checksum is the Internet checksum of the 40 bytes of
+ * the IPv6 header.
+ *
+ * If CONFIG_NET_ARCH_CHKSUM is defined, then this function must be
+ * provided by architecture-specific logic.
+ *
+ * Returned Value:
+ * The IPv6 header checksum of the IPv6 header in the d_buf buffer.
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_NET_IPv6) && !defined(CONFIG_NET_ARCH_CHKSUM)
+uint16_t ipv6_chksum(FAR struct net_driver_s *dev)
{
uint16_t sum;
- sum = chksum(0, &dev->d_buf[NET_LL_HDRLEN(dev)], IP_HDRLEN);
+ sum = chksum(0, &dev->d_buf[NET_LL_HDRLEN(dev)], IPv6_HDRLEN);
return (sum == 0) ? 0xffff : htons(sum);
}
#endif /* CONFIG_NET_ARCH_CHKSUM */