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