60 # define LWIP_CHKSUM lwip_standard_chksum 61 # ifndef LWIP_CHKSUM_ALGORITHM 62 # define LWIP_CHKSUM_ALGORITHM 2 67 #ifndef LWIP_CHKSUM_ALGORITHM 68 # define LWIP_CHKSUM_ALGORITHM 0 71 #if (LWIP_CHKSUM_ALGORITHM == 1) 91 octetptr = (
const u8_t*)dataptr;
95 src = (*octetptr) << 8;
105 src = (*octetptr) << 8;
109 acc = (acc >> 16) + (acc & 0x0000ffffUL);
110 if ((acc & 0xffff0000UL) != 0) {
111 acc = (acc >> 16) + (acc & 0x0000ffffUL);
120 #if (LWIP_CHKSUM_ALGORITHM == 2) 138 const u8_t *pb = (
const u8_t *)dataptr;
145 if (odd && len > 0) {
146 ((
u8_t *)&t)[1] = *pb++;
151 ps = (
const u16_t *)(
const void *)pb;
159 ((
u8_t *)&t)[0] = *(
const u8_t *)ps;
179 #if (LWIP_CHKSUM_ALGORITHM == 3) 194 const u8_t *pb = (
const u8_t *)dataptr;
202 if (odd && len > 0) {
203 ((
u8_t *)&t)[1] = *pb++;
207 ps = (
const u16_t *)(
const void*)pb;
214 pl = (
const u32_t *)(
const void*)ps;
233 ps = (
const u16_t *)pl;
243 ((
u8_t *)&t)[0] = *(
const u8_t *)ps;
269 for (q = p; q !=
NULL; q = q->
next) {
271 (
void *)q, (
void *)q->
next));
277 if (q->
len % 2 != 0) {
278 swapped = 1 - swapped;
296 return (
u16_t)~(acc & 0xffffUL);
313 inet_chksum_pseudo(
struct pbuf *p,
u8_t proto,
u16_t proto_len,
314 const ip4_addr_t *src,
const ip4_addr_t *dest)
319 addr = ip4_addr_get_u32(src);
320 acc = (addr & 0xffffUL);
321 acc += ((addr >> 16) & 0xffffUL);
322 addr = ip4_addr_get_u32(dest);
323 acc += (addr & 0xffffUL);
324 acc += ((addr >> 16) & 0xffffUL);
329 return inet_cksum_pseudo_base(p, proto, proto_len, acc);
346 ip6_chksum_pseudo(
struct pbuf *p,
u8_t proto,
u16_t proto_len,
347 const ip6_addr_t *src,
const ip6_addr_t *dest)
353 for (addr_part = 0; addr_part < 4; addr_part++) {
354 addr = src->addr[addr_part];
355 acc += (addr & 0xffffUL);
356 acc += ((addr >> 16) & 0xffffUL);
357 addr = dest->addr[addr_part];
358 acc += (addr & 0xffffUL);
359 acc += ((addr >> 16) & 0xffffUL);
365 return inet_cksum_pseudo_base(p, proto, proto_len, acc);
387 return ip6_chksum_pseudo(p, proto, proto_len,
ip_2_ip6(src),
ip_2_ip6(dest));
390 #if LWIP_IPV4 && LWIP_IPV6 395 return inet_chksum_pseudo(p, proto, proto_len, ip_2_ip4(src), ip_2_ip4(dest));
402 inet_cksum_pseudo_partial_base(
struct pbuf *p,
u8_t proto,
u16_t proto_len,
410 for (q = p; (q !=
NULL) && (chksum_len > 0); q = q->
next) {
412 (
void *)q, (
void *)q->
next));
414 if (chklen > chksum_len) {
418 chksum_len -= chklen;
423 if (q->
len % 2 != 0) {
424 swapped = 1 - swapped;
442 return (
u16_t)~(acc & 0xffffUL);
459 inet_chksum_pseudo_partial(
struct pbuf *p,
u8_t proto,
u16_t proto_len,
460 u16_t chksum_len,
const ip4_addr_t *src,
const ip4_addr_t *dest)
465 addr = ip4_addr_get_u32(src);
466 acc = (addr & 0xffffUL);
467 acc += ((addr >> 16) & 0xffffUL);
468 addr = ip4_addr_get_u32(dest);
469 acc += (addr & 0xffffUL);
470 acc += ((addr >> 16) & 0xffffUL);
475 return inet_cksum_pseudo_partial_base(p, proto, proto_len, chksum_len, acc);
494 ip6_chksum_pseudo_partial(
struct pbuf *p,
u8_t proto,
u16_t proto_len,
495 u16_t chksum_len,
const ip6_addr_t *src,
const ip6_addr_t *dest)
501 for (addr_part = 0; addr_part < 4; addr_part++) {
502 addr = src->addr[addr_part];
503 acc += (addr & 0xffffUL);
504 acc += ((addr >> 16) & 0xffffUL);
505 addr = dest->addr[addr_part];
506 acc += (addr & 0xffffUL);
507 acc += ((addr >> 16) & 0xffffUL);
513 return inet_cksum_pseudo_partial_base(p, proto, proto_len, chksum_len, acc);
534 return ip6_chksum_pseudo_partial(p, proto, proto_len, chksum_len,
ip_2_ip6(src),
ip_2_ip6(dest));
537 #if LWIP_IPV4 && LWIP_IPV6 542 return inet_chksum_pseudo_partial(p, proto, proto_len, chksum_len, ip_2_ip4(src), ip_2_ip4(dest));
579 for (q = p; q !=
NULL; q = q->
next) {
582 if (q->
len % 2 != 0) {
583 swapped = 1 - swapped;
591 return (
u16_t)~(acc & 0xffffUL);
601 #if (LWIP_CHKSUM_COPY_ALGORITHM == 1) 607 lwip_chksum_copy(
void *dst,
const void *src,
u16_t len)
u16_t ip_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, const ip_addr_t *src, const ip_addr_t *dest)
#define MEMCPY(dst, src, len)
u16_t inet_chksum(const void *dataptr, u16_t len)
u16_t inet_chksum_pbuf(struct pbuf *p)
u16_t lwip_standard_chksum(const void *dataptr, int len)
#define SWAP_BYTES_IN_WORD(w)
#define LWIP_ASSERT(message, assertion)
u16_t ip_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest)
#define LWIP_DEBUGF(debug, message)