2001-12-13 18:09:07 +03:00
|
|
|
/* $NetBSD: irframe_tty.c,v 1.14 2001/12/13 15:09:07 augustss Exp $ */
|
2001-12-05 02:33:33 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO
|
|
|
|
* Implement dongle support.
|
|
|
|
* Test!!!
|
|
|
|
* Get rid of MAX_IRDA_FRAME
|
|
|
|
*/
|
2001-12-04 02:32:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2001-12-05 04:13:58 +03:00
|
|
|
* by Lennart Augustsson (lennart@augustsson.net) and Tommy Bohlin
|
|
|
|
* (tommy@gatespace.com).
|
2001-12-04 02:32:32 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loosely based on ppp_tty.c.
|
2001-12-05 17:50:13 +03:00
|
|
|
* Framing and dongle handling written by Tommy Bohlin.
|
2001-12-04 02:32:32 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/kernel.h>
|
2001-12-04 22:56:43 +03:00
|
|
|
#include <sys/malloc.h>
|
2001-12-04 02:32:32 +03:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/file.h>
|
2001-12-04 22:56:43 +03:00
|
|
|
#include <sys/vnode.h>
|
2001-12-04 02:32:32 +03:00
|
|
|
#include <sys/poll.h>
|
|
|
|
|
|
|
|
#include <dev/ir/ir.h>
|
2001-12-05 17:50:13 +03:00
|
|
|
#include <dev/ir/sir.h>
|
2001-12-04 02:32:32 +03:00
|
|
|
#include <dev/ir/irdaio.h>
|
|
|
|
#include <dev/ir/irframevar.h>
|
|
|
|
|
|
|
|
/* Macros to clear/set/test flags. */
|
|
|
|
#define SET(t, f) (t) |= (f)
|
2001-12-04 22:56:43 +03:00
|
|
|
#define CLR(t, f) (t) &= ~(f)
|
2001-12-04 02:32:32 +03:00
|
|
|
#define ISSET(t, f) ((t) & (f))
|
|
|
|
|
|
|
|
#ifdef IRFRAMET_DEBUG
|
|
|
|
#define DPRINTF(x) if (irframetdebug) printf x
|
2001-12-04 22:56:43 +03:00
|
|
|
#define Static
|
2001-12-05 07:31:02 +03:00
|
|
|
int irframetdebug = 0;
|
2001-12-04 02:32:32 +03:00
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
2001-12-04 22:56:43 +03:00
|
|
|
#define Static static
|
2001-12-04 02:32:32 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*****/
|
|
|
|
|
2001-12-13 18:09:07 +03:00
|
|
|
/* Max size with framing. */
|
|
|
|
#define MAX_IRDA_FRAME (2*IRDA_MAX_FRAME_SIZE + IRDA_MAX_EBOFS + 4)
|
2001-12-04 02:32:32 +03:00
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
struct frame {
|
|
|
|
u_char *buf;
|
|
|
|
u_int len;
|
|
|
|
};
|
|
|
|
#define MAXFRAMES 4
|
|
|
|
|
2001-12-04 02:32:32 +03:00
|
|
|
struct irframet_softc {
|
|
|
|
struct irframe_softc sc_irp;
|
|
|
|
struct tty *sc_tp;
|
2001-12-04 22:56:43 +03:00
|
|
|
|
2001-12-05 02:33:33 +03:00
|
|
|
int sc_dongle;
|
2001-12-05 22:59:54 +03:00
|
|
|
int sc_dongle_private;
|
2001-12-05 02:33:33 +03:00
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
int sc_state;
|
|
|
|
#define IRT_RSLP 0x01 /* waiting for data (read) */
|
|
|
|
#if 0
|
|
|
|
#define IRT_WSLP 0x02 /* waiting for data (write) */
|
|
|
|
#define IRT_CLOSING 0x04 /* waiting for output to drain */
|
|
|
|
#endif
|
|
|
|
|
2001-12-04 02:32:32 +03:00
|
|
|
int sc_ebofs;
|
2001-12-05 00:50:50 +03:00
|
|
|
int sc_speed;
|
2001-12-04 22:56:43 +03:00
|
|
|
|
|
|
|
u_char* sc_inbuf;
|
|
|
|
int sc_maxsize;
|
|
|
|
int sc_framestate;
|
|
|
|
#define FRAME_OUTSIDE 0
|
|
|
|
#define FRAME_INSIDE 1
|
|
|
|
#define FRAME_ESCAPE 2
|
|
|
|
int sc_inchars;
|
|
|
|
int sc_inFCS;
|
|
|
|
struct callout sc_timeout;
|
|
|
|
|
|
|
|
u_int sc_nframes;
|
|
|
|
u_int sc_framei;
|
|
|
|
u_int sc_frameo;
|
|
|
|
struct frame sc_frames[MAXFRAMES];
|
|
|
|
struct selinfo sc_rsel;
|
2001-12-04 02:32:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* line discipline methods */
|
|
|
|
int irframetopen(dev_t dev, struct tty *tp);
|
|
|
|
int irframetclose(struct tty *tp, int flag);
|
|
|
|
int irframetioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
|
2001-12-05 02:33:33 +03:00
|
|
|
struct proc *);
|
2001-12-04 02:32:32 +03:00
|
|
|
int irframetinput(int c, struct tty *tp);
|
|
|
|
int irframetstart(struct tty *tp);
|
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
/* pseudo device init */
|
2001-12-04 02:32:32 +03:00
|
|
|
void irframettyattach(int);
|
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
/* irframe methods */
|
|
|
|
Static int irframet_open(void *h, int flag, int mode, struct proc *p);
|
|
|
|
Static int irframet_close(void *h, int flag, int mode, struct proc *p);
|
|
|
|
Static int irframet_read(void *h, struct uio *uio, int flag);
|
|
|
|
Static int irframet_write(void *h, struct uio *uio, int flag);
|
|
|
|
Static int irframet_poll(void *h, int events, struct proc *p);
|
|
|
|
Static int irframet_set_params(void *h, struct irda_params *params);
|
|
|
|
Static int irframet_get_speeds(void *h, int *speeds);
|
|
|
|
Static int irframet_get_turnarounds(void *h, int *times);
|
|
|
|
|
|
|
|
/* internal */
|
2001-12-05 22:59:54 +03:00
|
|
|
Static int irt_write_frame(struct tty *tp, u_int8_t *buf, size_t len);
|
|
|
|
Static int irt_putc(struct tty *tp, int c);
|
2001-12-04 22:56:43 +03:00
|
|
|
Static void irt_frame(struct irframet_softc *sc, u_char *buf, u_int len);
|
|
|
|
Static void irt_timeout(void *v);
|
2001-12-05 22:59:54 +03:00
|
|
|
Static void irt_setspeed(struct tty *tp, u_int speed);
|
|
|
|
Static void irt_setline(struct tty *tp, u_int line);
|
|
|
|
Static void irt_delay(struct tty *tp, u_int delay);
|
2001-12-04 22:56:43 +03:00
|
|
|
|
2001-12-05 22:59:54 +03:00
|
|
|
Static const struct irframe_methods irframet_methods = {
|
2001-12-04 02:32:32 +03:00
|
|
|
irframet_open, irframet_close, irframet_read, irframet_write,
|
2001-12-04 22:56:43 +03:00
|
|
|
irframet_poll, irframet_set_params,
|
|
|
|
irframet_get_speeds, irframet_get_turnarounds
|
2001-12-04 02:32:32 +03:00
|
|
|
};
|
|
|
|
|
2001-12-05 22:59:54 +03:00
|
|
|
Static void irts_none(struct tty *tp, u_int speed);
|
|
|
|
Static void irts_tekram(struct tty *tp, u_int speed);
|
|
|
|
Static void irts_jeteye(struct tty *tp, u_int speed);
|
|
|
|
Static void irts_actisys(struct tty *tp, u_int speed);
|
|
|
|
Static void irts_litelink(struct tty *tp, u_int speed);
|
|
|
|
Static void irts_girbil(struct tty *tp, u_int speed);
|
|
|
|
|
|
|
|
#define NORMAL_SPEEDS (IRDA_SPEEDS_SIR & ~IRDA_SPEED_2400)
|
|
|
|
#define TURNT_POS (IRDA_TURNT_10000 | IRDA_TURNT_5000 | IRDA_TURNT_1000 | \
|
|
|
|
IRDA_TURNT_500 | IRDA_TURNT_100 | IRDA_TURNT_50 | IRDA_TURNT_10)
|
|
|
|
Static const struct dongle {
|
|
|
|
void (*setspeed)(struct tty *tp, u_int speed);
|
|
|
|
u_int speedmask;
|
|
|
|
u_int turnmask;
|
|
|
|
} irt_dongles[DONGLE_MAX] = {
|
|
|
|
/* Indexed by dongle number from irdaio.h */
|
|
|
|
{ irts_none, IRDA_SPEEDS_SIR, IRDA_TURNT_10000 },
|
|
|
|
{ irts_tekram, IRDA_SPEEDS_SIR, IRDA_TURNT_10000 },
|
|
|
|
{ irts_jeteye, IRDA_SPEED_9600|IRDA_SPEED_19200|IRDA_SPEED_115200,
|
|
|
|
IRDA_TURNT_10000 },
|
|
|
|
{ irts_actisys, NORMAL_SPEEDS & ~IRDA_SPEED_38400, TURNT_POS },
|
|
|
|
{ irts_actisys, NORMAL_SPEEDS, TURNT_POS },
|
|
|
|
{ irts_litelink, NORMAL_SPEEDS, TURNT_POS },
|
|
|
|
{ irts_girbil, IRDA_SPEEDS_SIR, IRDA_TURNT_10000 | IRDA_TURNT_5000 },
|
|
|
|
};
|
|
|
|
|
2001-12-04 02:32:32 +03:00
|
|
|
void
|
|
|
|
irframettyattach(int n)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Line specific open routine for async tty devices.
|
|
|
|
* Attach the given tty to the first available irframe unit.
|
|
|
|
* Called from device open routine or ttioctl.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
irframetopen(dev_t dev, struct tty *tp)
|
|
|
|
{
|
|
|
|
struct proc *p = curproc; /* XXX */
|
|
|
|
struct irframet_softc *sc;
|
|
|
|
int error, s;
|
|
|
|
|
|
|
|
DPRINTF(("%s\n", __FUNCTION__));
|
|
|
|
|
|
|
|
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
2001-12-05 07:07:06 +03:00
|
|
|
DPRINTF(("%s: linesw=%p disc=%s\n", __FUNCTION__, tp->t_linesw,
|
|
|
|
tp->t_linesw->l_name));
|
|
|
|
if (strcmp(tp->t_linesw->l_name, "irframe") == 0) { /* XXX */
|
2001-12-04 02:32:32 +03:00
|
|
|
sc = (struct irframet_softc *)tp->t_sc;
|
|
|
|
DPRINTF(("%s: sc=%p sc_tp=%p\n", __FUNCTION__, sc, sc->sc_tp));
|
|
|
|
if (sc != NULL) {
|
|
|
|
splx(s);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tp->t_sc = irframe_alloc(sizeof (struct irframet_softc),
|
|
|
|
&irframet_methods, tp);
|
|
|
|
sc = (struct irframet_softc *)tp->t_sc;
|
|
|
|
sc->sc_tp = tp;
|
2001-12-05 07:07:06 +03:00
|
|
|
printf("%s attached at tty%02d\n", sc->sc_irp.sc_dev.dv_xname,
|
|
|
|
minor(tp->t_dev));
|
2001-12-04 02:32:32 +03:00
|
|
|
|
|
|
|
DPRINTF(("%s: set sc=%p\n", __FUNCTION__, sc));
|
|
|
|
|
|
|
|
ttyflush(tp, FREAD | FWRITE);
|
|
|
|
|
2001-12-05 02:33:33 +03:00
|
|
|
sc->sc_dongle = DONGLE_NONE;
|
2001-12-05 22:59:54 +03:00
|
|
|
sc->sc_dongle_private = 0;
|
2001-12-05 02:33:33 +03:00
|
|
|
|
2001-12-04 02:32:32 +03:00
|
|
|
splx(s);
|
2001-12-04 22:56:43 +03:00
|
|
|
|
2001-12-04 02:32:32 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Line specific close routine, called from device close routine
|
|
|
|
* and from ttioctl.
|
|
|
|
* Detach the tty from the irframe unit.
|
|
|
|
* Mimics part of ttyclose().
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
irframetclose(struct tty *tp, int flag)
|
|
|
|
{
|
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
ttyflush(tp, FREAD | FWRITE);
|
|
|
|
tp->t_linesw = linesw[0]; /* default line discipline */
|
|
|
|
if (sc != NULL) {
|
|
|
|
tp->t_sc = NULL;
|
2001-12-04 22:56:43 +03:00
|
|
|
printf("%s detached from tty%02d\n", sc->sc_irp.sc_dev.dv_xname,
|
2001-12-04 02:32:32 +03:00
|
|
|
minor(tp->t_dev));
|
|
|
|
|
|
|
|
if (sc->sc_tp == tp)
|
|
|
|
irframe_dealloc(&sc->sc_irp.sc_dev);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Line specific (tty) ioctl routine.
|
|
|
|
* This discipline requires that tty device drivers call
|
|
|
|
* the line specific l_ioctl routine from their ioctl routines.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
irframetioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
|
|
|
|
struct proc *p)
|
|
|
|
{
|
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
|
|
|
int error;
|
2001-12-05 22:59:54 +03:00
|
|
|
int d;
|
2001-12-04 02:32:32 +03:00
|
|
|
|
|
|
|
DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
|
|
|
|
|
|
|
|
if (sc == NULL || tp != sc->sc_tp)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
switch (cmd) {
|
2001-12-05 02:33:33 +03:00
|
|
|
case IRFRAMETTY_GET_DEVICE:
|
|
|
|
*(int *)data = sc->sc_irp.sc_dev.dv_unit;
|
|
|
|
break;
|
|
|
|
case IRFRAMETTY_GET_DONGLE:
|
|
|
|
*(int *)data = sc->sc_dongle;
|
|
|
|
break;
|
|
|
|
case IRFRAMETTY_SET_DONGLE:
|
2001-12-05 22:59:54 +03:00
|
|
|
d = *(int *)data;
|
|
|
|
if (d < 0 || d >= DONGLE_MAX)
|
|
|
|
return (EINVAL);
|
|
|
|
sc->sc_dongle = d;
|
2001-12-05 02:33:33 +03:00
|
|
|
break;
|
2001-12-04 02:32:32 +03:00
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-12-05 17:50:13 +03:00
|
|
|
* Start output on async tty interface.
|
2001-12-04 02:32:32 +03:00
|
|
|
* Called at spltty or higher.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
irframetstart(struct tty *tp)
|
|
|
|
{
|
|
|
|
/*struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;*/
|
|
|
|
|
|
|
|
DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
|
|
|
|
|
|
|
|
if (tp->t_oproc != NULL)
|
|
|
|
(*tp->t_oproc)(tp);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
void
|
|
|
|
irt_frame(struct irframet_softc *sc, u_char *buf, u_int len)
|
|
|
|
{
|
2001-12-05 07:07:06 +03:00
|
|
|
DPRINTF(("%s: nframe=%d framei=%d frameo=%d\n",
|
|
|
|
__FUNCTION__, sc->sc_nframes, sc->sc_framei, sc->sc_frameo));
|
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
if (sc->sc_nframes >= MAXFRAMES) {
|
|
|
|
#ifdef IRFRAMET_DEBUG
|
|
|
|
printf("%s: dropped frame\n", __FUNCTION__);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sc->sc_frames[sc->sc_framei].buf == NULL)
|
|
|
|
return;
|
|
|
|
memcpy(sc->sc_frames[sc->sc_framei].buf, buf, len);
|
|
|
|
sc->sc_frames[sc->sc_framei].len = len;
|
|
|
|
sc->sc_framei = (sc->sc_framei+1) % MAXFRAMES;
|
|
|
|
sc->sc_nframes++;
|
|
|
|
if (sc->sc_state & IRT_RSLP) {
|
|
|
|
sc->sc_state &= ~IRT_RSLP;
|
|
|
|
DPRINTF(("%s: waking up reader\n", __FUNCTION__));
|
|
|
|
wakeup(sc->sc_frames);
|
|
|
|
}
|
|
|
|
selwakeup(&sc->sc_rsel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
irt_timeout(void *v)
|
|
|
|
{
|
|
|
|
struct irframet_softc *sc = v;
|
|
|
|
|
|
|
|
#ifdef IRFRAMET_DEBUG
|
|
|
|
if (sc->sc_framestate != FRAME_OUTSIDE)
|
|
|
|
printf("%s: input frame timeout\n", __FUNCTION__);
|
|
|
|
#endif
|
|
|
|
sc->sc_framestate = FRAME_OUTSIDE;
|
|
|
|
}
|
|
|
|
|
2001-12-04 02:32:32 +03:00
|
|
|
int
|
|
|
|
irframetinput(int c, struct tty *tp)
|
|
|
|
{
|
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
|
|
|
|
2001-12-05 07:07:06 +03:00
|
|
|
c &= 0xff;
|
|
|
|
|
|
|
|
#if IRFRAMET_DEBUG
|
|
|
|
if (irframetdebug > 1)
|
|
|
|
DPRINTF(("%s: tp=%p c=0x%02x\n", __FUNCTION__, tp, c));
|
|
|
|
#endif
|
2001-12-04 02:32:32 +03:00
|
|
|
|
|
|
|
if (sc == NULL || tp != (struct tty *)sc->sc_tp)
|
|
|
|
return (0);
|
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
if (sc->sc_inbuf == NULL)
|
|
|
|
return (0);
|
2001-12-04 02:32:32 +03:00
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
switch (c) {
|
|
|
|
case SIR_BOF:
|
2001-12-05 07:07:06 +03:00
|
|
|
DPRINTF(("%s: BOF\n", __FUNCTION__));
|
2001-12-04 22:56:43 +03:00
|
|
|
sc->sc_framestate = FRAME_INSIDE;
|
|
|
|
sc->sc_inchars = 0;
|
|
|
|
sc->sc_inFCS = INITFCS;
|
|
|
|
break;
|
|
|
|
case SIR_EOF:
|
2001-12-05 07:07:06 +03:00
|
|
|
DPRINTF(("%s: EOF state=%d inchars=%d fcs=0x%04x\n",
|
|
|
|
__FUNCTION__,
|
|
|
|
sc->sc_framestate, sc->sc_inchars, sc->sc_inFCS));
|
2001-12-04 22:56:43 +03:00
|
|
|
if (sc->sc_framestate == FRAME_INSIDE &&
|
|
|
|
sc->sc_inchars >= 4 && sc->sc_inFCS == GOODFCS) {
|
|
|
|
irt_frame(sc, sc->sc_inbuf, sc->sc_inchars - 2);
|
|
|
|
} else if (sc->sc_framestate != FRAME_OUTSIDE) {
|
|
|
|
#ifdef IRFRAMET_DEBUG
|
|
|
|
printf("%s: malformed input frame\n", __FUNCTION__);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
sc->sc_framestate = FRAME_OUTSIDE;
|
|
|
|
break;
|
|
|
|
case SIR_CE:
|
2001-12-05 07:07:06 +03:00
|
|
|
DPRINTF(("%s: CE\n", __FUNCTION__));
|
2001-12-04 22:56:43 +03:00
|
|
|
if (sc->sc_framestate == FRAME_INSIDE)
|
|
|
|
sc->sc_framestate = FRAME_ESCAPE;
|
|
|
|
break;
|
|
|
|
default:
|
2001-12-05 07:31:02 +03:00
|
|
|
#if IRFRAMET_DEBUG
|
|
|
|
if (irframetdebug > 1)
|
2001-12-05 07:07:06 +03:00
|
|
|
DPRINTF(("%s: c=0x%02x, inchar=%d state=%d\n", __FUNCTION__, c,
|
|
|
|
sc->sc_inchars, sc->sc_state));
|
2001-12-05 07:31:02 +03:00
|
|
|
#endif
|
2001-12-04 22:56:43 +03:00
|
|
|
if (sc->sc_framestate != FRAME_OUTSIDE) {
|
|
|
|
if (sc->sc_framestate == FRAME_ESCAPE) {
|
|
|
|
sc->sc_framestate = FRAME_INSIDE;
|
|
|
|
c ^= SIR_ESC_BIT;
|
|
|
|
}
|
|
|
|
if (sc->sc_inchars < sc->sc_maxsize + 2) {
|
|
|
|
sc->sc_inbuf[sc->sc_inchars++] = c;
|
|
|
|
sc->sc_inFCS = updateFCS(sc->sc_inFCS, c);
|
|
|
|
} else {
|
|
|
|
sc->sc_framestate = FRAME_OUTSIDE;
|
|
|
|
#ifdef IRFRAMET_DEBUG
|
|
|
|
printf("%s: input frame overrun\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2001-12-04 02:32:32 +03:00
|
|
|
}
|
|
|
|
|
2001-12-05 07:07:06 +03:00
|
|
|
#if 1
|
2001-12-04 22:56:43 +03:00
|
|
|
if (sc->sc_framestate != FRAME_OUTSIDE) {
|
2001-12-05 07:07:06 +03:00
|
|
|
callout_reset(&sc->sc_timeout, hz/20, irt_timeout, sc);
|
2001-12-04 02:32:32 +03:00
|
|
|
}
|
2001-12-05 07:07:06 +03:00
|
|
|
#endif
|
2001-12-04 02:32:32 +03:00
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
return (0);
|
2001-12-04 02:32:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*** irframe methods ***/
|
|
|
|
|
|
|
|
int
|
|
|
|
irframet_open(void *h, int flag, int mode, struct proc *p)
|
|
|
|
{
|
|
|
|
struct tty *tp = h;
|
2001-12-04 23:53:21 +03:00
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
2001-12-04 02:32:32 +03:00
|
|
|
|
|
|
|
DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
|
2001-12-04 23:53:21 +03:00
|
|
|
|
2001-12-05 00:50:50 +03:00
|
|
|
sc->sc_speed = 0;
|
2001-12-04 23:53:21 +03:00
|
|
|
sc->sc_ebofs = IRDA_DEFAULT_EBOFS;
|
|
|
|
sc->sc_maxsize = 0;
|
|
|
|
sc->sc_framestate = FRAME_OUTSIDE;
|
|
|
|
sc->sc_nframes = 0;
|
|
|
|
sc->sc_framei = 0;
|
|
|
|
sc->sc_frameo = 0;
|
|
|
|
callout_init(&sc->sc_timeout);
|
|
|
|
|
2001-12-04 02:32:32 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
irframet_close(void *h, int flag, int mode, struct proc *p)
|
|
|
|
{
|
|
|
|
struct tty *tp = h;
|
2001-12-04 23:53:21 +03:00
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
|
|
|
int i, s;
|
2001-12-04 02:32:32 +03:00
|
|
|
|
|
|
|
DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
|
2001-12-04 23:53:21 +03:00
|
|
|
|
|
|
|
callout_stop(&sc->sc_timeout);
|
|
|
|
s = splir();
|
|
|
|
if (sc->sc_inbuf != NULL) {
|
|
|
|
free(sc->sc_inbuf, M_DEVBUF);
|
|
|
|
sc->sc_inbuf = NULL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAXFRAMES; i++) {
|
|
|
|
if (sc->sc_frames[i].buf != NULL) {
|
|
|
|
free(sc->sc_frames[i].buf, M_DEVBUF);
|
|
|
|
sc->sc_frames[i].buf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
2001-12-04 02:32:32 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
irframet_read(void *h, struct uio *uio, int flag)
|
|
|
|
{
|
|
|
|
struct tty *tp = h;
|
2001-12-04 22:56:43 +03:00
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
|
|
|
int error = 0;
|
|
|
|
int s;
|
2001-12-04 02:32:32 +03:00
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
DPRINTF(("%s: resid=%d, iovcnt=%d, offset=%ld\n",
|
|
|
|
__FUNCTION__, uio->uio_resid, uio->uio_iovcnt,
|
|
|
|
(long)uio->uio_offset));
|
2001-12-05 07:07:06 +03:00
|
|
|
DPRINTF(("%s: nframe=%d framei=%d frameo=%d\n",
|
|
|
|
__FUNCTION__, sc->sc_nframes, sc->sc_framei, sc->sc_frameo));
|
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
|
|
|
|
s = splir();
|
|
|
|
while (sc->sc_nframes == 0) {
|
|
|
|
if (flag & IO_NDELAY) {
|
|
|
|
splx(s);
|
|
|
|
return (EWOULDBLOCK);
|
|
|
|
}
|
|
|
|
sc->sc_state |= IRT_RSLP;
|
|
|
|
DPRINTF(("%s: sleep\n", __FUNCTION__));
|
|
|
|
error = tsleep(sc->sc_frames, PZERO | PCATCH, "irtrd", 0);
|
|
|
|
DPRINTF(("%s: woke, error=%d\n", __FUNCTION__, error));
|
|
|
|
if (error) {
|
|
|
|
sc->sc_state &= ~IRT_RSLP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do just one frame transfer per read */
|
|
|
|
if (!error) {
|
|
|
|
if (uio->uio_resid < sc->sc_frames[sc->sc_frameo].len) {
|
|
|
|
DPRINTF(("%s: uio buffer smaller than frame size (%d < %d)\n", __FUNCTION__, uio->uio_resid, sc->sc_frames[sc->sc_frameo].len));
|
|
|
|
error = EINVAL;
|
|
|
|
} else {
|
|
|
|
DPRINTF(("%s: moving %d bytes\n", __FUNCTION__,
|
|
|
|
sc->sc_frames[sc->sc_frameo].len));
|
2001-12-05 07:07:06 +03:00
|
|
|
error = uiomove(sc->sc_frames[sc->sc_frameo].buf,
|
2001-12-04 22:56:43 +03:00
|
|
|
sc->sc_frames[sc->sc_frameo].len, uio);
|
2001-12-05 07:07:06 +03:00
|
|
|
DPRINTF(("%s: error=%d\n", __FUNCTION__, error));
|
2001-12-04 22:56:43 +03:00
|
|
|
}
|
2001-12-05 07:07:06 +03:00
|
|
|
sc->sc_frameo = (sc->sc_frameo+1) % MAXFRAMES;
|
2001-12-04 22:56:43 +03:00
|
|
|
sc->sc_nframes--;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (error);
|
2001-12-04 02:32:32 +03:00
|
|
|
}
|
|
|
|
|
2001-12-04 22:56:43 +03:00
|
|
|
int
|
2001-12-05 22:59:54 +03:00
|
|
|
irt_putc(struct tty *tp, int c)
|
2001-12-04 02:32:32 +03:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
int error;
|
|
|
|
|
2001-12-05 17:50:13 +03:00
|
|
|
#if IRFRAMET_DEBUG
|
|
|
|
if (irframetdebug > 3)
|
|
|
|
DPRINTF(("%s: tp=%p c=0x%02x cc=%d\n", __FUNCTION__, tp, c,
|
|
|
|
tp->t_outq.c_cc));
|
|
|
|
#endif
|
2001-12-04 02:32:32 +03:00
|
|
|
if (tp->t_outq.c_cc > tp->t_hiwat) {
|
|
|
|
irframetstart(tp);
|
|
|
|
s = spltty();
|
|
|
|
/*
|
|
|
|
* This can only occur if FLUSHO is set in t_lflag,
|
|
|
|
* or if ttstart/oproc is synchronous (or very fast).
|
|
|
|
*/
|
|
|
|
if (tp->t_outq.c_cc <= tp->t_hiwat) {
|
|
|
|
splx(s);
|
|
|
|
goto go;
|
|
|
|
}
|
|
|
|
SET(tp->t_state, TS_ASLEEP);
|
|
|
|
error = ttysleep(tp, &tp->t_outq, TTOPRI | PCATCH, ttyout, 0);
|
|
|
|
splx(s);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
go:
|
2001-12-05 07:31:02 +03:00
|
|
|
if (putc(c, &tp->t_outq) < 0) {
|
2001-12-04 02:32:32 +03:00
|
|
|
printf("irframe: putc failed\n");
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
irframet_write(void *h, struct uio *uio, int flag)
|
|
|
|
{
|
2001-12-05 17:50:13 +03:00
|
|
|
struct tty *tp = h;
|
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
2001-12-04 02:32:32 +03:00
|
|
|
u_int8_t buf[MAX_IRDA_FRAME];
|
2001-12-05 17:50:13 +03:00
|
|
|
int n;
|
2001-12-04 02:32:32 +03:00
|
|
|
|
2001-12-05 07:07:06 +03:00
|
|
|
DPRINTF(("%s: resid=%d, iovcnt=%d, offset=%ld\n",
|
|
|
|
__FUNCTION__, uio->uio_resid, uio->uio_iovcnt,
|
|
|
|
(long)uio->uio_offset));
|
2001-12-04 02:32:32 +03:00
|
|
|
|
2001-12-05 17:50:13 +03:00
|
|
|
n = irda_sir_frame(buf, MAX_IRDA_FRAME, uio, sc->sc_ebofs);
|
2001-12-06 03:11:18 +03:00
|
|
|
if (n < 0) {
|
|
|
|
#ifdef IRFRAMET_DEBUG
|
|
|
|
printf("%s: irda_sir_frame() error=%d\n", __FUNCTION__, -n);
|
|
|
|
#endif
|
2001-12-05 17:50:13 +03:00
|
|
|
return (-n);
|
2001-12-06 03:11:18 +03:00
|
|
|
}
|
2001-12-05 22:59:54 +03:00
|
|
|
return (irt_write_frame(tp, buf, n));
|
2001-12-04 02:32:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-12-05 22:59:54 +03:00
|
|
|
irt_write_frame(struct tty *tp, u_int8_t *buf, size_t len)
|
2001-12-04 02:32:32 +03:00
|
|
|
{
|
2001-12-05 17:50:13 +03:00
|
|
|
int error, i;
|
2001-12-04 02:32:32 +03:00
|
|
|
|
|
|
|
DPRINTF(("%s: tp=%p len=%d\n", __FUNCTION__, tp, len));
|
|
|
|
|
|
|
|
error = 0;
|
2001-12-05 17:50:13 +03:00
|
|
|
for (i = 0; !error && i < len; i++)
|
2001-12-05 22:59:54 +03:00
|
|
|
error = irt_putc(tp, buf[i]);
|
2001-12-04 02:32:32 +03:00
|
|
|
|
|
|
|
irframetstart(tp);
|
|
|
|
|
2001-12-05 17:50:13 +03:00
|
|
|
DPRINTF(("%s: done, error=%d\n", __FUNCTION__, error));
|
2001-12-05 07:07:06 +03:00
|
|
|
|
2001-12-04 02:32:32 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
irframet_poll(void *h, int events, struct proc *p)
|
|
|
|
{
|
2001-12-04 22:56:43 +03:00
|
|
|
struct tty *tp = h;
|
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
2001-12-04 02:32:32 +03:00
|
|
|
int revents = 0;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
DPRINTF(("%s: sc=%p\n", __FUNCTION__, sc));
|
|
|
|
|
|
|
|
s = splir();
|
2001-12-05 17:50:13 +03:00
|
|
|
/* XXX is this a good check? */
|
2001-12-04 02:32:32 +03:00
|
|
|
if (events & (POLLOUT | POLLWRNORM))
|
2001-12-05 17:50:13 +03:00
|
|
|
if (tp->t_outq.c_cc <= tp->t_lowat)
|
|
|
|
revents |= events & (POLLOUT | POLLWRNORM);
|
|
|
|
|
2001-12-04 02:32:32 +03:00
|
|
|
if (events & (POLLIN | POLLRDNORM)) {
|
2001-12-04 22:56:43 +03:00
|
|
|
if (sc->sc_nframes > 0) {
|
2001-12-04 02:32:32 +03:00
|
|
|
DPRINTF(("%s: have data\n", __FUNCTION__));
|
|
|
|
revents |= events & (POLLIN | POLLRDNORM);
|
|
|
|
} else {
|
2001-12-05 07:07:06 +03:00
|
|
|
DPRINTF(("%s: recording select\n", __FUNCTION__));
|
2001-12-04 02:32:32 +03:00
|
|
|
selrecord(p, &sc->sc_rsel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (revents);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
irframet_set_params(void *h, struct irda_params *p)
|
|
|
|
{
|
|
|
|
struct tty *tp = h;
|
2001-12-04 23:53:21 +03:00
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
2001-12-04 22:56:43 +03:00
|
|
|
int i;
|
2001-12-04 02:32:32 +03:00
|
|
|
|
2001-12-05 07:07:06 +03:00
|
|
|
DPRINTF(("%s: tp=%p speed=%d ebofs=%d maxsize=%d\n",
|
|
|
|
__FUNCTION__, tp, p->speed, p->ebofs, p->maxsize));
|
2001-12-04 02:32:32 +03:00
|
|
|
|
2001-12-05 00:50:50 +03:00
|
|
|
if (p->speed != sc->sc_speed) {
|
2001-12-13 18:09:07 +03:00
|
|
|
/* Checked in irframe.c */
|
2001-12-05 22:59:54 +03:00
|
|
|
irt_dongles[sc->sc_dongle].setspeed(tp, p->speed);
|
|
|
|
sc->sc_speed = p->speed;
|
2001-12-04 23:53:21 +03:00
|
|
|
}
|
|
|
|
|
2001-12-13 18:09:07 +03:00
|
|
|
/* Max size checked in irframe.c */
|
2001-12-04 02:32:32 +03:00
|
|
|
sc->sc_ebofs = p->ebofs;
|
2001-12-13 18:09:07 +03:00
|
|
|
/* Max size checked in irframe.c */
|
2001-12-04 22:56:43 +03:00
|
|
|
if (sc->sc_maxsize != p->maxsize) {
|
|
|
|
sc->sc_maxsize = p->maxsize;
|
|
|
|
if (sc->sc_inbuf != NULL)
|
|
|
|
free(sc->sc_inbuf, M_DEVBUF);
|
|
|
|
for (i = 0; i < MAXFRAMES; i++)
|
|
|
|
if (sc->sc_frames[i].buf != NULL)
|
|
|
|
free(sc->sc_frames[i].buf, M_DEVBUF);
|
|
|
|
if (sc->sc_maxsize != 0) {
|
|
|
|
sc->sc_inbuf = malloc(sc->sc_maxsize+2, M_DEVBUF,
|
|
|
|
M_WAITOK);
|
|
|
|
for (i = 0; i < MAXFRAMES; i++)
|
|
|
|
sc->sc_frames[i].buf = malloc(sc->sc_maxsize,
|
|
|
|
M_DEVBUF, M_WAITOK);
|
|
|
|
} else {
|
|
|
|
sc->sc_inbuf = NULL;
|
|
|
|
for (i = 0; i < MAXFRAMES; i++)
|
|
|
|
sc->sc_frames[i].buf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sc->sc_framestate = FRAME_OUTSIDE;
|
2001-12-04 02:32:32 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
irframet_get_speeds(void *h, int *speeds)
|
|
|
|
{
|
|
|
|
struct tty *tp = h;
|
2001-12-05 22:59:54 +03:00
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
2001-12-04 02:32:32 +03:00
|
|
|
|
|
|
|
DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
|
2001-12-05 22:59:54 +03:00
|
|
|
|
2001-12-06 03:11:18 +03:00
|
|
|
if (sc == NULL) /* during attach */
|
|
|
|
*speeds = IRDA_SPEEDS_SIR;
|
|
|
|
else
|
|
|
|
*speeds = irt_dongles[sc->sc_dongle].speedmask;
|
2001-12-04 02:32:32 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
irframet_get_turnarounds(void *h, int *turnarounds)
|
|
|
|
{
|
|
|
|
struct tty *tp = h;
|
2001-12-05 22:59:54 +03:00
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
2001-12-04 02:32:32 +03:00
|
|
|
|
|
|
|
DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
|
2001-12-05 22:59:54 +03:00
|
|
|
|
|
|
|
*turnarounds = irt_dongles[sc->sc_dongle].turnmask;
|
2001-12-04 02:32:32 +03:00
|
|
|
return (0);
|
|
|
|
}
|
2001-12-05 22:59:54 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
irt_setspeed(struct tty *tp, u_int speed)
|
|
|
|
{
|
|
|
|
struct termios tt;
|
|
|
|
|
|
|
|
ttioctl(tp, TIOCGETA, (caddr_t)&tt, 0, curproc);
|
|
|
|
tt.c_ispeed = tt.c_ospeed = speed;
|
|
|
|
ttioctl(tp, TIOCSETAF, (caddr_t)&tt, 0, curproc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
irt_setline(struct tty *tp, u_int line)
|
|
|
|
{
|
|
|
|
int mline = line;
|
|
|
|
ttioctl(tp, TIOCMSET, (caddr_t)&mline, 0, curproc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
irt_delay(struct tty *tp, u_int ms)
|
|
|
|
{
|
|
|
|
if (cold)
|
|
|
|
delay(ms * 1000);
|
|
|
|
else
|
2001-12-12 20:21:36 +03:00
|
|
|
tsleep(&irt_delay, PZERO, "irtdly", ms * hz / 1000 + 1);
|
2001-12-05 22:59:54 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* No dongle
|
|
|
|
**********************************************************************/
|
|
|
|
void
|
|
|
|
irts_none(struct tty *tp, u_int speed)
|
|
|
|
{
|
|
|
|
irt_setspeed(tp, speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Tekram
|
|
|
|
**********************************************************************/
|
|
|
|
#define TEKRAM_PW 0x10
|
|
|
|
|
|
|
|
#define TEKRAM_115200 (TEKRAM_PW|0x00)
|
|
|
|
#define TEKRAM_57600 (TEKRAM_PW|0x01)
|
|
|
|
#define TEKRAM_38400 (TEKRAM_PW|0x02)
|
|
|
|
#define TEKRAM_19200 (TEKRAM_PW|0x03)
|
|
|
|
#define TEKRAM_9600 (TEKRAM_PW|0x04)
|
|
|
|
#define TEKRAM_2400 (TEKRAM_PW|0x08)
|
|
|
|
|
|
|
|
#define TEKRAM_TV (TEKRAM_PW|0x05)
|
|
|
|
|
|
|
|
void
|
|
|
|
irts_tekram(struct tty *tp, u_int speed)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
irt_setspeed(tp, 9600);
|
|
|
|
irt_setline(tp, 0);
|
|
|
|
irt_delay(tp, 50);
|
|
|
|
irt_setline(tp, TIOCM_RTS);
|
|
|
|
irt_delay(tp, 1);
|
|
|
|
irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
|
|
|
|
irt_delay(tp, 1); /* 50 us */
|
|
|
|
irt_setline(tp, TIOCM_DTR);
|
|
|
|
irt_delay(tp, 1); /* 7 us */
|
|
|
|
switch(speed) {
|
|
|
|
case 115200: s = TEKRAM_115200; break;
|
|
|
|
case 57600: s = TEKRAM_57600; break;
|
|
|
|
case 38400: s = TEKRAM_38400; break;
|
|
|
|
case 19200: s = TEKRAM_19200; break;
|
|
|
|
case 2400: s = TEKRAM_2400; break;
|
|
|
|
default: s = TEKRAM_9600; break;
|
|
|
|
}
|
|
|
|
irt_putc(tp, s);
|
2001-12-12 20:52:06 +03:00
|
|
|
irt_delay(tp, 100);
|
2001-12-05 22:59:54 +03:00
|
|
|
irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
|
|
|
|
if (speed != 9600)
|
|
|
|
irt_setspeed(tp, speed);
|
|
|
|
irt_delay(tp, 1); /* 50 us */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Jeteye
|
|
|
|
**********************************************************************/
|
|
|
|
void
|
|
|
|
irts_jeteye(struct tty *tp, u_int speed)
|
|
|
|
{
|
|
|
|
switch (speed) {
|
|
|
|
case 19200:
|
|
|
|
irt_setline(tp, TIOCM_DTR);
|
|
|
|
break;
|
|
|
|
case 115200:
|
|
|
|
irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
|
|
|
|
break;
|
|
|
|
default: /*9600*/
|
|
|
|
irt_setline(tp, TIOCM_RTS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
irt_setspeed(tp, speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Actisys
|
|
|
|
**********************************************************************/
|
|
|
|
void
|
|
|
|
irts_actisys(struct tty *tp, u_int speed)
|
|
|
|
{
|
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
|
|
|
int pulses;
|
|
|
|
|
|
|
|
irt_setspeed(tp, speed);
|
|
|
|
|
|
|
|
switch(speed) {
|
|
|
|
case 19200: pulses=1; break;
|
|
|
|
case 57600: pulses=2; break;
|
|
|
|
case 115200: pulses=3; break;
|
|
|
|
case 38400: pulses=4; break;
|
|
|
|
default: /* 9600 */ pulses=0; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_dongle_private == 0) {
|
|
|
|
sc->sc_dongle_private = 1;
|
|
|
|
irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
|
|
|
|
/*
|
|
|
|
* Must wait at least 50ms after initial
|
|
|
|
* power on to charge internal capacitor
|
|
|
|
*/
|
|
|
|
irt_delay(tp, 50);
|
|
|
|
}
|
|
|
|
irt_setline(tp, TIOCM_RTS);
|
|
|
|
delay(2);
|
|
|
|
for (;;) {
|
|
|
|
irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
|
|
|
|
delay(2);
|
|
|
|
if (--pulses <= 0)
|
|
|
|
break;
|
|
|
|
irt_setline(tp, TIOCM_DTR);
|
|
|
|
delay(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Litelink
|
|
|
|
**********************************************************************/
|
|
|
|
void
|
|
|
|
irts_litelink(struct tty *tp, u_int speed)
|
|
|
|
{
|
|
|
|
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
|
|
|
|
int pulses;
|
|
|
|
|
|
|
|
irt_setspeed(tp, speed);
|
|
|
|
|
|
|
|
switch(speed) {
|
|
|
|
case 57600: pulses=1; break;
|
|
|
|
case 38400: pulses=2; break;
|
|
|
|
case 19200: pulses=3; break;
|
|
|
|
case 9600: pulses=4; break;
|
|
|
|
default: /* 115200 */ pulses=0; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_dongle_private == 0) {
|
|
|
|
sc->sc_dongle_private = 1;
|
|
|
|
irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
|
|
|
|
}
|
|
|
|
irt_setline(tp, TIOCM_RTS);
|
|
|
|
irt_delay(tp, 1); /* 15 us */;
|
|
|
|
for (;;) {
|
|
|
|
irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
|
|
|
|
irt_delay(tp, 1); /* 15 us */;
|
|
|
|
if (--pulses <= 0)
|
|
|
|
break;
|
|
|
|
irt_setline(tp, TIOCM_DTR);
|
|
|
|
irt_delay(tp, 1); /* 15 us */;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Girbil
|
|
|
|
**********************************************************************/
|
|
|
|
/* Control register 1 */
|
|
|
|
#define GIRBIL_TXEN 0x01 /* Enable transmitter */
|
|
|
|
#define GIRBIL_RXEN 0x02 /* Enable receiver */
|
|
|
|
#define GIRBIL_ECAN 0x04 /* Cancel self emmited data */
|
|
|
|
#define GIRBIL_ECHO 0x08 /* Echo control characters */
|
|
|
|
|
|
|
|
/* LED Current Register */
|
|
|
|
#define GIRBIL_HIGH 0x20
|
|
|
|
#define GIRBIL_MEDIUM 0x21
|
|
|
|
#define GIRBIL_LOW 0x22
|
|
|
|
|
|
|
|
/* Baud register */
|
|
|
|
#define GIRBIL_2400 0x30
|
|
|
|
#define GIRBIL_4800 0x31
|
|
|
|
#define GIRBIL_9600 0x32
|
|
|
|
#define GIRBIL_19200 0x33
|
|
|
|
#define GIRBIL_38400 0x34
|
|
|
|
#define GIRBIL_57600 0x35
|
|
|
|
#define GIRBIL_115200 0x36
|
|
|
|
|
|
|
|
/* Mode register */
|
|
|
|
#define GIRBIL_IRDA 0x40
|
|
|
|
#define GIRBIL_ASK 0x41
|
|
|
|
|
|
|
|
/* Control register 2 */
|
|
|
|
#define GIRBIL_LOAD 0x51 /* Load the new baud rate value */
|
|
|
|
|
|
|
|
void
|
|
|
|
irts_girbil(struct tty *tp, u_int speed)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
irt_setspeed(tp, 9600);
|
|
|
|
irt_setline(tp, TIOCM_DTR);
|
|
|
|
irt_delay(tp, 5);
|
|
|
|
irt_setline(tp, TIOCM_RTS);
|
|
|
|
irt_delay(tp, 20);
|
|
|
|
switch(speed) {
|
|
|
|
case 115200: s = GIRBIL_115200; break;
|
|
|
|
case 57600: s = GIRBIL_57600; break;
|
|
|
|
case 38400: s = GIRBIL_38400; break;
|
|
|
|
case 19200: s = GIRBIL_19200; break;
|
|
|
|
case 4800: s = GIRBIL_4800; break;
|
|
|
|
case 2400: s = GIRBIL_2400; break;
|
|
|
|
default: s = GIRBIL_9600; break;
|
|
|
|
}
|
|
|
|
irt_putc(tp, GIRBIL_TXEN|GIRBIL_RXEN);
|
|
|
|
irt_putc(tp, s);
|
|
|
|
irt_putc(tp, GIRBIL_LOAD);
|
|
|
|
irt_delay(tp, 100);
|
|
|
|
irt_setline(tp, TIOCM_DTR | TIOCM_RTS);
|
|
|
|
if (speed != 9600)
|
|
|
|
irt_setspeed(tp, speed);
|
|
|
|
}
|