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