linuxptp/lstab.h
Richard Cochran 43c51cf144 Introduce a leap second table.
There are several issues surrounding leap seconds that emerge when a clock
takes on the Grand Master role.  One of them is the fact that GPS radios
provide time of day in the UTC time scale and not in TAI, and they do not,
in general, provide any conversion information.  Another issue is the
expectation that the GM provide correct leap second status flags to the
network.  Although both NTP and GPS do, in theory, provide on-line leap
second status, in practice the information is not reliable due to poor
implementations.

In order to provide correct leap second status and TAI - UTC offsets,
this patch introduces a leap second table based on the information
published by the IETF and NIST.  The hard coded default table can be
updated at run time by reading the standard leap seconds file from the
commonly used tzdata package.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-07 14:57:47 -07:00

65 lines
1.6 KiB
C

/**
* @file lstab.h
* @note Copyright (C) 2012 Richard Cochran <richardcochran@gmail.com>
* @note SPDX-License-Identifier: GPL-2.0+
*/
#ifndef HAVE_LEAP_SECONDS_H
#define HAVE_LEAP_SECONDS_H
#include <stdint.h>
/** Opaque type */
struct lstab;
/**
* Creates an instance of a leap second table.
* @param filename File from which to initialize the table. If NULL or empty,
* the hard coded default table will be used.
* @return A pointer to a leap second table on success, NULL otherwise.
*/
struct lstab *lstab_create(const char *filename);
/**
* Destroys a leap second table instance.
* @param lstab A pointer obtained via lstab_create().
*/
void lstab_destroy(struct lstab *lstab);
/**
* Enumerates the possible result code for the lstab_utc2tai() method.
*/
enum lstab_result {
/**
* The given UTC value was found in the table, and the
* corresponding TAI time is utctime + tai_offset.
*/
LSTAB_OK,
/**
* The given UTC value is out of the range of the table, and
* the tai_offset return value is not set.
*/
LSTAB_UNKNOWN,
/**
* The given UTC value is ambiguous. The corresponding TAI time is either
*
* utctime + tai_offset
* or
* utctime + tai_offset + 1.
*/
LSTAB_AMBIGUOUS,
};
/**
* Returns the TAI - UTC offset for a given UTC time value.
* @param lstab A pointer obtained via lstab_create().
* @param utctime The UTC time value of interest.
* @param tai_offset Pointer to a buffer to hold the result.
* @return One of the lstab_result enumeration values.
*/
enum lstab_result lstab_utc2tai(struct lstab *lstab, uint64_t utctime,
int *tai_offset);
#endif