summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2006-04-27 19:30:29 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2006-04-27 19:30:29 +0000
commita15426ecd54ac6bd38f84c977ce6e8dd09f7d5cf (patch)
treed4d7a62f135a86b94cb7e3e5d07c66c18f4712d7
parent17eb13c151eb29a4a105173e61a3c689ddc93077 (diff)
create a (very simple) method for timestamping CTS & DCD events on ttys,
using ioctl TIOCSTSTAMP & TIOCGTSTAMP. to be used later for gps monitoring type things; ok kettenis miod
-rw-r--r--share/man/man4/tty.419
-rw-r--r--sys/kern/tty.c42
-rw-r--r--sys/sys/tty.h9
-rw-r--r--sys/sys/ttycom.h9
4 files changed, 75 insertions, 4 deletions
diff --git a/share/man/man4/tty.4 b/share/man/man4/tty.4
index 0964b5790a5..92ab55c0dd6 100644
--- a/share/man/man4/tty.4
+++ b/share/man/man4/tty.4
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tty.4,v 1.25 2005/04/08 19:48:13 jmc Exp $
+.\" $OpenBSD: tty.4,v 1.26 2006/04/27 19:30:27 deraadt Exp $
.\" $NetBSD: tty.4,v 1.4 1996/03/19 04:26:01 paulus Exp $
.\"
.\" Copyright (c) 1991, 1992, 1993
@@ -437,6 +437,23 @@ represent modem state as described above; however, each bit which is on
in
.Fa state
is cleared in the terminal.
+.It Dv TIOCGTSTAMP Fa struct timeval *timeval
+Return the (single) timestamp.
+.It Dv TIOCSTSTAMP Fa struct tstamp *tstamps
+Chooses the conditions which will cause the current system time to be
+immediately copied to the terminal timestamp storage.
+This is often used to determine exactly the moment at which one or
+more of these events occurred, though only one can be monitored.
+Only
+.Dv TIOCM_CTS
+and
+.Dv TIOCM_CAR
+are honoured in
+.Va tstamps.ts_set
+and
+.Va tstamps.ts_clr ;
+these indicate which raising and lowering events on the respective lines
+should cause a timestamp capture.
.It Dv TIOCSFLAGS Fa int *state
The bits in the integer pointed to by
.Fa state
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index a4196c475fb..6e64e24c672 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.69 2005/12/21 12:43:49 jsg Exp $ */
+/* $OpenBSD: tty.c,v 1.70 2006/04/27 19:30:28 deraadt Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
@@ -835,6 +835,11 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
case TIOCGWINSZ: /* get window size */
*(struct winsize *)data = tp->t_winsize;
break;
+ case TIOCGTSTAMP:
+ s = spltty();
+ *(struct timeval *)data = tp->t_tv;
+ splx(s);
+ break;
case TIOCGPGRP: /* get pgrp of tty */
if (!isctty(p, tp) && suser(p, 0))
return (ENOTTY);
@@ -1006,6 +1011,25 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
pgsignal(tp->t_pgrp, SIGWINCH, 1);
}
break;
+ case TIOCSTSTAMP: {
+ struct tstamps *ts = (struct tstamps *)data;
+
+ s = spltty();
+ CLR(tp->t_flags, TS_TSTAMPDCDSET);
+ CLR(tp->t_flags, TS_TSTAMPCTSSET);
+ CLR(tp->t_flags, TS_TSTAMPDCDCLR);
+ CLR(tp->t_flags, TS_TSTAMPCTSCLR);
+ if (ISSET(ts->ts_set, TIOCM_CAR))
+ SET(tp->t_flags, TS_TSTAMPDCDSET);
+ if (ISSET(ts->ts_set, TIOCM_CTS))
+ SET(tp->t_flags, TS_TSTAMPCTSSET);
+ if (ISSET(ts->ts_clr, TIOCM_CAR))
+ SET(tp->t_flags, TS_TSTAMPDCDCLR);
+ if (ISSET(ts->ts_clr, TIOCM_CTS))
+ SET(tp->t_flags, TS_TSTAMPCTSCLR);
+ splx(s);
+ break;
+ }
default:
#ifdef COMPAT_OLDTTY
return (ttcompat(tp, cmd, data, flag, p));
@@ -2315,3 +2339,19 @@ sysctl_tty(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
}
/* NOTREACHED */
}
+
+void
+ttytstamp(struct tty *tp, int octs, int ncts, int odcd, int ndcd)
+{
+ int doit = 0;
+
+ if (ncts ^ octs) {
+ doit = (ncts && ISSET(tp->t_flags, TS_TSTAMPCTSSET)) ||
+ (!ncts && ISSET(tp->t_flags, TS_TSTAMPCTSCLR));
+ } else if (ndcd ^ odcd) {
+ doit = (ndcd && ISSET(tp->t_flags, TS_TSTAMPDCDSET)) ||
+ (!ndcd && ISSET(tp->t_flags, TS_TSTAMPDCDCLR));
+ }
+ if (doit)
+ microtime(&tp->t_tv);
+}
diff --git a/sys/sys/tty.h b/sys/sys/tty.h
index d2af7c8e052..5f884ef0bdd 100644
--- a/sys/sys/tty.h
+++ b/sys/sys/tty.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.h,v 1.20 2005/11/21 18:16:46 millert Exp $ */
+/* $OpenBSD: tty.h,v 1.21 2006/04/27 19:30:28 deraadt Exp $ */
/* $NetBSD: tty.h,v 1.30.4.1 1996/06/02 09:08:13 mrg Exp $ */
/*-
@@ -130,6 +130,7 @@ struct tty {
short t_lowat; /* Low water mark. */
short t_gen; /* Generation number. */
struct timeout t_rstrt_to; /* restart timeout */
+ struct timeval t_tv; /* timestamp */
};
/*
@@ -194,6 +195,11 @@ struct itty {
#define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */
#define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
+#define TS_TSTAMPDCDSET 0x10000 /* update timestamp on DCD set */
+#define TS_TSTAMPDCDCLR 0x20000 /* update timestamp on DCD clr */
+#define TS_TSTAMPCTSSET 0x40000 /* update timestamp on CTS set */
+#define TS_TSTAMPCTSCLR 0x80000 /* update timestamp on CTS clr */
+
/* Character type information. */
#define ORDINARY 0
#define CONTROL 1
@@ -286,6 +292,7 @@ int ttysleep(struct tty *tp,
void *chan, int pri, char *wmesg, int timeout);
int ttywait(struct tty *tp);
int ttywflush(struct tty *tp);
+void ttytstamp(struct tty *tp, int octs, int ncts, int odcd, int ndcd);
void tty_init(void);
struct tty *ttymalloc(void);
diff --git a/sys/sys/ttycom.h b/sys/sys/ttycom.h
index 017a4abec78..ad0f3579d1e 100644
--- a/sys/sys/ttycom.h
+++ b/sys/sys/ttycom.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ttycom.h,v 1.6 2003/06/02 23:28:22 millert Exp $ */
+/* $OpenBSD: ttycom.h,v 1.7 2006/04/27 19:30:28 deraadt Exp $ */
/* $NetBSD: ttycom.h,v 1.4 1996/05/19 17:17:53 jonathan Exp $ */
/*-
@@ -58,6 +58,11 @@ struct winsize {
unsigned short ws_ypixel; /* vertical size, pixels */
};
+struct tstamps {
+ int ts_set; /* TIOCM_CAR and/or TIOCM_CTS */
+ int ts_clr;
+};
+
#define TIOCM_LE 0001 /* line enable */
#define TIOCM_DTR 0002 /* data terminal ready */
#define TIOCM_RTS 0004 /* request to send */
@@ -125,6 +130,8 @@ struct winsize {
#define TIOCFLAG_CRTSCTS 0x04 /* set crtscts on open */
#define TIOCFLAG_MDMBUF 0x08 /* set mdmbuf on open */
#define TIOCFLAG_PPS 0x10 /* call hardpps on carrier up */
+#define TIOCGTSTAMP _IOR('t', 91, struct timeval) /* get timestamp */
+#define TIOCSTSTAMP _IOW('t', 90, struct tstamps) /* timestamp reasons */
/* Backwards compatibility */
#define TIOCMODG TIOCMGET