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

ROHC CRC routines. More...

#include "crc.h"
#include "rohc.h"
#include "protocols/udp.h"
#include "protocols/rtp.h"
#include "protocols/esp.h"
#include <stdlib.h>
#include <assert.h>
Include dependency graph for crc.c:

Functions

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

Variables

unsigned char crc_table_8 [256]
unsigned char crc_table_7 [256]
unsigned char crc_table_6 [256]
unsigned char crc_table_3 [256]
unsigned char crc_table_2 [256]
static unsigned int static
unsigned int static unsigned
char static bool 
warn_unused_result

Detailed Description

ROHC CRC routines.

Author:
Didier Barvaux <didier.barvaux@toulouse.viveris.com>
The hackers from ROHC for Linux
Didier Barvaux <didier@barvaux.org>
FWX <rohc_team@dialine.fr>

Function Documentation

unsigned int compute_crc_dynamic ( const unsigned char *const  ip,
const unsigned char *const  ip2,
const unsigned char *const  next_header,
const rohc_crc_type_t  crc_type,
const unsigned int  init_val,
const unsigned char *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:
ipThe outer IP packet
ip2The 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

References ipv4_hdr::check, crc_calculate(), get_ip_version(), IPV4, ipv4_hdr::tot_len, and version.

Referenced by c_generic_create(), d_generic_create(), esp_compute_crc_dynamic(), and udp_compute_crc_dynamic().

unsigned int compute_crc_static ( const unsigned char *const  ip,
const unsigned char *const  ip2,
const unsigned char *const  next_header,
const rohc_crc_type_t  crc_type,
const unsigned int  init_val,
const unsigned char *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:
ipThe outer IP packet
ip2The 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

References crc_calculate(), ipv4_hdr::frag_off, get_ip_version(), IPV4, ipv4_hdr::saddr, and version.

Referenced by c_generic_create(), d_generic_create(), esp_compute_crc_static(), and udp_compute_crc_static().

uint32_t crc_calc_fcs32 ( const unsigned char *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

Referenced by rohc_compress2().

unsigned int crc_calculate ( const rohc_crc_type_t  crc_type,
const unsigned char *const  data,
const size_t  length,
const unsigned char  init_val,
const unsigned char *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

References ROHC_CRC_TYPE_2, ROHC_CRC_TYPE_3, ROHC_CRC_TYPE_6, ROHC_CRC_TYPE_7, and ROHC_CRC_TYPE_8.

Referenced by c_generic_feedback(), code_IR_DYN_packet(), code_IR_packet(), compute_crc_dynamic(), compute_crc_static(), esp_compute_crc_dynamic(), esp_compute_crc_static(), f_wrap_feedback(), rtp_compute_crc_dynamic(), rtp_compute_crc_static(), udp_compute_crc_dynamic(), and udp_compute_crc_static().

unsigned int esp_compute_crc_dynamic ( const unsigned char *const  ip,
const unsigned char *const  ip2,
const unsigned char *const  next_header,
const rohc_crc_type_t  crc_type,
const unsigned int  init_val,
const unsigned char *const  crc_table 
)

Compute the CRC-DYNAMIC part of an ESP header.

Concerned fields are:

  • bytes 5-8 in original ESP header
Parameters:
ipThe outer IP packet
ip2The 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

References compute_crc_dynamic(), crc_calculate(), and esphdr::sn.

unsigned int esp_compute_crc_static ( const unsigned char *const  ip,
const unsigned char *const  ip2,
const unsigned char *const  next_header,
const rohc_crc_type_t  crc_type,
const unsigned int  init_val,
const unsigned char *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:
ipThe outer IP packet
ip2The 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

References compute_crc_static(), crc_calculate(), and esphdr::spi.

bool rohc_crc_init_table ( unsigned char *const  table,
const rohc_crc_type_t  crc_type 
)

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

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

Referenced by rohc_alloc_compressor(), and rohc_alloc_decompressor().

unsigned int rtp_compute_crc_dynamic ( const unsigned char *const  ip,
const unsigned char *const  ip2,
const unsigned char *const  next_header,
const rohc_crc_type_t  crc_type,
const unsigned int  init_val,
const unsigned char *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:
ipThe outer IP packet
ip2The 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

References crc_calculate(), and udp_compute_crc_dynamic().

Referenced by d_rtp_create().

unsigned int rtp_compute_crc_static ( const unsigned char *const  ip,
const unsigned char *const  ip2,
const unsigned char *const  next_header,
const rohc_crc_type_t  crc_type,
const unsigned int  init_val,
const unsigned char *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:
ipThe outer IP packet
ip2The 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

References crc_calculate(), and udp_compute_crc_static().

Referenced by d_rtp_create().

unsigned int udp_compute_crc_dynamic ( const unsigned char *const  ip,
const unsigned char *const  ip2,
const unsigned char *const  next_header,
const rohc_crc_type_t  crc_type,
const unsigned int  init_val,
const unsigned char *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:
ipThe outer IP packet
ip2The 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

References compute_crc_dynamic(), crc_calculate(), and udphdr::len.

Referenced by d_udp_create(), d_udp_lite_create(), and rtp_compute_crc_dynamic().

unsigned int udp_compute_crc_static ( const unsigned char *const  ip,
const unsigned char *const  ip2,
const unsigned char *const  next_header,
const rohc_crc_type_t  crc_type,
const unsigned int  init_val,
const unsigned char *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:
ipThe outer IP packet
ip2The 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

References compute_crc_static(), crc_calculate(), and udphdr::source.

Referenced by d_udp_create(), d_udp_lite_create(), and rtp_compute_crc_static().


Variable Documentation

unsigned char crc_table_2[256]
unsigned char ROHC_EXPORT crc_table_3 ( )

The table to enable fast CRC-3 computation

Deprecated:
please do not use this variable anymore
unsigned char ROHC_EXPORT crc_table_6 ( )

The table to enable fast CRC-6 computation

Deprecated:
please do not use this variable anymore
unsigned char ROHC_EXPORT crc_table_7 ( )

The table to enable fast CRC-7 computation

Deprecated:
please do not use this variable anymore
unsigned char ROHC_EXPORT crc_table_8 ( )

The table to enable fast CRC-8 computation

Deprecated:
please do not use this variable anymore
unsigned int static unsigned int static unsigned char static bool warn_unused_result