2 * Copyright (c) 2001, Adam Dunkels.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote
14 * products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * This file is part of the uIP TCP/IP stack.
45 /*-----------------------------------------------------------------------------------*/
46 u16_t
uip_chksum(u16_t
*sdata
, u32_t len
)
50 for(acc
= 0;len
> 1;len
-= 2) {
54 /* add up any odd byte */
56 acc
+= htons((u16_t
)((((u8_t
*)sdata
)[0]&0xff)<<8));
58 while(acc
>>16) acc
= (acc
&0xffffUL
)+(acc
>>16);
63 /*-----------------------------------------------------------------------------------*/
64 u16_t
uip_chksum_pseudo(struct uip_pbuf
*p
,struct uip_ip_addr
*src
,struct uip_ip_addr
*dst
,u8_t proto
,u16_t proto_len
)
72 for(q
=p
;q
!=NULL
&& rem
>0;q
=q
->next
) {
73 len
= (rem
>q
->len
)?q
->len
:rem
;
74 acc
+= uip_chksum(q
->payload
,len
);
78 acc
+= (src
->addr
&0xffffUL
);
79 acc
+= ((src
->addr
>>16)&0xffffUL
);
80 acc
+= (dst
->addr
&0xffffUL
);
81 acc
+= ((dst
->addr
>>16)&0xffffUL
);
82 acc
+= (u32_t
)htons(proto
);
83 acc
+= (u32_t
)htons(proto_len
);
85 while(acc
>>16) acc
= (acc
&0xffffUL
)+(acc
>>16);
87 return (u16_t
)~(acc
&0xffffUL
);
89 /*-----------------------------------------------------------------------------------*/
91 uip_ipchksum(void *dataptr
,u16_t len
)
93 return ~(uip_chksum(dataptr
,len
));
96 u16_t
uip_ipchksum_pbuf(struct uip_pbuf
*p
)
102 for(q
= p
; q
!= NULL
; q
= q
->next
) {
103 acc
+= uip_chksum(q
->payload
,q
->len
);
105 while(acc
>>16) acc
= (acc
&0xffffUL
)+(acc
>>16);
107 return (u16_t
)~(acc
& 0xffffUL
);
110 void uip_log(const char *filename
,int line_nb
,char *msg
)
112 printf("%s(%d):\n%s\n",filename
,line_nb
,msg
);
115 /*-----------------------------------------------------------------------------------*/