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
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.21 2009/03/18 10:22:43 cegger Exp $
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 $");
45 #include <sys/param.h>
47 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
48 #include <sys/ioccom.h>
49 #include <i386/isa/isa_device.h>
51 #include <sys/ioctl.h>
54 #include <sys/kernel.h>
55 #include <sys/systm.h>
59 #include <sys/fcntl.h>
60 #include <sys/socket.h>
65 #if defined(__FreeBSD__) && __FreeBSD__ == 3
66 #include "opt_devfs.h"
70 #include <sys/devfsext.h>
73 #endif /* __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>
83 #include <sys/device.h>
84 #include <netisdn/i4b_debug.h>
85 #include <netisdn/i4b_ioctl.h>
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
;
103 static d_poll_t i4bctlpoll
;
104 #define POLLFIELD i4bctlpoll
106 #define POLLFIELD noselect
109 #define CDEV_MAJOR 55
111 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
112 static struct cdevsw i4bctl_cdevsw
= {
113 /* open */ i4bctlopen
,
114 /* close */ i4bctlclose
,
117 /* ioctl */ i4bctlioctl
,
118 /* poll */ POLLFIELD
,
120 /* strategy */ nostrategy
,
122 /* maj */ CDEV_MAJOR
,
129 static struct cdevsw i4bctl_cdevsw
=
130 { i4bctlopen
, i4bctlclose
, noread
, nowrite
,
131 i4bctlioctl
, nostop
, nullreset
, nodevtotty
,
132 POLLFIELD
, nommap
, NULL
, "i4bctl", NULL
, -1 };
135 static void i4bctlattach(void *);
136 PSEUDO_SET(i4bctlattach
, i4b_i4bctldrv
);
138 #define PDEVSTATIC static
139 #endif /* __FreeBSD__ */
141 #if defined(__FreeBSD__) && __FreeBSD__ == 3
143 static void *devfs_token
;
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 */
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 *---------------------------------------------------------------------------*/
167 i4bctlinit(void *unused
)
169 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
170 cdevsw_add(&i4bctl_cdevsw
);
172 dev_t dev
= makedev(CDEV_MAJOR
, 0);
173 cdevsw_add(&dev
, &i4bctl_cdevsw
, NULL
);
177 SYSINIT(i4bctldev
, SI_SUB_DRIVERS
,SI_ORDER_MIDDLE
+CDEV_MAJOR
, &i4bctlinit
, NULL
);
179 #endif /* BSD > 199306 && defined(__FreeBSD__) */
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
=
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
);
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 *---------------------------------------------------------------------------*/
214 isdnctlattach(void *dummy
)
220 #if defined(__FreeBSD__)
224 devfs_token
= devfs_add_devswf(&i4bctl_cdevsw
, 0, DV_CHR
,
225 UID_ROOT
, GID_WHEEL
, 0600,
230 make_dev(&i4bctl_cdevsw
, 0, UID_ROOT
, GID_WHEEL
, 0600, "i4bctl");
235 /*---------------------------------------------------------------------------*
236 * i4bctlopen - device driver open routine
237 *---------------------------------------------------------------------------*/
239 isdnctlopen(dev_t dev
, int flag
, int fmt
,
253 /*---------------------------------------------------------------------------*
254 * i4bctlclose - device driver close routine
255 *---------------------------------------------------------------------------*/
257 isdnctlclose(dev_t dev
, int flag
, int fmt
,
264 /*---------------------------------------------------------------------------*
265 * i4bctlioctl - device driver ioctl routine
266 *---------------------------------------------------------------------------*/
268 isdnctlioctl(dev_t dev
, u_long cmd
, void *data
, int flag
,
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_CHIPSTAT
:
302 struct chipstat
*cst
;
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
);
310 case I4B_CTL_CLR_CHIPSTAT
:
312 struct chipstat
*cst
;
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
);
320 case I4B_CTL_GET_LAPDSTAT
:
324 l2s
= (l2stat_t
*)data
;
326 sc
= (l2_softc_t
*)isdn_find_softc_by_isdnif(l2s
->unit
);
332 memcpy(&l2s
->lapdstat
, &sc
->stat
, sizeof(lapdstat_t
));
336 case I4B_CTL_CLR_LAPDSTAT
:
342 sc
= (l2_softc_t
*)isdn_find_softc_by_isdnif(*up
);
348 memset(&sc
->stat
, 0, sizeof(lapdstat_t
));
357 #endif /* DO_I4B_DEBUG */
360 #if defined(__FreeBSD__) && defined(OS_USES_POLL)
362 /*---------------------------------------------------------------------------*
363 * i4bctlpoll - device driver poll routine
364 *---------------------------------------------------------------------------*/
366 isdnctlpoll (dev_t dev
, int events
, struct lwp
*l
)
373 #endif /* NISDNCTL > 0 */