From 9ac3cddf749366f81540aac549ac7583602b7170 Mon Sep 17 00:00:00 2001 From: Josh Allen Date: Fri, 10 Feb 2017 06:54:58 -0500 Subject: crc check decoded data --- tools/ootx_decode/HMD_Datagen.c | 4 +++- tools/ootx_decode/Makefile | 6 +++--- tools/ootx_decode/crc32.h | 13 +++++++++++++ tools/ootx_decode/ootx_decoder.c | 10 +++++++++- tools/ootx_decode/ootx_decoder.h | 1 + 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 tools/ootx_decode/crc32.h (limited to 'tools') diff --git a/tools/ootx_decode/HMD_Datagen.c b/tools/ootx_decode/HMD_Datagen.c index d71d291..f2e8b19 100644 --- a/tools/ootx_decode/HMD_Datagen.c +++ b/tools/ootx_decode/HMD_Datagen.c @@ -10,6 +10,8 @@ #include #include +#include "crc32.h" + uint32_t time_stamp = -525198892; char* fmt_str = "L Y HMD %d 5 1 206230 %d\n"; @@ -19,7 +21,7 @@ void print_preamble(); void print_uint16(uint16_t d); void print_uint32(uint32_t d); void print_payload(char* data, uint16_t length); -uint32_t crc32(uint32_t crc, uint8_t *buf, size_t size); + int main(int argc, char* argv[]) { diff --git a/tools/ootx_decode/Makefile b/tools/ootx_decode/Makefile index f72cbb5..2c0d01a 100644 --- a/tools/ootx_decode/Makefile +++ b/tools/ootx_decode/Makefile @@ -1,7 +1,7 @@ all: ootx_decode hmd_datagen -hmd_datagen: HMD_Datagen.c crc32.c +hmd_datagen: HMD_Datagen.c crc32.c crc32.h gcc -Wall HMD_Datagen.c crc32.c -o hmd_datagen -ootx_decode: ootx_decode.c ootx_decoder.c ootx_decoder.h - gcc -Wall ootx_decode.c ootx_decoder.c -o ootx_decode \ No newline at end of file +ootx_decode: ootx_decode.c ootx_decoder.c ootx_decoder.h crc32.c crc32.h + gcc -Wall ootx_decode.c ootx_decoder.c crc32.c -o ootx_decode \ No newline at end of file diff --git a/tools/ootx_decode/crc32.h b/tools/ootx_decode/crc32.h new file mode 100644 index 0000000..c771d4a --- /dev/null +++ b/tools/ootx_decode/crc32.h @@ -0,0 +1,13 @@ +// (C) 2016 Joshua Allen, MIT/x11 License. +// +//All MIT/x11 Licensed Code in this file may be relicensed freely under the GPL or LGPL licenses. + +#ifndef CRC32_H +#define CRC32_H + +#include +#include + +uint32_t crc32(uint32_t crc, uint8_t *buf, size_t size); + +#endif \ No newline at end of file diff --git a/tools/ootx_decode/ootx_decoder.c b/tools/ootx_decode/ootx_decoder.c index 70a88b5..2bd818f 100644 --- a/tools/ootx_decode/ootx_decoder.c +++ b/tools/ootx_decode/ootx_decoder.c @@ -9,6 +9,7 @@ #include #include "ootx_decoder.h" +#include "crc32.h" //char* fmt_str = "L Y HMD %d 5 1 206230 %d\n"; @@ -103,7 +104,14 @@ void ootx_process_bit(uint32_t length) { op.length = *(uint16_t*)buffer; op.data = buffer+2; op.crc32 = *(uint32_t*)(buffer+2+op.length); - if (ootx_packet_clbk) ootx_packet_clbk(&op); + + uint32_t crc = crc32(0xffffffff,op.data,op.length); + + if (crc != op.crc32) { + printf("CRC mismatch\n"); + } + + if ((crc == op.crc32) && ootx_packet_clbk) ootx_packet_clbk(&op); ootx_reset_buffer(); } diff --git a/tools/ootx_decode/ootx_decoder.h b/tools/ootx_decode/ootx_decoder.h index b714b53..3a14f74 100644 --- a/tools/ootx_decode/ootx_decoder.h +++ b/tools/ootx_decode/ootx_decoder.h @@ -5,6 +5,7 @@ #ifndef OOTX_DECODER_H #define OOTX_DECODER_H +#include #include typedef struct { -- cgit v1.2.3