osdep: include glib-compat.h before other QEMU headers
[qemu/ar7.git] / include / qemu / crc-ccitt.h
blob06ee55b159b3eba53836fd4f44d698bbc3dc065b
1 /*
2 * CRC16 (CCITT) Checksum Algorithm
4 * Copyright (c) 2021 Wind River Systems, Inc.
6 * Author:
7 * Bin Meng <bin.meng@windriver.com>
9 * From Linux kernel v5.10 include/linux/crc-ccitt.h
11 * SPDX-License-Identifier: GPL-2.0
14 #ifndef _CRC_CCITT_H
15 #define _CRC_CCITT_H
17 extern uint16_t const crc_ccitt_table[256];
18 extern uint16_t const crc_ccitt_false_table[256];
20 extern uint16_t crc_ccitt(uint16_t crc, const uint8_t *buffer, size_t len);
21 extern uint16_t crc_ccitt_false(uint16_t crc, const uint8_t *buffer, size_t len);
23 static inline uint16_t crc_ccitt_byte(uint16_t crc, const uint8_t c)
25 return (crc >> 8) ^ crc_ccitt_table[(crc ^ c) & 0xff];
28 static inline uint16_t crc_ccitt_false_byte(uint16_t crc, const uint8_t c)
30 return (crc << 8) ^ crc_ccitt_false_table[(crc >> 8) ^ c];
33 #endif /* _CRC_CCITT_H */