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
|
|
|
|
1997-12-16 17:40:42 +00:00
|
|
|
#include "opt_compat.h"
|
1998-01-24 02:54:56 +00:00
|
|
|
#include "opt_devfs.h"
|
1997-12-16 17:40:42 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1997-03-24 11:37:53 +00:00
|
|
|
#include <sys/filio.h>
|
1997-11-18 16:12:51 +00:00
|
|
|
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
|
|
|
|
#include <sys/ioctl_compat.h>
|
|
|
|
#endif
|
1995-02-14 21:21:26 +00:00
|
|
|
#include <sys/proc.h>
|
1997-10-12 20:26:33 +00:00
|
|
|
#include <sys/malloc.h>
|
1995-02-14 21:21:26 +00:00
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/conf.h>
|
1997-09-14 02:42:03 +00:00
|
|
|
#include <sys/poll.h>
|
1995-02-14 21:21:26 +00:00
|
|
|
#include <sys/kernel.h>
|
1995-11-29 10:49:16 +00:00
|
|
|
#ifdef DEVFS
|
|
|
|
#include <sys/devfsext.h>
|
|
|
|
#endif /*DEVFS*/
|
1995-12-08 11:19:42 +00:00
|
|
|
#include <sys/snoop.h>
|
1997-11-18 16:12:51 +00:00
|
|
|
#include <sys/vnode.h>
|
1995-12-08 11:19:42 +00:00
|
|
|
|
|
|
|
static d_open_t snpopen;
|
|
|
|
static d_close_t snpclose;
|
|
|
|
static d_read_t snpread;
|
|
|
|
static d_write_t snpwrite;
|
|
|
|
static d_ioctl_t snpioctl;
|
1997-09-14 02:42:03 +00:00
|
|
|
static d_poll_t snppoll;
|
1995-12-08 11:19:42 +00:00
|
|
|
|
1995-11-29 10:49:16 +00:00
|
|
|
#define CDEV_MAJOR 53
|
1995-12-08 23:23:00 +00:00
|
|
|
static struct cdevsw snp_cdevsw =
|
1995-12-08 11:19:42 +00:00
|
|
|
{ snpopen, snpclose, snpread, snpwrite, /*53*/
|
|
|
|
snpioctl, nostop, nullreset, nodevtotty,/* snoop */
|
1997-09-14 02:42:03 +00:00
|
|
|
snppoll, nommap, NULL, "snp", NULL, -1 };
|
1995-12-08 11:19:42 +00:00
|
|
|
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct snoop snoopsw[NSNP];
|
|
|
|
|
1997-03-16 19:11:40 +00:00
|
|
|
static struct tty *snpdevtotty __P((dev_t dev));
|
1995-12-14 08:32:45 +00:00
|
|
|
static int snp_detach __P((struct snoop *snp));
|
1995-12-02 18:58:56 +00:00
|
|
|
|
1995-02-25 20:09:44 +00:00
|
|
|
static struct tty *
|
1997-03-16 19:11:40 +00:00
|
|
|
snpdevtotty (dev)
|
1995-02-25 20:09:44 +00:00
|
|
|
dev_t dev;
|
|
|
|
{
|
1997-03-16 19:11:40 +00:00
|
|
|
struct cdevsw *cdp;
|
|
|
|
int maj;
|
|
|
|
|
|
|
|
maj = major(dev);
|
|
|
|
if ((u_int)maj >= nchrdev)
|
|
|
|
return (NULL);
|
|
|
|
cdp = cdevsw[maj];
|
|
|
|
if (cdp == NULL)
|
|
|
|
return (NULL);
|
|
|
|
return ((*cdp->d_devtotty)(dev));
|
1995-02-25 20:09:44 +00:00
|
|
|
}
|
|
|
|
|
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...
|
|
|
|
*/
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-02-27 19:47:53 +00:00
|
|
|
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-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-02-14 21:21:26 +00:00
|
|
|
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;
|
|
|
|
|
1999-01-08 17:31:30 +00:00
|
|
|
KASSERT(snp->snp_len + snp->snp_base <= snp->snp_blen,
|
1999-01-10 01:58:29 +00:00
|
|
|
("snoop buffer error"));
|
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) {
|
1997-11-18 16:12:51 +00:00
|
|
|
if (flag & IO_NDELAY)
|
|
|
|
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;
|
1999-01-27 21:50:00 +00:00
|
|
|
if ((nbuf = malloc(nblen, M_TTYS, M_NOWAIT)) != NULL) {
|
1995-02-15 16:35:38 +00:00
|
|
|
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
|
1997-11-18 16:12:51 +00:00
|
|
|
snpinc(struct snoop *snp, char c)
|
1995-02-27 19:47:53 +00:00
|
|
|
{
|
|
|
|
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;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1999-01-10 01:58:29 +00:00
|
|
|
KASSERT(n >= 0, ("negative snoop char count"));
|
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;
|
|
|
|
|
1999-01-08 17:31:30 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
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;
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-02-14 21:21:26 +00:00
|
|
|
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
|
|
|
|
1999-04-27 11:18:52 +00:00
|
|
|
if ((error = suser(p)) != 0)
|
1995-02-14 21:21:26 +00:00
|
|
|
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-12-14 08:32:45 +00:00
|
|
|
static 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-12-08 11:19:42 +00:00
|
|
|
static 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
|
|
|
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static 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;
|
1998-06-07 17:13:14 +00:00
|
|
|
u_long cmd;
|
1995-02-15 16:35:38 +00:00
|
|
|
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));
|
|
|
|
|
1997-03-16 19:11:40 +00:00
|
|
|
tp = snpdevtotty(tdev);
|
1995-02-25 20:09:44 +00:00
|
|
|
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:
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1997-09-14 02:42:03 +00:00
|
|
|
snppoll(dev, events, p)
|
1995-02-15 16:35:38 +00:00
|
|
|
dev_t dev;
|
1997-09-14 02:42:03 +00:00
|
|
|
int events;
|
1995-02-15 16:35:38 +00:00
|
|
|
struct proc *p;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-10-29 15:33:36 +00:00
|
|
|
int unit = minor(dev);
|
1995-02-15 16:35:38 +00:00
|
|
|
struct snoop *snp = &snoopsw[unit];
|
1997-09-14 02:42:03 +00:00
|
|
|
int revents = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-25 20:09:44 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
/*
|
1997-09-14 02:42:03 +00:00
|
|
|
* If snoop is down,we don't want to poll() forever so we return 1.
|
1995-02-15 16:35:38 +00:00
|
|
|
* Caller should see if we down via FIONREAD ioctl().The last should
|
|
|
|
* return -1 to indicate down state.
|
|
|
|
*/
|
1999-05-06 18:13:11 +00:00
|
|
|
if (events & (POLLIN | POLLRDNORM)) {
|
1997-09-14 02:42:03 +00:00
|
|
|
if (snp->snp_flags & SNOOP_DOWN || snp->snp_len > 0)
|
|
|
|
revents |= events & (POLLIN | POLLRDNORM);
|
|
|
|
else
|
|
|
|
selrecord(p, &snp->snp_sel);
|
1999-05-06 18:13:11 +00:00
|
|
|
}
|
1997-09-14 02:42:03 +00:00
|
|
|
return (revents);
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
|
|
|
|
1996-03-28 14:31:42 +00:00
|
|
|
#ifdef DEVFS
|
1995-12-08 11:19:42 +00:00
|
|
|
static void *snp_devfs_token[NSNP];
|
1996-03-28 14:31:42 +00:00
|
|
|
#endif
|
1998-02-20 13:46:58 +00:00
|
|
|
static int snp_devsw_installed;
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1997-09-16 11:44:05 +00:00
|
|
|
static void snp_drvinit __P((void *unused));
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
1997-09-16 11:44:05 +00:00
|
|
|
snp_drvinit(unused)
|
|
|
|
void *unused;
|
1995-11-29 10:49:16 +00:00
|
|
|
{
|
|
|
|
dev_t dev;
|
1996-03-28 14:31:42 +00:00
|
|
|
#ifdef DEVFS
|
1995-12-08 11:19:42 +00:00
|
|
|
int i;
|
1996-03-28 14:31:42 +00:00
|
|
|
#endif
|
1995-11-29 10:49:16 +00:00
|
|
|
|
|
|
|
if( ! snp_devsw_installed ) {
|
1995-12-08 11:19:42 +00:00
|
|
|
dev = makedev(CDEV_MAJOR, 0);
|
|
|
|
cdevsw_add(&dev,&snp_cdevsw, NULL);
|
1995-11-29 10:49:16 +00:00
|
|
|
snp_devsw_installed = 1;
|
|
|
|
#ifdef DEVFS
|
1995-12-08 11:19:42 +00:00
|
|
|
for ( i = 0 ; i < NSNP ; i++) {
|
|
|
|
snp_devfs_token[i] =
|
1996-03-28 14:31:42 +00:00
|
|
|
devfs_add_devswf(&snp_cdevsw, i, DV_CHR, 0, 0,
|
|
|
|
0600, "snp%d", i);
|
1995-11-29 10:49:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
1995-11-29 14:41:20 +00:00
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(snpdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,snp_drvinit,NULL)
|
|
|
|
|
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
#endif
|