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