ROHC compression/decompression library
Macros | Enumerations | Functions
crc.h File Reference

ROHC CRC routines. More...

#include "ip.h"
#include "protocols/udp.h"
#include "protocols/rtp.h"
#include "protocols/esp.h"
#include "protocols/tcp.h"
#include <stdbool.h>
Include dependency graph for crc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CRC_INIT_3   0x7
 The CRC-3 initial value. More...
 
#define CRC_INIT_7   0x7f
 The CRC-7 initial value. More...
 
#define CRC_INIT_8   0xff
 The CRC-8 initial value. More...
 
#define CRC_INIT_FCS32   0xffffffff
 
#define CRC_FCS32_LEN   4U
 

Enumerations

enum  rohc_crc_type_t { ROHC_CRC_TYPE_NONE = 0, ROHC_CRC_TYPE_3 = 3, ROHC_CRC_TYPE_7 = 7, ROHC_CRC_TYPE_8 = 8 }
 

Functions

void rohc_crc_init_table (uint8_t *const table, const rohc_crc_type_t crc_type)
 Initialize a CRC table given a 256-byte table and the CRC type to use. More...
 
uint8_t crc_calculate (const rohc_crc_type_t crc_type, const uint8_t *const data, const size_t length, const uint8_t init_val, const uint8_t *const crc_table)
 Calculate the checksum for the given data. More...
 
uint32_t crc_calc_fcs32 (const uint8_t *const data, const size_t length, const uint32_t init_val)
 Optimized CRC FCS-32 calculation using a table. More...
 
