/contrib/ntp/include/ntp_refclock.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 273 lines · 183 code · 32 blank · 58 comment · 3 complexity · 33117abd2918b80274cefc9d96c452af MD5 · raw file

  1. /*
  2. * ntp_refclock.h - definitions for reference clock support
  3. */
  4. #ifndef NTP_REFCLOCK_H
  5. #define NTP_REFCLOCK_H
  6. #include "ntp_types.h"
  7. #if defined(HAVE_BSD_TTYS)
  8. #include <sgtty.h>
  9. #endif /* HAVE_BSD_TTYS */
  10. #if defined(HAVE_SYSV_TTYS)
  11. #include <termio.h>
  12. #endif /* HAVE_SYSV_TTYS */
  13. #if defined(HAVE_TERMIOS)
  14. # ifdef TERMIOS_NEEDS__SVID3
  15. # define _SVID3
  16. # endif
  17. # include <termios.h>
  18. # ifdef TERMIOS_NEEDS__SVID3
  19. # undef _SVID3
  20. # endif
  21. #endif
  22. #if defined(HAVE_SYS_MODEM_H)
  23. #include <sys/modem.h>
  24. #endif
  25. #if 0 /* If you need that, include ntp_io.h instead */
  26. #if defined(STREAM)
  27. #include <stropts.h>
  28. #if defined(CLK) /* This is never defined, except perhaps by a system header file */
  29. #include <sys/clkdefs.h>
  30. #endif /* CLK */
  31. #endif /* STREAM */
  32. #endif
  33. #include "recvbuff.h"
  34. #if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS)
  35. #define BSD_TTYS
  36. #endif /* SYSV_TTYS STREAM BSD_TTYS */
  37. #define SAMPLE(x) pp->coderecv = (pp->coderecv + 1) % MAXSTAGE; \
  38. pp->filter[pp->coderecv] = (x); \
  39. if (pp->coderecv == pp->codeproc) \
  40. pp->codeproc = (pp->codeproc + 1) % MAXSTAGE;
  41. /*
  42. * Macros to determine the clock type and unit numbers from a
  43. * 127.127.t.u address
  44. */
  45. #define REFCLOCKTYPE(srcadr) ((SRCADR(srcadr) >> 8) & 0xff)
  46. #define REFCLOCKUNIT(srcadr) (SRCADR(srcadr) & 0xff)
  47. /*
  48. * List of reference clock names and descriptions. These must agree with
  49. * lib/clocktypes.c and ntpd/refclock_conf.c.
  50. */
  51. struct clktype {
  52. int code; /* driver "major" number */
  53. const char *clocktype; /* long description */
  54. const char *abbrev; /* short description */
  55. };
  56. extern struct clktype clktypes[];
  57. /*
  58. * Configuration flag values
  59. */
  60. #define CLK_HAVETIME1 0x1
  61. #define CLK_HAVETIME2 0x2
  62. #define CLK_HAVEVAL1 0x4
  63. #define CLK_HAVEVAL2 0x8
  64. #define CLK_FLAG1 0x1
  65. #define CLK_FLAG2 0x2
  66. #define CLK_FLAG3 0x4
  67. #define CLK_FLAG4 0x8
  68. #define CLK_HAVEFLAG1 0x10
  69. #define CLK_HAVEFLAG2 0x20
  70. #define CLK_HAVEFLAG3 0x40
  71. #define CLK_HAVEFLAG4 0x80
  72. /*
  73. * Constant for disabling event reporting in
  74. * refclock_receive. ORed in leap
  75. * parameter
  76. */
  77. #define REFCLOCK_OWN_STATES 0x80
  78. /*
  79. * Structure for returning clock status
  80. */
  81. struct refclockstat {
  82. u_char type; /* clock type */
  83. u_char flags; /* clock flags */
  84. u_char haveflags; /* bit array of valid flags */
  85. u_short lencode; /* length of last timecode */
  86. const char *p_lastcode; /* last timecode received */
  87. u_int32 polls; /* transmit polls */
  88. u_int32 noresponse; /* no response to poll */
  89. u_int32 badformat; /* bad format timecode received */
  90. u_int32 baddata; /* invalid data timecode received */
  91. u_int32 timereset; /* driver resets */
  92. const char *clockdesc; /* ASCII description */
  93. double fudgetime1; /* configure fudge time1 */
  94. double fudgetime2; /* configure fudge time2 */
  95. int32 fudgeval1; /* configure fudge value1 */
  96. int32 fudgeval2; /* configure fudge value2 */
  97. u_char currentstatus; /* clock status */
  98. u_char lastevent; /* last exception event */
  99. u_char leap; /* leap bits */
  100. struct ctl_var *kv_list; /* additional variables */
  101. };
  102. /*
  103. * Reference clock I/O structure. Used to provide an interface between
  104. * the reference clock drivers and the I/O module.
  105. */
  106. struct refclockio {
  107. struct refclockio *next; /* link to next structure */
  108. void (*clock_recv) P((struct recvbuf *)); /* completion routine */
  109. int (*io_input) P((struct recvbuf *)); /* input routine -
  110. to avoid excessive buffer use
  111. due to small bursts
  112. of refclock input data */
  113. caddr_t srcclock; /* pointer to clock structure */
  114. int datalen; /* lenth of data */
  115. SOCKET fd; /* file descriptor */
  116. u_long recvcount; /* count of receive completions */
  117. };
  118. /*
  119. * Structure for returning debugging info
  120. */
  121. #define NCLKBUGVALUES 16
  122. #define NCLKBUGTIMES 32
  123. struct refclockbug {
  124. u_char nvalues; /* values following */
  125. u_char ntimes; /* times following */
  126. u_short svalues; /* values format sign array */
  127. u_int32 stimes; /* times format sign array */
  128. u_int32 values[NCLKBUGVALUES]; /* real values */
  129. l_fp times[NCLKBUGTIMES]; /* real times */
  130. };
  131. /*
  132. * Structure interface between the reference clock support
  133. * ntp_refclock.c and the driver utility routines
  134. */
  135. #define MAXSTAGE 60 /* max median filter stages */
  136. #define NSTAGE 5 /* default median filter stages */
  137. #define BMAX 128 /* max timecode length */
  138. #define GMT 0 /* I hope nobody sees this */
  139. #define MAXDIAL 60 /* max length of modem dial strings */
  140. /*
  141. * Line discipline flags. These require line discipline or streams
  142. * modules to be installed/loaded in the kernel. If specified, but not
  143. * installed, the code runs as if unspecified.
  144. */
  145. #define LDISC_STD 0x00 /* standard */
  146. #define LDISC_CLK 0x01 /* tty_clk \n intercept */
  147. #define LDISC_CLKPPS 0x02 /* tty_clk \377 intercept */
  148. #define LDISC_ACTS 0x04 /* tty_clk #* intercept */
  149. #define LDISC_CHU 0x08 /* depredated */
  150. #define LDISC_PPS 0x10 /* ppsclock, ppsapi */
  151. #define LDISC_RAW 0x20 /* raw binary */
  152. #define LDISC_ECHO 0x40 /* enable echo */
  153. #define LDISC_REMOTE 0x80 /* remote mode */
  154. #define LDISC_7O1 0x100 /* 7-bit, odd parity for Z3801A */
  155. struct refclockproc {
  156. struct refclockio io; /* I/O handler structure */
  157. caddr_t unitptr; /* pointer to unit structure */
  158. u_char leap; /* leap/synchronization code */
  159. u_char currentstatus; /* clock status */
  160. u_char lastevent; /* last exception event */
  161. u_char type; /* clock type */
  162. const char *clockdesc; /* clock description */
  163. char a_lastcode[BMAX]; /* last timecode received */
  164. u_short lencode; /* length of last timecode */
  165. int year; /* year of eternity */
  166. int day; /* day of year */
  167. int hour; /* hour of day */
  168. int minute; /* minute of hour */
  169. int second; /* second of minute */
  170. long nsec; /* nanosecond of second */
  171. u_long yearstart; /* beginning of year */
  172. int coderecv; /* put pointer */
  173. int codeproc; /* get pointer */
  174. l_fp lastref; /* reference timestamp */
  175. l_fp lastrec; /* receive timestamp */
  176. double offset; /* mean offset */
  177. double disp; /* sample dispersion */
  178. double jitter; /* jitter (mean squares) */
  179. double filter[MAXSTAGE]; /* median filter */
  180. /*
  181. * Configuration data
  182. */
  183. double fudgetime1; /* fudge time1 */
  184. double fudgetime2; /* fudge time2 */
  185. u_char stratum; /* server stratum */
  186. u_int32 refid; /* reference identifier */
  187. u_char sloppyclockflag; /* fudge flags */
  188. /*
  189. * Status tallies
  190. */
  191. u_long timestarted; /* time we started this */
  192. u_long polls; /* polls sent */
  193. u_long noreply; /* no replies to polls */
  194. u_long badformat; /* bad format reply */
  195. u_long baddata; /* bad data reply */
  196. };
  197. /*
  198. * Structure interface between the reference clock support
  199. * ntp_refclock.c and particular clock drivers. This must agree with the
  200. * structure defined in the driver.
  201. */
  202. #define noentry 0 /* flag for null routine */
  203. #define NOFLAGS 0 /* flag for null flags */
  204. struct refclock {
  205. int (*clock_start) P((int, struct peer *));
  206. void (*clock_shutdown) P((int, struct peer *));
  207. void (*clock_poll) P((int, struct peer *));
  208. void (*clock_control) P((int, struct refclockstat *,
  209. struct refclockstat *, struct peer *));
  210. void (*clock_init) P((void));
  211. void (*clock_buginfo) P((int, struct refclockbug *, struct peer *));
  212. void (*clock_timer) P((int, struct peer *));
  213. };
  214. /*
  215. * Function prototypes
  216. */
  217. /*
  218. * auxiliary PPS interface (implemented by refclock_atom())
  219. */
  220. extern int pps_sample P((l_fp *));
  221. extern int io_addclock_simple P((struct refclockio *));
  222. extern int io_addclock P((struct refclockio *));
  223. extern void io_closeclock P((struct refclockio *));
  224. #ifdef REFCLOCK
  225. extern void refclock_buginfo P((struct sockaddr_storage *,
  226. struct refclockbug *));
  227. extern void refclock_control P((struct sockaddr_storage *,
  228. struct refclockstat *,
  229. struct refclockstat *));
  230. extern int refclock_open P((char *, u_int, u_int));
  231. extern int refclock_setup P((int, u_int, u_int));
  232. extern void refclock_timer P((struct peer *));
  233. extern void refclock_transmit P((struct peer *));
  234. extern int refclock_ioctl P((int, u_int));
  235. extern int refclock_process P((struct refclockproc *));
  236. extern void refclock_process_offset P((struct refclockproc *, l_fp, l_fp, double));
  237. extern void refclock_report P((struct peer *, int));
  238. extern int refclock_gtlin P((struct recvbuf *, char *, int, l_fp *));
  239. extern int refclock_gtraw P((struct recvbuf *, char *, int, l_fp *));
  240. #endif /* REFCLOCK */
  241. #endif /* NTP_REFCLOCK_H */