FreeBSD/Linux Kernel Cross Reference
sys/netisdn/i4b_ctl.c
1 /*
2 * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
3 *
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.
12 *
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.
24 *
25 *---------------------------------------------------------------------------
26 *
27 * i4b_ctl.c - i4b system control port driver
28 * ------------------------------------------
29 *
30 * $Id: i4b_ctl.c,v 1.12 2003/10/03 16:38:44 pooka Exp $
31 *
32 * $FreeBSD$
33 *
34 * last edit-date: [Fri Jan 5 11:33:46 2001]
35 *
36 *---------------------------------------------------------------------------*/
37
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: i4b_ctl.c,v 1.12 2003/10/03 16:38:44 pooka Exp $");
40
41 #include "isdnctl.h"
42
43 #if NISDNCTL > 0
44
45 #include <sys/param.h>
46
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
53
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>
62
63 #ifdef __FreeBSD__
64
65 #if defined(__FreeBSD__) && __FreeBSD__ == 3
66 #include "opt_devfs.h"
67 #endif
68
69 #ifdef DEVFS
70 #include <sys/devfsext.h>
71 #endif
72
73 #endif /* __FreeBSD__ */
74
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 <machine/bus.h>
83 #include <sys/device.h>
84 #include <netisdn/i4b_debug.h>
85 #include <netisdn/i4b_ioctl.h>
86 #endif
87
88 #include <netisdn/i4b_global.h>
89 #include <netisdn/i4b_mbuf.h>
90 #include <netisdn/i4b_l3l4.h>
91
92 #include <netisdn/i4b_l2.h>
93 #include <netisdn/i4b_l1l2.h>
94 #include <netisdn/i4b_l2.h>
95
96 static int openflag = 0;
97
98 #if BSD > 199306 && defined(__FreeBSD__)
99 static d_open_t i4bctlopen;
100 static d_close_t i4bctlclose;
101 static d_ioctl_t i4bctlioctl;
102
103 #ifdef OS_USES_POLL
104 static d_poll_t i4bctlpoll;
105 #define POLLFIELD i4bctlpoll
106 #else
107 #define POLLFIELD noselect
108 #endif
109
110 #define CDEV_MAJOR 55
111
112 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
113 static struct cdevsw i4bctl_cdevsw = {
114 /* open */ i4bctlopen,
115 /* close */ i4bctlclose,
116 /* read */ noread,
117 /* write */ nowrite,
118 /* ioctl */ i4bctlioctl,
119 /* poll */ POLLFIELD,
120 /* mmap */ nommap,
121 /* strategy */ nostrategy,
122 /* name */ "i4bctl",
123 /* maj */ CDEV_MAJOR,
124 /* dump */ nodump,
125 /* psize */ nopsize,
126 /* flags */ 0,
127 /* bmaj */ -1
128 };
129 #else
130 static struct cdevsw i4bctl_cdevsw =
131 { i4bctlopen, i4bctlclose, noread, nowrite,
132 i4bctlioctl, nostop, nullreset, nodevtotty,
133 POLLFIELD, nommap, NULL, "i4bctl", NULL, -1 };
134 #endif
135
136 static void i4bctlattach(void *);
137 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
138
139 #define PDEVSTATIC static
140 #endif /* __FreeBSD__ */
141
142 #if defined(__FreeBSD__) && __FreeBSD__ == 3
143 #ifdef DEVFS
144 static void *devfs_token;
145 #endif
146 #endif
147
148 #ifndef __FreeBSD__
149 #define PDEVSTATIC /* */
150 void isdnctlattach __P((void));
151 int isdnctlopen __P((dev_t dev, int flag, int fmt, struct proc *p));
152 int isdnctlclose __P((dev_t dev, int flag, int fmt, struct proc *p));
153 int isdnctlioctl __P((dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p));
154 #endif /* !FreeBSD */
155
156 #ifdef __NetBSD__
157 const struct cdevsw isdnctl_cdevsw = {
158 isdnctlopen, isdnctlclose, noread, nowrite, isdnctlioctl,
159 nostop, notty, nopoll, nommap, nokqfilter,
160 };
161 #endif /* __NetBSD__ */
162
163 #if BSD > 199306 && defined(__FreeBSD__)
164 /*---------------------------------------------------------------------------*
165 * initialization at kernel load time
166 *---------------------------------------------------------------------------*/
167 static void
168 i4bctlinit(void *unused)
169 {
170 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
171 cdevsw_add(&i4bctl_cdevsw);
172 #else
173 dev_t dev = makedev(CDEV_MAJOR, 0);
174 cdevsw_add(&dev, &i4bctl_cdevsw, NULL);
175 #endif
176 }
177
178 SYSINIT(i4bctldev, SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, &i4bctlinit, NULL);
179
180 #endif /* BSD > 199306 && defined(__FreeBSD__) */
181
182 #ifdef __bsdi__
183 int i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux);
184 void dummy_i4bctlattach(struct device*, struct device *, void *);
185
186 #define CDEV_MAJOR 64
187
188 static struct cfdriver i4bctlcd =
189 { NULL, "i4bctl", i4bctlmatch, dummy_i4bctlattach, DV_DULL,
190 sizeof(struct cfdriver) };
191 struct devsw i4bctlsw =
192 { &i4bctlcd,
193 i4bctlopen, i4bctlclose, noread, nowrite,
194 i4bctlioctl, seltrue, nommap, nostrat,
195 nodump, nopsize, 0, nostop
196 };
197
198 int
199 i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux)
200 {
201 printf("i4bctlmatch: aux=0x%x\n", aux);
202 return 1;
203 }
204 void
205 dummy_i4bctlattach(struct device *parent, struct device *self, void *aux)
206 {
207 printf("dummy_i4bctlattach: aux=0x%x\n", aux);
208 }
209 #endif /* __bsdi__ */
210 /*---------------------------------------------------------------------------*
211 * interface attach routine
212 *---------------------------------------------------------------------------*/
213 PDEVSTATIC void
214 #ifdef __FreeBSD__
215 isdnctlattach(void *dummy)
216 #else
217 isdnctlattach()
218 #endif
219 {
220
221 #if defined(__FreeBSD__)
222 #if __FreeBSD__ == 3
223
224 #ifdef DEVFS
225 devfs_token = devfs_add_devswf(&i4bctl_cdevsw, 0, DV_CHR,
226 UID_ROOT, GID_WHEEL, 0600,
227 "i4bctl");
228 #endif
229
230 #else
231 make_dev(&i4bctl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "i4bctl");
232 #endif
233 #endif
234 }
235
236 /*---------------------------------------------------------------------------*
237 * i4bctlopen - device driver open routine
238 *---------------------------------------------------------------------------*/
239 PDEVSTATIC int
240 isdnctlopen(dev_t dev, int flag, int fmt, struct proc *p)
241 {
242 if(minor(dev))
243 return (ENXIO);
244
245 if(openflag)
246 return (EBUSY);
247
248 openflag = 1;
249
250 return (0);
251 }
252
253 /*---------------------------------------------------------------------------*
254 * i4bctlclose - device driver close routine
255 *---------------------------------------------------------------------------*/
256 PDEVSTATIC int
257 isdnctlclose(dev_t dev, int flag, int fmt, struct proc *p)
258 {
259 openflag = 0;
260 return (0);
261 }
262
263 /*---------------------------------------------------------------------------*
264 * i4bctlioctl - device driver ioctl routine
265 *---------------------------------------------------------------------------*/
266 PDEVSTATIC int
267 isdnctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
268 {
269 #if DO_I4B_DEBUG
270 ctl_debug_t *cdbg;
271 int error = 0;
272 #endif
273
274 #if !DO_I4B_DEBUG
275 return(ENODEV);
276 #else
277 if(minor(dev))
278 return(ENODEV);
279
280 switch(cmd)
281 {
282 case I4B_CTL_GET_DEBUG:
283 cdbg = (ctl_debug_t *)data;
284 cdbg->l1 = i4b_l1_debug;
285 cdbg->l2 = i4b_l2_debug;
286 cdbg->l3 = i4b_l3_debug;
287 cdbg->l4 = i4b_l4_debug;
288 break;
289
290 case I4B_CTL_SET_DEBUG:
291 cdbg = (ctl_debug_t *)data;
292 i4b_l1_debug = cdbg->l1;
293 i4b_l2_debug = cdbg->l2;
294 i4b_l3_debug = cdbg->l3;
295 i4b_l4_debug = cdbg->l4;
296 break;
297
298 case I4B_CTL_GET_CHIPSTAT:
299 {
300 struct chipstat *cst;
301 l2_softc_t * scl2;
302 cst = (struct chipstat *)data;
303 scl2 = (l2_softc_t*)isdn_find_softc_by_isdnif(cst->driver_unit);
304 scl2->driver->mph_command_req(scl2->l1_token, CMR_GCST, cst);
305 break;
306 }
307
308 case I4B_CTL_CLR_CHIPSTAT:
309 {
310 struct chipstat *cst;
311 l2_softc_t * scl2;
312 cst = (struct chipstat *)data;
313 scl2 = (l2_softc_t*)isdn_find_softc_by_isdnif(cst->driver_unit);
314 scl2->driver->mph_command_req(scl2->l1_token, CMR_CCST, cst);
315 break;
316 }
317
318 case I4B_CTL_GET_LAPDSTAT:
319 {
320 l2stat_t *l2s;
321 l2_softc_t *sc;
322 l2s = (l2stat_t *)data;
323
324 sc = (l2_softc_t*)isdn_find_softc_by_isdnif(l2s->unit);
325 if (sc == NULL) {
326 error = EINVAL;
327 break;
328 }
329
330 memcpy(&l2s->lapdstat, &sc->stat, sizeof(lapdstat_t));
331 break;
332 }
333
334 case I4B_CTL_CLR_LAPDSTAT:
335 {
336 int *up;
337 l2_softc_t *sc;
338 up = (int *)data;
339
340 sc = (l2_softc_t*)isdn_find_softc_by_isdnif(*up);
341 if (sc == NULL) {
342 error = EINVAL;
343 break;
344 }
345
346 memset(&sc->stat, 0, sizeof(lapdstat_t));
347 break;
348 }
349
350 default:
351 error = ENOTTY;
352 break;
353 }
354 return(error);
355 #endif /* DO_I4B_DEBUG */
356 }
357
358 #if defined(__FreeBSD__) && defined(OS_USES_POLL)
359
360 /*---------------------------------------------------------------------------*
361 * i4bctlpoll - device driver poll routine
362 *---------------------------------------------------------------------------*/
363 static int
364 isdnctlpoll (dev_t dev, int events, struct proc *p)
365 {
366 return (ENODEV);
367 }
368
369 #endif
370
371 #endif /* NISDNCTL > 0 */
Cache object: d2b4f9f79b8d35aa7e80fc0780b21135
|