serial revision 180619
12061Sjkh#!/bin/sh 250479Speter# 32061Sjkh# Copyright (c) 1996 Andrey A. Chernov 438666Sjb# All rights reserved. 532427Sjb# 638666Sjb# Redistribution and use in source and binary forms, with or without 738666Sjb# modification, are permitted provided that the following conditions 838666Sjb# are met: 938666Sjb# 1. Redistributions of source code must retain the above copyright 1038666Sjb# notice, this list of conditions and the following disclaimer. 1144918Sjkh# 2. Redistributions in binary form must reproduce the above copyright 1238666Sjb# notice, this list of conditions and the following disclaimer in the 1338666Sjb# documentation and/or other materials provided with the distribution. 1438666Sjb# 1538666Sjb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1638666Sjb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1738666Sjb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1838666Sjb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1938978Sjb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2038978Sjb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2132427Sjb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2238666Sjb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2338666Sjb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2438666Sjb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2538666Sjb# SUCH DAMAGE. 2638666Sjb# 2738666Sjb# $FreeBSD: head/etc/rc.d/serial 180619 2008-07-19 20:12:02Z marcel $ 2817308Speter# 2938666Sjb 3038666Sjb# PROVIDE: serial 3138666Sjb# REQUIRE: root 3219175Sbde# KEYWORD: nojail 3338666Sjb 3438666Sjb# Change some defaults for serial devices. 3538042Sbde# Standard defaults are: 3639726Sjb# dtrwait 300 drainwait `sysctl -n kern.drainwait` 3738666Sjb# initial cflag from <sys/ttydefaults.h> = cread cs8 hupcl 3838666Sjb# initial iflag, lflag and oflag all 0 3938042Sbde# speed 9600 4038666Sjb# special chars from <sys/ttydefaults.h> 4149315Shoek# nothing locked 4217308Speter# except for serial consoles the initial iflag, lflag and oflag are from 4338666Sjb# <sys/ttydefaults.h> and clocal is locked on. 4438666Sjb 4538666Sjbdefault() { 4638666Sjb # Reset everything changed by the other functions to initial defaults. 4717308Speter 4845108Sobrien dc=$1; shift # device name character 4942128Speter drainwait=`sysctl -n kern.drainwait` 5042128Speter 5138666Sjb for i in $* 5251361Sjb do 5338666Sjb comcontrol /dev/tty${dc}${i} dtrwait 300 drainwait $drainwait 5417308Speter stty < /dev/tty${dc}${i}.init -clocal crtscts hupcl 9600 reprint ^R 5538666Sjb stty < /dev/tty${dc}${i}.lock -clocal -crtscts -hupcl 0 5617308Speter stty < /dev/cua${dc}${i}.init -clocal crtscts hupcl 9600 reprint ^R 5738666Sjb stty < /dev/cua${dc}${i}.lock -clocal -crtscts -hupcl 0 5817308Speter done 5927910Sasami} 6043226Sjkh 6143226Sjkhmaybe() { 6243226Sjkh # Special settings. 6338666Sjb 6427910Sasami dc=$1; shift 6538666Sjb 6638666Sjb for i in $* 6738666Sjb do 6827910Sasami # Don't use ^R; it breaks bash's ^R when typed ahead. 6938666Sjb stty < /dev/tty${dc}${i}.init reprint undef 7038666Sjb stty < /dev/cua${dc}${i}.init reprint undef 7143226Sjkh # Lock clocal off on dialin device for security. 7243226Sjkh stty < /dev/tty${dc}${i}.lock clocal 7327910Sasami # Lock the speeds to use old binaries that don't support them. 7438666Sjb # Any legal speed works to lock the initial speed. 7538666Sjb stty < /dev/tty${dc}${i}.lock 300 7627910Sasami stty < /dev/cua${dc}${i}.lock 300 7738666Sjb done 7827910Sasami} 7917308Speter 8038666Sjbmodem() { 8138666Sjb # Modem that supports CTS and perhaps RTS handshaking. 8217308Speter 8340495Sbde dc=$1; shift 8440495Sbde 8540495Sbde for i in $* 8654324Smarcel do 872061Sjkh # may depend on modem 8854324Smarcel comcontrol /dev/tty${dc}${i} dtrwait 100 drainwait 180 8954324Smarcel # Lock crtscts on. 9017308Speter # Speed reasonable for V42bis. 9138666Sjb stty < /dev/tty${dc}${i}.init crtscts 115200 9217308Speter stty < /dev/tty${dc}${i}.lock crtscts 9338666Sjb stty < /dev/cua${dc}${i}.init crtscts 115200 9438666Sjb stty < /dev/cua${dc}${i}.lock crtscts 9554324Smarcel done 962302Spaul} 9739206Sjkh 9839206Sjkhmouse() { 9939206Sjkh # Mouse on either callin or callout port. 10054324Smarcel 10117308Speter dc=$1; shift 10254324Smarcel 10354324Smarcel for i in $* 10454324Smarcel do 10554324Smarcel # Lock clocal on, hupcl off. 10654324Smarcel # Standard speed for Microsoft mouse. 10754324Smarcel stty < /dev/tty${dc}${i}.init clocal -hupcl 1200 10854324Smarcel stty < /dev/tty${dc}${i}.lock clocal hupcl 10954324Smarcel stty < /dev/cua${dc}${i}.init clocal -hupcl 1200 11054324Smarcel stty < /dev/cua${dc}${i}.lock clocal hupcl 11154324Smarcel done 11254324Smarcel} 11354324Smarcel 11454324Smarcelterminal() { 11554324Smarcel # Terminal that supports CTS and perhaps RTS handshaking 11654324Smarcel # with the cable or terminal arranged so that DCD is on 11754324Smarcel # at least while the terminal is on. 11854324Smarcel # Also works for bidirectional communications to another pc 11954324Smarcel # provided at most one side runs getty. 12054324Smarcel # Same as modem() except we want a faster speed and no dtrwait. 12154324Smarcel 12254324Smarcel dc=$1; shift 12354324Smarcel 12454324Smarcel modem ${dc} $* 12554324Smarcel for i in $* 12654324Smarcel do 12754324Smarcel comcontrol /dev/tty${dc}${i} dtrwait 0 12854324Smarcel stty < /dev/tty${dc}${i}.init 115200 12954324Smarcel stty < /dev/cua${dc}${i}.init 115200 13054324Smarcel done 13154324Smarcel} 13254324Smarcel 13354324Smarcel3wire() { 13438666Sjb # 3-wire serial terminals. These don't supply carrier, so 13538666Sjb # clocal needs to be set, and crtscts needs to be unset. 13617308Speter 13738666Sjb dc=$1; shift 13838666Sjb 13938666Sjb terminal ${dc} $* 14017308Speter for i in $* 14138666Sjb do 14244103Smsmith stty < /dev/tty${dc}${i}.init clocal -crtscts 1432061Sjkh stty < /dev/cua${dc}${i}.init clocal -crtscts 14417308Speter done 14538666Sjb} 14638666Sjb 14717308Speter# Don't use anything from this file unless you have some buggy programs 14838666Sjb# that require it. 1493626Swollman 15017308Speter# Edit the functions and the examples to suit your system. 15138666Sjb# $1 is the device identifier, and the remainder of the line 15238666Sjb# lists the device numbers. 15317308Speter 15438978Sjb# Initialize assorted 8250-16550 (uart) ports. 15538978Sjb# 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 1563626Swollman# mouse u 2 15717308Speter# modem u 1 15838666Sjb# terminal u 0 15917308Speter# 3wire u 0 16043226Sjkh 16143226Sjkh# Initialize all ports on a Cyclades-8yo. 16243226Sjkh# modem c 00 01 02 03 04 05 06 07 16338666Sjb 16438666Sjb# Initialize all ports on a Cyclades-16ye. 16544103Smsmith# modem c 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 166 167# Initialize all ports on a Digiboard 8. 168# modem D 00 01 02 03 04 05 06 07 169