xref: /dflybsd-src/etc/rc.d/serial (revision ce0833857e05eba4d13f3fd8a4d049ea68c5ffa4)
19c600e7dSMatthew Dillon#!/bin/sh
29c600e7dSMatthew Dillon#
39c600e7dSMatthew Dillon# Copyright (c) 1996  Andrey A. Chernov
49c600e7dSMatthew Dillon# All rights reserved.
59c600e7dSMatthew Dillon#
69c600e7dSMatthew Dillon# Redistribution and use in source and binary forms, with or without
79c600e7dSMatthew Dillon# modification, are permitted provided that the following conditions
89c600e7dSMatthew Dillon# are met:
99c600e7dSMatthew Dillon# 1. Redistributions of source code must retain the above copyright
109c600e7dSMatthew Dillon#    notice, this list of conditions and the following disclaimer.
119c600e7dSMatthew Dillon# 2. Redistributions in binary form must reproduce the above copyright
129c600e7dSMatthew Dillon#    notice, this list of conditions and the following disclaimer in the
139c600e7dSMatthew Dillon#    documentation and/or other materials provided with the distribution.
149c600e7dSMatthew Dillon#
159c600e7dSMatthew Dillon# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
169c600e7dSMatthew Dillon# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
179c600e7dSMatthew Dillon# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
189c600e7dSMatthew Dillon# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199c600e7dSMatthew Dillon# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209c600e7dSMatthew Dillon# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
219c600e7dSMatthew Dillon# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
229c600e7dSMatthew Dillon# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
239c600e7dSMatthew Dillon# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
249c600e7dSMatthew Dillon# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
259c600e7dSMatthew Dillon# SUCH DAMAGE.
269c600e7dSMatthew Dillon#
279c600e7dSMatthew Dillon# $FreeBSD: src/etc/rc.d/serial,v 1.20 2003/05/05 03:26:50 bde Exp $
289c600e7dSMatthew Dillon#
299c600e7dSMatthew Dillon
309c600e7dSMatthew Dillon# PROVIDE: serial
31*ce083385SAaron LI# REQUIRE: FILESYSTEMS
32*ce083385SAaron LI# BEFORE:  NETWORKING
339c600e7dSMatthew Dillon
340c823069SMatthew Dillon. /etc/rc.subr
350c823069SMatthew Dillondummy_rc_command "$1"
360c823069SMatthew Dillon
379c600e7dSMatthew Dillon# Change some defaults for serial devices.
389c600e7dSMatthew Dillon# Standard defaults are:
399c600e7dSMatthew Dillon#	dtrwait 300 drainwait `sysctl -n kern.drainwait`
409c600e7dSMatthew Dillon#	initial cflag from <sys/ttydefaults.h> = cread cs8 hupcl
419c600e7dSMatthew Dillon#	initial iflag, lflag and oflag all 0
420cf00aa2SMatthew Dillon#	speed 115200
439c600e7dSMatthew Dillon#	special chars from <sys/ttydefaults.h>
449c600e7dSMatthew Dillon#	nothing locked
459c600e7dSMatthew Dillon# except for serial consoles the initial iflag, lflag and oflag are from
469c600e7dSMatthew Dillon# <sys/ttydefaults.h> and clocal is locked on.
479c600e7dSMatthew Dillon
489c600e7dSMatthew Dillondefault() {
499c600e7dSMatthew Dillon	# Reset everything changed by the other functions to initial defaults.
509c600e7dSMatthew Dillon
519c600e7dSMatthew Dillon	ci=$1; shift	# call in device identifier
529c600e7dSMatthew Dillon	co=$1; shift	# call out device identifier
53b0a4258dSAaron LI	drainwait=`${SYSCTL_N} kern.drainwait`
549c600e7dSMatthew Dillon
559c600e7dSMatthew Dillon	for i in $*
569c600e7dSMatthew Dillon	do
579c600e7dSMatthew Dillon		comcontrol /dev/tty${ci}${i} dtrwait 300 drainwait $drainwait
580cf00aa2SMatthew Dillon		stty < /dev/ttyi${ci}${i} -clocal crtscts hupcl 115200 reprint ^R
599c600e7dSMatthew Dillon		stty < /dev/ttyl${ci}${i} -clocal -crtscts -hupcl 0
600cf00aa2SMatthew Dillon		stty < /dev/cuai${co}${i} -clocal crtscts hupcl 115200 reprint ^R
619c600e7dSMatthew Dillon		stty < /dev/cual${co}${i} -clocal -crtscts -hupcl 0
629c600e7dSMatthew Dillon	done
639c600e7dSMatthew Dillon}
649c600e7dSMatthew Dillon
659c600e7dSMatthew Dillonmaybe() {
669c600e7dSMatthew Dillon	# Special settings.
679c600e7dSMatthew Dillon
689c600e7dSMatthew Dillon	ci=$1; shift
699c600e7dSMatthew Dillon	co=$1; shift
709c600e7dSMatthew Dillon
719c600e7dSMatthew Dillon	for i in $*
729c600e7dSMatthew Dillon	do
739c600e7dSMatthew Dillon		# Don't use ^R; it breaks bash's ^R when typed ahead.
749c600e7dSMatthew Dillon		stty < /dev/ttyi${ci}${i} reprint undef
759c600e7dSMatthew Dillon		stty < /dev/cuai${co}${i} reprint undef
769c600e7dSMatthew Dillon		# Lock clocal off on dialin device for security.
779c600e7dSMatthew Dillon		stty < /dev/ttyl${ci}${i} clocal
789c600e7dSMatthew Dillon		# Lock the speeds to use old binaries that don't support them.
799c600e7dSMatthew Dillon		# Any legal speed works to lock the initial speed.
809c600e7dSMatthew Dillon		stty < /dev/ttyl${ci}${i} 300
819c600e7dSMatthew Dillon		stty < /dev/cual${co}${i} 300
829c600e7dSMatthew Dillon	done
839c600e7dSMatthew Dillon}
849c600e7dSMatthew Dillon
859c600e7dSMatthew Dillonmodem() {
869c600e7dSMatthew Dillon	# Modem that supports CTS and perhaps RTS handshaking.
879c600e7dSMatthew Dillon
889c600e7dSMatthew Dillon	ci=$1; shift
899c600e7dSMatthew Dillon	co=$1; shift
909c600e7dSMatthew Dillon
919c600e7dSMatthew Dillon	for i in $*
929c600e7dSMatthew Dillon	do
939c600e7dSMatthew Dillon		# may depend on modem
949c600e7dSMatthew Dillon		comcontrol /dev/tty${ci}${i} dtrwait 100 drainwait 180
959c600e7dSMatthew Dillon		# Lock crtscts on.
969c600e7dSMatthew Dillon		# Speed reasonable for V42bis.
979c600e7dSMatthew Dillon		stty < /dev/ttyi${ci}${i} crtscts 115200
989c600e7dSMatthew Dillon		stty < /dev/ttyl${ci}${i} crtscts
999c600e7dSMatthew Dillon		stty < /dev/cuai${co}${i} crtscts 115200
1009c600e7dSMatthew Dillon		stty < /dev/cual${co}${i} crtscts
1019c600e7dSMatthew Dillon	done
1029c600e7dSMatthew Dillon}
1039c600e7dSMatthew Dillon
1049c600e7dSMatthew Dillonmouse() {
1059c600e7dSMatthew Dillon	# Mouse on either callin or callout port.
1069c600e7dSMatthew Dillon
1079c600e7dSMatthew Dillon	ci=$1; shift
1089c600e7dSMatthew Dillon	co=$1; shift
1099c600e7dSMatthew Dillon
1109c600e7dSMatthew Dillon	for i in $*
1119c600e7dSMatthew Dillon	do
1129c600e7dSMatthew Dillon		# Lock clocal on, hupcl off.
1139c600e7dSMatthew Dillon		# Standard speed for Microsoft mouse.
1149c600e7dSMatthew Dillon		stty < /dev/ttyi${ci}${i} clocal -hupcl 1200
1159c600e7dSMatthew Dillon		stty < /dev/ttyl${ci}${i} clocal  hupcl
1169c600e7dSMatthew Dillon		stty < /dev/cuai${co}${i} clocal -hupcl 1200
1179c600e7dSMatthew Dillon		stty < /dev/cual${co}${i} clocal  hupcl
1189c600e7dSMatthew Dillon	done
1199c600e7dSMatthew Dillon}
1209c600e7dSMatthew Dillon
1219c600e7dSMatthew Dillonterminal() {
1229c600e7dSMatthew Dillon	# Terminal that supports CTS and perhaps RTS handshaking
1239c600e7dSMatthew Dillon	# with the cable or terminal arranged so that DCD is on
1249c600e7dSMatthew Dillon	# at least while the terminal is on.
1259c600e7dSMatthew Dillon	# Also works for bidirectional communications to another pc
1269c600e7dSMatthew Dillon	# provided at most one side runs getty.
1279c600e7dSMatthew Dillon	# Same as modem() except we want a faster speed and no dtrwait.
1289c600e7dSMatthew Dillon
1299c600e7dSMatthew Dillon	ci=$1; shift
1309c600e7dSMatthew Dillon	co=$1; shift
1319c600e7dSMatthew Dillon
1329c600e7dSMatthew Dillon	modem ${ci} ${co} $*
1339c600e7dSMatthew Dillon	for i in $*
1349c600e7dSMatthew Dillon	do
1359c600e7dSMatthew Dillon		comcontrol /dev/tty${ci}${i} dtrwait 0
1369c600e7dSMatthew Dillon		stty < /dev/ttyi${ci}${i} 115200
1379c600e7dSMatthew Dillon		stty < /dev/cuai${co}${i} 115200
1389c600e7dSMatthew Dillon	done
1399c600e7dSMatthew Dillon}
1409c600e7dSMatthew Dillon
1419c600e7dSMatthew Dillon# Don't use anything from this file unless you have some buggy programs
1429c600e7dSMatthew Dillon# that require it.
1439c600e7dSMatthew Dillon
1449c600e7dSMatthew Dillon# Edit the functions and the examples to suit your system.
1459c600e7dSMatthew Dillon# $1 is the call in device identifier, $2 is the call out device identifier
1469c600e7dSMatthew Dillon# and the remainder of the line lists the device numbers.
1479c600e7dSMatthew Dillon
1489c600e7dSMatthew Dillon# Initialize assorted 8250-16550 (sio) ports.
1499c600e7dSMatthew Dillon# 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
1509c600e7dSMatthew Dillon# mouse    d a      2
1519c600e7dSMatthew Dillon# modem    d a    1
1529c600e7dSMatthew Dillon# terminal d a  0
1539c600e7dSMatthew Dillon
1549c600e7dSMatthew Dillon# Initialize all ports on a Cyclades-8yo.
1559c600e7dSMatthew Dillon# modem    c c  00 01 02 03 04 05 06 07
1569c600e7dSMatthew Dillon
1579c600e7dSMatthew Dillon# Initialize all ports on a Cyclades-16ye.
1589c600e7dSMatthew Dillon# modem    c c  00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
1599c600e7dSMatthew Dillon
1609c600e7dSMatthew Dillon# Initialize all ports on a Digiboard 8.
1619c600e7dSMatthew Dillon# modem    D D  00 01 02 03 04 05 06 07
162