Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
crc8.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 #ifndef __CRC8_H_
17 #define __CRC8_H_
18 
19 #include <linux/types.h>
20 
21 /* see usage of this value in crc8() description */
22 #define CRC8_INIT_VALUE 0xFF
23 
24 /*
25  * Return value of crc8() indicating valid message+crc. This is true
26  * if a CRC is inverted before transmission. The CRC computed over the
27  * whole received bitstream is _table[x], where x is the bit pattern
28  * of the modification (almost always 0xff).
29  */
30 #define CRC8_GOOD_VALUE(_table) (_table[0xFF])
31 
32 /* required table size for crc8 algorithm */
33 #define CRC8_TABLE_SIZE 256
34 
35 /* helper macro assuring right table size is used */
36 #define DECLARE_CRC8_TABLE(_table) \
37  static u8 _table[CRC8_TABLE_SIZE]
38 
55 void crc8_populate_lsb(u8 table[CRC8_TABLE_SIZE], u8 polynomial);
56 
73 void crc8_populate_msb(u8 table[CRC8_TABLE_SIZE], u8 polynomial);
74 
99 u8 crc8(const u8 table[CRC8_TABLE_SIZE], u8 *pdata, size_t nbytes, u8 crc);
100 
101 #endif /* __CRC8_H_ */