xref: /csrg-svn/sys/kern/tty_bk.c (revision 8590)
1*8590Sroot /*	tty_bk.c	4.7	82/10/17	*/
27385Sroot 
37385Sroot #include "bk.h"
47385Sroot 
57385Sroot #if NBK > 0
67385Sroot #include "../h/param.h"
77385Sroot #include "../h/systm.h"
87385Sroot #include "../h/dir.h"
97385Sroot #include "../h/user.h"
107385Sroot #include "../h/tty.h"
117385Sroot #include "../h/proc.h"
127385Sroot #include "../h/inode.h"
137385Sroot #include "../h/file.h"
147385Sroot #include "../h/conf.h"
157385Sroot #include "../h/buf.h"
167725Sroot #include "../h/uio.h"
177385Sroot 
187385Sroot /*
197385Sroot  * Line discipline for Berkeley network.
207385Sroot  *
217385Sroot  * This supplies single lines to a user level program
227385Sroot  * with a minimum of fuss.  Lines are newline terminated.
237385Sroot  *
247385Sroot  * This discipline requires that tty device drivers call
257385Sroot  * the line specific l_ioctl routine from their ioctl routines,
267385Sroot  * assigning the result to cmd so that we can refuse most tty specific
277385Sroot  * ioctls which are unsafe because we have ambushed the
287385Sroot  * teletype input queues, overlaying them with other information.
297385Sroot  */
307385Sroot 
317385Sroot /*
327385Sroot  * Open as networked discipline.  Called when discipline changed
337385Sroot  * with ioctl, this assigns a buffer to the line for input, and
347385Sroot  * changing the interpretation of the information in the tty structure.
357385Sroot  */
367385Sroot /*ARGSUSED*/
377385Sroot bkopen(dev, tp)
387629Ssam 	dev_t dev;
397629Ssam 	register struct tty *tp;
407385Sroot {
417385Sroot 	register struct buf *bp;
427385Sroot 
438561Sroot 	if (tp->t_line == NETLDISC)
448561Sroot 		return (EBUSY);	/* sometimes the network opens /dev/tty */
457385Sroot 	bp = geteblk(1024);
467385Sroot 	flushtty(tp, FREAD|FWRITE);
477385Sroot 	tp->t_bufp = bp;
487385Sroot 	tp->t_cp = (char *)bp->b_un.b_addr;
497385Sroot 	tp->t_inbuf = 0;
507385Sroot 	tp->t_rec = 0;
518561Sroot 	return (0);
527385Sroot }
537385Sroot 
547385Sroot /*
557385Sroot  * Break down... called when discipline changed or from device
567385Sroot  * close routine.
577385Sroot  */
587385Sroot bkclose(tp)
598561Sroot 	register struct tty *tp;
607385Sroot {
618561Sroot 	register int s;
627385Sroot 
637385Sroot 	s = spl5();
647385Sroot 	wakeup((caddr_t)&tp->t_rawq);
657385Sroot 	if (tp->t_bufp) {
667385Sroot 		brelse(tp->t_bufp);
677385Sroot 		tp->t_bufp = 0;
687385Sroot 	} else
697385Sroot 		printf("bkclose: no buf\n");
707385Sroot 	tp->t_cp = 0;
717385Sroot 	tp->t_inbuf = 0;
727385Sroot 	tp->t_rec = 0;
737385Sroot 	tp->t_line = 0;		/* paranoid: avoid races */
747385Sroot 	splx(s);
757385Sroot }
767385Sroot 
777385Sroot /*
787385Sroot  * Read from a network line.
797385Sroot  * Characters have been buffered in a system buffer and are
807385Sroot  * now dumped back to the user in one fell swoop, and with a
817385Sroot  * minimum of fuss.  Note that no input is accepted when a record
827385Sroot  * is waiting.  Our clearing tp->t_rec here allows further input
837385Sroot  * to accumulate.
847385Sroot  */
857725Sroot bkread(tp, uio)
867725Sroot 	register struct tty *tp;
877725Sroot 	struct uio *uio;
887385Sroot {
89*8590Sroot 	register int s;
908521Sroot 	int error;
917385Sroot 
927385Sroot 	if ((tp->t_state&TS_CARR_ON)==0)
937385Sroot 		return (-1);
947385Sroot 	s = spl5();
957385Sroot 	while (tp->t_rec == 0 && tp->t_line == NETLDISC)
967385Sroot 		sleep((caddr_t)&tp->t_rawq, TTIPRI);
977385Sroot 	splx(s);
987385Sroot 	if (tp->t_line != NETLDISC)
997385Sroot 		return (-1);
1008521Sroot 	error = uiomove(tp->t_bufp->b_un.b_addr, tp->t_inbuf, UIO_READ, uio);
1017385Sroot 	tp->t_cp = (char *)tp->t_bufp->b_un.b_addr;
1027385Sroot 	tp->t_inbuf = 0;
1037385Sroot 	tp->t_rec = 0;
1048521Sroot 	return (error);
1057385Sroot }
1067385Sroot 
1077385Sroot /*
1087385Sroot  * Low level character input routine.
1097385Sroot  * Stuff the character in the buffer, and wake up the top
1107385Sroot  * half after setting t_rec if this completes the record
1117385Sroot  * or if the buffer is (ick!) full.
1127385Sroot  *
1137385Sroot  * Thisis where the formatting should get done to allow
1147385Sroot  * 8 character data paths through escapes.
1157385Sroot  *
1167385Sroot  * This rutine should be expanded in-line in the receiver
1177385Sroot  * interrupt routine of the dh-11 to make it run as fast as possible.
1187385Sroot  */
1197385Sroot bkinput(c, tp)
1207385Sroot register c;
1217385Sroot register struct tty *tp;
1227385Sroot {
1237385Sroot 
1247385Sroot 	if (tp->t_rec)
1257385Sroot 		return;
1267385Sroot 	*tp->t_cp++ = c;
1277385Sroot 	if (++tp->t_inbuf == 1024 || c == '\n') {
1287385Sroot 		tp->t_rec = 1;
1297385Sroot 		wakeup((caddr_t)&tp->t_rawq);
1307385Sroot 	}
1317385Sroot }
1327385Sroot 
1337385Sroot /*
1347385Sroot  * This routine is called whenever a ioctl is about to be performed
1357385Sroot  * and gets a chance to reject the ioctl.  We reject all teletype
1367385Sroot  * oriented ioctl's except those which set the discipline, and
1377385Sroot  * those which get parameters (gtty and get special characters).
1387385Sroot  */
1397385Sroot /*ARGSUSED*/
1407629Ssam bkioctl(tp, cmd, data, flag)
1417629Ssam 	struct tty *tp;
1427629Ssam 	caddr_t data;
1437385Sroot {
1447385Sroot 
1457385Sroot 	if ((cmd>>8) != 't')
1468561Sroot 		return (-1);
1477385Sroot 	switch (cmd) {
1487385Sroot 
1497385Sroot 	case TIOCSETD:
1507385Sroot 	case TIOCGETD:
1517385Sroot 	case TIOCGETP:
1527385Sroot 	case TIOCGETC:
1538561Sroot 		return (-1);
1547385Sroot 	}
1558561Sroot 	return (ENOTTY);
1567385Sroot }
1577385Sroot #endif
158