autobauding on UNIX?

Jim McKie jim at mcvax.UUCP
Wed Nov 23 22:40:08 AEST 1983


We don't have any terminals/modems/diallers/etc. on our machines,
everything is attached to a Micom portselector. So we have autobaud
detection in getty. Originally done by mcvax!piet, added to 4.2BSD
by me. Here is a diff of the source with the original, followed by
a copy of /etc/gettytab. It isn't hard to fit it into a non-4.2BSD.

Jim McKie	Mathematisch Centrum, Amsterdam		....mcvax!jim
======================================================================

diff -c ./gettytab.h /usr/src/local/etc/getty/gettytab.h
*** ./gettytab.h	Sun Jul 10 03:35:15 1983
--- /usr/src/local/etc/getty/gettytab.h	Sun Sep 18 13:13:13 1983
***************
*** 97,102
  #define	PS	gettyflags[16].value
  #define	HC	gettyflags[17].value
  #define UB	gettyflags[18].value
  
  int	getent();
  long	getnum();

--- 97,105 -----
  #define	PS	gettyflags[16].value
  #define	HC	gettyflags[17].value
  #define UB	gettyflags[18].value
+ #ifdef MCVAX
+ #define AB	gettyflags[19].value
+ #endif MCVAX
  
  int	getent();
  long	getnum();
diff -c ./init.c /usr/src/local/etc/getty/init.c
*** ./init.c	Sun Jul 10 03:35:16 1983
--- /usr/src/local/etc/getty/init.c	Sun Sep 18 13:13:13 1983
***************
*** 80,84
  	{ "ps",	0 },			/* do port selector speed select */
  	{ "hc",	1 },			/* don't set hangup on close */
  	{ "ub", 0 },			/* unbuffered output */
  	{ 0 }
  };

--- 80,87 -----
  	{ "ps",	0 },			/* do port selector speed select */
  	{ "hc",	1 },			/* don't set hangup on close */
  	{ "ub", 0 },			/* unbuffered output */
+ #ifdef MCVAX
+ 	{ "ab", 0 },			/* auto-baud detect with '\r' */
+ #endif MCVAX
  	{ 0 }
  };
diff -c ./main.c /usr/src/local/etc/getty/main.c
*** ./main.c	Tue Aug  2 01:07:07 1983
--- /usr/src/local/etc/getty/main.c	Sun Sep 18 13:13:13 1983
***************
*** 128,133
  		ioctl(0, TIOCSETD, &ldisp);
  		if (HC)
  			ioctl(0, TIOCHPCL, 0);
  		if (PS) {
  			tname = portselector();
  			continue;

--- 128,141 -----
  		ioctl(0, TIOCSETD, &ldisp);
  		if (HC)
  			ioctl(0, TIOCHPCL, 0);
+ #ifdef MCVAX
+ 		if (AB) {
+ 			extern char *autobaud();
+ 
+ 			tname = autobaud();
+ 			continue;
+ 		}
+ #endif MCVAX
  		if (PS) {
  			tname = portselector();
  			continue;
diff -c ./subr.c /usr/src/local/etc/getty/subr.c
*** ./subr.c	Thu Jul  7 12:32:55 1983
--- /usr/src/local/etc/getty/subr.c	Tue Oct 11 10:09:55 1983
***************
*** 406,408
  	sleep(2);	/* wait for connection to complete */
  	return (type);
  }

--- 406,463 -----
  	sleep(2);	/* wait for connection to complete */
  	return (type);
  }
+ 
+ #ifdef MCVAX
+ /*
+  * This auto-baud speed select machanism is written for the Micom 600
+  * portselector. Selection is done by looking at how the character '\r'
+  * is garbled at the different speeds.
+  */
+ #include <sys/time.h>
+ 
+ char *
+ autobaud()
+ {
+ 	int rfds;
+ 	struct timeval timeout;
+ 	char c, *type = "2400-baud";
+ 	int null = 0;
+ 
+ 	ioctl(0, TIOCFLUSH, &null);
+ 	rfds = 1 << 0;
+ 	timeout.tv_sec = 5;
+ 	timeout.tv_usec = 0;
+ 	if(select(32, &rfds, (int *)0, (int *)0, &timeout) <= 0)
+ 		return(type);
+ 	if(read(0, &c, sizeof(char)) != sizeof(char))
+ 		return(type);
+ 	timeout.tv_sec = 0;
+ 	timeout.tv_usec = 20;
+ 	(void) select(32, (int *)0, (int *)0, (int *)0, &timeout);
+ 	ioctl(0, TIOCFLUSH, &null);
+ 	switch(c&0377){
+ 
+ 	case 0200:		/* 300-baud */
+ 		type = "300-baud";
+ 		break;
+ 
+ 	case 0346:		/* 1200-baud */
+ 		type = "1200-baud";
+ 		break;
+ 
+ 	case  015:		/* 2400-baud */
+ 	case 0215:
+ 		type = "2400-baud";
+ 		break;
+ 
+ 	default:		/* 4800-baud */
+ 		type = "4800-baud";
+ 		break;
+ 
+ 	case 0377:		/* 9600-baud */
+ 		type = "9600-baud";
+ 		break;
+ 	}
+ 	return(type);
+ }
+ #endif MCVAX
===========================================================================
/etc/gettytab
===========================================================================
#
# Mathematisch Centrum gettytab.
#

#
# The default gettytab entry, used to set defaults for all other
# entries, and in cases where getty is called with no table name
#
default:\
	:ap:er=^H:kl=^X:in=\177:sp#2400:cd#3:im=\r\n%h\r\n\007:

#
# Auto-baud speed detect entry for Micom 600.
# Special code in getty will switch this out
# to one of the other entries.
#
A|Auto-baud:\
	:ab:sp#2400:f0#040:

#
# Other general speed tables. These can be cycled-round
# by using "break" (watch on the Micom!).
# The names "SPEED-baud" are also known to the special
# code in getty for auto-baud.
#
B|300-baud:\
	:nx=9600-baud:cd@:sp#300:
C|1200-baud:\
	:nx=300-baud:cd@:sp#1200:
D|2400-baud:\
	:nx=1200-baud:
E|4800-baud:\
	:nx=2400-baud:cd@:sp#4800:
F|9600-baud:\
	:nx=4800-baud:cd@:sp#9600:

#
# Fixed-speed dialup lines.
#
H|Dialup-1200:\
	:cd@:sp#1200:
L|Dialup-300:\
	:cd@:sp#300:

#
# Console Decwriter-III
#
c|Console|Console Decwriter III:\
	:cd@:fd#1:ht:



More information about the Comp.unix.wizards mailing list