diff --git a/arch/platform/cc2538dk/contiki-conf.h b/arch/platform/cc2538dk/contiki-conf.h index 307b015fe..a3ef81196 100644 --- a/arch/platform/cc2538dk/contiki-conf.h +++ b/arch/platform/cc2538dk/contiki-conf.h @@ -47,7 +47,14 @@ typedef uint32_t rtimer_clock_t; #define RADIO_DELAY_BEFORE_DETECT 0 #ifndef TSCH_CONF_BASE_DRIFT_PPM /* The drift compared to "true" 10ms slots. - * Enable adaptive sync to enable compensation for this. */ + * Enable adaptive sync to enable compensation for this. + * Slot length 10000 usec + * 328 ticks + * Tick duration 30.517578125 usec + * Real slot duration 10009.765625 usec + * Target - real duration = -9.765625 usec + * TSCH_CONF_BASE_DRIFT_PPM -977 + */ #define TSCH_CONF_BASE_DRIFT_PPM -977 #endif /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/jn516x/platform-conf.h b/arch/platform/jn516x/platform-conf.h index 703826ce7..3caadae2f 100644 --- a/arch/platform/jn516x/platform-conf.h +++ b/arch/platform/jn516x/platform-conf.h @@ -110,9 +110,15 @@ typedef uint32_t rtimer_clock_t; /* If the timer base a binary 32kHz clock, compensate for this base drift */ #if RTIMER_USE_32KHZ && JN516X_EXTERNAL_CRYSTAL_OSCILLATOR -/* Drift calculated using this formula: -* ((US_TO_TICKS(10000) * 100) - RTIMER_SECOND) * 1e6 = 976.5625 ppm -*/ +/* The drift compared to "true" 10ms slots. + * Enable adaptive sync to enable compensation for this. + * Slot length 10000 usec + * 328 ticks + * Tick duration 30.517578125 usec + * Real slot duration 10009.765625 usec + * Target - real duration = -9.765625 usec + * TSCH_CONF_BASE_DRIFT_PPM -977 + */ #define TSCH_CONF_BASE_DRIFT_PPM -977 #endif diff --git a/arch/platform/openmote-cc2538/contiki-conf.h b/arch/platform/openmote-cc2538/contiki-conf.h index d28a85ba3..5e7e967da 100644 --- a/arch/platform/openmote-cc2538/contiki-conf.h +++ b/arch/platform/openmote-cc2538/contiki-conf.h @@ -86,7 +86,14 @@ typedef uint32_t rtimer_clock_t; #define RADIO_DELAY_BEFORE_DETECT 0 #ifndef TSCH_CONF_BASE_DRIFT_PPM /* The drift compared to "true" 10ms slots. - * Enable adaptive sync to enable compensation for this. */ + * Enable adaptive sync to enable compensation for this. + * Slot length 10000 usec + * 328 ticks + * Tick duration 30.517578125 usec + * Real slot duration 10009.765625 usec + * Target - real duration = -9.765625 usec + * TSCH_CONF_BASE_DRIFT_PPM -977 + */ #define TSCH_CONF_BASE_DRIFT_PPM -977 #endif /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/srf06-cc26xx/contiki-conf.h b/arch/platform/srf06-cc26xx/contiki-conf.h index bb51131e9..4f464809a 100644 --- a/arch/platform/srf06-cc26xx/contiki-conf.h +++ b/arch/platform/srf06-cc26xx/contiki-conf.h @@ -280,7 +280,14 @@ typedef uint32_t rtimer_clock_t; #ifndef TSCH_CONF_BASE_DRIFT_PPM /* The drift compared to "true" 10ms slots. - * Enable adaptive sync to enable compensation for this. */ + * Enable adaptive sync to enable compensation for this. + * Slot length 10000 usec + * 328 ticks + * Tick duration 30.517578125 usec + * Real slot duration 10009.765625 usec + * Target - real duration = -9.765625 usec + * TSCH_CONF_BASE_DRIFT_PPM -977 + */ #define TSCH_CONF_BASE_DRIFT_PPM -977 #endif diff --git a/arch/platform/zoul/contiki-conf.h b/arch/platform/zoul/contiki-conf.h index 38b34e5ad..a67e37e2c 100644 --- a/arch/platform/zoul/contiki-conf.h +++ b/arch/platform/zoul/contiki-conf.h @@ -84,7 +84,14 @@ typedef uint32_t rtimer_clock_t; #define RADIO_DELAY_BEFORE_DETECT 0 #ifndef TSCH_CONF_BASE_DRIFT_PPM /* The drift compared to "true" 10ms slots. - * Enable adaptive sync to enable compensation for this. */ + * Enable adaptive sync to enable compensation for this. + * Slot length 10000 usec + * 328 ticks + * Tick duration 30.517578125 usec + * Real slot duration 10009.765625 usec + * Target - real duration = -9.765625 usec + * TSCH_CONF_BASE_DRIFT_PPM -977 + */ #define TSCH_CONF_BASE_DRIFT_PPM -977 #endif /*---------------------------------------------------------------------------*/ diff --git a/os/net/mac/tsch/tsch-adaptive-timesync.c b/os/net/mac/tsch/tsch-adaptive-timesync.c index 430db841d..5d9774537 100644 --- a/os/net/mac/tsch/tsch-adaptive-timesync.c +++ b/os/net/mac/tsch/tsch-adaptive-timesync.c @@ -68,7 +68,7 @@ tsch_adaptive_timesync_get_drift_ppm(void) /*---------------------------------------------------------------------------*/ /* Add a value to a moving average estimator */ static int32_t -timesync_entry_add(int32_t val, uint32_t time_delta) +timesync_entry_add(int32_t val) { #define NUM_TIMESYNC_ENTRIES 8 static int32_t buffer[NUM_TIMESYNC_ENTRIES]; @@ -101,9 +101,9 @@ timesync_learn_drift_ticks(uint32_t time_delta_asn, int32_t drift_ticks) /* should fit in a 32-bit integer */ int32_t time_delta_ticks = time_delta_asn * tsch_timing[tsch_ts_timeslot_length]; int32_t real_drift_ticks = drift_ticks + compensated_ticks; - int32_t last_drift_ppm = (int32_t)((int64_t)real_drift_ticks * TSCH_DRIFT_UNIT / time_delta_ticks); + int32_t last_drift_ppm = (int32_t)(((int64_t)real_drift_ticks * TSCH_DRIFT_UNIT) / time_delta_ticks); - drift_ppm = timesync_entry_add(last_drift_ppm, time_delta_ticks); + drift_ppm = timesync_entry_add(last_drift_ppm); TSCH_LOG_ADD(tsch_log_message, snprintf(log->message, sizeof(log->message), diff --git a/os/net/mac/tsch/tsch-security.c b/os/net/mac/tsch/tsch-security.c index d0a5f85e5..b132e5882 100644 --- a/os/net/mac/tsch/tsch-security.c +++ b/os/net/mac/tsch/tsch-security.c @@ -138,6 +138,7 @@ tsch_security_secure_frame(uint8_t *hdr, uint8_t *outbuf, uint8_t with_encryption; uint8_t mic_len; uint8_t nonce[16]; + struct ieee802154_ies ies; uint8_t a_len; uint8_t m_len; @@ -151,6 +152,13 @@ tsch_security_secure_frame(uint8_t *hdr, uint8_t *outbuf, return 0; } + memset(&ies, 0, sizeof(ies)); + if(frame802154e_parse_information_elements(hdr + hdrlen, datalen, &ies) > 0) { + /* put Header IEs into the header part which is not encrypted */ + hdrlen += ies.ie_payload_ie_offset; + datalen -= ies.ie_payload_ie_offset; + } + if(!frame.fcf.security_enabled) { /* Security is not enabled for this frame, we're done */ return 0; @@ -204,6 +212,7 @@ tsch_security_parse_frame(const uint8_t *hdr, int hdrlen, int datalen, uint8_t nonce[16]; uint8_t a_len; uint8_t m_len; + struct ieee802154_ies ies; if(frame == NULL || hdr == NULL || hdrlen < 0 || datalen < 0) { return 0; @@ -229,6 +238,12 @@ tsch_security_parse_frame(const uint8_t *hdr, int hdrlen, int datalen, return 0; } + memset(&ies, 0, sizeof(ies)); + (void)frame802154e_parse_information_elements(hdr + hdrlen, datalen, &ies); + /* put Header IEs into the header part which is not encrypted */ + hdrlen += ies.ie_payload_ie_offset; + datalen -= ies.ie_payload_ie_offset; + tsch_security_init_nonce(nonce, sender, asn); if(with_encryption) { diff --git a/os/net/mac/tsch/tsch-slot-operation.c b/os/net/mac/tsch/tsch-slot-operation.c index d84a1998d..715b9463d 100644 --- a/os/net/mac/tsch/tsch-slot-operation.c +++ b/os/net/mac/tsch/tsch-slot-operation.c @@ -763,6 +763,12 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) packet_duration = TSCH_PACKET_DURATION(current_input->len); + if(!frame_valid) { + TSCH_LOG_ADD(tsch_log_message, + snprintf(log->message, sizeof(log->message), + "!failed to parse frame %u %u", header_len, current_input->len)); + } + if(frame_valid) { if(frame.fcf.frame_type != FRAME802154_DATAFRAME && frame.fcf.frame_type != FRAME802154_BEACONFRAME) { @@ -786,11 +792,6 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) "!failed to authenticate frame %u", current_input->len)); frame_valid = 0; } - } else { - TSCH_LOG_ADD(tsch_log_message, - snprintf(log->message, sizeof(log->message), - "!failed to parse frame %u %u", header_len, current_input->len)); - frame_valid = 0; } #endif /* LLSEC802154_ENABLED */