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->filter[pp->coderecv++ % MAXSTAGE] = (x); \ 48 if (pp->coderecv % MAXSTAGE == pp->codeproc % MAXSTAGE) \ 49 pp->codeproc++; 50 51 /* 52 * Macros to determine the clock type and unit numbers from a 53 * 127.127.t.u address 54 */ 55 #define REFCLOCKTYPE(srcadr) ((SRCADR(srcadr) >> 8) & 0xff) 56 #define REFCLOCKUNIT(srcadr) (SRCADR(srcadr) & 0xff) 57 58 /* 59 * List of reference clock names and descriptions. These must agree with 60 * lib/clocktypes.c and ntpd/refclock_conf.c. 61 */ 62 struct clktype { 63 int code; /* driver "major" number */ 64 const char *clocktype; /* long description */ 65 const char *abbrev; /* short description */ 66 }; 67 68 /* 69 * Configuration flag values 70 */ 71 #define CLK_HAVETIME1 0x1 72 #define CLK_HAVETIME2 0x2 73 #define CLK_HAVEVAL1 0x4 74 #define CLK_HAVEVAL2 0x8 75 76 #define CLK_FLAG1 0x1 77 #define CLK_FLAG2 0x2 78 #define CLK_FLAG3 0x4 79 #define CLK_FLAG4 0x8 80 81 #define CLK_HAVEFLAG1 0x10 82 #define CLK_HAVEFLAG2 0x20 83 #define CLK_HAVEFLAG3 0x40 84 #define CLK_HAVEFLAG4 0x80 85 86 /* 87 * Constant for disabling event reporting in 88 * refclock_receive. ORed in leap 89 * parameter 90 */ 91 #define REFCLOCK_OWN_STATES 0x80 92 93 /* 94 * Structure for returning clock status 95 */ 96 struct refclockstat { 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 */ 116 }; 117 118 /* 119 * Reference clock I/O structure. Used to provide an interface between 120 * the reference clock drivers and the I/O module. 121 */ 122 struct refclockio { 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 127 due to small bursts 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 */ 133 }; 134 135 /* 136 * Structure for returning debugging info 137 */ 138 #define NCLKBUGVALUES 16 139 #define NCLKBUGTIMES 32 140 141 struct refclockbug { 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 */ 148 }; 149 150 /* 151 * Structure interface between the reference clock support 152 * ntp_refclock.c and the driver utility routines 153 */ 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 */ 159 160 /* 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. 164 */ 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 */ 172 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 */ 181 182 char a_lastcode[BMAX]; /* last timecode received */ 183 u_short lencode; /* length of last timecode */ 184 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 */ 201 202 /* 203 * Configuration data 204 */ 205 double fudgetime1; /* fudge time1 */ 206 double fudgetime2; /* fudge time2 */ 207 u_int32 refid; /* reference identifier */ 208 u_char sloppyclockflag; /* fudge flags */ 209 210 /* 211 * Status tallies 212 */ 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 */ 218 }; 219 220 /* 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. 224 */ 225 #define noentry 0 /* flag for null routine */ 226 #define NOFLAGS 0 /* flag for null flags */ 227 228 struct refclock { 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 *)); 236 u_long clock_flags; 237 }; 238 239 /* 240 * Function prototypes 241 */ 242 /* 243 * auxiliary PPS interface (implemented by refclock_atom()) 244 */ 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 *)); 249 250 #ifdef REFCLOCK 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, 263 l_fp *)); 264 #endif /* REFCLOCK */ 265 266 #endif /* NTP_REFCLOCK_H */ 267