diff options
author | Fred Sundvik <fsundvik@gmail.com> | 2016-02-14 21:13:16 +0200 |
---|---|---|
committer | Fred Sundvik <fsundvik@gmail.com> | 2016-02-14 21:13:16 +0200 |
commit | 62058329ff9000589ddba6454ff8ef8a551b7243 (patch) | |
tree | 7dba4d57587f5d13fca4de596c3ec0b65a29ffca /serial_link/protocol | |
parent | a3ec3bbef8d46a897f59dd22c8e59d951e87a961 (diff) |
Add crc32 validation of received frames
Diffstat (limited to 'serial_link/protocol')
-rw-r--r-- | serial_link/protocol/frame_validator.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/serial_link/protocol/frame_validator.c b/serial_link/protocol/frame_validator.c index 1ffd3aad85..d3337f6e32 100644 --- a/serial_link/protocol/frame_validator.c +++ b/serial_link/protocol/frame_validator.c @@ -23,6 +23,7 @@ SOFTWARE. */ #include "protocol/frame_validator.h" +#include "protocol/frame_router.h" const uint32_t poly8_lookup[256] = { @@ -101,5 +102,11 @@ static uint32_t crc32_byte(uint8_t *p, uint32_t bytelength) } void recv_frame(uint8_t* data, uint16_t size) { - + if (size > 4) { + uint32_t frame_crc = *(uint32_t*)(data + size - 4); + uint32_t expected_crc = crc32_byte(data, size - 4); + if (frame_crc == expected_crc) { + route_frame(data, size-4); + } + } } |