2005-01-06 22:18:23 +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.
|
2005-01-06 22:18:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
1998-12-27 21:47:14 +00:00
|
|
|
*
|
|
|
|
* i4b_ctl.c - i4b system control port driver
|
|
|
|
* ------------------------------------------
|
2002-03-17 09:33:15 +00:00
|
|
|
* last edit-date: [Sun Mar 17 09:49:24 2002]
|
1998-12-27 21:47:14 +00:00
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
|
2003-06-10 23:23:33 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <machine/i4b_debug.h>
|
|
|
|
#include <machine/i4b_ioctl.h>
|
|
|
|
|
|
|
|
#include <i4b/include/i4b_global.h>
|
2000-10-09 13:18:17 +00:00
|
|
|
#include <i4b/include/i4b_l3l4.h>
|
|
|
|
|
1999-08-06 14:05:10 +00:00
|
|
|
#include <i4b/layer2/i4b_l2.h>
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
static int openflag = 0;
|
|
|
|
|
|
|
|
static d_open_t i4bctlopen;
|
|
|
|
static d_close_t i4bctlclose;
|
|
|
|
static d_ioctl_t i4bctlioctl;
|
2002-03-17 09:33:15 +00:00
|
|
|
static d_poll_t i4bctlpoll;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
1999-08-06 14:05:10 +00:00
|
|
|
|
1999-06-01 08:46:56 +00:00
|
|
|
static struct cdevsw i4bctl_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_flags = D_NEEDGIANT,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = i4bctlopen,
|
|
|
|
.d_close = i4bctlclose,
|
|
|
|
.d_ioctl = i4bctlioctl,
|
|
|
|
.d_poll = i4bctlpoll,
|
|
|
|
.d_name = "i4bctl",
|
1999-06-01 08:46:56 +00:00
|
|
|
};
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
static void i4bctlattach(void *);
|
|
|
|
PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* interface attach routine
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static void
|
1998-12-27 21:47:14 +00:00
|
|
|
i4bctlattach(void *dummy)
|
|
|
|
{
|
|
|
|
printf("i4bctl: ISDN system control port attached\n");
|
1999-08-27 07:26:26 +00:00
|
|
|
make_dev(&i4bctl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "i4bctl");
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* i4bctlopen - device driver open routine
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
i4bctlopen(struct cdev *dev, int flag, int fmt, struct thread *td)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
if(minor(dev))
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if(openflag)
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
openflag = 1;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* i4bctlclose - device driver close routine
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
i4bctlclose(struct cdev *dev, int flag, int fmt, struct thread *td)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
openflag = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* i4bctlioctl - device driver ioctl routine
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
i4bctlioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
#if DO_I4B_DEBUG
|
1998-12-27 21:47:14 +00:00
|
|
|
ctl_debug_t *cdbg;
|
|
|
|
int error = 0;
|
2000-10-09 13:18:17 +00:00
|
|
|
#endif
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
#if !DO_I4B_DEBUG
|
1998-12-27 21:47:14 +00:00
|
|
|
return(ENODEV);
|
|
|
|
#else
|
|
|
|
if(minor(dev))
|
|
|
|
return(ENODEV);
|
|
|
|
|
|
|
|
switch(cmd)
|
|
|
|
{
|
|
|
|
case I4B_CTL_GET_DEBUG:
|
|
|
|
cdbg = (ctl_debug_t *)data;
|
|
|
|
cdbg->l1 = i4b_l1_debug;
|
|
|
|
cdbg->l2 = i4b_l2_debug;
|
|
|
|
cdbg->l3 = i4b_l3_debug;
|
|
|
|
cdbg->l4 = i4b_l4_debug;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I4B_CTL_SET_DEBUG:
|
|
|
|
cdbg = (ctl_debug_t *)data;
|
|
|
|
i4b_l1_debug = cdbg->l1;
|
|
|
|
i4b_l2_debug = cdbg->l2;
|
|
|
|
i4b_l3_debug = cdbg->l3;
|
|
|
|
i4b_l4_debug = cdbg->l4;
|
|
|
|
break;
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
case I4B_CTL_GET_CHIPSTAT:
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
struct chipstat *cst;
|
|
|
|
cst = (struct chipstat *)data;
|
|
|
|
(*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_GCST, cst);
|
1998-12-27 21:47:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
case I4B_CTL_CLR_CHIPSTAT:
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
struct chipstat *cst;
|
|
|
|
cst = (struct chipstat *)data;
|
|
|
|
(*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_CCST, cst);
|
1998-12-27 21:47:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-08-06 14:05:10 +00:00
|
|
|
case I4B_CTL_GET_LAPDSTAT:
|
|
|
|
{
|
|
|
|
l2stat_t *l2s;
|
|
|
|
l2_softc_t *sc;
|
|
|
|
l2s = (l2stat_t *)data;
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
if( l2s->unit < 0 || l2s->unit > MAXL1UNITS)
|
1999-08-06 14:05:10 +00:00
|
|
|
{
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc = &l2_softc[l2s->unit];
|
|
|
|
|
|
|
|
bcopy(&sc->stat, &l2s->lapdstat, sizeof(lapdstat_t));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case I4B_CTL_CLR_LAPDSTAT:
|
|
|
|
{
|
|
|
|
int *up;
|
|
|
|
l2_softc_t *sc;
|
|
|
|
up = (int *)data;
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
if( *up < 0 || *up > MAXL1UNITS)
|
1999-08-06 14:05:10 +00:00
|
|
|
{
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc = &l2_softc[*up];
|
|
|
|
|
|
|
|
bzero(&sc->stat, sizeof(lapdstat_t));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(error);
|
2002-05-24 06:22:48 +00:00
|
|
|
#endif /* DO_I4B_DEBUG */
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* i4bctlpoll - device driver poll routine
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
i4bctlpoll (struct cdev *dev, int events, struct thread *td)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
return (ENODEV);
|
|
|
|
}
|