Home | History | Annotate | Line # | Download | only in kern
tty_conf.c revision 1.24.8.4
      1  1.24.8.4    bouyer /*	$NetBSD: tty_conf.c,v 1.24.8.4 2001/02/11 19:16:49 bouyer 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.22   thorpej 
     43      1.22   thorpej #include "opt_compat_freebsd.h"
     44      1.24  christos #include "opt_compat_43.h"
     45      1.10       cgd 
     46      1.10       cgd #include <sys/param.h>
     47      1.10       cgd #include <sys/systm.h>
     48      1.10       cgd #include <sys/buf.h>
     49      1.10       cgd #include <sys/ioctl.h>
     50      1.10       cgd #include <sys/proc.h>
     51      1.10       cgd #include <sys/tty.h>
     52  1.24.8.2    bouyer #include <sys/ioctl.h>
     53  1.24.8.2    bouyer #include <sys/ttycom.h>
     54      1.10       cgd #include <sys/conf.h>
     55  1.24.8.2    bouyer #include <sys/malloc.h>
     56      1.10       cgd 
     57      1.10       cgd #include "tb.h"
     58      1.10       cgd #if NTB > 0
     59      1.10       cgd int	tbopen __P((dev_t dev, struct tty *tp));
     60      1.10       cgd int	tbclose __P((struct tty *tp, int flags));
     61      1.10       cgd int	tbread __P((struct tty *tp, struct uio *uio, int flags));
     62      1.15       cgd int	tbtioctl __P((struct tty *tp, u_long cmd, caddr_t data,
     63      1.10       cgd 			int flag, struct proc *p));
     64      1.10       cgd int	tbinput __P((int c, struct tty *tp));
     65      1.10       cgd #endif
     66      1.10       cgd 
     67      1.10       cgd #include "sl.h"
     68      1.10       cgd #if NSL > 0
     69      1.10       cgd int	slopen __P((dev_t dev, struct tty *tp));
     70      1.10       cgd int	slclose __P((struct tty *tp, int flags));
     71      1.15       cgd int	sltioctl __P((struct tty *tp, u_long cmd, caddr_t data,
     72      1.10       cgd 			int flag, struct proc *p));
     73      1.10       cgd int	slinput __P((int c, struct tty *tp));
     74      1.10       cgd int	slstart __P((struct tty *tp));
     75      1.10       cgd #endif
     76      1.10       cgd 
     77      1.10       cgd #include "ppp.h"
     78      1.10       cgd #if NPPP > 0
     79      1.10       cgd int	pppopen __P((dev_t dev, struct tty *tp));
     80      1.10       cgd int	pppclose __P((struct tty *tp, int flags));
     81      1.15       cgd int	ppptioctl __P((struct tty *tp, u_long cmd, caddr_t data,
     82      1.10       cgd 			int flag, struct proc *p));
     83      1.13    paulus int	pppinput __P((int c, struct tty *tp));
     84      1.13    paulus int	pppstart __P((struct tty *tp));
     85      1.10       cgd int	pppread __P((struct tty *tp, struct uio *uio, int flag));
     86      1.10       cgd int	pppwrite __P((struct tty *tp, struct uio *uio, int flag));
     87      1.10       cgd #endif
     88      1.10       cgd 
     89      1.18  jonathan #include "strip.h"
     90      1.18  jonathan #if NSTRIP > 0
     91      1.18  jonathan int	stripopen __P((dev_t dev, struct tty *tp));
     92      1.18  jonathan int	stripclose __P((struct tty *tp, int flags));
     93      1.18  jonathan int	striptioctl __P((struct tty *tp, u_long cmd, caddr_t data,
     94      1.18  jonathan 			int flag, struct proc *p));
     95      1.18  jonathan int	stripinput __P((int c, struct tty *tp));
     96      1.18  jonathan int	stripstart __P((struct tty *tp));
     97      1.18  jonathan #endif
     98      1.18  jonathan 
     99  1.24.8.3    bouyer 
    100  1.24.8.2    bouyer struct  linesw termios_disc =
    101  1.24.8.2    bouyer 	{ "termios", 0, ttylopen, ttylclose, ttread, ttwrite, nullioctl,
    102  1.24.8.2    bouyer 	  ttyinput, ttstart, ttymodem };		/* 0- termios */
    103  1.24.8.2    bouyer struct  linesw defunct_disc =
    104  1.24.8.2    bouyer 	{ "defunct", 1, ttynodisc, ttyerrclose, ttyerrio, ttyerrio, nullioctl,
    105  1.24.8.2    bouyer 	  ttyerrinput, ttyerrstart, nullmodem };	/* 1- defunct */
    106      1.16   mycroft #if defined(COMPAT_43) || defined(COMPAT_FREEBSD)
    107  1.24.8.2    bouyer struct  linesw ntty_disc =
    108  1.24.8.2    bouyer 	{ "ntty", 2, ttylopen, ttylclose, ttread, ttwrite, nullioctl,
    109  1.24.8.2    bouyer 	  ttyinput, ttstart, ttymodem };		/* 2- old NTTYDISC */
    110      1.12   mycroft #endif
    111      1.10       cgd #if NTB > 0
    112  1.24.8.2    bouyer struct  linesw table_disc =
    113  1.24.8.4    bouyer 	{ "tablet", 3, tbopen, tbclose, tbread, ttyerrio, tbtioctl,
    114  1.24.8.2    bouyer 	  tbinput, ttstart, nullmodem };		/* 3- TABLDISC */
    115      1.10       cgd #endif
    116      1.10       cgd #if NSL > 0
    117  1.24.8.2    bouyer struct  linesw slip_disc =
    118  1.24.8.2    bouyer 	{ "slip", 4, slopen, slclose, ttyerrio, ttyerrio, sltioctl,
    119  1.24.8.2    bouyer 	  slinput, slstart, nullmodem };		/* 4- SLIPDISC */
    120      1.10       cgd #endif
    121      1.10       cgd #if NPPP > 0
    122  1.24.8.2    bouyer struct  linesw ppp_disc =
    123  1.24.8.2    bouyer 	{ "ppp", 5, pppopen, pppclose, pppread, pppwrite, ppptioctl,
    124  1.24.8.2    bouyer 	  pppinput, pppstart, ttymodem };		/* 5- PPPDISC */
    125      1.18  jonathan #endif
    126      1.18  jonathan #if NSTRIP > 0
    127  1.24.8.2    bouyer struct  linesw strip_disc =
    128  1.24.8.2    bouyer 	{ "strip", 6, stripopen, stripclose, ttyerrio, ttyerrio, striptioctl,
    129  1.24.8.2    bouyer 	  stripinput, stripstart, nullmodem };		/* 6- STRIPDISC */
    130  1.24.8.1    bouyer #endif
    131  1.24.8.1    bouyer 
    132  1.24.8.1    bouyer /*
    133  1.24.8.2    bouyer  * Registered line disciplines.  Don't use this
    134  1.24.8.2    bouyer  * it will go away.
    135  1.24.8.1    bouyer  */
    136  1.24.8.2    bouyer #define LSWITCHBRK	20
    137  1.24.8.2    bouyer struct	linesw **linesw = NULL;
    138  1.24.8.2    bouyer int	nlinesw = 0;
    139  1.24.8.2    bouyer int	slinesw = 0;
    140      1.10       cgd 
    141      1.10       cgd /*
    142      1.10       cgd  * Do nothing specific version of line
    143      1.10       cgd  * discipline specific ioctl command.
    144      1.10       cgd  */
    145      1.10       cgd /*ARGSUSED*/
    146      1.17  christos int
    147      1.10       cgd nullioctl(tp, cmd, data, flags, p)
    148      1.10       cgd 	struct tty *tp;
    149      1.15       cgd 	u_long cmd;
    150      1.10       cgd 	char *data;
    151      1.10       cgd 	int flags;
    152      1.10       cgd 	struct proc *p;
    153      1.10       cgd {
    154      1.10       cgd 
    155      1.10       cgd #ifdef lint
    156      1.10       cgd 	tp = tp; data = data; flags = flags; p = p;
    157      1.10       cgd #endif
    158      1.10       cgd 	return (-1);
    159  1.24.8.2    bouyer }
    160  1.24.8.2    bouyer 
    161  1.24.8.2    bouyer /*
    162  1.24.8.2    bouyer  * Register a line discipline, optionally providing a
    163  1.24.8.2    bouyer  * specific discipline number for compatibility, -1 allocates
    164  1.24.8.2    bouyer  * a new one.  Returns a discipline number, or -1 on
    165  1.24.8.2    bouyer  * failure.
    166  1.24.8.2    bouyer  */
    167  1.24.8.2    bouyer int
    168  1.24.8.2    bouyer ttyldisc_add(disc, no)
    169  1.24.8.2    bouyer 	struct linesw *disc;
    170  1.24.8.2    bouyer 	int no;
    171  1.24.8.2    bouyer {
    172  1.24.8.2    bouyer 
    173  1.24.8.2    bouyer 	/* You are not allowed to exceed TTLINEDNAMELEN */
    174  1.24.8.2    bouyer 	if (strlen(disc->l_name) > TTLINEDNAMELEN)
    175  1.24.8.2    bouyer 		return (-1);
    176  1.24.8.2    bouyer 
    177  1.24.8.2    bouyer 	/*
    178  1.24.8.2    bouyer 	 * You are not allowed to specify a line switch
    179  1.24.8.2    bouyer 	 * compatibility number greater than 10.
    180  1.24.8.2    bouyer 	 */
    181  1.24.8.2    bouyer 	if (no > 10)
    182  1.24.8.2    bouyer 		return (-1);
    183  1.24.8.2    bouyer 
    184  1.24.8.2    bouyer 	if (linesw == NULL)
    185  1.24.8.2    bouyer 		panic("adding uninitialized linesw");
    186  1.24.8.2    bouyer 
    187  1.24.8.2    bouyer 	if (no == -1) {
    188  1.24.8.2    bouyer 		/* Hunt for any slot */
    189  1.24.8.2    bouyer 
    190  1.24.8.2    bouyer 		for (no = slinesw; no-- > 0;)
    191  1.24.8.2    bouyer 			if (linesw[no] == NULL)
    192  1.24.8.2    bouyer 				break;
    193  1.24.8.2    bouyer 		/* if no == -1 we should realloc linesw, but for now... */
    194  1.24.8.2    bouyer 		if (no == -1)
    195  1.24.8.2    bouyer 			return (-1);
    196  1.24.8.2    bouyer 	}
    197  1.24.8.2    bouyer 
    198  1.24.8.2    bouyer 	/* Need a specific slot */
    199  1.24.8.2    bouyer 	if (linesw[no] != NULL)
    200  1.24.8.2    bouyer 		return (-1);
    201  1.24.8.2    bouyer 
    202  1.24.8.2    bouyer 	linesw[no] = disc;
    203  1.24.8.2    bouyer 	disc->l_no = no;
    204  1.24.8.2    bouyer 
    205  1.24.8.2    bouyer 	/* Define size of table */
    206  1.24.8.2    bouyer 	if (no >= nlinesw)
    207  1.24.8.2    bouyer 		nlinesw = no + 1;
    208  1.24.8.2    bouyer 
    209  1.24.8.2    bouyer 	return (no);
    210  1.24.8.2    bouyer }
    211  1.24.8.2    bouyer 
    212  1.24.8.2    bouyer /*
    213  1.24.8.2    bouyer  * Remove a line discipline by its name.  Returns the
    214  1.24.8.2    bouyer  * discipline on success or NULL on failure.
    215  1.24.8.2    bouyer  */
    216  1.24.8.2    bouyer struct linesw *
    217  1.24.8.2    bouyer ttyldisc_remove(name)
    218  1.24.8.2    bouyer 	char *name;
    219  1.24.8.2    bouyer {
    220  1.24.8.2    bouyer 	struct linesw *disc;
    221  1.24.8.2    bouyer 	int i;
    222  1.24.8.2    bouyer 
    223  1.24.8.2    bouyer 	if (linesw == NULL)
    224  1.24.8.2    bouyer 		panic("removing uninitialized linesw");
    225  1.24.8.2    bouyer 
    226  1.24.8.2    bouyer 	for (i = 0; i < nlinesw; i++) {
    227  1.24.8.2    bouyer 		if (linesw[i] && (strcmp(name, linesw[i]->l_name) == 0)) {
    228  1.24.8.2    bouyer 			disc = linesw[i];
    229  1.24.8.2    bouyer 			linesw[i] = NULL;
    230  1.24.8.2    bouyer 
    231  1.24.8.2    bouyer 			if (nlinesw == i + 1) {
    232  1.24.8.2    bouyer 				/* Need to fix up array sizing */
    233  1.24.8.2    bouyer 				while (i-- > 0 && linesw[i] == NULL)
    234  1.24.8.2    bouyer 					continue;
    235  1.24.8.2    bouyer 				nlinesw = i + 1;
    236  1.24.8.2    bouyer 			}
    237  1.24.8.2    bouyer 			return (disc);
    238  1.24.8.2    bouyer 		}
    239  1.24.8.2    bouyer 	}
    240  1.24.8.2    bouyer 	return (NULL);
    241  1.24.8.2    bouyer }
    242  1.24.8.2    bouyer 
    243  1.24.8.2    bouyer /*
    244  1.24.8.2    bouyer  * Look up a line discipline by its name.
    245  1.24.8.2    bouyer  */
    246  1.24.8.2    bouyer struct linesw *
    247  1.24.8.2    bouyer ttyldisc_lookup(name)
    248  1.24.8.2    bouyer 	char *name;
    249  1.24.8.2    bouyer {
    250  1.24.8.2    bouyer 	int i;
    251  1.24.8.2    bouyer 
    252  1.24.8.2    bouyer 	for (i = 0; i < nlinesw; i++)
    253  1.24.8.2    bouyer 		if (linesw[i] && (strcmp(name, linesw[i]->l_name) == 0))
    254  1.24.8.2    bouyer 			return (linesw[i]);
    255  1.24.8.2    bouyer 	return (NULL);
    256  1.24.8.2    bouyer }
    257  1.24.8.2    bouyer 
    258  1.24.8.2    bouyer #define TTYLDISCINIT(s, v) \
    259  1.24.8.2    bouyer 	do { \
    260  1.24.8.2    bouyer 		if (ttyldisc_add(&(s), (v)) != (v)) \
    261  1.24.8.2    bouyer 			panic(__CONCAT("ttyldisc_init: ", __STRING(s))); \
    262  1.24.8.2    bouyer 	} while (0)
    263  1.24.8.2    bouyer 
    264  1.24.8.2    bouyer /*
    265  1.24.8.2    bouyer  * Register the basic line disciplines.
    266  1.24.8.2    bouyer  */
    267  1.24.8.2    bouyer void
    268  1.24.8.2    bouyer ttyldisc_init()
    269  1.24.8.2    bouyer {
    270  1.24.8.2    bouyer 
    271  1.24.8.2    bouyer 	/* Only initialize once */
    272  1.24.8.2    bouyer 	if (linesw)
    273  1.24.8.2    bouyer 		return;
    274  1.24.8.2    bouyer 
    275  1.24.8.2    bouyer 	slinesw = LSWITCHBRK;
    276  1.24.8.2    bouyer 	linesw = malloc(slinesw * sizeof(struct linesw *),
    277  1.24.8.2    bouyer 	    M_TTYS, M_WAITOK);
    278  1.24.8.2    bouyer 	bzero(linesw, slinesw * sizeof(struct linesw *));
    279  1.24.8.2    bouyer 
    280  1.24.8.2    bouyer 	TTYLDISCINIT(termios_disc, 0);
    281  1.24.8.2    bouyer 	/* Do we really need this one? */
    282  1.24.8.2    bouyer 	TTYLDISCINIT(defunct_disc, 1);
    283  1.24.8.2    bouyer 
    284  1.24.8.2    bouyer 	/*
    285  1.24.8.2    bouyer 	 * The following should really be moved to
    286  1.24.8.2    bouyer 	 * initialization code for each module.
    287  1.24.8.2    bouyer 	 */
    288  1.24.8.2    bouyer 
    289  1.24.8.2    bouyer #if defined(COMPAT_43) || defined(COMPAT_FREEBSD)
    290  1.24.8.2    bouyer 	TTYLDISCINIT(ntty_disc, 2);
    291  1.24.8.2    bouyer #endif
    292  1.24.8.2    bouyer #if NTB > 0
    293  1.24.8.2    bouyer 	TTYLDISCINIT(table_disc, 3);
    294  1.24.8.2    bouyer #endif
    295  1.24.8.2    bouyer #if NSL > 0
    296  1.24.8.2    bouyer 	TTYLDISCINIT(slip_disc, 4);
    297  1.24.8.2    bouyer #endif
    298  1.24.8.2    bouyer #if NPPP > 0
    299  1.24.8.2    bouyer 	TTYLDISCINIT(ppp_disc, 5);
    300  1.24.8.2    bouyer #endif
    301  1.24.8.2    bouyer #if NSTRIP > 0
    302  1.24.8.2    bouyer 	TTYLDISCINIT(strip_disc, 6);
    303  1.24.8.2    bouyer #endif
    304      1.10       cgd }
    305