aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/snp/snp.c81
-rw-r--r--sys/kern/tty.c14
-rw-r--r--sys/kern/tty_snoop.c81
-rw-r--r--sys/sys/snoop.h13
4 files changed, 166 insertions, 23 deletions
diff --git a/sys/dev/snp/snp.c b/sys/dev/snp/snp.c
index 553b5c252ed6..e36af000a998 100644
--- a/sys/dev/snp/snp.c
+++ b/sys/dev/snp/snp.c
@@ -49,6 +49,52 @@ devtotty (dev)
return (*cdevsw[major(dev)].d_devtotty)(dev);
}
+#define SNP_INPUT_BUF 5 /* This is even too much,the maximal
+ * interactive mode write is 3 bytes
+ * length for function keys...
+ */
+
+int
+snpwrite(dev, uio, flag)
+ dev_t dev;
+ struct uio *uio;
+ int flag;
+{
+ int unit = minor(dev), len, i, error;
+ struct snoop *snp = &snoopsw[unit];
+ struct tty *tp;
+ char c[SNP_INPUT_BUF];
+
+ if (snp->snp_tty == NULL)
+ return (EIO);
+
+ tp = snp->snp_tty;
+
+ if ((tp->t_sc == snp) && (tp->t_state & TS_SNOOP) &&
+ (tp->t_line == OTTYDISC || tp->t_line == NTTYDISC))
+ goto tty_input;
+
+ printf("Snoop: attempt to write to bad tty.\n");
+ return (EIO);
+
+tty_input:
+ if (!(tp->t_state & TS_ISOPEN))
+ return (EIO);
+
+ while (uio->uio_resid > 0) {
+ len = MIN(uio->uio_resid,SNP_INPUT_BUF);
+ if ((error = uiomove(c, len, uio)) != 0)
+ return (error);
+ for (i=0;i<len;i++) {
+ if (ttyinput(c[i] , tp))
+ return (EIO);
+ }
+ }
+ return 0;
+
+}
+
+
int
snpread(dev, uio, flag)
dev_t dev;
@@ -66,7 +112,7 @@ snpread(dev, uio, flag)
panic("snoop buffer error");
#endif
- if (snp->snp_target == -1)
+ if (snp->snp_tty == NULL)
return (EIO);
snp->snp_flags &= ~SNOOP_RWAIT;
@@ -114,6 +160,17 @@ snpread(dev, uio, flag)
return error;
}
+int
+snpinc(snp, c)
+ struct snoop *snp;
+ char c;
+{
+ char buf[1];
+
+ buf[0]=c;
+ return (snpin(snp,buf,1));
+}
+
int
snpin(snp, buf, n)
@@ -237,8 +294,9 @@ snpopen(dev, flag, mode, p)
snp->snp_len = 0;
/*
- * unit == -1 is for inactive snoop devices.
+ * snp_tty == NULL is for inactive snoop devices.
*/
+ snp->snp_tty = NULL;
snp->snp_target = -1;
return (0);
}
@@ -258,11 +316,11 @@ snp_detach(snp)
* change it anyway.
*/
- if (snp->snp_target == -1)
+ if (snp->snp_tty == NULL)
goto detach_notty;
- tp = devtotty(snp->snp_target);
-
+ tp = snp->snp_tty;
+
if (tp && (tp->t_sc == snp) && (tp->t_state & TS_SNOOP) &&
(tp->t_line == OTTYDISC || tp->t_line == NTTYDISC)) {
tp->t_sc = NULL;
@@ -270,6 +328,7 @@ snp_detach(snp)
} else
printf("Snoop: bad attached tty data.\n");
+ snp->snp_tty = NULL;
snp->snp_target = -1;
detach_notty:
@@ -338,13 +397,14 @@ snpioctl(dev, cmd, data, flag)
s = spltty();
if (snp->snp_target == -1) {
- tpo = devtotty(snp->snp_target);
+ tpo = snp->snp_tty;
if (tpo)
tpo->t_state &= ~TS_SNOOP;
}
tp->t_sc = (caddr_t) snp;
tp->t_state |= TS_SNOOP;
+ snp->snp_tty = tp;
snp->snp_target = tdev;
/*
@@ -357,6 +417,11 @@ snpioctl(dev, cmd, data, flag)
break;
case SNPGTTY:
+ /*
+ * We keep snp_target field specially to make
+ * SNPGTTY happy,else we can't know what is device
+ * major/minor for tty.
+ */
*((dev_t *) data) = snp->snp_target;
break;
@@ -376,7 +441,7 @@ snpioctl(dev, cmd, data, flag)
case FIONREAD:
s = spltty();
- if (snp->snp_target != -1)
+ if (snp->snp_tty != NULL)
*(int *) data = snp->snp_len;
else
if (snp->snp_flags & SNOOP_DOWN) {
@@ -407,7 +472,7 @@ snpselect(dev, rw, p)
struct snoop *snp = &snoopsw[unit];
if (rw != FREAD)
- return 0;
+ return 1;
if (snp->snp_len > 0)
return 1;
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index 03a055159b53..e516ec22b2a8 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)tty.c 8.8 (Berkeley) 1/21/94
- * $Id: tty.c,v 1.31 1995/02/24 02:36:01 ache Exp $
+ * $Id: tty.c,v 1.32 1995/02/25 20:09:29 pst Exp $
*/
#include "snp.h"
@@ -1484,6 +1484,18 @@ read:
*/
if (CCEQ(cc[VEOF], c) && ISSET(lflag, ICANON))
break;
+
+#if NSNP > 0
+ /*
+ * Only when tty echoes characters , we want to
+ * feed them to the snoop device.Else they will come
+ * there if the application would like to.
+ */
+ if (ISSET(tp->t_lflag, ECHO))
+ if (ISSET(tp->t_state, TS_SNOOP) && tp->t_sc != NULL)
+ snpinc((struct snoop *)tp->t_sc, (char)c);
+#endif
+
/*
* Give user character.
*/
diff --git a/sys/kern/tty_snoop.c b/sys/kern/tty_snoop.c
index 553b5c252ed6..e36af000a998 100644
--- a/sys/kern/tty_snoop.c
+++ b/sys/kern/tty_snoop.c
@@ -49,6 +49,52 @@ devtotty (dev)
return (*cdevsw[major(dev)].d_devtotty)(dev);
}
+#define SNP_INPUT_BUF 5 /* This is even too much,the maximal
+ * interactive mode write is 3 bytes
+ * length for function keys...
+ */
+
+int
+snpwrite(dev, uio, flag)
+ dev_t dev;
+ struct uio *uio;
+ int flag;
+{
+ int unit = minor(dev), len, i, error;
+ struct snoop *snp = &snoopsw[unit];
+ struct tty *tp;
+ char c[SNP_INPUT_BUF];
+
+ if (snp->snp_tty == NULL)
+ return (EIO);
+
+ tp = snp->snp_tty;
+
+ if ((tp->t_sc == snp) && (tp->t_state & TS_SNOOP) &&
+ (tp->t_line == OTTYDISC || tp->t_line == NTTYDISC))
+ goto tty_input;
+
+ printf("Snoop: attempt to write to bad tty.\n");
+ return (EIO);
+
+tty_input:
+ if (!(tp->t_state & TS_ISOPEN))
+ return (EIO);
+
+ while (uio->uio_resid > 0) {
+ len = MIN(uio->uio_resid,SNP_INPUT_BUF);
+ if ((error = uiomove(c, len, uio)) != 0)
+ return (error);
+ for (i=0;i<len;i++) {
+ if (ttyinput(c[i] , tp))
+ return (EIO);
+ }
+ }
+ return 0;
+
+}
+
+
int
snpread(dev, uio, flag)
dev_t dev;
@@ -66,7 +112,7 @@ snpread(dev, uio, flag)
panic("snoop buffer error");
#endif
- if (snp->snp_target == -1)
+ if (snp->snp_tty == NULL)
return (EIO);
snp->snp_flags &= ~SNOOP_RWAIT;
@@ -114,6 +160,17 @@ snpread(dev, uio, flag)
return error;
}
+int
+snpinc(snp, c)
+ struct snoop *snp;
+ char c;
+{
+ char buf[1];
+
+ buf[0]=c;
+ return (snpin(snp,buf,1));
+}
+
int
snpin(snp, buf, n)
@@ -237,8 +294,9 @@ snpopen(dev, flag, mode, p)
snp->snp_len = 0;
/*
- * unit == -1 is for inactive snoop devices.
+ * snp_tty == NULL is for inactive snoop devices.
*/
+ snp->snp_tty = NULL;
snp->snp_target = -1;
return (0);
}
@@ -258,11 +316,11 @@ snp_detach(snp)
* change it anyway.
*/
- if (snp->snp_target == -1)
+ if (snp->snp_tty == NULL)
goto detach_notty;
- tp = devtotty(snp->snp_target);
-
+ tp = snp->snp_tty;
+
if (tp && (tp->t_sc == snp) && (tp->t_state & TS_SNOOP) &&
(tp->t_line == OTTYDISC || tp->t_line == NTTYDISC)) {
tp->t_sc = NULL;
@@ -270,6 +328,7 @@ snp_detach(snp)
} else
printf("Snoop: bad attached tty data.\n");
+ snp->snp_tty = NULL;
snp->snp_target = -1;
detach_notty:
@@ -338,13 +397,14 @@ snpioctl(dev, cmd, data, flag)
s = spltty();
if (snp->snp_target == -1) {
- tpo = devtotty(snp->snp_target);
+ tpo = snp->snp_tty;
if (tpo)
tpo->t_state &= ~TS_SNOOP;
}
tp->t_sc = (caddr_t) snp;
tp->t_state |= TS_SNOOP;
+ snp->snp_tty = tp;
snp->snp_target = tdev;
/*
@@ -357,6 +417,11 @@ snpioctl(dev, cmd, data, flag)
break;
case SNPGTTY:
+ /*
+ * We keep snp_target field specially to make
+ * SNPGTTY happy,else we can't know what is device
+ * major/minor for tty.
+ */
*((dev_t *) data) = snp->snp_target;
break;
@@ -376,7 +441,7 @@ snpioctl(dev, cmd, data, flag)
case FIONREAD:
s = spltty();
- if (snp->snp_target != -1)
+ if (snp->snp_tty != NULL)
*(int *) data = snp->snp_len;
else
if (snp->snp_flags & SNOOP_DOWN) {
@@ -407,7 +472,7 @@ snpselect(dev, rw, p)
struct snoop *snp = &snoopsw[unit];
if (rw != FREAD)
- return 0;
+ return 1;
if (snp->snp_len > 0)
return 1;
diff --git a/sys/sys/snoop.h b/sys/sys/snoop.h
index 6da28a84b319..1c6f73d078db 100644
--- a/sys/sys/snoop.h
+++ b/sys/sys/snoop.h
@@ -33,12 +33,13 @@
*/
struct snoop {
- dev_t snp_target; /* major/minor number of device*/
- u_long snp_len; /* buffer data length */
- u_long snp_base; /* buffer data base */
- u_long snp_blen; /* Overall buffer len */
- caddr_t snp_buf; /* Data buffer */
- int snp_flags; /* Flags place */
+ dev_t snp_target; /* major/minor number of device*/
+ struct tty *snp_tty; /* tty device pointer */
+ u_long snp_len; /* buffer data length */
+ u_long snp_base; /* buffer data base */
+ u_long snp_blen; /* Overall buffer len */
+ caddr_t snp_buf; /* Data buffer */
+ int snp_flags; /* Flags place */
#define SNOOP_NBIO 0x0001
#define SNOOP_ASYNC 0x0002
#define SNOOP_OPEN 0x0004