tty_conf.c revision 1.37 1 1.37 christos /* $NetBSD: tty_conf.c,v 1.37 2002/02/08 18:36:53 christos Exp $ */
2 1.14 cgd
3 1.10 cgd /*-
4 1.10 cgd * Copyright (c) 1982, 1986, 1991, 1993
5 1.10 cgd * The Regents of the University of California. All rights reserved.
6 1.10 cgd * (c) UNIX System Laboratories, Inc.
7 1.10 cgd * All or some portions of this file are derived from material licensed
8 1.10 cgd * to the University of California by American Telephone and Telegraph
9 1.10 cgd * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 1.10 cgd * the permission of UNIX System Laboratories, Inc.
11 1.10 cgd *
12 1.10 cgd * Redistribution and use in source and binary forms, with or without
13 1.10 cgd * modification, are permitted provided that the following conditions
14 1.10 cgd * are met:
15 1.10 cgd * 1. Redistributions of source code must retain the above copyright
16 1.10 cgd * notice, this list of conditions and the following disclaimer.
17 1.10 cgd * 2. Redistributions in binary form must reproduce the above copyright
18 1.10 cgd * notice, this list of conditions and the following disclaimer in the
19 1.10 cgd * documentation and/or other materials provided with the distribution.
20 1.10 cgd * 3. All advertising materials mentioning features or use of this software
21 1.10 cgd * must display the following acknowledgement:
22 1.10 cgd * This product includes software developed by the University of
23 1.10 cgd * California, Berkeley and its contributors.
24 1.10 cgd * 4. Neither the name of the University nor the names of its contributors
25 1.10 cgd * may be used to endorse or promote products derived from this software
26 1.10 cgd * without specific prior written permission.
27 1.10 cgd *
28 1.10 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.10 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.10 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.10 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.10 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.10 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.10 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.10 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.10 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.10 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.10 cgd * SUCH DAMAGE.
39 1.10 cgd *
40 1.20 fvdl * @(#)tty_conf.c 8.5 (Berkeley) 1/9/95
41 1.10 cgd */
42 1.35 lukem
43 1.35 lukem #include <sys/cdefs.h>
44 1.37 christos __KERNEL_RCSID(0, "$NetBSD: tty_conf.c,v 1.37 2002/02/08 18:36:53 christos Exp $");
45 1.22 thorpej
46 1.22 thorpej #include "opt_compat_freebsd.h"
47 1.24 christos #include "opt_compat_43.h"
48 1.10 cgd
49 1.10 cgd #include <sys/param.h>
50 1.10 cgd #include <sys/systm.h>
51 1.10 cgd #include <sys/buf.h>
52 1.10 cgd #include <sys/ioctl.h>
53 1.10 cgd #include <sys/proc.h>
54 1.10 cgd #include <sys/tty.h>
55 1.28 eeh #include <sys/ioctl.h>
56 1.28 eeh #include <sys/ttycom.h>
57 1.10 cgd #include <sys/conf.h>
58 1.28 eeh #include <sys/malloc.h>
59 1.10 cgd
60 1.10 cgd #include "tb.h"
61 1.10 cgd #if NTB > 0
62 1.10 cgd int tbopen __P((dev_t dev, struct tty *tp));
63 1.10 cgd int tbclose __P((struct tty *tp, int flags));
64 1.10 cgd int tbread __P((struct tty *tp, struct uio *uio, int flags));
65 1.15 cgd int tbtioctl __P((struct tty *tp, u_long cmd, caddr_t data,
66 1.10 cgd int flag, struct proc *p));
67 1.10 cgd int tbinput __P((int c, struct tty *tp));
68 1.10 cgd #endif
69 1.10 cgd
70 1.10 cgd #include "sl.h"
71 1.10 cgd #if NSL > 0
72 1.10 cgd int slopen __P((dev_t dev, struct tty *tp));
73 1.10 cgd int slclose __P((struct tty *tp, int flags));
74 1.15 cgd int sltioctl __P((struct tty *tp, u_long cmd, caddr_t data,
75 1.10 cgd int flag, struct proc *p));
76 1.10 cgd int slinput __P((int c, struct tty *tp));
77 1.10 cgd int slstart __P((struct tty *tp));
78 1.10 cgd #endif
79 1.10 cgd
80 1.10 cgd #include "ppp.h"
81 1.10 cgd #if NPPP > 0
82 1.10 cgd int pppopen __P((dev_t dev, struct tty *tp));
83 1.10 cgd int pppclose __P((struct tty *tp, int flags));
84 1.15 cgd int ppptioctl __P((struct tty *tp, u_long cmd, caddr_t data,
85 1.10 cgd int flag, struct proc *p));
86 1.13 paulus int pppinput __P((int c, struct tty *tp));
87 1.13 paulus int pppstart __P((struct tty *tp));
88 1.10 cgd int pppread __P((struct tty *tp, struct uio *uio, int flag));
89 1.10 cgd int pppwrite __P((struct tty *tp, struct uio *uio, int flag));
90 1.10 cgd #endif
91 1.10 cgd
92 1.18 jonathan #include "strip.h"
93 1.18 jonathan #if NSTRIP > 0
94 1.18 jonathan int stripopen __P((dev_t dev, struct tty *tp));
95 1.18 jonathan int stripclose __P((struct tty *tp, int flags));
96 1.18 jonathan int striptioctl __P((struct tty *tp, u_long cmd, caddr_t data,
97 1.18 jonathan int flag, struct proc *p));
98 1.18 jonathan int stripinput __P((int c, struct tty *tp));
99 1.18 jonathan int stripstart __P((struct tty *tp));
100 1.18 jonathan #endif
101 1.18 jonathan
102 1.36 augustss #include "irframetty.h"
103 1.36 augustss #if NIRFRAMETTY > 0
104 1.36 augustss int irframetopen __P((dev_t dev, struct tty *tp));
105 1.36 augustss int irframetclose __P((struct tty *tp, int flags));
106 1.36 augustss int irframetioctl __P((struct tty *tp, u_long cmd, caddr_t data,
107 1.36 augustss int flag, struct proc *p));
108 1.36 augustss int irframetinput __P((int c, struct tty *tp));
109 1.36 augustss int irframetstart __P((struct tty *tp));
110 1.36 augustss int irframetread __P((struct tty *tp, struct uio *uio, int flag));
111 1.36 augustss int irframetwrite __P((struct tty *tp, struct uio *uio, int flag));
112 1.36 augustss int irframetpoll __P((struct tty *tp, int events, struct proc *p));
113 1.36 augustss #endif
114 1.36 augustss
115 1.10 cgd
116 1.28 eeh struct linesw termios_disc =
117 1.36 augustss { "termios", TTYDISC, ttylopen, ttylclose, ttread, ttwrite, nullioctl,
118 1.32 scw ttyinput, ttstart, ttymodem, ttpoll }; /* 0- termios */
119 1.28 eeh struct linesw defunct_disc =
120 1.28 eeh { "defunct", 1, ttynodisc, ttyerrclose, ttyerrio, ttyerrio, nullioctl,
121 1.32 scw ttyerrinput, ttyerrstart, nullmodem, ttyerrpoll }; /* 1- defunct */
122 1.16 mycroft #if defined(COMPAT_43) || defined(COMPAT_FREEBSD)
123 1.28 eeh struct linesw ntty_disc =
124 1.28 eeh { "ntty", 2, ttylopen, ttylclose, ttread, ttwrite, nullioctl,
125 1.32 scw ttyinput, ttstart, ttymodem, ttpoll }; /* 2- old NTTYDISC */
126 1.12 mycroft #endif
127 1.10 cgd #if NTB > 0
128 1.28 eeh struct linesw table_disc =
129 1.36 augustss { "tablet", TABLDISC, tbopen, tbclose, tbread, ttyerrio, tbtioctl,
130 1.32 scw tbinput, ttstart, nullmodem, ttyerrpoll }; /* 3- TABLDISC */
131 1.10 cgd #endif
132 1.10 cgd #if NSL > 0
133 1.28 eeh struct linesw slip_disc =
134 1.36 augustss { "slip", SLIPDISC, slopen, slclose, ttyerrio, ttyerrio, sltioctl,
135 1.32 scw slinput, slstart, nullmodem, ttyerrpoll }; /* 4- SLIPDISC */
136 1.10 cgd #endif
137 1.10 cgd #if NPPP > 0
138 1.28 eeh struct linesw ppp_disc =
139 1.36 augustss { "ppp", PPPDISC, pppopen, pppclose, pppread, pppwrite, ppptioctl,
140 1.32 scw pppinput, pppstart, ttymodem, ttpoll }; /* 5- PPPDISC */
141 1.18 jonathan #endif
142 1.18 jonathan #if NSTRIP > 0
143 1.28 eeh struct linesw strip_disc =
144 1.36 augustss { "strip", STRIPDISC, stripopen, stripclose, ttyerrio, ttyerrio,
145 1.36 augustss striptioctl, stripinput, stripstart, nullmodem, ttyerrpoll };
146 1.36 augustss /* 6- STRIPDISC */
147 1.36 augustss #endif
148 1.36 augustss #if NIRFRAMETTY > 0
149 1.36 augustss struct linesw irframet_disc =
150 1.36 augustss { "irframe", IRFRAMEDISC, irframetopen, irframetclose, ttyerrio,
151 1.36 augustss ttyerrio, irframetioctl, irframetinput, irframetstart,
152 1.36 augustss ttymodem, ttyerrpoll }; /* 10- IRFRAMEDISC */
153 1.25 eeh #endif
154 1.25 eeh
155 1.25 eeh /*
156 1.28 eeh * Registered line disciplines. Don't use this
157 1.28 eeh * it will go away.
158 1.25 eeh */
159 1.28 eeh #define LSWITCHBRK 20
160 1.28 eeh struct linesw **linesw = NULL;
161 1.28 eeh int nlinesw = 0;
162 1.28 eeh int slinesw = 0;
163 1.10 cgd
164 1.10 cgd /*
165 1.10 cgd * Do nothing specific version of line
166 1.10 cgd * discipline specific ioctl command.
167 1.10 cgd */
168 1.10 cgd /*ARGSUSED*/
169 1.17 christos int
170 1.10 cgd nullioctl(tp, cmd, data, flags, p)
171 1.10 cgd struct tty *tp;
172 1.15 cgd u_long cmd;
173 1.10 cgd char *data;
174 1.10 cgd int flags;
175 1.10 cgd struct proc *p;
176 1.10 cgd {
177 1.10 cgd
178 1.10 cgd #ifdef lint
179 1.10 cgd tp = tp; data = data; flags = flags; p = p;
180 1.10 cgd #endif
181 1.10 cgd return (-1);
182 1.28 eeh }
183 1.28 eeh
184 1.28 eeh /*
185 1.28 eeh * Register a line discipline, optionally providing a
186 1.28 eeh * specific discipline number for compatibility, -1 allocates
187 1.28 eeh * a new one. Returns a discipline number, or -1 on
188 1.28 eeh * failure.
189 1.28 eeh */
190 1.28 eeh int
191 1.28 eeh ttyldisc_add(disc, no)
192 1.28 eeh struct linesw *disc;
193 1.28 eeh int no;
194 1.28 eeh {
195 1.28 eeh
196 1.28 eeh /* You are not allowed to exceed TTLINEDNAMELEN */
197 1.37 christos if (strlen(disc->l_name) >= TTLINEDNAMELEN)
198 1.28 eeh return (-1);
199 1.28 eeh
200 1.28 eeh /*
201 1.28 eeh * You are not allowed to specify a line switch
202 1.28 eeh * compatibility number greater than 10.
203 1.28 eeh */
204 1.28 eeh if (no > 10)
205 1.28 eeh return (-1);
206 1.28 eeh
207 1.28 eeh if (linesw == NULL)
208 1.28 eeh panic("adding uninitialized linesw");
209 1.32 scw
210 1.32 scw #ifdef DEBUG
211 1.32 scw /*
212 1.32 scw * XXX: For the benefit of LKMs
213 1.32 scw */
214 1.32 scw if (disc->l_poll == NULL)
215 1.32 scw panic("line discipline must now provide l_poll() entry point");
216 1.32 scw #endif
217 1.28 eeh
218 1.28 eeh if (no == -1) {
219 1.28 eeh /* Hunt for any slot */
220 1.28 eeh
221 1.29 enami for (no = slinesw; no-- > 0;)
222 1.29 enami if (linesw[no] == NULL)
223 1.29 enami break;
224 1.30 enami /* if no == -1 we should realloc linesw, but for now... */
225 1.30 enami if (no == -1)
226 1.30 enami return (-1);
227 1.28 eeh }
228 1.28 eeh
229 1.28 eeh /* Need a specific slot */
230 1.28 eeh if (linesw[no] != NULL)
231 1.28 eeh return (-1);
232 1.28 eeh
233 1.28 eeh linesw[no] = disc;
234 1.28 eeh disc->l_no = no;
235 1.28 eeh
236 1.28 eeh /* Define size of table */
237 1.28 eeh if (no >= nlinesw)
238 1.28 eeh nlinesw = no + 1;
239 1.28 eeh
240 1.28 eeh return (no);
241 1.28 eeh }
242 1.28 eeh
243 1.28 eeh /*
244 1.28 eeh * Remove a line discipline by its name. Returns the
245 1.28 eeh * discipline on success or NULL on failure.
246 1.28 eeh */
247 1.28 eeh struct linesw *
248 1.28 eeh ttyldisc_remove(name)
249 1.28 eeh char *name;
250 1.28 eeh {
251 1.28 eeh struct linesw *disc;
252 1.28 eeh int i;
253 1.28 eeh
254 1.28 eeh if (linesw == NULL)
255 1.28 eeh panic("removing uninitialized linesw");
256 1.28 eeh
257 1.29 enami for (i = 0; i < nlinesw; i++) {
258 1.28 eeh if (linesw[i] && (strcmp(name, linesw[i]->l_name) == 0)) {
259 1.28 eeh disc = linesw[i];
260 1.28 eeh linesw[i] = NULL;
261 1.28 eeh
262 1.28 eeh if (nlinesw == i + 1) {
263 1.28 eeh /* Need to fix up array sizing */
264 1.30 enami while (i-- > 0 && linesw[i] == NULL)
265 1.30 enami continue;
266 1.30 enami nlinesw = i + 1;
267 1.28 eeh }
268 1.28 eeh return (disc);
269 1.28 eeh }
270 1.28 eeh }
271 1.28 eeh return (NULL);
272 1.28 eeh }
273 1.28 eeh
274 1.28 eeh /*
275 1.28 eeh * Look up a line discipline by its name.
276 1.28 eeh */
277 1.28 eeh struct linesw *
278 1.28 eeh ttyldisc_lookup(name)
279 1.28 eeh char *name;
280 1.28 eeh {
281 1.28 eeh int i;
282 1.28 eeh
283 1.29 enami for (i = 0; i < nlinesw; i++)
284 1.28 eeh if (linesw[i] && (strcmp(name, linesw[i]->l_name) == 0))
285 1.28 eeh return (linesw[i]);
286 1.28 eeh return (NULL);
287 1.28 eeh }
288 1.28 eeh
289 1.28 eeh #define TTYLDISCINIT(s, v) \
290 1.28 eeh do { \
291 1.28 eeh if (ttyldisc_add(&(s), (v)) != (v)) \
292 1.33 kristerw panic("ttyldisc_init: " __STRING(s)); \
293 1.29 enami } while (0)
294 1.28 eeh
295 1.28 eeh /*
296 1.28 eeh * Register the basic line disciplines.
297 1.28 eeh */
298 1.28 eeh void
299 1.29 enami ttyldisc_init()
300 1.29 enami {
301 1.29 enami
302 1.28 eeh /* Only initialize once */
303 1.28 eeh if (linesw)
304 1.28 eeh return;
305 1.28 eeh
306 1.28 eeh slinesw = LSWITCHBRK;
307 1.28 eeh linesw = malloc(slinesw * sizeof(struct linesw *),
308 1.29 enami M_TTYS, M_WAITOK);
309 1.34 thorpej memset(linesw, 0, slinesw * sizeof(struct linesw *));
310 1.28 eeh
311 1.28 eeh TTYLDISCINIT(termios_disc, 0);
312 1.28 eeh /* Do we really need this one? */
313 1.28 eeh TTYLDISCINIT(defunct_disc, 1);
314 1.28 eeh
315 1.28 eeh /*
316 1.28 eeh * The following should really be moved to
317 1.28 eeh * initialization code for each module.
318 1.28 eeh */
319 1.28 eeh
320 1.28 eeh #if defined(COMPAT_43) || defined(COMPAT_FREEBSD)
321 1.28 eeh TTYLDISCINIT(ntty_disc, 2);
322 1.28 eeh #endif
323 1.28 eeh #if NTB > 0
324 1.28 eeh TTYLDISCINIT(table_disc, 3);
325 1.28 eeh #endif
326 1.28 eeh #if NSL > 0
327 1.28 eeh TTYLDISCINIT(slip_disc, 4);
328 1.28 eeh #endif
329 1.28 eeh #if NPPP > 0
330 1.28 eeh TTYLDISCINIT(ppp_disc, 5);
331 1.28 eeh #endif
332 1.28 eeh #if NSTRIP > 0
333 1.28 eeh TTYLDISCINIT(strip_disc, 6);
334 1.36 augustss #endif
335 1.36 augustss #if NIRFRAMETTY > 0
336 1.36 augustss ttyldisc_add(&irframet_disc, -1);
337 1.28 eeh #endif
338 1.10 cgd }
339