Skip to content

File dp_crc.h

FileList > doppler > dp_crc.h

Go to the source code of this file

One parametric CRC: the Rocksoft model over a bit stream. More...

  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct dp_crc_t
A CRC model: width, polynomial, initial register, output reflection, output XOR and input reflection.

Public Static Functions

Type Name
uint64_t dp_crc_bits (const dp_crc_t * p, const uint8_t * bits, size_t n)
The CRC of a bit stream: first bit presented is shifted in first.
uint64_t dp_crc_bytes (const dp_crc_t * p, const uint8_t * bytes, size_t n)
The CRC of octets, the model's refin choosing each octet's bit order.
uint64_t dp_crc_finish (const dp_crc_t * p, uint64_t reg)
The register's result: reflected if the model says so, then XORed. The one place that happens.
uint64_t dp_crc_mask (unsigned width)
uint64_t dp_crc_reflect (uint64_t v, unsigned width)
The register's bits, reversed within width .
uint64_t dp_crc_step (const dp_crc_t * p, uint64_t reg, unsigned bit)
Shift one bit into the register: the only place the model's arithmetic is written.
int dp_crc_valid (const dp_crc_t * p)
Is p a model this header can compute?

Macros

Type Name
define DP_CRC_16_IBM_3740 /* multi line expression */
CRC-16/IBM-3740, formerly CRC-16/CCITT-FALSE: the burst frame's trailer. Check 0x29B1, refin false.
define DP_CRC_16_KERMIT /* multi line expression */
CRC-16/KERMIT. Check 0x2189, refin true.
define DP_CRC_16_XMODEM /* multi line expression */
CRC-16/XMODEM. Check 0x31C3, refin false.
define DP_CRC_32C /* multi line expression */
CRC-32C (Castagnoli, iSCSI). Check 0xE3069283, refin true.
define DP_CRC_32_BZIP2 /* multi line expression */
CRC-32/BZIP2: the same polynomial, not reflected. Check 0xFC891918, refin false.
define DP_CRC_32_ISO_HDLC /* multi line expression */
CRC-32/ISO-HDLC (Ethernet, zlib). Check value 0xCBF43926. Its catalogue refin is true: feed octets LSB-first, which dp_crc_bytes() does for it.
define DP_CRC_64_ECMA_182 /* multi line expression */
CRC-64/ECMA-182. Check 0x6C40DF5F0B497347, refin false.
define DP_CRC_8_ROHC /* multi line expression */
CRC-8/ROHC. Check 0xD0, refin true.
define DP_CRC_8_SMBUS /* multi line expression */
CRC-8/SMBUS. Check 0xF4, refin false.

Detailed Description

A CRC is a model, not an algorithm: a width, a generator polynomial, an initial register, whether each input octet is reflected, whether the final register is, and a value XORed into the result. Every named CRC is those six numbers. This header holds the one loop that computes any of them and the named instances the tree uses, so a frame's FCS (CRC-32) and the burst frame's trailer (CRC-16-CCITT) are rows of data and cannot grow copies of the arithmetic. (The SIG fields' CRC-8 parameters are not a named row: they are the protocol's to state, see the last paragraph.)

Header-only, for the reason dp_crc16.h was: no component grows a link-line dependency for a ten-line kernel.

The input is a bit stream; <tt>refin</tt> is for the caller holding octets

