Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / netisdn / i4b_ctl.c
blob56dcde99288e1db1813b51682ce1f492e01fef5d
1 /*
2 * Copyright (c) 1997, 2000 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
6 * are met:
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
23 * SUCH DAMAGE.
25 *---------------------------------------------------------------------------
27 * i4b_ctl.c - i4b system control port driver
28 * ------------------------------------------
30 * $Id: i4b_ctl.c,v 1.21 2009/03/18 10:22:43 cegger Exp $
32 * $FreeBSD$
34 * last edit-date: [Fri Jan 5 11:33:46 2001]
36 *---------------------------------------------------------------------------*/
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: i4b_ctl.c,v 1.20 2009/03/14 14:46:10 dsl Exp $");
41 #include "isdnctl.h"
43 #if NISDNCTL > 0
45 #include <sys/param.h>
47 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
48 #include <sys/ioccom.h>
49 #include <i386/isa/isa_device.h>
50 #else
51 #include <sys/ioctl.h>
52 #endif
54 #include <sys/kernel.h>
55 #include <sys/systm.h>
56 #include <sys/conf.h>
57 #include <sys/mbuf.h>
58 #include <sys/proc.h>
59 #include <sys/fcntl.h>
60 #include <sys/socket.h>
61 #include <net/if.h>
63 #ifdef __FreeBSD__
65 #if defined(__FreeBSD__) && __FreeBSD__ == 3
66 #include "opt_devfs.h"
67 #endif
69 #ifdef DEVFS
70 #include <sys/devfsext.h>
71 #endif
73 #endif /* __FreeBSD__ */
75 #ifdef __FreeBSD__
76 #include <machine/i4b_debug.h>
77 #include <machine/i4b_ioctl.h>
78 #elif defined(__bsdi__)
79 #include <i4b/i4b_debug.h>
80 #include <i4b/i4b_ioctl.h>
81 #else
82 #include <sys/bus.h>
83 #include <sys/device.h>
84 #include <netisdn/i4b_debug.h>
85 #include <netisdn/i4b_ioctl.h>
86 #endif
88 #include <netisdn/i4b_global.h>
89 #include <netisdn/i4b_mbuf.h>
90 #include <netisdn/i4b_l3l4.h>
92 #include <netisdn/i4b_l2.h>
93 #include <netisdn/i4b_l1l2.h>
95 static int openflag = 0;
97 #if BSD > 199306 && defined(__FreeBSD__)
98 static d_open_t i4bctlopen;
99 static d_close_t i4bctlclose;
100 static d_ioctl_t i4bctlioctl;
102 #ifdef OS_USES_POLL
103 static d_poll_t i4bctlpoll;
104 #define POLLFIELD i4bctlpoll
105 #else
106 #define POLLFIELD noselect
107 #endif
109 #define CDEV_MAJOR 55
111 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
112 static struct cdevsw i4bctl_cdevsw = {
113 /* open */ i4bctlopen,
114 /* close */ i4bctlclose,
115 /* read */ noread,
116 /* write */ nowrite,
117 /* ioctl */ i4bctlioctl,
118 /* poll */ POLLFIELD,
119 /* mmap */ nommap,
120 /* strategy */ nostrategy,
121 /* name */ "i4bctl",
122 /* maj */ CDEV_MAJOR,
123 /* dump */ nodump,
124 /* psize */ nopsize,
125 /* flags */ 0,
126 /* bmaj */ -1
128 #else
129 static struct cdevsw i4bctl_cdevsw =
130 { i4bctlopen, i4bctlclose, noread, nowrite,
131 i4bctlioctl, nostop, nullreset, nodevtotty,
132 POLLFIELD, nommap, NULL, "i4bctl", NULL, -1 };
133 #endif
135 static void i4bctlattach(void *);
136 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
138 #define PDEVSTATIC static
139 #endif /* __FreeBSD__ */
141 #if defined(__FreeBSD__) && __FreeBSD__ == 3
142 #ifdef DEVFS
143 static void *devfs_token;
144 #endif
145 #endif
147 #ifndef __FreeBSD__
148 #define PDEVSTATIC /* */
149 void isdnctlattach(void);
150 int isdnctlopen(dev_t dev, int flag, int fmt, struct lwp *l);
151 int isdnctlclose(dev_t dev, int flag, int fmt, struct lwp *l);
152 int isdnctlioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l);
153 #endif /* !FreeBSD */
155 #ifdef __NetBSD__
156 const struct cdevsw isdnctl_cdevsw = {
157 isdnctlopen, isdnctlclose, noread, nowrite, isdnctlioctl,
158 nostop, notty, nopoll, nommap, nokqfilter, D_OTHER
160 #endif /* __NetBSD__ */
162 #if BSD > 199306 && defined(__FreeBSD__)
163 /*---------------------------------------------------------------------------*
164 * initialization at kernel load time
165 *---------------------------------------------------------------------------*/
166 static void
167 i4bctlinit(void *unused)
169 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
170 cdevsw_add(&i4bctl_cdevsw);
171 #else
172 dev_t dev = makedev(CDEV_MAJOR, 0);
173 cdevsw_add(&dev, &i4bctl_cdevsw, NULL);
174 #endif
177 SYSINIT(i4bctldev, SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, &i4bctlinit, NULL);
179 #endif /* BSD > 199306 && defined(__FreeBSD__) */
181 #ifdef __bsdi__
182 int i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux);
183 void dummy_i4bctlattach(struct device*, struct device *, void *);
185 #define CDEV_MAJOR 64
187 static struct cfdriver i4bctlcd =
188 { NULL, "i4bctl", i4bctlmatch, dummy_i4bctlattach, DV_DULL,
189 sizeof(struct cfdriver) };
190 struct devsw i4bctlsw =
191 { &i4bctlcd,
192 i4bctlopen, i4bctlclose, noread, nowrite,
193 i4bctlioctl, seltrue, nommap, nostrat,
194 nodump, nopsize, 0, nostop
198 i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux)
200 printf("i4bctlmatch: aux=0x%x\n", aux);
201 return 1;
203 void
204 dummy_i4bctlattach(struct device *parent, struct device *self, void *aux)
206 printf("dummy_i4bctlattach: aux=0x%x\n", aux);
208 #endif /* __bsdi__ */
209 /*---------------------------------------------------------------------------*
210 * interface attach routine
211 *---------------------------------------------------------------------------*/
212 PDEVSTATIC void
213 #ifdef __FreeBSD__
214 isdnctlattach(void *dummy)
215 #else
216 isdnctlattach(void)
217 #endif
220 #if defined(__FreeBSD__)
221 #if __FreeBSD__ == 3
223 #ifdef DEVFS
224 devfs_token = devfs_add_devswf(&i4bctl_cdevsw, 0, DV_CHR,
225 UID_ROOT, GID_WHEEL, 0600,
226 "i4bctl");
227 #endif
229 #else
230 make_dev(&i4bctl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "i4bctl");
231 #endif
232 #endif
235 /*---------------------------------------------------------------------------*
236 * i4bctlopen - device driver open routine
237 *---------------------------------------------------------------------------*/
238 PDEVSTATIC int
239 isdnctlopen(dev_t dev, int flag, int fmt,
240 struct lwp *l)
242 if(minor(dev))
243 return (ENXIO);
245 if(openflag)
246 return (EBUSY);
248 openflag = 1;
250 return (0);
253 /*---------------------------------------------------------------------------*
254 * i4bctlclose - device driver close routine
255 *---------------------------------------------------------------------------*/
256 PDEVSTATIC int
257 isdnctlclose(dev_t dev, int flag, int fmt,
258 struct lwp *l)
260 openflag = 0;
261 return (0);
264 /*---------------------------------------------------------------------------*
265 * i4bctlioctl - device driver ioctl routine
266 *---------------------------------------------------------------------------*/
267 PDEVSTATIC int
268 isdnctlioctl(dev_t dev, u_long cmd, void *data, int flag,
269 struct lwp *l)
271 #if DO_I4B_DEBUG
272 ctl_debug_t *cdbg;
273 int error = 0;
274 #endif
276 #if !DO_I4B_DEBUG
277 return(ENODEV);
278 #else
279 if(minor(dev))
280 return(ENODEV);
282 switch(cmd)
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;
290 break;
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;
298 break;
300 case I4B_CTL_GET_CHIPSTAT:
302 struct chipstat *cst;
303 l2_softc_t * scl2;
304 cst = (struct chipstat *)data;
305 scl2 = (l2_softc_t*)isdn_find_softc_by_isdnif(cst->driver_unit);
306 scl2->driver->mph_command_req(scl2->l1_token, CMR_GCST, cst);
307 break;
310 case I4B_CTL_CLR_CHIPSTAT:
312 struct chipstat *cst;
313 l2_softc_t * scl2;
314 cst = (struct chipstat *)data;
315 scl2 = (l2_softc_t*)isdn_find_softc_by_isdnif(cst->driver_unit);
316 scl2->driver->mph_command_req(scl2->l1_token, CMR_CCST, cst);
317 break;
320 case I4B_CTL_GET_LAPDSTAT:
322 l2stat_t *l2s;
323 l2_softc_t *sc;
324 l2s = (l2stat_t *)data;
326 sc = (l2_softc_t*)isdn_find_softc_by_isdnif(l2s->unit);
327 if (sc == NULL) {
328 error = EINVAL;
329 break;
332 memcpy(&l2s->lapdstat, &sc->stat, sizeof(lapdstat_t));
333 break;
336 case I4B_CTL_CLR_LAPDSTAT:
338 int *up;
339 l2_softc_t *sc;
340 up = (int *)data;
342 sc = (l2_softc_t*)isdn_find_softc_by_isdnif(*up);
343 if (sc == NULL) {
344 error = EINVAL;
345 break;
348 memset(&sc->stat, 0, sizeof(lapdstat_t));
349 break;
352 default:
353 error = ENOTTY;
354 break;
356 return(error);
357 #endif /* DO_I4B_DEBUG */
360 #if defined(__FreeBSD__) && defined(OS_USES_POLL)
362 /*---------------------------------------------------------------------------*
363 * i4bctlpoll - device driver poll routine
364 *---------------------------------------------------------------------------*/
365 static int
366 isdnctlpoll (dev_t dev, int events, struct lwp *l)
368 return (ENODEV);
371 #endif
373 #endif /* NISDNCTL > 0 */