serial revision 100280
1266423Sjfv#!/bin/sh 2266423Sjfv# 3333343Serj# Copyright (c) 1996 Andrey A. Chernov 4266423Sjfv# All rights reserved. 5266423Sjfv# 6266423Sjfv# Redistribution and use in source and binary forms, with or without 7266423Sjfv# modification, are permitted provided that the following conditions 8266423Sjfv# are met: 9266423Sjfv# 1. Redistributions of source code must retain the above copyright 10266423Sjfv# notice, this list of conditions and the following disclaimer. 11266423Sjfv# 2. Redistributions in binary form must reproduce the above copyright 12266423Sjfv# notice, this list of conditions and the following disclaimer in the 13266423Sjfv# documentation and/or other materials provided with the distribution. 14266423Sjfv# 15266423Sjfv# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16266423Sjfv# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17266423Sjfv# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18266423Sjfv# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19266423Sjfv# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20266423Sjfv# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21266423Sjfv# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22266423Sjfv# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23266423Sjfv# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24266423Sjfv# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25266423Sjfv# SUCH DAMAGE. 26266423Sjfv# 27266423Sjfv# $FreeBSD: head/etc/rc.d/serial 100280 2002-07-18 05:00:17Z gordon $ 28266423Sjfv# 29266423Sjfv 30266423Sjfv# PROVIDE: serial 31266423Sjfv# REQUIRE: root 32266423Sjfv# KEYWORD: FreeBSD 33266423Sjfv 34266423Sjfv# Change some defaults for serial devices. 35270346Sjfv# Standard defaults are: 36270346Sjfv# dtrwait 300 drainwait 0 37269198Sjfv# initial cflag from <sys/ttydefaults.h> = cread cs8 hupcl 38318357Serj# initial iflag, lflag and oflag all 0 39318357Serj# speed 9600 40318357Serj# special chars from <sys/ttydefaults.h> 41318357Serj# nothing locked 42318357Serj# except for serial consoles the initial iflag, lflag and oflag are from 43303967Ssbruno# <sys/ttydefaults.h> and clocal is locked on. 44303967Ssbruno 45277262Sjfvdefault() { 46277262Sjfv # Reset everything changed by the other functions to initial defaults. 47266423Sjfv 48266423Sjfv ci=$1; shift # call in device identifier 49266423Sjfv co=$1; shift # call out device identifier 50333343Serj 51333343Serj for i in $* 52333343Serj do 53266423Sjfv comcontrol /dev/tty${ci}${i} dtrwait 300 drainwait 300 54333343Serj stty < /dev/ttyi${ci}${i} -clocal crtscts hupcl 9600 reprint ^R 55333343Serj stty < /dev/ttyl${ci}${i} -clocal -crtscts -hupcl 0 56333343Serj stty < /dev/cuai${co}${i} -clocal crtscts hupcl 9600 reprint ^R 57333343Serj stty < /dev/cual${co}${i} -clocal -crtscts -hupcl 0 58266423Sjfv done 59266423Sjfv} 60266423Sjfv 61266423Sjfvmaybe() { 62270346Sjfv # Special settings. 63266423Sjfv 64266423Sjfv ci=$1; shift 65266423Sjfv co=$1; shift 66266423Sjfv 67266423Sjfv for i in $* 68270346Sjfv do 69266423Sjfv # Don't use ^R; it breaks bash's ^R when typed ahead. 70266423Sjfv stty < /dev/ttyi${ci}${i} reprint undef 71266423Sjfv stty < /dev/cuai${co}${i} reprint undef 72266423Sjfv # Lock clocal off on dialin device for security. 73266423Sjfv stty < /dev/ttyl${ci}${i} clocal 74266423Sjfv # Lock the speeds to use old binaries that don't support them. 75266423Sjfv # Any legal speed works to lock the initial speed. 76270346Sjfv stty < /dev/ttyl${ci}${i} 300 77284049Sjfv stty < /dev/cual${co}${i} 300 78303967Ssbruno done 79303967Ssbruno} 80303967Ssbruno 81303967Ssbrunomodem() { 82303967Ssbruno # Modem that supports CTS and perhaps RTS handshaking. 83303967Ssbruno 84318357Serj ci=$1; shift 85318357Serj co=$1; shift 86266423Sjfv 87266423Sjfv for i in $* 88266423Sjfv do 89266423Sjfv # may depend on modem 90266423Sjfv comcontrol /dev/tty${ci}${i} dtrwait 100 drainwait 180 91266423Sjfv # Lock crtscts on. 92266423Sjfv # Speed reasonable for V42bis. 93266423Sjfv stty < /dev/ttyi${ci}${i} crtscts 57600 94270346Sjfv stty < /dev/ttyl${ci}${i} crtscts 95333343Serj stty < /dev/cuai${co}${i} crtscts 57600 96266423Sjfv stty < /dev/cual${co}${i} crtscts 97266423Sjfv done 98266423Sjfv} 99266423Sjfv 100266423Sjfvmouse() { 101266423Sjfv # Mouse on either callin or callout port. 102270346Sjfv 103270346Sjfv ci=$1; shift 104270346Sjfv co=$1; shift 105270346Sjfv 106299553Serj for i in $* 107303967Ssbruno do 108299553Serj # Lock clocal on, hupcl off. 109266423Sjfv # Standard speed for Microsoft mouse. 110266423Sjfv stty < /dev/ttyi${ci}${i} clocal -hupcl 1200 111266423Sjfv stty < /dev/ttyl${ci}${i} clocal hupcl 112266423Sjfv stty < /dev/cuai${co}${i} clocal -hupcl 1200 113270346Sjfv stty < /dev/cual${co}${i} clocal hupcl 114266423Sjfv done 115270346Sjfv} 116270346Sjfv 117270346Sjfvterminal() { 118270346Sjfv # Terminal that supports CTS and perhaps RTS handshaking 119279858Sjfv # with the cable or terminal arranged so that DCD is on 120299546Serj # at least while the terminal is on. 121299546Serj # Also works for bidirectional communications to another pc 122299546Serj # provided at most one side runs getty. 123279858Sjfv # Same as modem() except we want a faster speed and no dtrwait. 124266423Sjfv 125266423Sjfv ci=$1; shift 126266423Sjfv co=$1; shift 127270346Sjfv 128270346Sjfv modem ${ci} ${co} $* 129266423Sjfv for i in $* 130266423Sjfv do 131270346Sjfv comcontrol /dev/tty${ci}${i} dtrwait 0 132270346Sjfv stty < /dev/ttyi${ci}${i} 115200 133266423Sjfv stty < /dev/cuai${co}${i} 115200 134318357Serj done 135318357Serj} 136270346Sjfv 137270346Sjfv# Don't use anything from this file unless you have some buggy programs 138318357Serj# that require it. 139279860Sjfv 140279860Sjfv# Edit the functions and the examples to suit your system. 141279860Sjfv# $1 is the call in device identifier, $2 is the call out device identifier 142266423Sjfv# and the remainder of the line lists the device numbers. 143270346Sjfv 144270346Sjfv# Initialize assorted 8250-16550 (sio) ports. 145270346Sjfv# 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 146270346Sjfv# mouse d a 2 147270346Sjfv# modem d a 1 148270346Sjfv# terminal d a 0 149270346Sjfv 150266423Sjfv# Initialize all ports on a Cyclades-8yo. 151266423Sjfv# modem c c 00 01 02 03 04 05 06 07 152266423Sjfv 153270346Sjfv# Initialize all ports on a Cyclades-16ye. 154270346Sjfv# modem c c 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 155270346Sjfv 156270346Sjfv# Initialize all ports on a Digiboard 8. 157266423Sjfv# modem D D 00 01 02 03 04 05 06 07 158266423Sjfv