PebbleOS
Loading...
Searching...
No Matches
Data Structures | Macros | Functions

Checksums stored or exchanged by the firmware. More...

Data Structures

struct  pbl_crc32_legacy
 Running state of the legacy checksum. More...
 

Macros

#define PBL_CRC32_RESIDUE   0x2144DF1CU
 CRC-32 of a message with its little-endian CRC-32 appended, when the message is intact.
 

Functions

uint8_t pbl_crc8 (uint8_t crc, const void *data, size_t len)
 CRC-8/OPENSAFETY.
 
uint8_t pbl_crc8_reversed (uint8_t crc, const void *data, size_t len)
 pbl_crc8() consuming data from its last byte to its first.
 
uint32_t pbl_crc32 (uint32_t crc, const void *data, size_t len)
 CRC-32/ISO-HDLC, as used by zlib and PNG.
 
void pbl_crc32_legacy_init (struct pbl_crc32_legacy *ctx)
 Start a legacy checksum.
 
void pbl_crc32_legacy_update (struct pbl_crc32_legacy *ctx, const void *data, size_t len)
 Feed data to a legacy checksum.
 
uint32_t pbl_crc32_legacy_finish (struct pbl_crc32_legacy *ctx)
 Finish a legacy checksum.
 
uint32_t pbl_crc32_legacy (const void *data, size_t len)
 Legacy checksum of a single buffer.
 

Detailed Description

Checksums stored or exchanged by the firmware.

The software implementations are always built. Buffers of at least CONFIG_CRC_HW_MIN_LEN bytes are offloaded to a hardware CRC unit when a driver provides one (see CRC).

Every function takes the running value and returns the updated one, so data can be fed in chunks:

uint32_t crc = pbl_crc32(0, &hdr, sizeof(hdr));
crc = pbl_crc32(crc, payload, payload_len);
uint32_t pbl_crc32(uint32_t crc, const void *data, size_t len)
CRC-32/ISO-HDLC, as used by zlib and PNG.

Data Structure Documentation

◆ pbl_crc32_legacy

struct pbl_crc32_legacy

Running state of the legacy checksum.

The legacy checksum is the CRC-32/MPEG-2 computed by the STM32F2/F4 CRC unit over little-endian 32-bit words, MSB first: the checksum of bytes A B C D E F G H is the CRC of D C B A H G F E. A trailing partial word is zero-padded at the front, so bytes 1 2 3 4 5 6 are checksummed as 4 3 2 1 0 0 5 6. It persists in on-flash and on-wire formats.

struct pbl_crc32_legacy ctx;
pbl_crc32_legacy_update(&ctx, hdr, hdr_len);
pbl_crc32_legacy_update(&ctx, body, body_len);
uint32_t crc = pbl_crc32_legacy_finish(&ctx);
Running state of the legacy checksum.
Definition crc.h:85
uint32_t pbl_crc32_legacy_finish(struct pbl_crc32_legacy *ctx)
Finish a legacy checksum.
void pbl_crc32_legacy_update(struct pbl_crc32_legacy *ctx, const void *data, size_t len)
Feed data to a legacy checksum.
void pbl_crc32_legacy_init(struct pbl_crc32_legacy *ctx)
Start a legacy checksum.
Data Fields
uint8_t accumulated_length Number of valid bytes in accumulator.
uint8_t accumulator[3] Bytes of an incomplete word, pending until the next update or finish.
uint32_t reg CRC register.

Macro Definition Documentation

◆ PBL_CRC32_RESIDUE

#define PBL_CRC32_RESIDUE   0x2144DF1CU

CRC-32 of a message with its little-endian CRC-32 appended, when the message is intact.

Function Documentation

◆ pbl_crc32()

uint32_t pbl_crc32 ( uint32_t  crc,
const void *  data,
size_t  len 
)

CRC-32/ISO-HDLC, as used by zlib and PNG.

Compatible with zlib's crc32().

Parameters
crcRunning value, 0 to start.
dataData to checksum.
lenLength of data in bytes.
Returns
Updated CRC.

◆ pbl_crc32_legacy()

uint32_t pbl_crc32_legacy ( const void *  data,
size_t  len 
)

Legacy checksum of a single buffer.

Parameters
dataData to checksum.
lenLength of data in bytes.
Returns
Checksum.

◆ pbl_crc32_legacy_finish()

uint32_t pbl_crc32_legacy_finish ( struct pbl_crc32_legacy *  ctx)

Finish a legacy checksum.

Pads and consumes any trailing partial word.

Parameters
ctxChecksum state.
Returns
Checksum of all data fed since pbl_crc32_legacy_init().

◆ pbl_crc32_legacy_init()

void pbl_crc32_legacy_init ( struct pbl_crc32_legacy *  ctx)

Start a legacy checksum.

Parameters
ctxChecksum state.

◆ pbl_crc32_legacy_update()

void pbl_crc32_legacy_update ( struct pbl_crc32_legacy *  ctx,
const void *  data,
size_t  len 
)

Feed data to a legacy checksum.

Parameters
ctxChecksum state.
dataData to checksum.
lenLength of data in bytes.

◆ pbl_crc8()

uint8_t pbl_crc8 ( uint8_t  crc,
const void *  data,
size_t  len 
)

CRC-8/OPENSAFETY.

Polynomial 0x2F, zero initial value, no reflection and no final XOR.

Parameters
crcRunning value, 0 to start.
dataData to checksum.
lenLength of data in bytes.
Returns
Updated CRC.

◆ pbl_crc8_reversed()

uint8_t pbl_crc8_reversed ( uint8_t  crc,
const void *  data,
size_t  len 
)

pbl_crc8() consuming data from its last byte to its first.

Parameters
crcRunning value, 0 to start.
dataData to checksum.
lenLength of data in bytes.
Returns
Updated CRC.