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->coderecv = (pp->coderecv + 1) % MAXSTAGE; \
48 pp->filter[pp->coderecv] = (x); \
49 if (pp->coderecv == pp->codeproc) \
50 pp->codeproc = (pp->codeproc + 1) % MAXSTAGE;
53 * Macros to determine the clock type and unit numbers from a
56 #define REFCLOCKTYPE(srcadr) ((SRCADR(srcadr) >> 8) & 0xff)
57 #define REFCLOCKUNIT(srcadr) (SRCADR(srcadr) & 0xff)
60 * List of reference clock names and descriptions. These must agree with
61 * lib/clocktypes.c and ntpd/refclock_conf.c.
64 int code; /* driver "major" number */
65 const char *clocktype; /* long description */
66 const char *abbrev; /* short description */
70 * Configuration flag values
72 #define CLK_HAVETIME1 0x1
73 #define CLK_HAVETIME2 0x2
74 #define CLK_HAVEVAL1 0x4
75 #define CLK_HAVEVAL2 0x8
82 #define CLK_HAVEFLAG1 0x10
83 #define CLK_HAVEFLAG2 0x20
84 #define CLK_HAVEFLAG3 0x40
85 #define CLK_HAVEFLAG4 0x80
88 * Constant for disabling event reporting in
89 * refclock_receive. ORed in leap
92 #define REFCLOCK_OWN_STATES 0x80
95 * Structure for returning clock status
98 u_char type; /* clock type */
99 u_char flags; /* clock flags */
100 u_char haveflags; /* bit array of valid flags */
101 u_short lencode; /* length of last timecode */
102 const char *p_lastcode; /* last timecode received */
103 u_int32 polls; /* transmit polls */
104 u_int32 noresponse; /* no response to poll */
105 u_int32 badformat; /* bad format timecode received */
106 u_int32 baddata; /* invalid data timecode received */
107 u_int32 timereset; /* driver resets */
108 const char *clockdesc; /* ASCII description */
109 double fudgetime1; /* configure fudge time1 */
110 double fudgetime2; /* configure fudge time2 */
111 int32 fudgeval1; /* configure fudge value1 */
112 int32 fudgeval2; /* configure fudge value2 */
113 u_char currentstatus; /* clock status */
114 u_char lastevent; /* last exception event */
115 u_char leap; /* leap bits */
116 struct ctl_var *kv_list; /* additional variables */
120 * Reference clock I/O structure. Used to provide an interface between
121 * the reference clock drivers and the I/O module.
124 struct refclockio *next; /* link to next structure */
125 void (*clock_recv) P((struct recvbuf *)); /* completion routine */
126 int (*io_input) P((struct recvbuf *)); /* input routine -
127 to avoid excessive buffer use
129 of refclock input data */
130 caddr_t srcclock; /* pointer to clock structure */
131 int datalen; /* lenth of data */
132 SOCKET fd; /* file descriptor */
133 u_long recvcount; /* count of receive completions */
137 * Structure for returning debugging info
139 #define NCLKBUGVALUES 16
140 #define NCLKBUGTIMES 32
143 u_char nvalues; /* values following */
144 u_char ntimes; /* times following */
145 u_short svalues; /* values format sign array */
146 u_int32 stimes; /* times format sign array */
147 u_int32 values[NCLKBUGVALUES]; /* real values */
148 l_fp times[NCLKBUGTIMES]; /* real times */
152 * Structure interface between the reference clock support
153 * ntp_refclock.c and the driver utility routines
155 #define MAXSTAGE 60 /* max median filter stages */
156 #define NSTAGE 5 /* default median filter stages */
157 #define BMAX 128 /* max timecode length */
158 #define GMT 0 /* I hope nobody sees this */
159 #define MAXDIAL 60 /* max length of modem dial strings */
162 * Line discipline flags. These require line discipline or streams
163 * modules to be installed/loaded in the kernel. If specified, but not
164 * installed, the code runs as if unspecified.
166 #define LDISC_STD 0x0 /* standard */
167 #define LDISC_CLK 0x1 /* tty_clk \n intercept */
168 #define LDISC_CLKPPS 0x2 /* tty_clk \377 intercept */
169 #define LDISC_ACTS 0x4 /* tty_clk #* intercept */
170 #define LDISC_CHU 0x8 /* depredated */
171 #define LDISC_PPS 0x10 /* ppsclock, ppsapi */
172 #define LDISC_RAW 0x20 /* raw binary */
174 struct refclockproc {
175 struct refclockio io; /* I/O handler structure */
176 caddr_t unitptr; /* pointer to unit structure */
177 u_char leap; /* leap/synchronization code */
178 u_char currentstatus; /* clock status */
179 u_char lastevent; /* last exception event */
180 u_char type; /* clock type */
181 const char *clockdesc; /* clock description */
183 char a_lastcode[BMAX]; /* last timecode received */
184 u_short lencode; /* length of last timecode */
186 int year; /* year of eternity */
187 int day; /* day of year */
188 int hour; /* hour of day */
189 int minute; /* minute of hour */
190 int second; /* second of minute */
191 long nsec; /* nanosecond of second */
192 u_long yearstart; /* beginning of year */
193 int coderecv; /* put pointer */
194 int codeproc; /* get pointer */
195 l_fp lastref; /* reference timestamp */
196 l_fp lastrec; /* receive 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_char stratum; /* server stratum */
208 u_int32 refid; /* reference identifier */
209 u_char sloppyclockflag; /* fudge flags */
214 u_long timestarted; /* time we started this */
215 u_long polls; /* polls sent */
216 u_long noreply; /* no replies to polls */
217 u_long badformat; /* bad format reply */
218 u_long baddata; /* bad data reply */
222 * Structure interface between the reference clock support
223 * ntp_refclock.c and particular clock drivers. This must agree with the
224 * structure defined in the driver.
226 #define noentry 0 /* flag for null routine */
227 #define NOFLAGS 0 /* flag for null flags */
230 int (*clock_start) P((int, struct peer *));
231 void (*clock_shutdown) P((int, struct peer *));
232 void (*clock_poll) P((int, struct peer *));
233 void (*clock_control) P((int, struct refclockstat *,
234 struct refclockstat *, struct peer *));
235 void (*clock_init) P((void));
236 void (*clock_buginfo) P((int, struct refclockbug *, struct peer *));
241 * Function prototypes
244 * auxiliary PPS interface (implemented by refclock_atom())
246 extern int pps_sample P((l_fp *));
247 extern int io_addclock_simple P((struct refclockio *));
248 extern int io_addclock P((struct refclockio *));
249 extern void io_closeclock P((struct refclockio *));
252 extern void refclock_buginfo P((struct sockaddr_storage *,
253 struct refclockbug *));
254 extern void refclock_control P((struct sockaddr_storage *,
255 struct refclockstat *,
256 struct refclockstat *));
257 extern int refclock_open P((char *, int, int));
258 extern void refclock_transmit P((struct peer *));
259 extern int refclock_ioctl P((int, int));
260 extern int refclock_process P((struct refclockproc *));
261 extern void refclock_process_offset P((struct refclockproc *, l_fp, l_fp, double));
262 extern void refclock_report P((struct peer *, int));
263 extern int refclock_gtlin P((struct recvbuf *, char *, int,
265 #endif /* REFCLOCK */
267 #endif /* NTP_REFCLOCK_H */