1 /* $NetBSD: ntp_refclock.h,v 1.3 2006/05/11 00:11:25 mrg Exp $ */
4 * ntp_refclock.h - definitions for reference clock support
10 #include "ntp_types.h"
12 #if defined(HAVE_BSD_TTYS)
14 #endif /* HAVE_BSD_TTYS */
16 #if defined(HAVE_SYSV_TTYS)
18 #endif /* HAVE_SYSV_TTYS */
20 #if defined(HAVE_TERMIOS)
21 # ifdef TERMIOS_NEEDS__SVID3
25 # ifdef TERMIOS_NEEDS__SVID3
30 #if defined(HAVE_SYS_MODEM_H)
31 #include <sys/modem.h>
34 #if 0 /* If you need that, include ntp_io.h instead */
37 #if defined(CLK) /* This is never defined, except perhaps by a system header file */
38 #include <sys/clkdefs.h>
45 #if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS)
47 #endif /* SYSV_TTYS STREAM BSD_TTYS */
49 #define SAMPLE(x) pp->coderecv = (pp->coderecv + 1) % MAXSTAGE; \
50 pp->filter[pp->coderecv] = (x); \
51 if (pp->coderecv == pp->codeproc) \
52 pp->codeproc = (pp->codeproc + 1) % MAXSTAGE;
55 * Macros to determine the clock type and unit numbers from a
58 #define REFCLOCKTYPE(srcadr) ((SRCADR(srcadr) >> 8) & 0xff)
59 #define REFCLOCKUNIT(srcadr) (SRCADR(srcadr) & 0xff)
62 * List of reference clock names and descriptions. These must agree with
63 * lib/clocktypes.c and ntpd/refclock_conf.c.
66 int code
; /* driver "major" number */
67 const char *clocktype
; /* long description */
68 const char *abbrev
; /* short description */
70 extern struct clktype clktypes
[];
73 extern struct clktype clktypes
[];
76 * Configuration flag values
78 #define CLK_HAVETIME1 0x1
79 #define CLK_HAVETIME2 0x2
80 #define CLK_HAVEVAL1 0x4
81 #define CLK_HAVEVAL2 0x8
88 #define CLK_HAVEFLAG1 0x10
89 #define CLK_HAVEFLAG2 0x20
90 #define CLK_HAVEFLAG3 0x40
91 #define CLK_HAVEFLAG4 0x80
94 * Constant for disabling event reporting in
95 * refclock_receive. ORed in leap
98 #define REFCLOCK_OWN_STATES 0x80
101 * Structure for returning clock status
103 struct refclockstat
{
104 u_char type
; /* clock type */
105 u_char flags
; /* clock flags */
106 u_char haveflags
; /* bit array of valid flags */
107 u_short lencode
; /* length of last timecode */
108 const char *p_lastcode
; /* last timecode received */
109 u_int32 polls
; /* transmit polls */
110 u_int32 noresponse
; /* no response to poll */
111 u_int32 badformat
; /* bad format timecode received */
112 u_int32 baddata
; /* invalid data timecode received */
113 u_int32 timereset
; /* driver resets */
114 const char *clockdesc
; /* ASCII description */
115 double fudgetime1
; /* configure fudge time1 */
116 double fudgetime2
; /* configure fudge time2 */
117 int32 fudgeval1
; /* configure fudge value1 */
118 int32 fudgeval2
; /* configure fudge value2 */
119 u_char currentstatus
; /* clock status */
120 u_char lastevent
; /* last exception event */
121 u_char leap
; /* leap bits */
122 struct ctl_var
*kv_list
; /* additional variables */
126 * Reference clock I/O structure. Used to provide an interface between
127 * the reference clock drivers and the I/O module.
130 struct refclockio
*next
; /* link to next structure */
131 void (*clock_recv
) P((struct recvbuf
*)); /* completion routine */
132 int (*io_input
) P((struct recvbuf
*)); /* input routine -
133 to avoid excessive buffer use
135 of refclock input data */
136 caddr_t srcclock
; /* pointer to clock structure */
137 int datalen
; /* lenth of data */
138 SOCKET fd
; /* file descriptor */
139 u_long recvcount
; /* count of receive completions */
143 * Structure for returning debugging info
145 #define NCLKBUGVALUES 16
146 #define NCLKBUGTIMES 32
149 u_char nvalues
; /* values following */
150 u_char ntimes
; /* times following */
151 u_short svalues
; /* values format sign array */
152 u_int32 stimes
; /* times format sign array */
153 u_int32 values
[NCLKBUGVALUES
]; /* real values */
154 l_fp times
[NCLKBUGTIMES
]; /* real times */
158 * Structure interface between the reference clock support
159 * ntp_refclock.c and the driver utility routines
161 #define MAXSTAGE 60 /* max median filter stages */
162 #define NSTAGE 5 /* default median filter stages */
163 #define BMAX 128 /* max timecode length */
164 #define GMT 0 /* I hope nobody sees this */
165 #define MAXDIAL 60 /* max length of modem dial strings */
168 * Line discipline flags. These require line discipline or streams
169 * modules to be installed/loaded in the kernel. If specified, but not
170 * installed, the code runs as if unspecified.
172 #define LDISC_STD 0x00 /* standard */
173 #define LDISC_CLK 0x01 /* tty_clk \n intercept */
174 #define LDISC_CLKPPS 0x02 /* tty_clk \377 intercept */
175 #define LDISC_ACTS 0x04 /* tty_clk #* intercept */
176 #define LDISC_CHU 0x08 /* depredated */
177 #define LDISC_PPS 0x10 /* ppsclock, ppsapi */
178 #define LDISC_RAW 0x20 /* raw binary */
179 #define LDISC_ECHO 0x40 /* enable echo */
180 #define LDISC_REMOTE 0x80 /* remote mode */
181 #define LDISC_7O1 0x100 /* 7-bit, odd parity for Z3801A */
183 struct refclockproc
{
184 struct refclockio io
; /* I/O handler structure */
185 caddr_t unitptr
; /* pointer to unit structure */
186 u_char leap
; /* leap/synchronization code */
187 u_char currentstatus
; /* clock status */
188 u_char lastevent
; /* last exception event */
189 u_char type
; /* clock type */
190 const char *clockdesc
; /* clock description */
192 char a_lastcode
[BMAX
]; /* last timecode received */
193 u_short lencode
; /* length of last timecode */
195 int year
; /* year of eternity */
196 int day
; /* day of year */
197 int hour
; /* hour of day */
198 int minute
; /* minute of hour */
199 int second
; /* second of minute */
200 long nsec
; /* nanosecond of second */
201 u_long yearstart
; /* beginning of year */
202 int coderecv
; /* put pointer */
203 int codeproc
; /* get pointer */
204 l_fp lastref
; /* reference timestamp */
205 l_fp lastrec
; /* receive timestamp */
206 double offset
; /* mean offset */
207 double disp
; /* sample dispersion */
208 double jitter
; /* jitter (mean squares) */
209 double filter
[MAXSTAGE
]; /* median filter */
214 double fudgetime1
; /* fudge time1 */
215 double fudgetime2
; /* fudge time2 */
216 u_char stratum
; /* server stratum */
217 u_int32 refid
; /* reference identifier */
218 u_char sloppyclockflag
; /* fudge flags */
223 u_long timestarted
; /* time we started this */
224 u_long polls
; /* polls sent */
225 u_long noreply
; /* no replies to polls */
226 u_long badformat
; /* bad format reply */
227 u_long baddata
; /* bad data reply */
231 * Structure interface between the reference clock support
232 * ntp_refclock.c and particular clock drivers. This must agree with the
233 * structure defined in the driver.
235 #define noentry 0 /* flag for null routine */
236 #define NOFLAGS 0 /* flag for null flags */
239 int (*clock_start
) P((int, struct peer
*));
240 void (*clock_shutdown
) P((int, struct peer
*));
241 void (*clock_poll
) P((int, struct peer
*));
242 void (*clock_control
) P((int, struct refclockstat
*,
243 struct refclockstat
*, struct peer
*));
244 void (*clock_init
) P((void));
245 void (*clock_buginfo
) P((int, struct refclockbug
*, struct peer
*));
246 void (*clock_timer
) P((int, struct peer
*));
250 * Function prototypes
253 * auxiliary PPS interface (implemented by refclock_atom())
255 extern int pps_sample
P((l_fp
*));
256 extern int io_addclock_simple
P((struct refclockio
*));
257 extern int io_addclock
P((struct refclockio
*));
258 extern void io_closeclock
P((struct refclockio
*));
261 extern void refclock_buginfo
P((struct sockaddr_storage
*,
262 struct refclockbug
*));
263 extern void refclock_control
P((struct sockaddr_storage
*,
264 struct refclockstat
*,
265 struct refclockstat
*));
266 extern int refclock_open
P((char *, u_int
, u_int
));
267 extern int refclock_setup
P((int, u_int
, u_int
));
268 extern void refclock_timer
P((struct peer
*));
269 extern void refclock_transmit
P((struct peer
*));
270 extern int refclock_ioctl
P((int, u_int
));
271 extern int refclock_process
P((struct refclockproc
*));
272 extern void refclock_process_offset
P((struct refclockproc
*, l_fp
, l_fp
, double));
273 extern void refclock_report
P((struct peer
*, int));
274 extern int refclock_gtlin
P((struct recvbuf
*, char *, int, l_fp
*));
275 extern int refclock_gtraw
P((struct recvbuf
*, char *, int, l_fp
*));
276 #endif /* REFCLOCK */
278 #endif /* NTP_REFCLOCK_H */