1998-12-27 21:47:14 +00:00
|
|
|
/*
|
2002-03-17 09:33:15 +00:00
|
|
|
* Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved.
|
1998-12-27 21:47:14 +00: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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* i4btrc - device driver for trace data read device
|
|
|
|
* ---------------------------------------------------
|
2002-03-17 09:33:15 +00:00
|
|
|
* last edit-date: [Sun Mar 17 09:52:51 2002]
|
1998-12-27 21:47:14 +00:00
|
|
|
*
|
|
|
|
* NOTE: the code assumes that SPLI4B >= splimp !
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
|
2003-06-10 23:23:33 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
#include "i4btrc.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
|
|
|
|
#include <machine/i4b_trace.h>
|
|
|
|
#include <machine/i4b_ioctl.h>
|
1999-12-14 20:48:35 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
#include <i4b/include/i4b_mbuf.h>
|
|
|
|
#include <i4b/include/i4b_global.h>
|
|
|
|
#include <i4b/include/i4b_l3l4.h>
|
|
|
|
|
|
|
|
static struct ifqueue trace_queue[NI4BTRC];
|
2002-03-17 09:33:15 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
static int device_state[NI4BTRC];
|
|
|
|
#define ST_IDLE 0x00
|
|
|
|
#define ST_ISOPEN 0x01
|
|
|
|
#define ST_WAITDATA 0x02
|
|
|
|
|
|
|
|
static int analyzemode = 0;
|
|
|
|
static int rxunit = -1;
|
|
|
|
static int txunit = -1;
|
|
|
|
static int outunit = -1;
|
|
|
|
|
|
|
|
static d_open_t i4btrcopen;
|
|
|
|
static d_close_t i4btrcclose;
|
|
|
|
static d_read_t i4btrcread;
|
|
|
|
static d_ioctl_t i4btrcioctl;
|
|
|
|
static d_poll_t i4btrcpoll;
|
|
|
|
|
|
|
|
#define CDEV_MAJOR 59
|
1999-08-06 14:05:10 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
static struct cdevsw i4btrc_cdevsw = {
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = i4btrcopen,
|
|
|
|
.d_close = i4btrcclose,
|
|
|
|
.d_read = i4btrcread,
|
|
|
|
.d_ioctl = i4btrcioctl,
|
|
|
|
.d_poll = i4btrcpoll,
|
|
|
|
.d_name = "i4btrc",
|
|
|
|
.d_maj = CDEV_MAJOR,
|
1998-12-27 21:47:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void i4btrcattach(void *);
|
|
|
|
PSEUDO_SET(i4btrcattach, i4b_trace);
|
|
|
|
|
|
|
|
int get_trace_data_from_l1(i4b_trace_hdr_t *hdr, int len, char *buf);
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* interface attach routine
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static void
|
1998-12-27 21:47:14 +00:00
|
|
|
i4btrcattach(void *dummy)
|
|
|
|
{
|
|
|
|
int i;
|
2001-01-15 14:54:43 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
printf("i4btrc: %d ISDN trace device(s) attached\n", NI4BTRC);
|
|
|
|
|
|
|
|
for(i=0; i < NI4BTRC; i++)
|
|
|
|
{
|
1999-08-27 07:26:26 +00:00
|
|
|
make_dev(&i4btrc_cdevsw, i,
|
|
|
|
UID_ROOT, GID_WHEEL, 0600, "i4btrc%d", i);
|
1998-12-27 21:47:14 +00:00
|
|
|
trace_queue[i].ifq_maxlen = IFQ_MAXLEN;
|
2001-01-15 14:54:43 +00:00
|
|
|
|
2001-12-30 09:27:28 +00:00
|
|
|
if(!mtx_initialized(&trace_queue[i].ifq_mtx))
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&trace_queue[i].ifq_mtx, "i4b_trace", NULL, MTX_DEF);
|
2002-03-17 09:33:15 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
device_state[i] = ST_IDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* get_trace_data_from_l1()
|
|
|
|
* ------------------------
|
|
|
|
* is called from layer 1, adds timestamp to trace data and puts
|
|
|
|
* it into a queue, from which it can be read from the i4btrc
|
|
|
|
* device. The unit number in the trace header selects the minor
|
|
|
|
* device's queue the data is put into.
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
get_trace_data_from_l1(i4b_trace_hdr_t *hdr, int len, char *buf)
|
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
int x;
|
|
|
|
int unit;
|
|
|
|
int trunc = 0;
|
|
|
|
int totlen = len + sizeof(i4b_trace_hdr_t);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* for telephony (or better non-HDLC HSCX mode) we get
|
|
|
|
* (MCLBYTE + sizeof(i4b_trace_hdr_t)) length packets
|
|
|
|
* to put into the queue to userland. because of this
|
|
|
|
* we detect this situation, strip the length to MCLBYTES
|
|
|
|
* max size, and infor the userland program of this fact
|
|
|
|
* by putting the no of truncated bytes into hdr->trunc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(totlen > MCLBYTES)
|
|
|
|
{
|
|
|
|
trunc = 1;
|
|
|
|
hdr->trunc = totlen - MCLBYTES;
|
|
|
|
totlen = MCLBYTES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hdr->trunc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set length of trace record */
|
|
|
|
|
|
|
|
hdr->length = totlen;
|
|
|
|
|
|
|
|
/* check valid unit no */
|
|
|
|
|
2003-05-31 16:57:01 +00:00
|
|
|
if((unit = hdr->unit) >= NI4BTRC)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
printf("i4b_trace: get_trace_data_from_l1 - unit > NI4BTRC!\n");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get mbuf */
|
|
|
|
|
|
|
|
if(!(m = i4b_Bgetmbuf(totlen)))
|
|
|
|
{
|
|
|
|
printf("i4b_trace: get_trace_data_from_l1 - i4b_getmbuf() failed!\n");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we are in analyzemode */
|
|
|
|
|
|
|
|
if(analyzemode && (unit == rxunit || unit == txunit))
|
|
|
|
{
|
|
|
|
if(unit == rxunit)
|
|
|
|
hdr->dir = FROM_NT;
|
|
|
|
else
|
|
|
|
hdr->dir = FROM_TE;
|
|
|
|
unit = outunit;
|
|
|
|
}
|
|
|
|
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
IF_LOCK(&trace_queue[unit]);
|
2002-03-17 09:33:15 +00:00
|
|
|
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
if(_IF_QFULL(&trace_queue[unit]))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m1;
|
|
|
|
|
|
|
|
x = SPLI4B();
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
_IF_DEQUEUE(&trace_queue[unit], m1);
|
1998-12-27 21:47:14 +00:00
|
|
|
splx(x);
|
|
|
|
|
|
|
|
i4b_Bfreembuf(m1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy trace header */
|
|
|
|
memcpy(m->m_data, hdr, sizeof(i4b_trace_hdr_t));
|
|
|
|
|
|
|
|
/* copy trace data */
|
|
|
|
if(trunc)
|
|
|
|
memcpy(&m->m_data[sizeof(i4b_trace_hdr_t)], buf, totlen-sizeof(i4b_trace_hdr_t));
|
|
|
|
else
|
|
|
|
memcpy(&m->m_data[sizeof(i4b_trace_hdr_t)], buf, len);
|
|
|
|
|
|
|
|
x = SPLI4B();
|
|
|
|
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
_IF_ENQUEUE(&trace_queue[unit], m);
|
|
|
|
IF_UNLOCK(&trace_queue[unit]);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
if(device_state[unit] & ST_WAITDATA)
|
|
|
|
{
|
|
|
|
device_state[unit] &= ~ST_WAITDATA;
|
2003-03-02 16:54:40 +00:00
|
|
|
wakeup( &trace_queue[unit]);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
splx(x);
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* open trace device
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
i4btrcopen(dev_t dev, int flag, int fmt, struct thread *td)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int unit = minor(dev);
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
if(unit >= NI4BTRC)
|
1998-12-27 21:47:14 +00:00
|
|
|
return(ENXIO);
|
|
|
|
|
|
|
|
if(device_state[unit] & ST_ISOPEN)
|
|
|
|
return(EBUSY);
|
|
|
|
|
|
|
|
if(analyzemode && (unit == outunit || unit == rxunit || unit == txunit))
|
|
|
|
return(EBUSY);
|
|
|
|
|
|
|
|
x = SPLI4B();
|
|
|
|
|
|
|
|
device_state[unit] = ST_ISOPEN;
|
|
|
|
|
|
|
|
splx(x);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* close trace device
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
i4btrcclose(dev_t dev, int flag, int fmt, struct thread *td)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
int unit = minor(dev);
|
2000-10-09 13:18:17 +00:00
|
|
|
int i, x;
|
|
|
|
int cno = -1;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
for(i=0; i < nctrl; i++)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
if((ctrl_desc[i].ctrl_type == CTRL_PASSIVE) &&
|
|
|
|
(ctrl_desc[i].unit == unit))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
cno = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(analyzemode && (unit == outunit))
|
|
|
|
{
|
|
|
|
analyzemode = 0;
|
|
|
|
outunit = -1;
|
|
|
|
|
|
|
|
if(cno >= 0)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
(*ctrl_desc[cno].N_MGMT_COMMAND)(rxunit, CMR_SETTRACE, TRACE_OFF);
|
|
|
|
(*ctrl_desc[cno].N_MGMT_COMMAND)(txunit, CMR_SETTRACE, TRACE_OFF);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
rxunit = -1;
|
|
|
|
txunit = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cno >= 0)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
(*ctrl_desc[cno].N_MGMT_COMMAND)(ctrl_desc[cno].unit, CMR_SETTRACE, TRACE_OFF);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
x = SPLI4B();
|
|
|
|
device_state[unit] = ST_IDLE;
|
|
|
|
splx(x);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* read from trace device
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
1998-12-27 21:47:14 +00:00
|
|
|
i4btrcread(dev_t dev, struct uio * uio, int ioflag)
|
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
int x;
|
|
|
|
int error = 0;
|
|
|
|
int unit = minor(dev);
|
|
|
|
|
|
|
|
if(!(device_state[unit] & ST_ISOPEN))
|
|
|
|
return(EIO);
|
|
|
|
|
|
|
|
x = SPLI4B();
|
|
|
|
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
IF_LOCK(&trace_queue[unit]);
|
2002-03-17 09:33:15 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
while(IF_QEMPTY(&trace_queue[unit]) && (device_state[unit] & ST_ISOPEN))
|
|
|
|
{
|
|
|
|
device_state[unit] |= ST_WAITDATA;
|
|
|
|
|
2003-03-02 16:54:40 +00:00
|
|
|
if((error = msleep( &trace_queue[unit],
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
&trace_queue[unit].ifq_mtx,
|
2003-11-10 14:20:34 +00:00
|
|
|
I4BPRI | PCATCH,
|
1998-12-27 21:47:14 +00:00
|
|
|
"bitrc", 0 )) != 0)
|
|
|
|
{
|
|
|
|
device_state[unit] &= ~ST_WAITDATA;
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
IF_UNLOCK(&trace_queue[unit]);
|
1998-12-27 21:47:14 +00:00
|
|
|
splx(x);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
_IF_DEQUEUE(&trace_queue[unit], m);
|
|
|
|
IF_UNLOCK(&trace_queue[unit]);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
if(m && m->m_len)
|
|
|
|
error = uiomove(m->m_data, m->m_len, uio);
|
|
|
|
else
|
|
|
|
error = EIO;
|
|
|
|
|
|
|
|
if(m)
|
|
|
|
i4b_Bfreembuf(m);
|
|
|
|
|
|
|
|
splx(x);
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* poll device
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
i4btrcpoll(dev_t dev, int events, struct thread *td)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
return(ENODEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* device driver ioctl routine
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
i4btrcioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
int unit = minor(dev);
|
|
|
|
i4b_trace_setupa_t *tsa;
|
2000-10-09 13:18:17 +00:00
|
|
|
int i;
|
|
|
|
int cno = -1;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
/* find the first passive controller matching our unit no */
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
for(i=0; i < nctrl; i++)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
if((ctrl_desc[i].ctrl_type == CTRL_PASSIVE) &&
|
|
|
|
(ctrl_desc[i].unit == unit))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
cno = i;
|
|
|
|
break;
|
|
|
|
}
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(cmd)
|
|
|
|
{
|
|
|
|
case I4B_TRC_SET:
|
|
|
|
if(cno < 0)
|
|
|
|
return ENOTTY;
|
2000-10-09 13:18:17 +00:00
|
|
|
(*ctrl_desc[cno].N_MGMT_COMMAND)(ctrl_desc[cno].unit, CMR_SETTRACE, (void *)*(unsigned int *)data);
|
1998-12-27 21:47:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case I4B_TRC_SETA:
|
|
|
|
tsa = (i4b_trace_setupa_t *)data;
|
|
|
|
|
|
|
|
if(tsa->rxunit >= 0 && tsa->rxunit < NI4BTRC)
|
|
|
|
rxunit = tsa->rxunit;
|
|
|
|
else
|
|
|
|
error = EINVAL;
|
|
|
|
|
|
|
|
if(tsa->txunit >= 0 && tsa->txunit < NI4BTRC)
|
|
|
|
txunit = tsa->txunit;
|
|
|
|
else
|
|
|
|
error = EINVAL;
|
|
|
|
|
|
|
|
if(error)
|
|
|
|
{
|
|
|
|
outunit = -1;
|
|
|
|
rxunit = -1;
|
|
|
|
txunit = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(cno < 0)
|
|
|
|
return ENOTTY;
|
|
|
|
|
|
|
|
outunit = unit;
|
|
|
|
analyzemode = 1;
|
2000-10-09 13:18:17 +00:00
|
|
|
(*ctrl_desc[cno].N_MGMT_COMMAND)(rxunit, CMR_SETTRACE, (int *)(tsa->rxflags & (TRACE_I | TRACE_D_RX | TRACE_B_RX)));
|
|
|
|
(*ctrl_desc[cno].N_MGMT_COMMAND)(txunit, CMR_SETTRACE, (int *)(tsa->txflags & (TRACE_I | TRACE_D_RX | TRACE_B_RX)));
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I4B_TRC_RESETA:
|
|
|
|
analyzemode = 0;
|
|
|
|
outunit = -1;
|
|
|
|
rxunit = -1;
|
|
|
|
txunit = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(error);
|
|
|
|
}
|