File: ntp_refclock.h

package info (click to toggle)
ntpsec 1.2.3%2Bdfsg1-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,960 kB
  • sloc: ansic: 62,004; python: 32,017; sh: 1,553; yacc: 1,293; makefile: 190; javascript: 138
file content (292 lines) | stat: -rw-r--r-- 8,192 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
 * ntp_refclock.h - definitions for reference clock support
 */

#ifndef GUARD_NTP_REFCLOCK_H
#define GUARD_NTP_REFCLOCK_H

#if defined(HAVE_SYS_MODEM_H)
#include <sys/modem.h>
#endif

#include "ntp_types.h"
#include "ntp_tty.h"
#include "recvbuff.h"

/*
 * Configuration flag values
 */
#define	CLK_HAVETIME1	0x1
#define	CLK_HAVETIME2	0x2
#define	CLK_HAVEVAL1	0x4
#define	CLK_HAVEVAL2	0x8

#define	CLK_FLAG1	0x1
#define	CLK_FLAG2	0x2
#define	CLK_FLAG3	0x4
#define	CLK_FLAG4	0x8
#define CLK_HOLDOVER	0x10	/* no corresponding HAVE_ flag */

#define	CLK_HAVEFLAG1	0x10
#define	CLK_HAVEFLAG2	0x20
#define	CLK_HAVEFLAG3	0x40
#define	CLK_HAVEFLAG4	0x80

/*
 * Structure for returning clock status
 */
struct refclockstat {
	uint8_t	flags;		/* clock flags */
	uint8_t	haveflags;	/* bit array of valid flags */
	unsigned short	lencode;	/* length of last timecode */
	const char *p_lastcode;	/* last timecode received */
	uint32_t	polls;		/* transmit polls */
	uint32_t	noresponse;	/* no response to poll */
	uint32_t	badformat;	/* bad format timecode received */
	uint32_t	baddata;	/* invalid data timecode received */
	uint32_t	timereset;	/* driver resets */
	const char *clockname;	/* refclockname */
	const char *clockdesc;	/* ASCII description */
	double	fudgetime1;	/* configure fudge time1 */
	double	fudgetime2;	/* configure fudge time2 */
	int32_t	fudgeval1;	/* configure fudge value1 */
	uint32_t	fudgeval2;	/* configure fudge value2 */
	uint8_t	currentstatus;	/* clock status */
	uint8_t	lastevent;	/* last exception event */
	uint8_t	leap;		/* leap bits */
	struct	ctl_var *kv_list; /* additional variables */
};

/*
 * Reference clock I/O structure.  Used to provide an interface between
 * the reference clock drivers and the I/O module.
 */
struct refclockio {
	struct	refclockio *next; /* link to next structure */
	void	(*clock_recv) (struct recvbuf *); /* completion routine */
	int 	(*io_input)   (struct recvbuf *); /* input routine -
				to avoid excessive buffer use
				due to small bursts
				of refclock input data */
	struct peer *srcclock;	/* refclock peer */
	size_t	datalen;	/* length of data */
	int	fd;		/* file descriptor */
	unsigned long	recvcount;	/* count of receive completions */
	bool	active;		/* true when in use */
};

/*
 * Structure for returning debugging info
 */
#define	NCLKBUGVALUES	16
#define	NCLKBUGTIMES	32

struct refclockbug {
	uint8_t		nvalues;	/* values following */
	uint8_t		ntimes;		/* times following */
	unsigned short	svalues;	/* values format sign array */
	uint32_t	stimes;		/* times format sign array */
	uint32_t	values[NCLKBUGVALUES]; /* real values */
	l_fp		times[NCLKBUGTIMES]; /* real times */
};

/*
 * Structure interface between the reference clock support
 * ntp_refclock.c and the driver utility routines
 */
#define MAXSTAGE	60	/* max median filter stages  */
#define NSTAGE		5	/* default median filter stages */
#define BMAX		128	/* max timecode length */
#define MAXDIAL		60	/* max length of modem dial strings */

struct refclockproc {
	void *	unitptr;	/* pointer to unit structure */
	struct refclock * conf;	/* pointer to driver method table */
	struct refclockio io;	/* I/O handler structure */
	uint8_t	refclkunit;	/* reference clock unit number */
	uint8_t	leap;		/* leap/synchronization code */
	uint8_t	currentstatus;	/* clock status */
	uint8_t	lastevent;	/* last exception event */
	const char *clockname;	/* clock name (tag for logging) */
	const char *clockdesc;	/* clock description */
	unsigned long	nextaction;	/* local activity timeout */
	void	(*action)(struct peer *); /* timeout callback */

	char	a_lastcode[BMAX]; /* last timecode received */
	int	lencode;	/* length of last timecode */

	int	year;		/* year of eternity */
	int	yday;		/* day of year */
	int	hour;		/* hour of day */
	int	minute;		/* minute of hour */
	int	second;		/* second of minute */
	long	nsec;		/* nanosecond of second */
	uint32_t	yearstart;	/* beginning of year */
	int	coderecv;	/* put pointer */
	int	codeproc;	/* get pointer */
	l_fp	lastref;	/* reference timestamp */
	l_fp	lastrec;	/* receive timestamp */
	double	offset;		/* mean offset */
	double	disp;		/* sample dispersion */
	double	jitter;		/* jitter (mean squares) */
	double	filter[MAXSTAGE]; /* median filter */

