2 * Copyright (c) 1997, 1999 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
25 *---------------------------------------------------------------------------
27 * i4b_ctl.c - i4b system control port driver
28 * ------------------------------------------
30 * $Id: i4b_ctl.c,v 1.30 1999/12/13 21:25:23 hm Exp $
34 * last edit-date: [Mon Dec 13 21:38:15 1999]
36 *---------------------------------------------------------------------------*/
41 #error "only 1 (one) i4bctl device allowed!"
46 #include <sys/param.h>
48 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
49 #include <sys/ioccom.h>
50 #include <i386/isa/isa_device.h>
52 #include <sys/ioctl.h>
55 #include <sys/kernel.h>
56 #include <sys/systm.h>
60 #include <sys/fcntl.h>
61 #include <sys/socket.h>
66 #if defined(__FreeBSD__) && __FreeBSD__ == 3
67 #include "opt_devfs.h"
71 #include <sys/devfsext.h>
74 #endif /* __FreeBSD__ */
77 #include <machine/i4b_debug.h>
78 #include <machine/i4b_ioctl.h>
79 #elif defined(__bsdi__)
80 #include <i4b/i4b_debug.h>
81 #include <i4b/i4b_ioctl.h>
83 #include <machine/bus.h>
84 #include <sys/device.h>
85 #include <i4b/i4b_debug.h>
86 #include <i4b/i4b_ioctl.h>
89 #include <i4b/include/i4b_global.h>
90 #include <i4b/include/i4b_mbuf.h>
91 #include <i4b/layer1/i4b_l1.h>
92 #include <i4b/layer2/i4b_l2.h>
94 static int openflag = 0;
96 #if BSD > 199306 && defined(__FreeBSD__)
97 static d_open_t i4bctlopen;
98 static d_close_t i4bctlclose;
99 static d_ioctl_t i4bctlioctl;
102 static d_poll_t i4bctlpoll;
103 #define POLLFIELD i4bctlpoll
105 #define POLLFIELD noselect
108 #define CDEV_MAJOR 55
110 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
111 static struct cdevsw i4bctl_cdevsw = {
112 /* open */ i4bctlopen,
113 /* close */ i4bctlclose,
116 /* ioctl */ i4bctlioctl,
117 /* poll */ POLLFIELD,
119 /* strategy */ nostrategy,
121 /* maj */ CDEV_MAJOR,
128 static struct cdevsw i4bctl_cdevsw =
129 { i4bctlopen, i4bctlclose, noread, nowrite,
130 i4bctlioctl, nostop, nullreset, nodevtotty,
131 POLLFIELD, nommap, NULL, "i4bctl", NULL, -1 };
134 static void i4bctlattach(void *);
135 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
137 #define PDEVSTATIC static
138 #endif /* __FreeBSD__ */
140 #if defined(__FreeBSD__) && __FreeBSD__ == 3
142 static void *devfs_token;
147 #define PDEVSTATIC /* */
148 void i4bctlattach __P((void));
149 int i4bctlopen __P((dev_t dev, int flag, int fmt, struct proc *p));
150 int i4bctlclose __P((dev_t dev, int flag, int fmt, struct proc *p));
152 int i4bctlioctl __P((dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p));
154 int i4bctlioctl __P((dev_t dev, int cmd, caddr_t data, int flag, struct proc *p));
156 #endif /* !FreeBSD */
158 #if BSD > 199306 && defined(__FreeBSD__)
159 /*---------------------------------------------------------------------------*
160 * initialization at kernel load time
161 *---------------------------------------------------------------------------*/
163 i4bctlinit(void *unused)
165 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
166 cdevsw_add(&i4bctl_cdevsw);
168 dev_t dev = makedev(CDEV_MAJOR, 0);
169 cdevsw_add(&dev, &i4bctl_cdevsw, NULL);
173 SYSINIT(i4bctldev, SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, &i4bctlinit, NULL);
175 #endif /* BSD > 199306 && defined(__FreeBSD__) */
178 int i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux);
179 void dummy_i4bctlattach(struct device*, struct device *, void *);
181 #define CDEV_MAJOR 64
183 static struct cfdriver i4bctlcd =
184 { NULL, "i4bctl", i4bctlmatch, dummy_i4bctlattach, DV_DULL,
185 sizeof(struct cfdriver) };
186 struct devsw i4bctlsw =
188 i4bctlopen, i4bctlclose, noread, nowrite,
189 i4bctlioctl, seltrue, nommap, nostrat,
190 nodump, nopsize, 0, nostop
194 i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux)
196 printf("i4bctlmatch: aux=0x%x\n", aux);
200 dummy_i4bctlattach(struct device *parent, struct device *self, void *aux)
202 printf("dummy_i4bctlattach: aux=0x%x\n", aux);
204 #endif /* __bsdi__ */
205 /*---------------------------------------------------------------------------*
206 * interface attach routine
207 *---------------------------------------------------------------------------*/
210 i4bctlattach(void *dummy)
215 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
216 printf("i4bctl: ISDN system control port attached\n");
219 #if defined(__FreeBSD__)
223 devfs_token = devfs_add_devswf(&i4bctl_cdevsw, 0, DV_CHR,
224 UID_ROOT, GID_WHEEL, 0600,
229 make_dev(&i4bctl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "i4bctl");
234 /*---------------------------------------------------------------------------*
235 * i4bctlopen - device driver open routine
236 *---------------------------------------------------------------------------*/
238 i4bctlopen(dev_t dev, int flag, int fmt, struct proc *p)
251 /*---------------------------------------------------------------------------*
252 * i4bctlclose - device driver close routine
253 *---------------------------------------------------------------------------*/
255 i4bctlclose(dev_t dev, int flag, int fmt, struct proc *p)
261 /*---------------------------------------------------------------------------*
262 * i4bctlioctl - device driver ioctl routine
263 *---------------------------------------------------------------------------*/
265 #if defined (__FreeBSD_version) && __FreeBSD_version >= 300003
266 i4bctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
267 #elif defined(__bsdi__)
268 i4bctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
270 i4bctlioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
284 case I4B_CTL_GET_DEBUG:
285 cdbg = (ctl_debug_t *)data;
286 cdbg->l1 = i4b_l1_debug;
287 cdbg->l2 = i4b_l2_debug;
288 cdbg->l3 = i4b_l3_debug;
289 cdbg->l4 = i4b_l4_debug;
292 case I4B_CTL_SET_DEBUG:
293 cdbg = (ctl_debug_t *)data;
294 i4b_l1_debug = cdbg->l1;
295 i4b_l2_debug = cdbg->l2;
296 i4b_l3_debug = cdbg->l3;
297 i4b_l4_debug = cdbg->l4;
300 case I4B_CTL_GET_HSCXSTAT:
304 hst = (hscxstat_t *)data;
307 hst->unit > ISIC_MAXUNIT ||
316 sc = isic_find_sc(hst->unit);
318 sc = &l1_sc[hst->unit];
320 hst->vfr = sc->sc_chan[hst->chan].stat_VFR;
321 hst->rdo = sc->sc_chan[hst->chan].stat_RDO;
322 hst->crc = sc->sc_chan[hst->chan].stat_CRC;
323 hst->rab = sc->sc_chan[hst->chan].stat_RAB;
324 hst->xdu = sc->sc_chan[hst->chan].stat_XDU;
325 hst->rfo = sc->sc_chan[hst->chan].stat_RFO;
329 case I4B_CTL_CLR_HSCXSTAT:
333 hst = (hscxstat_t *)data;
336 hst->unit > ISIC_MAXUNIT ||
345 sc = isic_find_sc(hst->unit);
347 sc = &l1_sc[hst->unit];
350 sc->sc_chan[hst->chan].stat_VFR = 0;
351 sc->sc_chan[hst->chan].stat_RDO = 0;
352 sc->sc_chan[hst->chan].stat_CRC = 0;
353 sc->sc_chan[hst->chan].stat_RAB = 0;
354 sc->sc_chan[hst->chan].stat_XDU = 0;
355 sc->sc_chan[hst->chan].stat_RFO = 0;
360 case I4B_CTL_GET_LAPDSTAT:
364 l2s = (l2stat_t *)data;
366 if( l2s->unit < 0 || l2s->unit > ISIC_MAXUNIT)
372 sc = &l2_softc[l2s->unit];
374 bcopy(&sc->stat, &l2s->lapdstat, sizeof(lapdstat_t));
378 case I4B_CTL_CLR_LAPDSTAT:
384 if( *up < 0 || *up > ISIC_MAXUNIT)
392 bzero(&sc->stat, sizeof(lapdstat_t));
404 #if defined(__FreeBSD__) && defined(OS_USES_POLL)
406 /*---------------------------------------------------------------------------*
407 * i4bctlpoll - device driver poll routine
408 *---------------------------------------------------------------------------*/
410 i4bctlpoll (dev_t dev, int events, struct proc *p)
417 #endif /* NI4BCTL > 0 */