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.19 2007/10/19 12:16:47 ad 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.19 2007/10/19 12:16:47 ad 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 <sys/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 
   95 static int openflag = 0;
   96 
   97 #if BSD > 199306 && defined(__FreeBSD__)
   98 static  d_open_t        i4bctlopen;
   99 static  d_close_t       i4bctlclose;
  100 static  d_ioctl_t       i4bctlioctl;
  101 
  102 #ifdef OS_USES_POLL
  103 static d_poll_t         i4bctlpoll;
  104 #define POLLFIELD       i4bctlpoll
  105 #else
  106 #define POLLFIELD       noselect
  107 #endif
  108 
  109 #define CDEV_MAJOR 55
  110 
  111 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
  112 static struct cdevsw i4bctl_cdevsw = {
  113         /* open */      i4bctlopen,
  114         /* close */     i4bctlclose,
  115         /* read */      noread,
  116         /* write */     nowrite,
  117         /* ioctl */     i4bctlioctl,
  118         /* poll */      POLLFIELD,
  119         /* mmap */      nommap,
  120         /* strategy */  nostrategy,
  121         /* name */      "i4bctl",
  122         /* maj */       CDEV_MAJOR,
  123         /* dump */      nodump,
  124         /* psize */     nopsize,
  125         /* flags */     0,
  126         /* bmaj */      -1
  127 };
  128 #else
  129 static struct cdevsw i4bctl_cdevsw =
  130         { i4bctlopen,   i4bctlclose,    noread,         nowrite,
  131           i4bctlioctl,  nostop,         nullreset,      nodevtotty,
  132           POLLFIELD,    nommap,         NULL,   "i4bctl", NULL, -1 };
  133 #endif
  134 
  135 static void i4bctlattach(void *);
  136 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
  137 
  138 #define PDEVSTATIC      static
  139 #endif /* __FreeBSD__ */
  140 
  141 #if defined(__FreeBSD__) && __FreeBSD__ == 3
  142 #ifdef DEVFS
  143 static void *devfs_token;
  144 #endif
  145 #endif
  146 
  147 #ifndef __FreeBSD__
  148 #define PDEVSTATIC      /* */
  149 void isdnctlattach __P((void));
  150 int isdnctlopen __P((dev_t dev, int flag, int fmt, struct lwp *l));
  151 int isdnctlclose __P((dev_t dev, int flag, int fmt, struct lwp *l));
  152 int isdnctlioctl __P((dev_t dev, u_long cmd, void *data, int flag, struct lwp *l));
  153 #endif  /* !FreeBSD */
  154 
  155 #ifdef __NetBSD__
  156 const struct cdevsw isdnctl_cdevsw = {
  157         isdnctlopen, isdnctlclose, noread, nowrite, isdnctlioctl,
  158         nostop, notty, nopoll, nommap, nokqfilter, D_OTHER
  159 };
  160 #endif /* __NetBSD__ */
  161 
  162 #if BSD > 199306 && defined(__FreeBSD__)
  163 /*---------------------------------------------------------------------------*
  164  *      initialization at kernel load time
  165  *---------------------------------------------------------------------------*/
  166 static void
  167 i4bctlinit(void *unused)
  168 {
  169 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
  170         cdevsw_add(&i4bctl_cdevsw);
  171 #else
  172         dev_t dev = makedev(CDEV_MAJOR, 0);
  173         cdevsw_add(&dev, &i4bctl_cdevsw, NULL);
  174 #endif
  175 }
  176 
  177 SYSINIT(i4bctldev, SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, &i4bctlinit, NULL);
  178 
  179 #endif /* BSD > 199306 && defined(__FreeBSD__) */
  180 
  181 #ifdef __bsdi__
  182 int i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux);
  183 void dummy_i4bctlattach(struct device*, struct device *, void *);
  184 
  185 #define CDEV_MAJOR 64
  186 
  187 static struct cfdriver i4bctlcd =
  188         { NULL, "i4bctl", i4bctlmatch, dummy_i4bctlattach, DV_DULL,
  189           sizeof(struct cfdriver) };
  190 struct devsw i4bctlsw =
  191         { &i4bctlcd,
  192           i4bctlopen,   i4bctlclose,    noread,         nowrite,
  193           i4bctlioctl,  seltrue,        nommap,         nostrat,
  194           nodump,       nopsize,        0,              nostop
  195 };
  196 
  197 int
  198 i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux)
  199 {
  200         printf("i4bctlmatch: aux=0x%x\n", aux);
  201         return 1;
  202 }
  203 void
  204 dummy_i4bctlattach(struct device *parent, struct device *self, void *aux)
  205 {
  206         printf("dummy_i4bctlattach: aux=0x%x\n", aux);
  207 }
  208 #endif /* __bsdi__ */
  209 /*---------------------------------------------------------------------------*
  210  *      interface attach routine
  211  *---------------------------------------------------------------------------*/
  212 PDEVSTATIC void
  213 #ifdef __FreeBSD__
  214 isdnctlattach(void *dummy)
  215 #else
  216 isdnctlattach()
  217 #endif
  218 {
  219 
  220 #if defined(__FreeBSD__)
  221 #if __FreeBSD__ == 3
  222 
  223 #ifdef DEVFS
  224         devfs_token = devfs_add_devswf(&i4bctl_cdevsw, 0, DV_CHR,
  225                                        UID_ROOT, GID_WHEEL, 0600,
  226                                        "i4bctl");
  227 #endif
  228 
  229 #else
  230         make_dev(&i4bctl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "i4bctl");
  231 #endif
  232 #endif
  233 }
  234 
  235 /*---------------------------------------------------------------------------*
  236  *      i4bctlopen - device driver open routine
  237  *---------------------------------------------------------------------------*/
  238 PDEVSTATIC int
  239 isdnctlopen(dev_t dev, int flag, int fmt,
  240         struct lwp *l)
  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,
  258         struct lwp *l)
  259 {
  260         openflag = 0;
  261         return (0);
  262 }
  263 
  264 /*---------------------------------------------------------------------------*
  265  *      i4bctlioctl - device driver ioctl routine
  266  *---------------------------------------------------------------------------*/
  267 PDEVSTATIC int
  268 isdnctlioctl(dev_t dev, u_long cmd, void *data, int flag,
  269         struct lwp *l)
  270 {
  271 #if DO_I4B_DEBUG
  272         ctl_debug_t *cdbg;
  273         int error = 0;
  274 #endif
  275 
  276 #if !DO_I4B_DEBUG
  277         return(ENODEV);
  278 #else
  279         if(minor(dev))
  280                 return(ENODEV);
  281 
  282         switch(cmd)
  283         {
  284                 case I4B_CTL_GET_DEBUG:
  285                         cdbg = (ctl_debug_t *)data;
  286                         cdbg->l1 = i4b_l1_debug;
  287                         cdbg->l2 = i4b_l2_debug;
  288                         cdbg->l3 = i4b_l3_debug;
  289                         cdbg->l4 = i4b_l4_debug;
  290                         break;
  291 
  292                 case I4B_CTL_SET_DEBUG:
  293                         cdbg = (ctl_debug_t *)data;
  294                         i4b_l1_debug = cdbg->l1;
  295                         i4b_l2_debug = cdbg->l2;
  296                         i4b_l3_debug = cdbg->l3;
  297                         i4b_l4_debug = cdbg->l4;
  298                         break;
  299 
  300                 case I4B_CTL_GET_CHIPSTAT:
  301                 {
  302                         struct chipstat *cst;
  303                         l2_softc_t * scl2;
  304                         cst = (struct chipstat *)data;
  305                         scl2 = (l2_softc_t*)isdn_find_softc_by_isdnif(cst->driver_unit);
  306                         scl2->driver->mph_command_req(scl2->l1_token, CMR_GCST, cst);
  307                         break;
  308                 }
  309 
  310                 case I4B_CTL_CLR_CHIPSTAT:
  311                 {
  312                         struct chipstat *cst;
  313                         l2_softc_t * scl2;
  314                         cst = (struct chipstat *)data;
  315                         scl2 = (l2_softc_t*)isdn_find_softc_by_isdnif(cst->driver_unit);
  316                         scl2->driver->mph_command_req(scl2->l1_token, CMR_CCST, cst);
  317                         break;
  318                 }
  319 
  320                 case I4B_CTL_GET_LAPDSTAT:
  321                 {
  322                         l2stat_t *l2s;
  323                         l2_softc_t *sc;
  324                         l2s = (l2stat_t *)data;
  325 
  326                         sc = (l2_softc_t*)isdn_find_softc_by_isdnif(l2s->unit);
  327                         if (sc == NULL) {
  328                                 error = EINVAL;
  329                                 break;
  330                         }
  331 
  332                         memcpy(&l2s->lapdstat, &sc->stat, sizeof(lapdstat_t));
  333                         break;
  334                 }
  335 
  336                 case I4B_CTL_CLR_LAPDSTAT:
  337                 {
  338                         int *up;
  339                         l2_softc_t *sc;
  340                         up = (int *)data;
  341 
  342                         sc = (l2_softc_t*)isdn_find_softc_by_isdnif(*up);
  343                         if (sc == NULL) {
  344                                 error = EINVAL;
  345                                 break;
  346                         }
  347 
  348                         memset(&sc->stat, 0, sizeof(lapdstat_t));
  349                         break;
  350                 }
  351 
  352                 default:
  353                         error = ENOTTY;
  354                         break;
  355         }
  356         return(error);
  357 #endif /* DO_I4B_DEBUG */
  358 }
  359 
  360 #if defined(__FreeBSD__) && defined(OS_USES_POLL)
  361 
  362 /*---------------------------------------------------------------------------*
  363  *      i4bctlpoll - device driver poll routine
  364  *---------------------------------------------------------------------------*/
  365 static int
  366 isdnctlpoll (dev_t dev, int events, struct lwp *l)
  367 {
  368         return (ENODEV);
  369 }
  370 
  371 #endif
  372 
  373 #endif /* NISDNCTL > 0 */

Cache object: c3450bca290ab01e88a6cc2907fd626f


[ 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.