1*b06ebda0SMatthew Dillon /* 2*b06ebda0SMatthew Dillon * ng_ubt_var.h 3*b06ebda0SMatthew Dillon */ 4*b06ebda0SMatthew Dillon 5*b06ebda0SMatthew Dillon /*- 6*b06ebda0SMatthew Dillon * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> 7*b06ebda0SMatthew Dillon * All rights reserved. 8*b06ebda0SMatthew Dillon * 9*b06ebda0SMatthew Dillon * Redistribution and use in source and binary forms, with or without 10*b06ebda0SMatthew Dillon * modification, are permitted provided that the following conditions 11*b06ebda0SMatthew Dillon * are met: 12*b06ebda0SMatthew Dillon * 1. Redistributions of source code must retain the above copyright 13*b06ebda0SMatthew Dillon * notice, this list of conditions and the following disclaimer. 14*b06ebda0SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright 15*b06ebda0SMatthew Dillon * notice, this list of conditions and the following disclaimer in the 16*b06ebda0SMatthew Dillon * documentation and/or other materials provided with the distribution. 17*b06ebda0SMatthew Dillon * 18*b06ebda0SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19*b06ebda0SMatthew Dillon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*b06ebda0SMatthew Dillon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*b06ebda0SMatthew Dillon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22*b06ebda0SMatthew Dillon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23*b06ebda0SMatthew Dillon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24*b06ebda0SMatthew Dillon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25*b06ebda0SMatthew Dillon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26*b06ebda0SMatthew Dillon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27*b06ebda0SMatthew Dillon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28*b06ebda0SMatthew Dillon * SUCH DAMAGE. 29*b06ebda0SMatthew Dillon * 30*b06ebda0SMatthew Dillon * $Id: ng_ubt_var.h,v 1.2 2003/03/22 23:44:36 max Exp $ 31*b06ebda0SMatthew Dillon * $FreeBSD: src/sys/netgraph/bluetooth/drivers/ubt/ng_ubt_var.h,v 1.7 2006/09/07 23:38:09 emax Exp $ 32*b06ebda0SMatthew Dillon */ 33*b06ebda0SMatthew Dillon 34*b06ebda0SMatthew Dillon #ifndef _NG_UBT_VAR_H_ 35*b06ebda0SMatthew Dillon #define _NG_UBT_VAR_H_ 36*b06ebda0SMatthew Dillon 37*b06ebda0SMatthew Dillon /* pullup wrapper */ 38*b06ebda0SMatthew Dillon #define NG_UBT_M_PULLUP(m, s) \ 39*b06ebda0SMatthew Dillon do { \ 40*b06ebda0SMatthew Dillon if ((m)->m_len < (s)) \ 41*b06ebda0SMatthew Dillon (m) = m_pullup((m), (s)); \ 42*b06ebda0SMatthew Dillon if ((m) == NULL) \ 43*b06ebda0SMatthew Dillon NG_UBT_ALERT("%s: %s - m_pullup(%d) failed\n", \ 44*b06ebda0SMatthew Dillon __func__, device_get_nameunit(sc->sc_dev), (s)); \ 45*b06ebda0SMatthew Dillon } while (0) 46*b06ebda0SMatthew Dillon 47*b06ebda0SMatthew Dillon /* Debug printf's */ 48*b06ebda0SMatthew Dillon #define NG_UBT_ALERT if (sc->sc_debug >= NG_UBT_ALERT_LEVEL) printf 49*b06ebda0SMatthew Dillon #define NG_UBT_ERR if (sc->sc_debug >= NG_UBT_ERR_LEVEL) printf 50*b06ebda0SMatthew Dillon #define NG_UBT_WARN if (sc->sc_debug >= NG_UBT_WARN_LEVEL) printf 51*b06ebda0SMatthew Dillon #define NG_UBT_INFO if (sc->sc_debug >= NG_UBT_INFO_LEVEL) printf 52*b06ebda0SMatthew Dillon 53*b06ebda0SMatthew Dillon /* Bluetooth USB control request type */ 54*b06ebda0SMatthew Dillon #define UBT_HCI_REQUEST 0x20 55*b06ebda0SMatthew Dillon #define UBT_DEFAULT_QLEN 12 56*b06ebda0SMatthew Dillon 57*b06ebda0SMatthew Dillon /* USB device softc structure */ 58*b06ebda0SMatthew Dillon struct ubt_softc { 59*b06ebda0SMatthew Dillon /* State */ 60*b06ebda0SMatthew Dillon ng_ubt_node_debug_ep sc_debug; /* debug level */ 61*b06ebda0SMatthew Dillon u_int32_t sc_flags; /* device flags */ 62*b06ebda0SMatthew Dillon #define UBT_NEED_FRAME_TYPE (1 << 0) /* device required frame type */ 63*b06ebda0SMatthew Dillon #define UBT_HAVE_FRAME_TYPE UBT_NEED_FRAME_TYPE 64*b06ebda0SMatthew Dillon #define UBT_CMD_XMIT (1 << 1) /* CMD xmit in progress */ 65*b06ebda0SMatthew Dillon #define UBT_ACL_XMIT (1 << 2) /* ACL xmit in progress */ 66*b06ebda0SMatthew Dillon #define UBT_SCO_XMIT (1 << 3) /* SCO xmit in progress */ 67*b06ebda0SMatthew Dillon #define UBT_EVT_RECV (1 << 4) /* EVN recv in progress */ 68*b06ebda0SMatthew Dillon #define UBT_ACL_RECV (1 << 5) /* ACL recv in progress */ 69*b06ebda0SMatthew Dillon #define UBT_SCO_RECV (1 << 6) /* SCO recv in progress */ 70*b06ebda0SMatthew Dillon #define UBT_CTRL_DEV (1 << 7) /* ctrl device is open */ 71*b06ebda0SMatthew Dillon #define UBT_INTR_DEV (1 << 8) /* intr device is open */ 72*b06ebda0SMatthew Dillon #define UBT_BULK_DEV (1 << 9) /* bulk device is open */ 73*b06ebda0SMatthew Dillon #define UBT_ANY_DEV (UBT_CTRL_DEV|UBT_INTR_DEV|UBT_BULK_DEV) 74*b06ebda0SMatthew Dillon 75*b06ebda0SMatthew Dillon ng_ubt_node_stat_ep sc_stat; /* statistic */ 76*b06ebda0SMatthew Dillon #define NG_UBT_STAT_PCKTS_SENT(s) (s).pckts_sent ++ 77*b06ebda0SMatthew Dillon #define NG_UBT_STAT_BYTES_SENT(s, n) (s).bytes_sent += (n) 78*b06ebda0SMatthew Dillon #define NG_UBT_STAT_PCKTS_RECV(s) (s).pckts_recv ++ 79*b06ebda0SMatthew Dillon #define NG_UBT_STAT_BYTES_RECV(s, n) (s).bytes_recv += (n) 80*b06ebda0SMatthew Dillon #define NG_UBT_STAT_OERROR(s) (s).oerrors ++ 81*b06ebda0SMatthew Dillon #define NG_UBT_STAT_IERROR(s) (s).ierrors ++ 82*b06ebda0SMatthew Dillon #define NG_UBT_STAT_RESET(s) bzero(&(s), sizeof((s))) 83*b06ebda0SMatthew Dillon 84*b06ebda0SMatthew Dillon /* USB device specific */ 85*b06ebda0SMatthew Dillon device_t sc_dev; /* pointer back to USB device */ 86*b06ebda0SMatthew Dillon usbd_device_handle sc_udev; /* USB device handle */ 87*b06ebda0SMatthew Dillon 88*b06ebda0SMatthew Dillon usbd_interface_handle sc_iface0; /* USB interface 0 */ 89*b06ebda0SMatthew Dillon usbd_interface_handle sc_iface1; /* USB interface 1 */ 90*b06ebda0SMatthew Dillon 91*b06ebda0SMatthew Dillon /* Interrupt pipe (HCI events) */ 92*b06ebda0SMatthew Dillon int sc_intr_ep; /* interrupt endpoint */ 93*b06ebda0SMatthew Dillon usbd_pipe_handle sc_intr_pipe; /* interrupt pipe handle */ 94*b06ebda0SMatthew Dillon usbd_xfer_handle sc_intr_xfer; /* intr xfer */ 95*b06ebda0SMatthew Dillon struct mbuf *sc_intr_buffer; /* interrupt buffer */ 96*b06ebda0SMatthew Dillon 97*b06ebda0SMatthew Dillon /* Control pipe (HCI commands) */ 98*b06ebda0SMatthew Dillon usbd_xfer_handle sc_ctrl_xfer; /* control xfer handle */ 99*b06ebda0SMatthew Dillon void *sc_ctrl_buffer; /* control buffer */ 100*b06ebda0SMatthew Dillon struct ng_bt_mbufq sc_cmdq; /* HCI command queue */ 101*b06ebda0SMatthew Dillon #define UBT_CTRL_BUFFER_SIZE \ 102*b06ebda0SMatthew Dillon (sizeof(ng_hci_cmd_pkt_t) + NG_HCI_CMD_PKT_SIZE) 103*b06ebda0SMatthew Dillon 104*b06ebda0SMatthew Dillon /* Bulk in pipe (ACL data) */ 105*b06ebda0SMatthew Dillon int sc_bulk_in_ep; /* bulk-in enpoint */ 106*b06ebda0SMatthew Dillon usbd_pipe_handle sc_bulk_in_pipe; /* bulk-in pipe */ 107*b06ebda0SMatthew Dillon usbd_xfer_handle sc_bulk_in_xfer; /* bulk-in xfer */ 108*b06ebda0SMatthew Dillon struct mbuf *sc_bulk_in_buffer; /* bulk-in buffer */ 109*b06ebda0SMatthew Dillon 110*b06ebda0SMatthew Dillon /* Bulk out pipe (ACL data) */ 111*b06ebda0SMatthew Dillon int sc_bulk_out_ep; /* bulk-out endpoint */ 112*b06ebda0SMatthew Dillon usbd_pipe_handle sc_bulk_out_pipe; /* bulk-out pipe */ 113*b06ebda0SMatthew Dillon usbd_xfer_handle sc_bulk_out_xfer; /* bulk-out xfer */ 114*b06ebda0SMatthew Dillon void *sc_bulk_out_buffer; /* bulk-out buffer */ 115*b06ebda0SMatthew Dillon struct ng_bt_mbufq sc_aclq; /* ACL data queue */ 116*b06ebda0SMatthew Dillon #define UBT_BULK_BUFFER_SIZE \ 117*b06ebda0SMatthew Dillon MCLBYTES /* XXX should be big enough to hold one frame */ 118*b06ebda0SMatthew Dillon 119*b06ebda0SMatthew Dillon /* Isoc. in pipe (SCO data) */ 120*b06ebda0SMatthew Dillon int sc_isoc_in_ep; /* isoc-in endpoint */ 121*b06ebda0SMatthew Dillon usbd_pipe_handle sc_isoc_in_pipe; /* isoc-in pipe */ 122*b06ebda0SMatthew Dillon usbd_xfer_handle sc_isoc_in_xfer; /* isoc-in xfer */ 123*b06ebda0SMatthew Dillon void *sc_isoc_in_buffer; /* isoc-in buffer */ 124*b06ebda0SMatthew Dillon u_int16_t *sc_isoc_in_frlen; /* isoc-in. frame length */ 125*b06ebda0SMatthew Dillon 126*b06ebda0SMatthew Dillon /* Isoc. out pipe (ACL data) */ 127*b06ebda0SMatthew Dillon int sc_isoc_out_ep; /* isoc-out endpoint */ 128*b06ebda0SMatthew Dillon usbd_pipe_handle sc_isoc_out_pipe; /* isoc-out pipe */ 129*b06ebda0SMatthew Dillon usbd_xfer_handle sc_isoc_out_xfer; /* isoc-out xfer */ 130*b06ebda0SMatthew Dillon void *sc_isoc_out_buffer; /* isoc-in buffer */ 131*b06ebda0SMatthew Dillon u_int16_t *sc_isoc_out_frlen; /* isoc-out. frame length */ 132*b06ebda0SMatthew Dillon struct ng_bt_mbufq sc_scoq; /* SCO data queue */ 133*b06ebda0SMatthew Dillon 134*b06ebda0SMatthew Dillon int sc_isoc_size; /* max. size of isoc. packet */ 135*b06ebda0SMatthew Dillon u_int32_t sc_isoc_nframes; /* num. isoc. frames */ 136*b06ebda0SMatthew Dillon #define UBT_ISOC_BUFFER_SIZE \ 137*b06ebda0SMatthew Dillon (sizeof(ng_hci_scodata_pkt_t) + NG_HCI_SCO_PKT_SIZE) 138*b06ebda0SMatthew Dillon 139*b06ebda0SMatthew Dillon /* Netgraph specific */ 140*b06ebda0SMatthew Dillon node_p sc_node; /* pointer back to node */ 141*b06ebda0SMatthew Dillon hook_p sc_hook; /* upstream hook */ 142*b06ebda0SMatthew Dillon }; 143*b06ebda0SMatthew Dillon typedef struct ubt_softc ubt_softc_t; 144*b06ebda0SMatthew Dillon typedef struct ubt_softc * ubt_softc_p; 145*b06ebda0SMatthew Dillon 146*b06ebda0SMatthew Dillon #endif /* ndef _NG_UBT_VAR_H_ */ 147*b06ebda0SMatthew Dillon 148