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