libosmocore  UNKNOWN
Osmocom core library
crc16.h
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 
18 #pragma once
19 
20 #include <stdint.h>
21 
22 #include <sys/types.h>
23 
24 extern uint16_t const osmo_crc16_table[256];
25 
26 extern uint16_t osmo_crc16(uint16_t crc, const uint8_t *buffer, size_t len);
27 
28 static inline uint16_t osmo_crc16_byte(uint16_t crc, const uint8_t data)
29 {
30  return (crc >> 8) ^ osmo_crc16_table[(crc ^ data) & 0xff];
31 }
32 
33 
34 /* CCITT polynome 0x8408. This corresponds to x^0 + x^5 + x^12 */
35 
36 extern uint16_t const osmo_crc16_ccitt_table[256];
37 
38 extern uint16_t osmo_crc16_ccitt(uint16_t crc, const uint8_t *buffer, size_t len);
39 
40 static inline uint16_t osmo_crc16_ccitt_byte(uint16_t crc, const uint8_t data)
41 {
42  return (crc >> 8) ^ osmo_crc16_ccitt_table[(crc ^ data) & 0xff];
43 }
int len
of data bits
Definition: conv.h:59