1*7725Sroot /* tty_bk.c 4.3 82/08/13 */ 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" 16*7725Sroot #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 437385Sroot if (u.u_error) 447385Sroot return; /* paranoia */ 457385Sroot if (tp->t_line == NETLDISC) { 467385Sroot u.u_error = EBUSY; /* sometimes the network */ 477385Sroot return; /* ... opens /dev/tty */ 487385Sroot } 497385Sroot bp = geteblk(1024); 507385Sroot flushtty(tp, FREAD|FWRITE); 517385Sroot tp->t_bufp = bp; 527385Sroot tp->t_cp = (char *)bp->b_un.b_addr; 537385Sroot tp->t_inbuf = 0; 547385Sroot tp->t_rec = 0; 557385Sroot } 567385Sroot 577385Sroot /* 587385Sroot * Break down... called when discipline changed or from device 597385Sroot * close routine. 607385Sroot */ 617385Sroot bkclose(tp) 627385Sroot register struct tty *tp; 637385Sroot { 647385Sroot register s; 657385Sroot 667385Sroot s = spl5(); 677385Sroot wakeup((caddr_t)&tp->t_rawq); 687385Sroot if (tp->t_bufp) { 697385Sroot brelse(tp->t_bufp); 707385Sroot tp->t_bufp = 0; 717385Sroot } else 727385Sroot printf("bkclose: no buf\n"); 737385Sroot tp->t_cp = 0; 747385Sroot tp->t_inbuf = 0; 757385Sroot tp->t_rec = 0; 767385Sroot tp->t_line = 0; /* paranoid: avoid races */ 777385Sroot splx(s); 787385Sroot } 797385Sroot 807385Sroot /* 817385Sroot * Read from a network line. 827385Sroot * Characters have been buffered in a system buffer and are 837385Sroot * now dumped back to the user in one fell swoop, and with a 847385Sroot * minimum of fuss. Note that no input is accepted when a record 857385Sroot * is waiting. Our clearing tp->t_rec here allows further input 867385Sroot * to accumulate. 877385Sroot */ 88*7725Sroot bkread(tp, uio) 89*7725Sroot register struct tty *tp; 90*7725Sroot struct uio *uio; 917385Sroot { 927385Sroot register int i; 937385Sroot register s; 947385Sroot 957385Sroot if ((tp->t_state&TS_CARR_ON)==0) 967385Sroot return (-1); 977385Sroot s = spl5(); 987385Sroot while (tp->t_rec == 0 && tp->t_line == NETLDISC) 997385Sroot sleep((caddr_t)&tp->t_rawq, TTIPRI); 1007385Sroot splx(s); 1017385Sroot if (tp->t_line != NETLDISC) 1027385Sroot return (-1); 103*7725Sroot u.u_error = copyuout(uio, tp->t_bufp->b_un.b_addr, tp->t_inbuf); 1047385Sroot tp->t_cp = (char *)tp->t_bufp->b_un.b_addr; 1057385Sroot tp->t_inbuf = 0; 1067385Sroot tp->t_rec = 0; 1077385Sroot return (0); 1087385Sroot } 1097385Sroot 1107385Sroot /* 1117385Sroot * Low level character input routine. 1127385Sroot * Stuff the character in the buffer, and wake up the top 1137385Sroot * half after setting t_rec if this completes the record 1147385Sroot * or if the buffer is (ick!) full. 1157385Sroot * 1167385Sroot * Thisis where the formatting should get done to allow 1177385Sroot * 8 character data paths through escapes. 1187385Sroot * 1197385Sroot * This rutine should be expanded in-line in the receiver 1207385Sroot * interrupt routine of the dh-11 to make it run as fast as possible. 1217385Sroot */ 1227385Sroot bkinput(c, tp) 1237385Sroot register c; 1247385Sroot register struct tty *tp; 1257385Sroot { 1267385Sroot 1277385Sroot if (tp->t_rec) 1287385Sroot return; 1297385Sroot *tp->t_cp++ = c; 1307385Sroot if (++tp->t_inbuf == 1024 || c == '\n') { 1317385Sroot tp->t_rec = 1; 1327385Sroot wakeup((caddr_t)&tp->t_rawq); 1337385Sroot } 1347385Sroot } 1357385Sroot 1367385Sroot /* 1377385Sroot * This routine is called whenever a ioctl is about to be performed 1387385Sroot * and gets a chance to reject the ioctl. We reject all teletype 1397385Sroot * oriented ioctl's except those which set the discipline, and 1407385Sroot * those which get parameters (gtty and get special characters). 1417385Sroot */ 1427385Sroot /*ARGSUSED*/ 1437629Ssam bkioctl(tp, cmd, data, flag) 1447629Ssam struct tty *tp; 1457629Ssam caddr_t data; 1467385Sroot { 1477385Sroot 1487385Sroot if ((cmd>>8) != 't') 1497385Sroot return (cmd); 1507385Sroot switch (cmd) { 1517385Sroot 1527385Sroot case TIOCSETD: 1537385Sroot case TIOCGETD: 1547385Sroot case TIOCGETP: 1557385Sroot case TIOCGETC: 1567385Sroot return (cmd); 1577385Sroot } 1587385Sroot u.u_error = ENOTTY; 1597385Sroot return (0); 1607385Sroot } 1617385Sroot #endif 162