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

Subversion Repositories openrisc

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

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
 
39
#define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
40
#define IP_PROTO_TCP    6
41
 
42
/*-----------------------------------------------------------------------------------*/
43
void
44
uip_add32(u8_t *op32, u16_t op16)
45
{
46
 
47
  uip_acc32[3] = op32[3] + (op16 & 0xff);
48
  uip_acc32[2] = op32[2] + (op16 >> 8);
49
  uip_acc32[1] = op32[1];
50
  uip_acc32[0] = op32[0];
51
 
52
  if(uip_acc32[2] < (op16 >> 8)) {
53
    ++uip_acc32[1];
54
    if(uip_acc32[1] == 0) {
55
      ++uip_acc32[0];
56
    }
57
  }
58
 
59
 
60
  if(uip_acc32[3] < (op16 & 0xff)) {
61
    ++uip_acc32[2];
62
    if(uip_acc32[2] == 0) {
63
      ++uip_acc32[1];
64
      if(uip_acc32[1] == 0) {
65
        ++uip_acc32[0];
66
      }
67
    }
68
  }
69
}
70
/*-----------------------------------------------------------------------------------*/
71
u16_t
72
uip_chksum(u16_t *sdata, u16_t len)
73
{
74
  u16_t acc;
75
 
76
  for (acc = 0; len > 1; len -= 2) {
77
    u16_t u = ((unsigned char *)sdata)[0] + (((unsigned char *)sdata)[1] << 8);
78
    if ((acc += u) < u) {
79
      /* Overflow, so we add the carry to acc (i.e., increase by
80
         one). */
81
      ++acc;
82
    }
83
    ++sdata;
84
  }
85
 
86
  /* add up any odd byte */
87
  if(len == 1) {
88
    acc += htons(((u16_t)(*(u8_t *)sdata)) << 8);
89
    if(acc < htons(((u16_t)(*(u8_t *)sdata)) << 8)) {
90
      ++acc;
91
    }
92
  }
93
 
94
  return acc;
95
}
96
/*-----------------------------------------------------------------------------------*/
97
u16_t
98
uip_ipchksum(void)
99
{
100
  return uip_chksum((u16_t *)&uip_buf[UIP_LLH_LEN], 20);
101
}
102
/*-----------------------------------------------------------------------------------*/
103
u16_t
104
uip_tcpchksum(void)
105
{
106
  u16_t hsum, sum;
107
 
108
 
109
  /* Compute the checksum of the TCP header. */
110
  hsum = uip_chksum((u16_t *)&uip_buf[20 + UIP_LLH_LEN], 20);
111
 
112
  /* Compute the checksum of the data in the TCP packet and add it to
113
     the TCP header checksum. */
114
  sum = uip_chksum((u16_t *)uip_appdata,
115
                   (u16_t)(((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 40)));
116
 
117
  if((sum += hsum) < hsum) {
118
    ++sum;
119
  }
120
 
121
  if((sum += BUF->srcipaddr[0]) < BUF->srcipaddr[0]) {
122
    ++sum;
123
  }
124
  if((sum += BUF->srcipaddr[1]) < BUF->srcipaddr[1]) {
125
    ++sum;
126
  }
127
  if((sum += BUF->destipaddr[0]) < BUF->destipaddr[0]) {
128
    ++sum;
129
  }
130
  if((sum += BUF->destipaddr[1]) < BUF->destipaddr[1]) {
131
    ++sum;
132
  }
133
  if((sum += (u16_t)htons((u16_t)IP_PROTO_TCP)) < (u16_t)htons((u16_t)IP_PROTO_TCP)) {
134
    ++sum;
135
  }
136
 
137
  hsum = (u16_t)htons((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 20);
138
 
139
  if((sum += hsum) < hsum) {
140
    ++sum;
141
  }
142
 
143
  return sum;
144
}
145
/*-----------------------------------------------------------------------------------*/

powered by: WebSVN 2.1.0

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