	/*
	 * Configuration data
	 */
	double	fudgetime1;	/* fudge time1 */
	double	fudgetime2;	/* fudge time2 */
	uint8_t	stratum;	/* server stratum */
	refid_t	refid;		/* reference identifier */
	uint8_t	sloppyclockflag; /* driver options */

	/*
	 * Status tallies
 	 */
	uptime_t		timestarted;	/* time we started this */
	unsigned long	polls;		/* polls sent */
	unsigned long	noreply;	/* no replies to polls */
	unsigned long	badformat;	/* bad format reply */
	unsigned long	baddata;	/* bad data reply */
};

/*
 * Structure interface between the reference clock support
 * ntp_refclock.c and particular clock drivers. This must agree with the
 * structure defined in the driver.
 */

struct refclock {
	const char *basename;
	bool (*clock_start)	(int, struct peer *);
	void (*clock_shutdown)	(struct refclockproc *);
	void (*clock_poll)	(int, struct peer *);
	void (*clock_control)	(int, const struct refclockstat *,
				 struct refclockstat *, struct peer *);
	void (*clock_init)	(void);
	void (*clock_timer)	(int, struct peer *);
};

/*
 * Function prototypes
 */
extern	bool	io_addclock	(struct refclockio *);
extern	void	io_closeclock	(struct refclockio *);

#ifdef REFCLOCK
extern	bool	refclock_newpeer (uint8_t, int, struct peer *);
extern	void	refclock_unpeer (struct peer *);
extern	void	refclock_receive (struct peer *);
extern	void	init_refclock	(void);
extern	void	refclock_control(sockaddr_u *,
				 const struct refclockstat *,
				 struct refclockstat *);
extern	int	refclock_open	(char *, unsigned int, unsigned int);
extern	void	refclock_timer	(struct peer *);
extern	void	refclock_transmit(struct peer *);
extern 	bool	refclock_process(struct refclockproc *);
extern 	bool	refclock_process_f(struct refclockproc *, double);
extern 	void	refclock_process_offset(struct refclockproc *, l_fp,
					l_fp, double);
extern	void	refclock_report	(struct peer *, int);
extern	char	*refclock_name	(const struct peer *);
extern	int	refclock_gtlin	(struct recvbuf *, char *, int, l_fp *);
extern	size_t	refclock_gtraw	(struct recvbuf *, char *, size_t, l_fp *);
extern	bool	indicate_refclock_packet(struct refclockio *,
					 struct recvbuf *);

extern struct refclock refclock_none;

#ifdef CLOCK_ARBITER
extern  struct refclock refclock_arbiter;
#else
#define refclock_arbiter refclock_none
#endif

#ifdef CLOCK_GENERIC
extern	struct refclock	refclock_parse;
#else
#define	refclock_parse	refclock_none
#endif

#if defined(CLOCK_GPSDJSON)
extern struct refclock refclock_gpsdjson;
#else
#define refclock_gpsdjson refclock_none
#endif

#ifdef CLOCK_HPGPS
extern	struct refclock	refclock_hpgps;
#else
#define	refclock_hpgps	refclock_none
#endif

#ifdef CLOCK_JJY
extern	struct refclock	refclock_jjy;
#else
#define	refclock_jjy refclock_none
#endif

#ifdef CLOCK_LOCAL
extern	struct refclock	refclock_local;
#else
#define	refclock_local	refclock_none
#endif

#ifdef CLOCK_MODEM
extern	struct refclock	refclock_modem;
#else
#define refclock_modem	refclock_none
#endif

#ifdef CLOCK_NMEA
extern	struct refclock refclock_nmea;
#else
#define	refclock_nmea	refclock_none
#endif

#if defined(CLOCK_ONCORE)
extern	struct refclock refclock_oncore;
#else
#define refclock_oncore refclock_none
#endif

#if defined (CLOCK_PPS) && defined(HAVE_PPSAPI)
extern	struct refclock	refclock_pps;
#else
#define refclock_pps	refclock_none
#endif

#ifdef CLOCK_SPECTRACOM
extern	struct refclock	refclock_spectracom;
#else
#define	refclock_spectracom	refclock_none
#endif

#ifdef CLOCK_TRUETIME
extern	struct refclock	refclock_true;
#else
#define	refclock_true	refclock_none
#endif

#ifdef CLOCK_SHM
extern	struct refclock refclock_shm;
#else
#define refclock_shm refclock_none
#endif

#ifdef CLOCK_TRIMBLE
extern	struct refclock refclock_trimble;
#else
#define refclock_trimble refclock_none
#endif

#ifdef CLOCK_ZYFER
extern	struct refclock	refclock_zyfer;
#else
#define	refclock_zyfer refclock_none
#endif

#endif /* REFCLOCK */

#endif /* GUARD_NTP_REFCLOCK_H */