Files
m241Neelima/components/ip_net2-6.9/ipsntp/src/ipsntp_h.h
T
2026-07-30 11:19:44 +05:30

297 lines
9.5 KiB
C

/*
******************************************************************************
* INTERPEAK INTERNAL API HEADER FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipsntp_h.h,v $ $Revision: 1.21.12.4 $
* $Source: /home/interpeak/CVSRoot/ipsntp/src/ipsntp_h.h,v $
* $Author: jren $ $Date: 2015-08-03 08:44:18 $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Markus Carlstedt <markus@interpeak.se>
******************************************************************************
*/
#ifndef IPSNTP_H_H
#define IPSNTP_H_H
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
* Internal header file.
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#include <ipcom_sock.h>
#include <ipcom_tmo.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
/* 1970 - 1900 in seconds */
#define IPSNTP_JAN_1970 2208988800UL
/* 2001 - 1900 in seconds */
#define IPSNTP_JAN_2001 3187296000UL
/* NTP fragments to microseconds: 1/sec * x * 10^-6 sec * 2^32 */
#define IPSNTP_MICROFRAC 4295L
/* Start date for system clock */
#define IPSNTP_RTC_START IPSNTP_JAN_1970
/* Seconds per day */
#define IPSNTP_SECONDS_PER_DAY (24*3600)
#define IPSNTP_POSITIVE_LEAP_SECOND 1
#define IPSNTP_NEGATIVE_LEAP_SECOND -1
/* (S)NTP modes. */
#define IPSNTP_RESERVED 0
#define IPSNTP_SYMMETRIC_ACTIVE 1
#define IPSNTP_SYMMETRIC_PASSIVE 2
#define IPSNTP_CLIENT_MODE 3
#define IPSNTP_SERVER_MODE 4
#define IPSNTP_BROADCAST_MODE 5
#define IPSNTP_RESERVED_CONTROL 6
#define IPSNTP_RESERVED_PRIVATE 7
/* Useful macros */
#define IPSNTP_MODE(xxpkt) ((xxpkt)->LVM & 0x07)
#define IPSNTP_VERSION(xxpkt) (((xxpkt)->LVM & 0x38) >> 3)
#define IPSNTP_LEAP(xxpkt) (((xxpkt)->LVM & 0xc0) >> 6)
/* Check version >= 1, no alarm and stratum 1-14 */
#define IPSNTP_CHECK_VERSION_ALARM_STRATUM(xxsntp) \
(IPSNTP_VERSION((xxsntp)->pkt) > 0 && \
IPSNTP_LEAP((xxsntp)->pkt) < 3 && \
(xxsntp)->packet.stratum < 16 && (xxsntp)->packet.stratum > 0)
/* Match response with last request */
#define IPSNTP_MATCH_RESPONSE(xxsntp) \
((xxsntp)->packet.orgTimestamp.sec == (xxsntp)->outputTime.sec && \
(xxsntp)->packet.orgTimestamp.frac == (xxsntp)->outputTime.frac)
/* The maximum number of fallback servers */
#define IPSNTP_NUMSERV 4
/* The delimiter between the address and the interface for scoped addresses
* ex FE80::200:30FF:FE40:5060%eth0
*/
#define IPSNTP_IF_DELIMITER '%'
/* The maximum RTC time difference that can be gracefully adjusted */
#if defined(IP_PORT_OSE) || defined(IP_PORT_OSE5)
#define IPSNTP_MAX_GRACEFUL_ADJUST 2100
#else
#define IPSNTP_MAX_GRACEFUL_ADJUST 0 /* Unsupported if not OSE */
#endif
/* Poll interval for API queries */
#define IPSNTP_QUERY_POLL 2
/* Maximum reasonable roundtrip time before the server time is discarded */
#define IPSNTP_MAX_REASONABLE_ROUND_TIME 5
/*
*===========================================================================
* SYSLOG
*===========================================================================
* Syslog settings
*/
#ifdef IPCOM_SYSLOG_FACILITY
#undef IPCOM_SYSLOG_FACILITY
#endif
#define IPCOM_SYSLOG_FACILITY IPCOM_LOG_IPSNTP
#ifdef IPCOM_SYSLOG_PRIORITY
#undef IPCOM_SYSLOG_PRIORITY
#endif
#if defined(_WRS_CONFIG_IPSNTP_SYSLOG_PRIORITY)
#define IPCOM_SYSLOG_PRIORITY _WRS_CONFIG_IPSNTP_SYSLOG_PRIORITY
#else
#define IPCOM_SYSLOG_PRIORITY IPCOM_LOG_WARNING
#endif
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
/*
*===========================================================================
* Ipsntp_rtc_time
*===========================================================================
*/
typedef struct Ipsntp_rtc_time_struct
{
Ip_time_t seconds; /* Seconds since IPSNTP_RTC_START */
Ip_u32 nanos; /* Additional nanoseconds */
}
Ipsntp_rtc_time;
/*
*===========================================================================
* Ipsntp_ntp_time
*===========================================================================
*/
typedef struct Ipsntp_ntp_time_struct
{
Ip_u32 sec;
Ip_u32 frac;
}
Ipsntp_ntp_time;
/*
*===========================================================================
* Ipsntp_packet
*===========================================================================
*/
typedef struct Ipsntp_packet_struct
{
Ip_u8 LVM;
Ip_u8 stratum;
Ip_u8 poll;
Ip_u8 precision;
Ip_u32 rootDelay;
Ip_u32 rootDispersion;
Ip_u32 refId;
/* Timestamps. */
Ipsntp_ntp_time refTimestamp;
Ipsntp_ntp_time orgTimestamp;
Ipsntp_ntp_time rcvTimestamp;
Ipsntp_ntp_time traTimestamp; /* only used for client. */
/* Optional Authenticator unsupported. 'U32 auth[3],' */
}
Ipsntp_packet;
/* SNTP packet data retrived from SNTP protocol message */
typedef struct Ipsntp_packet_data_struct
{
Ip_u8 leapVerMode;
Ip_u8 stratum;
Ip_u8 poll;
Ip_u8 precision;
} Ipsntp_packet_data;
/*
*===========================================================================
* Ipsntp_data
*===========================================================================
*/
typedef struct Ipsntp_data_struct
{
Ipsntp_packet packet; /* SNTP packet. */
Ipsntp_packet *pkt; /* Alignment trick. */
Ipsntp_rtc_time inputTime; /* Time when packet arrived. */
Ipsntp_ntp_time outputTime; /* Time when packet departed */
Ip_u16 port_n;
Ip_u16 pad;
Ip_bool is_server; /* IP_TRUE if server mode */
#ifdef IPCOM_USE_INET
struct Ip_in_addr cliservip[IPSNTP_NUMSERV]; /* (S)NTP server IP. */
struct Ip_in_addr climultiip; /* Multicast client group */
char climultiifname[IP_IFNAMSIZ]; /* Multicast client interface */
#endif
#ifdef IPCOM_USE_INET6
struct Ip_in6_addr cliservip6[IPSNTP_NUMSERV]; /* (S)NTP server IPv6. */
Ip_u32 cliservip6_ifindex[IPSNTP_NUMSERV]; /* Interface index */
struct Ip_in6_addr climulti6ip; /* Multicast client IPv6 group */
char climulti6ifname[IP_IFNAMSIZ]; /* Multicast client IPv6 interface */
#endif
Ip_u32 clicurip; /* Index ^ of current server used. */
Ip_s32 clitimeout; /* Client timeout (interval). */
Ip_bool syncronized;
Ipcom_tmo adj_tmo;
Ip_bool first; /* Remember boot. */
Ip_s32 climaxretrans; /* Maximum number of cliretrans. */
Ip_s32 cliretrans; /* Current client retrans. */
Ip_s32 clisecretrans; /* Seconds between each retrans. */
#ifdef IPCOM_USE_INET
struct Ip_in_addr servbrdip; /* Server broadcast IP */
Ip_u32 servbrdip_ifindex; /* Interface index */
#endif
#ifdef IPCOM_USE_INET6
struct Ip_in6_addr servbrdip6; /* Server broadcast IPv6 */
Ip_u32 servbrdip6_ifindex; /* Interface index */
#endif
Ip_s32 servtimeout; /* Broadcast/multicast server. */
Ip_s32 stratum; /* Stratum. */
Ip_s32 precision; /* Precision. */
Ip_s32 mcast_ttl; /* TTL. */
Ip_u32 ref_id; /* Reference source */
Ipsntp_rtc_time ref_time; /* Reference time */
int (*servtime)(Ip_u32 *, Ip_u32 *);
Ipcom_tmo tmo;
Ip_time_t tick;
#ifdef IPCOM_USE_INET
Ip_fd fd;
#endif
#ifdef IPCOM_USE_INET6
Ip_fd fd6;
#endif
void *msg_control; /* ancillary data */
Ip_socklen_t msg_controllen; /* ancillary data buffer len */
Ip_u32 leap_second; /* Leap second in NTP time. */
int leap_second_flag; /* Indicator a positive or negative leap second. */
}
Ipsntp_data;
/*
****************************************************************************
* 6 FUNCTIONS
****************************************************************************
*/
IP_GLOBAL int ipsntp_cmd_sntp(int argc, char **argv);
#ifdef IP_PORT_VXWORKS
IP_GLOBAL int ipsntp_clock_gettime(Ipsntp_rtc_time *clock_time);
IP_GLOBAL int ipsntp_clock_settime(Ipsntp_rtc_time *clock_time);
#endif
#ifdef __cplusplus
}
#endif
#endif
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/