libosmocore  0.9.3
Osmocom core library
include/osmocom/core/crc16.h
00001 /*
00002  * This was copied from the linux kernel and adjusted for our types.
00003  */
00004 /*
00005  *      crc16.h - CRC-16 routine
00006  *
00007  * Implements the standard CRC-16:
00008  *   Width 16
00009  *   Poly  0x8005 (x^16 + x^15 + x^2 + 1)
00010  *   Init  0
00011  *
00012  * Copyright (c) 2005 Ben Gardner <bgardner@wabtec.com>
00013  *
00014  * This source code is licensed under the GNU General Public License,
00015  * Version 2. See the file COPYING for more details.
00016  */
00017 
00018 #pragma once
00019 
00020 #include <stdint.h>
00021 
00022 #include <sys/types.h>
00023 
00024 extern uint16_t const osmo_crc16_table[256];
00025 
00026 extern uint16_t osmo_crc16(uint16_t crc, const uint8_t *buffer, size_t len);
00027 
00028 static inline uint16_t osmo_crc16_byte(uint16_t crc, const uint8_t data)
00029 {
00030         return (crc >> 8) ^ osmo_crc16_table[(crc ^ data) & 0xff];
00031 }