diff --git a/lstab.c b/lstab.c index 72c02e8e..881b5d34 100644 --- a/lstab.c +++ b/lstab.c @@ -182,10 +182,6 @@ enum lstab_result lstab_utc2tai(struct lstab *lstab, uint64_t utctime, { int epoch = -1, index, next; - if (utctime > lstab->expiration_utc) { - return LSTAB_UNKNOWN; - } - for (index = lstab->length - 1; index > -1; index--) { if (utctime >= lstab->lstab[index].utc) { epoch = index; @@ -203,5 +199,10 @@ enum lstab_result lstab_utc2tai(struct lstab *lstab, uint64_t utctime, if (next < lstab->length && utctime == lstab->lstab[next].utc - 1) { return LSTAB_AMBIGUOUS; } + + if (utctime > lstab->expiration_utc) { + return LSTAB_EXPIRED; + } + return LSTAB_OK; } diff --git a/lstab.h b/lstab.h index d2393b4b..3811aedd 100644 --- a/lstab.h +++ b/lstab.h @@ -41,6 +41,12 @@ enum lstab_result { */ LSTAB_UNKNOWN, + /** + * The given lstab is past its expiry date and the tai_offset return + * value may not be correct. + */ + LSTAB_EXPIRED, + /** * The given UTC value is ambiguous. The corresponding TAI time is either * diff --git a/ts2phc_nmea_pps_source.c b/ts2phc_nmea_pps_source.c index db8b5c62..8ea26bf4 100644 --- a/ts2phc_nmea_pps_source.c +++ b/ts2phc_nmea_pps_source.c @@ -188,7 +188,7 @@ static int ts2phc_nmea_pps_source_getppstime(struct ts2phc_pps_source *src, struct ts2phc_nmea_pps_source *m = container_of(src, struct ts2phc_nmea_pps_source, pps_source); tmv_t delay_t1, delay_t2, duration_since_rmc, local_t1, local_t2, rmc; - int lstab_error = 0, tai_offset = 0; + int lstab_error = -1, tai_offset = 0; enum lstab_result result; struct timespec now; int64_t utc_time; @@ -237,11 +237,12 @@ static int ts2phc_nmea_pps_source_getppstime(struct ts2phc_pps_source *src, break; case LSTAB_UNKNOWN: pr_err("nmea: unable to find utc time in leap second table"); - lstab_error = -1; + break; + case LSTAB_EXPIRED: + pr_err("nmea: utc time is past leap second table expiry date"); break; case LSTAB_AMBIGUOUS: pr_err("nmea: utc time stamp is ambiguous"); - lstab_error = -1; break; } ts->tv_sec += tai_offset;