source: mainline/uspace/srv/net/include/checksum.h@ 1a0fb3f8

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1a0fb3f8 was 21580dd, checked in by Lukas Mejdrech <lukas@…>, 16 years ago

Merged with network branch svn://svn.helenos.org/HelenOS/branches/network revision 4759; ipc_share_* and ipc_data_* changed to async_*; client connection in module.c returns on IPC_M_PHONE_HUNGUP; * Qemu scripts renamed to net-qe.*; (the dp8390 does not respond)

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2009 Lukas Mejdrech
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 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup net
30 * @{
31 */
32
33/** @file
34 * General CRC and checksum computation.
35 */
36
37#ifndef __NET_CHECKSUM_H__
38#define __NET_CHECKSUM_H__
39
40#include <byteorder.h>
41
42#include <sys/types.h>
43
44/** Computes CRC32 value.
45 * @param[in] seed Initial value. Often used as 0 or ~0.
46 * @param[in] data Pointer to the beginning of data to process.
47 * @param[in] length Length of the data in bits.
48 * @returns The computed CRC32 of the length bits of the data.
49 */
50#ifdef ARCH_IS_BIG_ENDIAN
51 #define compute_crc32( seed, data, length ) compute_crc32_be( seed, ( uint8_t * ) data, length )
52#else
53 #define compute_crc32( seed, data, length ) compute_crc32_le( seed, ( uint8_t * ) data, length )
54#endif
55
56/** Computes CRC32 value in the little-endian environment.
57 * @param[in] seed Initial value. Often used as 0 or ~0.
58 * @param[in] data Pointer to the beginning of data to process.
59 * @param[in] length Length of the data in bits.
60 * @returns The computed CRC32 of the length bits of the data.
61 */
62uint32_t compute_crc32_le( uint32_t seed, uint8_t * data, size_t length );
63
64/** Computes CRC32 value in the big-endian environment.
65 * @param[in] seed Initial value. Often used as 0 or ~0.
66 * @param[in] data Pointer to the beginning of data to process.
67 * @param[in] length Length of the data in bits.
68 * @returns The computed CRC32 of the length bits of the data.
69 */
70uint32_t compute_crc32_be( uint32_t seed, uint8_t * data, size_t length );
71
72/** Computes sum of the 2 byte fields.
73 * Padds one zero (0) byte if odd.
74 * @param[in] seed Initial value. Often used as 0 or ~0.
75 * @param[in] data Pointer to the beginning of data to process.
76 * @param[in] length Length of the data in bytes.
77 * @returns The computed checksum of the length bytes of the data.
78 */
79uint32_t compute_checksum( uint32_t seed, uint8_t * data, size_t length );
80
81/** Compacts the computed checksum to the 16 bit number adding the carries.
82 * @param[in] sum Computed checksum.
83 * @returns Compacted computed checksum to the 16 bits.
84 */
85uint16_t compact_checksum( uint32_t sum );
86
87/** Returns or flips the checksum if zero.
88 * @param[in] checksum The computed checksum.
89 * @returns The internet protocol header checksum.
90 * @returns 0xFFFF if the computed checksum is zero.
91 */
92uint16_t flip_checksum( uint16_t checksum );
93
94/** Computes the ip header checksum.
95 * To compute the checksum of a new packet, the checksum header field must be zero.
96 * To check the checksum of a received packet, the checksum may be left set.
97 * The zero (0) value will be returned in this case if valid.
98 * @param[in] data The header data.
99 * @param[in] length The header length in bytes.
100 * @returns The internet protocol header checksum.
101 * @returns 0xFFFF if the computed checksum is zero.
102 */
103uint16_t ip_checksum( uint8_t * data, size_t length );
104
105#endif
106
107/** @}
108 */
Note: See TracBrowser for help on using the repository browser.