The library moves bits unpacked, one per byte in the LSB (conv, the interleaver, a frame's stages). dp_crc_bits() takes exactly that and shifts the first bit presented into the register first, MSB-first. The catalogue's refin ("reflect each input byte") is a field of the model for a caller holding octets: dp_crc_bytes() feeds each octet LSB-first when refin is set, and calls the same bit loop. dp_crc_bits() never reads it: a stream already in bit order has nothing left to reflect, so for it refin is a property of the stream the caller builds. refout acts on the result, in both.

Where the check values come from

The named instances below carry the catalogue's names and parameters (the CRC RevEng catalogue, https://reveng.sourceforge.io/crc-catalogue/), and test_dp_crc.c pins each to the catalogue's check value, the CRC of the nine ASCII characters 123456789. Those values define the named CRC. That is what the test holds: each named model's check value, nothing more.

A named instance is not a claim that a standard uses it. Which model a given protocol field takes, and in what bit order the value is transmitted, are facts in that protocol's text. Nothing here says so.

Public Static Functions Documentation

function dp_crc_bits

The CRC of a bit stream: first bit presented is shifted in first.

static inline uint64_t dp_crc_bits (
    const dp_crc_t * p,
    const uint8_t * bits,
    size_t n
) 

Each input byte carries ONE bit (0/1) in its LSB, the form the frame paths pass around. The register shifts MSB-first, so presenting the bits in transmission order gives the usual CRC of a transmitted message, and an refin = true catalogue model needs each octet's bits presented LSB-first (see dp_crc_bytes()).

The value is returned right-aligned in width bits. How it is transmitted, MSB-first or otherwise, is the protocol's, not this function's.

Parameters:

  • p A valid model (see dp_crc_valid(); not checked here).
  • bits n bytes, each 0 or 1 (only the LSB is used).
  • n Number of bits.

Returns:

The CRC, in the low p->width bits.


function dp_crc_bytes

The CRC of octets, the model's refin choosing each octet's bit order.

static inline uint64_t dp_crc_bytes (
    const dp_crc_t * p,
    const uint8_t * bytes,
    size_t n
) 

Presents every octet's bits to the same step as dp_crc_bits(): LSB-first when p->refin is non-zero (the reflected CRCs: ISO-HDLC, CRC-32C, KERMIT, ROHC), MSB-first when it is zero.

Parameters:

  • p A valid model.
  • bytes n octets.
  • n Number of octets.

Returns:

The CRC, in the low p->width bits.


function dp_crc_finish

The register's result: reflected if the model says so, then XORed. The one place that happens.

static inline uint64_t dp_crc_finish (
    const dp_crc_t * p,
    uint64_t reg
) 


function dp_crc_mask

static inline uint64_t dp_crc_mask (
    unsigned width
) 

function dp_crc_reflect

The register's bits, reversed within width .

static inline uint64_t dp_crc_reflect (
    uint64_t v,
    unsigned width
) 


function dp_crc_step

Shift one bit into the register: the only place the model's arithmetic is written.

static inline uint64_t dp_crc_step (
    const dp_crc_t * p,
    uint64_t reg,
    unsigned bit
) 

dp_crc_bits() and dp_crc_bytes() both call this, so there is one step and the two entry points cannot disagree about it.

Parameters:

  • p A valid model.
  • reg The register, width bits.
  • bit The bit; only the LSB is used.

Returns:

The register after the bit.


function dp_crc_valid

Is p a model this header can compute?

static inline int dp_crc_valid (
    const dp_crc_t * p
) 

Parameters:

  • p The model.

Returns:

Non-zero if width is in [1, 64] and poly, init and xorout fit in width bits. A polynomial of zero is allowed (it is the degenerate CRC that shifts its register out).


Macro Definition Documentation

define DP_CRC_16_IBM_3740

CRC-16/IBM-3740, formerly CRC-16/CCITT-FALSE: the burst frame's trailer. Check 0x29B1, refin false.

#define DP_CRC_16_IBM_3740 `/* multi line expression */`


define DP_CRC_16_KERMIT

CRC-16/KERMIT. Check 0x2189, refin true.

#define DP_CRC_16_KERMIT `/* multi line expression */`


define DP_CRC_16_XMODEM

CRC-16/XMODEM. Check 0x31C3, refin false.

#define DP_CRC_16_XMODEM `/* multi line expression */`


define DP_CRC_32C

CRC-32C (Castagnoli, iSCSI). Check 0xE3069283, refin true.

#define DP_CRC_32C `/* multi line expression */`


define DP_CRC_32_BZIP2

CRC-32/BZIP2: the same polynomial, not reflected. Check 0xFC891918, refin false.

#define DP_CRC_32_BZIP2 `/* multi line expression */`


define DP_CRC_32_ISO_HDLC

CRC-32/ISO-HDLC (Ethernet, zlib). Check value 0xCBF43926. Its catalogue refin is true: feed octets LSB-first, which dp_crc_bytes() does for it.

#define DP_CRC_32_ISO_HDLC `/* multi line expression */`


define DP_CRC_64_ECMA_182

CRC-64/ECMA-182. Check 0x6C40DF5F0B497347, refin false.

#define DP_CRC_64_ECMA_182 `/* multi line expression */`


define DP_CRC_8_ROHC

CRC-8/ROHC. Check 0xD0, refin true.

#define DP_CRC_8_ROHC `/* multi line expression */`


define DP_CRC_8_SMBUS

CRC-8/SMBUS. Check 0xF4, refin false.

#define DP_CRC_8_SMBUS `/* multi line expression */`



The documentation for this class was generated from the following file native/inc/doppler/dp_crc.h