Merge from vendor branch WPA_SUPPLICANT:
[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.11 2005/06/14 21:19:18 joerg 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/ioccom.h>
50
51 #include <sys/kernel.h>
52 #include <sys/systm.h>
53 #include <sys/conf.h>
54 #include <sys/socket.h>
55 #include <net/if.h>
56
57 #include <net/i4b/include/machine/i4b_debug.h>
58 #include <net/i4b/include/machine/i4b_ioctl.h>
59
60 #include "../include/i4b_global.h"
61 #include "../include/i4b_l3l4.h"
62 #include "../layer2/i4b_l2.h"
63
64 static int openflag = 0;
65
66 static  d_open_t        i4bctlopen;
67 static  d_close_t       i4bctlclose;
68 static  d_ioctl_t       i4bctlioctl;
69
70 static d_poll_t         i4bctlpoll;
71 #define POLLFIELD       i4bctlpoll
72
73 #define CDEV_MAJOR 55
74
75 static struct cdevsw i4bctl_cdevsw = {
76         /* name */      "i4bctl",
77         /* maj */       CDEV_MAJOR,
78         /* flags */     0,
79         /* port */      NULL,
80         /* clone */     NULL,
81
82         /* open */      i4bctlopen,
83         /* close */     i4bctlclose,
84         /* read */      noread,
85         /* write */     nowrite,
86         /* ioctl */     i4bctlioctl,
87         /* poll */      POLLFIELD,
88         /* mmap */      nommap,
89         /* strategy */  nostrategy,
90         /* dump */      nodump,
91         /* psize */     nopsize
92 };
93
94 static void i4bctlattach(void *);
95 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
96
97 #define PDEVSTATIC      static
98
99 /*---------------------------------------------------------------------------*
100  *      initialization at kernel load time
101  *---------------------------------------------------------------------------*/
102 static void
103 i4bctlinit(void *unused)
104 {
105         cdevsw_add(&i4bctl_cdevsw, 0, 0);
106 }
107
108 SYSINIT(i4bctldev, SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, &i4bctlinit, NULL);
109
110 /*---------------------------------------------------------------------------*
111  *      interface attach routine
112  *---------------------------------------------------------------------------*/
113 PDEVSTATIC void
114 i4bctlattach(void *dummy)
115 {
116 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
117         printf("i4bctl: ISDN system control port attached\n");
118 #endif
119 }
120
121 /*---------------------------------------------------------------------------*
122  *      i4bctlopen - device driver open routine
123  *---------------------------------------------------------------------------*/
124 PDEVSTATIC int
125 i4bctlopen(dev_t dev, int flag, int fmt, struct thread *td)
126 {
127         if(minor(dev))
128                 return (ENXIO);
129
130         if(openflag)
131                 return (EBUSY);
132         
133         openflag = 1;
134         
135         return (0);
136 }
137
138 /*---------------------------------------------------------------------------*
139  *      i4bctlclose - device driver close routine
140  *---------------------------------------------------------------------------*/
141 PDEVSTATIC int
142 i4bctlclose(dev_t dev, int flag, int fmt, struct thread *td)
143 {
144         openflag = 0;
145         return (0);
146 }
147
148 /*---------------------------------------------------------------------------*
149  *      i4bctlioctl - device driver ioctl routine
150  *---------------------------------------------------------------------------*/
151 PDEVSTATIC int
152 i4bctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
153 {
154 #if DO_I4B_DEBUG
155         ctl_debug_t *cdbg;      
156         int error = 0;
157 #endif
158         
159 #if !DO_I4B_DEBUG
160        return(ENODEV);
161 #else
162         if(minor(dev))
163                 return(ENODEV);
164
165         switch(cmd)
166         {
167                 case I4B_CTL_GET_DEBUG:
168                         cdbg = (ctl_debug_t *)data;
169                         cdbg->l1 = i4b_l1_debug;
170                         cdbg->l2 = i4b_l2_debug;
171                         cdbg->l3 = i4b_l3_debug;
172                         cdbg->l4 = i4b_l4_debug;
173                         break;
174                 
175                 case I4B_CTL_SET_DEBUG:
176                         cdbg = (ctl_debug_t *)data;
177                         i4b_l1_debug = cdbg->l1;
178                         i4b_l2_debug = cdbg->l2;
179                         i4b_l3_debug = cdbg->l3;
180                         i4b_l4_debug = cdbg->l4;
181                         break;
182
183                 case I4B_CTL_GET_CHIPSTAT:
184                 {
185                         struct chipstat *cst;
186                         cst = (struct chipstat *)data;
187                         (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_GCST, cst);
188                         break;
189                 }
190
191                 case I4B_CTL_CLR_CHIPSTAT:
192                 {
193                         struct chipstat *cst;
194                         cst = (struct chipstat *)data;
195                         (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_CCST, cst);
196                         break;
197                 }
198
199                 case I4B_CTL_GET_LAPDSTAT:
200                 {
201                         l2stat_t *l2s;
202                         l2_softc_t *sc;
203                         l2s = (l2stat_t *)data;
204
205                         if( l2s->unit < 0 || l2s->unit > MAXL1UNITS)
206                         {
207                                 error = EINVAL;
208                                 break;
209                         }
210                           
211                         sc = &l2_softc[l2s->unit];
212
213                         bcopy(&sc->stat, &l2s->lapdstat, sizeof(lapdstat_t));
214                         break;
215                 }
216
217                 case I4B_CTL_CLR_LAPDSTAT:
218                 {
219                         int *up;
220                         l2_softc_t *sc;
221                         up = (int *)data;
222
223                         if( *up < 0 || *up > MAXL1UNITS)
224                         {
225                                 error = EINVAL;
226                                 break;
227                         }
228                           
229                         sc = &l2_softc[*up];
230
231                         bzero(&sc->stat, sizeof(lapdstat_t));
232                         break;
233                 }
234
235                 default:
236                         error = ENOTTY;
237                         break;
238         }
239         return(error);
240 #endif /* DO_I4B_DEBUG */
241 }
242
243 /*---------------------------------------------------------------------------*
244  *      i4bctlpoll - device driver poll routine
245  *---------------------------------------------------------------------------*/
246 static int
247 i4bctlpoll (dev_t dev, int events, struct thread *td)
248 {
249         return (ENODEV);
250 }
251
252 #endif /* NI4BCTL > 0 */