summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Heron <phil@sanslogic.co.uk>2018-07-04 10:41:03 +0100
committerPhilip Heron <phil@sanslogic.co.uk>2018-07-04 10:41:03 +0100
commit035f920f5c96880bfd89d4469428b934e830c7c9 (patch)
treeba00449fe85d247971a4e93866888ee3f28f9659
parent3310c6f0c3d19757ba9a25869009cf3795ab6a05 (diff)
Add some packet sanity checks
-rw-r--r--ssdv.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/ssdv.c b/ssdv.c
index f90c869..a9c9622 100644
--- a/ssdv.c
+++ b/ssdv.c
@@ -1313,6 +1313,13 @@ char ssdv_dec_feed(ssdv_t *s, uint8_t *packet)
/* Is this not the packet we expected? */
if(packet_id != s->packet_id)
{
+ if(packet_id < s->packet_id)
+ {
+ /* The decoder can only accept packets in the correct order */
+ fprintf(stderr, "Packets are not in order. %i > %i\n", s->packet_id - 1, packet_id);
+ return(SSDV_FEED_ME);
+ }
+
/* One or more packets have been lost! */
fprintf(stderr, "Gap detected between packets %i and %i\n", s->packet_id - 1, packet_id);
@@ -1343,6 +1350,13 @@ char ssdv_dec_feed(ssdv_t *s, uint8_t *packet)
/* The first MCU in a packet is byte aligned,
* any old bits should be dropped. */
s->workbits = s->worklen = 0;
+
+ /* Abandon the packet if the MCU index is not what it should be. */
+ if(s->mcu_id != s->packet_mcu_id)
+ {
+ fprintf(stderr, "Unexpected MCU ID in packet %d.\n", packet_id);
+ return(SSDV_FEED_ME);
+ }
}
b = packet[SSDV_PKT_SIZE_HEADER + i];