Subversion Repositories HelenOS

Rev

Rev 4075 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4075 Rev 4505
Line 29... Line 29...
29
/** @addtogroup net
29
/** @addtogroup net
30
 *  @{
30
 *  @{
31
 */
31
 */
32
 
32
 
33
/** @file
33
/** @file
34
 *  General CRC computation implementation.
34
 *  General CRC and checksum computation implementation.
35
 */
35
 */
36
 
36
 
37
#include <sys/types.h>
37
#include <sys/types.h>
38
 
38
 
39
#include "include/crc.h"
39
#include "include/crc.h"
Line 98... Line 98...
98
        length -= 8;
98
        length -= 8;
99
    }
99
    }
100
    return seed;
100
    return seed;
101
}
101
}
102
 
102
 
-
 
103
uint32_t compute_checksum( uint32_t seed, uint8_t * data, int length ){
-
 
104
    int index;
-
 
105
 
-
 
106
    // sum all the 16 bit fields
-
 
107
    for( index = 0; index < length - 1; index += 2 ){
-
 
108
        seed += ( data[ index ] << 8 ) + data[ index + 1 ];
-
 
109
    }
-
 
110
 
-
 
111
    // last odd byte with zero padding
-
 
112
    if( index == length - 1 ){
-
 
113
        seed += data[ index ] << 8;
-
 
114
    }
-
 
115
 
-
 
116
    return seed;
-
 
117
}
-
 
118
 
-
 
119
uint16_t compact_checksum( uint32_t sum ){
-
 
120
    // shorten to the 16 bits
-
 
121
    while( sum >> 16 ) sum = ( sum & 0xFFFF ) + ( sum >> 16 );
-
 
122
 
-
 
123
    return ( uint16_t ) sum;
-
 
124
}
-
 
125
 
103
/** @}
126
/** @}
104
 */
127
 */