serial revision 126744
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: head/etc/rc.d/serial 126744 2004-03-08 12:25:05Z pjd $
28#
29
30# PROVIDE: serial
31# REQUIRE: root
32# KEYWORD: FreeBSD 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	ci=$1; shift	# call in device identifier
49	co=$1; shift	# call out device identifier
50	drainwait=`sysctl -n kern.drainwait`
51
52	for i in $*
53	do
54		comcontrol /dev/tty${ci}${i} dtrwait 300 drainwait $drainwait
55		stty < /dev/ttyi${ci}${i} -clocal crtscts hupcl 9600 reprint ^R
56		stty < /dev/ttyl${ci}${i} -clocal -crtscts -hupcl 0
57		stty < /dev/cuai${co}${i} -clocal crtscts hupcl 9600 reprint ^R
58		stty < /dev/cual${co}${i} -clocal -crtscts -hupcl 0
59	done
60}
61
62maybe() {
63	# Special settings.
64
65	ci=$1; shift
66	co=$1; shift
67
68	for i in $*
69	do
70		# Don't use ^R; it breaks bash's ^R when typed ahead.
71		stty < /dev/ttyi${ci}${i} reprint undef
72		stty < /dev/cuai${co}${i} reprint undef
73		# Lock clocal off on dialin device for security.
74		stty < /dev/ttyl${ci}${i} clocal
75		# Lock the speeds to use old binaries that don't support them.
76		# Any legal speed works to lock the initial speed.
77		stty < /dev/ttyl${ci}${i} 300
78		stty < /dev/cual${co}${i} 300
79	done
80}
81
82modem() {
83	# Modem that supports CTS and perhaps RTS handshaking.
84
85	ci=$1; shift
86	co=$1; shift
87
88	for i in $*
89	do
90		# may depend on modem
91		comcontrol /dev/tty${ci}${i} dtrwait 100 drainwait 180
92		# Lock crtscts on.
93		# Speed reasonable for V42bis.
94		stty < /dev/ttyi${ci}${i} crtscts 115200
95		stty < /dev/ttyl${ci}${i} crtscts
96		stty < /dev/cuai${co}${i} crtscts 115200
97		stty < /dev/cual${co}${i} crtscts
98	done
99}
100
101mouse() {
102	# Mouse on either callin or callout port.
103
104	ci=$1; shift
105	co=$1; shift
106
107	for i in $*
108	do
109		# Lock clocal on, hupcl off.
110		# Standard speed for Microsoft mouse.
111		stty < /dev/ttyi${ci}${i} clocal -hupcl 1200
112		stty < /dev/ttyl${ci}${i} clocal  hupcl
113		stty < /dev/cuai${co}${i} clocal -hupcl 1200
114		stty < /dev/cual${co}${i} clocal  hupcl
115	done
116}
117
118terminal() {
119	# Terminal that supports CTS and perhaps RTS handshaking
120	# with the cable or terminal arranged so that DCD is on
121	# at least while the terminal is on.
122	# Also works for bidirectional communications to another pc
123	# provided at most one side runs getty.
124	# Same as modem() except we want a faster speed and no dtrwait.
125
126	ci=$1; shift
127	co=$1; shift
128
129	modem ${ci} ${co} $*
130	for i in $*
131	do
132		comcontrol /dev/tty${ci}${i} dtrwait 0
133		stty < /dev/ttyi${ci}${i} 115200
134		stty < /dev/cuai${co}${i} 115200
135	done
136}
137
138# Don't use anything from this file unless you have some buggy programs
139# that require it.
140
141# Edit the functions and the examples to suit your system.
142# $1 is the call in device identifier, $2 is the call out device identifier
143# and the remainder of the line lists the device numbers.
144
145# Initialize assorted 8250-16550 (sio) ports.
146# 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
147# mouse    d a      2
148# modem    d a    1
149# terminal d a  0
150
151# Initialize all ports on a Cyclades-8yo.
152# modem    c c  00 01 02 03 04 05 06 07
153
154# Initialize all ports on a Cyclades-16ye.
155# modem    c c  00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
156
157# Initialize all ports on a Digiboard 8.
158# modem    D D  00 01 02 03 04 05 06 07
159