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 * ------------------------------------------
32 * last edit-date: [Tue Jun 8 09:27:15 1999]
34 *---------------------------------------------------------------------------*/
39 #error "only 1 (one) i4bctl device allowed!"
44 #include <sys/param.h>
46 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
47 #include <sys/ioccom.h>
48 #include <i386/isa/isa_device.h>
50 #include <sys/ioctl.h>
53 #include <sys/kernel.h>
54 #include <sys/systm.h>
58 #include <sys/fcntl.h>
59 #include <sys/socket.h>
63 #include <machine/i4b_debug.h>
64 #include <machine/i4b_ioctl.h>
65 #elif defined(__bsdi__)
66 #include <i4b/i4b_debug.h>
67 #include <i4b/i4b_ioctl.h>
69 #include <machine/bus.h>
70 #include <sys/device.h>
71 #include <i4b/i4b_debug.h>
72 #include <i4b/i4b_ioctl.h>
75 #include <i4b/include/i4b_global.h>
76 #include <i4b/include/i4b_mbuf.h>
77 #include <i4b/layer1/i4b_l1.h>
78 #include <i4b/layer2/i4b_l2.h>
80 static int openflag = 0;
82 #if BSD > 199306 && defined(__FreeBSD__)
83 static d_open_t i4bctlopen;
84 static d_close_t i4bctlclose;
85 static d_ioctl_t i4bctlioctl;
88 static d_poll_t i4bctlpoll;
89 #define POLLFIELD i4bctlpoll
91 #define POLLFIELD noselect
96 #if defined (__FreeBSD_version) && __FreeBSD_version >= 400006
97 static struct cdevsw i4bctl_cdevsw = {
98 /* open */ i4bctlopen,
99 /* close */ i4bctlclose,
102 /* ioctl */ i4bctlioctl,
103 /* poll */ POLLFIELD,
105 /* strategy */ nostrategy,
107 /* maj */ CDEV_MAJOR,
114 static struct cdevsw i4bctl_cdevsw =
115 { i4bctlopen, i4bctlclose, noread, nowrite,
116 i4bctlioctl, nostop, nullreset, nodevtotty,
117 POLLFIELD, nommap, NULL, "i4bctl", NULL, -1 };
120 static void i4bctlattach(void *);
121 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
123 #define PDEVSTATIC static
124 #endif /* __FreeBSD__ */
127 #define PDEVSTATIC /* */
128 void i4bctlattach __P((void));
129 int i4bctlopen __P((dev_t dev, int flag, int fmt, struct proc *p));
130 int i4bctlclose __P((dev_t dev, int flag, int fmt, struct proc *p));
132 int i4bctlioctl __P((dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p));
134 int i4bctlioctl __P((dev_t dev, int cmd, caddr_t data, int flag, struct proc *p));
136 #endif /* !FreeBSD */
138 #if BSD > 199306 && defined(__FreeBSD__)
139 /*---------------------------------------------------------------------------*
140 * initialization at kernel load time
141 *---------------------------------------------------------------------------*/
143 i4bctlinit(void *unused)
145 #if defined (__FreeBSD_version) && __FreeBSD_version >= 400006
146 cdevsw_add(&i4bctl_cdevsw);
148 dev_t dev = makedev(CDEV_MAJOR, 0);
149 cdevsw_add(&dev, &i4bctl_cdevsw, NULL);
153 SYSINIT(i4bctldev, SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, &i4bctlinit, NULL);
155 #endif /* BSD > 199306 && defined(__FreeBSD__) */
158 int i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux);
159 void dummy_i4bctlattach(struct device*, struct device *, void *);
161 #define CDEV_MAJOR 64
163 static struct cfdriver i4bctlcd =
164 { NULL, "i4bctl", i4bctlmatch, dummy_i4bctlattach, DV_DULL,
165 sizeof(struct cfdriver) };
166 struct devsw i4bctlsw =
168 i4bctlopen, i4bctlclose, noread, nowrite,
169 i4bctlioctl, seltrue, nommap, nostrat,
170 nodump, nopsize, 0, nostop
174 i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux)
176 printf("i4bctlmatch: aux=0x%x\n", aux);
180 dummy_i4bctlattach(struct device *parent, struct device *self, void *aux)
182 printf("dummy_i4bctlattach: aux=0x%x\n", aux);
184 #endif /* __bsdi__ */
185 /*---------------------------------------------------------------------------*
186 * interface attach routine
187 *---------------------------------------------------------------------------*/
190 i4bctlattach(void *dummy)
195 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
196 printf("i4bctl: ISDN system control port attached\n");
198 make_dev(&i4bctl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "i4bctl");
201 /*---------------------------------------------------------------------------*
202 * i4bctlopen - device driver open routine
203 *---------------------------------------------------------------------------*/
205 i4bctlopen(dev_t dev, int flag, int fmt, struct proc *p)
218 /*---------------------------------------------------------------------------*
219 * i4bctlclose - device driver close routine
220 *---------------------------------------------------------------------------*/
222 i4bctlclose(dev_t dev, int flag, int fmt, struct proc *p)
228 /*---------------------------------------------------------------------------*
229 * i4bctlioctl - device driver ioctl routine
230 *---------------------------------------------------------------------------*/
232 #if defined (__FreeBSD_version) && __FreeBSD_version >= 300003
233 i4bctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
234 #elif defined(__bsdi__)
235 i4bctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
237 i4bctlioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
251 case I4B_CTL_GET_DEBUG:
252 cdbg = (ctl_debug_t *)data;
253 cdbg->l1 = i4b_l1_debug;
254 cdbg->l2 = i4b_l2_debug;
255 cdbg->l3 = i4b_l3_debug;
256 cdbg->l4 = i4b_l4_debug;
259 case I4B_CTL_SET_DEBUG:
260 cdbg = (ctl_debug_t *)data;
261 i4b_l1_debug = cdbg->l1;
262 i4b_l2_debug = cdbg->l2;
263 i4b_l3_debug = cdbg->l3;
264 i4b_l4_debug = cdbg->l4;
267 case I4B_CTL_GET_HSCXSTAT:
270 struct isic_softc *sc;
271 hst = (hscxstat_t *)data;
274 hst->unit > ISIC_MAXUNIT ||
283 sc = isic_find_sc(hst->unit);
285 sc = &isic_sc[hst->unit];
287 hst->vfr = sc->sc_chan[hst->chan].stat_VFR;
288 hst->rdo = sc->sc_chan[hst->chan].stat_RDO;
289 hst->crc = sc->sc_chan[hst->chan].stat_CRC;
290 hst->rab = sc->sc_chan[hst->chan].stat_RAB;
291 hst->xdu = sc->sc_chan[hst->chan].stat_XDU;
292 hst->rfo = sc->sc_chan[hst->chan].stat_RFO;
296 case I4B_CTL_CLR_HSCXSTAT:
299 struct isic_softc *sc;
300 hst = (hscxstat_t *)data;
303 hst->unit > ISIC_MAXUNIT ||
312 sc = isic_find_sc(hst->unit);
314 sc = &isic_sc[hst->unit];
317 sc->sc_chan[hst->chan].stat_VFR = 0;
318 sc->sc_chan[hst->chan].stat_RDO = 0;
319 sc->sc_chan[hst->chan].stat_CRC = 0;
320 sc->sc_chan[hst->chan].stat_RAB = 0;
321 sc->sc_chan[hst->chan].stat_XDU = 0;
322 sc->sc_chan[hst->chan].stat_RFO = 0;
327 case I4B_CTL_GET_LAPDSTAT:
331 l2s = (l2stat_t *)data;
333 if( l2s->unit < 0 || l2s->unit > ISIC_MAXUNIT)
339 sc = &l2_softc[l2s->unit];
341 bcopy(&sc->stat, &l2s->lapdstat, sizeof(lapdstat_t));
345 case I4B_CTL_CLR_LAPDSTAT:
351 if( *up < 0 || *up > ISIC_MAXUNIT)
359 bzero(&sc->stat, sizeof(lapdstat_t));
371 #if defined(__FreeBSD__) && defined(OS_USES_POLL)
373 /*---------------------------------------------------------------------------*
374 * i4bctlpoll - device driver poll routine
375 *---------------------------------------------------------------------------*/
377 i4bctlpoll (dev_t dev, int events, struct proc *p)
384 #endif /* NI4BCTL > 0 */