ROHC compression/decompression library
Functions | Variables
crc.c File Reference

ROHC CRC routines. More...

#include "crc.h"
#include "protocols/ip_numbers.h"
#include "protocols/ip.h"
#include "protocols/ipv4.h"
#include "protocols/ipv6.h"
#include "protocols/udp.h"
#include "protocols/rtp.h"
#include "protocols/esp.h"
#include "protocols/tcp.h"
#include <stdlib.h>
#include <assert.h>
Include dependency graph for crc.c:

Functions

static uint8_t ipv6_ext_calc_crc_static (const uint8_t *const ip, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-STATIC part of IPv6 extensions. More...
 
static uint8_t ipv6_ext_calc_crc_dyn (const uint8_t *const ip, const rohc_crc_type_t crc_type, const uint8_t init_val, const uint8_t *const crc_table)
 Compute the CRC-DYNAMIC part of IPv6 extensions. More...
 
static uint8_t * ipv6_get_first_extension (const uint8_t *const ip, uint8_t *const type)
 Get the first extension in an IPv6 packet. More...
 
static bool rohc_crc_get_polynom (const rohc_crc_type_t crc_type, uint8_t *const polynom)
 Get the polynom for the given CRC type. More...
 
static uint8_t crc_calc_8 (const uint8_t *const buf, const size_t size, const uint8_t init_val, const uint8_t *const crc_table)
 Optimized CRC-8 calculation using a table. More...
 
static uint8_t crc_calc_7 (const uint8_t *const buf, const size_t size, const uint8_t init_val, const uint8_t *const crc_table)
 Optimized CRC-7 calculation using a table. More...
 
static uint8_t crc_calc_3 (const uint8_t *const buf, const size_t size, const uint8_t init_val, const uint8_t *const crc_table)
 Optimized CRC-3 calculation using a table. More...
 
bool 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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 

Variables

static const uint32_t crc_table_fcs32 [256]
 The pre-computed table for 32-bit Frame Check Sequence (FCS) 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

Function Documentation

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
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
static uint8_t crc_calc_3 ( const uint8_t *const  buf,
const size_t  size,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)
inlinestatic

Optimized CRC-3 calculation using a table.

Parameters
bufThe data to compute the CRC for
sizeThe size of the data
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The CRC byte
static uint8_t crc_calc_7 ( const uint8_t *const  buf,
const size_t  size,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)
inlinestatic

Optimized CRC-7 calculation using a table.

Parameters
bufThe data to compute the CRC for
sizeThe size of the data
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The CRC byte
static uint8_t crc_calc_8 ( const uint8_t *const  buf,
const size_t  size,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)
inlinestatic

Optimized CRC-8 calculation using a table.

Parameters
bufThe data to compute the CRC for
sizeThe size of the data
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The CRC byte
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
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
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.

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
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.

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
static uint8_t ipv6_ext_calc_crc_dyn ( const uint8_t *const  ip,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)
static

Compute the CRC-DYNAMIC part of IPv6 extensions.

Only entire AH header is concerned.

Parameters
ipThe IPv6 packet
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The checksum
static uint8_t ipv6_ext_calc_crc_static ( const uint8_t *const  ip,
const rohc_crc_type_t  crc_type,
const uint8_t  init_val,
const uint8_t *const  crc_table 
)
static

Compute the CRC-STATIC part of IPv6 extensions.

Prototypes of private functions

Private functions All extensions are concerned except entire AH header.

Parameters
ipThe IPv6 packet
crc_typeThe type of CRC
init_valThe initial CRC value
crc_tableThe pre-computed table for fast CRC computation
Returns
The checksum
static uint8_t * ipv6_get_first_extension ( const uint8_t *const  ip,
uint8_t *const  type 
)
static

Get the first extension in an IPv6 packet.

Parameters
ipThe IPv6 packet
typeThe type of the extension
Returns
The extension, NULL if there is no extension
static bool rohc_crc_get_polynom ( const rohc_crc_type_t  crc_type,
uint8_t *const  polynom 
)
static

Get the polynom for the given CRC type.

Parameters
crc_typeThe CRC type
polynomIN/OUT: the polynom for the requested CRC type
Returns
true in case of success, false otherwise
bool 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
Returns
true in case of success, false in case of failure
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.

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
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.

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
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.

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
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.

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

Variable Documentation

const uint32_t crc_table_fcs32[256]
static

The pre-computed table for 32-bit Frame Check Sequence (FCS)

x**0 + x**1 + x**2 + x**4 + x**5 + x**7 + x**8 + x**10 + x**11 + x**12 + x**16 + x**22 + x**23 + x**26 + x**32

Copied from RFC 1662, appendix C.3