1996-06-12 05:11:41 +00:00
|
|
|
/* @(#)$Id: iitty.c,v 1.21 1996/04/02 22:06:23 gpalmer Exp $
|
|
|
|
*******************************************************************************
|
|
|
|
* II - Version 0.1 $Revision: 1.21 $ $State: Exp $
|
1995-02-14 15:00:39 +00:00
|
|
|
*
|
|
|
|
* Copyright 1994 Dietmar Friede
|
|
|
|
*******************************************************************************
|
|
|
|
* Bug reports, patches, comments, suggestions should be sent to:
|
|
|
|
*
|
|
|
|
* jkr@saarlink.de or jkrause@guug.de
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
1995-12-17 21:17:48 +00:00
|
|
|
*/
|
1995-02-14 15:00:39 +00:00
|
|
|
|
|
|
|
#include "ity.h"
|
|
|
|
#if NITY > 0
|
|
|
|
|
1995-11-29 10:49:16 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef DEVFS
|
|
|
|
#include <sys/devfsext.h>
|
|
|
|
#endif /*DEVFS*/
|
1995-12-08 11:19:42 +00:00
|
|
|
|
|
|
|
#include "gnu/isdn/isdn_ioctl.h"
|
|
|
|
|
|
|
|
static d_open_t ityopen;
|
|
|
|
static d_close_t ityclose;
|
|
|
|
static d_read_t ityread;
|
|
|
|
static d_write_t itywrite;
|
|
|
|
static d_ioctl_t ityioctl;
|
|
|
|
static d_stop_t itystop;
|
1995-12-10 15:55:34 +00:00
|
|
|
static d_devtotty_t itydevtotty;
|
1995-12-08 11:19:42 +00:00
|
|
|
|
1995-11-29 10:49:16 +00:00
|
|
|
#define CDEV_MAJOR 56
|
1995-12-08 23:23:00 +00:00
|
|
|
static struct cdevsw ity_cdevsw =
|
1995-12-08 11:19:42 +00:00
|
|
|
{ ityopen, ityclose, ityread, itywrite, /*56*/
|
|
|
|
ityioctl, itystop, noreset, itydevtotty,/* ity */
|
|
|
|
ttselect, nommap, NULL, "ity", NULL, -1 };
|
|
|
|
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1995-12-17 21:17:48 +00:00
|
|
|
static int ityparam __P((struct tty *tp, struct termios *t));
|
|
|
|
static void itystart __P((struct tty *tp));
|
1995-02-14 15:00:39 +00:00
|
|
|
|
1995-12-17 21:17:48 +00:00
|
|
|
static int itydefaultrate = 64000;
|
|
|
|
static short ity_addr[NITY];
|
|
|
|
static struct tty ity_tty[NITY];
|
1995-02-14 15:00:39 +00:00
|
|
|
static int applnr[NITY];
|
|
|
|
static int next_if= 0;
|
1995-12-08 11:19:42 +00:00
|
|
|
#ifdef DEVFS
|
|
|
|
void *devfs_token[NITY];
|
1995-12-17 21:17:48 +00:00
|
|
|
static void *devfs_token_out[NITY];
|
1995-12-08 11:19:42 +00:00
|
|
|
#endif
|
1995-02-14 15:00:39 +00:00
|
|
|
|
|
|
|
#define UNIT(x) (minor(x)&0x3f)
|
|
|
|
#define OUTBOUND(x) ((minor(x)&0x80)==0x80)
|
|
|
|
|
|
|
|
int
|
|
|
|
ityattach(int ap)
|
|
|
|
{
|
|
|
|
if(next_if >= NITY)
|
|
|
|
return(-1);
|
|
|
|
|
|
|
|
applnr[next_if]= ap;
|
1995-12-08 11:19:42 +00:00
|
|
|
#ifdef DEVFS
|
1996-03-28 14:29:52 +00:00
|
|
|
devfs_token[next_if] =
|
|
|
|
devfs_add_devswf(&ity_cdevsw, next_if, DV_CHR, 0, 0,
|
|
|
|
0600, "isdn/ity%d", next_if);
|
1996-04-02 22:06:23 +00:00
|
|
|
devfs_token_out[next_if] =
|
1996-03-28 14:29:52 +00:00
|
|
|
devfs_add_devswf(&ity_cdevsw,(next_if | 0x80), DV_CHR, 0, 0,
|
|
|
|
0600, "isdn/Oity%d", next_if);
|
1995-12-08 11:19:42 +00:00
|
|
|
#endif
|
1995-02-14 15:00:39 +00:00
|
|
|
return(next_if++);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-02-14 15:00:39 +00:00
|
|
|
ityopen(dev_t dev, int flag, int mode, struct proc * p)
|
|
|
|
{
|
|
|
|
register struct tty *tp;
|
|
|
|
register int unit;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
unit = UNIT(dev);
|
|
|
|
if (unit >= next_if)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
tp = &ity_tty[unit];
|
|
|
|
tp->t_oproc = itystart;
|
|
|
|
tp->t_param = ityparam;
|
|
|
|
tp->t_dev = dev;
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0)
|
|
|
|
{
|
|
|
|
ttychars(tp);
|
|
|
|
if (tp->t_ispeed == 0)
|
|
|
|
{
|
|
|
|
tp->t_iflag = TTYDEF_IFLAG;
|
|
|
|
tp->t_oflag = TTYDEF_OFLAG;
|
|
|
|
tp->t_cflag = TTYDEF_CFLAG;
|
|
|
|
tp->t_lflag = TTYDEF_LFLAG;
|
|
|
|
tp->t_ispeed = tp->t_ospeed = itydefaultrate;
|
|
|
|
}
|
|
|
|
ityparam(tp, &tp->t_termios);
|
|
|
|
ttsetwater(tp);
|
|
|
|
} else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0)
|
|
|
|
return (EBUSY);
|
|
|
|
(void) spltty();
|
|
|
|
|
1995-07-31 21:02:00 +00:00
|
|
|
if (OUTBOUND(dev)) {
|
|
|
|
/*
|
|
|
|
* XXX should call l_modem() here and not meddle with CLOCAL,
|
|
|
|
* but itystart() wants TS_CARR_ON to give the true carrier.
|
|
|
|
*/
|
|
|
|
tp->t_cflag |= CLOCAL;
|
|
|
|
tp->t_state |= TS_CONNECTED;
|
|
|
|
}
|
1995-02-14 15:00:39 +00:00
|
|
|
|
|
|
|
while ((flag & O_NONBLOCK) == 0 && (tp->t_cflag & CLOCAL) == 0 &&
|
|
|
|
(tp->t_state & TS_CARR_ON) == 0)
|
|
|
|
{
|
1995-07-31 21:28:42 +00:00
|
|
|
error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "iidcd", 0);
|
|
|
|
if (error)
|
1995-02-14 15:00:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
(void) spl0();
|
|
|
|
if (error == 0)
|
|
|
|
error = (*linesw[tp->t_line].l_open) (dev, tp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-02-14 15:00:39 +00:00
|
|
|
ityclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
register struct tty *tp;
|
|
|
|
register ity;
|
|
|
|
register int unit;
|
|
|
|
|
|
|
|
unit = UNIT(dev);
|
|
|
|
ity = ity_addr[unit];
|
|
|
|
if(tp = &ity_tty[unit])
|
|
|
|
(*linesw[tp->t_line].l_close) (tp, flag);
|
|
|
|
ttyclose(tp);
|
|
|
|
isdn_disconnect(applnr[unit],0);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-02-14 15:00:39 +00:00
|
|
|
ityread(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1995-02-15 06:28:29 +00:00
|
|
|
int flag;
|
1995-02-14 15:00:39 +00:00
|
|
|
{
|
|
|
|
register struct tty *tp = &ity_tty[UNIT(dev)];
|
|
|
|
|
|
|
|
return ((*linesw[tp->t_line].l_read) (tp, uio, flag));
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-02-14 15:00:39 +00:00
|
|
|
itywrite(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1995-02-15 06:28:29 +00:00
|
|
|
int flag;
|
1995-02-14 15:00:39 +00:00
|
|
|
{
|
|
|
|
int unit = UNIT(dev);
|
|
|
|
register struct tty *tp = &ity_tty[unit];
|
|
|
|
|
|
|
|
return ((*linesw[tp->t_line].l_write) (tp, uio, flag));
|
|
|
|
}
|
|
|
|
|
1995-02-15 06:28:29 +00:00
|
|
|
int
|
1995-11-16 10:35:29 +00:00
|
|
|
ity_input(int no, int len, char *buf, int dir)
|
1995-02-14 15:00:39 +00:00
|
|
|
{
|
|
|
|
register struct tty *tp = &ity_tty[no];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (tp->t_state & TS_ISOPEN)
|
|
|
|
for(i= 0; i<len; i++)
|
|
|
|
(*linesw[tp->t_line].l_rint)(buf[i], tp);
|
|
|
|
else len= 0;
|
|
|
|
return(len);
|
|
|
|
}
|
|
|
|
|
1995-12-17 21:17:48 +00:00
|
|
|
static void
|
1995-02-14 15:00:39 +00:00
|
|
|
itystart(struct tty *tp)
|
|
|
|
{
|
|
|
|
int s, unit;
|
|
|
|
|
|
|
|
unit = UNIT(tp->t_dev);
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP))
|
|
|
|
{
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
1995-07-22 01:30:45 +00:00
|
|
|
ttwwakeup(tp);
|
1995-02-14 15:00:39 +00:00
|
|
|
if (tp->t_outq.c_cc)
|
|
|
|
{
|
|
|
|
if(OUTBOUND(tp->t_dev) && (tp->t_cflag & CLOCAL) &&
|
|
|
|
((tp->t_state & TS_CARR_ON) == 0))
|
|
|
|
isdn_msg(applnr[unit]);
|
|
|
|
else isdn_output(applnr[unit]);
|
|
|
|
tp->t_state |= TS_BUSY;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1995-02-15 06:28:29 +00:00
|
|
|
int
|
1995-02-14 15:00:39 +00:00
|
|
|
ity_out(int no, char *buf, int len)
|
|
|
|
{
|
|
|
|
struct tty *tp = &ity_tty[no];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(tp == NULL)
|
|
|
|
return(0);
|
|
|
|
if(tp->t_outq.c_cc)
|
|
|
|
{
|
|
|
|
for (i = 0; i < len && tp->t_outq.c_cc; ++i)
|
|
|
|
buf[i]= getc(&tp->t_outq);
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
tp->t_state &=~ (TS_BUSY|TS_FLUSH);
|
|
|
|
if (tp->t_line)
|
|
|
|
(*linesw[tp->t_line].l_start)(tp);
|
|
|
|
else
|
|
|
|
itystart(tp);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1995-02-15 06:28:29 +00:00
|
|
|
void
|
1995-02-14 15:00:39 +00:00
|
|
|
ity_connect(int no)
|
|
|
|
{
|
|
|
|
struct tty *tp = &ity_tty[no];
|
|
|
|
|
|
|
|
if(tp == NULL)
|
|
|
|
return;
|
|
|
|
if(OUTBOUND(tp->t_dev)) tp->t_cflag &= ~CLOCAL;
|
|
|
|
(*linesw[tp->t_line].l_modem) (tp, 1);
|
|
|
|
tp->t_state &=~ (TS_BUSY|TS_FLUSH);
|
|
|
|
if (tp->t_line)
|
|
|
|
(*linesw[tp->t_line].l_start)(tp);
|
|
|
|
else
|
|
|
|
itystart(tp);
|
|
|
|
}
|
|
|
|
|
1995-02-15 06:28:29 +00:00
|
|
|
void
|
1995-02-14 15:00:39 +00:00
|
|
|
ity_disconnect(int no)
|
|
|
|
{
|
|
|
|
struct tty *tp = &ity_tty[no];
|
|
|
|
if(tp) (*linesw[tp->t_line].l_modem) (tp, 0);
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-02-14 15:00:39 +00:00
|
|
|
ityioctl(dev, cmd, data, flag,p)
|
|
|
|
dev_t dev;
|
|
|
|
int cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
register struct tty *tp;
|
|
|
|
register int unit = UNIT(dev);
|
|
|
|
register int error;
|
|
|
|
|
|
|
|
tp = &ity_tty[unit];
|
|
|
|
error = (*linesw[tp->t_line].l_ioctl) (tp, cmd, data, flag,p);
|
|
|
|
if (error >= 0)
|
|
|
|
return (error);
|
|
|
|
error = ttioctl(tp, cmd, data, flag);
|
|
|
|
if (error >= 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return (ENOTTY);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-12-17 21:17:48 +00:00
|
|
|
static int
|
1995-02-14 15:00:39 +00:00
|
|
|
ityparam(tp, t)
|
|
|
|
register struct tty *tp;
|
|
|
|
register struct termios *t;
|
|
|
|
{
|
1996-06-12 05:11:41 +00:00
|
|
|
register int cflag = t->c_cflag;
|
1995-02-14 15:00:39 +00:00
|
|
|
int unit = UNIT(tp->t_dev);
|
|
|
|
int ospeed = t->c_ospeed;
|
|
|
|
|
|
|
|
/* check requested parameters */
|
|
|
|
if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
|
|
|
|
return (EINVAL);
|
|
|
|
/* and copy to tty */
|
|
|
|
tp->t_ispeed = t->c_ispeed;
|
|
|
|
tp->t_ospeed = t->c_ospeed;
|
|
|
|
tp->t_cflag = cflag;
|
|
|
|
|
|
|
|
if (ospeed == 0)
|
|
|
|
{
|
|
|
|
isdn_disconnect(applnr[unit],0);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop output on a line.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
1995-02-14 15:00:39 +00:00
|
|
|
itystop(struct tty *tp, int flag)
|
|
|
|
{
|
|
|
|
register int s;
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
if (tp->t_state & TS_BUSY)
|
|
|
|
{
|
|
|
|
if ((tp->t_state & TS_TTSTOP) == 0)
|
|
|
|
tp->t_state |= TS_FLUSH;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static struct tty *
|
1995-02-25 20:09:44 +00:00
|
|
|
itydevtotty(dev_t dev)
|
|
|
|
{
|
|
|
|
register int unit = UNIT(dev);
|
|
|
|
if (unit >= next_if)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
return (&ity_tty[unit]);
|
|
|
|
}
|
|
|
|
|
1995-11-29 10:49:16 +00:00
|
|
|
static ity_devsw_installed = 0;
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
|
|
|
ity_drvinit(void *unused)
|
1995-11-29 10:49:16 +00:00
|
|
|
{
|
|
|
|
dev_t dev;
|
|
|
|
|
|
|
|
if( ! ity_devsw_installed ) {
|
1995-12-08 11:19:42 +00:00
|
|
|
dev = makedev(CDEV_MAJOR, 0);
|
|
|
|
cdevsw_add(&dev,&ity_cdevsw, NULL);
|
1995-11-29 10:49:16 +00:00
|
|
|
ity_devsw_installed = 1;
|
1995-11-29 14:41:20 +00:00
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(itydev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,ity_drvinit,NULL)
|
|
|
|
|
1995-02-14 15:00:39 +00:00
|
|
|
#endif
|