comparison libutil/osmo_bits.h @ 194:05d01e810217

libutil: add TFO message gen function based on Osmocom crc8gen
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 17 Mar 2023 16:52:21 -0800
parents
children
comparison
equal deleted inserted replaced
193:1f9a6cede2c5 194:05d01e810217
1 /*
2 * This include file has been put together from Osmocom (specifically
3 * libosmocore) header files, containing definitions for bit vector
4 * manipulation and CRC functions.
5 */
6
7 /* from bits.h */
8
9 /*! unpacked bit (0 or 1): 1 bit per byte */
10 typedef uint8_t ubit_t;
11
12 /* from crc8gen.h */
13
14 /*! structure describing a given CRC code of max 8 bits */
15 struct osmo_crc8gen_code {
16 int bits; /*!< Actual number of bits of the CRC */
17 uint8_t poly; /*!< Polynom (normal representation, MSB omitted */
18 uint8_t init; /*!< Initialization value of the CRC state */
19 uint8_t remainder; /*!< Remainder of the CRC (final XOR) */
20 };
21
22 uint8_t osmo_crc8gen_compute_bits(const struct osmo_crc8gen_code *code,
23 const ubit_t *in, int len);
24 int osmo_crc8gen_check_bits(const struct osmo_crc8gen_code *code,
25 const ubit_t *in, int len, const ubit_t *crc_bits);
26 void osmo_crc8gen_set_bits(const struct osmo_crc8gen_code *code,
27 const ubit_t *in, int len, ubit_t *crc_bits);
28
29 /*
30 * Themyscira-added (not Osmocom-originating) functions
31 * that use the ubit_t defined type that (to our knowledge)
32 * was invented by Osmocom.
33 */
34
35 void uint16_to_bits(uint16_t word, ubit_t *out, unsigned nbits);