serial revision 100280
1139804Simp#!/bin/sh
21541Srgrimes#
3152376Srwatson# Copyright (c) 1996  Andrey A. Chernov
4152376Srwatson# All rights reserved.
5152376Srwatson#
61541Srgrimes# Redistribution and use in source and binary forms, with or without
71541Srgrimes# modification, are permitted provided that the following conditions
81541Srgrimes# are met:
91541Srgrimes# 1. Redistributions of source code must retain the above copyright
101541Srgrimes#    notice, this list of conditions and the following disclaimer.
111541Srgrimes# 2. Redistributions in binary form must reproduce the above copyright
121541Srgrimes#    notice, this list of conditions and the following disclaimer in the
131541Srgrimes#    documentation and/or other materials provided with the distribution.
141541Srgrimes#
151541Srgrimes# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
161541Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171541Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181541Srgrimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
191541Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201541Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
211541Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221541Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231541Srgrimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241541Srgrimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251541Srgrimes# SUCH DAMAGE.
261541Srgrimes#
271541Srgrimes# $FreeBSD: head/etc/rc.d/serial 100280 2002-07-18 05:00:17Z gordon $
281541Srgrimes#
291541Srgrimes
301541Srgrimes# PROVIDE: serial
311541Srgrimes# REQUIRE: root
321541Srgrimes# KEYWORD: FreeBSD
331541Srgrimes
34116182Sobrien# Change some defaults for serial devices.
35116182Sobrien# Standard defaults are:
36116182Sobrien#	dtrwait 300 drainwait 0
3713203Swollman#	initial cflag from <sys/ttydefaults.h> = cread cs8 hupcl
381541Srgrimes#	initial iflag, lflag and oflag all 0
391541Srgrimes#	speed 9600
402112Swollman#	special chars from <sys/ttydefaults.h>
4197993Sjhb#	nothing locked
4297993Sjhb# except for serial consoles the initial iflag, lflag and oflag are from
4397993Sjhb# <sys/ttydefaults.h> and clocal is locked on.
4476166Smarkm
4576166Smarkmdefault() {
4697993Sjhb	# Reset everything changed by the other functions to initial defaults.
47155031Sjeff
4897993Sjhb	ci=$1; shift	# call in device identifier
49164033Srwatson	co=$1; shift	# call out device identifier
501541Srgrimes
5197993Sjhb	for i in $*
521541Srgrimes	do
53176471Sdes		comcontrol /dev/tty${ci}${i} dtrwait 300 drainwait 300
54176471Sdes		stty < /dev/ttyi${ci}${i} -clocal crtscts hupcl 9600 reprint ^R
551541Srgrimes		stty < /dev/ttyl${ci}${i} -clocal -crtscts -hupcl 0
5674927Sjhb		stty < /dev/cuai${co}${i} -clocal crtscts hupcl 9600 reprint ^R
5797993Sjhb		stty < /dev/cual${co}${i} -clocal -crtscts -hupcl 0
58219042Sdchagin	done
591541Srgrimes}
6097993Sjhb
611541Srgrimesmaybe() {
62163606Srwatson	# Special settings.
63163606Srwatson
64152376Srwatson	ci=$1; shift
65152376Srwatson	co=$1; shift
66152376Srwatson
67152376Srwatson	for i in $*
68152376Srwatson	do
69152376Srwatson		# Don't use ^R; it breaks bash's ^R when typed ahead.
70152376Srwatson		stty < /dev/ttyi${ci}${i} reprint undef
71152376Srwatson		stty < /dev/cuai${co}${i} reprint undef
72152376Srwatson		# Lock clocal off on dialin device for security.
73152376Srwatson		stty < /dev/ttyl${ci}${i} clocal
74152376Srwatson		# Lock the speeds to use old binaries that don't support them.
75152376Srwatson		# Any legal speed works to lock the initial speed.
76152376Srwatson		stty < /dev/ttyl${ci}${i} 300
77152376Srwatson		stty < /dev/cual${co}${i} 300
78152376Srwatson	done
79152376Srwatson}
80152376Srwatson
81152376Srwatsonmodem() {
82152376Srwatson	# Modem that supports CTS and perhaps RTS handshaking.
8330354Sphk
8430309Sphk	ci=$1; shift
8513203Swollman	co=$1; shift
8612577Sbde
87219028Snetchild	for i in $*
88219028Snetchild	do
8997993Sjhb		# may depend on modem
9097993Sjhb		comcontrol /dev/tty${ci}${i} dtrwait 100 drainwait 180
9197993Sjhb		# Lock crtscts on.
9212819Sphk		# Speed reasonable for V42bis.
9397993Sjhb		stty < /dev/ttyi${ci}${i} crtscts 57600
9497993Sjhb		stty < /dev/ttyl${ci}${i} crtscts
95151927Srwatson		stty < /dev/cuai${co}${i} crtscts 57600
9697993Sjhb		stty < /dev/cual${co}${i} crtscts
97219042Sdchagin	done
9897993Sjhb}
9997993Sjhb
10097993Sjhbmouse() {
10197993Sjhb	# Mouse on either callin or callout port.
10297993Sjhb
103237663Sjhb	ci=$1; shift
104237663Sjhb	co=$1; shift
10597993Sjhb
10697993Sjhb	for i in $*
10797993Sjhb	do
10897993Sjhb		# Lock clocal on, hupcl off.
10997993Sjhb		# Standard speed for Microsoft mouse.
11097993Sjhb		stty < /dev/ttyi${ci}${i} clocal -hupcl 1200
11197993Sjhb		stty < /dev/ttyl${ci}${i} clocal  hupcl
11297993Sjhb		stty < /dev/cuai${co}${i} clocal -hupcl 1200
11397993Sjhb		stty < /dev/cual${co}${i} clocal  hupcl
11497993Sjhb	done
11597993Sjhb}
116219312Sdchagin
117176471Sdesterminal() {
118176471Sdes	# Terminal that supports CTS and perhaps RTS handshaking
119189707Sjhb	# with the cable or terminal arranged so that DCD is on
120219042Sdchagin	# at least while the terminal is on.
121219042Sdchagin	# Also works for bidirectional communications to another pc
122267015Sdelphij	# provided at most one side runs getty.
123237663Sjhb	# Same as modem() except we want a faster speed and no dtrwait.
124237663Sjhb
12597993Sjhb	ci=$1; shift
12697993Sjhb	co=$1; shift
12797993Sjhb
12897993Sjhb	modem ${ci} ${co} $*
129141633Sphk	for i in $*
130103234Sjhb	do
131118607Sjhb		comcontrol /dev/tty${ci}${i} dtrwait 0
132103234Sjhb		stty < /dev/ttyi${ci}${i} 115200
13397993Sjhb		stty < /dev/cuai${co}${i} 115200
134118607Sjhb	done
135103234Sjhb}
136103234Sjhb
137103234Sjhb# Don't use anything from this file unless you have some buggy programs
138103234Sjhb# that require it.
13997993Sjhb
140214158Sjhb# Edit the functions and the examples to suit your system.
141152376Srwatson# $1 is the call in device identifier, $2 is the call out device identifier
14297993Sjhb# and the remainder of the line lists the device numbers.
14397993Sjhb
14497993Sjhb# Initialize assorted 8250-16550 (sio) ports.
145219041Sdchagin# 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
146219311Sdchagin# mouse    d a      2
14797993Sjhb# modem    d a    1
148152376Srwatson# terminal d a  0
149214158Sjhb
150214158Sjhb# Initialize all ports on a Cyclades-8yo.
15197993Sjhb# modem    c c  00 01 02 03 04 05 06 07
152214158Sjhb
153152376Srwatson# Initialize all ports on a Cyclades-16ye.
15497993Sjhb# modem    c c  00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
15597993Sjhb
15697993Sjhb# Initialize all ports on a Digiboard 8.
157219311Sdchagin# modem    D D  00 01 02 03 04 05 06 07
15897993Sjhb