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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [ppc/] [lib/] [checksum.c] - Blame information for rev 1781

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

Line No. Rev Author Line
1 1624 jcastillo
/*
2
 * INET         An implementation of the TCP/IP protocol suite for the LINUX
3
 *              operating system.  INET is implemented using the  BSD Socket
4
 *              interface as the means of communication with the user level.
5
 *
6
 *              IP/TCP/UDP checksumming routines
7
 *
8
 * Authors:     Jorge Cwik, <jorge@laser.satlink.net>
9
 *              Arnt Gulbrandsen, <agulbra@nvg.unit.no>
10
 *              Tom May, <ftom@netcom.com>
11
 *              Lots of code moved from tcp.c and ip.c; see those files
12
 *              for more names.
13
 *
14
 * Adapted for PowerPC by Gary Thomas <gdt@mc.com>
15
 *
16
 *              This program is free software; you can redistribute it and/or
17
 *              modify it under the terms of the GNU General Public License
18
 *              as published by the Free Software Foundation; either version
19
 *              2 of the License, or (at your option) any later version.
20
 */
21
 
22
#include <net/checksum.h>
23
 
24
/*
25
 * computes the checksum of a memory block at buff, length len,
26
 * and adds in "sum" (32-bit)
27
 *
28
 * returns a 32-bit number suitable for feeding into itself
29
 * or csum_tcpudp_magic
30
 *
31
 * this function must be called with even lengths, except
32
 * for the last fragment, which may be odd
33
 *
34
 * it's best to have buff aligned on a 32-bit boundary
35
 */
36
unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
37
{
38
        unsigned long result = ~_csum_partial(buff, len, sum);
39
#if 0   
40
printk("Csum partial(%x, %d, %x) = %x\n", buff, len, sum, result);
41
dump_buf(buff, len);
42
#endif
43
        return result;
44
}
45
 
46
/*
47
 * the same as csum_partial, but copies from src while it
48
 * checksums
49
 *
50
 * here even more important to align src and dst on a 32-bit boundary
51
 */
52
 
53
unsigned int csum_partial_copy(const char *src, char *dst, int len, int sum)
54
{
55
        /*
56
         * The whole idea is to do the copy and the checksum at
57
         * the same time, but we do it the easy way now.
58
         *
59
         * At least csum on the source, not destination, for cache
60
         * reasons..
61
         */
62
        sum = csum_partial(src, len, sum);
63
        memcpy(dst, src, len);
64
        return sum;
65
}
66
 
67
extern unsigned short _ip_fast_csum(unsigned char *buf);
68
 
69
unsigned short
70
ip_fast_csum(unsigned char *buf, unsigned int len)
71
{
72
        unsigned short _val;
73
        _val = _ip_fast_csum(buf);
74
#if 0
75
        printk("IP CKSUM(%x, %d) = %x\n", buf, len, _val);
76
        dump_buf(buf, len*4);
77
#endif  
78
        return (_val);
79
}
80
 
81
extern unsigned short _ip_compute_csum(unsigned char *buf, int len);
82
 
83
unsigned short
84
ip_compute_csum(unsigned char *buf, int len)
85
{
86
        unsigned short _val;
87
        _val = _ip_compute_csum(buf, len);
88
#if 0
89
        printk("Compute IP CKSUM(%x, %d) = %x\n", buf, len, _val);
90
        dump_buf(buf, len);
91
#endif  
92
        return (_val);
93
}
94
 
95
unsigned short
96
_udp_check(unsigned char *buf, int len, int saddr, int daddr, int hdr);
97
 
98
unsigned short
99
udp_check(unsigned char *buf, int len, int saddr, int daddr)
100
{
101
        unsigned short _val;
102
        int hdr;
103
        hdr = (len << 16) + IPPROTO_UDP;
104
        _val = _udp_check(buf, len, saddr, daddr, hdr);
105
#if 0
106
        printk("UDP CSUM(%x,%d,%x,%x) = %x\n", buf, len, saddr, daddr, _val);
107
        dump_buf(buf, len);
108
#endif  
109
        return (_val);
110
}
111
 
112
unsigned short
113
_tcp_check(unsigned char *buf, int len, int saddr, int daddr, int hdr);
114
 
115
unsigned short
116
csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len, unsigned short proto, unsigned int sum)
117
{
118
        unsigned short _val;
119
        _val = _csum_tcpudp_magic(saddr, daddr, sum, (len<<16)+proto);
120
#if 0
121
        printk("TCP Magic(%x, %x, %x, %x) = %x\n", saddr, daddr, (len<<16)+proto, sum, _val);
122
#endif
123
        return (_val);
124
}
125
 
126
/*
127
 *      Fold a partial checksum without adding pseudo headers
128
 */
129
 
130
unsigned short csum_fold(unsigned int sum)
131
{
132
        sum = (sum & 0xffff) + (sum >> 16);
133
        sum = (sum & 0xffff) + (sum >> 16);
134
        return ~sum;
135
}
136
 

powered by: WebSVN 2.1.0

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