]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/uIP_Demo_Rowley_ARM7/uip/uip_arch.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / uIP_Demo_Rowley_ARM7 / uip / uip_arch.c
1 /*\r
2  * Copyright (c) 2001, Adam Dunkels.\r
3  * All rights reserved. \r
4  *\r
5  * Redistribution and use in source and binary forms, with or without \r
6  * modification, are permitted provided that the following conditions \r
7  * are met: \r
8  * 1. Redistributions of source code must retain the above copyright \r
9  *    notice, this list of conditions and the following disclaimer. \r
10  * 2. Redistributions in binary form must reproduce the above copyright \r
11  *    notice, this list of conditions and the following disclaimer in the \r
12  *    documentation and/or other materials provided with the distribution. \r
13  * 3. The name of the author may not be used to endorse or promote\r
14  *    products derived from this software without specific prior\r
15  *    written permission.  \r
16  *\r
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  \r
28  *\r
29  * This file is part of the uIP TCP/IP stack.\r
30  *\r
31  * $Id: uip_arch.c,v 1.2.2.1 2003/10/04 22:54:17 adam Exp $\r
32  *\r
33  */\r
34 \r
35 \r
36 #include "uip.h"\r
37 #include "uip_arch.h"\r
38 #include <__cross_studio_io.h>\r
39 \r
40 #define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])\r
41 #define IP_PROTO_TCP    6\r
42 \r
43 /*-----------------------------------------------------------------------------------*/\r
44 void\r
45 uip_add32(u8_t *op32, u16_t op16)\r
46 {\r
47   \r
48   uip_acc32[3] = op32[3] + (op16 & 0xff);\r
49   uip_acc32[2] = op32[2] + (op16 >> 8);\r
50   uip_acc32[1] = op32[1];\r
51   uip_acc32[0] = op32[0];\r
52   \r
53   if(uip_acc32[2] < (op16 >> 8)) {\r
54     ++uip_acc32[1];    \r
55     if(uip_acc32[1] == 0) {\r
56       ++uip_acc32[0];\r
57     }\r
58   }\r
59   \r
60   \r
61   if(uip_acc32[3] < (op16 & 0xff)) {\r
62     ++uip_acc32[2];  \r
63     if(uip_acc32[2] == 0) {\r
64       ++uip_acc32[1];    \r
65       if(uip_acc32[1] == 0) {\r
66         ++uip_acc32[0];\r
67       }\r
68     }\r
69   }\r
70 }\r
71 /*-----------------------------------------------------------------------------------*/\r
72 u16_t\r
73 uip_chksum(u16_t *sdata, u16_t len)\r
74 {\r
75   u16_t acc;\r
76   \r
77   for (acc = 0; len > 1; len -= 2) {\r
78     u16_t u = ((unsigned char *)sdata)[0] + (((unsigned char *)sdata)[1] << 8);\r
79     if ((acc += u) < u) {\r
80       /* Overflow, so we add the carry to acc (i.e., increase by\r
81          one). */\r
82       ++acc;\r
83     }\r
84     ++sdata;\r
85   }\r
86 \r
87   /* add up any odd byte */\r
88   if(len == 1) {\r
89     acc += htons(((u16_t)(*(u8_t *)sdata)) << 8);\r
90     if(acc < htons(((u16_t)(*(u8_t *)sdata)) << 8)) {\r
91       ++acc;\r
92     }\r
93   }\r
94 \r
95   return acc;\r
96 }\r
97 /*-----------------------------------------------------------------------------------*/\r
98 u16_t\r
99 uip_ipchksum(void)\r
100 {\r
101   return uip_chksum((u16_t *)&uip_buf[UIP_LLH_LEN], 20);\r
102 }\r
103 /*-----------------------------------------------------------------------------------*/\r
104 u16_t\r
105 uip_tcpchksum(void)\r
106 {\r
107   u16_t hsum, sum;\r
108 \r
109   \r
110   /* Compute the checksum of the TCP header. */\r
111   hsum = uip_chksum((u16_t *)&uip_buf[20 + UIP_LLH_LEN], 20);\r
112 \r
113   /* Compute the checksum of the data in the TCP packet and add it to\r
114      the TCP header checksum. */\r
115   sum = uip_chksum((u16_t *)uip_appdata,\r
116                    (u16_t)(((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 40)));\r
117 \r
118   if((sum += hsum) < hsum) {\r
119     ++sum;\r
120   }\r
121   \r
122   if((sum += BUF->srcipaddr[0]) < BUF->srcipaddr[0]) {\r
123     ++sum;\r
124   }\r
125   if((sum += BUF->srcipaddr[1]) < BUF->srcipaddr[1]) {\r
126     ++sum;\r
127   }\r
128   if((sum += BUF->destipaddr[0]) < BUF->destipaddr[0]) {\r
129     ++sum;\r
130   }\r
131   if((sum += BUF->destipaddr[1]) < BUF->destipaddr[1]) {\r
132     ++sum;\r
133   }\r
134   if((sum += (u16_t)htons((u16_t)IP_PROTO_TCP)) < (u16_t)htons((u16_t)IP_PROTO_TCP)) {\r
135     ++sum;\r
136   }\r
137 \r
138   hsum = (u16_t)htons((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 20);\r
139   \r
140   if((sum += hsum) < hsum) {\r
141     ++sum;\r
142   }\r
143 \r
144   return sum;\r
145 }\r
146 /*-----------------------------------------------------------------------------------*/\r