2 * ntp_refclock.h - definitions for reference clock support
10 #if defined(HAVE_BSD_TTYS)
12 #endif /* HAVE_BSD_TTYS */
14 #if defined(HAVE_SYSV_TTYS)
16 #endif /* HAVE_SYSV_TTYS */
18 #if defined(HAVE_TERMIOS)
19 # ifdef TERMIOS_NEEDS__SVID3
23 # ifdef TERMIOS_NEEDS__SVID3
28 #if defined(HAVE_SYS_MODEM_H)
29 #include <sys/modem.h>
32 #if 0 /* If you need that, include ntp_io.h instead */
35 #if defined(CLK) /* This is never defined, except perhaps by a system header file */
36 #include <sys/clkdefs.h>
43 #if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS)
45 #endif /* SYSV_TTYS STREAM BSD_TTYS */
47 #define SAMPLE(x) pp->filter[pp->coderecv++ % MAXSTAGE] = (x); \
48 if (pp->coderecv % MAXSTAGE == pp->codeproc % MAXSTAGE) \
52 * Macros to determine the clock type and unit numbers from a
55 #define REFCLOCKTYPE(srcadr) ((SRCADR(srcadr) >> 8) & 0xff)
56 #define REFCLOCKUNIT(srcadr) (SRCADR(srcadr) & 0xff)
59 * List of reference clock names and descriptions. These must agree with
60 * lib/clocktypes.c and ntpd/refclock_conf.c.
63 int code; /* driver "major" number */
64 const char *clocktype; /* long description */
65 const char *abbrev; /* short description */
69 * Configuration flag values
71 #define CLK_HAVETIME1 0x1
72 #define CLK_HAVETIME2 0x2
73 #define CLK_HAVEVAL1 0x4
74 #define CLK_HAVEVAL2 0x8
81 #define CLK_HAVEFLAG1 0x10
82 #define CLK_HAVEFLAG2 0x20
83 #define CLK_HAVEFLAG3 0x40
84 #define CLK_HAVEFLAG4 0x80
87 * Constant for disabling event reporting in
88 * refclock_receive. ORed in leap
91 #define REFCLOCK_OWN_STATES 0x80
94 * Structure for returning clock status
97 u_char type; /* clock type */
98 u_char flags; /* clock flags */
99 u_char haveflags; /* bit array of valid flags */
100 u_short lencode; /* length of last timecode */
101 const char *p_lastcode; /* last timecode received */
102 u_int32 polls; /* transmit polls */
103 u_int32 noresponse; /* no response to poll */
104 u_int32 badformat; /* bad format timecode received */
105 u_int32 baddata; /* invalid data timecode received */
106 u_int32 timereset; /* driver resets */
107 const char *clockdesc; /* ASCII description */
108 double fudgetime1; /* configure fudge time1 */
109 double fudgetime2; /* configure fudge time2 */
110 int32 fudgeval1; /* configure fudge value1 */
111 int32 fudgeval2; /* configure fudge value2 */
112 u_char currentstatus; /* clock status */
113 u_char lastevent; /* last exception event */
114 u_char leap; /* leap bits */
115 struct ctl_var *kv_list; /* additional variables */
119 * Reference clock I/O structure. Used to provide an interface between
120 * the reference clock drivers and the I/O module.
123 struct refclockio *next; /* link to next structure */
124 void (*clock_recv) P((struct recvbuf *)); /* completion routine */
125 int (*io_input) P((struct recvbuf *)); /* input routine -
126 to avoid excessive buffer use
128 of refclock input data */
129 caddr_t srcclock; /* pointer to clock structure */
130 int datalen; /* lenth of data */
131 int fd; /* file descriptor */
132 u_long recvcount; /* count of receive completions */
136 * Structure for returning debugging info
138 #define NCLKBUGVALUES 16
139 #define NCLKBUGTIMES 32
142 u_char nvalues; /* values following */
143 u_char ntimes; /* times following */
144 u_short svalues; /* values format sign array */
145 u_int32 stimes; /* times format sign array */
146 u_int32 values[NCLKBUGVALUES]; /* real values */
147 l_fp times[NCLKBUGTIMES]; /* real times */
151 * Structure interface between the reference clock support
152 * ntp_refclock.c and the driver utility routines
154 #define MAXSTAGE 60 /* max median filter stages */
155 #define NSTAGE 5 /* default median filter stages */
156 #define BMAX 128 /* max timecode length */
157 #define GMT 0 /* I hope nobody sees this */
158 #define MAXDIAL 60 /* max length of modem dial strings */
161 * Line discipline flags. These require line discipline or streams
162 * modules to be installed/loaded in the kernel. If specified, but not
163 * installed, the code runs as if unspecified.
165 #define LDISC_STD 0x0 /* standard */
166 #define LDISC_CLK 0x1 /* tty_clk \n intercept */
167 #define LDISC_CLKPPS 0x2 /* tty_clk \377 intercept */
168 #define LDISC_ACTS 0x4 /* tty_clk #* intercept */
169 #define LDISC_CHU 0x8 /* depredated */
170 #define LDISC_PPS 0x10 /* ppsclock, ppsapi */
171 #define LDISC_RAW 0x20 /* raw binary */
173 struct refclockproc {
174 struct refclockio io; /* I/O handler structure */
175 caddr_t unitptr; /* pointer to unit structure */
176 u_char leap; /* leap/synchronization code */
177 u_char currentstatus; /* clock status */
178 u_char lastevent; /* last exception event */
179 u_char type; /* clock type */
180 const char *clockdesc; /* clock description */
182 char a_lastcode[BMAX]; /* last timecode received */
183 u_short lencode; /* length of last timecode */
185 int year; /* year of eternity */
186 int day; /* day of year */
187 int hour; /* hour of day */
188 int minute; /* minute of hour */
189 int second; /* second of minute */
190 int msec; /* millisecond of second */
191 long usec; /* microsecond of second (alt) */
192 u_long yearstart; /* beginning of year */
193 int coderecv; /* put pointer */
194 int codeproc; /* get pointer */
195 l_fp lastref; /* timecode timestamp */
196 l_fp lastrec; /* local timestamp */
197 double offset; /* mean offset */
198 double disp; /* sample dispersion */
199 double jitter; /* jitter (mean squares) */
200 double filter[MAXSTAGE]; /* median filter */
205 double fudgetime1; /* fudge time1 */
206 double fudgetime2; /* fudge time2 */
207 u_int32 refid; /* reference identifier */
208 u_char sloppyclockflag; /* fudge flags */
213 u_long timestarted; /* time we started this */
214 u_long polls; /* polls sent */
215 u_long noreply; /* no replies to polls */
216 u_long badformat; /* bad format reply */
217 u_long baddata; /* bad data reply */
221 * Structure interface between the reference clock support
222 * ntp_refclock.c and particular clock drivers. This must agree with the
223 * structure defined in the driver.
225 #define noentry 0 /* flag for null routine */
226 #define NOFLAGS 0 /* flag for null flags */
229 int (*clock_start) P((int, struct peer *));
230 void (*clock_shutdown) P((int, struct peer *));
231 void (*clock_poll) P((int, struct peer *));
232 void (*clock_control) P((int, struct refclockstat *,
233 struct refclockstat *, struct peer *));
234 void (*clock_init) P((void));
235 void (*clock_buginfo) P((int, struct refclockbug *, struct peer *));
240 * Function prototypes
243 * auxiliary PPS interface (implemented by refclock_atom())
245 extern int pps_sample P((l_fp *));
246 extern int io_addclock_simple P((struct refclockio *));
247 extern int io_addclock P((struct refclockio *));
248 extern void io_closeclock P((struct refclockio *));
251 extern void refclock_buginfo P((struct sockaddr_in *,
252 struct refclockbug *));
253 extern void refclock_control P((struct sockaddr_in *,
254 struct refclockstat *,
255 struct refclockstat *));
256 extern int refclock_open P((char *, int, int));
257 extern void refclock_transmit P((struct peer *));
258 extern int refclock_ioctl P((int, int));
259 extern int refclock_process P((struct refclockproc *));
260 extern void refclock_process_offset P((struct refclockproc *, l_fp, l_fp, double));
261 extern void refclock_report P((struct peer *, int));
262 extern int refclock_gtlin P((struct recvbuf *, char *, int,
264 #endif /* REFCLOCK */
266 #endif /* NTP_REFCLOCK_H */