-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfec.c
568 lines (517 loc) · 16.5 KB
/
fec.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
/*
* 2D XOR based FEC
* v20160820_1940
* HanishKVC, 2016
*
* This is a new reimplementation of my very old 2d xor based fec logic.
* It uses SIMD and other special instructions supported by x86 to help
* speed up the fec logic.
*
* I have avoided looking at my old logic/implementation, to allow new
* ideas/logic to emerge if and where possible naturally. Have to check
* with my old logic later to see, how similar or dissimilar is some of
* the implementation details, in this new take on my old concept.
*
* Dedicated to my elders.
*/
#include <stdio.h>
#include <stdint.h>
#include <emmintrin.h>
#include <x86intrin.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#ifndef FEC_TARGETHAS_RDSEED
#include <sys/time.h>
#endif
#define FEC_BLOCKSIZE 4096
#define FEC_DATAMATRIX1D 8
#define FEC_FULLMATRIX ((FEC_DATAMATRIX1D+1)*(FEC_DATAMATRIX1D+1))
#define FEC_BUFFERSIZE (FEC_FULLMATRIX*FEC_BLOCKSIZE)
#define FEC_MAXMATRIX1D 32
// this structure tells if a given block in the fec buffer is valid or not
// the bits with in each blocks[index] correspond to the columns with in that row.
// So for now this allows a 32x32 fec matrix (including both data and fec)
// NOTE: row and column are numbered starting from 0
struct fecMatrixFlag {
uint32_t blocks[FEC_MAXMATRIX1D];
uint32_t rowview[FEC_MAXMATRIX1D];
uint32_t colview[FEC_MAXMATRIX1D];
uint32_t row, col;
};
struct fecMatrixFlag gMatFlag;
void fecmatflag_blockset(struct fecMatrixFlag *flag, int rowy, int colx)
{
flag->blocks[rowy] |= (1 << colx);
flag->rowview[rowy] |= (1 << colx);
flag->colview[colx] |= (1 << rowy);
}
void fecmatflag_blockclear(struct fecMatrixFlag *flag, int rowy, int colx)
{
flag->blocks[rowy] &= ~(1 << colx);
flag->rowview[rowy] &= ~(1 << colx);
flag->colview[colx] &= ~(1 << rowy);
}
int fecmatflag_blockget(struct fecMatrixFlag *flag, int rowy, int colx)
{
return (flag->blocks[rowy] & (1 << colx));
}
void fecmatflag_rowset(struct fecMatrixFlag *flag, int rowy)
{
flag->row |= (1 << rowy);
}
void fecmatflag_colset(struct fecMatrixFlag *flag, int colx)
{
flag->col |= (1 << colx);
}
void fecmatflag_print(struct fecMatrixFlag *flag, int dmatrix)
{
printf("FEC:INFO:matflag:row[0x%08X], col[0x%08X]\n", flag->row, flag->col);
for (int i = 0; i <= dmatrix; i++) {
printf("FEC:INFO:blocks[row:%02d]=0x%08X\n", i, flag->blocks[i]);
printf("FEC:INFO: rowview[%02d]=0x%08X\n", i, flag->rowview[i]);
printf("FEC:INFO: colview[%02d]=0x%08X\n", i, flag->colview[i]);
}
}
int fec_validmeta(int blocksize, int dmatrix)
{
if ((blocksize % 16) != 0) {
return -1;
}
return 0;
}
void m128i_print(__m128i vVal)
{
char *sVal;
sVal = (char*)&vVal;
for(int i = 0; i < 16; i++) {
printf(" %02X ",sVal[i]);
}
}
void fec_printbuf_start(uint8_t *buf, int blocksize, int dmatrix)
{
__m128i val;
for(int colx = 0; colx <= dmatrix; colx++) {
for(int rowy = 0; rowy <= dmatrix; rowy++) {
for(int i = 0; i < blocksize; i+= 2048) {
val = _mm_loadu_si128((__m128i*)&buf[rowy*(dmatrix+1)*blocksize+colx*blocksize+i]);
printf("FEC:INFO:COLX[%d],ROWY[%d],I[%4d]: ", colx, rowy, i);
m128i_print(val);
printf("\n");
}
}
}
}
// Row major 2D matrix
// Note2Self: X = Col, Y = Row
void fec_genfec(uint8_t *buf, int blocksize, int dmatrix)
{
__m128i res, val;
int iCurRowOffset;
// Handle fec for each row of data blocks
for(int rowy = 0; rowy < dmatrix; rowy++) {
iCurRowOffset = rowy*(dmatrix+1)*blocksize;
for(int i = 0; i < blocksize; i+= 16) {
res = _mm_setzero_si128();
for(int colx = 0; colx < dmatrix; colx++) {
val = _mm_loadu_si128((__m128i*)&buf[iCurRowOffset+colx*blocksize+i]);
res = _mm_xor_si128(res, val);
}
_mm_storeu_si128((__m128i*)&buf[iCurRowOffset+dmatrix*blocksize+i], res);
}
}
// handle fec for each column of data blocks
for(int colx = 0; colx < dmatrix; colx++) {
for(int i = 0; i < blocksize; i+= 16) {
res = _mm_setzero_si128();
for(int rowy = 0; rowy < dmatrix; rowy++) {
val = _mm_loadu_si128((__m128i*)&buf[rowy*(dmatrix+1)*blocksize+colx*blocksize+i]);
res = _mm_xor_si128(res, val);
}
_mm_storeu_si128((__m128i*)&buf[dmatrix*(dmatrix+1)*blocksize+colx*blocksize+i], res);
}
}
}
void fec_weakcrosscheck_amongflags(struct fecMatrixFlag *matFlag, int dmatrix)
{
uint32_t uBitPos;
uint32_t curRowSet, curColSet;
uint32_t curRowSetCnt, curColSetCnt;
int iErrorOrDebug = 0;
for(int i = 0; i <= dmatrix; i++) {
uBitPos = (1 << i);
// Check along row
curRowSet = matFlag->row & uBitPos;
curRowSetCnt = _mm_popcnt_u32(matFlag->rowview[i]);
if (curRowSet) {
if (curRowSetCnt == 0) {
iErrorOrDebug = 1;
printf("FEC:ERROR:weakcrosscheck: checkfec says row[%d] has error, but rowview[%d] doesnt have any bit set\n", i, i);
}
}
if (curRowSetCnt != 0) {
if (curRowSet == 0) {
iErrorOrDebug = 1;
printf("FEC:DEBUG:weakcrosscheck: rowview[%d] has bits set, but checkfec didnt find error: Either cyclical complementing errors present, which cant be detected at global level OR bug in checkfec?\n", i);
}
}
// Check along col
curColSet = matFlag->col & uBitPos;
curColSetCnt = _mm_popcnt_u32(matFlag->colview[i]);
if (curColSet) {
if (curColSetCnt == 0) {
iErrorOrDebug = 1;
printf("FEC:ERROR:weakcrosscheck: checkfec says col[%d] has error, but colview[%d] doesnt have any bit set\n", i, i);
}
}
if (curColSetCnt != 0) {
if (curColSet == 0) {
iErrorOrDebug = 1;
printf("FEC:DEBUG:weakcrosscheck: colview[%d] has bits set, but checkfec didnt find error: Either cyclical complementing errors present, which cant be detected at global level OR bug in checkfec?\n", i);
}
}
}
if (iErrorOrDebug == 0) {
printf("FEC:GOOD:weakcrosscheck: Didn't find any issues, but remember this is a weak check, some complementing errors can slip through\n");
} else {
printf("FEC:GOOD:weakcrosscheck: If there is a FEC:DEBUG: msg above corresponding to fec row/col, in most cases it can be ignored as checkfec ignores fec row/col because fec row/col doesn't have a fec block of its own, for its own recovery from within\n");
printf("FEC:GOOD:weakcrosscheck: Found issues, but remember this is a weak check, some complementing errors can confuse the logic\n");
}
}
void fec_checkfec(uint8_t *buf, int blocksize, int dmatrix, struct fecMatrixFlag *matFlag)
{
__m128i res, val;
int iCurRowOffset;
__v4si v4i32;
uint32_t iRes, *p32Res;
// Check fec for each row of data blocks
for(int rowy = 0; rowy < dmatrix; rowy++) {
iCurRowOffset = rowy*(dmatrix+1)*blocksize;
for(int i = 0; i < blocksize; i+= 16) {
res = _mm_setzero_si128();
for(int colx = 0; colx <= dmatrix; colx++) {
val = _mm_loadu_si128((__m128i*)&buf[iCurRowOffset+colx*blocksize+i]);
res = _mm_xor_si128(res, val);
}
#ifdef FORCE_ERROR
res = _mm_set_epi32(0x00,0x55,0xaa,0xff);
#endif
v4i32 = (__v4si)res;
iRes = v4i32[0] + v4i32[1] + v4i32[2] + v4i32[3];
if (iRes != 0) {
printf("FEC:WARN:ROWY=%d Not Valid\n", rowy);
fecmatflag_rowset(matFlag, rowy);
}
}
}
// Check fec for each column of data blocks
for(int colx = 0; colx < dmatrix; colx++) {
for(int i = 0; i < blocksize; i+= 16) {
res = _mm_setzero_si128();
for(int rowy = 0; rowy <= dmatrix; rowy++) {
val = _mm_loadu_si128((__m128i*)&buf[rowy*(dmatrix+1)*blocksize+colx*blocksize+i]);
res = _mm_xor_si128(res, val);
}
//iRes = res.m128i_i32[0] + res.m128i_i32[1];
p32Res = (uint32_t*)&res;
iRes = p32Res[0] + p32Res[1] + p32Res[2] + p32Res[3];
if (iRes != 0) {
printf("FEC:WARN:COLX=%d Not Valid\n", colx);
fecmatflag_colset(matFlag, colx);
}
}
}
// Cross check between error block flags set by user program and Global error identification above
fec_weakcrosscheck_amongflags(matFlag, dmatrix);
}
#define FEC_RECOVER_ALONGROW 0
#define FEC_RECOVER_ALONGCOL 1
void fec_recoverblock(uint8_t *buf, int blocksize, int dmatrix, struct fecMatrixFlag *matFlag, int errBlockRowY, int errBlockColX, int along)
{
__m128i res, val;
int iCurRowOffset;
if (along == FEC_RECOVER_ALONGROW) {
iCurRowOffset = errBlockRowY*(dmatrix+1)*blocksize;
for(int i = 0; i < blocksize; i+= 16) {
res = _mm_setzero_si128();
for(int colx = 0; colx <= dmatrix; colx++) {
if (colx == errBlockColX) {
continue;
}
val = _mm_loadu_si128((__m128i*)&buf[iCurRowOffset+colx*blocksize+i]);
res = _mm_xor_si128(res, val);
}
_mm_storeu_si128((__m128i*)&buf[iCurRowOffset+errBlockColX*blocksize+i], res);
}
} else { // FEC_RECOVER_ALONGCOL
for(int i = 0; i < blocksize; i+= 16) {
res = _mm_setzero_si128();
for(int rowy = 0; rowy <= dmatrix; rowy++) {
if (rowy == errBlockRowY) {
continue;
}
val = _mm_loadu_si128((__m128i*)&buf[rowy*(dmatrix+1)*blocksize+errBlockColX*blocksize+i]);
res = _mm_xor_si128(res, val);
}
_mm_storeu_si128((__m128i*)&buf[errBlockRowY*(dmatrix+1)*blocksize+errBlockColX*blocksize+i], res);
}
}
fecmatflag_blockclear(matFlag, errBlockRowY, errBlockColX);
}
void fec_recover(uint8_t *buf, int blocksize, int dmatrix, struct fecMatrixFlag *matFlag)
{
int iNumErrBlocks, iErrCol, iErrRow;
int iContinue, iDone;
int iTryCnt;
iTryCnt = 0;
iDone = 1;
iContinue = 1;
while(iContinue) {
printf("FEC:INFO:Recover: Take [%d] at recovery...\n", iTryCnt);
iDone = 1;
iContinue = 0;
// Check along the rows
for (int i = 0; i < dmatrix; i++) {
iNumErrBlocks = _mm_popcnt_u32(matFlag->rowview[i]);
if (iNumErrBlocks == 0) {
printf("FEC:INFO:GOOD:NO ERRBLOCKS: row[%d]\n", i);
}
if (iNumErrBlocks == 1) {
iContinue = 1;
printf("FEC:INFO: OK:ONE ERRBLOCKS: row[%d]\n", i);
iErrCol = __bsfd(matFlag->rowview[i]);
printf("FEC:INFO: recovering err block at rowy[%d], colx[%d]\n", i, iErrCol);
fec_recoverblock(buf, blocksize, dmatrix, matFlag, i, iErrCol, FEC_RECOVER_ALONGROW);
}
if (iNumErrBlocks > 1) {
printf("FEC:INFO: BAD:MANY ERRBLOCKS: row[%d]\n", i);
iDone = 0;
}
}
// Check along the columns
for (int i = 0; i < dmatrix; i++) {
iNumErrBlocks = _mm_popcnt_u32(matFlag->colview[i]);
if (iNumErrBlocks == 0) {
printf("FEC:INFO:GOOD:NO ERRBLOCKS: col[%d]\n", i);
}
if (iNumErrBlocks == 1) {
iContinue = 1;
printf("FEC:INFO: OK:ONE ERRBLOCKS: col[%d]\n", i);
iErrRow = __bsfd(matFlag->colview[i]);
printf("FEC:INFO: recovering err block at rowy[%d], colx[%d]\n", iErrRow, i);
fec_recoverblock(buf, blocksize, dmatrix, matFlag, iErrRow, i, FEC_RECOVER_ALONGCOL);
}
if (iNumErrBlocks > 1) {
printf("FEC:INFO: BAD:MANY ERRBLOCKS: col[%d]\n", i);
iDone = 0;
}
}
printf("FEC:INFO:Recover: iDone[%d], iContinue[%d]\n", iDone, iContinue);
iTryCnt += 1;
}
}
#define FEC_BUFFILE_DATAONLY 0
#define FEC_BUFFILE_DATAFEC 1
int fec_loadbuf(uint8_t *buf, int hFile, int blocksize, int dmatrix, int mode)
{
int iRead;
int iCurRowOffset;
int iBufSizeDataOnlyRow = dmatrix*blocksize;
int iBufSizeDataFecRow = (dmatrix+1)*blocksize;
int iBufSizeForRow = 0;
int iRowCount = 0;
if (mode == FEC_BUFFILE_DATAONLY) {
iBufSizeForRow = iBufSizeDataOnlyRow;
iRowCount = dmatrix;
} else {
iBufSizeForRow = iBufSizeDataFecRow;
iRowCount = dmatrix+1;
}
for(int rowy = 0; rowy < iRowCount; rowy++) {
iCurRowOffset = rowy*(dmatrix+1)*blocksize;
iRead = read(hFile, &buf[iCurRowOffset], iBufSizeForRow);
if (iRead != iBufSizeForRow)
return -1;
}
return 0;
}
int fec_storebuf(uint8_t *buf, int hFile, int blocksize, int dmatrix, int mode)
{
int iWrote;
int iCurRowOffset;
int iBufSizeDataOnlyRow = dmatrix*blocksize;
int iBufSizeDataFecRow = (dmatrix+1)*blocksize;
int iBufSizeForRow = 0;
int iRowCount = 0;
if (mode == FEC_BUFFILE_DATAONLY) {
iBufSizeForRow = iBufSizeDataOnlyRow;
iRowCount = dmatrix;
} else {
iBufSizeForRow = iBufSizeDataFecRow;
iRowCount = dmatrix+1;
}
for(int rowy = 0; rowy < iRowCount; rowy++) {
iCurRowOffset = rowy*(dmatrix+1)*blocksize;
iWrote = write(hFile, &buf[iCurRowOffset], iBufSizeForRow);
if (iWrote != iBufSizeForRow)
return -1;
}
return 0;
}
int fec_getrandom16(uint16_t *rand)
{
int res = 0;
#ifdef FEC_TARGETHAS_RDSEED
res = _rdseed16_step(rand);
#else
static int inited = 0;
struct timeval tv;
if (inited == 0) {
gettimeofday(&tv, NULL);
srandom(tv.tv_sec);
inited = 1;
}
res = 1;
*rand = random();
#endif
return res;
}
void fec_injecterror(uint8_t *buf, int blocksize, int dmatrix, struct fecMatrixFlag *matFlag)
{
uint16_t iRand;
int colx, rowy;
for(int i = 0; i < 3; i++) {
printf("FEC:INFO: injecting error [%d]:",i);
if (fec_getrandom16(&iRand)) {
colx = iRand % (dmatrix+1);
} else {
printf("RDSeed Failed\n");
}
if (fec_getrandom16(&iRand)) {
rowy = iRand % (dmatrix+1);
} else {
printf("RDSeed Failed\n");
}
if (fec_getrandom16(&iRand)) {
buf[rowy*(dmatrix+1)*blocksize+colx*blocksize+i] = iRand;
} else {
printf("RDSeed Failed\n");
}
fecmatflag_blockset(matFlag, rowy, colx);
printf(" injected error at rowy[%d], colx[%d], i[%d] = 0x%X\n", rowy, colx, i, iRand);
}
}
#define FEC_PRGMODE_GENFEC 0
#define FEC_PRGMODE_USEFEC 1
#define FEC_PRGMODE_ALLFEC 2
int test_genfec(int hFSrc, int hFDst)
{
uint8_t buf[FEC_BUFFERSIZE];
int iMatrix;
memset(buf, 0, FEC_BUFFERSIZE);
iMatrix = 0;
while(1) {
printf("FEC:INFO: processing data matrix [%d]\n", iMatrix);
if (fec_loadbuf(buf, hFSrc, FEC_BLOCKSIZE, FEC_DATAMATRIX1D, FEC_BUFFILE_DATAONLY) != 0) {
printf("FEC:INFO: failed loading of data matrix [%d], maybe EOF, quiting...\n", iMatrix);
return -1;
} else {
printf("FEC:INFO: loaded data matrix [%d]\n", iMatrix);
}
fec_printbuf_start(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D);
fec_genfec(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D);
fec_printbuf_start(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D);
if (fec_storebuf(buf, hFDst, FEC_BLOCKSIZE, FEC_DATAMATRIX1D, FEC_BUFFILE_DATAFEC) != 0) {
printf("FEC:INFO: failed storing of data+fec matrix [%d], maybe EOF, quiting...\n", iMatrix);
return -1;
} else {
printf("FEC:INFO: stored data+fec matrix [%d]\n", iMatrix);
}
iMatrix += 1;
}
return 0;
}
int test_usefec(int hFSrc, int hFDst)
{
uint8_t buf[FEC_BUFFERSIZE];
int iMatrix;
memset(buf, 0, FEC_BUFFERSIZE);
iMatrix = 0;
while(1) {
printf("FEC:INFO: processing data+fec matrix [%d]\n", iMatrix);
if (fec_loadbuf(buf, hFSrc, FEC_BLOCKSIZE, FEC_DATAMATRIX1D, FEC_BUFFILE_DATAFEC) != 0) {
printf("FEC:INFO: failed loading of data+fec matrix [%d], maybe EOF, quiting...\n", iMatrix);
return -1;
} else {
printf("FEC:INFO: loaded data+fec matrix [%d]\n", iMatrix);
}
fec_printbuf_start(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D);
fec_injecterror(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D, &gMatFlag);
fec_checkfec(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D, &gMatFlag);
fecmatflag_print(&gMatFlag, FEC_DATAMATRIX1D);
fec_recover(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D, &gMatFlag);
if (fec_storebuf(buf, hFDst, FEC_BLOCKSIZE, FEC_DATAMATRIX1D, FEC_BUFFILE_DATAONLY) != 0) {
printf("FEC:INFO: failed storing of data matrix [%d], maybe EOF, quiting...\n", iMatrix);
return -1;
} else {
printf("FEC:INFO: stored data matrix [%d]\n", iMatrix);
}
iMatrix += 1;
}
return 0;
}
int test_all(int hFSrc, int hFDst)
{
uint8_t buf[FEC_BUFFERSIZE];
int iMatrix;
memset(buf, 0, FEC_BUFFERSIZE);
iMatrix = 0;
while(1) {
printf("FEC:INFO: processing data matrix [%d]\n", iMatrix);
if (fec_loadbuf(buf, hFSrc, FEC_BLOCKSIZE, FEC_DATAMATRIX1D, FEC_BUFFILE_DATAONLY) != 0) {
printf("FEC:INFO: failed loading of data matrix [%d], maybe EOF, quiting...\n", iMatrix);
break;
} else {
printf("FEC:INFO: loaded data matrix [%d]\n", iMatrix);
}
fec_printbuf_start(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D);
fec_genfec(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D);
fec_printbuf_start(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D);
write(hFDst, buf, FEC_BUFFERSIZE);
fec_injecterror(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D, &gMatFlag);
fec_checkfec(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D, &gMatFlag);
fecmatflag_print(&gMatFlag, FEC_DATAMATRIX1D);
fec_recover(buf, FEC_BLOCKSIZE, FEC_DATAMATRIX1D, &gMatFlag);
iMatrix += 1;
}
return 0;
}
int main(int argc, char **argv)
{
int hFSrc, hFDst;
int iMode;
if (strncmp(argv[1], "gen",3) == 0) {
iMode = FEC_PRGMODE_GENFEC;
} else {
if (strncmp(argv[1], "use",3) == 0) {
iMode = FEC_PRGMODE_USEFEC;
} else {
iMode = FEC_PRGMODE_ALLFEC;
}
}
hFSrc = open(argv[2], O_RDONLY);
hFDst = open(argv[3], O_CREAT | O_WRONLY, S_IRUSR);
switch(iMode) {
case FEC_PRGMODE_GENFEC:
test_genfec(hFSrc, hFDst);
break;
case FEC_PRGMODE_USEFEC:
test_usefec(hFSrc, hFDst);
break;
default:
test_all(hFSrc, hFDst);
}
return 0;
}