rc: Use SYSCTL{,_N,_W} variables
[dragonfly.git] / etc / rc.d / serial
1 #!/bin/sh
2 #
3 # Copyright (c) 1996  Andrey A. Chernov
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 #    notice, this list of conditions and the following disclaimer in the
13 #    documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE.
26 #
27 # $FreeBSD: src/etc/rc.d/serial,v 1.20 2003/05/05 03:26:50 bde Exp $
28 #
29
30 # PROVIDE: serial
31 # REQUIRE: root
32
33 . /etc/rc.subr
34 dummy_rc_command "$1"   
35
36 # Change some defaults for serial devices.
37 # Standard defaults are:
38 #       dtrwait 300 drainwait `sysctl -n kern.drainwait`
39 #       initial cflag from <sys/ttydefaults.h> = cread cs8 hupcl
40 #       initial iflag, lflag and oflag all 0
41 #       speed 9600
42 #       special chars from <sys/ttydefaults.h>
43 #       nothing locked
44 # except for serial consoles the initial iflag, lflag and oflag are from
45 # <sys/ttydefaults.h> and clocal is locked on.
46
47 default() {
48         # Reset everything changed by the other functions to initial defaults.
49
50         ci=$1; shift    # call in device identifier
51         co=$1; shift    # call out device identifier
52         drainwait=`${SYSCTL_N} kern.drainwait`
53
54         for i in $*
55         do
56                 comcontrol /dev/tty${ci}${i} dtrwait 300 drainwait $drainwait
57                 stty < /dev/ttyi${ci}${i} -clocal crtscts hupcl 9600 reprint ^R
58                 stty < /dev/ttyl${ci}${i} -clocal -crtscts -hupcl 0
59                 stty < /dev/cuai${co}${i} -clocal crtscts hupcl 9600 reprint ^R
60                 stty < /dev/cual${co}${i} -clocal -crtscts -hupcl 0
61         done
62 }
63
64 maybe() {
65         # Special settings.
66
67         ci=$1; shift
68         co=$1; shift
69
70         for i in $*
71         do
72                 # Don't use ^R; it breaks bash's ^R when typed ahead.
73                 stty < /dev/ttyi${ci}${i} reprint undef
74                 stty < /dev/cuai${co}${i} reprint undef
75                 # Lock clocal off on dialin device for security.
76                 stty < /dev/ttyl${ci}${i} clocal
77                 # Lock the speeds to use old binaries that don't support them.
78                 # Any legal speed works to lock the initial speed.
79                 stty < /dev/ttyl${ci}${i} 300
80                 stty < /dev/cual${co}${i} 300
81         done
82 }
83
84 modem() {
85         # Modem that supports CTS and perhaps RTS handshaking.
86
87         ci=$1; shift
88         co=$1; shift
89
90         for i in $*
91         do
92                 # may depend on modem
93                 comcontrol /dev/tty${ci}${i} dtrwait 100 drainwait 180
94                 # Lock crtscts on.
95                 # Speed reasonable for V42bis.
96                 stty < /dev/ttyi${ci}${i} crtscts 115200
97                 stty < /dev/ttyl${ci}${i} crtscts
98                 stty < /dev/cuai${co}${i} crtscts 115200
99                 stty < /dev/cual${co}${i} crtscts
100         done
101 }
102
103 mouse() {
104         # Mouse on either callin or callout port.
105
106         ci=$1; shift
107         co=$1; shift
108
109         for i in $*
110         do
111                 # Lock clocal on, hupcl off.
112                 # Standard speed for Microsoft mouse.
113                 stty < /dev/ttyi${ci}${i} clocal -hupcl 1200
114                 stty < /dev/ttyl${ci}${i} clocal  hupcl
115                 stty < /dev/cuai${co}${i} clocal -hupcl 1200
116                 stty < /dev/cual${co}${i} clocal  hupcl
117         done
118 }
119
120 terminal() {
121         # Terminal that supports CTS and perhaps RTS handshaking
122         # with the cable or terminal arranged so that DCD is on
123         # at least while the terminal is on.
124         # Also works for bidirectional communications to another pc
125         # provided at most one side runs getty.
126         # Same as modem() except we want a faster speed and no dtrwait.
127
128         ci=$1; shift
129         co=$1; shift
130
131         modem ${ci} ${co} $*
132         for i in $*
133         do
134                 comcontrol /dev/tty${ci}${i} dtrwait 0
135                 stty < /dev/ttyi${ci}${i} 115200
136                 stty < /dev/cuai${co}${i} 115200
137         done
138 }
139
140 # Don't use anything from this file unless you have some buggy programs
141 # that require it.
142
143 # Edit the functions and the examples to suit your system.
144 # $1 is the call in device identifier, $2 is the call out device identifier
145 # and the remainder of the line lists the device numbers.
146
147 # Initialize assorted 8250-16550 (sio) ports.
148 # maybe    d a  0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v
149 # mouse    d a      2
150 # modem    d a    1
151 # terminal d a  0
152
153 # Initialize all ports on a Cyclades-8yo.
154 # modem    c c  00 01 02 03 04 05 06 07
155
156 # Initialize all ports on a Cyclades-16ye.
157 # modem    c c  00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
158
159 # Initialize all ports on a Digiboard 8.
160 # modem    D D  00 01 02 03 04 05 06 07