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

ROHC CRC routines. More...

#include "crc.h"
#include "rohc.h"
#include "rtp.h"
#include <netinet/udp.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 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 int crc_type)
 Initialize a CRC table given a 256-byte table and the CRC type to use.
unsigned int crc_calculate (const int crc_type, const unsigned char *const data, const int length, const unsigned int init_val, const unsigned char *const crc_table)
 Calculate the checksum for the given data.
unsigned int compute_crc_static (const unsigned char *const ip, const unsigned char *const ip2, const unsigned char *const next_header, const unsigned int 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 unsigned int 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 unsigned int 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 unsigned int 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 rtp_compute_crc_static (const unsigned char *const ip, const unsigned char *const ip2, const unsigned char *const next_header, const unsigned int 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 unsigned int crc_type, const unsigned int init_val, const unsigned char *const crc_table)
 Compute the CRC-DYNAMIC part of a RTP header.
unsigned int ipv6_ext_compute_crc_static (const unsigned char *const ip, const unsigned int crc_type, const unsigned int init_val, const unsigned char *const crc_table)
 Compute the CRC-STATIC part of IPv6 extensions.
unsigned int ipv6_ext_compute_crc_dynamic (const unsigned char *const ip, const unsigned int crc_type, const unsigned int init_val, const unsigned char *const crc_table)
 Compute the CRC-DYNAMIC part of IPv6 extensions.

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

Function Documentation

unsigned int compute_crc_dynamic ( const unsigned char *const  ip,
const unsigned char *const  ip2,
const unsigned char *const  next_header,
const unsigned int  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 crc_calculate(), get_ip_version(), IPV4, ipv6_ext_compute_crc_dynamic(), and version.

Referenced by c_generic_create(), d_generic_create(), 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 unsigned int  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(), get_ip_version(), IPV4, ipv6_ext_compute_crc_static(), and version.

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

unsigned int crc_calculate ( const int  crc_type,
const unsigned char *const  data,
const int  length,
const unsigned int  init_val,
const unsigned char *const  crc_table 
)

Calculate the checksum for the given data.

Parameters:
crc_typeThe CRC type among CRC_TYPE_2, CRC_TYPE_3, CRC_TYPE_6, CRC_TYPE_7 or CRC_TYPE_8
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 CRC_TYPE_2, CRC_TYPE_3, CRC_TYPE_6, CRC_TYPE_7, and CRC_TYPE_8.

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

unsigned int ipv6_ext_compute_crc_dynamic ( const unsigned char *const  ip,
const unsigned int  crc_type,
const unsigned int  init_val,
const unsigned char *const  crc_table 
)

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

References crc_calculate(), ip_get_extension_size(), ip_get_next_ext_header_from_ext(), and IPV6_EXT_AUTH.

Referenced by compute_crc_dynamic().

unsigned int ipv6_ext_compute_crc_static ( const unsigned char *const  ip,
const unsigned int  crc_type,
const unsigned int  init_val,
const unsigned char *const  crc_table 
)

Compute the CRC-STATIC part of IPv6 extensions.

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

References crc_calculate(), ip_get_extension_size(), ip_get_next_ext_header_from_ext(), and IPV6_EXT_AUTH.

Referenced by compute_crc_static().

bool rohc_crc_init_table ( unsigned char *const  table,
const int  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 unsigned int  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 c_rtp_create(), and 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 unsigned int  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 c_rtp_create(), and 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 unsigned int  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(), and crc_calculate().

Referenced by c_udp_create(), c_udp_lite_create(), 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 unsigned int  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(), and crc_calculate().

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


Variable Documentation

unsigned char crc_table_2[256]
unsigned char crc_table_3 ( )

The table to enable fast CRC-3 computation

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

The table to enable fast CRC-6 computation

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

The table to enable fast CRC-7 computation

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

The table to enable fast CRC-8 computation

Deprecated:
please do not use this variable anymore