ROHC compression/decompression library
|
ROHC CRC routines. More...
#include "crc.h"
#include "protocols/ip_numbers.h"
#include "protocols/udp.h"
#include "protocols/rtp.h"
#include "protocols/esp.h"
#include "protocols/tcp.h"
#include <stdlib.h>
#include <assert.h>
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. | |
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. | |
static uint8_t * | ipv6_get_first_extension (const uint8_t *const ip, uint8_t *const type) |
Get the first extension in an IPv6 packet. | |
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. | |
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. | |
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. | |
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. | |
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 (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. | |
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. | |
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. | |
uint8_t | compute_crc_static (const uint8_t *const ip, const uint8_t *const ip2, 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. | |
uint8_t | compute_crc_dynamic (const uint8_t *const ip, const uint8_t *const ip2, 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. | |
uint8_t | udp_compute_crc_static (const uint8_t *const ip, const uint8_t *const ip2, 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. | |
uint8_t | udp_compute_crc_dynamic (const uint8_t *const ip, const uint8_t *const ip2, 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. | |
uint8_t | esp_compute_crc_static (const uint8_t *const ip, const uint8_t *const ip2, 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. | |
uint8_t | esp_compute_crc_dynamic (const uint8_t *const ip, const uint8_t *const ip2, 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. | |
uint8_t | rtp_compute_crc_static (const uint8_t *const ip, const uint8_t *const ip2, 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. | |
uint8_t | rtp_compute_crc_dynamic (const uint8_t *const ip, const uint8_t *const ip2, 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. | |
uint8_t | tcp_compute_crc_static (const uint8_t *const ip, const uint8_t *const ip2, 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 TCP header. | |
uint8_t | tcp_compute_crc_dynamic (const uint8_t *const ip, const uint8_t *const ip2, 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 TCP 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 const uint32_t | crc_table_fcs32 [256] |
The pre-computed table for 32-bit Frame Check Sequence (FCS) |
ROHC CRC routines.
uint8_t compute_crc_dynamic | ( | const uint8_t *const | ip, |
const uint8_t *const | ip2, | ||
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:
ip | The outer IP packet |
ip2 | The inner IP packet if there is 2 IP headers, NULL otherwise |
next_header | The next header located after the IP header(s) |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
uint8_t compute_crc_static | ( | const uint8_t *const | ip, |
const uint8_t *const | ip2, | ||
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
This function is one of the functions that must exist in one profile for the framework to work.
ip | The outer IP packet |
ip2 | The inner IP packet if there is 2 IP headers, NULL otherwise |
next_header | The next header located after the IP header(s) |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
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 | ||
) | [inline, static] |
Optimized CRC-3 calculation using a table.
buf | The data to compute the CRC for |
size | The size of the data |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
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 | ||
) | [inline, static] |
Optimized CRC-7 calculation using a table.
buf | The data to compute the CRC for |
size | The size of the data |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
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 | ||
) | [inline, static] |
Optimized CRC-8 calculation using a table.
buf | The data to compute the CRC for |
size | The size of the data |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
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.
data | The data to compute the CRC for |
length | The size of the data |
init_val | The initial value of the 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.
crc_type | The CRC type |
data | The data to calculate the checksum on |
length | The length of the data |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
uint8_t esp_compute_crc_dynamic | ( | const uint8_t *const | ip, |
const uint8_t *const | ip2, | ||
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:
ip | The outer IP packet |
ip2 | The inner IP packet if there is 2 IP headers, NULL otherwise |
next_header | The next header located after the IP header(s) |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
uint8_t esp_compute_crc_static | ( | const uint8_t *const | ip, |
const uint8_t *const | ip2, | ||
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
ip | The outer IP packet |
ip2 | The inner IP packet if there is 2 IP headers, NULL otherwise |
next_header | The next header located after the IP header(s) |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
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.
ip | The IPv6 packet |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
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.
ip | The IPv6 packet |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
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.
ip | The IPv6 packet |
type | The type of the 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.
crc_type | The CRC type |
polynom | IN/OUT: the polynom for the requested CRC type |
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.
table | IN/OUT: The 256-byte table to initialize |
crc_type | The type of CRC to initialize the table for |
uint8_t rtp_compute_crc_dynamic | ( | const uint8_t *const | ip, |
const uint8_t *const | ip2, | ||
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:
ip | The outer IP packet |
ip2 | The inner IP packet if there is 2 IP headers, NULL otherwise |
next_header | The next header located after the IP header(s) |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
uint8_t rtp_compute_crc_static | ( | const uint8_t *const | ip, |
const uint8_t *const | ip2, | ||
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
ip | The outer IP packet |
ip2 | The inner IP packet if there is 2 IP headers, NULL otherwise |
next_header | The next header located after the IP header(s) |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
uint8_t tcp_compute_crc_dynamic | ( | const uint8_t *const | ip, |
const uint8_t *const | ip2, | ||
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 TCP header.
Concerned fields are:
ip | The outer IP packet |
ip2 | The inner IP packet if there is 2 IP headers, NULL otherwise |
next_header | The next header located after the IP header(s) |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
uint8_t tcp_compute_crc_static | ( | const uint8_t *const | ip, |
const uint8_t *const | ip2, | ||
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 TCP header.
Concerned fields are: all fields expect those for CRC-DYNAMIC
ip | The outer IP packet |
ip2 | The inner IP packet if there is 2 IP headers, NULL otherwise |
next_header | The next header located after the IP header(s) |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
uint8_t udp_compute_crc_dynamic | ( | const uint8_t *const | ip, |
const uint8_t *const | ip2, | ||
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:
ip | The outer IP packet |
ip2 | The inner IP packet if there is 2 IP headers, NULL otherwise |
next_header | The next header located after the IP header(s) |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
uint8_t udp_compute_crc_static | ( | const uint8_t *const | ip, |
const uint8_t *const | ip2, | ||
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
ip | The outer IP packet |
ip2 | The inner IP packet if there is 2 IP headers, NULL otherwise |
next_header | The next header located after the IP header(s) |
crc_type | The type of CRC |
init_val | The initial CRC value |
crc_table | The pre-computed table for fast CRC computation |
unsigned char crc_table_2[256] |
The table to enable fast CRC-2 computation
unsigned char crc_table_3[256] |
The table to enable fast CRC-3 computation
unsigned char crc_table_6[256] |
The table to enable fast CRC-6 computation
unsigned char crc_table_7[256] |
The table to enable fast CRC-7 computation
unsigned char crc_table_8[256] |
The table to enable fast CRC-8 computation
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