1*0696600cSBjoern A. Zeeb#!/bin/sh 2*0696600cSBjoern A. Zeeb# 3*0696600cSBjoern A. Zeeb# Copyright (c) 1996 Andrey A. Chernov 4*0696600cSBjoern A. Zeeb# All rights reserved. 5*0696600cSBjoern A. Zeeb# 6*0696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without 7*0696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions 8*0696600cSBjoern A. Zeeb# are met: 9*0696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright 10*0696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer. 11*0696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright 12*0696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer in the 13*0696600cSBjoern A. Zeeb# documentation and/or other materials provided with the distribution. 14*0696600cSBjoern A. Zeeb# 15*0696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*0696600cSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*0696600cSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*0696600cSBjoern A. Zeeb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*0696600cSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*0696600cSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*0696600cSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*0696600cSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*0696600cSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*0696600cSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*0696600cSBjoern A. Zeeb# SUCH DAMAGE. 26*0696600cSBjoern A. Zeeb# 27*0696600cSBjoern A. Zeeb# $FreeBSD$ 28*0696600cSBjoern A. Zeeb# 29*0696600cSBjoern A. Zeeb 30*0696600cSBjoern A. Zeeb# PROVIDE: serial 31*0696600cSBjoern A. Zeeb# REQUIRE: root 32*0696600cSBjoern A. Zeeb# KEYWORD: nojail 33*0696600cSBjoern A. Zeeb 34*0696600cSBjoern A. Zeeb# Change some defaults for serial devices. 35*0696600cSBjoern A. Zeeb# Standard defaults are: 36*0696600cSBjoern A. Zeeb# dtrwait 300 drainwait `sysctl -n kern.drainwait` 37*0696600cSBjoern A. Zeeb# initial cflag from <sys/ttydefaults.h> = cread cs8 hupcl 38*0696600cSBjoern A. Zeeb# initial iflag, lflag and oflag all 0 39*0696600cSBjoern A. Zeeb# speed 9600 40*0696600cSBjoern A. Zeeb# special chars from <sys/ttydefaults.h> 41*0696600cSBjoern A. Zeeb# nothing locked 42*0696600cSBjoern A. Zeeb# except for serial consoles the initial iflag, lflag and oflag are from 43*0696600cSBjoern A. Zeeb# <sys/ttydefaults.h> and clocal is locked on. 44*0696600cSBjoern A. Zeeb 45*0696600cSBjoern A. Zeebdefault() { 46*0696600cSBjoern A. Zeeb # Reset everything changed by the other functions to initial defaults. 47*0696600cSBjoern A. Zeeb 48*0696600cSBjoern A. Zeeb dc=$1; shift # device name character 49*0696600cSBjoern A. Zeeb drainwait=`sysctl -n kern.drainwait` 50*0696600cSBjoern A. Zeeb 51*0696600cSBjoern A. Zeeb for i in $* 52*0696600cSBjoern A. Zeeb do 53*0696600cSBjoern A. Zeeb comcontrol /dev/tty${dc}${i} dtrwait 300 drainwait $drainwait 54*0696600cSBjoern A. Zeeb stty < /dev/tty${dc}${i}.init -clocal crtscts hupcl 9600 reprint ^R 55*0696600cSBjoern A. Zeeb stty < /dev/tty${dc}${i}.lock -clocal -crtscts -hupcl 0 56*0696600cSBjoern A. Zeeb stty < /dev/cua${dc}${i}.init -clocal crtscts hupcl 9600 reprint ^R 57*0696600cSBjoern A. Zeeb stty < /dev/cua${dc}${i}.lock -clocal -crtscts -hupcl 0 58*0696600cSBjoern A. Zeeb done 59*0696600cSBjoern A. Zeeb} 60*0696600cSBjoern A. Zeeb 61*0696600cSBjoern A. Zeebmaybe() { 62*0696600cSBjoern A. Zeeb # Special settings. 63*0696600cSBjoern A. Zeeb 64*0696600cSBjoern A. Zeeb dc=$1; shift 65*0696600cSBjoern A. Zeeb 66*0696600cSBjoern A. Zeeb for i in $* 67*0696600cSBjoern A. Zeeb do 68*0696600cSBjoern A. Zeeb # Don't use ^R; it breaks bash's ^R when typed ahead. 69*0696600cSBjoern A. Zeeb stty < /dev/tty${dc}${i}.init reprint undef 70*0696600cSBjoern A. Zeeb stty < /dev/cua${dc}${i}.init reprint undef 71*0696600cSBjoern A. Zeeb # Lock clocal off on dialin device for security. 72*0696600cSBjoern A. Zeeb stty < /dev/tty${dc}${i}.lock clocal 73*0696600cSBjoern A. Zeeb # Lock the speeds to use old binaries that don't support them. 74*0696600cSBjoern A. Zeeb # Any legal speed works to lock the initial speed. 75*0696600cSBjoern A. Zeeb stty < /dev/tty${dc}${i}.lock 300 76*0696600cSBjoern A. Zeeb stty < /dev/cua${dc}${i}.lock 300 77*0696600cSBjoern A. Zeeb done 78*0696600cSBjoern A. Zeeb} 79*0696600cSBjoern A. Zeeb 80*0696600cSBjoern A. Zeebmodem() { 81*0696600cSBjoern A. Zeeb # Modem that supports CTS and perhaps RTS handshaking. 82*0696600cSBjoern A. Zeeb 83*0696600cSBjoern A. Zeeb dc=$1; shift 84*0696600cSBjoern A. Zeeb 85*0696600cSBjoern A. Zeeb for i in $* 86*0696600cSBjoern A. Zeeb do 87*0696600cSBjoern A. Zeeb # may depend on modem 88*0696600cSBjoern A. Zeeb comcontrol /dev/tty${dc}${i} dtrwait 100 drainwait 180 89*0696600cSBjoern A. Zeeb # Lock crtscts on. 90*0696600cSBjoern A. Zeeb # Speed reasonable for V42bis. 91*0696600cSBjoern A. Zeeb stty < /dev/tty${dc}${i}.init crtscts 115200 92*0696600cSBjoern A. Zeeb stty < /dev/tty${dc}${i}.lock crtscts 93*0696600cSBjoern A. Zeeb stty < /dev/cua${dc}${i}.init crtscts 115200 94*0696600cSBjoern A. Zeeb stty < /dev/cua${dc}${i}.lock crtscts 95*0696600cSBjoern A. Zeeb done 96*0696600cSBjoern A. Zeeb} 97*0696600cSBjoern A. Zeeb 98*0696600cSBjoern A. Zeebmouse() { 99*0696600cSBjoern A. Zeeb # Mouse on either callin or callout port. 100*0696600cSBjoern A. Zeeb 101*0696600cSBjoern A. Zeeb dc=$1; shift 102*0696600cSBjoern A. Zeeb 103*0696600cSBjoern A. Zeeb for i in $* 104*0696600cSBjoern A. Zeeb do 105*0696600cSBjoern A. Zeeb # Lock clocal on, hupcl off. 106*0696600cSBjoern A. Zeeb # Standard speed for Microsoft mouse. 107*0696600cSBjoern A. Zeeb stty < /dev/tty${dc}${i}.init clocal -hupcl 1200 108*0696600cSBjoern A. Zeeb stty < /dev/tty${dc}${i}.lock clocal hupcl 109*0696600cSBjoern A. Zeeb stty < /dev/cua${dc}${i}.init clocal -hupcl 1200 110*0696600cSBjoern A. Zeeb stty < /dev/cua${dc}${i}.lock clocal hupcl 111*0696600cSBjoern A. Zeeb done 112*0696600cSBjoern A. Zeeb} 113*0696600cSBjoern A. Zeeb 114*0696600cSBjoern A. Zeebterminal() { 115*0696600cSBjoern A. Zeeb # Terminal that supports CTS and perhaps RTS handshaking 116*0696600cSBjoern A. Zeeb # with the cable or terminal arranged so that DCD is on 117*0696600cSBjoern A. Zeeb # at least while the terminal is on. 118*0696600cSBjoern A. Zeeb # Also works for bidirectional communications to another pc 119*0696600cSBjoern A. Zeeb # provided at most one side runs getty. 120*0696600cSBjoern A. Zeeb # Same as modem() except we want a faster speed and no dtrwait. 121*0696600cSBjoern A. Zeeb 122*0696600cSBjoern A. Zeeb dc=$1; shift 123*0696600cSBjoern A. Zeeb 124*0696600cSBjoern A. Zeeb modem ${dc} $* 125*0696600cSBjoern A. Zeeb for i in $* 126*0696600cSBjoern A. Zeeb do 127*0696600cSBjoern A. Zeeb comcontrol /dev/tty${dc}${i} dtrwait 0 128*0696600cSBjoern A. Zeeb stty < /dev/tty${dc}${i}.init 115200 129*0696600cSBjoern A. Zeeb stty < /dev/cua${dc}${i}.init 115200 130*0696600cSBjoern A. Zeeb done 131*0696600cSBjoern A. Zeeb} 132*0696600cSBjoern A. Zeeb 133*0696600cSBjoern A. Zeeb3wire() { 134*0696600cSBjoern A. Zeeb # 3-wire serial terminals. These don't supply carrier, so 135*0696600cSBjoern A. Zeeb # clocal needs to be set, and crtscts needs to be unset. 136*0696600cSBjoern A. Zeeb 137*0696600cSBjoern A. Zeeb dc=$1; shift 138*0696600cSBjoern A. Zeeb 139*0696600cSBjoern A. Zeeb terminal ${dc} $* 140*0696600cSBjoern A. Zeeb for i in $* 141*0696600cSBjoern A. Zeeb do 142*0696600cSBjoern A. Zeeb stty < /dev/tty${dc}${i}.init clocal -crtscts 143*0696600cSBjoern A. Zeeb stty < /dev/cua${dc}${i}.init clocal -crtscts 144*0696600cSBjoern A. Zeeb done 145*0696600cSBjoern A. Zeeb} 146*0696600cSBjoern A. Zeeb 147*0696600cSBjoern A. Zeeb# Don't use anything from this file unless you have some buggy programs 148*0696600cSBjoern A. Zeeb# that require it. 149*0696600cSBjoern A. Zeeb 150*0696600cSBjoern A. Zeeb# Edit the functions and the examples to suit your system. 151*0696600cSBjoern A. Zeeb# $1 is the device identifier, and the remainder of the line 152*0696600cSBjoern A. Zeeb# lists the device numbers. 153*0696600cSBjoern A. Zeeb 154*0696600cSBjoern A. Zeeb# Initialize assorted 8250-16550 (uart) ports. 155*0696600cSBjoern A. Zeeb# 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 156*0696600cSBjoern A. Zeeb# mouse u 2 157*0696600cSBjoern A. Zeeb# modem u 1 158*0696600cSBjoern A. Zeeb# terminal u 0 159*0696600cSBjoern A. Zeeb# 3wire u 0 160*0696600cSBjoern A. Zeeb 161*0696600cSBjoern A. Zeeb# Initialize all ports on a Cyclades-8yo. 162*0696600cSBjoern A. Zeeb# modem c 00 01 02 03 04 05 06 07 163*0696600cSBjoern A. Zeeb 164*0696600cSBjoern A. Zeeb# Initialize all ports on a Cyclades-16ye. 165*0696600cSBjoern A. Zeeb# modem c 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 166*0696600cSBjoern A. Zeeb 167*0696600cSBjoern A. Zeeb# Initialize all ports on a Digiboard 8. 168*0696600cSBjoern A. Zeeb# modem D 00 01 02 03 04 05 06 07 169