OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [uIP_Demo_Rowley_ARM7/] [uip/] [uip_arch.c] - Blame information for rev 609

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 583 jeremybenn
/*
2
 * Copyright (c) 2001, Adam Dunkels.
3
 * All rights reserved.
4
 *
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.
16
 *
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.
28
 *
29
 * This file is part of the uIP TCP/IP stack.
30
 *
31
 * $Id: uip_arch.c 2 2011-07-17 20:13:17Z filepang@gmail.com $
32
 *
33
 */
34
 
35
 
36
#include "uip.h"
37
#include "uip_arch.h"
38
#include <__cross_studio_io.h>
39
 
40
#define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
41
#define IP_PROTO_TCP    6
42
 
43
/*-----------------------------------------------------------------------------------*/
44
void
45
uip_add32(u8_t *op32, u16_t op16)
46
{
47
 
48
  uip_acc32[3] = op32[3] + (op16 & 0xff);
49
  uip_acc32[2] = op32[2] + (op16 >> 8);
50
  uip_acc32[1] = op32[1];
51
  uip_acc32[0] = op32[0];
52
 
53
  if(uip_acc32[2] < (op16 >> 8)) {
54
    ++uip_acc32[1];
55
    if(uip_acc32[1] == 0) {
56
      ++uip_acc32[0];
57
    }
58
  }
59
 
60
 
61
  if(uip_acc32[3] < (op16 & 0xff)) {
62
    ++uip_acc32[2];
63
    if(uip_acc32[2] == 0) {
64
      ++uip_acc32[1];
65
      if(uip_acc32[1] == 0) {
66
        ++uip_acc32[0];
67
      }
68
    }
69
  }
70
}
71
/*-----------------------------------------------------------------------------------*/
72
u16_t
73
uip_chksum(u16_t *sdata, u16_t len)
74
{
75
  u16_t acc;
76
 
77
  for (acc = 0; len > 1; len -= 2) {
78
    u16_t u = ((unsigned char *)sdata)[0] + (((unsigned char *)sdata)[1] << 8);
79
    if ((acc += u) < u) {
80
      /* Overflow, so we add the carry to acc (i.e., increase by
81
         one). */
82
      ++acc;
83
    }
84
    ++sdata;
85
  }
86
 
87
  /* add up any odd byte */
88
  if(len == 1) {
89
    acc += htons(((u16_t)(*(u8_t *)sdata)) << 8);
90
    if(acc < htons(((u16_t)(*(u8_t *)sdata)) << 8)) {
91
      ++acc;
92
    }
93
  }
94
 
95
  return acc;
96
}
97
/*-----------------------------------------------------------------------------------*/
98
u16_t
99
uip_ipchksum(void)
100
{
101
  return uip_chksum((u16_t *)&uip_buf[UIP_LLH_LEN], 20);
102
}
103
/*-----------------------------------------------------------------------------------*/
104
u16_t
105
uip_tcpchksum(void)
106
{
107
  u16_t hsum, sum;
108
 
109
 
110
  /* Compute the checksum of the TCP header. */
111
  hsum = uip_chksum((u16_t *)&uip_buf[20 + UIP_LLH_LEN], 20);
112
 
113
  /* Compute the checksum of the data in the TCP packet and add it to
114
     the TCP header checksum. */
115
  sum = uip_chksum((u16_t *)uip_appdata,
116
                   (u16_t)(((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 40)));
117
 
118
  if((sum += hsum) < hsum) {
119
    ++sum;
120
  }
121
 
122
  if((sum += BUF->srcipaddr[0]) < BUF->srcipaddr[0]) {
123
    ++sum;
124
  }
125
  if((sum += BUF->srcipaddr[1]) < BUF->srcipaddr[1]) {
126
    ++sum;
127
  }
128
  if((sum += BUF->destipaddr[0]) < BUF->destipaddr[0]) {
129
    ++sum;
130
  }
131
  if((sum += BUF->destipaddr[1]) < BUF->destipaddr[1]) {
132
    ++sum;
133
  }
134
  if((sum += (u16_t)htons((u16_t)IP_PROTO_TCP)) < (u16_t)htons((u16_t)IP_PROTO_TCP)) {
135
    ++sum;
136
  }
137
 
138
  hsum = (u16_t)htons((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 20);
139
 
140
  if((sum += hsum) < hsum) {
141
    ++sum;
142
  }
143
 
144
  return sum;
145
}
146
/*-----------------------------------------------------------------------------------*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.