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