2 * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 /*---------------------------------------------------------------------------
28 * i4b_ctl.c - i4b system control port driver
29 * ------------------------------------------
30 * last edit-date: [Sun Mar 17 09:49:24 2002]
32 *---------------------------------------------------------------------------*/
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
38 #include <sys/ioccom.h>
39 #include <sys/kernel.h>
40 #include <sys/systm.h>
42 #include <sys/socket.h>
45 #include <machine/i4b_debug.h>
46 #include <machine/i4b_ioctl.h>
48 #include <i4b/include/i4b_global.h>
49 #include <i4b/include/i4b_l3l4.h>
51 #include <i4b/layer2/i4b_l2.h>
53 static int openflag = 0;
55 static d_open_t i4bctlopen;
56 static d_close_t i4bctlclose;
57 static d_ioctl_t i4bctlioctl;
58 static d_poll_t i4bctlpoll;
61 static struct cdevsw i4bctl_cdevsw = {
62 .d_version = D_VERSION,
63 .d_flags = D_NEEDGIANT,
65 .d_close = i4bctlclose,
66 .d_ioctl = i4bctlioctl,
71 static void i4bctlattach(void *);
72 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
74 /*---------------------------------------------------------------------------*
75 * interface attach routine
76 *---------------------------------------------------------------------------*/
78 i4bctlattach(void *dummy)
80 printf("i4bctl: ISDN system control port attached\n");
81 make_dev(&i4bctl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "i4bctl");
84 /*---------------------------------------------------------------------------*
85 * i4bctlopen - device driver open routine
86 *---------------------------------------------------------------------------*/
88 i4bctlopen(struct cdev *dev, int flag, int fmt, struct thread *td)
101 /*---------------------------------------------------------------------------*
102 * i4bctlclose - device driver close routine
103 *---------------------------------------------------------------------------*/
105 i4bctlclose(struct cdev *dev, int flag, int fmt, struct thread *td)
111 /*---------------------------------------------------------------------------*
112 * i4bctlioctl - device driver ioctl routine
113 *---------------------------------------------------------------------------*/
115 i4bctlioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
130 case I4B_CTL_GET_DEBUG:
131 cdbg = (ctl_debug_t *)data;
132 cdbg->l1 = i4b_l1_debug;
133 cdbg->l2 = i4b_l2_debug;
134 cdbg->l3 = i4b_l3_debug;
135 cdbg->l4 = i4b_l4_debug;
138 case I4B_CTL_SET_DEBUG:
139 cdbg = (ctl_debug_t *)data;
140 i4b_l1_debug = cdbg->l1;
141 i4b_l2_debug = cdbg->l2;
142 i4b_l3_debug = cdbg->l3;
143 i4b_l4_debug = cdbg->l4;
146 case I4B_CTL_GET_CHIPSTAT:
148 struct chipstat *cst;
149 cst = (struct chipstat *)data;
150 (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_GCST, cst);
154 case I4B_CTL_CLR_CHIPSTAT:
156 struct chipstat *cst;
157 cst = (struct chipstat *)data;
158 (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_CCST, cst);
162 case I4B_CTL_GET_LAPDSTAT:
166 l2s = (l2stat_t *)data;
168 if( l2s->unit < 0 || l2s->unit > MAXL1UNITS)
174 sc = &l2_softc[l2s->unit];
176 bcopy(&sc->stat, &l2s->lapdstat, sizeof(lapdstat_t));
180 case I4B_CTL_CLR_LAPDSTAT:
186 if( *up < 0 || *up > MAXL1UNITS)
194 bzero(&sc->stat, sizeof(lapdstat_t));
203 #endif /* DO_I4B_DEBUG */
206 /*---------------------------------------------------------------------------*
207 * i4bctlpoll - device driver poll routine
208 *---------------------------------------------------------------------------*/
210 i4bctlpoll (struct cdev *dev, int events, struct thread *td)