Subject: Serial Port Strangeness.
To: None <current-users@NetBSD.ORG>
From: Dave Burgess <burgess@cynjut.neonramp.com>
List: current-users
Date: 09/09/1997 13:11:39
I asked this on the port-i386 list, and got a couple of answers - one of
which makes me wonder it this might not be a problem across the
platforms.

I'm working on mgetty with the 1.2G tar 'non-release' from last month.
Whenever I use the TIOCMGET ioctl on the /dev/tty0* ports, I get an
[ENOTTY] error.  The rest of the TIO ioctls I tried all work (some of
them only sort of, but they don't error out).

The obvious stupid question is "if /dev/tty isn't a tty, what is?"
immediately leaps to mind.

kermit exhibits the same behavior:  when the command 'sho comm' is
issued, kermit dutifully shows the port information from the software
side, but fails to show the comm port line statuses.  This is a 'fairly'
recent change.  Does anyone have any insight (or a 'better solution')?

Here is a program I wrote to try out the problem. 

- - - - - - - -
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "tio.h"

int main(int argc, char *argv[]) {

int fd;
int flags;

	if (argc > 1) {
		fd = open(argv[1],O_RDWR|O_NONBLOCK,0);
	} else {
		fd = open("/dev/tty00",O_RDWR|O_NONBLOCK,0);
	}

	if (fd < 0) {
		printf("%s\n",strerror(errno));
	} else {
		printf("open succeeded\n");
	}
/* tio_get_rs232_lines()
 *
 * get the status of all RS232 status lines
 * (coded by the TIO_F_* flags. On systems that have the BSD TIOCM_*
 * flags, we use them, on others we may have to do some other tricks)
 *
 * "-1" can mean "error" or "not supported on this system" (e.g. SCO).
 */

    flags &= TIOCFLAG_SOFTCAR;
    flags &= TIOCFLAG_CLOCAL;
    flags &= TIOCFLAG_CRTSCTS;
    flags &= TIOCFLAG_MDMBUF;
    if ( ioctl(fd, TIOCSFLAGS, &flags ) < 0 ) {
    	printf("tio_get_rs232_lines: TIOCSFLAGS failed\n" );
	printf("%s\n",strerror(errno));
    } else {
    	printf("tio_get_rs232_lines: TIOCSFLAGS succeeded\n" );
    }
    flags = 0;
    if ( ioctl(fd, TIOCGFLAGS, &flags ) < 0 ) {
    	printf("tio_get_rs232_lines: TIOCGFLAGS failed\n" );
	printf("%s\n",strerror(errno));
    } else {
    	printf("tio_get_rs232_lines: TIOCGFLAGS succeeded\n" );
    }

    printf("tio_get_rs232_lines: flags:" );
    if ( flags & TIOCFLAG_SOFTCAR ) puts( " SOFTCAR" );
    if ( flags & TIOCFLAG_CLOCAL ) puts( " CLOCAL" );
    if ( flags & TIOCFLAG_CRTSCTS ) puts( " CRTSCTS" );
    if ( flags & TIOCFLAG_MDMBUF ) puts( " MDMBUF" );
    printf("\n");
    if ( ioctl(fd, TIOCMGET, &flags ) < 0 ) {
    	printf("tio_get_rs232_lines: TIOCMGET failed\n" );
	printf("%s\n",strerror(errno));
    }

    printf("tio_get_rs232_lines: status:" );
    if ( flags & TIOCM_RTS ) puts( " RTS" );
    if ( flags & TIOCM_CTS ) puts( " CTS" );
    if ( flags & TIOCM_DSR ) puts( " DSR" );
    if ( flags & TIOCM_DTR ) puts( " DTR" );
    if ( flags & TIOCM_CAR ) puts( " DCD" );
    if ( flags & TIOCM_RI  ) puts( " RI" );
    printf("\n");
    return flags;
}

- - - - - - end of segment - - - - - -
-- 
Dave Burgess                   Network Engineer - Nebraska On-Ramp, Inc.
*bsd FAQ Maintainer / SysAdmin for the NetBSD system in my spare bedroom
"Just because something is stupid doesn't mean there isn't someone that 
doesn't want to do it...."