1 /*- 2 * Copyright (c) 1982, 1986, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)tty_conf.c 8.4 (Berkeley) 1/21/94 39 * $FreeBSD: src/sys/kern/tty_conf.c,v 1.16.2.1 2002/03/11 01:14:55 dd Exp $ 40 * $DragonFly: src/sys/kern/tty_conf.c,v 1.3 2003/06/23 17:55:41 dillon Exp $ 41 */ 42 43 #include "opt_compat.h" 44 45 #include <sys/param.h> 46 #include <sys/systm.h> 47 #include <sys/tty.h> 48 #include <sys/conf.h> 49 50 #ifndef MAXLDISC 51 #define MAXLDISC 9 52 #endif 53 54 static l_open_t l_noopen; 55 static l_close_t l_noclose; 56 static l_rint_t l_norint; 57 static l_start_t l_nostart; 58 59 /* 60 * XXX it probably doesn't matter what the entries other than the l_open 61 * entry are here. The l_nullioctl and ttymodem entries still look fishy. 62 * Reconsider the removal of nullmodem anyway. It was too much like 63 * ttymodem, but a completely null version might be useful. 64 */ 65 #define NODISC(n) \ 66 { l_noopen, l_noclose, l_noread, l_nowrite, \ 67 l_nullioctl, l_norint, l_nostart, ttymodem } 68 69 struct linesw linesw[MAXLDISC] = 70 { 71 /* 0- termios */ 72 { ttyopen, ttylclose, ttread, ttwrite, 73 l_nullioctl, ttyinput, ttstart, ttymodem }, 74 NODISC(1), /* 1- defunct */ 75 /* 2- NTTYDISC */ 76 #ifdef COMPAT_43 77 { ttyopen, ttylclose, ttread, ttwrite, 78 l_nullioctl, ttyinput, ttstart, ttymodem }, 79 #else 80 NODISC(2), 81 #endif 82 NODISC(3), /* loadable */ 83 NODISC(4), /* SLIPDISC */ 84 NODISC(5), /* PPPDISC */ 85 NODISC(6), /* NETGRAPHDISC */ 86 NODISC(7), /* loadable */ 87 NODISC(8), /* loadable */ 88 }; 89 90 int nlinesw = sizeof (linesw) / sizeof (linesw[0]); 91 92 static struct linesw nodisc = NODISC(0); 93 94 #define LOADABLE_LDISC 7 95 /* 96 * ldisc_register: Register a line discipline. 97 * 98 * discipline: Index for discipline to load, or LDISC_LOAD for us to choose. 99 * linesw_p: Pointer to linesw_p. 100 * 101 * Returns: Index used or -1 on failure. 102 */ 103 int 104 ldisc_register(discipline, linesw_p) 105 int discipline; 106 struct linesw *linesw_p; 107 { 108 int slot = -1; 109 110 if (discipline == LDISC_LOAD) { 111 int i; 112 for (i = LOADABLE_LDISC; i < MAXLDISC; i++) 113 if (bcmp(linesw + i, &nodisc, sizeof(nodisc)) == 0) { 114 slot = i; 115 } 116 } 117 else if (discipline >= 0 && discipline < MAXLDISC) { 118 slot = discipline; 119 } 120 121 if (slot != -1 && linesw_p) 122 linesw[slot] = *linesw_p; 123 124 return slot; 125 } 126 127 /* 128 * ldisc_deregister: Deregister a line discipline obtained with 129 * ldisc_register. 130 * 131 * discipline: Index for discipline to unload. 132 */ 133 void 134 ldisc_deregister(discipline) 135 int discipline; 136 { 137 if (discipline < MAXLDISC) { 138 linesw[discipline] = nodisc; 139 } 140 } 141 142 static int 143 l_noopen(dev, tp) 144 dev_t dev; 145 struct tty *tp; 146 { 147 148 return (ENODEV); 149 } 150 151 static int 152 l_noclose(tp, flag) 153 struct tty *tp; 154 int flag; 155 { 156 157 return (ENODEV); 158 } 159 160 int 161 l_noread(tp, uio, flag) 162 struct tty *tp; 163 struct uio *uio; 164 int flag; 165 { 166 167 return (ENODEV); 168 } 169 170 int 171 l_nowrite(tp, uio, flag) 172 struct tty *tp; 173 struct uio *uio; 174 int flag; 175 { 176 177 return (ENODEV); 178 } 179 180 static int 181 l_norint(c, tp) 182 int c; 183 struct tty *tp; 184 { 185 186 return (ENODEV); 187 } 188 189 static int 190 l_nostart(tp) 191 struct tty *tp; 192 { 193 194 return (ENODEV); 195 } 196 197 /* 198 * Do nothing specific version of line 199 * discipline specific ioctl command. 200 */ 201 int 202 l_nullioctl(tp, cmd, data, flags, td) 203 struct tty *tp; 204 u_long cmd; 205 char *data; 206 int flags; 207 struct thread *td; 208 { 209 210 return (ENOIOCTL); 211 } 212