1184610Salfred/* 2184610Salfred * ng_ubt_var.h 3184610Salfred */ 4184610Salfred 5184610Salfred/*- 6187494Semax * Copyright (c) 2001-2009 Maksim Yevmenkin <m_evmenkin@yahoo.com> 7184610Salfred * All rights reserved. 8184610Salfred * 9184610Salfred * Redistribution and use in source and binary forms, with or without 10184610Salfred * modification, are permitted provided that the following conditions 11184610Salfred * are met: 12184610Salfred * 1. Redistributions of source code must retain the above copyright 13184610Salfred * notice, this list of conditions and the following disclaimer. 14184610Salfred * 2. Redistributions in binary form must reproduce the above copyright 15184610Salfred * notice, this list of conditions and the following disclaimer in the 16184610Salfred * documentation and/or other materials provided with the distribution. 17184610Salfred * 18184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21184610Salfred * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28184610Salfred * SUCH DAMAGE. 29184610Salfred * 30184610Salfred * $Id: ng_ubt_var.h,v 1.2 2003/03/22 23:44:36 max Exp $ 31184610Salfred * $FreeBSD$ 32184610Salfred */ 33184610Salfred 34184610Salfred#ifndef _NG_UBT_VAR_H_ 35187494Semax#define _NG_UBT_VAR_H_ 1 36184610Salfred 37184610Salfred/* Debug printf's */ 38187494Semax#define UBT_DEBUG(level, sc, fmt, ...) \ 39187494Semaxdo { \ 40187494Semax if ((sc)->sc_debug >= (level)) \ 41187741Semax device_printf((sc)->sc_dev, "%s:%d: " fmt, \ 42187494Semax __FUNCTION__, __LINE__,## __VA_ARGS__); \ 43184610Salfred} while (0) 44184610Salfred 45187494Semax#define UBT_ALERT(...) UBT_DEBUG(NG_UBT_ALERT_LEVEL, __VA_ARGS__) 46187494Semax#define UBT_ERR(...) UBT_DEBUG(NG_UBT_ERR_LEVEL, __VA_ARGS__) 47187494Semax#define UBT_WARN(...) UBT_DEBUG(NG_UBT_WARN_LEVEL, __VA_ARGS__) 48187494Semax#define UBT_INFO(...) UBT_DEBUG(NG_UBT_INFO_LEVEL, __VA_ARGS__) 49184610Salfred 50187741Semax#define UBT_NG_LOCK(sc) mtx_lock(&(sc)->sc_ng_mtx) 51187741Semax#define UBT_NG_UNLOCK(sc) mtx_unlock(&(sc)->sc_ng_mtx) 52187494Semax 53184610Salfred/* Bluetooth USB control request type */ 54184610Salfred#define UBT_HCI_REQUEST 0x20 55187494Semax#define UBT_DEFAULT_QLEN 64 56187494Semax#define UBT_ISOC_NFRAMES 32 /* should be factor of 8 */ 57184610Salfred 58184610Salfred/* Bluetooth USB defines */ 59187494Semaxenum { 60187494Semax /* Interface #0 transfers */ 61187494Semax UBT_IF_0_BULK_DT_WR = 0, 62187494Semax UBT_IF_0_BULK_DT_RD, 63187494Semax UBT_IF_0_INTR_DT_RD, 64187494Semax UBT_IF_0_CTRL_DT_WR, 65187494Semax 66187494Semax /* Interface #1 transfers */ 67187741Semax UBT_IF_1_ISOC_DT_RD1, 68187494Semax UBT_IF_1_ISOC_DT_RD2, 69187494Semax UBT_IF_1_ISOC_DT_WR1, 70187494Semax UBT_IF_1_ISOC_DT_WR2, 71184610Salfred 72187494Semax UBT_N_TRANSFER, /* total number of transfers */ 73187494Semax}; 74187494Semax 75184610Salfred/* USB device softc structure */ 76184610Salfredstruct ubt_softc { 77187741Semax device_t sc_dev; /* for debug printf */ 78187494Semax 79184610Salfred /* State */ 80187494Semax ng_ubt_node_debug_ep sc_debug; /* debug level */ 81184610Salfred 82187494Semax ng_ubt_node_stat_ep sc_stat; /* statistic */ 83187494Semax#define UBT_STAT_PCKTS_SENT(sc) (sc)->sc_stat.pckts_sent ++ 84187494Semax#define UBT_STAT_BYTES_SENT(sc, n) (sc)->sc_stat.bytes_sent += (n) 85187494Semax#define UBT_STAT_PCKTS_RECV(sc) (sc)->sc_stat.pckts_recv ++ 86187494Semax#define UBT_STAT_BYTES_RECV(sc, n) (sc)->sc_stat.bytes_recv += (n) 87187494Semax#define UBT_STAT_OERROR(sc) (sc)->sc_stat.oerrors ++ 88187494Semax#define UBT_STAT_IERROR(sc) (sc)->sc_stat.ierrors ++ 89187494Semax#define UBT_STAT_RESET(sc) bzero(&(sc)->sc_stat, sizeof((sc)->sc_stat)) 90184610Salfred 91184610Salfred /* USB device specific */ 92187741Semax struct mtx sc_if_mtx; /* interfaces lock */ 93192984Sthompsa struct usb_xfer *sc_xfer[UBT_N_TRANSFER]; 94184610Salfred 95187741Semax struct mtx sc_ng_mtx; /* lock for shared NG data */ 96184610Salfred 97187494Semax /* HCI commands */ 98187494Semax struct ng_bt_mbufq sc_cmdq; /* HCI command queue */ 99192984Sthompsa#define UBT_CTRL_BUFFER_SIZE (sizeof(struct usb_device_request) + \ 100187494Semax sizeof(ng_hci_cmd_pkt_t) + NG_HCI_CMD_PKT_SIZE) 101187494Semax#define UBT_INTR_BUFFER_SIZE (MCLBYTES-1) /* reserve 1 byte for ID-tag */ 102184610Salfred 103187494Semax /* ACL data */ 104187494Semax struct ng_bt_mbufq sc_aclq; /* ACL data queue */ 105187494Semax#define UBT_BULK_READ_BUFFER_SIZE (MCLBYTES-1) /* reserve 1 byte for ID-tag */ 106184610Salfred#define UBT_BULK_WRITE_BUFFER_SIZE (MCLBYTES) 107184610Salfred 108187494Semax /* SCO data */ 109187494Semax struct ng_bt_mbufq sc_scoq; /* SCO data queue */ 110187494Semax struct mbuf *sc_isoc_in_buffer; /* SCO reassembly buffer */ 111184610Salfred 112187494Semax /* Netgraph specific */ 113187494Semax node_p sc_node; /* pointer back to node */ 114187494Semax hook_p sc_hook; /* upstream hook */ 115184610Salfred 116187494Semax /* Glue */ 117187494Semax int sc_task_flags; /* task flags */ 118187494Semax#define UBT_FLAG_T_PENDING (1 << 0) /* task pending */ 119187494Semax#define UBT_FLAG_T_STOP_ALL (1 << 1) /* stop all xfers */ 120187494Semax#define UBT_FLAG_T_START_ALL (1 << 2) /* start all read and isoc 121187494Semax write xfers */ 122187494Semax#define UBT_FLAG_T_START_CTRL (1 << 3) /* start control xfer (write) */ 123187494Semax#define UBT_FLAG_T_START_BULK (1 << 4) /* start bulk xfer (write) */ 124187494Semax 125187494Semax struct task sc_task; 126184610Salfred}; 127187494Semaxtypedef struct ubt_softc ubt_softc_t; 128187494Semaxtypedef struct ubt_softc * ubt_softc_p; 129184610Salfred 130187494Semax#endif /* ndef _NG_UBT_VAR_H_ */ 131187494Semax 132