aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJosh Allen <axlecrusher@gmail.com>2017-02-10 06:54:58 -0500
committerJosh Allen <axlecrusher@gmail.com>2017-02-10 06:54:58 -0500
commit9ac3cddf749366f81540aac549ac7583602b7170 (patch)
tree606fa3d8c650bbbb23133cbe91a238bbc28b62ae /tools
parent917a7f7754e47567bf9102b6c26b6649ae6b28dd (diff)
downloadlibsurvive-9ac3cddf749366f81540aac549ac7583602b7170.tar.gz
libsurvive-9ac3cddf749366f81540aac549ac7583602b7170.tar.bz2
crc check decoded data
Diffstat (limited to 'tools')
-rw-r--r--tools/ootx_decode/HMD_Datagen.c4
-rw-r--r--tools/ootx_decode/Makefile6
-rw-r--r--tools/ootx_decode/crc32.h13
-rw-r--r--tools/ootx_decode/ootx_decoder.c10
-rw-r--r--tools/ootx_decode/ootx_decoder.h1
5 files changed, 29 insertions, 5 deletions
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 <time.h>
#include <stdlib.h>
+#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 <stddef.h>
+#include <stdint.h>
+
+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 <assert.h>
#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 <stddef.h>
#include <stdint.h>
typedef struct {