2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 #define RANDOM_MAX 0x7fffffff
32 return (double) random() / (double) RANDOM_MAX;
36 gaussian_random(double mean, double dev)
38 static int save_x_valid = 0;
50 double normal_x1, normal_x2;
53 normal_x1 = 2 * rand_real () - 1;
54 normal_x2 = 2 * rand_real () - 1;
55 w = normal_x1*normal_x1 + normal_x2*normal_x2;
56 } while (w >= 1 || w < 1E-30);
58 w = sqrt(log(w)*(-2./w));
61 * normal_x1 and normal_x2 are independent normally
62 * distributed variates
66 /* save normal_x2 for next call */
67 save_x = normal_x2 * w;
70 return x * dev + mean;
73 #define PREPARE_LEN(input_len) ((input_len) + AO_FEC_PREPARE_EXTRA)
74 #define ENCODE_LEN(input_len) (PREPARE_LEN(input_len) * 2)
75 #define DECODE_LEN(input_len) ((input_len) + AO_FEC_PREPARE_EXTRA)
76 #define EXPAND_LEN(input_len) (ENCODE_LEN(input_len) * 8)
78 static uint8_t ao_bit(uint8_t b) {
85 ao_expand(uint8_t *bits, int bits_len, uint8_t *bytes)
90 for (i = 0; i < bits_len; i++) {
92 for (bit = 7; bit >= 0; bit--)
93 *bytes++ = ao_bit ((b >> bit) & 1);
100 ao_fuzz (uint8_t *in, int in_len, uint8_t *out, double dev)
106 for (i = 0; i < in_len; i++) {
107 double error = gaussian_random(0, dev);
108 uint8_t byte = in[i];
132 #define SAVE_MASK (((1 << SAVE) - 1) << (8 - SAVE))
135 for (s = SAVE; s < 8; s += SAVE)
144 ao_random_data(uint8_t *out, uint8_t out_len)
146 uint8_t len = random() % (out_len + 1);
149 for (i = 0; i < len; i++)
155 static uint8_t real_packet[] = {
156 0x40, 0x38, 0xcd, 0x38, 0x3d, 0x34, 0xca, 0x31, 0xc3, 0xc1, 0xc6, 0x35, 0xcc, 0x3a, 0x3c,
157 0x3c, 0x3d, 0x3c, 0x37, 0xc5, 0xc1, 0xc0, 0xc1, 0xc1, 0xc3, 0xc0, 0xc1, 0xc6, 0x38, 0x3b, 0xc6,
158 0xc0, 0xc6, 0x32, 0xc9, 0xc9, 0x34, 0xcf, 0x35, 0xcf, 0x3a, 0x3b, 0xc6, 0xc7, 0x35, 0xcf, 0x36,
159 0xce, 0x37, 0xc8, 0xc8, 0x3a, 0x3c, 0xc9, 0xc8, 0x3a, 0x3c, 0xcc, 0x32, 0xcd, 0x32, 0xce, 0x32,
160 0xc9, 0xc6, 0x37, 0x3e, 0x3d, 0xc8, 0xc3, 0xc6, 0x38, 0x3d, 0xcf, 0x34, 0x3d, 0x3b, 0xcb, 0x31,
161 0xca, 0x35, 0x38, 0xcb, 0x31, 0xcc, 0x31, 0x3b, 0xc7, 0xbf, 0xbe, 0xbe, 0xc3, 0x35, 0x38, 0xcb,
162 0x2f, 0xc9, 0xc2, 0x34, 0x3c, 0xcc, 0x31, 0xca, 0xc1, 0xc0, 0xc3, 0x33, 0x3f, 0x3f, 0x3e, 0x3c,
163 0xcc, 0x31, 0xcc, 0xc3, 0xc4, 0x32, 0xd1, 0x34, 0x3f, 0x3c, 0xcc, 0x31, 0xcc, 0xc3, 0x33, 0xd0,
164 0x31, 0xd1, 0x35, 0x3f, 0x3e, 0x3c, 0xca, 0xc5, 0x34, 0xcc, 0xc2, 0xc3, 0xc3, 0xc5, 0x36, 0x40,
165 0x3e, 0x41, 0x3e, 0x41, 0x3e, 0x3f, 0x41, 0x40, 0xce, 0xc5, 0x33, 0xcf, 0xc7, 0x36, 0xd2, 0x32,
166 0xd1, 0xc5, 0xc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c2, 0xc3, 0xc5, 0x33, 0xd0, 0xc5, 0xc4, 0x35, 0x40, 0x40, 0x3e, 0x41, 0x3e, 0xd2, 0x30, 0x3f,
276 0x3e, 0x3d, 0x21, 0xc8, 0x0d, 0x23, 0xec, 0xb1, 0x1a, 0xf0, 0xf3, 0x10, 0xc6, 0xbd, 0x5b, 0x0d,
277 0xff, 0xe2, 0xe6, 0xd4, 0x72, 0xe2, 0xda, 0x0c, 0xf8, 0x1b, 0x04, 0x0b, 0xf7, 0xb4, 0xf0, 0x44,
278 0xcd, 0xaf, 0x12, 0x1f, 0x11, 0xa1, 0x29, 0xb8, 0x1a, 0xdb, 0x09, 0x69, 0xf7, 0x20, 0xc4, 0x1c,
279 0xc0, 0xc8, 0x1d, 0x45, 0xd9, 0x30, 0xd8, 0x2e, 0xd8, 0x2e, 0xd6, 0x2c, 0xd5, 0x2d, 0xd4, 0x2b,
280 0xd5, 0x2b, 0xd1, 0x31, 0xd0, 0x32, 0xd2, 0x30, 0xd0, 0x31, 0xd0, 0x31, 0xce, 0x2f, 0xd3, 0x2e,
281 0xce, 0x2f, 0xd1, 0x31, 0x3c, 0xd1, 0x2d, 0xd0, 0xc0, 0x2e, 0x3c, 0x3d, 0xd1, 0xc3, 0x2c, 0xd2,
282 0xc3, 0xc5, 0x31, 0x40, 0x40, 0xd5, 0x2c, 0x3a, 0x3d, 0xd0, 0x2b, 0xd3, 0xc0, 0xc0, 0x2d, 0xd4,
283 0x2c, 0x3f, 0x3e, 0x3c, 0x3f, 0x3c, 0xd2, 0xc1, 0xc2, 0xc0, 0xc1, 0xc1, 0xc1, 0xc1, 0xc1, 0x2a,
293 ok = ao_fec_decode(real_packet, 576, decode, 34, NULL);
295 if (ok && decode[33] == AO_FEC_DECODE_CRC_OK) {
298 ao_fec_dump_bytes(decode, 34, "Decode");
300 printf ("actual packet crc error\n");
306 #define EXPECT_DECODE_FAIL 0
307 #define EXPECT_CRC_MISMATCH 6386
308 #define EXPECT_DATA_MISMATCH 0
309 #define NOISE_AMOUNT 0x50
312 main(int argc, char **argv)
316 uint8_t original[120];
317 uint8_t original_len;
319 uint8_t encode[ENCODE_LEN(sizeof(original))];
322 uint8_t transmit[EXPAND_LEN(sizeof(original))];
325 uint8_t receive[EXPAND_LEN(sizeof(original))];
328 uint8_t decode[DECODE_LEN(sizeof(original))];
333 int crc_mismatch = 0;
334 int data_mismatch = 0;
336 if (!ao_real_packet())
340 for (trial = 0; trial < 100000; trial++) {
342 /* Compute some random data */
343 original_len = ao_random_data(original, sizeof(original));
346 encode_len = ao_fec_encode(original, original_len, encode);
348 /* Expand from 1-bit-per-symbol to 1-byte-per-symbol */
349 transmit_len = ao_expand(encode, encode_len, transmit);
351 /* Add gaussian noise to the signal */
352 (void) ao_fuzz(transmit, transmit_len, receive, NOISE_AMOUNT);
353 receive_len = transmit_len;
356 decode_ok = ao_fec_decode(receive, receive_len, decode, original_len + 2, NULL);
358 /* Check to see if we received the right data */
362 else if (decode[original_len +1] != AO_FEC_DECODE_CRC_OK)
364 else if (memcmp(original, decode, original_len) != 0)
369 printf ("%d packets coded\n", trial);
370 printf ("decode_fail %d crc_mismatch %d data_mismatch %d\n",
371 decode_fail, crc_mismatch, data_mismatch);
372 if (decode_fail != EXPECT_DECODE_FAIL) {
373 printf ("expected %d decode failures\n", EXPECT_DECODE_FAIL);
376 if (crc_mismatch != EXPECT_CRC_MISMATCH) {
377 printf ("expected %d crc mismatch\n", EXPECT_CRC_MISMATCH);
380 if (data_mismatch != EXPECT_DATA_MISMATCH) {
381 printf ("expected %d data mismatch\n", EXPECT_DATA_MISMATCH);