blob: 83b2e5f784b35f35fc0c4a4dc0b05c242356b209 [file] [log] [blame]
Ingo Albrecht383134b2010-07-15 22:43:52 +02001/*
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 Munaut12ba7782014-06-16 10:13:40 +020018#pragma once
Ingo Albrecht383134b2010-07-15 22:43:52 +020019
20#include <stdint.h>
21
22#include <sys/types.h>
23
Pablo Neira Ayusoddcd2af2011-05-07 12:43:12 +020024extern uint16_t const osmo_crc16_table[256];
Ingo Albrecht383134b2010-07-15 22:43:52 +020025
Pablo Neira Ayusoddcd2af2011-05-07 12:43:12 +020026extern uint16_t osmo_crc16(uint16_t crc, const uint8_t *buffer, size_t len);
Ingo Albrecht383134b2010-07-15 22:43:52 +020027
Pablo Neira Ayusoddcd2af2011-05-07 12:43:12 +020028static inline uint16_t osmo_crc16_byte(uint16_t crc, const uint8_t data)
Ingo Albrecht383134b2010-07-15 22:43:52 +020029{
Pablo Neira Ayusoddcd2af2011-05-07 12:43:12 +020030 return (crc >> 8) ^ osmo_crc16_table[(crc ^ data) & 0xff];
Ingo Albrecht383134b2010-07-15 22:43:52 +020031}