xref: /freebsd/libexec/rc/rc.d/serial (revision ffe00a05229ef58272669dea141e9fa33e07a5ee)
10696600cSBjoern A. Zeeb#!/bin/sh
20696600cSBjoern A. Zeeb#
30696600cSBjoern A. Zeeb# Copyright (c) 1996  Andrey A. Chernov
40696600cSBjoern A. Zeeb# All rights reserved.
50696600cSBjoern A. Zeeb#
60696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without
70696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions
80696600cSBjoern A. Zeeb# are met:
90696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright
100696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer.
110696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright
120696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer in the
130696600cSBjoern A. Zeeb#    documentation and/or other materials provided with the distribution.
140696600cSBjoern A. Zeeb#
150696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
160696600cSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
170696600cSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
180696600cSBjoern A. Zeeb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
190696600cSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
200696600cSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
210696600cSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
220696600cSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
230696600cSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
240696600cSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
250696600cSBjoern A. Zeeb# SUCH DAMAGE.
260696600cSBjoern A. Zeeb#
270696600cSBjoern A. Zeeb#
280696600cSBjoern A. Zeeb
290696600cSBjoern A. Zeeb# PROVIDE: serial
300696600cSBjoern A. Zeeb# REQUIRE: root
310696600cSBjoern A. Zeeb# KEYWORD: nojail
320696600cSBjoern A. Zeeb
330696600cSBjoern A. Zeeb# Change some defaults for serial devices.
340696600cSBjoern A. Zeeb# Standard defaults are:
350696600cSBjoern A. Zeeb#	dtrwait 300 drainwait `sysctl -n kern.drainwait`
360696600cSBjoern A. Zeeb#	initial cflag from <sys/ttydefaults.h> = cread cs8 hupcl
370696600cSBjoern A. Zeeb#	initial iflag, lflag and oflag all 0
384722ceb7SEd Maste#	speed 115200
390696600cSBjoern A. Zeeb#	special chars from <sys/ttydefaults.h>
400696600cSBjoern A. Zeeb#	nothing locked
410696600cSBjoern A. Zeeb# except for serial consoles the initial iflag, lflag and oflag are from
420696600cSBjoern A. Zeeb# <sys/ttydefaults.h> and clocal is locked on.
430696600cSBjoern A. Zeeb
440696600cSBjoern A. Zeebdefault() {
450696600cSBjoern A. Zeeb	# Reset everything changed by the other functions to initial defaults.
460696600cSBjoern A. Zeeb
470696600cSBjoern A. Zeeb	dc=$1; shift	# device name character
48*ffe00a05SWarner Losh	drainwait=`sysctl -n kern.tty_drainwait`
490696600cSBjoern A. Zeeb
500696600cSBjoern A. Zeeb	for i in $*
510696600cSBjoern A. Zeeb	do
520696600cSBjoern A. Zeeb		comcontrol /dev/tty${dc}${i} dtrwait 300 drainwait $drainwait
534722ceb7SEd Maste		stty < /dev/tty${dc}${i}.init -clocal crtscts hupcl 115200 reprint ^R
540696600cSBjoern A. Zeeb		stty < /dev/tty${dc}${i}.lock -clocal -crtscts -hupcl 0
554722ceb7SEd Maste		stty < /dev/cua${dc}${i}.init -clocal crtscts hupcl 115200 reprint ^R
560696600cSBjoern A. Zeeb		stty < /dev/cua${dc}${i}.lock -clocal -crtscts -hupcl 0
570696600cSBjoern A. Zeeb	done
580696600cSBjoern A. Zeeb}
590696600cSBjoern A. Zeeb
600696600cSBjoern A. Zeebmaybe() {
610696600cSBjoern A. Zeeb	# Special settings.
620696600cSBjoern A. Zeeb
630696600cSBjoern A. Zeeb	dc=$1; shift
640696600cSBjoern A. Zeeb
650696600cSBjoern A. Zeeb	for i in $*
660696600cSBjoern A. Zeeb	do
670696600cSBjoern A. Zeeb		# Don't use ^R; it breaks bash's ^R when typed ahead.
680696600cSBjoern A. Zeeb		stty < /dev/tty${dc}${i}.init reprint undef
690696600cSBjoern A. Zeeb		stty < /dev/cua${dc}${i}.init reprint undef
700696600cSBjoern A. Zeeb		# Lock clocal off on dialin device for security.
710696600cSBjoern A. Zeeb		stty < /dev/tty${dc}${i}.lock clocal
720696600cSBjoern A. Zeeb		# Lock the speeds to use old binaries that don't support them.
730696600cSBjoern A. Zeeb		# Any legal speed works to lock the initial speed.
740696600cSBjoern A. Zeeb		stty < /dev/tty${dc}${i}.lock 300
750696600cSBjoern A. Zeeb		stty < /dev/cua${dc}${i}.lock 300
760696600cSBjoern A. Zeeb	done
770696600cSBjoern A. Zeeb}
780696600cSBjoern A. Zeeb
790696600cSBjoern A. Zeebmodem() {
800696600cSBjoern A. Zeeb	# Modem that supports CTS and perhaps RTS handshaking.
810696600cSBjoern A. Zeeb
820696600cSBjoern A. Zeeb	dc=$1; shift
830696600cSBjoern A. Zeeb
840696600cSBjoern A. Zeeb	for i in $*
850696600cSBjoern A. Zeeb	do
860696600cSBjoern A. Zeeb		# may depend on modem
87*ffe00a05SWarner Losh		comcontrol /dev/tty${dc}${i} drainwait 180
880696600cSBjoern A. Zeeb		# Lock crtscts on.
890696600cSBjoern A. Zeeb		# Speed reasonable for V42bis.
900696600cSBjoern A. Zeeb		stty < /dev/tty${dc}${i}.init crtscts 115200
910696600cSBjoern A. Zeeb		stty < /dev/tty${dc}${i}.lock crtscts
920696600cSBjoern A. Zeeb		stty < /dev/cua${dc}${i}.init crtscts 115200
930696600cSBjoern A. Zeeb		stty < /dev/cua${dc}${i}.lock crtscts
940696600cSBjoern A. Zeeb	done
950696600cSBjoern A. Zeeb}
960696600cSBjoern A. Zeeb
970696600cSBjoern A. Zeebmouse() {
980696600cSBjoern A. Zeeb	# Mouse on either callin or callout port.
990696600cSBjoern A. Zeeb
1000696600cSBjoern A. Zeeb	dc=$1; shift
1010696600cSBjoern A. Zeeb
1020696600cSBjoern A. Zeeb	for i in $*
1030696600cSBjoern A. Zeeb	do
1040696600cSBjoern A. Zeeb		# Lock clocal on, hupcl off.
1050696600cSBjoern A. Zeeb		# Standard speed for Microsoft mouse.
1060696600cSBjoern A. Zeeb		stty < /dev/tty${dc}${i}.init clocal -hupcl 1200
1070696600cSBjoern A. Zeeb		stty < /dev/tty${dc}${i}.lock clocal  hupcl
1080696600cSBjoern A. Zeeb		stty < /dev/cua${dc}${i}.init clocal -hupcl 1200
1090696600cSBjoern A. Zeeb		stty < /dev/cua${dc}${i}.lock clocal  hupcl
1100696600cSBjoern A. Zeeb	done
1110696600cSBjoern A. Zeeb}
1120696600cSBjoern A. Zeeb
1130696600cSBjoern A. Zeebterminal() {
1140696600cSBjoern A. Zeeb	# Terminal that supports CTS and perhaps RTS handshaking
1150696600cSBjoern A. Zeeb	# with the cable or terminal arranged so that DCD is on
1160696600cSBjoern A. Zeeb	# at least while the terminal is on.
1170696600cSBjoern A. Zeeb	# Also works for bidirectional communications to another pc
1180696600cSBjoern A. Zeeb	# provided at most one side runs getty.
1190696600cSBjoern A. Zeeb	# Same as modem() except we want a faster speed and no dtrwait.
1200696600cSBjoern A. Zeeb
1210696600cSBjoern A. Zeeb	dc=$1; shift
1220696600cSBjoern A. Zeeb
1230696600cSBjoern A. Zeeb	modem ${dc} $*
1240696600cSBjoern A. Zeeb	for i in $*
1250696600cSBjoern A. Zeeb	do
1260696600cSBjoern A. Zeeb		comcontrol /dev/tty${dc}${i} dtrwait 0
1270696600cSBjoern A. Zeeb		stty < /dev/tty${dc}${i}.init 115200
1280696600cSBjoern A. Zeeb		stty < /dev/cua${dc}${i}.init 115200
1290696600cSBjoern A. Zeeb	done
1300696600cSBjoern A. Zeeb}
1310696600cSBjoern A. Zeeb
1320696600cSBjoern A. Zeeb3wire() {
1330696600cSBjoern A. Zeeb	# 3-wire serial terminals.  These don't supply carrier, so
1340696600cSBjoern A. Zeeb	# clocal needs to be set, and crtscts needs to be unset.
1350696600cSBjoern A. Zeeb
1360696600cSBjoern A. Zeeb	dc=$1; shift
1370696600cSBjoern A. Zeeb
1380696600cSBjoern A. Zeeb	terminal ${dc} $*
1390696600cSBjoern A. Zeeb	for i in $*
1400696600cSBjoern A. Zeeb	do
1410696600cSBjoern A. Zeeb		stty < /dev/tty${dc}${i}.init clocal -crtscts
1420696600cSBjoern A. Zeeb		stty < /dev/cua${dc}${i}.init clocal -crtscts
1430696600cSBjoern A. Zeeb	done
1440696600cSBjoern A. Zeeb}
1450696600cSBjoern A. Zeeb
1460696600cSBjoern A. Zeeb# Don't use anything from this file unless you have some buggy programs
1470696600cSBjoern A. Zeeb# that require it.
1480696600cSBjoern A. Zeeb
1490696600cSBjoern A. Zeeb# Edit the functions and the examples to suit your system.
1500696600cSBjoern A. Zeeb# $1 is the device identifier, and the remainder of the line
1510696600cSBjoern A. Zeeb# lists the device numbers.
1520696600cSBjoern A. Zeeb
1530696600cSBjoern A. Zeeb# Initialize assorted 8250-16550 (uart) ports.
1540696600cSBjoern A. Zeeb# 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
1550696600cSBjoern A. Zeeb# mouse    u      2
1560696600cSBjoern A. Zeeb# modem    u    1
1570696600cSBjoern A. Zeeb# terminal u  0
1580696600cSBjoern A. Zeeb# 3wire    u  0
159