QUIC: Update IETF draft URL (draft-08)
[metze/wireshark/wip.git] / epan / reedsolomon.h
1 /* reedsolomon.h
2  *
3  * Global definitions for Reed-Solomon encoder/decoder,
4  * by Phil Karn (karn@ka9q.ampr.org) September 1996
5  * Copyright 1999 Phil Karn, KA9Q
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /* Set one of these to enable encoder/decoder debugging and error checking,
31  * at the expense of speed */
32 /* #undef DEBUG 1*/
33 /* #undef DEBUG 2*/
34 #undef DEBUG
35
36 /* To select the CCSDS standard (255,223) code, define CCSDS. This
37  * implies standard values for MM, KK, B0 and PRIM.
38  */
39 /* #undef CCSDS 1*/
40 #undef CCSDS
41 #ifndef CCSDS
42
43 /* Otherwise, leave CCSDS undefined and set the parameters below:
44  *
45  * Set MM to be the size of each code symbol in bits. The Reed-Solomon
46  * block size will then be NN = 2**M - 1 symbols. Supported values are
47  * defined in rs.c.
48  */
49 #define MM 8 /* Symbol size in bits */
50
51 /*
52  * Set KK to be the number of data symbols in each block, which must be
53  * less than the block size. The code will then be able to correct up
54  * to NN-KK erasures or (NN-KK)/2 errors, or combinations thereof with
55  * each error counting as two erasures.
56  */
57 #define KK 207 /* Number of data symbols per block */
58
59 /* Set B0 to the first root of the generator polynomial, in alpha form, and
60  * set PRIM to the power of alpha used to generate the roots of the
61  * generator polynomial. The generator polynomial will then be
62  * @**PRIM*B0, @**PRIM*(B0+1), @**PRIM*(B0+2)...@**PRIM*(B0+NN-KK)
63  * where "@" represents a lower case alpha.
64  */
65 #define B0 1 /* First root of generator polynomial, alpha form */
66 #define PRIM 1 /* power of alpha used to generate roots of generator poly */
67 #define STANDARD_ORDER
68
69 /* If you want to select your own field generator polynomial, you'll have
70  * to edit that in rs.c.
71  */
72
73 #else /* CCSDS */
74 /* Don't change these, they're CCSDS standard */
75 #define MM 8
76 #define KK 223
77 #define B0 112
78 #define PRIM 11
79 #endif
80
81 #define NN ((1 << MM) - 1)
82
83 #if MM <= 8
84 typedef unsigned char dtype;
85 #else
86 typedef unsigned int dtype;
87 #endif
88
89 /* Reed-Solomon encoding
90  * data[] is the input block, parity symbols are placed in bb[]
91  * bb[] may lie past the end of the data, e.g., for (255,223):
92  *      encode_rs(&data[0],&data[223]);
93  */
94 int encode_rs(dtype data[], dtype bb[]);
95
96 /* Reed-Solomon erasures-and-errors decoding
97  * The received block goes into data[], and a list of zero-origin
98  * erasure positions, if any, goes in eras_pos[] with a count in no_eras.
99  *
100  * The decoder corrects the symbols in place, if possible and returns
101  * the number of corrected symbols. If the codeword is illegal or
102  * uncorrectible, the data array is unchanged and -1 is returned
103  */
104 int eras_dec_rs(dtype data[], int eras_pos[], int no_eras);
105
106 #ifdef __cplusplus
107 }
108 #endif