184c5da4cSAndrew Thompson /* 284c5da4cSAndrew Thompson * ng_ubt_var.h 384c5da4cSAndrew Thompson */ 484c5da4cSAndrew Thompson 584c5da4cSAndrew Thompson /*- 64d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 7fe267a55SPedro F. Giffuni * 884c5da4cSAndrew Thompson * Copyright (c) 2001-2009 Maksim Yevmenkin <m_evmenkin@yahoo.com> 984c5da4cSAndrew Thompson * All rights reserved. 1084c5da4cSAndrew Thompson * 1184c5da4cSAndrew Thompson * Redistribution and use in source and binary forms, with or without 1284c5da4cSAndrew Thompson * modification, are permitted provided that the following conditions 1384c5da4cSAndrew Thompson * are met: 1484c5da4cSAndrew Thompson * 1. Redistributions of source code must retain the above copyright 1584c5da4cSAndrew Thompson * notice, this list of conditions and the following disclaimer. 1684c5da4cSAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1784c5da4cSAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1884c5da4cSAndrew Thompson * documentation and/or other materials provided with the distribution. 1984c5da4cSAndrew Thompson * 2084c5da4cSAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2184c5da4cSAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2284c5da4cSAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2384c5da4cSAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2484c5da4cSAndrew Thompson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2584c5da4cSAndrew Thompson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2684c5da4cSAndrew Thompson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2784c5da4cSAndrew Thompson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2884c5da4cSAndrew Thompson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2984c5da4cSAndrew Thompson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3084c5da4cSAndrew Thompson * SUCH DAMAGE. 3184c5da4cSAndrew Thompson * 3284c5da4cSAndrew Thompson * $Id: ng_ubt_var.h,v 1.2 2003/03/22 23:44:36 max Exp $ 3384c5da4cSAndrew Thompson */ 3484c5da4cSAndrew Thompson 3584c5da4cSAndrew Thompson #ifndef _NG_UBT_VAR_H_ 3684c5da4cSAndrew Thompson #define _NG_UBT_VAR_H_ 1 3784c5da4cSAndrew Thompson 3884c5da4cSAndrew Thompson /* Debug printf's */ 3984c5da4cSAndrew Thompson #define UBT_DEBUG(level, sc, fmt, ...) \ 4084c5da4cSAndrew Thompson do { \ 4184c5da4cSAndrew Thompson if ((sc)->sc_debug >= (level)) \ 4284c5da4cSAndrew Thompson device_printf((sc)->sc_dev, "%s:%d: " fmt, \ 4384c5da4cSAndrew Thompson __FUNCTION__, __LINE__,## __VA_ARGS__); \ 4484c5da4cSAndrew Thompson } while (0) 4584c5da4cSAndrew Thompson 4684c5da4cSAndrew Thompson #define UBT_ALERT(...) UBT_DEBUG(NG_UBT_ALERT_LEVEL, __VA_ARGS__) 4784c5da4cSAndrew Thompson #define UBT_ERR(...) UBT_DEBUG(NG_UBT_ERR_LEVEL, __VA_ARGS__) 4884c5da4cSAndrew Thompson #define UBT_WARN(...) UBT_DEBUG(NG_UBT_WARN_LEVEL, __VA_ARGS__) 4984c5da4cSAndrew Thompson #define UBT_INFO(...) UBT_DEBUG(NG_UBT_INFO_LEVEL, __VA_ARGS__) 5084c5da4cSAndrew Thompson 5184c5da4cSAndrew Thompson #define UBT_NG_LOCK(sc) mtx_lock(&(sc)->sc_ng_mtx) 5284c5da4cSAndrew Thompson #define UBT_NG_UNLOCK(sc) mtx_unlock(&(sc)->sc_ng_mtx) 5384c5da4cSAndrew Thompson 5484c5da4cSAndrew Thompson /* Bluetooth USB control request type */ 5584c5da4cSAndrew Thompson #define UBT_HCI_REQUEST 0x20 5684c5da4cSAndrew Thompson #define UBT_DEFAULT_QLEN 64 5784c5da4cSAndrew Thompson #define UBT_ISOC_NFRAMES 32 /* should be factor of 8 */ 5884c5da4cSAndrew Thompson 5984c5da4cSAndrew Thompson /* Bluetooth USB defines */ 6084c5da4cSAndrew Thompson enum { 6184c5da4cSAndrew Thompson /* Interface #0 transfers */ 6284c5da4cSAndrew Thompson UBT_IF_0_BULK_DT_WR = 0, 6384c5da4cSAndrew Thompson UBT_IF_0_BULK_DT_RD, 6484c5da4cSAndrew Thompson UBT_IF_0_INTR_DT_RD, 6584c5da4cSAndrew Thompson UBT_IF_0_CTRL_DT_WR, 6684c5da4cSAndrew Thompson 6784c5da4cSAndrew Thompson /* Interface #1 transfers */ 6884c5da4cSAndrew Thompson UBT_IF_1_ISOC_DT_RD1, 6984c5da4cSAndrew Thompson UBT_IF_1_ISOC_DT_RD2, 7084c5da4cSAndrew Thompson UBT_IF_1_ISOC_DT_WR1, 7184c5da4cSAndrew Thompson UBT_IF_1_ISOC_DT_WR2, 7284c5da4cSAndrew Thompson 7384c5da4cSAndrew Thompson UBT_N_TRANSFER, /* total number of transfers */ 7484c5da4cSAndrew Thompson }; 7584c5da4cSAndrew Thompson 763544d43bSVladimir Kondratyev /* USB control request (HCI command) structure */ 773544d43bSVladimir Kondratyev struct ubt_hci_cmd { 783544d43bSVladimir Kondratyev uint16_t opcode; 793544d43bSVladimir Kondratyev uint8_t length; 803544d43bSVladimir Kondratyev uint8_t data[]; 813544d43bSVladimir Kondratyev } __attribute__ ((packed)); 823544d43bSVladimir Kondratyev #define UBT_HCI_CMD_SIZE(cmd) \ 833544d43bSVladimir Kondratyev ((cmd)->length + offsetof(struct ubt_hci_cmd, data)) 843544d43bSVladimir Kondratyev 853544d43bSVladimir Kondratyev /* USB interrupt transfer HCI event header structure */ 863544d43bSVladimir Kondratyev struct ubt_hci_evhdr { 873544d43bSVladimir Kondratyev uint8_t event; 883544d43bSVladimir Kondratyev uint8_t length; 893544d43bSVladimir Kondratyev } __attribute__ ((packed)); 903544d43bSVladimir Kondratyev /* USB interrupt transfer (generic HCI event) structure */ 913544d43bSVladimir Kondratyev struct ubt_hci_event { 923544d43bSVladimir Kondratyev struct ubt_hci_evhdr header; 933544d43bSVladimir Kondratyev uint8_t data[]; 943544d43bSVladimir Kondratyev } __attribute__ ((packed)); 953544d43bSVladimir Kondratyev /* USB interrupt transfer (HCI command completion event) structure */ 963544d43bSVladimir Kondratyev struct ubt_hci_event_command_compl { 973544d43bSVladimir Kondratyev struct ubt_hci_evhdr header; 983544d43bSVladimir Kondratyev uint8_t numpkt; 993544d43bSVladimir Kondratyev uint16_t opcode; 1003544d43bSVladimir Kondratyev uint8_t data[]; 1013544d43bSVladimir Kondratyev } __attribute__ ((packed)); 1023544d43bSVladimir Kondratyev #define UBT_HCI_EVENT_SIZE(evt) \ 1033544d43bSVladimir Kondratyev ((evt)->header.length + offsetof(struct ubt_hci_event, data)) 104788a171cSVladimir Kondratyev #define UBT_HCI_EVENT_COMPL_HEAD_SIZE \ 105788a171cSVladimir Kondratyev (offsetof(struct ubt_hci_event_command_compl, data) - \ 106788a171cSVladimir Kondratyev offsetof(struct ubt_hci_event_command_compl, numpkt)) 107788a171cSVladimir Kondratyev 1083544d43bSVladimir Kondratyev 10984c5da4cSAndrew Thompson /* USB device softc structure */ 11084c5da4cSAndrew Thompson struct ubt_softc { 11184c5da4cSAndrew Thompson device_t sc_dev; /* for debug printf */ 11284c5da4cSAndrew Thompson 11384c5da4cSAndrew Thompson /* State */ 11484c5da4cSAndrew Thompson ng_ubt_node_debug_ep sc_debug; /* debug level */ 11584c5da4cSAndrew Thompson 11684c5da4cSAndrew Thompson ng_ubt_node_stat_ep sc_stat; /* statistic */ 11784c5da4cSAndrew Thompson #define UBT_STAT_PCKTS_SENT(sc) (sc)->sc_stat.pckts_sent ++ 11884c5da4cSAndrew Thompson #define UBT_STAT_BYTES_SENT(sc, n) (sc)->sc_stat.bytes_sent += (n) 11984c5da4cSAndrew Thompson #define UBT_STAT_PCKTS_RECV(sc) (sc)->sc_stat.pckts_recv ++ 12084c5da4cSAndrew Thompson #define UBT_STAT_BYTES_RECV(sc, n) (sc)->sc_stat.bytes_recv += (n) 12184c5da4cSAndrew Thompson #define UBT_STAT_OERROR(sc) (sc)->sc_stat.oerrors ++ 12284c5da4cSAndrew Thompson #define UBT_STAT_IERROR(sc) (sc)->sc_stat.ierrors ++ 12384c5da4cSAndrew Thompson #define UBT_STAT_RESET(sc) bzero(&(sc)->sc_stat, sizeof((sc)->sc_stat)) 12484c5da4cSAndrew Thompson 12584c5da4cSAndrew Thompson /* USB device specific */ 12684c5da4cSAndrew Thompson struct mtx sc_if_mtx; /* interfaces lock */ 127760bc48eSAndrew Thompson struct usb_xfer *sc_xfer[UBT_N_TRANSFER]; 12884c5da4cSAndrew Thompson 12984c5da4cSAndrew Thompson struct mtx sc_ng_mtx; /* lock for shared NG data */ 13084c5da4cSAndrew Thompson 13184c5da4cSAndrew Thompson /* HCI commands */ 13284c5da4cSAndrew Thompson struct ng_bt_mbufq sc_cmdq; /* HCI command queue */ 133760bc48eSAndrew Thompson #define UBT_CTRL_BUFFER_SIZE (sizeof(struct usb_device_request) + \ 13484c5da4cSAndrew Thompson sizeof(ng_hci_cmd_pkt_t) + NG_HCI_CMD_PKT_SIZE) 13584c5da4cSAndrew Thompson #define UBT_INTR_BUFFER_SIZE (MCLBYTES-1) /* reserve 1 byte for ID-tag */ 13684c5da4cSAndrew Thompson 13784c5da4cSAndrew Thompson /* ACL data */ 13884c5da4cSAndrew Thompson struct ng_bt_mbufq sc_aclq; /* ACL data queue */ 13984c5da4cSAndrew Thompson #define UBT_BULK_READ_BUFFER_SIZE (MCLBYTES-1) /* reserve 1 byte for ID-tag */ 14084c5da4cSAndrew Thompson #define UBT_BULK_WRITE_BUFFER_SIZE (MCLBYTES) 14184c5da4cSAndrew Thompson 14284c5da4cSAndrew Thompson /* SCO data */ 14384c5da4cSAndrew Thompson struct ng_bt_mbufq sc_scoq; /* SCO data queue */ 14484c5da4cSAndrew Thompson struct mbuf *sc_isoc_in_buffer; /* SCO reassembly buffer */ 14584c5da4cSAndrew Thompson 14684c5da4cSAndrew Thompson /* Netgraph specific */ 14784c5da4cSAndrew Thompson node_p sc_node; /* pointer back to node */ 14884c5da4cSAndrew Thompson hook_p sc_hook; /* upstream hook */ 14984c5da4cSAndrew Thompson 15084c5da4cSAndrew Thompson /* Glue */ 15184c5da4cSAndrew Thompson int sc_task_flags; /* task flags */ 15284c5da4cSAndrew Thompson #define UBT_FLAG_T_PENDING (1 << 0) /* task pending */ 15384c5da4cSAndrew Thompson #define UBT_FLAG_T_STOP_ALL (1 << 1) /* stop all xfers */ 15484c5da4cSAndrew Thompson #define UBT_FLAG_T_START_ALL (1 << 2) /* start all read and isoc 15584c5da4cSAndrew Thompson write xfers */ 15684c5da4cSAndrew Thompson #define UBT_FLAG_T_START_CTRL (1 << 3) /* start control xfer (write) */ 15784c5da4cSAndrew Thompson #define UBT_FLAG_T_START_BULK (1 << 4) /* start bulk xfer (write) */ 15884c5da4cSAndrew Thompson 15984c5da4cSAndrew Thompson struct task sc_task; 16084c5da4cSAndrew Thompson }; 16184c5da4cSAndrew Thompson typedef struct ubt_softc ubt_softc_t; 16284c5da4cSAndrew Thompson typedef struct ubt_softc * ubt_softc_p; 16384c5da4cSAndrew Thompson 1643544d43bSVladimir Kondratyev usb_error_t ubt_do_hci_request(struct usb_device *, struct ubt_hci_cmd *, 1653544d43bSVladimir Kondratyev void *, usb_timeout_t); 1663544d43bSVladimir Kondratyev 167*24ae172aSVladimir Kondratyev extern const STRUCT_USB_HOST_ID ubt_rtl_devs[]; 168*24ae172aSVladimir Kondratyev extern const size_t ubt_rtl_devs_sizeof; 169*24ae172aSVladimir Kondratyev 1703544d43bSVladimir Kondratyev extern driver_t ubt_driver; 1713544d43bSVladimir Kondratyev 17284c5da4cSAndrew Thompson #endif /* ndef _NG_UBT_VAR_H_ */ 173