1995-02-14 21:21:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Ugen J.S.Antsilevich
|
|
|
|
*
|
|
|
|
* Redistribution and use in source forms, with and without modification,
|
|
|
|
* are permitted provided that this entire comment appears intact.
|
|
|
|
*
|
|
|
|
* Redistribution in binary form may occur without any restrictions.
|
|
|
|
* Obviously, it would be nice if you gave credit where credit is due
|
|
|
|
* but requiring it would be too onerous.
|
|
|
|
*
|
|
|
|
* This software is provided ``AS IS'' without any warranties of any kind.
|
|
|
|
*
|
|
|
|
* Snoop stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "snp.h"
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
#if NSNP > 0
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/ioctl.h>
|
1995-02-15 16:35:38 +00:00
|
|
|
#include <sys/ioctl_compat.h> /* Oooh..We need O/NTTYDISC */
|
1995-02-14 21:21:26 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#define TTYDEFCHARS
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#undef TTYDEFCHARS
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <sys/snoop.h>
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct snoop snoopsw[NSNP];
|
|
|
|
|
1995-02-25 20:09:44 +00:00
|
|
|
static struct tty *
|
|
|
|
devtotty (dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
if (major(dev) > nchrdev)
|
|
|
|
return (NULL); /* no such device available */
|
|
|
|
|
|
|
|
return (*cdevsw[major(dev)].d_devtotty)(dev);
|
|
|
|
}
|
|
|
|
|
1995-02-27 19:47:53 +00:00
|
|
|
#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;
|
1995-05-30 08:16:23 +00:00
|
|
|
char c[SNP_INPUT_BUF];
|
1995-02-27 19:47:53 +00:00
|
|
|
|
|
|
|
if (snp->snp_tty == NULL)
|
|
|
|
return (EIO);
|
|
|
|
|
|
|
|
tp = snp->snp_tty;
|
|
|
|
|
|
|
|
if ((tp->t_sc == snp) && (tp->t_state & TS_SNOOP) &&
|
1995-05-30 08:16:23 +00:00
|
|
|
(tp->t_line == OTTYDISC || tp->t_line == NTTYDISC))
|
1995-02-27 19:47:53 +00:00
|
|
|
goto tty_input;
|
|
|
|
|
|
|
|
printf("Snoop: attempt to write to bad tty.\n");
|
|
|
|
return (EIO);
|
|
|
|
|
|
|
|
tty_input:
|
1995-05-30 08:16:23 +00:00
|
|
|
if (!(tp->t_state & TS_ISOPEN))
|
1995-02-27 19:47:53 +00:00
|
|
|
return (EIO);
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-02-27 19:47:53 +00:00
|
|
|
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;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-02-27 19:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
int
|
|
|
|
snpread(dev, uio, flag)
|
1995-02-15 16:35:38 +00:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flag;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
int unit = minor(dev), s;
|
|
|
|
struct snoop *snp = &snoopsw[unit];
|
|
|
|
int len, n, nblen, error = 0;
|
|
|
|
caddr_t from;
|
|
|
|
char *nbuf;
|
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
1995-02-15 16:35:38 +00:00
|
|
|
if ((snp->snp_len + snp->snp_base) > snp->snp_blen)
|
1995-02-14 21:21:26 +00:00
|
|
|
panic("snoop buffer error");
|
|
|
|
#endif
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-27 19:47:53 +00:00
|
|
|
if (snp->snp_tty == NULL)
|
1995-02-14 21:21:26 +00:00
|
|
|
return (EIO);
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags &= ~SNOOP_RWAIT;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
do {
|
1995-02-15 16:35:38 +00:00
|
|
|
if (snp->snp_len == 0) {
|
1995-02-14 21:21:26 +00:00
|
|
|
if (snp->snp_flags & SNOOP_NBIO) {
|
|
|
|
return EWOULDBLOCK;
|
|
|
|
}
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags |= SNOOP_RWAIT;
|
|
|
|
tsleep((caddr_t) snp, (PZERO + 1) | PCATCH, "snoopread", 0);
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
|
|
|
} while (snp->snp_len == 0);
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
n = snp->snp_len;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
while (snp->snp_len > 0 && uio->uio_resid > 0 && error == 0) {
|
|
|
|
len = MIN(uio->uio_resid, snp->snp_len);
|
|
|
|
from = (caddr_t) (snp->snp_buf + snp->snp_base);
|
1995-02-14 21:21:26 +00:00
|
|
|
if (len == 0)
|
|
|
|
break;
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
error = uiomove(from, len, uio);
|
|
|
|
snp->snp_base += len;
|
|
|
|
snp->snp_len -= len;
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
1995-02-15 16:35:38 +00:00
|
|
|
if ((snp->snp_flags & SNOOP_OFLOW) && (n < snp->snp_len)) {
|
1995-02-14 21:21:26 +00:00
|
|
|
snp->snp_flags &= ~SNOOP_OFLOW;
|
1995-02-15 16:35:38 +00:00
|
|
|
}
|
|
|
|
s = spltty();
|
|
|
|
nblen = snp->snp_blen;
|
|
|
|
if (((nblen / 2) >= SNOOP_MINLEN) && (nblen / 2) >= snp->snp_len) {
|
|
|
|
while (((nblen / 2) >= snp->snp_len) && ((nblen / 2) >= SNOOP_MINLEN))
|
|
|
|
nblen = nblen / 2;
|
|
|
|
if (nbuf = malloc(nblen, M_TTYS, M_NOWAIT)) {
|
|
|
|
bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len);
|
|
|
|
free(snp->snp_buf, M_TTYS);
|
|
|
|
snp->snp_buf = nbuf;
|
|
|
|
snp->snp_blen = nblen;
|
|
|
|
snp->snp_base = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1995-02-27 19:47:53 +00:00
|
|
|
int
|
|
|
|
snpinc(snp, c)
|
|
|
|
struct snoop *snp;
|
|
|
|
char c;
|
|
|
|
{
|
|
|
|
char buf[1];
|
|
|
|
|
|
|
|
buf[0]=c;
|
|
|
|
return (snpin(snp,buf,1));
|
|
|
|
}
|
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
int
|
1995-02-15 16:35:38 +00:00
|
|
|
snpin(snp, buf, n)
|
|
|
|
struct snoop *snp;
|
|
|
|
char *buf;
|
|
|
|
int n;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
int s_free, s_tail;
|
|
|
|
int s, len, nblen;
|
|
|
|
caddr_t from, to;
|
|
|
|
char *nbuf;
|
|
|
|
struct tty *tp;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
if (n == 0)
|
1995-02-14 21:21:26 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (n < 0)
|
|
|
|
panic("bad snoop char count");
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
if (!(snp->snp_flags & SNOOP_OPEN)) {
|
|
|
|
printf("Snoop: data coming to closed device.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (snp->snp_flags & SNOOP_DOWN) {
|
|
|
|
printf("Snoop: more data to down interface.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
1995-02-15 18:41:57 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
if (snp->snp_flags & SNOOP_OFLOW) {
|
|
|
|
printf("Snoop: buffer overflow.\n");
|
|
|
|
/*
|
|
|
|
* On overflow we just repeat the standart close
|
|
|
|
* procedure...yes , this is waste of space but.. Then next
|
|
|
|
* read from device will fail if one would recall he is
|
|
|
|
* snooping and retry...
|
|
|
|
*/
|
|
|
|
|
1995-02-15 18:41:57 +00:00
|
|
|
return (snpdown(snp));
|
1995-02-15 16:35:38 +00:00
|
|
|
}
|
|
|
|
s_tail = snp->snp_blen - (snp->snp_len + snp->snp_base);
|
|
|
|
s_free = snp->snp_blen - snp->snp_len;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (n > s_free) {
|
1995-02-15 16:35:38 +00:00
|
|
|
s = spltty();
|
|
|
|
nblen = snp->snp_blen;
|
|
|
|
while ((n > s_free) && ((nblen * 2) <= SNOOP_MAXLEN)) {
|
|
|
|
nblen = snp->snp_blen * 2;
|
|
|
|
s_free = nblen - (snp->snp_len + snp->snp_base);
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
1995-02-15 16:35:38 +00:00
|
|
|
if ((n <= s_free) && (nbuf = malloc(nblen, M_TTYS, M_NOWAIT))) {
|
|
|
|
bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len);
|
|
|
|
free(snp->snp_buf, M_TTYS);
|
|
|
|
snp->snp_buf = nbuf;
|
|
|
|
snp->snp_blen = nblen;
|
|
|
|
snp->snp_base = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
} else {
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags |= SNOOP_OFLOW;
|
1995-02-14 21:21:26 +00:00
|
|
|
if (snp->snp_flags & SNOOP_RWAIT) {
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags &= ~SNOOP_RWAIT;
|
|
|
|
wakeup((caddr_t) snp);
|
|
|
|
}
|
1995-02-14 21:21:26 +00:00
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
if (n > s_tail) {
|
1995-02-15 16:35:38 +00:00
|
|
|
from = (caddr_t) (snp->snp_buf + snp->snp_base);
|
|
|
|
to = (caddr_t) (snp->snp_buf);
|
|
|
|
len = snp->snp_len;
|
|
|
|
bcopy(from, to, len);
|
|
|
|
snp->snp_base = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
1995-02-15 16:35:38 +00:00
|
|
|
to = (caddr_t) (snp->snp_buf + snp->snp_base + snp->snp_len);
|
|
|
|
bcopy(buf, to, n);
|
|
|
|
snp->snp_len += n;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
if (snp->snp_flags & SNOOP_RWAIT) {
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags &= ~SNOOP_RWAIT;
|
|
|
|
wakeup((caddr_t) snp);
|
|
|
|
}
|
1995-02-14 21:21:26 +00:00
|
|
|
selwakeup(&snp->snp_sel);
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_sel.si_pid = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
snpopen(dev, flag, mode, p)
|
1995-02-15 16:35:38 +00:00
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
struct snoop *snp;
|
|
|
|
register int unit, error;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
if (error = suser(p->p_ucred, &p->p_acflag))
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if ((unit = minor(dev)) >= NSNP)
|
|
|
|
return (ENXIO);
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
snp = &snoopsw[unit];
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
if (snp->snp_flags & SNOOP_OPEN)
|
|
|
|
return (ENXIO);
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
/*
|
|
|
|
* We intentionally do not OR flags with SNOOP_OPEN,but set them so
|
|
|
|
* all previous settings (especially SNOOP_OFLOW) will be cleared.
|
|
|
|
*/
|
|
|
|
snp->snp_flags = SNOOP_OPEN;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK);
|
|
|
|
snp->snp_blen = SNOOP_MINLEN;
|
|
|
|
snp->snp_base = 0;
|
|
|
|
snp->snp_len = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
/*
|
1995-02-27 19:47:53 +00:00
|
|
|
* snp_tty == NULL is for inactive snoop devices.
|
1995-02-14 21:21:26 +00:00
|
|
|
*/
|
1995-02-27 19:47:53 +00:00
|
|
|
snp->snp_tty = NULL;
|
1995-02-25 20:09:44 +00:00
|
|
|
snp->snp_target = -1;
|
1995-02-14 21:21:26 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
int
|
1995-02-15 16:35:38 +00:00
|
|
|
snp_detach(snp)
|
|
|
|
struct snoop *snp;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
struct tty *tp;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
snp->snp_base = 0;
|
|
|
|
snp->snp_len = 0;
|
|
|
|
|
|
|
|
/*
|
1995-02-15 16:35:38 +00:00
|
|
|
* If line disc. changed we do not touch this pointer,SLIP/PPP will
|
|
|
|
* change it anyway.
|
1995-02-14 21:21:26 +00:00
|
|
|
*/
|
|
|
|
|
1995-02-27 19:47:53 +00:00
|
|
|
if (snp->snp_tty == NULL)
|
1995-02-15 18:41:57 +00:00
|
|
|
goto detach_notty;
|
1995-02-15 16:35:38 +00:00
|
|
|
|
1995-02-27 19:47:53 +00:00
|
|
|
tp = snp->snp_tty;
|
|
|
|
|
1995-02-25 20:09:44 +00:00
|
|
|
if (tp && (tp->t_sc == snp) && (tp->t_state & TS_SNOOP) &&
|
1995-02-15 16:35:38 +00:00
|
|
|
(tp->t_line == OTTYDISC || tp->t_line == NTTYDISC)) {
|
1995-02-14 21:21:26 +00:00
|
|
|
tp->t_sc = NULL;
|
1995-02-15 16:35:38 +00:00
|
|
|
tp->t_state &= ~TS_SNOOP;
|
|
|
|
} else
|
|
|
|
printf("Snoop: bad attached tty data.\n");
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-27 19:47:53 +00:00
|
|
|
snp->snp_tty = NULL;
|
1995-02-25 20:09:44 +00:00
|
|
|
snp->snp_target = -1;
|
1995-02-15 16:35:38 +00:00
|
|
|
|
1995-02-15 18:41:57 +00:00
|
|
|
detach_notty:
|
1995-02-14 21:21:26 +00:00
|
|
|
selwakeup(&snp->snp_sel);
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_sel.si_pid = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
int
|
1995-09-08 11:09:15 +00:00
|
|
|
snpclose(dev, flags, fmt, p)
|
1995-02-15 16:35:38 +00:00
|
|
|
dev_t dev;
|
1995-09-08 11:09:15 +00:00
|
|
|
int flags;
|
|
|
|
int fmt;
|
|
|
|
struct proc *p;
|
1995-02-15 16:35:38 +00:00
|
|
|
{
|
|
|
|
register int unit = minor(dev);
|
|
|
|
struct snoop *snp = &snoopsw[unit];
|
|
|
|
|
|
|
|
snp->snp_blen = 0;
|
|
|
|
free(snp->snp_buf, M_TTYS);
|
|
|
|
snp->snp_flags &= ~SNOOP_OPEN;
|
|
|
|
|
|
|
|
return (snp_detach(snp));
|
|
|
|
}
|
|
|
|
|
1995-02-15 18:41:57 +00:00
|
|
|
int
|
|
|
|
snpdown(snp)
|
|
|
|
struct snoop *snp;
|
|
|
|
{
|
|
|
|
snp->snp_blen = SNOOP_MINLEN;
|
|
|
|
free(snp->snp_buf, M_TTYS);
|
|
|
|
snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK);
|
|
|
|
snp->snp_flags |= SNOOP_DOWN;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 18:41:57 +00:00
|
|
|
return (snp_detach(snp));
|
|
|
|
}
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
1995-09-08 11:09:15 +00:00
|
|
|
snpioctl(dev, cmd, data, flags, p)
|
1995-02-15 16:35:38 +00:00
|
|
|
dev_t dev;
|
|
|
|
int cmd;
|
|
|
|
caddr_t data;
|
1995-09-08 11:09:15 +00:00
|
|
|
int flags;
|
|
|
|
struct proc *p;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
int unit = minor(dev), s;
|
1995-02-25 20:09:44 +00:00
|
|
|
dev_t tdev;
|
1995-02-15 16:35:38 +00:00
|
|
|
struct snoop *snp = &snoopsw[unit];
|
|
|
|
struct tty *tp, *tpo;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SNPSTTY:
|
1995-02-25 20:09:44 +00:00
|
|
|
tdev = *((dev_t *) data);
|
|
|
|
if (tdev == -1)
|
1995-02-15 18:41:57 +00:00
|
|
|
return (snpdown(snp));
|
|
|
|
|
1995-02-25 20:09:44 +00:00
|
|
|
tp = devtotty(tdev);
|
|
|
|
if (!tp)
|
1995-02-14 21:21:26 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
1995-02-25 20:09:44 +00:00
|
|
|
if ((tp->t_sc != (caddr_t) snp) && (tp->t_state & TS_SNOOP))
|
1995-02-14 21:21:26 +00:00
|
|
|
return (EBUSY);
|
|
|
|
|
1995-02-25 20:09:44 +00:00
|
|
|
if ((tp->t_line != OTTYDISC) && (tp->t_line != NTTYDISC))
|
1995-02-14 21:21:26 +00:00
|
|
|
return (EBUSY);
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
s = spltty();
|
1995-02-25 20:09:44 +00:00
|
|
|
|
|
|
|
if (snp->snp_target == -1) {
|
1995-02-27 19:47:53 +00:00
|
|
|
tpo = snp->snp_tty;
|
1995-02-25 20:09:44 +00:00
|
|
|
if (tpo)
|
|
|
|
tpo->t_state &= ~TS_SNOOP;
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
tp->t_sc = (caddr_t) snp;
|
1995-02-14 21:21:26 +00:00
|
|
|
tp->t_state |= TS_SNOOP;
|
1995-02-27 19:47:53 +00:00
|
|
|
snp->snp_tty = tp;
|
1995-02-25 20:09:44 +00:00
|
|
|
snp->snp_target = tdev;
|
|
|
|
|
1995-02-15 18:41:57 +00:00
|
|
|
/*
|
|
|
|
* Clean overflow and down flags -
|
|
|
|
* we'll have a chance to get them in the future :)))
|
|
|
|
*/
|
|
|
|
snp->snp_flags &= ~SNOOP_OFLOW;
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags &= ~SNOOP_DOWN;
|
1995-02-14 21:21:26 +00:00
|
|
|
splx(s);
|
|
|
|
break;
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
case SNPGTTY:
|
1995-02-27 19:47:53 +00:00
|
|
|
/*
|
|
|
|
* We keep snp_target field specially to make
|
|
|
|
* SNPGTTY happy,else we can't know what is device
|
|
|
|
* major/minor for tty.
|
|
|
|
*/
|
1995-02-25 20:09:44 +00:00
|
|
|
*((dev_t *) data) = snp->snp_target;
|
1995-02-14 21:21:26 +00:00
|
|
|
break;
|
1995-02-15 16:35:38 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
case FIONBIO:
|
1995-02-15 16:35:38 +00:00
|
|
|
if (*(int *) data)
|
1995-02-14 21:21:26 +00:00
|
|
|
snp->snp_flags |= SNOOP_NBIO;
|
|
|
|
else
|
|
|
|
snp->snp_flags &= ~SNOOP_NBIO;
|
|
|
|
break;
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
case FIOASYNC:
|
1995-02-15 16:35:38 +00:00
|
|
|
if (*(int *) data)
|
1995-02-14 21:21:26 +00:00
|
|
|
snp->snp_flags |= SNOOP_ASYNC;
|
|
|
|
else
|
|
|
|
snp->snp_flags &= ~SNOOP_ASYNC;
|
|
|
|
break;
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
case FIONREAD:
|
|
|
|
s = spltty();
|
1995-02-27 19:47:53 +00:00
|
|
|
if (snp->snp_tty != NULL)
|
1995-02-15 16:35:38 +00:00
|
|
|
*(int *) data = snp->snp_len;
|
1995-05-30 08:16:23 +00:00
|
|
|
else
|
1995-02-25 20:09:44 +00:00
|
|
|
if (snp->snp_flags & SNOOP_DOWN) {
|
|
|
|
if (snp->snp_flags & SNOOP_OFLOW)
|
1995-02-15 18:41:57 +00:00
|
|
|
*(int *) data = SNP_OFLOW;
|
|
|
|
else
|
|
|
|
*(int *) data = SNP_TTYCLOSE;
|
|
|
|
} else {
|
|
|
|
*(int *) data = SNP_DETACH;
|
|
|
|
}
|
1995-02-14 21:21:26 +00:00
|
|
|
splx(s);
|
|
|
|
break;
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
default:
|
|
|
|
return (ENOTTY);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
snpselect(dev, rw, p)
|
1995-02-15 16:35:38 +00:00
|
|
|
dev_t dev;
|
|
|
|
int rw;
|
|
|
|
struct proc *p;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
int unit = minor(dev), s;
|
|
|
|
struct snoop *snp = &snoopsw[unit];
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-25 20:09:44 +00:00
|
|
|
if (rw != FREAD)
|
1995-02-27 19:47:53 +00:00
|
|
|
return 1;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-02-25 20:09:44 +00:00
|
|
|
if (snp->snp_len > 0)
|
1995-02-15 16:35:38 +00:00
|
|
|
return 1;
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
/*
|
|
|
|
* If snoop is down,we don't want to select() forever so we return 1.
|
|
|
|
* Caller should see if we down via FIONREAD ioctl().The last should
|
|
|
|
* return -1 to indicate down state.
|
|
|
|
*/
|
1995-02-25 20:09:44 +00:00
|
|
|
if (snp->snp_flags & SNOOP_DOWN)
|
1995-02-15 16:35:38 +00:00
|
|
|
return 1;
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
selrecord(p, &snp->snp_sel);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|