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