Subversion Repositories HelenOS

Rev

Rev 4743 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4743 Rev 4756
Line 40... Line 40...
40
#include <byteorder.h>
40
#include <byteorder.h>
41
 
41
 
42
#include <sys/types.h>
42
#include <sys/types.h>
43
 
43
 
44
/** Computes CRC32 value.
44
/** Computes CRC32 value.
45
 *  @param seed Initial value. Often used as 0 or ~0. Input parameter.
45
 *  @param[in] seed Initial value. Often used as 0 or ~0.
46
 *  @param data Pointer to the beginning of data to process. Input parameter.
46
 *  @param[in] data Pointer to the beginning of data to process.
47
 *  @param length Length of the data in bits. Input parameter.
47
 *  @param[in] length Length of the data in bits.
48
 *  @returns The computed CRC32 of the length bits of the data.
48
 *  @returns The computed CRC32 of the length bits of the data.
49
 */
49
 */
50
#ifdef ARCH_IS_BIG_ENDIAN
50
#ifdef ARCH_IS_BIG_ENDIAN
51
    #define compute_crc32( seed, data, length ) compute_crc32_be( seed, ( uint8_t * ) data, length )
51
    #define compute_crc32( seed, data, length ) compute_crc32_be( seed, ( uint8_t * ) data, length )
52
#else
52
#else
53
    #define compute_crc32( seed, data, length ) compute_crc32_le( seed, ( uint8_t * ) data, length )
53
    #define compute_crc32( seed, data, length ) compute_crc32_le( seed, ( uint8_t * ) data, length )
54
#endif
54
#endif
55
 
55
 
56
/** Computes CRC32 value in the little-endian environment.
56
/** Computes CRC32 value in the little-endian environment.
57
 *  @param seed Initial value. Often used as 0 or ~0. Input parameter.
57
 *  @param[in] seed Initial value. Often used as 0 or ~0.
58
 *  @param data Pointer to the beginning of data to process. Input parameter.
58
 *  @param[in] data Pointer to the beginning of data to process.
59
 *  @param length Length of the data in bits. Input parameter.
59
 *  @param[in] length Length of the data in bits.
60
 *  @returns The computed CRC32 of the length bits of the data.
60
 *  @returns The computed CRC32 of the length bits of the data.
61
 */
61
 */
62
uint32_t    compute_crc32_le( uint32_t seed, uint8_t * data, size_t length );
62
uint32_t    compute_crc32_le( uint32_t seed, uint8_t * data, size_t length );
63
 
63
 
64
/** Computes CRC32 value in the big-endian environment.
64
/** Computes CRC32 value in the big-endian environment.
65
 *  @param seed Initial value. Often used as 0 or ~0. Input parameter.
65
 *  @param[in] seed Initial value. Often used as 0 or ~0.
66
 *  @param data Pointer to the beginning of data to process. Input parameter.
66
 *  @param[in] data Pointer to the beginning of data to process.
67
 *  @param length Length of the data in bits. Input parameter.
67
 *  @param[in] length Length of the data in bits.
68
 *  @returns The computed CRC32 of the length bits of the data.
68
 *  @returns The computed CRC32 of the length bits of the data.
69
 */
69
 */
70
uint32_t    compute_crc32_be( uint32_t seed, uint8_t * data, size_t length );
70
uint32_t    compute_crc32_be( uint32_t seed, uint8_t * data, size_t length );
71
 
71
 
72
/** Computes sum of the 2 byte fields.
72
/** Computes sum of the 2 byte fields.
73
 *  Padds one zero (0) byte if odd.
73
 *  Padds one zero (0) byte if odd.
74
 *  @param seed Initial value. Often used as 0 or ~0. Input parameter.
74
 *  @param[in] seed Initial value. Often used as 0 or ~0.
75
 *  @param data Pointer to the beginning of data to process. Input parameter.
75
 *  @param[in] data Pointer to the beginning of data to process.
76
 *  @param length Length of the data in bytes. Input parameter.
76
 *  @param[in] length Length of the data in bytes.
77
 *  @returns The computed checksum of the length bytes of the data.
77
 *  @returns The computed checksum of the length bytes of the data.
78
 */
78
 */
79
uint32_t    compute_checksum( uint32_t seed, uint8_t * data, size_t length );
79
uint32_t    compute_checksum( uint32_t seed, uint8_t * data, size_t length );
80
 
80
 
81
/** Compacts the computed checksum to the 16 bit number adding the carries.
81
/** Compacts the computed checksum to the 16 bit number adding the carries.
82
 *  @param sum Computed checksum. Input parameter.
82
 *  @param[in] sum Computed checksum.
83
 *  @returns Compacted computed checksum to the 16 bits.
83
 *  @returns Compacted computed checksum to the 16 bits.
84
 */
84
 */
85
uint16_t    compact_checksum( uint32_t sum );
85
uint16_t    compact_checksum( uint32_t sum );
86
 
86
 
87
/** Returns or flips the checksum if zero.
87
/** Returns or flips the checksum if zero.
88
 *  @param checksum The computed checksum. Input parameter.
88
 *  @param[in] checksum The computed checksum.
89
 *  @returns The internet protocol header checksum.
89
 *  @returns The internet protocol header checksum.
90
 *  @returns 0xFFFF if the computed checksum is zero.
90
 *  @returns 0xFFFF if the computed checksum is zero.
91
 */
91
 */
92
uint16_t    flip_checksum( uint16_t checksum );
92
uint16_t    flip_checksum( uint16_t checksum );
93
 
93
 
94
/** Computes the ip header checksum.
94
/** Computes the ip header checksum.
95
 *  To compute the checksum of a new packet, the checksum header field must be zero.
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.
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.
97
 *  The zero (0) value will be returned in this case if valid.
98
 *  @param data The header data. Input parameter.
98
 *  @param[in] data The header data.
99
 *  @param length The header length in bytes. Input parameter.
99
 *  @param[in] length The header length in bytes.
100
 *  @returns The internet protocol header checksum.
100
 *  @returns The internet protocol header checksum.
101
 *  @returns 0xFFFF if the computed checksum is zero.
101
 *  @returns 0xFFFF if the computed checksum is zero.
102
 */
102
 */
103
uint16_t ip_checksum( uint8_t * data, size_t length );
103
uint16_t ip_checksum( uint8_t * data, size_t length );
104
 
104