76 # define LWIP_CHKSUM lwip_standard_chksum 77 # ifndef LWIP_CHKSUM_ALGORITHM 78 # define LWIP_CHKSUM_ALGORITHM 2 80 u16_t lwip_standard_chksum(
const void *dataptr,
int len);
83 #ifndef LWIP_CHKSUM_ALGORITHM 84 # define LWIP_CHKSUM_ALGORITHM 0 87 #if (LWIP_CHKSUM_ALGORITHM == 1) 99 lwip_standard_chksum(
const void *dataptr,
int len)
103 const u8_t *octetptr;
107 octetptr = (
const u8_t*)dataptr;
111 src = (*octetptr) << 8;
121 src = (*octetptr) << 8;
125 acc = (acc >> 16) + (acc & 0x0000ffffUL);
126 if ((acc & 0xffff0000UL) != 0) {
127 acc = (acc >> 16) + (acc & 0x0000ffffUL);
132 return lwip_htons((u16_t)acc);
136 #if (LWIP_CHKSUM_ALGORITHM == 2) 152 lwip_standard_chksum(
const void *dataptr,
int len)
154 const u8_t *pb = (
const u8_t *)dataptr;
158 int odd = ((mem_ptr_t)pb & 1);
161 if (odd && len > 0) {
162 ((u8_t *)&t)[1] = *pb++;
167 ps = (
const u16_t *)(
const void *)pb;
175 ((u8_t *)&t)[0] = *(
const u8_t *)ps;
195 #if (LWIP_CHKSUM_ALGORITHM == 3) 208 lwip_standard_chksum(
const void *dataptr,
int len)
210 const u8_t *pb = (
const u8_t *)dataptr;
216 int odd = ((mem_ptr_t)pb & 1);
218 if (odd && len > 0) {
219 ((u8_t *)&t)[1] = *pb++;
223 ps = (
const u16_t *)(
const void*)pb;
225 if (((mem_ptr_t)ps & 3) && len > 1) {
230 pl = (
const u32_t *)(
const void*)ps;
249 ps = (
const u16_t *)pl;
259 ((u8_t *)&t)[0] = *(
const u8_t *)ps;
279 inet_cksum_pseudo_base(
struct pbuf *p, u8_t proto, u16_t proto_len, u32_t acc)
285 for (q = p; q != NULL; q = q->
next) {
287 (
void *)q, (
void *)q->
next));
293 if (q->
len % 2 != 0) {
294 swapped = 1 - swapped;
304 acc += (u32_t)lwip_htons((u16_t)proto);
305 acc += (u32_t)lwip_htons(proto_len);
312 return (u16_t)~(acc & 0xffffUL);
329 inet_chksum_pseudo(
struct pbuf *p, u8_t proto, u16_t proto_len,
330 const ip4_addr_t *src,
const ip4_addr_t *dest)
335 addr = ip4_addr_get_u32(src);
336 acc = (addr & 0xffffUL);
337 acc += ((addr >> 16) & 0xffffUL);
338 addr = ip4_addr_get_u32(dest);
339 acc += (addr & 0xffffUL);
340 acc += ((addr >> 16) & 0xffffUL);
345 return inet_cksum_pseudo_base(p, proto, proto_len, acc);
362 ip6_chksum_pseudo(
struct pbuf *p, u8_t proto, u16_t proto_len,
363 const ip6_addr_t *src,
const ip6_addr_t *dest)
369 for (addr_part = 0; addr_part < 4; addr_part++) {
370 addr = src->addr[addr_part];
371 acc += (addr & 0xffffUL);
372 acc += ((addr >> 16) & 0xffffUL);
373 addr = dest->addr[addr_part];
374 acc += (addr & 0xffffUL);
375 acc += ((addr >> 16) & 0xffffUL);
381 return inet_cksum_pseudo_base(p, proto, proto_len, acc);
398 ip_chksum_pseudo(
struct pbuf *p, u8_t proto, u16_t proto_len,
399 const ip_addr_t *src,
const ip_addr_t *dest)
402 if (IP_IS_V6(dest)) {
403 return ip6_chksum_pseudo(p, proto, proto_len, ip_2_ip6(src), ip_2_ip6(dest));
406 #if LWIP_IPV4 && LWIP_IPV6 411 return inet_chksum_pseudo(p, proto, proto_len, ip_2_ip4(src), ip_2_ip4(dest));
418 inet_cksum_pseudo_partial_base(
struct pbuf *p, u8_t proto, u16_t proto_len,
419 u16_t chksum_len, u32_t acc)
426 for (q = p; (q != NULL) && (chksum_len > 0); q = q->
next) {
428 (
void *)q, (
void *)q->
next));
430 if (chklen > chksum_len) {
433 acc += LWIP_CHKSUM(q->
payload, chklen);
434 chksum_len -= chklen;
435 LWIP_ASSERT(
"delete me", chksum_len < 0x7fff);
439 if (q->
len % 2 != 0) {
440 swapped = 1 - swapped;
450 acc += (u32_t)lwip_htons((u16_t)proto);
451 acc += (u32_t)lwip_htons(proto_len);
458 return (u16_t)~(acc & 0xffffUL);
475 inet_chksum_pseudo_partial(
struct pbuf *p, u8_t proto, u16_t proto_len,
476 u16_t chksum_len,
const ip4_addr_t *src,
const ip4_addr_t *dest)
481 addr = ip4_addr_get_u32(src);
482 acc = (addr & 0xffffUL);
483 acc += ((addr >> 16) & 0xffffUL);
484 addr = ip4_addr_get_u32(dest);
485 acc += (addr & 0xffffUL);
486 acc += ((addr >> 16) & 0xffffUL);
491 return inet_cksum_pseudo_partial_base(p, proto, proto_len, chksum_len, acc);
510 ip6_chksum_pseudo_partial(
struct pbuf *p, u8_t proto, u16_t proto_len,
511 u16_t chksum_len,
const ip6_addr_t *src,
const ip6_addr_t *dest)
517 for (addr_part = 0; addr_part < 4; addr_part++) {
518 addr = src->addr[addr_part];
519 acc += (addr & 0xffffUL);
520 acc += ((addr >> 16) & 0xffffUL);
521 addr = dest->addr[addr_part];
522 acc += (addr & 0xffffUL);
523 acc += ((addr >> 16) & 0xffffUL);
529 return inet_cksum_pseudo_partial_base(p, proto, proto_len, chksum_len, acc);
545 ip_chksum_pseudo_partial(
struct pbuf *p, u8_t proto, u16_t proto_len,
546 u16_t chksum_len,
const ip_addr_t *src,
const ip_addr_t *dest)
549 if (IP_IS_V6(dest)) {
550 return ip6_chksum_pseudo_partial(p, proto, proto_len, chksum_len, ip_2_ip6(src), ip_2_ip6(dest));
553 #if LWIP_IPV4 && LWIP_IPV6 558 return inet_chksum_pseudo_partial(p, proto, proto_len, chksum_len, ip_2_ip4(src), ip_2_ip4(dest));
574 inet_chksum(
const void *dataptr, u16_t len)
576 return (u16_t)~(
unsigned int)LWIP_CHKSUM(dataptr, len);
595 for (q = p; q != NULL; q = q->
next) {
598 if (q->
len % 2 != 0) {
599 swapped = 1 - swapped;
607 return (u16_t)~(acc & 0xffffUL);
617 #if (LWIP_CHKSUM_COPY_ALGORITHM == 1) 623 lwip_chksum_copy(
void *dst,
const void *src, u16_t len)
625 MEMCPY(dst, src, len);
626 return LWIP_CHKSUM(dst, len);
u16_t inet_chksum_pbuf(struct pbuf *p)
#define SWAP_BYTES_IN_WORD(w)
#define LWIP_DEBUGF(debug, message)