]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ntp/include/ntp_refclock.h
This commit was generated by cvs2svn to compensate for changes in r176187,
[FreeBSD/FreeBSD.git] / contrib / ntp / include / ntp_refclock.h
1 /*
2  * ntp_refclock.h - definitions for reference clock support
3  */
4
5 #ifndef NTP_REFCLOCK_H
6 #define NTP_REFCLOCK_H
7
8 #include "ntp_types.h"
9
10 #if defined(HAVE_BSD_TTYS)
11 #include <sgtty.h>
12 #endif /* HAVE_BSD_TTYS */
13
14 #if defined(HAVE_SYSV_TTYS)
15 #include <termio.h>
16 #endif /* HAVE_SYSV_TTYS */
17
18 #if defined(HAVE_TERMIOS)
19 # ifdef TERMIOS_NEEDS__SVID3
20 #  define _SVID3
21 # endif
22 # include <termios.h>
23 # ifdef TERMIOS_NEEDS__SVID3
24 #  undef _SVID3
25 # endif
26 #endif
27
28 #if defined(HAVE_SYS_MODEM_H)
29 #include <sys/modem.h>
30 #endif
31
32 #if 0 /* If you need that, include ntp_io.h instead */
33 #if defined(STREAM)
34 #include <stropts.h>
35 #if defined(CLK) /* This is never defined, except perhaps by a system header file */
36 #include <sys/clkdefs.h>
37 #endif /* CLK */
38 #endif /* STREAM */
39 #endif
40
41 #include "recvbuff.h"
42
43 #if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS)
44 #define BSD_TTYS
45 #endif /* SYSV_TTYS STREAM BSD_TTYS */
46
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;
51
52 /*
53  * Macros to determine the clock type and unit numbers from a
54  * 127.127.t.u address
55  */
56 #define REFCLOCKTYPE(srcadr)    ((SRCADR(srcadr) >> 8) & 0xff)
57 #define REFCLOCKUNIT(srcadr)    (SRCADR(srcadr) & 0xff)
58
59 /*
60  * List of reference clock names and descriptions. These must agree with
61  * lib/clocktypes.c and ntpd/refclock_conf.c.
62  */
63 struct clktype {
64         int code;               /* driver "major" number */
65         const char *clocktype;  /* long description */
66         const char *abbrev;     /* short description */
67 };
68
69 /*
70  * Configuration flag values
71  */
72 #define CLK_HAVETIME1   0x1
73 #define CLK_HAVETIME2   0x2
74 #define CLK_HAVEVAL1    0x4
75 #define CLK_HAVEVAL2    0x8
76
77 #define CLK_FLAG1       0x1
78 #define CLK_FLAG2       0x2
79 #define CLK_FLAG3       0x4
80 #define CLK_FLAG4       0x8
81
82 #define CLK_HAVEFLAG1   0x10
83 #define CLK_HAVEFLAG2   0x20
84 #define CLK_HAVEFLAG3   0x40
85 #define CLK_HAVEFLAG4   0x80
86
87 /*
88  * Constant for disabling event reporting in
89  * refclock_receive. ORed in leap
90  * parameter
91  */
92 #define REFCLOCK_OWN_STATES     0x80
93
94 /*
95  * Structure for returning clock status
96  */
97 struct refclockstat {
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 */
117 };
118
119 /*
120  * Reference clock I/O structure.  Used to provide an interface between
121  * the reference clock drivers and the I/O module.
122  */
123 struct refclockio {
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
128                                 due to small bursts
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 */
134 };
135
136 /*
137  * Structure for returning debugging info
138  */
139 #define NCLKBUGVALUES   16
140 #define NCLKBUGTIMES    32
141
142 struct refclockbug {
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 */
149 };
150
151 /*
152  * Structure interface between the reference clock support
153  * ntp_refclock.c and the driver utility routines
154  */
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 */
160
161 /*
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.
165  */
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 */
173
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 */
182
183         char    a_lastcode[BMAX]; /* last timecode received */
184         u_short lencode;        /* length of last timecode */
185
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 */
201
202         /*
203          * Configuration data
204          */
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 */
210
211         /*
212          * Status tallies
213          */
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 */
219 };
220
221 /*
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.
225  */
226 #define noentry 0               /* flag for null routine */
227 #define NOFLAGS 0               /* flag for null flags */
228
229 struct refclock {
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 *));
237         u_long clock_flags;
238 };
239
240 /*
241  * Function prototypes
242  */
243 /*
244  * auxiliary PPS interface (implemented by refclock_atom())
245  */
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 *));
250
251 #ifdef REFCLOCK
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,
264                                     l_fp *));
265 #endif /* REFCLOCK */
266
267 #endif /* NTP_REFCLOCK_H */