ROHC compression/decompression library
crc.h
Go to the documentation of this file.
1 /*
2  * Copyright 2007,2008 CNES
3  * Copyright 2011,2012,2013 Didier Barvaux
4  * Copyright 2007,2008 Thales Alenia Space
5  * Copyright 2009,2010 Thales Communications
6  * Copyright 2007,2009,2010,2012,2013 Viveris Technologies
7  * Copyright 2012 WBX
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 /**
25  * @file crc.h
26  * @brief ROHC CRC routines
27  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
28  * @author Didier Barvaux <didier@barvaux.org>
29  * @author FWX <rohc_team@dialine.fr>
30  */
31 
32 #ifndef ROHC_COMMON_CRC_H
33 #define ROHC_COMMON_CRC_H
34 
35 #include "ip.h"
36 
37 #ifdef __KERNEL__
38 # include <linux/types.h>
39 #else
40 # include <stdbool.h>
41 #endif
42 
43 /// The CRC-3 initial value
44 #define CRC_INIT_3 0x7
45 /// The CRC-7 initial value
46 #define CRC_INIT_7 0x7f
47 /// The CRC-8 initial value
48 #define CRC_INIT_8 0xff
49 
50 /** The FCS-32 initial value */
51 #define CRC_INIT_FCS32 0xffffffff
52 /** The length (in bytes) of the FCS-32 CRC */
53 #define CRC_FCS32_LEN 4U
54 
55 /** The different types of CRC used to protect ROHC headers */
56 typedef enum
57 {
58  ROHC_CRC_TYPE_NONE = 0, /**< No CRC selected */
59  ROHC_CRC_TYPE_3 = 3, /**< The CRC-3 type */
60  ROHC_CRC_TYPE_7 = 7, /**< The CRC-7 type */
61  ROHC_CRC_TYPE_8 = 8, /**< The CRC-8 type */
63 
64 
65 /*
66  * Function prototypes.
67  */
68 
69 bool rohc_crc_init_table(uint8_t *const table,
70  const rohc_crc_type_t crc_type)
71  __attribute__((nonnull(1), warn_unused_result));
72 
73 uint8_t crc_calculate(const rohc_crc_type_t crc_type,
74  const uint8_t *const data,
75  const size_t length,
76  const uint8_t init_val,
77  const uint8_t *const crc_table)
78  __attribute__((nonnull(2, 5), warn_unused_result));
79 
80 uint32_t crc_calc_fcs32(const uint8_t *const data,
81  const size_t length,
82  const uint32_t init_val)
83  __attribute__((nonnull(1), warn_unused_result, pure));
84 
85 uint8_t compute_crc_static(const uint8_t *const outer_ip,
86  const uint8_t *const inner_ip,
87  const uint8_t *const next_header,
88  const rohc_crc_type_t crc_type,
89  const uint8_t init_val,
90  const uint8_t *const crc_table)
91  __attribute__((nonnull(1, 6), warn_unused_result));
92 uint8_t compute_crc_dynamic(const uint8_t *const outer_ip,
93  const uint8_t *const inner_ip,
94  const uint8_t *const next_header,
95  const rohc_crc_type_t crc_type,
96  const uint8_t init_val,
97  const uint8_t *const crc_table)
98  __attribute__((nonnull(1, 6), warn_unused_result));
99 
100 uint8_t udp_compute_crc_static(const uint8_t *const outer_ip,
101  const uint8_t *const inner_ip,
102  const uint8_t *const next_header,
103  const rohc_crc_type_t crc_type,
104  const uint8_t init_val,
105  const uint8_t *const crc_table)
106  __attribute__((nonnull(1, 3, 6), warn_unused_result));
107 uint8_t udp_compute_crc_dynamic(const uint8_t *const outer_ip,
108  const uint8_t *const inner_ip,
109  const uint8_t *const next_header,
110  const rohc_crc_type_t crc_type,
111  const uint8_t init_val,
112  const uint8_t *const crc_table)
113  __attribute__((nonnull(1, 3, 6), warn_unused_result));
114 
115 uint8_t esp_compute_crc_static(const uint8_t *const outer_ip,
116  const uint8_t *const inner_ip,
117  const uint8_t *const next_header,
118  const rohc_crc_type_t crc_type,
119  const uint8_t init_val,
120  const uint8_t *const crc_table)
121  __attribute__((nonnull(1, 3, 6), warn_unused_result));
122 uint8_t esp_compute_crc_dynamic(const uint8_t *const outer_ip,
123  const uint8_t *const inner_ip,
124  const uint8_t *const next_header,
125  const rohc_crc_type_t crc_type,
126  const uint8_t init_val,
127  const uint8_t *const crc_table)
128  __attribute__((nonnull(1, 3, 6), warn_unused_result));
129 
130 uint8_t rtp_compute_crc_static(const uint8_t *const outer_ip,
131  const uint8_t *const inner_ip,
132  const uint8_t *const next_header,
133  const rohc_crc_type_t crc_type,
134  const uint8_t init_val,
135  const uint8_t *const crc_table)
136  __attribute__((nonnull(1, 3, 6), warn_unused_result));
137 uint8_t rtp_compute_crc_dynamic(const uint8_t *const outer_ip,
138  const uint8_t *const inner_ip,
139  const uint8_t *const next_header,
140  const rohc_crc_type_t crc_type,
141  const uint8_t init_val,
142  const uint8_t *const crc_table)
143  __attribute__((nonnull(1, 3, 6), warn_unused_result));
144 
145 #endif
146 
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.
Definition: crc.c:597
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.
Definition: crc.c:518
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.
Definition: crc.c:558
IP-agnostic packet.
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.
Definition: crc.c:234
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.
Definition: crc.c:178
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.
Definition: crc.c:309
Definition: crc.h:60
rohc_crc_type_t
Definition: crc.h:56
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.
Definition: crc.c:402
Definition: crc.h:59
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.
Definition: crc.c:681
Definition: crc.h:58
Definition: crc.h:61
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.
Definition: crc.c:479
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.
Definition: crc.c:637
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.
Definition: crc.c:274