Subject: ntpd problems with GPS receiver under NetBSD-amd64
To: None <port-amd64@netbsd.org>
From: Alicia da Conceicao <alicia@engine.ca>
List: tech-net
Date: 02/02/2005 16:10:40
Greetings:

I have a GPS receiver with a TTL PPS feed, which I managed to successfully
wire up to a RS232 (DB9) serial port.  When I connect it to a NetBSD-amd64
version 2.0 computer running minicom at 4800 bps for tty02, I am able to
read all of the GPS data (including time, position, etc.) in the
raw NMEA-0183 strings.  So far so good right.

Note that the DB9 serial port was wired as follows (male view):

         ------------------------------------------
	\  [1-TTL] [2-TX] [3-RX] [4-???] [5-GND] /
          \    [6-???] [7-???] [8-???] [9-???]   /
           --------------------------------------

with the TTL on pin1, transmit on pin2, receive on pin3, and ground on
pin5.

Also note that NetBSD-amd64 2.0 kernel was compiled with the following
related options:

	options NTP
	options PPS_SYNC

Then I try to run it under ntpd version "4.2.0-r" with the following
config:

	pidfile /var/run/ntpd.pid
	driftfile /var/db/ntp.drift
	logconfig -syncstatus
	peer 127.127.20.0 prefer
	fudge 127.127.20.0 stratum 0
	fudge 127.127.20.0 time1 -1.0
	peer 127.127.22.0
	fudge 127.127.22.0 stratum 0
	fudge 127.127.22.0 flag2 0
	fudge 127.127.22.0 flag3 1

and with symlinks:

	/dev/gps0 => /dev/tty02
	/dev/pps0 => /dev/tty02

Unfortunately ntpd fails with the following errors:

	ioctl(TIOCSCTTY, 0) fails for clock I/O: Operation not permitted
	internal error: refclockio structure not found
	configuration of 127.127.20.0 failed
	reclock_atom: /dev/pps0: Interrupted system call
	configuration of 127.127.22.0 failed

I could understand if there where some ntpd related issues regarding the
NetBSD implimentation of PPS, even though I did enable it in the kernel.
But considering that I can see a continuous stream of NMEA strings being
sent by the GPS clock through the serial bus when I use minicom, I am at
a loss as to why ntpd is failing for the NMEA pseduo-port at 127.127.20.0.

Looking at the NetBSD kernel source code, the original of that EPERM errno
value outputed by ntpd appears to originate in "/usr/src/sys/kern/tty.c"
when ntpd attempts to do a "ioctl(rio->fd,TIOCSCTTY,0)" in "libntp/iosignal.c"
to become a controlling tty.

Any suggestions is greatly apprecated.

Thanks in advance.
Alicia.