xref: /freebsd/libexec/rc/rc.d/serial (revision 8aac90f18aef7c9eea906c3ff9a001ca7b94f375)
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#
28
29# PROVIDE: serial
30# REQUIRE: root
31# KEYWORD: nojail
32
33# Change some defaults for serial devices.
34# Standard defaults are:
35#	dtrwait 300 drainwait `sysctl -n kern.drainwait`
36#	initial cflag from <sys/ttydefaults.h> = cread cs8 hupcl
37#	initial iflag, lflag and oflag all 0
38#	speed 115200
39#	special chars from <sys/ttydefaults.h>
40#	nothing locked
41# except for serial consoles the initial iflag, lflag and oflag are from
42# <sys/ttydefaults.h> and clocal is locked on.
43
44default() {
45	# Reset everything changed by the other functions to initial defaults.
46
47	dc=$1; shift	# device name character
48	drainwait=`sysctl -n kern.drainwait`
49
50	for i in $*
51	do
52		comcontrol /dev/tty${dc}${i} dtrwait 300 drainwait $drainwait
53		stty < /dev/tty${dc}${i}.init -clocal crtscts hupcl 115200 reprint ^R
54		stty < /dev/tty${dc}${i}.lock -clocal -crtscts -hupcl 0
55		stty < /dev/cua${dc}${i}.init -clocal crtscts hupcl 115200 reprint ^R
56		stty < /dev/cua${dc}${i}.lock -clocal -crtscts -hupcl 0
57	done
58}
59
60maybe() {
61	# Special settings.
62
63	dc=$1; shift
64
65	for i in $*
66	do
67		# Don't use ^R; it breaks bash's ^R when typed ahead.
68		stty < /dev/tty${dc}${i}.init reprint undef
69		stty < /dev/cua${dc}${i}.init reprint undef
70		# Lock clocal off on dialin device for security.
71		stty < /dev/tty${dc}${i}.lock clocal
72		# Lock the speeds to use old binaries that don't support them.
73		# Any legal speed works to lock the initial speed.
74		stty < /dev/tty${dc}${i}.lock 300
75		stty < /dev/cua${dc}${i}.lock 300
76	done
77}
78
79modem() {
80	# Modem that supports CTS and perhaps RTS handshaking.
81
82	dc=$1; shift
83
84	for i in $*
85	do
86		# may depend on modem
87		comcontrol /dev/tty${dc}${i} dtrwait 100 drainwait 180
88		# Lock crtscts on.
89		# Speed reasonable for V42bis.
90		stty < /dev/tty${dc}${i}.init crtscts 115200
91		stty < /dev/tty${dc}${i}.lock crtscts
92		stty < /dev/cua${dc}${i}.init crtscts 115200
93		stty < /dev/cua${dc}${i}.lock crtscts
94	done
95}
96
97mouse() {
98	# Mouse on either callin or callout port.
99
100	dc=$1; shift
101
102	for i in $*
103	do
104		# Lock clocal on, hupcl off.
105		# Standard speed for Microsoft mouse.
106		stty < /dev/tty${dc}${i}.init clocal -hupcl 1200
107		stty < /dev/tty${dc}${i}.lock clocal  hupcl
108		stty < /dev/cua${dc}${i}.init clocal -hupcl 1200
109		stty < /dev/cua${dc}${i}.lock clocal  hupcl
110	done
111}
112
113terminal() {
114	# Terminal that supports CTS and perhaps RTS handshaking
115	# with the cable or terminal arranged so that DCD is on
116	# at least while the terminal is on.
117	# Also works for bidirectional communications to another pc
118	# provided at most one side runs getty.
119	# Same as modem() except we want a faster speed and no dtrwait.
120
121	dc=$1; shift
122
123	modem ${dc} $*
124	for i in $*
125	do
126		comcontrol /dev/tty${dc}${i} dtrwait 0
127		stty < /dev/tty${dc}${i}.init 115200
128		stty < /dev/cua${dc}${i}.init 115200
129	done
130}
131
1323wire() {
133	# 3-wire serial terminals.  These don't supply carrier, so
134	# clocal needs to be set, and crtscts needs to be unset.
135
136	dc=$1; shift
137
138	terminal ${dc} $*
139	for i in $*
140	do
141		stty < /dev/tty${dc}${i}.init clocal -crtscts
142		stty < /dev/cua${dc}${i}.init clocal -crtscts
143	done
144}
145
146# Don't use anything from this file unless you have some buggy programs
147# that require it.
148
149# Edit the functions and the examples to suit your system.
150# $1 is the device identifier, and the remainder of the line
151# lists the device numbers.
152
153# Initialize assorted 8250-16550 (uart) ports.
154# maybe    u  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
155# mouse    u      2
156# modem    u    1
157# terminal u  0
158# 3wire    u  0
159
160# Initialize all ports on a Cyclades-8yo.
161# modem    c  00 01 02 03 04 05 06 07
162
163# Initialize all ports on a Cyclades-16ye.
164# modem    c  00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
165
166# Initialize all ports on a Digiboard 8.
167# modem    D  00 01 02 03 04 05 06 07
168