The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netisdn/i4b_ctl.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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.16 2006/11/16 01:33:49 christos 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.16 2006/11/16 01:33:49 christos 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 lwp *l));
  152 int isdnctlclose __P((dev_t dev, int flag, int fmt, struct lwp *l));
  153 int isdnctlioctl __P((dev_t dev, u_long cmd, caddr_t data, int flag, struct lwp *l));
  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, D_OTHER
  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,
  241         struct lwp *l)
  242 {
  243         if(minor(dev))
  244                 return (ENXIO);
  245 
  246         if(openflag)
  247                 return (EBUSY);
  248 
  249         openflag = 1;
  250 
  251         return (0);
  252 }
  253 
  254 /*---------------------------------------------------------------------------*
  255  *      i4bctlclose - device driver close routine
  256  *---------------------------------------------------------------------------*/
  257 PDEVSTATIC int
  258 isdnctlclose(dev_t dev, int flag, int fmt,
  259         struct lwp *l)
  260 {
  261         openflag = 0;
  262         return (0);
  263 }
  264 
  265 /*---------------------------------------------------------------------------*
  266  *      i4bctlioctl - device driver ioctl routine
  267  *---------------------------------------------------------------------------*/
  268 PDEVSTATIC int
  269 isdnctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag,
  270         struct lwp *l)
  271 {
  272 #if DO_I4B_DEBUG
  273         ctl_debug_t *cdbg;
  274         int error = 0;
  275 #endif
  276 
  277 #if !DO_I4B_DEBUG
  278         return(ENODEV);
  279 #else
  280         if(minor(dev))
  281                 return(ENODEV);
  282 
  283         switch(cmd)
  284         {
  285                 case I4B_CTL_GET_DEBUG:
  286                         cdbg = (ctl_debug_t *)data;
  287                         cdbg->l1 = i4b_l1_debug;
  288                         cdbg->l2 = i4b_l2_debug;
  289                         cdbg->l3 = i4b_l3_debug;
  290                         cdbg->l4 = i4b_l4_debug;
  291                         break;
  292 
  293                 case I4B_CTL_SET_DEBUG:
  294                         cdbg = (ctl_debug_t *)data;
  295                         i4b_l1_debug = cdbg->l1;
  296                         i4b_l2_debug = cdbg->l2;
  297                         i4b_l3_debug = cdbg->l3;
  298                         i4b_l4_debug = cdbg->l4;
  299                         break;
  300 
  301                 case I4B_CTL_GET_CHIPSTAT:
  302                 {
  303                         struct chipstat *cst;
  304                         l2_softc_t * scl2;
  305                         cst = (struct chipstat *)data;
  306                         scl2 = (l2_softc_t*)isdn_find_softc_by_isdnif(cst->driver_unit);
  307                         scl2->driver->mph_command_req(scl2->l1_token, CMR_GCST, cst);
  308                         break;
  309                 }
  310 
  311                 case I4B_CTL_CLR_CHIPSTAT:
  312                 {
  313                         struct chipstat *cst;
  314                         l2_softc_t * scl2;
  315                         cst = (struct chipstat *)data;
  316                         scl2 = (l2_softc_t*)isdn_find_softc_by_isdnif(cst->driver_unit);
  317                         scl2->driver->mph_command_req(scl2->l1_token, CMR_CCST, cst);
  318                         break;
  319                 }
  320 
  321                 case I4B_CTL_GET_LAPDSTAT:
  322                 {
  323                         l2stat_t *l2s;
  324                         l2_softc_t *sc;
  325                         l2s = (l2stat_t *)data;
  326 
  327                         sc = (l2_softc_t*)isdn_find_softc_by_isdnif(l2s->unit);
  328                         if (sc == NULL) {
  329                                 error = EINVAL;
  330                                 break;
  331                         }
  332 
  333                         memcpy(&l2s->lapdstat, &sc->stat, sizeof(lapdstat_t));
  334                         break;
  335                 }
  336 
  337                 case I4B_CTL_CLR_LAPDSTAT:
  338                 {
  339                         int *up;
  340                         l2_softc_t *sc;
  341                         up = (int *)data;
  342 
  343                         sc = (l2_softc_t*)isdn_find_softc_by_isdnif(*up);
  344                         if (sc == NULL) {
  345                                 error = EINVAL;
  346                                 break;
  347                         }
  348 
  349                         memset(&sc->stat, 0, sizeof(lapdstat_t));
  350                         break;
  351                 }
  352 
  353                 default:
  354                         error = ENOTTY;
  355                         break;
  356         }
  357         return(error);
  358 #endif /* DO_I4B_DEBUG */
  359 }
  360 
  361 #if defined(__FreeBSD__) && defined(OS_USES_POLL)
  362 
  363 /*---------------------------------------------------------------------------*
  364  *      i4bctlpoll - device driver poll routine
  365  *---------------------------------------------------------------------------*/
  366 static int
  367 isdnctlpoll (dev_t dev, int events, struct lwp *l)
  368 {
  369         return (ENODEV);
  370 }
  371 
  372 #endif
  373 
  374 #endif /* NISDNCTL > 0 */

Cache object: 22fc3216a244ac542d7dffb6bc0a499e


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.