TSCH: before associating on an EB, check that the Rx timestamp is sensible
@@ -749,16 +749,26 @@ PT_THREAD(tsch_scan(struct pt *pt))
}
if(is_packet_pending) {
+ rtimer_clock_t t1;
/* Read packet */
input_eb.len = NETSTACK_RADIO.read(input_eb.payload, TSCH_PACKET_MAX_LEN);
/* Save packet timestamp */
NETSTACK_RADIO.get_object(RADIO_PARAM_LAST_PACKET_TIMESTAMP, &t0, sizeof(rtimer_clock_t));
+ t1 = RTIMER_NOW();
/* Parse EB and attempt to associate */
LOG_INFO("scan: received packet (%u bytes) on channel %u\n", input_eb.len, current_channel);
+ /* Sanity-check the timestamp */
+ if(ABS(RTIMER_CLOCK_DIFF(t0, t1)) < tsch_timing[tsch_ts_timeslot_length]) {
tsch_associate(&input_eb, t0);
+ } else {
+ LOG_WARN("scan: dropping packet, timestamp too far from current time %u %u\n",
+ (unsigned)t0,
+ (unsigned)t1
+ );
+ }
}
if(tsch_is_associated) {
