46 |
#include "lwip/def.h" |
#include "lwip/def.h" |
47 |
#include "lwip/inet.h" |
#include "lwip/inet.h" |
48 |
|
|
49 |
|
#include "lwip/sys.h" |
50 |
|
|
51 |
|
/* This is a reference implementation of the checksum algorithm |
52 |
|
|
53 |
|
- it may not work on all architectures, and all processors, particularly |
54 |
|
if they have issues with alignment and 16 bit access. |
55 |
|
|
56 |
|
- in this case you will need to port it to your architecture and |
57 |
|
#define LWIP_CHKSUM <your_checksum_routine> |
58 |
|
in your sys_arch.h |
59 |
|
*/ |
60 |
|
#ifndef LWIP_CHKSUM |
61 |
|
#define LWIP_CHKSUM lwip_standard_chksum |
62 |
static u16_t |
static u16_t |
63 |
lwip_chksum(void *dataptr, int len) |
lwip_standard_chksum(void *dataptr, int len) |
64 |
{ |
{ |
65 |
u32_t acc; |
u32_t acc; |
66 |
|
|
86 |
|
|
87 |
return (u16_t)acc; |
return (u16_t)acc; |
88 |
} |
} |
89 |
|
#endif |
90 |
|
|
91 |
/* inet_chksum_pseudo: |
/* inet_chksum_pseudo: |
92 |
* |
* |
108 |
for(q = p; q != NULL; q = q->next) { |
for(q = p; q != NULL; q = q->next) { |
109 |
LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n", |
LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n", |
110 |
(void *)q, (void *)q->next)); |
(void *)q, (void *)q->next)); |
111 |
acc += lwip_chksum(q->payload, q->len); |
acc += LWIP_CHKSUM(q->payload, q->len); |
112 |
/*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%lx \n", acc));*/ |
/*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%lx \n", acc));*/ |
113 |
while (acc >> 16) { |
while (acc >> 16) { |
114 |
acc = (acc & 0xffffUL) + (acc >> 16); |
acc = (acc & 0xffffUL) + (acc >> 16); |
148 |
{ |
{ |
149 |
u32_t acc; |
u32_t acc; |
150 |
|
|
151 |
acc = lwip_chksum(dataptr, len); |
acc = LWIP_CHKSUM(dataptr, len); |
152 |
while (acc >> 16) { |
while (acc >> 16) { |
153 |
acc = (acc & 0xffff) + (acc >> 16); |
acc = (acc & 0xffff) + (acc >> 16); |
154 |
} |
} |
165 |
acc = 0; |
acc = 0; |
166 |
swapped = 0; |
swapped = 0; |
167 |
for(q = p; q != NULL; q = q->next) { |
for(q = p; q != NULL; q = q->next) { |
168 |
acc += lwip_chksum(q->payload, q->len); |
acc += LWIP_CHKSUM(q->payload, q->len); |
169 |
while (acc >> 16) { |
while (acc >> 16) { |
170 |
acc = (acc & 0xffffUL) + (acc >> 16); |
acc = (acc & 0xffffUL) + (acc >> 16); |
171 |
} |
} |