3
3
#include "bch.h"
4
4
5
5
#define SHOW_BYTES
6
+ #define MAX_LENGTH 64
7
+
8
+ static uint8_t r2f_mask [] = { 0x07 , 0x76 , 0xa0 };
6
9
7
10
int test (bch_t * bch , char * msg , int * bits , int length ) {
8
11
int corrected = 0 ;
9
- int temp_bits [length ];
12
+ int temp_bits [MAX_LENGTH ];
10
13
uint8_t bytes [8 ];
11
14
12
15
memcpy (temp_bits , bits , length * sizeof (int ));
@@ -43,15 +46,21 @@ int main(int argc, char **argv) {
43
46
44
47
45
48
if (argc != 4 ) {
46
- fprintf (stderr , "Expecting 3 arguments.\n" );
49
+ fprintf (stderr , "Expecting 3 arguments: m, length, and t .\n" );
47
50
return -1 ;
48
51
}
49
52
50
53
sscanf (argv [1 ], "%d" , & m );
51
54
sscanf (argv [2 ], "%d" , & length );
52
55
sscanf (argv [3 ], "%d" , & t );
53
56
54
- int orig_bits [length + 1 ];
57
+ if (length > MAX_LENGTH ) {
58
+ fprintf (stderr , "Max supported length is %d\n" , MAX_LENGTH );
59
+ return -2 ;
60
+ }
61
+
62
+
63
+ int orig_bits [MAX_LENGTH + 1 ];
55
64
56
65
init_bch (& bch , m , length , t );
57
66
data_len = bch .k ;
@@ -63,24 +72,27 @@ printf("data_len=%d, crc_len=%d\n", data_len, crc_len);
63
72
//
64
73
// THIS IS THE LSB-FIRST VERSION
65
74
//
66
- fprintf (stderr , "Enter HCB+ATAD _WITH_ the parity bit intact and XOR already applied.\n" );
75
+ fprintf (stderr , "Enter HCB+ATAD _WITH_ the parity bit intact.\n" );
76
+ fprintf (stderr , "If 't' is 3, that implies an R2F packet and the given packet will be XOR'ed with 0x0776a0.\n" );
67
77
while (1 ) {
68
78
for (int i = 0 ; i < 8 ; i ++ ) {
69
79
int temp ;
70
80
int status = scanf ("%x " , & temp );
71
- bytes [i ] = temp ;
72
81
if (status == EOF ) {
73
82
return 0 ;
74
83
}
75
84
76
85
if (status != 1 ) {
77
86
fprintf (stderr , "Error: %d" , status );
78
87
}
79
- printf ("%0x " , bytes [i ]);
88
+
89
+ bytes [i ] = temp ;
90
+ if (t == 3 && i < sizeof (r2f_mask )) {
91
+ bytes [i ] ^= r2f_mask [i ];
92
+ }
80
93
}
81
- printf ("\n" );
82
94
83
- int temp [length ];
95
+ int temp [MAX_LENGTH ];
84
96
85
97
// HCB + ATAD
86
98
bytes_to_bits (bytes , orig_bits , length + 1 );
@@ -111,7 +123,7 @@ printf("\n");
111
123
test (& bch , "DATA+BCH: " , temp , length );
112
124
113
125
// BCH+DATA
114
- int swap [length ];
126
+ int swap [MAX_LENGTH ];
115
127
bytes_to_bits (bytes , orig_bits , length + 1 );
116
128
rotate_bits (orig_bits + 1 , temp , length );
117
129
// now DATA+BCH
@@ -123,7 +135,7 @@ printf("\n");
123
135
printf ("\n" );
124
136
test (& bch , "BCH+DATA: " , swap , length );
125
137
126
- int rot [length ];
138
+ int rot [MAX_LENGTH ];
127
139
// DATA + HCB
128
140
bytes_to_bits (bytes , orig_bits , length + 1 );
129
141
memcpy (rot + data_len , orig_bits + 1 , crc_len * sizeof (int ));
0 commit comments