Ingo Albrecht | 383134b | 2010-07-15 22:43:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This was copied from the linux kernel and adjusted for our types. |
| 3 | */ |
| 4 | /* |
| 5 | * crc16.h - CRC-16 routine |
| 6 | * |
| 7 | * Implements the standard CRC-16: |
| 8 | * Width 16 |
| 9 | * Poly 0x8005 (x^16 + x^15 + x^2 + 1) |
| 10 | * Init 0 |
| 11 | * |
| 12 | * Copyright (c) 2005 Ben Gardner <bgardner@wabtec.com> |
| 13 | * |
| 14 | * This source code is licensed under the GNU General Public License, |
| 15 | * Version 2. See the file COPYING for more details. |
| 16 | */ |
| 17 | |
Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 18 | #pragma once |
Ingo Albrecht | 383134b | 2010-07-15 22:43:52 +0200 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <sys/types.h> |
| 23 | |
Pablo Neira Ayuso | ddcd2af | 2011-05-07 12:43:12 +0200 | [diff] [blame] | 24 | extern uint16_t const osmo_crc16_table[256]; |
Ingo Albrecht | 383134b | 2010-07-15 22:43:52 +0200 | [diff] [blame] | 25 | |
Pablo Neira Ayuso | ddcd2af | 2011-05-07 12:43:12 +0200 | [diff] [blame] | 26 | extern uint16_t osmo_crc16(uint16_t crc, const uint8_t *buffer, size_t len); |
Ingo Albrecht | 383134b | 2010-07-15 22:43:52 +0200 | [diff] [blame] | 27 | |
Pablo Neira Ayuso | ddcd2af | 2011-05-07 12:43:12 +0200 | [diff] [blame] | 28 | static inline uint16_t osmo_crc16_byte(uint16_t crc, const uint8_t data) |
Ingo Albrecht | 383134b | 2010-07-15 22:43:52 +0200 | [diff] [blame] | 29 | { |
Pablo Neira Ayuso | ddcd2af | 2011-05-07 12:43:12 +0200 | [diff] [blame] | 30 | return (crc >> 8) ^ osmo_crc16_table[(crc ^ data) & 0xff]; |
Ingo Albrecht | 383134b | 2010-07-15 22:43:52 +0200 | [diff] [blame] | 31 | } |