2 * Copyright (c) 2001, Adam Dunkels.
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\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
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
29 * This file is part of the uIP TCP/IP stack.
\r
31 * $Id: uip_arch.c,v 1.2.2.1 2003/10/04 22:54:17 adam Exp $
\r
37 #include "uip_arch.h"
\r
38 #include <__cross_studio_io.h>
\r
40 #define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
\r
41 #define IP_PROTO_TCP 6
\r
43 /*-----------------------------------------------------------------------------------*/
\r
45 uip_add32(u8_t *op32, u16_t op16)
\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
53 if(uip_acc32[2] < (op16 >> 8)) {
\r
55 if(uip_acc32[1] == 0) {
\r
61 if(uip_acc32[3] < (op16 & 0xff)) {
\r
63 if(uip_acc32[2] == 0) {
\r
65 if(uip_acc32[1] == 0) {
\r
71 /*-----------------------------------------------------------------------------------*/
\r
73 uip_chksum(u16_t *sdata, u16_t len)
\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
87 /* add up any odd byte */
\r
89 acc += htons(((u16_t)(*(u8_t *)sdata)) << 8);
\r
90 if(acc < htons(((u16_t)(*(u8_t *)sdata)) << 8)) {
\r
97 /*-----------------------------------------------------------------------------------*/
\r
101 return uip_chksum((u16_t *)&uip_buf[UIP_LLH_LEN], 20);
\r
103 /*-----------------------------------------------------------------------------------*/
\r
105 uip_tcpchksum(void)
\r
110 /* Compute the checksum of the TCP header. */
\r
111 hsum = uip_chksum((u16_t *)&uip_buf[20 + UIP_LLH_LEN], 20);
\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
118 if((sum += hsum) < hsum) {
\r
122 if((sum += BUF->srcipaddr[0]) < BUF->srcipaddr[0]) {
\r
125 if((sum += BUF->srcipaddr[1]) < BUF->srcipaddr[1]) {
\r
128 if((sum += BUF->destipaddr[0]) < BUF->destipaddr[0]) {
\r
131 if((sum += BUF->destipaddr[1]) < BUF->destipaddr[1]) {
\r
134 if((sum += (u16_t)htons((u16_t)IP_PROTO_TCP)) < (u16_t)htons((u16_t)IP_PROTO_TCP)) {
\r
138 hsum = (u16_t)htons((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 20);
\r
140 if((sum += hsum) < hsum) {
\r
146 /*-----------------------------------------------------------------------------------*/
\r