add SO_TYPE option (get only!), correct mbuf lengths
[unix-history] / usr / src / sys / kern / tty_bk.c
CommitLineData
da7c5cc6
KM
1/*
2 * Copyright (c) 1982 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 6.3 (Berkeley) %G%
7 */
f2d9204a
BJ
8
9#include "bk.h"
10
11#if NBK > 0
94368568
JB
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"
f2d9204a
BJ
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*/
44bkopen(dev, tp)
942f05a9
SL
45 dev_t dev;
46 register struct tty *tp;
f2d9204a
BJ
47{
48 register struct buf *bp;
49
e5c9c00b
BJ
50 if (tp->t_line == NETLDISC)
51 return (EBUSY); /* sometimes the network opens /dev/tty */
f2d9204a 52 bp = geteblk(1024);
88a7a62a 53 ttyflush(tp, FREAD|FWRITE);
f2d9204a
BJ
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;
e5c9c00b 58 return (0);
f2d9204a
BJ
59}
60
61/*
62 * Break down... called when discipline changed or from device
63 * close routine.
64 */
65bkclose(tp)
e5c9c00b 66 register struct tty *tp;
f2d9204a 67{
e5c9c00b 68 register int s;
f2d9204a
BJ
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 */
740e4029
BJ
92bkread(tp, uio)
93 register struct tty *tp;
94 struct uio *uio;
f2d9204a 95{
a8d3bf7f 96 register int s;
840510a3 97 int error;
f2d9204a
BJ
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);
840510a3 107 error = uiomove(tp->t_bufp->b_un.b_addr, tp->t_inbuf, UIO_READ, uio);
f2d9204a
BJ
108 tp->t_cp = (char *)tp->t_bufp->b_un.b_addr;
109 tp->t_inbuf = 0;
110 tp->t_rec = 0;
840510a3 111 return (error);
f2d9204a
BJ
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 */
126bkinput(c, tp)
127register c;
128register 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*/
942f05a9
SL
147bkioctl(tp, cmd, data, flag)
148 struct tty *tp;
149 caddr_t data;
f2d9204a
BJ
150{
151
152 if ((cmd>>8) != 't')
e5c9c00b 153 return (-1);
f2d9204a
BJ
154 switch (cmd) {
155
156 case TIOCSETD:
157 case TIOCGETD:
158 case TIOCGETP:
159 case TIOCGETC:
e5c9c00b 160 return (-1);
f2d9204a 161 }
e5c9c00b 162 return (ENOTTY);
f2d9204a
BJ
163}
164#endif