xref: /freebsd/sys/dev/usb/net/if_urndisreg.h (revision 9268022b74279434ed6300244e3f977e56a8ceb5)
1 /*	$FreeBSD$ */
2 /*	$OpenBSD: if_urndisreg.h,v 1.19 2013/11/21 14:08:05 mpi Exp $ */
3 
4 /*
5  * Copyright (c) 2010 Jonathan Armani <armani@openbsd.org>
6  * Copyright (c) 2010 Fabien Romano <fabien@openbsd.org>
7  * Copyright (c) 2010 Michael Knudsen <mk@openbsd.org>
8  * All rights reserved.
9  *
10  * Permission to use, copy, modify, and distribute this software for any
11  * purpose with or without fee is hereby granted, provided that the above
12  * copyright notice and this permission notice appear in all copies.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22 
23 #ifndef _IF_URNDISREG_H_
24 #define	_IF_URNDISREG_H_
25 
26 #define	RNDIS_RESPONSE_LEN	1024	/* bytes */
27 #define	RNDIS_RX_MAXLEN		(16 * 1024)
28 #define	RNDIS_TX_FRAMES_MAX	8
29 #define	RNDIS_TX_MAXLEN		MCLBYTES
30 
31 enum {
32 	URNDIS_BULK_RX,
33 	URNDIS_BULK_TX,
34 	URNDIS_INTR_RX,
35 	URNDIS_N_TRANSFER,
36 };
37 
38 struct urndis_softc {
39 
40 	struct usb_ether sc_ue;
41 	struct mtx sc_mtx;
42 
43 	/* RNDIS device info */
44 	uint32_t sc_lim_pktsz;
45 	uint32_t sc_filter;
46 
47 	struct usb_device *sc_udev;
48 	struct usb_xfer *sc_xfer[URNDIS_N_TRANSFER];
49 
50 	uint8_t	sc_ifaceno_ctl;
51 	uint8_t	sc_response_buf[RNDIS_RESPONSE_LEN] __aligned(4);
52 };
53 
54 #define	URNDIS_LOCK(sc) mtx_lock(&(sc)->sc_mtx)
55 #define	URNDIS_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx)
56 #define	URNDIS_LOCK_ASSERT(sc, what) mtx_assert(&(sc)->sc_mtx, (what))
57 
58 #define	RNDIS_STATUS_BUFFER_OVERFLOW 	0x80000005L
59 #define	RNDIS_STATUS_FAILURE 		0xC0000001L
60 #define	RNDIS_STATUS_INVALID_DATA 	0xC0010015L
61 #define	RNDIS_STATUS_MEDIA_CONNECT 	0x4001000BL
62 #define	RNDIS_STATUS_MEDIA_DISCONNECT 	0x4001000CL
63 #define	RNDIS_STATUS_NOT_SUPPORTED 	0xC00000BBL
64 #define	RNDIS_STATUS_PENDING 		STATUS_PENDING	/* XXX */
65 #define	RNDIS_STATUS_RESOURCES 		0xC000009AL
66 #define	RNDIS_STATUS_SUCCESS 		0x00000000L
67 
68 #define	OID_GEN_SUPPORTED_LIST		0x00010101
69 #define	OID_GEN_HARDWARE_STATUS		0x00010102
70 #define	OID_GEN_MEDIA_SUPPORTED		0x00010103
71 #define	OID_GEN_MEDIA_IN_USE		0x00010104
72 #define	OID_GEN_MAXIMUM_LOOKAHEAD	0x00010105
73 #define	OID_GEN_MAXIMUM_FRAME_SIZE	0x00010106
74 #define	OID_GEN_LINK_SPEED		0x00010107
75 #define	OID_GEN_TRANSMIT_BUFFER_SPACE	0x00010108
76 #define	OID_GEN_RECEIVE_BUFFER_SPACE	0x00010109
77 #define	OID_GEN_TRANSMIT_BLOCK_SIZE	0x0001010A
78 #define	OID_GEN_RECEIVE_BLOCK_SIZE	0x0001010B
79 #define	OID_GEN_VENDOR_ID		0x0001010C
80 #define	OID_GEN_VENDOR_DESCRIPTION	0x0001010D
81 #define	OID_GEN_CURRENT_PACKET_FILTER	0x0001010E
82 #define	OID_GEN_CURRENT_LOOKAHEAD	0x0001010F
83 #define	OID_GEN_DRIVER_VERSION		0x00010110
84 #define	OID_GEN_MAXIMUM_TOTAL_SIZE	0x00010111
85 #define	OID_GEN_PROTOCOL_OPTIONS	0x00010112
86 #define	OID_GEN_MAC_OPTIONS		0x00010113
87 #define	OID_GEN_MEDIA_CONNECT_STATUS	0x00010114
88 #define	OID_GEN_MAXIMUM_SEND_PACKETS	0x00010115
89 #define	OID_GEN_VENDOR_DRIVER_VERSION	0x00010116
90 #define	OID_GEN_SUPPORTED_GUIDS		0x00010117
91 #define	OID_GEN_NETWORK_LAYER_ADDRESSES	0x00010118
92 #define	OID_GEN_TRANSPORT_HEADER_OFFSET	0x00010119
93 #define	OID_GEN_MACHINE_NAME		0x0001021A
94 #define	OID_GEN_RNDIS_CONFIG_PARAMETER	0x0001021B
95 #define	OID_GEN_VLAN_ID			0x0001021C
96 
97 #define	OID_802_3_PERMANENT_ADDRESS	0x01010101
98 #define	OID_802_3_CURRENT_ADDRESS	0x01010102
99 #define	OID_802_3_MULTICAST_LIST	0x01010103
100 #define	OID_802_3_MAXIMUM_LIST_SIZE	0x01010104
101 #define	OID_802_3_MAC_OPTIONS		0x01010105
102 #define	OID_802_3_RCV_ERROR_ALIGNMENT	0x01020101
103 #define	OID_802_3_XMIT_ONE_COLLISION	0x01020102
104 #define	OID_802_3_XMIT_MORE_COLLISIONS	0x01020103
105 #define	OID_802_3_XMIT_DEFERRED		0x01020201
106 #define	OID_802_3_XMIT_MAX_COLLISIONS	0x01020202
107 #define	OID_802_3_RCV_OVERRUN		0x01020203
108 #define	OID_802_3_XMIT_UNDERRUN		0x01020204
109 #define	OID_802_3_XMIT_HEARTBEAT_FAILURE	0x01020205
110 #define	OID_802_3_XMIT_TIMES_CRS_LOST	0x01020206
111 #define	OID_802_3_XMIT_LATE_COLLISIONS	0x01020207
112 
113 #define	RNDIS_MEDIUM_802_3		0x00000000
114 
115 /* Device flags */
116 #define	RNDIS_DF_CONNECTIONLESS		0x00000001
117 #define	RNDIS_DF_CONNECTION_ORIENTED	0x00000002
118 
119 /*
120  * RNDIS data message
121  */
122 #define	REMOTE_NDIS_PACKET_MSG		0x00000001
123 
124 struct urndis_packet_msg {
125 	uint32_t rm_type;
126 	uint32_t rm_len;
127 	uint32_t rm_dataoffset;
128 	uint32_t rm_datalen;
129 	uint32_t rm_oobdataoffset;
130 	uint32_t rm_oobdatalen;
131 	uint32_t rm_oobdataelements;
132 	uint32_t rm_pktinfooffset;
133 	uint32_t rm_pktinfolen;
134 	uint32_t rm_vchandle;
135 	uint32_t rm_reserved;
136 };
137 
138 /*
139  * RNDIS control messages
140  */
141 struct urndis_comp_hdr {
142 	uint32_t rm_type;
143 	uint32_t rm_len;
144 	uint32_t rm_rid;
145 	uint32_t rm_status;
146 };
147 
148 /* Initialize the device. */
149 #define	REMOTE_NDIS_INITIALIZE_MSG	0x00000002
150 #define	REMOTE_NDIS_INITIALIZE_CMPLT	0x80000002
151 
152 struct urndis_init_req {
153 	uint32_t rm_type;
154 	uint32_t rm_len;
155 	uint32_t rm_rid;
156 	uint32_t rm_ver_major;
157 	uint32_t rm_ver_minor;
158 	uint32_t rm_max_xfersz;
159 };
160 
161 struct urndis_init_comp {
162 	uint32_t rm_type;
163 	uint32_t rm_len;
164 	uint32_t rm_rid;
165 	uint32_t rm_status;
166 	uint32_t rm_ver_major;
167 	uint32_t rm_ver_minor;
168 	uint32_t rm_devflags;
169 	uint32_t rm_medium;
170 	uint32_t rm_pktmaxcnt;
171 	uint32_t rm_pktmaxsz;
172 	uint32_t rm_align;
173 	uint32_t rm_aflistoffset;
174 	uint32_t rm_aflistsz;
175 };
176 
177 /* Halt the device.  No response sent. */
178 #define	REMOTE_NDIS_HALT_MSG		0x00000003
179 
180 struct urndis_halt_req {
181 	uint32_t rm_type;
182 	uint32_t rm_len;
183 	uint32_t rm_rid;
184 };
185 
186 /* Send a query object. */
187 #define	REMOTE_NDIS_QUERY_MSG		0x00000004
188 #define	REMOTE_NDIS_QUERY_CMPLT		0x80000004
189 
190 struct urndis_query_req {
191 	uint32_t rm_type;
192 	uint32_t rm_len;
193 	uint32_t rm_rid;
194 	uint32_t rm_oid;
195 	uint32_t rm_infobuflen;
196 	uint32_t rm_infobufoffset;
197 	uint32_t rm_devicevchdl;
198 };
199 
200 struct urndis_query_comp {
201 	uint32_t rm_type;
202 	uint32_t rm_len;
203 	uint32_t rm_rid;
204 	uint32_t rm_status;
205 	uint32_t rm_infobuflen;
206 	uint32_t rm_infobufoffset;
207 };
208 
209 /* Send a set object request. */
210 #define	REMOTE_NDIS_SET_MSG		0x00000005
211 #define	REMOTE_NDIS_SET_CMPLT		0x80000005
212 
213 struct urndis_set_req {
214 	uint32_t rm_type;
215 	uint32_t rm_len;
216 	uint32_t rm_rid;
217 	uint32_t rm_oid;
218 	uint32_t rm_infobuflen;
219 	uint32_t rm_infobufoffset;
220 	uint32_t rm_devicevchdl;
221 };
222 
223 struct urndis_set_comp {
224 	uint32_t rm_type;
225 	uint32_t rm_len;
226 	uint32_t rm_rid;
227 	uint32_t rm_status;
228 };
229 
230 #define	REMOTE_NDIS_SET_PARAM_NUMERIC	0x00000000
231 #define	REMOTE_NDIS_SET_PARAM_STRING	0x00000002
232 
233 struct urndis_set_parameter {
234 	uint32_t rm_nameoffset;
235 	uint32_t rm_namelen;
236 	uint32_t rm_type;
237 	uint32_t rm_valueoffset;
238 	uint32_t rm_valuelen;
239 };
240 
241 /* Perform a soft reset on the device. */
242 #define	REMOTE_NDIS_RESET_MSG		0x00000006
243 #define	REMOTE_NDIS_RESET_CMPLT		0x80000006
244 
245 struct urndis_reset_req {
246 	uint32_t rm_type;
247 	uint32_t rm_len;
248 	uint32_t rm_rid;
249 };
250 
251 struct urndis_reset_comp {
252 	uint32_t rm_type;
253 	uint32_t rm_len;
254 	uint32_t rm_status;
255 	uint32_t rm_adrreset;
256 };
257 
258 /* 802.3 link-state or undefined message error. */
259 #define	REMOTE_NDIS_INDICATE_STATUS_MSG	0x00000007
260 
261 /* Keepalive messsage.  May be sent by device. */
262 #define	REMOTE_NDIS_KEEPALIVE_MSG	0x00000008
263 #define	REMOTE_NDIS_KEEPALIVE_CMPLT	0x80000008
264 
265 struct urndis_keepalive_req {
266 	uint32_t rm_type;
267 	uint32_t rm_len;
268 	uint32_t rm_rid;
269 };
270 
271 struct urndis_keepalive_comp {
272 	uint32_t rm_type;
273 	uint32_t rm_len;
274 	uint32_t rm_rid;
275 	uint32_t rm_status;
276 };
277 
278 /* packet filter bits used by OID_GEN_CURRENT_PACKET_FILTER */
279 #define	RNDIS_PACKET_TYPE_DIRECTED		0x00000001
280 #define	RNDIS_PACKET_TYPE_MULTICAST		0x00000002
281 #define	RNDIS_PACKET_TYPE_ALL_MULTICAST		0x00000004
282 #define	RNDIS_PACKET_TYPE_BROADCAST		0x00000008
283 #define	RNDIS_PACKET_TYPE_SOURCE_ROUTING	0x00000010
284 #define	RNDIS_PACKET_TYPE_PROMISCUOUS		0x00000020
285 #define	RNDIS_PACKET_TYPE_SMT			0x00000040
286 #define	RNDIS_PACKET_TYPE_ALL_LOCAL		0x00000080
287 #define	RNDIS_PACKET_TYPE_GROUP			0x00001000
288 #define	RNDIS_PACKET_TYPE_ALL_FUNCTIONAL	0x00002000
289 #define	RNDIS_PACKET_TYPE_FUNCTIONAL		0x00004000
290 #define	RNDIS_PACKET_TYPE_MAC_FRAME		0x00008000
291 
292 /* RNDIS offsets */
293 #define	RNDIS_HEADER_OFFSET	8	/* bytes */
294 #define	RNDIS_DATA_OFFSET	((uint32_t)(sizeof(struct urndis_packet_msg) - RNDIS_HEADER_OFFSET))
295 
296 #endif					/* _IF_URNDISREG_H_ */
297