Path: blob/main/sys/netgraph/bluetooth/drivers/ubt/ng_ubt_var.h
35065 views
/*1* ng_ubt_var.h2*/34/*-5* SPDX-License-Identifier: BSD-2-Clause6*7* Copyright (c) 2001-2009 Maksim Yevmenkin <[email protected]>8* All rights reserved.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18*19* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE23* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*31* $Id: ng_ubt_var.h,v 1.2 2003/03/22 23:44:36 max Exp $32*/3334#ifndef _NG_UBT_VAR_H_35#define _NG_UBT_VAR_H_ 13637/* Debug printf's */38#define UBT_DEBUG(level, sc, fmt, ...) \39do { \40if ((sc)->sc_debug >= (level)) \41device_printf((sc)->sc_dev, "%s:%d: " fmt, \42__FUNCTION__, __LINE__,## __VA_ARGS__); \43} while (0)4445#define UBT_ALERT(...) UBT_DEBUG(NG_UBT_ALERT_LEVEL, __VA_ARGS__)46#define UBT_ERR(...) UBT_DEBUG(NG_UBT_ERR_LEVEL, __VA_ARGS__)47#define UBT_WARN(...) UBT_DEBUG(NG_UBT_WARN_LEVEL, __VA_ARGS__)48#define UBT_INFO(...) UBT_DEBUG(NG_UBT_INFO_LEVEL, __VA_ARGS__)4950#define UBT_NG_LOCK(sc) mtx_lock(&(sc)->sc_ng_mtx)51#define UBT_NG_UNLOCK(sc) mtx_unlock(&(sc)->sc_ng_mtx)5253/* Bluetooth USB control request type */54#define UBT_HCI_REQUEST 0x2055#define UBT_DEFAULT_QLEN 6456#define UBT_ISOC_NFRAMES 32 /* should be factor of 8 */5758/* Bluetooth USB defines */59enum {60/* Interface #0 transfers */61UBT_IF_0_BULK_DT_WR = 0,62UBT_IF_0_BULK_DT_RD,63UBT_IF_0_INTR_DT_RD,64UBT_IF_0_CTRL_DT_WR,6566/* Interface #1 transfers */67UBT_IF_1_ISOC_DT_RD1,68UBT_IF_1_ISOC_DT_RD2,69UBT_IF_1_ISOC_DT_WR1,70UBT_IF_1_ISOC_DT_WR2,7172UBT_N_TRANSFER, /* total number of transfers */73};7475/* USB control request (HCI command) structure */76struct ubt_hci_cmd {77uint16_t opcode;78uint8_t length;79uint8_t data[];80} __attribute__ ((packed));81#define UBT_HCI_CMD_SIZE(cmd) \82((cmd)->length + offsetof(struct ubt_hci_cmd, data))8384/* USB interrupt transfer HCI event header structure */85struct ubt_hci_evhdr {86uint8_t event;87uint8_t length;88} __attribute__ ((packed));89/* USB interrupt transfer (generic HCI event) structure */90struct ubt_hci_event {91struct ubt_hci_evhdr header;92uint8_t data[];93} __attribute__ ((packed));94/* USB interrupt transfer (HCI command completion event) structure */95struct ubt_hci_event_command_compl {96struct ubt_hci_evhdr header;97uint8_t numpkt;98uint16_t opcode;99uint8_t data[];100} __attribute__ ((packed));101#define UBT_HCI_EVENT_SIZE(evt) \102((evt)->header.length + offsetof(struct ubt_hci_event, data))103#define UBT_HCI_EVENT_COMPL_HEAD_SIZE \104(offsetof(struct ubt_hci_event_command_compl, data) - \105offsetof(struct ubt_hci_event_command_compl, numpkt))106107108/* USB device softc structure */109struct ubt_softc {110device_t sc_dev; /* for debug printf */111112/* State */113ng_ubt_node_debug_ep sc_debug; /* debug level */114115ng_ubt_node_stat_ep sc_stat; /* statistic */116#define UBT_STAT_PCKTS_SENT(sc) (sc)->sc_stat.pckts_sent ++117#define UBT_STAT_BYTES_SENT(sc, n) (sc)->sc_stat.bytes_sent += (n)118#define UBT_STAT_PCKTS_RECV(sc) (sc)->sc_stat.pckts_recv ++119#define UBT_STAT_BYTES_RECV(sc, n) (sc)->sc_stat.bytes_recv += (n)120#define UBT_STAT_OERROR(sc) (sc)->sc_stat.oerrors ++121#define UBT_STAT_IERROR(sc) (sc)->sc_stat.ierrors ++122#define UBT_STAT_RESET(sc) bzero(&(sc)->sc_stat, sizeof((sc)->sc_stat))123124/* USB device specific */125struct mtx sc_if_mtx; /* interfaces lock */126struct usb_xfer *sc_xfer[UBT_N_TRANSFER];127128struct mtx sc_ng_mtx; /* lock for shared NG data */129130/* HCI commands */131struct ng_bt_mbufq sc_cmdq; /* HCI command queue */132#define UBT_CTRL_BUFFER_SIZE (sizeof(struct usb_device_request) + \133sizeof(ng_hci_cmd_pkt_t) + NG_HCI_CMD_PKT_SIZE)134#define UBT_INTR_BUFFER_SIZE (MCLBYTES-1) /* reserve 1 byte for ID-tag */135136/* ACL data */137struct ng_bt_mbufq sc_aclq; /* ACL data queue */138#define UBT_BULK_READ_BUFFER_SIZE (MCLBYTES-1) /* reserve 1 byte for ID-tag */139#define UBT_BULK_WRITE_BUFFER_SIZE (MCLBYTES)140141/* SCO data */142struct ng_bt_mbufq sc_scoq; /* SCO data queue */143struct mbuf *sc_isoc_in_buffer; /* SCO reassembly buffer */144145/* Netgraph specific */146node_p sc_node; /* pointer back to node */147hook_p sc_hook; /* upstream hook */148149/* Glue */150int sc_task_flags; /* task flags */151#define UBT_FLAG_T_PENDING (1 << 0) /* task pending */152#define UBT_FLAG_T_STOP_ALL (1 << 1) /* stop all xfers */153#define UBT_FLAG_T_START_ALL (1 << 2) /* start all read and isoc154write xfers */155#define UBT_FLAG_T_START_CTRL (1 << 3) /* start control xfer (write) */156#define UBT_FLAG_T_START_BULK (1 << 4) /* start bulk xfer (write) */157158struct task sc_task;159};160typedef struct ubt_softc ubt_softc_t;161typedef struct ubt_softc * ubt_softc_p;162163usb_error_t ubt_do_hci_request(struct usb_device *, struct ubt_hci_cmd *,164void *, usb_timeout_t);165166extern const STRUCT_USB_HOST_ID ubt_rtl_devs[];167extern const size_t ubt_rtl_devs_sizeof;168169extern driver_t ubt_driver;170171#endif /* ndef _NG_UBT_VAR_H_ */172173174