libosmocore  1.9.0.20-4ca0f.202310312026
Osmocom core library
crc16gen.h
Go to the documentation of this file.
1 
3 /*
4  * Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com>
5  *
6  * All Rights Reserved
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */
18 
19 #pragma once
20 
25 #include <stdint.h>
26 #include <osmocom/core/bits.h>
27 
28 
31  int bits;
32  uint16_t poly;
33  uint16_t init;
34  uint16_t remainder;
35 };
36 
37 uint16_t osmo_crc16gen_compute_bits(const struct osmo_crc16gen_code *code,
38  const ubit_t *in, int len);
39 int osmo_crc16gen_check_bits(const struct osmo_crc16gen_code *code,
40  const ubit_t *in, int len, const ubit_t *crc_bits);
41 void osmo_crc16gen_set_bits(const struct osmo_crc16gen_code *code,
42  const ubit_t *in, int len, ubit_t *crc_bits);
43 
44 
47 /* vim: set syntax=c: */
Osmocom bit level support code.
uint8_t ubit_t
unpacked bit (0 or 1): 1 bit per byte
Definition: bits.h:24
static size_t len(const char *str)
uint16_t osmo_crc16gen_compute_bits(const struct osmo_crc16gen_code *code, const ubit_t *in, int len)
Compute the CRC value of a given array of hard-bits.
Definition: crc16gen.c:40
void osmo_crc16gen_set_bits(const struct osmo_crc16gen_code *code, const ubit_t *in, int len, ubit_t *crc_bits)
Computes and writes the CRC value of a given array of bits.
Definition: crc16gen.c:100
int osmo_crc16gen_check_bits(const struct osmo_crc16gen_code *code, const ubit_t *in, int len, const ubit_t *crc_bits)
Checks the CRC value of a given array of hard-bits.
Definition: crc16gen.c:75
structure describing a given CRC code of max 16 bits
Definition: crc16gen.h:30
int bits
Actual number of bits of the CRC.
Definition: crc16gen.h:31
uint16_t init
Initialization value of the CRC state.
Definition: crc16gen.h:33
uint16_t poly
Polynom (normal representation, MSB omitted.
Definition: crc16gen.h:32
uint16_t remainder
Remainder of the CRC (final XOR)
Definition: crc16gen.h:34