diff options
author | peter <peter@FreeBSD.org> | 1995-12-30 19:02:48 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1995-12-30 19:02:48 +0000 |
commit | c3f352d4ad515968c54d216a0e53252eff8ab3ef (patch) | |
tree | 48ddeda3c6c8d8572cc34bf52ccf9cb9bd97d488 /usr.sbin/xntpd/kernel | |
parent | ab124e78b0271ddb904b761b31e5c9a0cf24e070 (diff) | |
download | FreeBSD-src-c3f352d4ad515968c54d216a0e53252eff8ab3ef.zip FreeBSD-src-c3f352d4ad515968c54d216a0e53252eff8ab3ef.tar.gz |
This commit was generated by cvs2svn to compensate for changes in r13122,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'usr.sbin/xntpd/kernel')
-rw-r--r-- | usr.sbin/xntpd/kernel/Makefile.tmpl | 59 | ||||
-rw-r--r-- | usr.sbin/xntpd/kernel/README | 90 | ||||
-rw-r--r-- | usr.sbin/xntpd/kernel/README.streams | 86 | ||||
-rw-r--r-- | usr.sbin/xntpd/kernel/tty_chu.c | 276 | ||||
-rw-r--r-- | usr.sbin/xntpd/kernel/tty_chu_STREAMS.c | 603 | ||||
-rw-r--r-- | usr.sbin/xntpd/kernel/tty_clk.c | 317 | ||||
-rw-r--r-- | usr.sbin/xntpd/kernel/tty_clk_STREAMS.c | 266 |
7 files changed, 0 insertions, 1697 deletions
diff --git a/usr.sbin/xntpd/kernel/Makefile.tmpl b/usr.sbin/xntpd/kernel/Makefile.tmpl deleted file mode 100644 index 8b40f4a..0000000 --- a/usr.sbin/xntpd/kernel/Makefile.tmpl +++ /dev/null @@ -1,59 +0,0 @@ -# -# /src/NTP/REPOSITORY/v3/kernel/Makefile.tmpl,v 3.6 1994/01/25 19:04:35 kardel Exp -# -# parse routine that could be used in two places -# -COMPILER= cc -COPTS= -O -AUTHDEFS=-DDES -LIBDEFS= -DBIG_ENDIAN -RANLIB= ranlib -INSTALL= install -CLOCKDEFS= -DEFS= -DEFS_OPT= -DEFS_LOCAL= -CLK_VDOBJS=clkinit.o tty_clk_STREAMS.o -CHU_VDOBJS=chuinit.o tty_chu_STREAMS.o -INCL=-I../include -CFLAGS= $(COPTS) $(DEFS) $(DEFS_LOCAL) $(INCL) -DKERNEL -CC= $(COMPILER) -# - -all: - @echo $(DEFS) $(DEFS_LOCAL) $(CLOCKDEFS) | \ - awk '/-DREFCLOCK/ && ( /-D.*CLK/ || /-D.*PPS/ ) { makeit=1; }\ - END { if (makeit) \ - { print ""; \ - print "### STREAMS kernel modules ppsclock, ppsclocd or line disciplines must"; \ - print "### be installed manually if needed"; \ - print "### see kernel/README* for details"; \ - print "### The parse refclock implementation has their own support in"; \ - print "### parse/*."; } }' - -loadable: clk.o chu.o - -clk.o: ${CLK_VDOBJS} - ld -r ${OBJS} -o clk.o - -clk.h: - echo "#define NCLK 2" > clk.h - -tty_clk_STREAMS.o: clk.h tty_clk_STREAMS.c - cc ${CFLAGS} tty_clk_STREAMS.c -c tty_clk_STREAMS.o - -chu.o: ${CHU_VDOBJS} - ld -r ${OBJS} -o chu.o - -chu.h: - echo "#define NCHU 2" > chu.h - -tty_chu_STREAMS.o: chu.h tty_chu_STREAMS.c - cc ${CFLAGS} tty_chu_STREAMS.c -c tty_chu_STREAMS.o - -clean: - -@rm -f *~ *.o *.out *.ln make.log Makefile.bak \ - lintlib.errs lint.errs - -distclean: clean - -@rm -f *.orig *.rej .version Makefile diff --git a/usr.sbin/xntpd/kernel/README b/usr.sbin/xntpd/kernel/README deleted file mode 100644 index cf69b13..0000000 --- a/usr.sbin/xntpd/kernel/README +++ /dev/null @@ -1,90 +0,0 @@ -This directory contains code for two line disciplines which may -work with BSD-style terminal drivers. While I'll try to cover -installation details for the more useful one here as best I can, -you really should know what you are doing before attempting to -put one of these in your kernel since the details seem to vary -from BSD variant to BSD variant. - -Tty_clk.c contains a generic clock support line discipline. -The terminal driver is actually run in raw mode, giving you an -eight bit data path. Instead of delivering the data -character-by-character, however, the line discipline collects -characters until one of two magic characters (your current erase -and kill characters. Don't throw up) is received. A timestamp -is then taken (by calling microtime()), inserted in the input -buffer after the magic character, and the whole mess made available -for input by the application. Both select() and SIGIO are supported -by the discipline. - -Tty_chu.c is a special purpose line discipline for receiving -the CHU time code. It understands enough about the format of the -code CHU transmits to filter out errors, and delivers an entire -ten character code group to the application all at once, including -a timestamp for each character. The structure the code group is -delivered in is defined in chudefs.h. Note that this line discipline -is old and could use some rewriting for better portability. Please -drop me a line if you are interested in using this. - -To install the clock line discipline, do something like the following: - -(1) Copy tty_clk.c into /sys/sys - -(2) Edit /sys/sys/tty_conf.c. You will want to include some facsimile - of the following lines: - -#include "clk.h" -#if NCLK > 0 -int clkopen(), clkclose(), clkwrite(), clkinput(), clkioctl(); -#endif - -#if NCLK > 0 - { clkopen, clkclose, ttread, clkwrite, clkioctl, - clkinput, nodev, nulldev, ttstart, nullmodem, /* 10- CLKLDISC */ - ttselect }, -#else - { nodev, nodev, nodev, nodev, nodev, - nodev, nodev, nodev, nodev, nodev, - nodev }, -#endif - - In Ultrix 4.2a and 4.3 the file to edit is /sys/data/tty_conf_data.c. - The lines should be - -#if NCLK > 0 - clkopen, clkclose, ttread, clkwrite, clkioctl, /* 10 */ - clkinput, nodev, nulldev, ttstart, nulldev, -#else - nodev, nodev, nodev, nodev, nodev, - nodev, nodev, nodev, nodev, nodev, -#endif - - Note that if your kernel doesn't include the ??select() entry in - the structure (i.e. there are only 10 entry points in the structure) - just leave it out. Also note that the number you give the line - discipline (10 in my kernel) will be specific to your kernel and - will depend on what is in there already. The entries sould be in - order with no missing space; that is, if there are only seven - disciplines already defined and you want to use 10 for good reason, - you should define a dummy 9th entry like this - - nodev, nodev, nodev, nodev, nodev, /* 9 */ - nodev, nodev, nodev, nodev, nodev, - -(3) Edit /sys/h/ioctl.h and include a line (somewhere near where other - line disciplines are defined) like: - -#define CLKLDISC 10 /* clock line discipline */ - - The `10' should match what you used in /sys/sys/tty_conf.c. - -(4) Edit /sys/conf/files and add a line which looks like: - -sys/tty_clk.c optional clk - -(5) Edit the configuration file for the machine you want to use - the clock line discipline on to include the following: - -pseudo-device clk 4 - -(6) Run config, then make clean, then make depend, then make vmunix. - Then reboot the new kernel. diff --git a/usr.sbin/xntpd/kernel/README.streams b/usr.sbin/xntpd/kernel/README.streams deleted file mode 100644 index 26c2825..0000000 --- a/usr.sbin/xntpd/kernel/README.streams +++ /dev/null @@ -1,86 +0,0 @@ -Some kernels don't support additional user defined line disciplines. -Especially notable in this regard is SunOS and System V. They -provide similar support in the form of "Streams". Accordingly, -included in this directory is a pair of STREAMS modules to -replace the line disciplines that provide clock support for -xntpd. Notice that the "clkdefs.h" file is not used in the -original line discipline, but the "chudefs.h" file is the -same one used in the original line discipline. - -TO INSTALL A NEW STREAMS DRIVER: - -1. Copy your choice to /sys/os, removing the "_STREAMS" in the -filename. - -2. Copy the appropriate *defs.h file to /usr/include/sys, -then link it (with ln) to /sys/sys. - -In the following steps, substitute "clk" for "chu" if you're -installing the clk driver. - -3. Append to /sys/conf.common/files.cmn: - -os/tty_chu.c optional chu - -4. Edit /sys/sun/str_conf.c. You'll want to add lines in three -places. It'll be sort of clear where when you see the file. - -. -. -. -#include "chu.h" -. -. -. -#if NCHU > 0 -extern struct streamtab chuinfo; -#endif -. -. -. -#if NCHU > 0 - { "chu", &chuinfo }, -#endif -. -. -. - -At this point, the kernel-making "config [k-name] ; cd ../[k-name] ; make" -should produce a kernel just as it did before. If it fouls up, -something's wrong. - -5. Edit /sys/[arch]/conf/[k-name] (substituting the architecture and -kernel name) to stick in: - -pseudo-device chu4 # CHU clock support - -You can change 4 to anything you like. It will limit the number -of instantiations of the chu driver you can use at the same time. - -6. Make a new kernel and boot it. - -HOW TO USE THE CHU STREAMS DRIVER: - -The driver should act exactly like the line discipline. -After setting the raw mode, and exclusive access (if you want), -pop off all the extra streams, then push the chu module -on. From then on, any reads from the file in question -will return chucode structures as defined in chudefs.h. -Depending on the settings of PEDANTIC and ANAL_RETENTIVE -used when compiling the kernel, some checking of the -data may or may not be necessary. - -HOW TO USE THE CLK STREAMS DRIVER: - -First, it should be noted that a new ioctl() has been defined. -The CLK_SETSTR ioctl takes a pointer to a string of no more -than CLK_MAXSTRSIZE characters. Until the first CLK_SETSTR -is performed, the driver will simply pass through characters. -Once it is passed a string, then any character in that string -will be immediately followed by a struct timeval. You can -change the string whenever you want by doing another -CLK_SETSTR. The character must be an exact, 8 bit match. -The character '\000' cannot, unfortunately, be stamped. -Passing an empty string to CLK_SETSTR turns off stamping. -Passing NULL will produce undefined results. - diff --git a/usr.sbin/xntpd/kernel/tty_chu.c b/usr.sbin/xntpd/kernel/tty_chu.c deleted file mode 100644 index 4615875..0000000 --- a/usr.sbin/xntpd/kernel/tty_chu.c +++ /dev/null @@ -1,276 +0,0 @@ -/* tty_chu.c,v 3.1 1993/07/06 01:07:30 jbj Exp - * tty_chu.c - CHU line driver - */ - -#include "chu.h" -#if NCHU > 0 - -#include "../h/param.h" -#include "../h/types.h" -#include "../h/systm.h" -#include "../h/dir.h" -#include "../h/user.h" -#include "../h/ioctl.h" -#include "../h/tty.h" -#include "../h/proc.h" -#include "../h/file.h" -#include "../h/conf.h" -#include "../h/buf.h" -#include "../h/uio.h" - -#include "../h/chudefs.h" - -/* - * Line discipline for receiving CHU time codes. - * Does elementary noise elimination, takes time stamps after - * the arrival of each character, returns a buffer full of the - * received 10 character code and the associated time stamps. - */ -#define NUMCHUBUFS 3 - -struct chudata { - u_char used; /* Set to 1 when structure in use */ - u_char lastindex; /* least recently used buffer */ - u_char curindex; /* buffer to use */ - u_char sleeping; /* set to 1 when we're sleeping on a buffer */ - struct chucode chubuf[NUMCHUBUFS]; -} chu_data[NCHU]; - -/* - * Number of microseconds we allow between - * character arrivals. The speed is 300 baud - * so this should be somewhat more than 30 msec - */ -#define CHUMAXUSEC (50*1000) /* 50 msec */ - -int chu_debug = 0; - -/* - * Open as CHU time discipline. Called when discipline changed - * with ioctl, and changes the interpretation of the information - * in the tty structure. - */ -/*ARGSUSED*/ -chuopen(dev, tp) - dev_t dev; - register struct tty *tp; -{ - register struct chudata *chu; - - /* - * Don't allow multiple opens. This will also protect us - * from someone opening /dev/tty - */ - if (tp->t_line == CHULDISC) - return (EBUSY); - ttywflush(tp); - for (chu = chu_data; chu < &chu_data[NCHU]; chu++) - if (!chu->used) - break; - if (chu >= &chu[NCHU]) - return (EBUSY); - chu->used++; - chu->lastindex = chu->curindex = 0; - chu->sleeping = 0; - chu->chubuf[0].ncodechars = 0; - tp->T_LINEP = (caddr_t) chu; - return (0); -} - -/* - * Break down... called when discipline changed or from device - * close routine. - */ -chuclose(tp) - register struct tty *tp; -{ - register int s = spl5(); - - ((struct chudata *) tp->T_LINEP)->used = 0; - tp->t_cp = 0; - tp->t_inbuf = 0; - tp->t_rawq.c_cc = 0; /* clear queues -- paranoid */ - tp->t_canq.c_cc = 0; - tp->t_line = 0; /* paranoid: avoid races */ - splx(s); -} - -/* - * Read a CHU buffer. Sleep on the current buffer - */ -churead(tp, uio) - register struct tty *tp; - struct uio *uio; -{ - register struct chudata *chu; - register struct chucode *chucode; - register int s; - - if ((tp->t_state&TS_CARR_ON)==0) - return (EIO); - - chu = (struct chudata *) (tp->T_LINEP); - - s = spl5(); - chucode = &(chu->chubuf[chu->lastindex]); - while (chu->curindex == chu->lastindex) { - chu->sleeping = 1; - sleep((caddr_t)chucode, TTIPRI); - } - chu->sleeping = 0; - if (++(chu->lastindex) >= NUMCHUBUFS) - chu->lastindex = 0; - splx(s); - - return (uiomove((caddr_t)chucode, sizeof(*chucode), UIO_READ, uio)); -} - -/* - * Low level character input routine. - * If the character looks okay, grab a time stamp. If the stuff in - * the buffer is too old, dump it and start fresh. If the character is - * non-BCDish, everything in the buffer too. - */ -chuinput(c, tp) - register int c; - register struct tty *tp; -{ - register struct chudata *chu = (struct chudata *) tp->T_LINEP; - register struct chucode *chuc; - register int i; - long sec, usec; - struct timeval tv; - - /* - * Do a check on the BSDness of the character. This delays - * the time stamp a bit but saves a fair amount of overhead - * when the static is bad. - */ - if (((c) & 0xf) > 9 || (((c)>>4) & 0xf) > 9) { - chuc = &(chu->chubuf[chu->curindex]); - chuc->ncodechars = 0; /* blow all previous away */ - return; - } - - /* - * Call microtime() to get the current time of day - */ - microtime(&tv); - - /* - * Compute the difference in this character's time stamp - * and the last. If it exceeds the margin, blow away all - * the characters currently in the buffer. - */ - chuc = &(chu->chubuf[chu->curindex]); - i = (int)chuc->ncodechars; - if (i > 0) { - sec = tv.tv_sec - chuc->codetimes[i-1].tv_sec; - usec = tv.tv_usec - chuc->codetimes[i-1].tv_usec; - if (usec < 0) { - sec -= 1; - usec += 1000000; - } - if (sec != 0 || usec > CHUMAXUSEC) { - i = 0; - chuc->ncodechars = 0; - } - } - - /* - * Store the character. If we're done, have to tell someone - */ - chuc->codechars[i] = (u_char)c; - chuc->codetimes[i] = tv; - - if (++i < NCHUCHARS) { - /* - * Not much to do here. Save the count and wait - * for another character. - */ - chuc->ncodechars = (u_char)i; - } else { - /* - * Mark this buffer full and point at next. If the - * next buffer is full we overwrite it by bumping the - * next pointer. - */ - chuc->ncodechars = NCHUCHARS; - if (++(chu->curindex) >= NUMCHUBUFS) - chu->curindex = 0; - if (chu->curindex == chu->lastindex) - if (++(chu->lastindex) >= NUMCHUBUFS) - chu->lastindex = 0; - chu->chubuf[chu->curindex].ncodechars = 0; - - /* - * Wake up anyone sleeping on this. Also wake up - * selectors and/or deliver a SIGIO as required. - */ - if (tp->t_rsel) { - selwakeup(tp->t_rsel, tp->t_state&TS_RCOLL); - tp->t_state &= ~TS_RCOLL; - tp->t_rsel = 0; - } - if (tp->t_state & TS_ASYNC) - gsignal(tp->t_pgrp, SIGIO); - if (chu->sleeping) - (void) wakeup((caddr_t)chuc); - } -} - -/* - * Handle ioctls. We reject all tty-style except those that - * change the line discipline. - */ -chuioctl(tp, cmd, data, flag) - struct tty *tp; - int cmd; - caddr_t data; - int flag; -{ - - if ((cmd>>8) != 't') - return (-1); - switch (cmd) { - case TIOCSETD: - case TIOCGETD: - case TIOCGETP: - case TIOCGETC: - return (-1); - } - return (ENOTTY); /* not quite appropriate */ -} - - -chuselect(dev, rw) - dev_t dev; - int rw; -{ - register struct tty *tp = &cdevsw[major(dev)].d_ttys[minor(dev)]; - struct chudata *chu; - int s = spl5(); - - chu = (struct chudata *) (tp->T_LINEP); - - switch (rw) { - - case FREAD: - if (chu->curindex != chu->lastindex) - goto win; - if (tp->t_rsel && tp->t_rsel->p_wchan == (caddr_t)&selwait) - tp->t_state |= TS_RCOLL; - else - tp->t_rsel = u.u_procp; - break; - - case FWRITE: - goto win; - } - splx(s); - return (0); -win: - splx(s); - return (1); -} -#endif NCHU diff --git a/usr.sbin/xntpd/kernel/tty_chu_STREAMS.c b/usr.sbin/xntpd/kernel/tty_chu_STREAMS.c deleted file mode 100644 index f46e25d..0000000 --- a/usr.sbin/xntpd/kernel/tty_chu_STREAMS.c +++ /dev/null @@ -1,603 +0,0 @@ -/* - * CHU STREAMS module for SunOS - * - * Version 2.6 - * - * Copyright 1991-1994, Nick Sayer - * - * Special thanks to Greg Onufer for his debug assists. - * Special thanks to Matthias Urlichs for the 4.1.x loadable driver support - * code. - * Special wet-noodle whippings to Sun for not properly documenting - * ANYTHING that makes this stuff at all possible. - * - * Should be PUSHed directly on top of a serial I/O channel. - * Provides complete chucode structures to user space. - * - * COMPILATION: - * - * - * To make a SunOS 4.1.x compatable loadable module (from the ntp kernel - * directory): - * - * % cc -c -I../include -DLOADABLE tty_chu_STREAMS.c - * - * The resulting .o file is the loadable module. Modload it - * thusly: - * - * % modload tty_chu_STREAMS.o -entry _chuinit - * - * When none of the instances are pushed in a STREAM, you can - * modunload the driver in the usual manner if you wish. - * - * As an alternative to loading it dynamically you can compile it - * directly into the kernel by hacking str_conf.c. See the README - * file for more details on doing it the old fashioned way. - * - * - * To make a Solaris 2.x compatable module (from the ntp kernel - * directory): - * - * % {gcc,cc} -c -I../include -DSOLARIS2 tty_chu_STREAMS.c - * % ld -r -o /usr/kernel/strmod/chu tty_chu_STREAMS.o - * % chmod 755 /usr/kernel/strmod/chu - * - * The OS will load it for you automagically when it is first pushed. - * - * If you get syntax errors from <sys/timer.h> (really references - * to types that weren't typedef'd in gcc's version of types.h), - * add -D_SYS_TIMER_H to blot out the miscreants. - * - * Under Solaris 2.2 and previous, do not attempt to modunload the - * module unless you're SURE it's not in use. I haven't tried it, but - * I've been told it won't do the right thing. Under Solaris 2.3 (and - * presumably future revs) an attempt to unload the module when it's in - * use will properly refuse with a "busy" message. - * - * - * HISTORY: - * - * v2.6 - Mutexed the per-instance chucode just to be safe. - * v2.5 - Fixed show-stopper bug in Solaris 2.x - qprocson(). - * v2.4 - Added dynamic allocation support for Solaris 2.x. - * v2.3 - Added support for Solaris 2.x. - * v2.2 - Added SERVICE IMMEDIATE hack. - * v2.1 - Added 'sixth byte' heuristics. - * v2.0 - first version with an actual version number. - * Added support for new CHU 'second 31' data format. - * Deleted PEDANTIC and ANAL_RETENTIVE. - * - */ - -#ifdef SOLARIS2 -# ifndef NCHU -# define NCHU 1 -# endif -# define _KERNEL -#elif defined(LOADABLE) -# ifndef NCHU -# define NCHU 3 -# define KERNEL -# endif -#else -# include "chu.h" -#endif - -#if NCHU > 0 - -/* - * Number of microseconds we allow between - * character arrivals. The speed is 300 baud - * so this should be somewhat more than 30 msec - */ -#define CHUMAXUSEC (60*1000) /* 60 msec */ - -#include <sys/types.h> -#include <sys/stream.h> -#include <sys/param.h> -#include <sys/time.h> -#include <sys/errno.h> -#include <sys/user.h> -#include <syslog.h> -#include <sys/tty.h> - -#include <sys/chudefs.h> - -#ifdef SOLARIS2 - -#include <sys/ksynch.h> -#include <sys/kmem.h> -#include <sys/cmn_err.h> -#include <sys/conf.h> -#include <sys/strtty.h> -#include <sys/modctl.h> -#include <sys/ddi.h> -#include <sys/sunddi.h> - -#endif - -#ifdef LOADABLE - -#include <sys/kernel.h> -#include <sys/conf.h> -#include <sys/buf.h> -#include <sundev/mbvar.h> -#include <sun/autoconf.h> -#include <sun/vddrv.h> - -#endif - - -static struct module_info rminfo = { 0, "chu", 0, INFPSZ, 0, 0 }; -static struct module_info wminfo = { 0, "chu", 0, INFPSZ, 0, 0 }; -static int chuopen(), churput(), chuwput(), chuclose(); - -static struct qinit rinit = { churput, NULL, chuopen, chuclose, NULL, - &rminfo, NULL }; - -static struct qinit winit = { chuwput, NULL, NULL, NULL, NULL, - &wminfo, NULL }; - -struct streamtab chuinfo = { &rinit, &winit, NULL, NULL }; - -/* - * Here's our private data type and structs - */ -struct priv_data -{ -#ifdef SOLARIS2 - kmutex_t chucode_mutex; -#else - char in_use; -#endif - struct chucode chu_struct; -}; - -#ifndef SOLARIS2 -struct priv_data our_priv_data[NCHU]; -#endif - -#ifdef SOLARIS2 - -static struct fmodsw fsw = -{ - "chu", - &chuinfo, - D_NEW | D_MP -}; - -extern struct mod_ops mod_strmodops; - -static struct modlstrmod modlstrmod = -{ - &mod_strmodops, - "CHU timecode decoder v2.6", - &fsw -}; - -static struct modlinkage modlinkage = -{ - MODREV_1, - (void*) &modlstrmod, - NULL -}; - -int _init() -{ - return mod_install(&modlinkage); -} - -int _info(foo) -struct modinfo *foo; -{ - return mod_info(&modlinkage,foo); -} - -int _fini() -{ - return mod_remove(&modlinkage); -} - -#endif /* SOLARIS2 */ - -#ifdef LOADABLE - -# ifdef sun - -static struct vdldrv vd = -{ - VDMAGIC_PSEUDO, - "chu", - NULL, NULL, NULL, 0, 0, NULL, NULL, 0, 0, -}; - -static struct fmodsw *chu_fmod; - -/*ARGSUSED*/ -chuinit (fc, vdp, vdi, vds) - unsigned int fc; - struct vddrv *vdp; - addr_t vdi; - struct vdstat *vds; -{ - switch (fc) { - case VDLOAD: - { - int dev, i; - - /* Find free entry in fmodsw */ - for (dev = 0; dev < fmodcnt; dev++) { - if (fmodsw[dev].f_str == NULL) - break; - } - if (dev == fmodcnt) - return (ENODEV); - chu_fmod = &fmodsw[dev]; - - /* If you think a kernel would have strcpy() you're mistaken. */ - for (i = 0; i <= FMNAMESZ; i++) - chu_fmod->f_name[i] = wminfo.mi_idname[i]; - - chu_fmod->f_str = &chuinfo; - } - vdp->vdd_vdtab = (struct vdlinkage *) & vd; - - { - int i; - - for (i=0; i<NCHU; i++) - our_priv_data[i].in_use=0; - } - - return 0; - case VDUNLOAD: - { - int dev; - - for (dev = 0; dev < NCHU; dev++) - if (our_priv_data[dev].in_use) { - /* One of the modules is still open */ - return (EBUSY); - } - } - chu_fmod->f_name[0] = '\0'; - chu_fmod->f_str = NULL; - return 0; - case VDSTAT: - return 0; - default: - return EIO; - } -} - -# endif /* sun */ - -#endif /* LOADABLE */ - -#if !defined(LOADABLE) && !defined(SOLARIS2) - -char chu_first_open=1; - -#endif - -/*ARGSUSED*/ -static int chuopen(q, dev, flag, sflag) -queue_t *q; -dev_t dev; -int flag; -int sflag; -{ - int i; - -#if !defined(LOADABLE) && !defined(SOLARIS2) - if (chu_first_open) - { - chu_first_open=0; - - for(i=0;i<NCHU;i++) - our_priv_data[i].in_use=0; - } -#endif - -#ifdef SOLARIS2 - /* According to the docs, calling with KM_SLEEP can never - fail */ - - q->q_ptr = kmem_alloc( sizeof(struct priv_data), KM_SLEEP ); - ((struct priv_data *) q->q_ptr)->chu_struct.ncodechars = 0; - - mutex_init(&((struct priv_data *) q->q_ptr)->chucode_mutex,"Chucode Mutex",MUTEX_DRIVER,NULL); - qprocson(q); - - if (!putnextctl1(WR(q), M_CTL, MC_SERVICEIMM)) - { - qprocsoff(q); - mutex_destroy(&((struct priv_data *)q->q_ptr)->chucode_mutex); - kmem_free(q->q_ptr, sizeof(struct chucode) ); - return (EFAULT); - } - - return 0; - -#else - for(i=0;i<NCHU;i++) - if (!our_priv_data[i].in_use) - { - ((struct priv_data *) (q->q_ptr))=&(our_priv_data[i]); - our_priv_data[i].in_use++; - our_priv_data[i].chu_struct.ncodechars = 0; - if (!putctl1(WR(q)->q_next, M_CTL, MC_SERVICEIMM)) - { - our_priv_data[i].in_use=0; - u.u_error = EFAULT; - return (OPENFAIL); - } - return 0; - } - - u.u_error = EBUSY; - return (OPENFAIL); -#endif - -} - -/*ARGSUSED*/ -static int chuclose(q, flag) -queue_t *q; -int flag; -{ -#ifdef SOLARIS2 - qprocsoff(q); - mutex_destroy(&((struct priv_data *)q->q_ptr)->chucode_mutex); - kmem_free(q->q_ptr, sizeof(struct chucode) ); -#else - ((struct priv_data *) (q->q_ptr))->in_use=0; -#endif - return (0); -} - -/* - * Now the crux of the biscuit. - * - * We will be passed data from the man downstairs. If it's not a data - * packet, it must be important, so pass it along unmunged. If, however, - * it is a data packet, we're gonna do special stuff to it. We're going - * to pass each character we get to the old line discipline code we - * include below for just such an occasion. When the old ldisc code - * gets a full chucode struct, we'll hand it back upstairs. - * - * chuinput takes a single character and q (as quickly as possible). - * passback takes a pointer to a chucode struct and q and sends it upstream. - */ - -void chuinput(); -void passback(); - -static int churput(q, mp) -queue_t *q; -mblk_t *mp; -{ - mblk_t *bp; - - switch(mp->b_datap->db_type) - { - case M_DATA: - for(bp=mp; bp!=NULL; bp=bp->b_cont) - { - while(bp->b_rptr < bp->b_wptr) - chuinput( ((u_char)*(bp->b_rptr++)) , q ); - } - freemsg(mp); - break; - default: - putnext(q,mp); - break; - } - -} - -/* - * Writing to a chu device doesn't make sense, but we'll pass them - * through in case they're important. - */ - -static int chuwput(q, mp) -queue_t *q; -mblk_t *mp; -{ - putnext(q,mp); -} - -/* - * Take a pointer to a filled chucode struct and a queue and - * send the chucode stuff upstream - */ - -void passback(outdata,q) -struct chucode *outdata; -queue_t *q; -{ - mblk_t *mp; - int j; - - mp=(mblk_t*) allocb(sizeof(struct chucode),BPRI_LO); - - if (mp==NULL) - { -#ifdef SOLARIS2 - cmn_err(CE_WARN,"chu module couldn't allocate message block"); -#else - log(LOG_ERR,"chu: cannot allocate message"); -#endif - return; - } - - for(j=0;j<sizeof(struct chucode); j++) - *mp->b_wptr++ = *( ((char*)outdata) + j ); - - putnext(q,mp); -} - -/* - * This routine was copied nearly verbatim from the old line discipline. - */ -void chuinput(c,q) -register u_char c; -queue_t *q; -{ - register struct chucode *chuc; - register int i; - long sec, usec; - struct timeval tv; - - /* - * Quick, Batman, get a timestamp! We need to do this - * right away. The time between the end of the stop bit - * and this point is critical, and should be as nearly - * constant and as short as possible. (Un)fortunately, - * the Sun's clock granularity is so big this isn't a - * major problem. - * - * uniqtime() is totally undocumented, but there you are. - */ - uniqtime(&tv); - -#ifdef SOLARIS2 - mutex_enter(&((struct priv_data *)q->q_ptr)->chucode_mutex); -#endif - - /* - * Now, locate the chu struct once so we don't have to do it - * over and over. - */ - chuc=&(((struct priv_data *) (q->q_ptr))->chu_struct); - - /* - * Compute the difference in this character's time stamp - * and the last. If it exceeds the margin, blow away all - * the characters currently in the buffer. - */ - i = (int)chuc->ncodechars; - if (i > 0) - { - sec = tv.tv_sec - chuc->codetimes[i-1].tv_sec; - usec = tv.tv_usec - chuc->codetimes[i-1].tv_usec; - if (usec < 0) - { - sec -= 1; - usec += 1000000; - } - if (sec != 0 || usec > CHUMAXUSEC) - { - i = 0; - chuc->ncodechars = 0; - } - } - - /* - * Store the character. - */ - chuc->codechars[i] = (u_char)c; - chuc->codetimes[i] = tv; - - /* - * Now we perform the 'sixth byte' heuristics. - * - * This is a long story. - * - * We used to be able to count on the first byte of the code - * having a '6' in the LSD. This prevented most code framing - * errors (garbage before the first byte wouldn't typically - * have a 6 in the LSD). That's no longer the case. - * - * We can get around this, however, by noting that the 6th byte - * must be either equal to or one's complement of the first. - * If we get a sixth byte that ISN'T like that, then it may - * well be that the first byte is garbage. The right thing - * to do is to left-shift the whole buffer one count and - * continue to wait for the sixth byte. - */ - if (i == NCHUCHARS/2) - { - register u_char temp_byte; - - temp_byte=chuc->codechars[i] ^ chuc->codechars[0]; - - if ( (temp_byte) && (temp_byte!=0xff) ) - { - register int t; - /* - * No match. Left-shift the buffer and try again - */ - for(t=0;t<=NCHUCHARS/2;t++) - { - chuc->codechars[t]=chuc->codechars[t+1]; - chuc->codetimes[t]=chuc->codetimes[t+1]; - } - - i--; /* This is because of the ++i immediately following */ - } - } - - /* - * We done yet? - */ - if (++i < NCHUCHARS) - { - /* - * We're not done. Not much to do here. Save the count and wait - * for another character. - */ - chuc->ncodechars = (u_char)i; - } - else - { - /* - * We are done. Mark this buffer full and pass it along. - */ - chuc->ncodechars = NCHUCHARS; - - /* - * Now we have a choice. Either the front half and back half - * have to match, or be one's complement of each other. - * - * So let's try the first byte and see - */ - - if(chuc->codechars[0] == chuc->codechars[NCHUCHARS/2]) - { - chuc->chutype = CHU_TIME; - for( i=0; i<(NCHUCHARS/2); i++) - if (chuc->codechars[i] != chuc->codechars[i+(NCHUCHARS/2)]) - { - chuc->ncodechars = 0; -#ifdef SOLARIS2 - mutex_exit(&((struct priv_data *)q->q_ptr)->chucode_mutex); -#endif - return; - } - } - else - { - chuc->chutype = CHU_YEAR; - for( i=0; i<(NCHUCHARS/2); i++) - if (((chuc->codechars[i] ^ chuc->codechars[i+(NCHUCHARS/2)]) & 0xff) - != 0xff ) - { - chuc->ncodechars = 0; -#ifdef SOLARIS2 - mutex_exit(&((struct priv_data *)q->q_ptr)->chucode_mutex); -#endif - return; - } - } - - passback(chuc,q); /* We're done! */ - chuc->ncodechars = 0; /* Start all over again! */ - } -#ifdef SOLARIS2 - mutex_exit(&((struct priv_data *)q->q_ptr)->chucode_mutex); -#endif -} - -#endif /* NCHU > 0 */ diff --git a/usr.sbin/xntpd/kernel/tty_clk.c b/usr.sbin/xntpd/kernel/tty_clk.c deleted file mode 100644 index 0720610..0000000 --- a/usr.sbin/xntpd/kernel/tty_clk.c +++ /dev/null @@ -1,317 +0,0 @@ -/* tty_clk.c,v 3.1 1993/07/06 01:07:33 jbj Exp - * tty_clk.c - Generic line driver for receiving radio clock timecodes - */ - -#include "clk.h" -#if NCLK > 0 - -#include "../h/param.h" -#include "../h/types.h" -#include "../h/systm.h" -#include "../h/dir.h" -#include "../h/user.h" -#include "../h/ioctl.h" -#include "../h/tty.h" -#include "../h/proc.h" -#include "../h/file.h" -#include "../h/conf.h" -#include "../h/buf.h" -#include "../h/uio.h" -#include "../h/clist.h" - -/* - * This line discipline is intended to provide well performing - * generic support for the reception and time stamping of radio clock - * timecodes. Most radio clock devices return a string where a - * particular character in the code (usually a \r) is on-time - * synchronized with the clock. The idea here is to collect characters - * until (one of) the synchronization character(s) (we allow two) is seen. - * When the magic character arrives we take a timestamp by calling - * microtime() and insert the eight bytes of struct timeval into the - * buffer after the magic character. We then wake up anyone waiting - * for the buffer and return the whole mess on the next read. - * - * To use this the calling program is expected to first open the - * port, and then to set the port into raw mode with the speed - * set appropriately with a TIOCSETP ioctl(), with the erase and kill - * characters set to those to be considered magic (yes, I know this - * is gross, but they were so convenient). If only one character is - * magic you can set then both the same, or perhaps to the alternate - * parity versions of said character. After getting all this set, - * change the line discipline to CLKLDISC and you are on your way. - * - * The only other bit of magic we do in here is to flush the receive - * buffers on writes if the CRMOD flag is set (hack, hack). - */ - -/* - * We run this very much like a raw mode terminal, with the exception - * that we store up characters locally until we hit one of the - * magic ones and then dump it into the rawq all at once. We keep - * the buffered data in clists since we can then often move it to - * the rawq without copying. For sanity we limit the number of - * characters between specials, and the total number of characters - * before we flush the rawq, as follows. - */ -#define CLKLINESIZE (256) -#define NCLKCHARS (CLKLINESIZE*4) - -struct clkdata { - int inuse; - struct clist clkbuf; -}; -#define clk_cc clkbuf.c_cc -#define clk_cf clkbuf.c_cf -#define clk_cl clkbuf.c_cl - -struct clkdata clk_data[NCLK]; - -/* - * Routine for flushing the internal clist - */ -#define clk_bflush(clk) (ndflush(&((clk)->clkbuf), (clk)->clk_cc)) - -int clk_debug = 0; - -/*ARGSUSED*/ -clkopen(dev, tp) - dev_t dev; - register struct tty *tp; -{ - register struct clkdata *clk; - - /* - * Don't allow multiple opens. This will also protect us - * from someone opening /dev/tty - */ - if (tp->t_line == CLKLDISC) - return (EBUSY); - ttywflush(tp); - for (clk = clk_data; clk < &clk_data[NCLK]; clk++) - if (!clk->inuse) - break; - if (clk >= &clk_data[NCLK]) - return (EBUSY); - clk->inuse++; - clk->clk_cc = 0; - clk->clk_cf = clk->clk_cl = NULL; - tp->T_LINEP = (caddr_t) clk; - return (0); -} - - -/* - * Break down... called when discipline changed or from device - * close routine. - */ -clkclose(tp) - register struct tty *tp; -{ - register struct clkdata *clk; - register int s = spltty(); - - clk = (struct clkdata *)tp->T_LINEP; - if (clk->clk_cc > 0) - clk_bflush(clk); - clk->inuse = 0; - tp->t_line = 0; /* paranoid: avoid races */ - splx(s); -} - - -/* - * Receive a write request. We pass these requests on to the terminal - * driver, except that if the CRMOD bit is set in the flags we - * first flush the input queues. - */ -clkwrite(tp, uio) - register struct tty *tp; - struct uio *uio; -{ - if (tp->t_flags & CRMOD) { - register struct clkdata *clk; - int s; - - s = spltty(); - if (tp->t_rawq.c_cc > 0) - ndflush(&tp->t_rawq, tp->t_rawq.c_cc); - clk = (struct clkdata *) tp->T_LINEP; - if (clk->clk_cc > 0) - clk_bflush(clk); - (void)splx(s); - } - ttwrite(tp, uio); -} - - -/* - * Low level character input routine. - * If the character looks okay, grab a time stamp. If the stuff in - * the buffer is too old, dump it and start fresh. If the character is - * non-BCDish, everything in the buffer too. - */ -clkinput(c, tp) - register int c; - register struct tty *tp; -{ - register struct clkdata *clk; - register int i; - register long s; - struct timeval tv; - - /* - * Check to see whether this isn't the magic character. If not, - * save the character and return. - */ -#ifdef ultrix - if (c != tp->t_cc[VERASE] && c != tp->t_cc[VKILL]) { -#else - if (c != tp->t_erase && c != tp->t_kill) { -#endif - clk = (struct clkdata *) tp->T_LINEP; - if (clk->clk_cc >= CLKLINESIZE) - clk_bflush(clk); - if (putc(c, &clk->clkbuf) == -1) { - /* - * Hopeless, no clists. Flush what we have - * and hope things improve. - */ - clk_bflush(clk); - } - return; - } - - /* - * Here we have a magic character. Get a timestamp and store - * everything. - */ - microtime(&tv); - clk = (struct clkdata *) tp->T_LINEP; - - if (putc(c, &clk->clkbuf) == -1) - goto flushout; - -#ifdef CLKLDISC - /* - * STREAMS people started writing timestamps this way. - * It's not my fault, I am just going along with the flow... - */ - for (i = 0; i < sizeof(struct timeval); i++) - if (putc(*( ((char*)&tv) + i ), &clk->clkbuf) == -1) - goto flushout; -#else - /* - * This is a machine independant way of puting longs into - * the datastream. It has fallen into disuse... - */ - s = tv.tv_sec; - for (i = 0; i < sizeof(long); i++) { - if (putc((s >> 24) & 0xff, &clk->clkbuf) == -1) - goto flushout; - s <<= 8; - } - - s = tv.tv_usec; - for (i = 0; i < sizeof(long); i++) { - if (putc((s >> 24) & 0xff, &clk->clkbuf) == -1) - goto flushout; - s <<= 8; - } -#endif - - /* - * If the length of the rawq exceeds our sanity limit, dump - * all the old crap in there before copying this in. - */ - if (tp->t_rawq.c_cc > NCLKCHARS) - ndflush(&tp->t_rawq, tp->t_rawq.c_cc); - - /* - * Now copy the buffer in. There is a special case optimization - * here. If there is nothing on the rawq at present we can - * just copy the clists we own over. Otherwise we must concatenate - * the present data on the end. - */ - s = (long)spltty(); - if (tp->t_rawq.c_cc <= 0) { - tp->t_rawq = clk->clkbuf; - clk->clk_cc = 0; - clk->clk_cl = clk->clk_cf = NULL; - (void) splx((int)s); - } else { - (void) splx((int)s); - catq(&clk->clkbuf, &tp->t_rawq); - clk_bflush(clk); - } - - /* - * Tell the world - */ - ttwakeup(tp); - return; - -flushout: - /* - * It would be nice if this never happened. Flush the - * internal clists and hope someone else frees some of them - */ - clk_bflush(clk); - return; -} - - -/* - * Handle ioctls. We reject most tty-style except those that - * change the line discipline and a couple of others.. - */ -clkioctl(tp, cmd, data, flag) - struct tty *tp; - int cmd; - caddr_t data; - int flag; -{ - int flags; - struct sgttyb *sg; - - if ((cmd>>8) != 't') - return (-1); - switch (cmd) { - case TIOCSETD: - case TIOCGETD: - case TIOCGETP: - case TIOCGETC: - case TIOCOUTQ: - return (-1); - - case TIOCSETP: - /* - * He likely wants to set new magic characters in. - * Do this part. - */ - sg = (struct sgttyb *)data; -#ifdef ultrix - tp->t_cc[VERASE] = sg->sg_erase; - tp->t_cc[VKILL] = sg->sg_kill; -#else - tp->t_erase = sg->sg_erase; - tp->t_kill = sg->sg_kill; -#endif - return (0); - - case TIOCFLUSH: - flags = *(int *)data; - if (flags == 0 || (flags & FREAD)) { - register struct clkdata *clk; - - clk = (struct clkdata *) tp->T_LINEP; - if (clk->clk_cc > 0) - clk_bflush(clk); - } - return (-1); - - default: - break; - } - return (ENOTTY); /* not quite appropriate */ -} -#endif NCLK diff --git a/usr.sbin/xntpd/kernel/tty_clk_STREAMS.c b/usr.sbin/xntpd/kernel/tty_clk_STREAMS.c deleted file mode 100644 index 13b0a25..0000000 --- a/usr.sbin/xntpd/kernel/tty_clk_STREAMS.c +++ /dev/null @@ -1,266 +0,0 @@ -/* tty_clk_STREAMS.c,v 3.1 1993/07/06 01:07:34 jbj Exp - * Timestamp STREAMS module for SunOS 4.1 - * - * Copyright 1991, Nick Sayer - * - * Special thanks to Greg Onufer for his debug assists. - * - * Should be PUSHed directly on top of a serial I/O channel. - * For any character in a user-designated set, adds a kernel - * timestamp to that character. - * - * BUGS: - * - * Only so many characters can be timestamped. This number, however, - * is adjustable. - * - * The null character ($00) cannot be timestamped. - * - * The M_DATA messages passed upstream will not be the same - * size as when they arrive from downstream, even if no - * timestamp character is in the message. This, however, - * should not affect anything. - * - */ - -#include "clk.h" -#if NCLK > 0 -/* - * How big should the messages we pass upstream be? - */ -#define MESSAGE_SIZE 128 - -#include <string.h> -#include <sys/types.h> -#include <sys/stream.h> -#include <sys/param.h> -#include <sys/time.h> -#include <sys/kernel.h> -#include <sys/user.h> -#include <sys/errno.h> -#include <sys/syslog.h> - -#include <sys/clkdefs.h> - -static struct module_info rminfo = { 0, "clk", 0, INFPSZ, 0, 0 }; -static struct module_info wminfo = { 0, "clk", 0, INFPSZ, 0, 0 }; -static int clkopen(), clkrput(), clkwput(), clkclose(); - -static struct qinit rinit = { clkrput, NULL, clkopen, clkclose, NULL, - &rminfo, NULL }; - -static struct qinit winit = { clkwput, NULL, NULL, NULL, NULL, - &wminfo, NULL }; - -struct streamtab clkinfo = { &rinit, &winit, NULL, NULL }; - -struct priv_data_type -{ - char in_use; - char string[CLK_MAXSTRSIZE]; -} priv_data[NCLK]; - -char first_open=1; - -/* - * God only knows why, but linking with strchr() fails - * on my system, so here's a renamed copy. - */ - -u_char *str_chr(s,c) -u_char *s; -int c; -{ - while (*s) - if(*s++ == c) - return (s-1); - return NULL; -} - -/*ARGSUSED*/ -static int clkopen(q, dev, flag, sflag) -queue_t *q; -dev_t dev; -int flag; -int sflag; -{ - int i; - -/* Damn it! We can't even have the global data struct properly - initialized! So we have a mark to tell us to init the global - data on the first open */ - - if (first_open) - { - first_open=0; - - for(i=0;i<NCLK;i++) - priv_data[i].in_use=0; - } - - for(i=0;i<NCLK;i++) - if(!priv_data[i].in_use) - { - priv_data[i].in_use++; - ((struct priv_data_type *) (q->q_ptr))=priv_data+i; - priv_data[i].string[0]=0; - return (0); - } - u.u_error = EBUSY; - return (OPENFAIL); -} - -/*ARGSUSED*/ -static int clkclose(q, flag) -queue_t *q; -int flag; -{ - ((struct priv_data_type *) (q->q_ptr))->in_use=0; - - return (0); -} - -/* - * Now the crux of the biscuit. - * - * If it's an M_DATA package, we take each character and pass - * it to clkchar. - */ - -void clkchar(); - -static int clkrput(q, mp) -queue_t *q; -mblk_t *mp; -{ - mblk_t *bp; - - switch(mp->b_datap->db_type) - { - case M_DATA: - clkchar(0,q,2); - for(bp=mp; bp!=NULL; bp=bp->b_cont) - { - while(bp->b_rptr < bp->b_wptr) - clkchar( ((u_char)*(bp->b_rptr++)) , q , 0 ); - } - clkchar(0,q,1); - freemsg(mp); - break; - default: - putnext(q,mp); - break; - } - -} - -/* - * If it's a matching M_IOCTL, handle it. - */ - -static int clkwput(q, mp) -queue_t *q; -mblk_t *mp; -{ - struct iocblk *iocp; - - switch(mp->b_datap->db_type) - { - case M_IOCTL: - iocp=(struct iocblk*) mp->b_rptr; - if (iocp->ioc_cmd==CLK_SETSTR) - { - strncpy( ((struct priv_data_type *) (RD(q)->q_ptr))->string, - (char *) mp->b_cont->b_rptr,CLK_MAXSTRSIZE); - /* make sure it's null terminated */ - ((struct priv_data_type *) (RD(q)->q_ptr))->string[CLK_MAXSTRSIZE-1]=0; - mp->b_datap->db_type = M_IOCACK; - qreply(q,mp); - } - else - putnext(q,mp); - break; - default: - putnext(q,mp); - break; - } -} - -/* - * Now clkchar. It takes a character, a queue pointer and an action - * flag and depending on the flag either: - * - * 0 - adds the character to the current message. If there's a - * timestamp to be done, do that too. If the message is less than - * 8 chars from being full, link in a new one, and set it up for - * the next call. - * - * 1 - sends the whole mess to Valhala. - * - * 2 - set things up. - * - * Yeah, it's an ugly hack. Complaints may be filed with /dev/null. - */ - - -void clkchar(c,q,f) - register u_char c; - queue_t *q; - char f; -{ - static char error; - static mblk_t *message,*mp; - struct timeval tv; - -/* Get a timestamp ASAP! */ - uniqtime(&tv); - - switch(f) - { - case 1: - if (!error) - putnext(q,message); - break; - case 2: - mp=message= (mblk_t*) allocb(MESSAGE_SIZE,BPRI_LO); - error=(message==NULL); - if (error) - log(LOG_ERR,"clk: cannot allocate message - data lost"); - break; - case 0: - if (error) /* If we had an error, forget it. */ - return; - - *mp->b_wptr++=c; /* Put the char away first. - - /* If it's in the special string, append a struct timeval */ - - if (str_chr( ((struct priv_data_type *) (q->q_ptr))->string , - c )!=NULL) - { - int i; - - for (i=0;i<sizeof(struct timeval);i++) - *mp->b_wptr++= *( ((char*)&tv) + i ); - } - - /* If we don't have space for a complete struct timeval, and a - char, it's time for a new mp block */ - - if (((mp->b_wptr-mp->b_rptr)+sizeof(struct timeval)+2)>MESSAGE_SIZE) - { - mp->b_cont= (mblk_t*) allocb(MESSAGE_SIZE,BPRI_LO); - error=(mp->b_cont==NULL); - if (error) - { - log(LOG_ERR,"clk: cannot allocate message - data lost"); - freemsg(message); - } - mp=mp->b_cont; - } - - break; - } -} - -#endif |