1*10465441SEvalZero /** 2*10465441SEvalZero * @file 3*10465441SEvalZero * IP checksum calculation functions 4*10465441SEvalZero */ 5*10465441SEvalZero 6*10465441SEvalZero /* 7*10465441SEvalZero * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 8*10465441SEvalZero * All rights reserved. 9*10465441SEvalZero * 10*10465441SEvalZero * Redistribution and use in source and binary forms, with or without modification, 11*10465441SEvalZero * are permitted provided that the following conditions are met: 12*10465441SEvalZero * 13*10465441SEvalZero * 1. Redistributions of source code must retain the above copyright notice, 14*10465441SEvalZero * this list of conditions and the following disclaimer. 15*10465441SEvalZero * 2. Redistributions in binary form must reproduce the above copyright notice, 16*10465441SEvalZero * this list of conditions and the following disclaimer in the documentation 17*10465441SEvalZero * and/or other materials provided with the distribution. 18*10465441SEvalZero * 3. The name of the author may not be used to endorse or promote products 19*10465441SEvalZero * derived from this software without specific prior written permission. 20*10465441SEvalZero * 21*10465441SEvalZero * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 22*10465441SEvalZero * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23*10465441SEvalZero * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 24*10465441SEvalZero * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25*10465441SEvalZero * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26*10465441SEvalZero * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27*10465441SEvalZero * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28*10465441SEvalZero * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29*10465441SEvalZero * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 30*10465441SEvalZero * OF SUCH DAMAGE. 31*10465441SEvalZero * 32*10465441SEvalZero * This file is part of the lwIP TCP/IP stack. 33*10465441SEvalZero * 34*10465441SEvalZero * Author: Adam Dunkels <[email protected]> 35*10465441SEvalZero * 36*10465441SEvalZero */ 37*10465441SEvalZero #ifndef LWIP_HDR_INET_CHKSUM_H 38*10465441SEvalZero #define LWIP_HDR_INET_CHKSUM_H 39*10465441SEvalZero 40*10465441SEvalZero #include "lwip/opt.h" 41*10465441SEvalZero 42*10465441SEvalZero #include "lwip/pbuf.h" 43*10465441SEvalZero #include "lwip/ip_addr.h" 44*10465441SEvalZero 45*10465441SEvalZero /** Swap the bytes in an u16_t: much like lwip_htons() for little-endian */ 46*10465441SEvalZero #ifndef SWAP_BYTES_IN_WORD 47*10465441SEvalZero #define SWAP_BYTES_IN_WORD(w) (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8) 48*10465441SEvalZero #endif /* SWAP_BYTES_IN_WORD */ 49*10465441SEvalZero 50*10465441SEvalZero /** Split an u32_t in two u16_ts and add them up */ 51*10465441SEvalZero #ifndef FOLD_U32T 52*10465441SEvalZero #define FOLD_U32T(u) (((u) >> 16) + ((u) & 0x0000ffffUL)) 53*10465441SEvalZero #endif 54*10465441SEvalZero 55*10465441SEvalZero #if LWIP_CHECKSUM_ON_COPY 56*10465441SEvalZero /** Function-like macro: same as MEMCPY but returns the checksum of copied data 57*10465441SEvalZero as u16_t */ 58*10465441SEvalZero # ifndef LWIP_CHKSUM_COPY 59*10465441SEvalZero # define LWIP_CHKSUM_COPY(dst, src, len) lwip_chksum_copy(dst, src, len) 60*10465441SEvalZero # ifndef LWIP_CHKSUM_COPY_ALGORITHM 61*10465441SEvalZero # define LWIP_CHKSUM_COPY_ALGORITHM 1 62*10465441SEvalZero # endif /* LWIP_CHKSUM_COPY_ALGORITHM */ 63*10465441SEvalZero # else /* LWIP_CHKSUM_COPY */ 64*10465441SEvalZero # define LWIP_CHKSUM_COPY_ALGORITHM 0 65*10465441SEvalZero # endif /* LWIP_CHKSUM_COPY */ 66*10465441SEvalZero #else /* LWIP_CHECKSUM_ON_COPY */ 67*10465441SEvalZero # define LWIP_CHKSUM_COPY_ALGORITHM 0 68*10465441SEvalZero #endif /* LWIP_CHECKSUM_ON_COPY */ 69*10465441SEvalZero 70*10465441SEvalZero #ifdef __cplusplus 71*10465441SEvalZero extern "C" { 72*10465441SEvalZero #endif 73*10465441SEvalZero 74*10465441SEvalZero u16_t inet_chksum(const void *dataptr, u16_t len); 75*10465441SEvalZero u16_t inet_chksum_pbuf(struct pbuf *p); 76*10465441SEvalZero #if LWIP_CHKSUM_COPY_ALGORITHM 77*10465441SEvalZero u16_t lwip_chksum_copy(void *dst, const void *src, u16_t len); 78*10465441SEvalZero #endif /* LWIP_CHKSUM_COPY_ALGORITHM */ 79*10465441SEvalZero 80*10465441SEvalZero #if LWIP_IPV4 81*10465441SEvalZero u16_t inet_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, 82*10465441SEvalZero const ip4_addr_t *src, const ip4_addr_t *dest); 83*10465441SEvalZero u16_t inet_chksum_pseudo_partial(struct pbuf *p, u8_t proto, 84*10465441SEvalZero u16_t proto_len, u16_t chksum_len, const ip4_addr_t *src, const ip4_addr_t *dest); 85*10465441SEvalZero #endif /* LWIP_IPV4 */ 86*10465441SEvalZero 87*10465441SEvalZero #if LWIP_IPV6 88*10465441SEvalZero u16_t ip6_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, 89*10465441SEvalZero const ip6_addr_t *src, const ip6_addr_t *dest); 90*10465441SEvalZero u16_t ip6_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, 91*10465441SEvalZero u16_t chksum_len, const ip6_addr_t *src, const ip6_addr_t *dest); 92*10465441SEvalZero #endif /* LWIP_IPV6 */ 93*10465441SEvalZero 94*10465441SEvalZero 95*10465441SEvalZero u16_t ip_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, 96*10465441SEvalZero const ip_addr_t *src, const ip_addr_t *dest); 97*10465441SEvalZero u16_t ip_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, 98*10465441SEvalZero u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest); 99*10465441SEvalZero 100*10465441SEvalZero #ifdef __cplusplus 101*10465441SEvalZero } 102*10465441SEvalZero #endif 103*10465441SEvalZero 104*10465441SEvalZero #endif /* LWIP_HDR_INET_H */ 105*10465441SEvalZero 106