]> git.saurik.com Git - apple/xnu.git/blame - bsd/kern/tty_conf.c
xnu-792.18.15.tar.gz
[apple/xnu.git] / bsd / kern / tty_conf.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
8f6c56a5
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/* Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved */
29/*-
30 * Copyright (c) 1982, 1986, 1991, 1993
31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 * @(#)tty_conf.c 8.4 (Berkeley) 1/21/94
67 */
68
69#include <sys/param.h>
70#include <sys/systm.h>
71#include <sys/tty.h>
72#include <sys/conf.h>
73
74#ifndef MAXLDISC
75#define MAXLDISC 8
76#endif
77
78#ifndef NeXT
79static l_open_t l_noopen;
80static l_close_t l_noclose;
1c79356b 81static l_rint_t l_norint;
1c79356b 82#else /* NeXT */
91447636
A
83#define l_noopen ((l_open_t *) &enodev)
84#define l_noclose ((l_close_t *) &enodev)
85#define l_noread ((l_read_t *) &enodev)
86#define l_nowrite ((l_write_t *) &enodev)
87#define l_norint ((l_rint_t *) &enodev)
1c79356b
A
88#endif /* !NeXT */
89
91447636
A
90static l_ioctl_t l_noioctl;
91static l_start_t l_nostart;
92
1c79356b
A
93/*
94 * XXX it probably doesn't matter what the entries other than the l_open
91447636 95 * entry are here. The l_noioctl and ttymodem entries still look fishy.
1c79356b
A
96 * Reconsider the removal of nullmodem anyway. It was too much like
97 * ttymodem, but a completely null version might be useful.
98 */
99#define NODISC(n) \
100 { l_noopen, l_noclose, l_noread, l_nowrite, \
91447636 101 l_noioctl, l_norint, l_nostart, ttymodem }
1c79356b
A
102
103struct linesw linesw[MAXLDISC] =
104{
105 /* 0- termios */
106 { ttyopen, ttylclose, ttread, ttwrite,
91447636 107 l_noioctl, ttyinput, ttwwakeup, ttymodem },
1c79356b
A
108 NODISC(1), /* 1- defunct */
109 /* 2- NTTYDISC */
91447636 110#if COMPAT_43_TTY
1c79356b 111 { ttyopen, ttylclose, ttread, ttwrite,
91447636 112 l_noioctl, ttyinput, ttwwakeup, ttymodem },
1c79356b
A
113#else
114 NODISC(2),
115#endif
116 NODISC(3), /* TABLDISC */
117 NODISC(4), /* SLIPDISC */
118 NODISC(5), /* PPPDISC */
119 NODISC(6), /* loadable */
120 NODISC(7), /* loadable */
121};
122
123int nlinesw = sizeof (linesw) / sizeof (linesw[0]);
124
125static struct linesw nodisc = NODISC(0);
126
127#define LOADABLE_LDISC 6
128/*
129 * ldisc_register: Register a line discipline.
130 *
131 * discipline: Index for discipline to load, or LDISC_LOAD for us to choose.
132 * linesw_p: Pointer to linesw_p.
133 *
134 * Returns: Index used or -1 on failure.
135 */
136int
137ldisc_register(discipline, linesw_p)
138 int discipline;
139 struct linesw *linesw_p;
140{
141 int slot = -1;
142
143 if (discipline == LDISC_LOAD) {
144 int i;
145 for (i = LOADABLE_LDISC; i < MAXLDISC; i++)
146 if (bcmp(linesw + i, &nodisc, sizeof(nodisc)) == 0) {
147 slot = i;
148 }
149 }
150 else if (discipline >= 0 && discipline < MAXLDISC) {
151 slot = discipline;
152 }
153
154 if (slot != -1 && linesw_p)
155 linesw[slot] = *linesw_p;
156
157 return slot;
158}
159
160/*
161 * ldisc_deregister: Deregister a line discipline obtained with
162 * ldisc_register. Can only deregister "loadable" ones now.
163 *
164 * discipline: Index for discipline to unload.
165 */
166void
167ldisc_deregister(discipline)
168 int discipline;
169{
170 if (discipline >= LOADABLE_LDISC && discipline < MAXLDISC) {
171 linesw[discipline] = nodisc;
172 }
173}
174
175#ifndef NeXT
176static int
177l_noopen(dev, tp)
178 dev_t dev;
179 struct tty *tp;
180{
181
182 return (ENODEV);
183}
184
185static int
186l_noclose(tp, flag)
187 struct tty *tp;
188 int flag;
189{
190
191 return (ENODEV);
192}
193
194int
195l_noread(tp, uio, flag)
196 struct tty *tp;
197 struct uio *uio;
198 int flag;
199{
200
201 return (ENODEV);
202}
203
204int
205l_nowrite(tp, uio, flag)
206 struct tty *tp;
207 struct uio *uio;
208 int flag;
209{
210
211 return (ENODEV);
212}
213
214static int
215l_norint(c, tp)
216 int c;
217 struct tty *tp;
218{
219
220 return (ENODEV);
221}
1c79356b
A
222#endif /* !NeXT */
223
224/*
225 * Do nothing specific version of line
226 * discipline specific ioctl command.
227 */
228static int
91447636
A
229l_noioctl(__unused struct tty *tp, __unused u_long cmd, __unused caddr_t data,
230 __unused int flags, __unused struct proc *p)
1c79356b
A
231{
232
91447636 233 return ENOTTY;
1c79356b 234}
91447636
A
235
236static void
237l_nostart(__unused struct tty *tp)
238 { }