Broadcom SDK and wireless driver: another attempt to update to ver. 5.10.147.0
[tomato.git] / release / src-rt / include / rts / crc.h
blobda457be0fbaab57d5aed06e263404fcb936a1c41
1 /*******************************************************************************
2 * $Id: crc.h,v 8.9 2003/10/16 21:55:54 Exp $
3 * Copyright (C) 2009, Broadcom Corporation
4 * All Rights Reserved.
5 *
6 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
7 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
8 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
9 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
10 * crc.h - a function to compute crc for iLine10 headers
11 ******************************************************************************/
13 #ifndef _RTS_CRC_H_
14 #define _RTS_CRC_H_ 1
16 #include "typedefs.h"
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
23 #define CRC8_INIT_VALUE 0xff /* Initial CRC8 checksum value */
24 #define CRC8_GOOD_VALUE 0x9f /* Good final CRC8 checksum value */
25 #define HCS_GOOD_VALUE 0x39 /* Good final header checksum value */
27 #define CRC16_INIT_VALUE 0xffff /* Initial CRC16 checksum value */
28 #define CRC16_GOOD_VALUE 0xf0b8 /* Good final CRC16 checksum value */
30 #define CRC32_INIT_VALUE 0xffffffff /* Initial CRC32 checksum value */
31 #define CRC32_GOOD_VALUE 0xdebb20e3 /* Good final CRC32 checksum value */
33 void hcs(uint8 *, uint);
34 uint8 crc8(uint8 *, uint, uint8);
35 uint16 crc16(uint8 *, uint, uint16);
36 uint32 crc32(uint8 *, uint, uint32);
38 /* macros for common usage */
40 #define APPEND_CRC8(pbytes, nbytes) \
41 do { \
42 uint8 tmp = crc8(pbytes, nbytes, CRC8_INIT_VALUE) ^ 0xff; \
43 (pbytes)[(nbytes)] = tmp; \
44 (nbytes) += 1; \
45 } while (0)
47 #define APPEND_CRC16(pbytes, nbytes) \
48 do { \
49 uint16 tmp = crc16(pbytes, nbytes, CRC16_INIT_VALUE) ^ 0xffff; \
50 (pbytes)[(nbytes) + 0] = (tmp >> 0) & 0xff; \
51 (pbytes)[(nbytes) + 1] = (tmp >> 8) & 0xff; \
52 (nbytes) += 2; \
53 } while (0)
55 #define APPEND_CRC32(pbytes, nbytes) \
56 do { \
57 uint32 tmp = crc32(pbytes, nbytes, CRC32_INIT_VALUE) ^ 0xffffffff; \
58 (pbytes)[(nbytes) + 0] = (tmp >> 0) & 0xff; \
59 (pbytes)[(nbytes) + 1] = (tmp >> 8) & 0xff; \
60 (pbytes)[(nbytes) + 2] = (tmp >> 16) & 0xff; \
61 (pbytes)[(nbytes) + 3] = (tmp >> 24) & 0xff; \
62 (nbytes) += 4; \
63 } while (0)
65 #ifdef __cplusplus
67 #endif
69 #endif /* _RTS_CRC_H_ */