4205e4632c4f820605bc1ff046522274c1d7beca
[dragonfly.git] / sys / net / i4b / driver / 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.37 2000/05/31 08:04:43 hm Exp $
31  *
32  * $FreeBSD: src/sys/i4b/driver/i4b_ctl.c,v 1.10.2.3 2001/08/12 16:22:48 hm Exp $
33  * $DragonFly: src/sys/net/i4b/driver/i4b_ctl.c,v 1.14 2006/12/22 23:44:55 swildner Exp $
34  *
35  *      last edit-date: [Sat Aug 11 18:06:38 2001]
36  *
37  *---------------------------------------------------------------------------*/
38
39 #include "use_i4bctl.h"
40
41 #if NI4BCTL > 1
42 #error "only 1 (one) i4bctl device allowed!"
43 #endif
44
45 #if NI4BCTL > 0
46
47 #include <sys/param.h>
48
49 #include <sys/kernel.h>
50 #include <sys/systm.h>
51 #include <sys/conf.h>
52 #include <sys/device.h>
53 #include <sys/socket.h>
54 #include <net/if.h>
55
56 #include <net/i4b/include/machine/i4b_debug.h>
57 #include <net/i4b/include/machine/i4b_ioctl.h>
58
59 #include "../include/i4b_global.h"
60 #include "../include/i4b_l3l4.h"
61 #include "../layer2/i4b_l2.h"
62
63 static int openflag = 0;
64
65 static  d_open_t        i4bctlopen;
66 static  d_close_t       i4bctlclose;
67 static  d_ioctl_t       i4bctlioctl;
68
69 static d_poll_t         i4bctlpoll;
70 #define POLLFIELD       i4bctlpoll
71
72 #define CDEV_MAJOR 55
73
74 static struct dev_ops i4bctl_ops = {
75         { "i4bctl", CDEV_MAJOR, 0 },
76         .d_open =      i4bctlopen,
77         .d_close =     i4bctlclose,
78         .d_ioctl =     i4bctlioctl,
79         .d_poll =      POLLFIELD,
80 };
81
82 static void i4bctlattach(void *);
83 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
84
85 #define PDEVSTATIC      static
86
87 /*---------------------------------------------------------------------------*
88  *      initialization at kernel load time
89  *---------------------------------------------------------------------------*/
90 static void
91 i4bctlinit(void *unused)
92 {
93         dev_ops_add(&i4bctl_ops, 0, 0);
94 }
95
96 SYSINIT(i4bctldev, SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, &i4bctlinit, NULL);
97
98 /*---------------------------------------------------------------------------*
99  *      interface attach routine
100  *---------------------------------------------------------------------------*/
101 PDEVSTATIC void
102 i4bctlattach(void *dummy)
103 {
104 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
105         kprintf("i4bctl: ISDN system control port attached\n");
106 #endif
107 }
108
109 /*---------------------------------------------------------------------------*
110  *      i4bctlopen - device driver open routine
111  *---------------------------------------------------------------------------*/
112 PDEVSTATIC int
113 i4bctlopen(struct dev_open_args *ap)
114 {
115         cdev_t dev = ap->a_head.a_dev;
116         if(minor(dev))
117                 return (ENXIO);
118         if(openflag)
119                 return (EBUSY);
120         openflag = 1;
121         return (0);
122 }
123
124 /*---------------------------------------------------------------------------*
125  *      i4bctlclose - device driver close routine
126  *---------------------------------------------------------------------------*/
127 PDEVSTATIC int
128 i4bctlclose(struct dev_close_args *ap)
129 {
130         openflag = 0;
131         return (0);
132 }
133
134 /*---------------------------------------------------------------------------*
135  *      i4bctlioctl - device driver ioctl routine
136  *---------------------------------------------------------------------------*/
137 PDEVSTATIC int
138 i4bctlioctl(struct dev_ioctl_args *ap)
139 {
140         cdev_t dev = ap->a_head.a_dev;
141 #if DO_I4B_DEBUG
142         ctl_debug_t *cdbg;      
143         int error = 0;
144 #endif
145         
146 #if !DO_I4B_DEBUG
147        return(ENODEV);
148 #else
149         if(minor(dev))
150                 return(ENODEV);
151
152         switch(ap->a_cmd)
153         {
154                 case I4B_CTL_GET_DEBUG:
155                         cdbg = (ctl_debug_t *)ap->a_data;
156                         cdbg->l1 = i4b_l1_debug;
157                         cdbg->l2 = i4b_l2_debug;
158                         cdbg->l3 = i4b_l3_debug;
159                         cdbg->l4 = i4b_l4_debug;
160                         break;
161                 
162                 case I4B_CTL_SET_DEBUG:
163                         cdbg = (ctl_debug_t *)ap->a_data;
164                         i4b_l1_debug = cdbg->l1;
165                         i4b_l2_debug = cdbg->l2;
166                         i4b_l3_debug = cdbg->l3;
167                         i4b_l4_debug = cdbg->l4;
168                         break;
169
170                 case I4B_CTL_GET_CHIPSTAT:
171                 {
172                         struct chipstat *cst;
173                         cst = (struct chipstat *)ap->a_data;
174                         (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_GCST, cst);
175                         break;
176                 }
177
178                 case I4B_CTL_CLR_CHIPSTAT:
179                 {
180                         struct chipstat *cst;
181                         cst = (struct chipstat *)ap->a_data;
182                         (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_CCST, cst);
183                         break;
184                 }
185
186                 case I4B_CTL_GET_LAPDSTAT:
187                 {
188                         l2stat_t *l2s;
189                         l2_softc_t *sc;
190                         l2s = (l2stat_t *)ap->a_data;
191
192                         if( l2s->unit < 0 || l2s->unit > MAXL1UNITS)
193                         {
194                                 error = EINVAL;
195                                 break;
196                         }
197                           
198                         sc = &l2_softc[l2s->unit];
199
200                         bcopy(&sc->stat, &l2s->lapdstat, sizeof(lapdstat_t));
201                         break;
202                 }
203
204                 case I4B_CTL_CLR_LAPDSTAT:
205                 {
206                         int *up;
207                         l2_softc_t *sc;
208                         up = (int *)ap->a_data;
209
210                         if( *up < 0 || *up > MAXL1UNITS)
211                         {
212                                 error = EINVAL;
213                                 break;
214                         }
215                           
216                         sc = &l2_softc[*up];
217
218                         bzero(&sc->stat, sizeof(lapdstat_t));
219                         break;
220                 }
221
222                 default:
223                         error = ENOTTY;
224                         break;
225         }
226         return(error);
227 #endif /* DO_I4B_DEBUG */
228 }
229
230 /*---------------------------------------------------------------------------*
231  *      i4bctlpoll - device driver poll routine
232  *---------------------------------------------------------------------------*/
233 static int
234 i4bctlpoll (struct dev_poll_args *ap)
235 {
236         return (ENODEV);
237 }
238
239 #endif /* NI4BCTL > 0 */