1: /*
   2:  * Copyright (c) 1982, 1986 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	@(#)tty_bk.c	7.1 (Berkeley) 6/5/86
   7:  */
   8: 
   9: #include "bk.h"
  10: 
  11: #if NBK > 0
  12: #include "param.h"
  13: #include "systm.h"
  14: #include "dir.h"
  15: #include "user.h"
  16: #include "ioctl.h"
  17: #include "tty.h"
  18: #include "proc.h"
  19: #include "inode.h"
  20: #include "file.h"
  21: #include "conf.h"
  22: #include "buf.h"
  23: #include "uio.h"
  24: 
  25: /*
  26:  * Line discipline for Berkeley network.
  27:  *
  28:  * This supplies single lines to a user level program
  29:  * with a minimum of fuss.  Lines are newline terminated.
  30:  *
  31:  * This discipline requires that tty device drivers call
  32:  * the line specific l_ioctl routine from their ioctl routines,
  33:  * assigning the result to cmd so that we can refuse most tty specific
  34:  * ioctls which are unsafe because we have ambushed the
  35:  * teletype input queues, overlaying them with other information.
  36:  */
  37: 
  38: /*
  39:  * Open as networked discipline.  Called when discipline changed
  40:  * with ioctl, this assigns a buffer to the line for input, and
  41:  * changing the interpretation of the information in the tty structure.
  42:  */
  43: /*ARGSUSED*/
  44: bkopen(dev, tp)
  45:     dev_t dev;
  46:     register struct tty *tp;
  47: {
  48:     register struct buf *bp;
  49: 
  50:     if (tp->t_line == NETLDISC)
  51:         return (EBUSY); /* sometimes the network opens /dev/tty */
  52:     bp = geteblk(1024);
  53:     ttyflush(tp, FREAD|FWRITE);
  54:     tp->t_bufp = bp;
  55:     tp->t_cp = (char *)bp->b_un.b_addr;
  56:     tp->t_inbuf = 0;
  57:     tp->t_rec = 0;
  58:     return (0);
  59: }
  60: 
  61: /*
  62:  * Break down... called when discipline changed or from device
  63:  * close routine.
  64:  */
  65: bkclose(tp)
  66:     register struct tty *tp;
  67: {
  68:     register int s;
  69: 
  70:     s = spl5();
  71:     wakeup((caddr_t)&tp->t_rawq);
  72:     if (tp->t_bufp) {
  73:         brelse(tp->t_bufp);
  74:         tp->t_bufp = 0;
  75:     } else
  76:         printf("bkclose: no buf\n");
  77:     tp->t_cp = 0;
  78:     tp->t_inbuf = 0;
  79:     tp->t_rec = 0;
  80:     tp->t_line = 0;     /* paranoid: avoid races */
  81:     splx(s);
  82: }
  83: 
  84: /*
  85:  * Read from a network line.
  86:  * Characters have been buffered in a system buffer and are
  87:  * now dumped back to the user in one fell swoop, and with a
  88:  * minimum of fuss.  Note that no input is accepted when a record
  89:  * is waiting.  Our clearing tp->t_rec here allows further input
  90:  * to accumulate.
  91:  */
  92: bkread(tp, uio)
  93:     register struct tty *tp;
  94:     struct uio *uio;
  95: {
  96:     register int s;
  97:     int error;
  98: 
  99:     if ((tp->t_state&TS_CARR_ON)==0)
 100:         return (-1);
 101:     s = spl5();
 102:     while (tp->t_rec == 0 && tp->t_line == NETLDISC)
 103:         sleep((caddr_t)&tp->t_rawq, TTIPRI);
 104:     splx(s);
 105:     if (tp->t_line != NETLDISC)
 106:         return (-1);
 107:     error = uiomove(tp->t_bufp->b_un.b_addr, tp->t_inbuf, UIO_READ, uio);
 108:     tp->t_cp = (char *)tp->t_bufp->b_un.b_addr;
 109:     tp->t_inbuf = 0;
 110:     tp->t_rec = 0;
 111:     return (error);
 112: }
 113: 
 114: /*
 115:  * Low level character input routine.
 116:  * Stuff the character in the buffer, and wake up the top
 117:  * half after setting t_rec if this completes the record
 118:  * or if the buffer is (ick!) full.
 119:  *
 120:  * Thisis where the formatting should get done to allow
 121:  * 8 character data paths through escapes.
 122:  *
 123:  * This rutine should be expanded in-line in the receiver
 124:  * interrupt routine of the dh-11 to make it run as fast as possible.
 125:  */
 126: bkinput(c, tp)
 127: register c;
 128: register struct tty *tp;
 129: {
 130: 
 131:     if (tp->t_rec)
 132:         return;
 133:     *tp->t_cp++ = c;
 134:     if (++tp->t_inbuf == 1024 || c == '\n') {
 135:         tp->t_rec = 1;
 136:         wakeup((caddr_t)&tp->t_rawq);
 137:     }
 138: }
 139: 
 140: /*
 141:  * This routine is called whenever a ioctl is about to be performed
 142:  * and gets a chance to reject the ioctl.  We reject all teletype
 143:  * oriented ioctl's except those which set the discipline, and
 144:  * those which get parameters (gtty and get special characters).
 145:  */
 146: /*ARGSUSED*/
 147: bkioctl(tp, cmd, data, flag)
 148:     struct tty *tp;
 149:     caddr_t data;
 150: {
 151: 
 152:     if ((cmd>>8) != 't')
 153:         return (-1);
 154:     switch (cmd) {
 155: 
 156:     case TIOCSETD:
 157:     case TIOCGETD:
 158:     case TIOCGETP:
 159:     case TIOCGETC:
 160:         return (-1);
 161:     }
 162:     return (ENOTTY);
 163: }
 164: #endif

Defined functions

bkclose defined in line 65; used 2 times
bkinput defined in line 126; used 2 times
bkioctl defined in line 147; used 2 times
bkopen defined in line 44; used 2 times
bkread defined in line 92; used 2 times
Last modified: 1986-06-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 936
Valid CSS Valid XHTML 1.0 Strict