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/netbt/hci_ioctl.c

Version: -  FREEBSD  -  FREEBSD11  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $OpenBSD: hci_ioctl.c,v 1.2 2008/02/24 21:34:48 uwe Exp $       */
    2 /*      $NetBSD: hci_ioctl.c,v 1.7 2007/11/28 20:16:12 plunky Exp $     */
    3 
    4 /*-
    5  * Copyright (c) 2005 Iain Hibbert.
    6  * Copyright (c) 2006 Itronix Inc.
    7  * All rights reserved.
    8  *
    9  * Redistribution and use in source and binary forms, with or without
   10  * modification, are permitted provided that the following conditions
   11  * are met:
   12  * 1. Redistributions of source code must retain the above copyright
   13  *    notice, this list of conditions and the following disclaimer.
   14  * 2. Redistributions in binary form must reproduce the above copyright
   15  *    notice, this list of conditions and the following disclaimer in the
   16  *    documentation and/or other materials provided with the distribution.
   17  * 3. The name of Itronix Inc. may not be used to endorse
   18  *    or promote products derived from this software without specific
   19  *    prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
   22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
   25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   28  * ON ANY THEORY OF LIABILITY, WHETHER IN
   29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   31  * POSSIBILITY OF SUCH DAMAGE.
   32  */
   33 
   34 #include <sys/param.h>
   35 #include <sys/domain.h>
   36 #include <sys/ioctl.h>
   37 #include <sys/kernel.h>
   38 #include <sys/mbuf.h>
   39 #include <sys/proc.h>
   40 #include <sys/systm.h>
   41 
   42 #include <netbt/bluetooth.h>
   43 #include <netbt/hci.h>
   44 #include <netbt/l2cap.h>
   45 #include <netbt/rfcomm.h>
   46 
   47 #ifdef BLUETOOTH_DEBUG
   48 #define BDADDR(bd)      (bd).b[5], (bd).b[4], (bd).b[3],        \
   49                         (bd).b[2], (bd).b[1], (bd).b[0]
   50 
   51 static void
   52 hci_dump(void)
   53 {
   54         struct hci_unit *unit;
   55         struct hci_link *link;
   56         struct l2cap_channel *chan;
   57         struct rfcomm_session *rs;
   58         struct rfcomm_dlc *dlc;
   59 
   60         printf("HCI:\n");
   61         TAILQ_FOREACH(unit, &hci_unit_list, hci_next) {
   62                 printf("UNIT %s: flags 0x%4.4x, "
   63                         "num_cmd=%d, num_acl=%d, num_sco=%d\n",
   64                         device_xname(unit->hci_dev), unit->hci_flags,
   65                         unit->hci_num_cmd_pkts,
   66                         unit->hci_num_acl_pkts,
   67                         unit->hci_num_sco_pkts);
   68                 TAILQ_FOREACH(link, &unit->hci_links, hl_next) {
   69                         printf("+HANDLE #%d: %s "
   70                             "raddr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
   71                             "state %d, refcnt %d\n",
   72                             link->hl_handle,
   73                             (link->hl_type == HCI_LINK_ACL ? "ACL":"SCO"),
   74                             BDADDR(link->hl_bdaddr),
   75                             link->hl_state, link->hl_refcnt);
   76                 }
   77         }
   78 
   79         printf("L2CAP:\n");
   80         LIST_FOREACH(chan, &l2cap_active_list, lc_ncid) {
   81                 printf("CID #%d state %d, psm=0x%4.4x, "
   82                     "laddr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
   83                     "raddr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
   84                     chan->lc_lcid, chan->lc_state, chan->lc_raddr.bt_psm,
   85                     BDADDR(chan->lc_laddr.bt_bdaddr),
   86                     BDADDR(chan->lc_raddr.bt_bdaddr));
   87         }
   88 
   89         LIST_FOREACH(chan, &l2cap_listen_list, lc_ncid) {
   90                 printf("LISTEN psm=0x%4.4x, "
   91                     "laddr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
   92                     chan->lc_laddr.bt_psm,
   93                     BDADDR(chan->lc_laddr.bt_bdaddr));
   94         }
   95 
   96         printf("RFCOMM:\n");
   97         LIST_FOREACH(rs, &rfcomm_session_active, rs_next) {
   98                 chan = rs->rs_l2cap;
   99                 printf("SESSION: state=%d, flags=0x%4.4x, psm 0x%4.4x "
  100                     "laddr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
  101                     "raddr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
  102                     rs->rs_state, rs->rs_flags, chan->lc_raddr.bt_psm,
  103                     BDADDR(chan->lc_laddr.bt_bdaddr),
  104                     BDADDR(chan->lc_raddr.bt_bdaddr));
  105                 LIST_FOREACH(dlc, &rs->rs_dlcs, rd_next) {
  106                         printf("+DLC channel=%d, dlci=%d, "
  107                             "state=%d, flags=0x%4.4x, rxcred=%d, rxsize=%ld, "
  108                             "txcred=%d, pending=%d, txqlen=%d\n",
  109                             dlc->rd_raddr.bt_channel, dlc->rd_dlci,
  110                             dlc->rd_state, dlc->rd_flags,
  111                             dlc->rd_rxcred, (unsigned long)dlc->rd_rxsize,
  112                             dlc->rd_txcred, dlc->rd_pending,
  113                             (dlc->rd_txbuf ? dlc->rd_txbuf->m_pkthdr.len : 0));
  114                 }
  115         }
  116 
  117         LIST_FOREACH(rs, &rfcomm_session_listen, rs_next) {
  118                 chan = rs->rs_l2cap;
  119                 printf("LISTEN: psm 0x%4.4x, "
  120                     "laddr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
  121                     chan->lc_laddr.bt_psm,
  122                     BDADDR(chan->lc_laddr.bt_bdaddr));
  123                 LIST_FOREACH(dlc, &rs->rs_dlcs, rd_next)
  124                         printf("+DLC channel=%d\n", dlc->rd_laddr.bt_channel);
  125         }
  126 }
  127 
  128 #undef BDADDR
  129 #endif
  130 
  131 int
  132 hci_ioctl(unsigned long cmd, void *data, struct proc *p)
  133 {
  134         struct btreq *btr = data;
  135         struct hci_unit *unit;
  136         int err = 0;
  137 
  138         DPRINTFN(1, "cmd %#lx\n", cmd);
  139 
  140         switch(cmd) {
  141 #ifdef BLUETOOTH_DEBUG
  142         case SIOCBTDUMP:
  143                 hci_dump();
  144                 return 0;
  145 #endif
  146         /*
  147          * Get unit info based on address rather than name
  148          */
  149         case SIOCGBTINFOA:
  150                 unit = hci_unit_lookup(&btr->btr_bdaddr);
  151                 if (unit == NULL)
  152                         return ENXIO;
  153 
  154                 break;
  155 
  156         /*
  157          * The remaining ioctl's all use the same btreq structure and
  158          * index on the name of the device, so we look that up first.
  159          */
  160         case SIOCNBTINFO:
  161                 /* empty name means give the first unit */
  162                 if (btr->btr_name[0] == '\0') {
  163                         unit = NULL;
  164                         break;
  165                 }
  166 
  167                 /* else fall through and look it up */
  168         case SIOCGBTINFO:
  169         case SIOCSBTFLAGS:
  170         case SIOCSBTPOLICY:
  171         case SIOCSBTPTYPE:
  172         case SIOCGBTSTATS:
  173         case SIOCZBTSTATS:
  174         case SIOCSBTSCOMTU:
  175                 TAILQ_FOREACH(unit, &hci_unit_list, hci_next) {
  176                         if (strncmp(device_xname(unit->hci_dev), btr->btr_name,
  177                             HCI_DEVNAME_SIZE) == 0)
  178                                 break;
  179                 }
  180 
  181                 if (unit == NULL)
  182                         return ENXIO;
  183 
  184                 break;
  185 
  186         default:        /* not one of mine */
  187                 return EPASSTHROUGH;
  188         }
  189 
  190         switch(cmd) {
  191         case SIOCNBTINFO:       /* get next info */
  192                 if (unit)
  193                         unit = TAILQ_NEXT(unit, hci_next);
  194                 else
  195                         unit = TAILQ_FIRST(&hci_unit_list);
  196 
  197                 if (unit == NULL) {
  198                         err = ENXIO;
  199                         break;
  200                 }
  201 
  202                 /* and fall through to */
  203         case SIOCGBTINFO:       /* get unit info */
  204         case SIOCGBTINFOA:      /* get info by address */
  205                 memset(btr, 0, sizeof(struct btreq));
  206                 strlcpy(btr->btr_name, device_xname(unit->hci_dev), HCI_DEVNAME_SIZE);
  207                 bdaddr_copy(&btr->btr_bdaddr, &unit->hci_bdaddr);
  208 
  209                 btr->btr_flags = unit->hci_flags;
  210 
  211                 btr->btr_num_cmd = unit->hci_num_cmd_pkts;
  212                 btr->btr_num_acl = unit->hci_num_acl_pkts;
  213                 btr->btr_num_sco = unit->hci_num_sco_pkts;
  214                 btr->btr_acl_mtu = unit->hci_max_acl_size;
  215                 btr->btr_sco_mtu = unit->hci_max_sco_size;
  216 
  217                 btr->btr_packet_type = unit->hci_packet_type;
  218                 btr->btr_link_policy = unit->hci_link_policy;
  219                 break;
  220 
  221         case SIOCSBTFLAGS:      /* set unit flags (privileged) */
  222                 err = suser(p, 0);
  223                 if (err)
  224                         break;
  225 
  226                 if ((unit->hci_flags & BTF_UP)
  227                     && (btr->btr_flags & BTF_UP) == 0) {
  228                         hci_disable(unit);
  229                         unit->hci_flags &= ~BTF_UP;
  230                 }
  231 
  232                 unit->hci_flags |= (btr->btr_flags & BTF_INIT);
  233 
  234                 if ((unit->hci_flags & BTF_UP) == 0
  235                     && (btr->btr_flags & BTF_UP)) {
  236                         err = hci_enable(unit);
  237                         if (err)
  238                                 break;
  239 
  240                         unit->hci_flags |= BTF_UP;
  241                 }
  242 
  243                 btr->btr_flags = unit->hci_flags;
  244                 break;
  245 
  246         case SIOCSBTPOLICY:     /* set unit link policy (privileged) */
  247                 err = suser(p, 0);
  248                 if (err)
  249                         break;
  250 
  251                 unit->hci_link_policy = btr->btr_link_policy;
  252                 unit->hci_link_policy &= unit->hci_lmp_mask;
  253                 btr->btr_link_policy = unit->hci_link_policy;
  254                 break;
  255 
  256         case SIOCSBTPTYPE:      /* set unit packet types (privileged) */
  257                 err = suser(p, 0);
  258                 if (err)
  259                         break;
  260 
  261                 unit->hci_packet_type = btr->btr_packet_type;
  262                 unit->hci_packet_type &= unit->hci_acl_mask;
  263                 btr->btr_packet_type = unit->hci_packet_type;
  264                 break;
  265 
  266         case SIOCGBTSTATS:      /* get unit statistics */
  267                 (*unit->hci_if->get_stats)(unit->hci_dev, &btr->btr_stats, 0);
  268                 break;
  269 
  270         case SIOCZBTSTATS:      /* get & reset unit statistics */
  271                 err = suser(p, 0);
  272                 if (err)
  273                         break;
  274 
  275                 (*unit->hci_if->get_stats)(unit->hci_dev, &btr->btr_stats, 1);
  276                 break;
  277 
  278         case SIOCSBTSCOMTU:     /* set sco_mtu value for unit */
  279                 /*
  280                  * This is a temporary ioctl and may not be supported
  281                  * in the future. The need is that if SCO packets are
  282                  * sent to USB bluetooth controllers that are not an
  283                  * integer number of frame sizes, the USB bus locks up.
  284                  */
  285                 err = suser(p, 0);
  286                 if (err)
  287                         break;
  288 
  289                 unit->hci_max_sco_size = btr->btr_sco_mtu;
  290                 break;
  291 
  292         default:
  293                 err = EFAULT;
  294                 break;
  295         }
  296 
  297         return err;
  298 }

Cache object: 0b0e7843bfbf299391347049773bb82e


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