FreeBSD kernel netgraph code
ng_ubt_var.h
Go to the documentation of this file.
1/*
2 * ng_ubt_var.h
3 */
4
5/*-
6 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
7 *
8 * Copyright (c) 2001-2009 Maksim Yevmenkin <m_evmenkin@yahoo.com>
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $Id: ng_ubt_var.h,v 1.2 2003/03/22 23:44:36 max Exp $
33 * $FreeBSD$
34 */
35
36#ifndef _NG_UBT_VAR_H_
37#define _NG_UBT_VAR_H_ 1
38
39/* Debug printf's */
40#define UBT_DEBUG(level, sc, fmt, ...) \
41do { \
42 if ((sc)->sc_debug >= (level)) \
43 device_printf((sc)->sc_dev, "%s:%d: " fmt, \
44 __FUNCTION__, __LINE__,## __VA_ARGS__); \
45} while (0)
46
47#define UBT_ALERT(...) UBT_DEBUG(NG_UBT_ALERT_LEVEL, __VA_ARGS__)
48#define UBT_ERR(...) UBT_DEBUG(NG_UBT_ERR_LEVEL, __VA_ARGS__)
49#define UBT_WARN(...) UBT_DEBUG(NG_UBT_WARN_LEVEL, __VA_ARGS__)
50#define UBT_INFO(...) UBT_DEBUG(NG_UBT_INFO_LEVEL, __VA_ARGS__)
51
52#define UBT_NG_LOCK(sc) mtx_lock(&(sc)->sc_ng_mtx)
53#define UBT_NG_UNLOCK(sc) mtx_unlock(&(sc)->sc_ng_mtx)
54
55/* Bluetooth USB control request type */
56#define UBT_HCI_REQUEST 0x20
57#define UBT_DEFAULT_QLEN 64
58#define UBT_ISOC_NFRAMES 32 /* should be factor of 8 */
59
60/* Bluetooth USB defines */
61enum {
62 /* Interface #0 transfers */
67
68 /* Interface #1 transfers */
73
74 UBT_N_TRANSFER, /* total number of transfers */
75};
76
77/* USB control request (HCI command) structure */
79 uint16_t opcode;
80 uint8_t length;
81 uint8_t data[];
82} __attribute__ ((packed));
83#define UBT_HCI_CMD_SIZE(cmd) \
84 ((cmd)->length + offsetof(struct ubt_hci_cmd, data))
85
86/* USB interrupt transfer HCI event header structure */
88 uint8_t event;
89 uint8_t length;
90} __attribute__ ((packed));
91/* USB interrupt transfer (generic HCI event) structure */
94 uint8_t data[];
95} __attribute__ ((packed));
96/* USB interrupt transfer (HCI command completion event) structure */
99 uint8_t numpkt;
100 uint16_t opcode;
101 uint8_t data[];
102} __attribute__ ((packed));
103#define UBT_HCI_EVENT_SIZE(evt) \
104 ((evt)->header.length + offsetof(struct ubt_hci_event, data))
105#define UBT_HCI_EVENT_COMPL_HEAD_SIZE \
106 (offsetof(struct ubt_hci_event_command_compl, data) - \
107 offsetof(struct ubt_hci_event_command_compl, numpkt))
108
109
110/* USB device softc structure */
111struct ubt_softc {
112 device_t sc_dev; /* for debug printf */
113
114 /* State */
116
118#define UBT_STAT_PCKTS_SENT(sc) (sc)->sc_stat.pckts_sent ++
119#define UBT_STAT_BYTES_SENT(sc, n) (sc)->sc_stat.bytes_sent += (n)
120#define UBT_STAT_PCKTS_RECV(sc) (sc)->sc_stat.pckts_recv ++
121#define UBT_STAT_BYTES_RECV(sc, n) (sc)->sc_stat.bytes_recv += (n)
122#define UBT_STAT_OERROR(sc) (sc)->sc_stat.oerrors ++
123#define UBT_STAT_IERROR(sc) (sc)->sc_stat.ierrors ++
124#define UBT_STAT_RESET(sc) bzero(&(sc)->sc_stat, sizeof((sc)->sc_stat))
125
126 /* USB device specific */
127 struct mtx sc_if_mtx; /* interfaces lock */
128 struct usb_xfer *sc_xfer[UBT_N_TRANSFER];
129
130 struct mtx sc_ng_mtx; /* lock for shared NG data */
131
132 /* HCI commands */
133 struct ng_bt_mbufq sc_cmdq; /* HCI command queue */
134#define UBT_CTRL_BUFFER_SIZE (sizeof(struct usb_device_request) + \
135 sizeof(ng_hci_cmd_pkt_t) + NG_HCI_CMD_PKT_SIZE)
136#define UBT_INTR_BUFFER_SIZE (MCLBYTES-1) /* reserve 1 byte for ID-tag */
137
138 /* ACL data */
139 struct ng_bt_mbufq sc_aclq; /* ACL data queue */
140#define UBT_BULK_READ_BUFFER_SIZE (MCLBYTES-1) /* reserve 1 byte for ID-tag */
141#define UBT_BULK_WRITE_BUFFER_SIZE (MCLBYTES)
142
143 /* SCO data */
144 struct ng_bt_mbufq sc_scoq; /* SCO data queue */
145 struct mbuf *sc_isoc_in_buffer; /* SCO reassembly buffer */
146
147 /* Netgraph specific */
148 node_p sc_node; /* pointer back to node */
149 hook_p sc_hook; /* upstream hook */
150
151 /* Glue */
152 int sc_task_flags; /* task flags */
153#define UBT_FLAG_T_PENDING (1 << 0) /* task pending */
154#define UBT_FLAG_T_STOP_ALL (1 << 1) /* stop all xfers */
155#define UBT_FLAG_T_START_ALL (1 << 2) /* start all read and isoc
156 write xfers */
157#define UBT_FLAG_T_START_CTRL (1 << 3) /* start control xfer (write) */
158#define UBT_FLAG_T_START_BULK (1 << 4) /* start bulk xfer (write) */
160 struct task sc_task;
162typedef struct ubt_softc ubt_softc_t;
163typedef struct ubt_softc * ubt_softc_p;
164
165usb_error_t ubt_do_hci_request(struct usb_device *, struct ubt_hci_cmd *,
166 void *, usb_timeout_t);
167
168extern devclass_t ubt_devclass;
169extern driver_t ubt_driver;
170
171#endif /* ndef _NG_UBT_VAR_H_ */
u_int16_t ng_ubt_node_debug_ep
Definition: ng_ubt.h:64
usb_error_t ubt_do_hci_request(struct usb_device *, struct ubt_hci_cmd *, void *, usb_timeout_t)
Definition: ng_ubt.c:539
devclass_t ubt_devclass
Definition: ng_ubt.c:1995
driver_t ubt_driver
Definition: ng_ubt.c:2005
@ UBT_IF_0_INTR_DT_RD
Definition: ng_ubt_var.h:65
@ UBT_IF_1_ISOC_DT_WR1
Definition: ng_ubt_var.h:71
@ UBT_IF_0_BULK_DT_WR
Definition: ng_ubt_var.h:63
@ UBT_IF_0_BULK_DT_RD
Definition: ng_ubt_var.h:64
@ UBT_IF_1_ISOC_DT_RD1
Definition: ng_ubt_var.h:69
@ UBT_N_TRANSFER
Definition: ng_ubt_var.h:74
@ UBT_IF_1_ISOC_DT_RD2
Definition: ng_ubt_var.h:70
@ UBT_IF_0_CTRL_DT_WR
Definition: ng_ubt_var.h:66
@ UBT_IF_1_ISOC_DT_WR2
Definition: ng_ubt_var.h:72
struct ubt_softc __attribute__
struct ubt_softc * ubt_softc_p
Definition: ng_ubt_var.h:162
uint8_t length
Definition: ng_ubt_var.h:80
uint16_t opcode
Definition: ng_ubt_var.h:79
uint8_t data[]
Definition: ng_ubt_var.h:81
struct ubt_hci_evhdr header
Definition: ng_ubt_var.h:98
uint8_t data[]
Definition: ng_ubt_var.h:94
struct ubt_hci_evhdr header
Definition: ng_ubt_var.h:93
uint8_t event
Definition: ng_ubt_var.h:88
uint8_t length
Definition: ng_ubt_var.h:89
struct task sc_task
Definition: ng_ubt_var.h:159
struct usb_xfer * sc_xfer[UBT_N_TRANSFER]
Definition: ng_ubt_var.h:128
struct ng_bt_mbufq sc_scoq
Definition: ng_ubt_var.h:144
ng_ubt_node_stat_ep sc_stat
Definition: ng_ubt_var.h:117
struct mtx sc_if_mtx
Definition: ng_ubt_var.h:127
ng_ubt_node_debug_ep sc_debug
Definition: ng_ubt_var.h:115
struct ng_bt_mbufq sc_cmdq
Definition: ng_ubt_var.h:133
struct mbuf * sc_isoc_in_buffer
Definition: ng_ubt_var.h:145
struct ng_bt_mbufq sc_aclq
Definition: ng_ubt_var.h:139
node_p sc_node
Definition: ng_ubt_var.h:148
struct mtx sc_ng_mtx
Definition: ng_ubt_var.h:130
int sc_task_flags
Definition: ng_ubt_var.h:152
device_t sc_dev
Definition: ng_ubt_var.h:112
hook_p sc_hook
Definition: ng_ubt_var.h:149