uint8_t compute_crc_static (const uint8_t *const outer_ip, const uint8_t *const inner_ip, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-STATIC part of an IP header. More...
 
uint8_t compute_crc_dynamic (const uint8_t *const outer_ip, const uint8_t *const inner_ip, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-DYNAMIC part of an IP header. More...
 
static uint8_t udp_compute_crc_static (const uint8_t *const outer_ip, const uint8_t *const inner_ip, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-STATIC part of an UDP or UDP-Lite header. More...
 
static uint8_t udp_compute_crc_dynamic (const uint8_t *const outer_ip, const uint8_t *const inner_ip, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-DYNAMIC part of an UDP or UDP-Lite header. More...
 
static uint8_t esp_compute_crc_static (const uint8_t *const outer_ip, const uint8_t *const inner_ip, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-STATIC part of an ESP header. More...
 
static uint8_t esp_compute_crc_dynamic (const uint8_t *const outer_ip, const uint8_t *const inner_ip, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-DYNAMIC part of an ESP header. More...
 
static uint8_t rtp_compute_crc_static (const uint8_t *const outer_ip, const uint8_t *const inner_ip, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-STATIC part of a RTP header. More...
 
static uint8_t rtp_compute_crc_dynamic (const uint8_t *const outer_ip, const uint8_t *const inner_ip, const uint8_t *const next_header, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-DYNAMIC part of a RTP header. More...
 

Detailed Description

ROHC CRC routines.

Author
Didier Barvaux didie.nosp@m.r.ba.nosp@m.rvaux.nosp@m.@tou.nosp@m.louse.nosp@m..viv.nosp@m.eris..nosp@m.com
Didier Barvaux didie.nosp@m.r@ba.nosp@m.rvaux.nosp@m..org
FWX rohc_.nosp@m.team.nosp@m.@dial.nosp@m.ine..nosp@m.fr

Macro Definition Documentation

◆ CRC_FCS32_LEN

#define CRC_FCS32_LEN   4U

The length (in bytes) of the FCS-32 CRC

◆ CRC_INIT_3

#define CRC_INIT_3   0x7

The CRC-3 initial value.

◆ CRC_INIT_7

#define CRC_INIT_7   0x7f

The CRC-7 initial value.

◆ CRC_INIT_8

#define CRC_INIT_8   0xff

The CRC-8 initial value.

◆ CRC_INIT_FCS32

#define CRC_INIT_FCS32   0xffffffff

The FCS-32 initial value

Enumeration Type Documentation

◆ rohc_crc_type_t

The different types of CRC used to protect ROHC headers

Enumerator
ROHC_CRC_TYPE_NONE 

No CRC selected

ROHC_CRC_TYPE_3 

The CRC-3 type

ROHC_CRC_TYPE_7 

The CRC-7 type

ROHC_CRC_TYPE_8 

The CRC-8 type

Function Documentation

◆ compute_crc_dynamic()

uint8_t compute_crc_dynamic ( const uint8_t *const  outer_ip,
const uint8_t *const  inner_ip,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-DYNAMIC part of an IP header.

Concerned fields are:

  • bytes 3-4, 5-6, 11-12 in original IPv4 header
  • bytes 5-6 in original IPv6 header
Parameters
outer_ipThe outer IP packet
inner_ipThe inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The checksum

◆ compute_crc_static()

uint8_t compute_crc_static ( const uint8_t *const  outer_ip,
const uint8_t *const  inner_ip,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Compute the CRC-STATIC part of an IP header.

Concerned fields are: all fields expect those for CRC-DYNAMIC

  • bytes 1-2, 7-10, 13-20 in original IPv4 header
  • bytes 1-4, 7-40 in original IPv6 header

This function is one of the functions that must exist in one profile for the framework to work.

Parameters
outer_ipThe outer IP packet
inner_ipThe inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The checksum

◆ crc_calc_fcs32()

uint32_t crc_calc_fcs32 ( const uint8_t *const  data,
const size_t  length,
const uint32_t  init_val 
)

Optimized CRC FCS-32 calculation using a table.

Parameters
dataThe data to compute the CRC for
lengthThe size of the data
init_valThe initial value of the CRC
Returns
The 32-bit CRC

◆ crc_calculate()

uint8_t crc_calculate ( const rohc_crc_type_t  crc_type,
const uint8_t *const  data,
const size_t  length,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)

Calculate the checksum for the given data.

Parameters
crc_typeThe CRC type
dataThe data to calculate the checksum on
lengthThe length of the data
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The checksum

◆ esp_compute_crc_dynamic()

static uint8_t esp_compute_crc_dynamic ( const uint8_t *const  outer_ip,
const uint8_t *const  inner_ip,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)
inlinestatic

Compute the CRC-DYNAMIC part of an ESP header.

Concerned fields are:

  • bytes 5-8 in original ESP header
Parameters
outer_ipThe outer IP packet
inner_ipThe inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The checksum

◆ esp_compute_crc_static()

static uint8_t esp_compute_crc_static ( const uint8_t *const  outer_ip,
const uint8_t *const  inner_ip,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)
inlinestatic

Compute the CRC-STATIC part of an ESP header.

Concerned fields are: all fields expect those for CRC-DYNAMIC

  • bytes 1-4 in original ESP header
Parameters
outer_ipThe outer IP packet
inner_ipThe inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The checksum

◆ rohc_crc_init_table()

void rohc_crc_init_table ( uint8_t *const  table,
const rohc_crc_type_t  crc_type 
)

Initialize a CRC table given a 256-byte table and the CRC type to use.

Public functions

Parameters
tableIN/OUT: The 256-byte table to initialize
crc_typeThe type of CRC to initialize the table for

◆ rtp_compute_crc_dynamic()

static uint8_t rtp_compute_crc_dynamic ( const uint8_t *const  outer_ip,
const uint8_t *const  inner_ip,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)
inlinestatic

Compute the CRC-DYNAMIC part of a RTP header.

Concerned fields are:

  • bytes 2, 3-4, 5-8 in original RTP header
Parameters
outer_ipThe outer IP packet
inner_ipThe inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The checksum

◆ rtp_compute_crc_static()

static uint8_t rtp_compute_crc_static ( const uint8_t *const  outer_ip,
const uint8_t *const  inner_ip,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)
inlinestatic

Compute the CRC-STATIC part of a RTP header.

Concerned fields are: all fields expect those for CRC-DYNAMIC

  • bytes 1, 9-12 (and CSRC list) in original RTP header
Parameters
outer_ipThe outer IP packet
inner_ipThe inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The checksum

◆ udp_compute_crc_dynamic()

static uint8_t udp_compute_crc_dynamic ( const uint8_t *const  outer_ip,
const uint8_t *const  inner_ip,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)
inlinestatic

Compute the CRC-DYNAMIC part of an UDP or UDP-Lite header.

Concerned fields are:

  • bytes 5-6, 7-8 in original UDP header
Parameters
outer_ipThe outer IP packet
inner_ipThe inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The checksum

◆ udp_compute_crc_static()

static uint8_t udp_compute_crc_static ( const uint8_t *const  outer_ip,
const uint8_t *const  inner_ip,
const uint8_t *const  next_header,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)
inlinestatic

Compute the CRC-STATIC part of an UDP or UDP-Lite header.

Concerned fields are: all fields expect those for CRC-DYNAMIC

  • bytes 1-4 in original UDP header
Parameters
outer_ipThe outer IP packet
inner_ipThe inner IP packet if there is 2 IP headers, NULL otherwise
next_headerThe next header located after the IP header(s)
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The checksum