change PAD_ScanPads()s behaviour. the return value now contains a bitmask of the...
[libogc.git] / libdb / uIP / uip_arch.c
blob5a973caf81396c3d993312eff018a18094a84ce9
1 /*
2 * Copyright (c) 2001, Adam Dunkels.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
15 * written permission.
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.
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdio.h>
38 #include "uip.h"
39 #include "uip_arch.h"
40 #include "uip_ip.h"
41 #include "uip_tcp.h"
42 #include "uip_pbuf.h"
45 /*-----------------------------------------------------------------------------------*/
46 u16_t uip_chksum(u16_t *sdata, u32_t len)
48 u32_t acc;
50 for(acc = 0;len > 1;len -= 2) {
51 acc += *sdata++;
54 /* add up any odd byte */
55 if(len==1) {
56 acc += htons((u16_t)((((u8_t *)sdata)[0]&0xff)<<8));
58 while(acc>>16) acc = (acc&0xffffUL)+(acc>>16);
60 return (u16_t)acc;
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)
66 u32_t acc,len,rem;
67 struct uip_pbuf *q;
69 acc = 0;
71 rem = 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);
75 rem -= 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 /*-----------------------------------------------------------------------------------*/
90 u16_t
91 uip_ipchksum(void *dataptr,u16_t len)
93 return ~(uip_chksum(dataptr,len));
96 u16_t uip_ipchksum_pbuf(struct uip_pbuf *p)
98 u32_t acc;
99 struct uip_pbuf *q;
101 acc = 0;
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 /*-----------------------------------------------------------------------------------*/