]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/i4b/driver/i4b_ctl.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / i4b / driver / i4b_ctl.c
1 /*-
2  * Copyright (c) 1997, 2002 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  *
28  *      i4b_ctl.c - i4b system control port driver
29  *      ------------------------------------------
30  *      last edit-date: [Sun Mar 17 09:49:24 2002]
31  *
32  *---------------------------------------------------------------------------*/
33
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
36
37 #include <sys/param.h>
38 #include <sys/ioccom.h>
39 #include <sys/kernel.h>
40 #include <sys/systm.h>
41 #include <sys/conf.h>
42 #include <sys/socket.h>
43 #include <net/if.h>
44
45 #include <i4b/include/i4b_debug.h>
46 #include <i4b/include/i4b_ioctl.h>
47
48 #include <i4b/include/i4b_global.h>
49 #include <i4b/include/i4b_l3l4.h>
50
51 #include <i4b/layer2/i4b_l2.h>
52
53 static int openflag = 0;
54
55 static  d_open_t        i4bctlopen;
56 static  d_close_t       i4bctlclose;
57 static  d_ioctl_t       i4bctlioctl;
58 static  d_poll_t        i4bctlpoll;
59
60
61 static struct cdevsw i4bctl_cdevsw = {
62         .d_version =    D_VERSION,
63         .d_flags =      D_NEEDGIANT,
64         .d_open =       i4bctlopen,
65         .d_close =      i4bctlclose,
66         .d_ioctl =      i4bctlioctl,
67         .d_poll =       i4bctlpoll,
68         .d_name =       "i4bctl",
69 };
70
71 static void i4bctlattach(void *);
72 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
73
74 /*---------------------------------------------------------------------------*
75  *      interface attach routine
76  *---------------------------------------------------------------------------*/
77 static void
78 i4bctlattach(void *dummy)
79 {
80         printf("i4bctl: ISDN system control port attached\n");
81         make_dev(&i4bctl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "i4bctl");
82 }
83
84 /*---------------------------------------------------------------------------*
85  *      i4bctlopen - device driver open routine
86  *---------------------------------------------------------------------------*/
87 static int
88 i4bctlopen(struct cdev *dev, int flag, int fmt, struct thread *td)
89 {
90         if(minor(dev))
91                 return (ENXIO);
92
93         if(openflag)
94                 return (EBUSY);
95         
96         openflag = 1;
97         
98         return (0);
99 }
100
101 /*---------------------------------------------------------------------------*
102  *      i4bctlclose - device driver close routine
103  *---------------------------------------------------------------------------*/
104 static int
105 i4bctlclose(struct cdev *dev, int flag, int fmt, struct thread *td)
106 {
107         openflag = 0;
108         return (0);
109 }
110
111 /*---------------------------------------------------------------------------*
112  *      i4bctlioctl - device driver ioctl routine
113  *---------------------------------------------------------------------------*/
114 static int
115 i4bctlioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
116 {
117 #if DO_I4B_DEBUG
118         ctl_debug_t *cdbg;      
119         int error = 0;
120 #endif
121         
122 #if !DO_I4B_DEBUG
123        return(ENODEV);
124 #else
125         if(minor(dev))
126                 return(ENODEV);
127
128         switch(cmd)
129         {
130                 case I4B_CTL_GET_DEBUG:
131                         cdbg = (ctl_debug_t *)data;
132                         cdbg->l1 = i4b_l1_debug;
133                         cdbg->l2 = i4b_l2_debug;
134                         cdbg->l3 = i4b_l3_debug;
135                         cdbg->l4 = i4b_l4_debug;
136                         break;
137                 
138                 case I4B_CTL_SET_DEBUG:
139                         cdbg = (ctl_debug_t *)data;
140                         i4b_l1_debug = cdbg->l1;
141                         i4b_l2_debug = cdbg->l2;
142                         i4b_l3_debug = cdbg->l3;
143                         i4b_l4_debug = cdbg->l4;
144                         break;
145
146                 case I4B_CTL_GET_CHIPSTAT:
147                 {
148                         struct chipstat *cst;
149                         cst = (struct chipstat *)data;
150                         (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_GCST, cst);
151                         break;
152                 }
153
154                 case I4B_CTL_CLR_CHIPSTAT:
155                 {
156                         struct chipstat *cst;
157                         cst = (struct chipstat *)data;
158                         (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_CCST, cst);
159                         break;
160                 }
161
162                 case I4B_CTL_GET_LAPDSTAT:
163                 {
164                         l2stat_t *l2s;
165                         l2_softc_t *sc;
166                         l2s = (l2stat_t *)data;
167
168                         if( l2s->unit < 0 || l2s->unit > MAXL1UNITS)
169                         {
170                                 error = EINVAL;
171                                 break;
172                         }
173                           
174                         sc = &l2_softc[l2s->unit];
175
176                         bcopy(&sc->stat, &l2s->lapdstat, sizeof(lapdstat_t));
177                         break;
178                 }
179
180                 case I4B_CTL_CLR_LAPDSTAT:
181                 {
182                         int *up;
183                         l2_softc_t *sc;
184                         up = (int *)data;
185
186                         if( *up < 0 || *up > MAXL1UNITS)
187                         {
188                                 error = EINVAL;
189                                 break;
190                         }
191                           
192                         sc = &l2_softc[*up];
193
194                         bzero(&sc->stat, sizeof(lapdstat_t));
195                         break;
196                 }
197
198                 default:
199                         error = ENOTTY;
200                         break;
201         }
202         return(error);
203 #endif /* DO_I4B_DEBUG */
204 }
205
206 /*---------------------------------------------------------------------------*
207  *      i4bctlpoll - device driver poll routine
208  *---------------------------------------------------------------------------*/
209 static int
210 i4bctlpoll (struct cdev *dev, int events, struct thread *td)
211 {
212         return (ENODEV);
213 }