root/dev/bluetooth/bthub.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. bthub_match
  2. bthub_attach
  3. bthub_detach
  4. bthubopen
  5. bthubclose
  6. bthubioctl

    1 /*      $OpenBSD: bthub.c,v 1.3 2007/07/23 14:45:38 mk Exp $    */
    2 
    3 /*
    4  * Copyright (c) 2007 Uwe Stuehler <uwe@openbsd.org>
    5  *
    6  * Permission to use, copy, modify, and distribute this software for any
    7  * purpose with or without fee is hereby granted, provided that the above
    8  * copyright notice and this permission notice appear in all copies.
    9  *
   10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   17  */
   18 
   19 #include <sys/param.h>
   20 #include <sys/systm.h>
   21 #include <sys/conf.h>
   22 #include <sys/device.h>
   23 #include <sys/ioctl.h>
   24 #include <sys/vnode.h>
   25 
   26 #include <netbt/bluetooth.h>
   27 
   28 struct bthub_softc {
   29         struct device sc_dev;
   30         int sc_open;
   31 };
   32 
   33 int     bthub_match(struct device *, void *, void *);
   34 void    bthub_attach(struct device *, struct device *, void *);
   35 int     bthub_detach(struct device *, int);
   36 
   37 struct cfattach bthub_ca = {
   38         sizeof(struct bthub_softc), bthub_match, bthub_attach, bthub_detach
   39 };
   40 
   41 struct cfdriver bthub_cd = {
   42         NULL, "bthub", DV_DULL
   43 };
   44 
   45 int
   46 bthub_match(struct device *parent, void *match, void *aux)
   47 {
   48         return (1);
   49 }
   50 
   51 void
   52 bthub_attach(struct device *parent, struct device *self, void *aux)
   53 {
   54         bdaddr_t *addr = aux;
   55         struct bthub_softc *sc = (struct bthub_softc *)self;
   56 
   57         sc->sc_open = 0;
   58 
   59         printf(" %02x:%02x:%02x:%02x:%02x:%02x\n",
   60             addr->b[5], addr->b[4], addr->b[3],
   61             addr->b[2], addr->b[1], addr->b[0]);
   62 }
   63 
   64 int
   65 bthub_detach(struct device *self, int flags)
   66 {
   67         int maj, mn;
   68 
   69         /* Locate the major number */
   70         for (maj = 0; maj < nchrdev; maj++)
   71                 if (cdevsw[maj].d_open == bthubopen)
   72                         break;
   73 
   74         /* Nuke the vnodes for any open instances (calls close) */
   75         mn = self->dv_unit;
   76         vdevgone(maj, mn, mn, VCHR);
   77 
   78         return (0);
   79 }
   80 
   81 int
   82 bthubopen(dev_t dev, int flag, int mode, struct proc *p)
   83 {
   84         struct device *dv;
   85         struct bthub_softc *sc;
   86 
   87         dv = device_lookup(&bthub_cd, minor(dev));
   88         if (dv == NULL)
   89                 return (ENXIO);
   90 
   91         sc = (struct bthub_softc *)dv;
   92         if (sc->sc_open) {
   93                 device_unref(dv);
   94                 return (EBUSY);
   95         }
   96 
   97         sc->sc_open = 1;
   98         device_unref(dv);
   99 
  100         return (0);
  101 }
  102 
  103 int
  104 bthubclose(dev_t dev, int flag, int mode, struct proc *p)
  105 {
  106         struct device *dv;
  107         struct bthub_softc *sc;
  108 
  109         dv = device_lookup(&bthub_cd, minor(dev));
  110         sc = (struct bthub_softc *)dv;
  111         sc->sc_open = 0;
  112         device_unref(dv);
  113 
  114         return (0);
  115 }
  116 
  117 int
  118 bthubioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
  119 {
  120         return (ENOTTY);
  121 }
  122 

/* [<][>][^][v][top][bottom][index][help] */