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	_NET_RNDIS_H_
24#define	_NET_RNDIS_H_
25
26/* Canonical major/minor version as of 22th Aug. 2016. */
27#define	RNDIS_VERSION_MAJOR		0x00000001
28#define	RNDIS_VERSION_MINOR		0x00000000
29
30#define	RNDIS_STATUS_SUCCESS 		0x00000000L
31#define	RNDIS_STATUS_PENDING 		0x00000103L
32#define	RNDIS_STATUS_MEDIA_CONNECT 	0x4001000BL
33#define	RNDIS_STATUS_MEDIA_DISCONNECT 	0x4001000CL
34#define	RNDIS_STATUS_LINK_SPEED_CHANGE	0x40010013L
35#define	RNDIS_STATUS_NETWORK_CHANGE	0x40010018L
36#define	RNDIS_STATUS_TASK_OFFLOAD_CURRENT_CONFIG	0x40020006L
37#define	RNDIS_STATUS_BUFFER_OVERFLOW 	0x80000005L
38#define	RNDIS_STATUS_FAILURE 		0xC0000001L
39#define	RNDIS_STATUS_NOT_SUPPORTED 	0xC00000BBL
40#define	RNDIS_STATUS_RESOURCES 		0xC000009AL
41#define	RNDIS_STATUS_INVALID_DATA 	0xC0010015L
42
43#define	OID_GEN_SUPPORTED_LIST		0x00010101
44#define	OID_GEN_HARDWARE_STATUS		0x00010102
45#define	OID_GEN_MEDIA_SUPPORTED		0x00010103
46#define	OID_GEN_MEDIA_IN_USE		0x00010104
47#define	OID_GEN_MAXIMUM_LOOKAHEAD	0x00010105
48#define	OID_GEN_MAXIMUM_FRAME_SIZE	0x00010106
49#define	OID_GEN_LINK_SPEED		0x00010107
50#define	OID_GEN_TRANSMIT_BUFFER_SPACE	0x00010108
51#define	OID_GEN_RECEIVE_BUFFER_SPACE	0x00010109
52#define	OID_GEN_TRANSMIT_BLOCK_SIZE	0x0001010A
53#define	OID_GEN_RECEIVE_BLOCK_SIZE	0x0001010B
54#define	OID_GEN_VENDOR_ID		0x0001010C
55#define	OID_GEN_VENDOR_DESCRIPTION	0x0001010D
56#define	OID_GEN_CURRENT_PACKET_FILTER	0x0001010E
57#define	OID_GEN_CURRENT_LOOKAHEAD	0x0001010F
58#define	OID_GEN_DRIVER_VERSION		0x00010110
59#define	OID_GEN_MAXIMUM_TOTAL_SIZE	0x00010111
60#define	OID_GEN_PROTOCOL_OPTIONS	0x00010112
61#define	OID_GEN_MAC_OPTIONS		0x00010113
62#define	OID_GEN_MEDIA_CONNECT_STATUS	0x00010114
63#define	OID_GEN_MAXIMUM_SEND_PACKETS	0x00010115
64#define	OID_GEN_VENDOR_DRIVER_VERSION	0x00010116
65#define	OID_GEN_SUPPORTED_GUIDS		0x00010117
66#define	OID_GEN_NETWORK_LAYER_ADDRESSES	0x00010118
67#define	OID_GEN_TRANSPORT_HEADER_OFFSET	0x00010119
68#define	OID_GEN_RECEIVE_SCALE_CAPABILITIES	0x00010203
69#define	OID_GEN_RECEIVE_SCALE_PARAMETERS	0x00010204
70#define	OID_GEN_MACHINE_NAME		0x0001021A
71#define	OID_GEN_RNDIS_CONFIG_PARAMETER	0x0001021B
72#define	OID_GEN_VLAN_ID			0x0001021C
73
74#define	OID_802_3_PERMANENT_ADDRESS	0x01010101
75#define	OID_802_3_CURRENT_ADDRESS	0x01010102
76#define	OID_802_3_MULTICAST_LIST	0x01010103
77#define	OID_802_3_MAXIMUM_LIST_SIZE	0x01010104
78#define	OID_802_3_MAC_OPTIONS		0x01010105
79#define	OID_802_3_RCV_ERROR_ALIGNMENT	0x01020101
80#define	OID_802_3_XMIT_ONE_COLLISION	0x01020102
81#define	OID_802_3_XMIT_MORE_COLLISIONS	0x01020103
82#define	OID_802_3_XMIT_DEFERRED		0x01020201
83#define	OID_802_3_XMIT_MAX_COLLISIONS	0x01020202
84#define	OID_802_3_RCV_OVERRUN		0x01020203
85#define	OID_802_3_XMIT_UNDERRUN		0x01020204
86#define	OID_802_3_XMIT_HEARTBEAT_FAILURE	0x01020205
87#define	OID_802_3_XMIT_TIMES_CRS_LOST	0x01020206
88#define	OID_802_3_XMIT_LATE_COLLISIONS	0x01020207
89
90#define	OID_TCP_OFFLOAD_PARAMETERS	0xFC01020C
91#define	OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES	0xFC01020D
92
93#define	RNDIS_MEDIUM_802_3		0x00000000
94
95/* Device flags */
96#define	RNDIS_DF_CONNECTIONLESS		0x00000001
97#define	RNDIS_DF_CONNECTION_ORIENTED	0x00000002
98
99/*
100 * Common RNDIS message header.
101 */
102struct rndis_msghdr {
103	uint32_t rm_type;
104	uint32_t rm_len;
105};
106
107/*
108 * RNDIS data message
109 */
110#define	REMOTE_NDIS_PACKET_MSG		0x00000001
111
112struct rndis_packet_msg {
113	uint32_t rm_type;
114	uint32_t rm_len;
115	uint32_t rm_dataoffset;
116	uint32_t rm_datalen;
117	uint32_t rm_oobdataoffset;
118	uint32_t rm_oobdatalen;
119	uint32_t rm_oobdataelements;
120	uint32_t rm_pktinfooffset;
121	uint32_t rm_pktinfolen;
122	uint32_t rm_vchandle;
123	uint32_t rm_reserved;
124};
125
126/*
127 * Minimum value for rm_dataoffset, rm_oobdataoffset, and
128 * rm_pktinfooffset.
129 */
130#define	RNDIS_PACKET_MSG_OFFSET_MIN		\
131	(sizeof(struct rndis_packet_msg) -	\
132	 __offsetof(struct rndis_packet_msg, rm_dataoffset))
133
134/* Offset from the beginning of rndis_packet_msg. */
135#define	RNDIS_PACKET_MSG_OFFSET_ABS(ofs)	\
136	((ofs) + __offsetof(struct rndis_packet_msg, rm_dataoffset))
137
138#define	RNDIS_PACKET_MSG_OFFSET_ALIGN		4
139#define	RNDIS_PACKET_MSG_OFFSET_ALIGNMASK	\
140	(RNDIS_PACKET_MSG_OFFSET_ALIGN - 1)
141
142/* Per-packet-info for RNDIS data message */
143struct rndis_pktinfo {
144	uint32_t rm_size;
145	uint32_t rm_type:31;		/* NDIS_PKTINFO_TYPE_ */
146	uint32_t rm_internal:1;		/* Indicate if internal type */
147	uint32_t rm_pktinfooffset;
148	uint8_t rm_data[];
149};
150
151#define	RNDIS_PKTINFO_OFFSET		\
152	__offsetof(struct rndis_pktinfo, rm_data[0])
153#define	RNDIS_PKTINFO_SIZE_ALIGN	4
154#define	RNDIS_PKTINFO_SIZE_ALIGNMASK	(RNDIS_PKTINFO_SIZE_ALIGN - 1)
155
156#define	NDIS_PKTINFO_TYPE_CSUM		0
157#define	NDIS_PKTINFO_TYPE_IPSEC		1
158#define	NDIS_PKTINFO_TYPE_LSO		2
159#define	NDIS_PKTINFO_TYPE_CLASSIFY	3
160/* reserved 4 */
161#define	NDIS_PKTINFO_TYPE_SGLIST	5
162#define	NDIS_PKTINFO_TYPE_VLAN		6
163#define	NDIS_PKTINFO_TYPE_ORIG		7
164#define	NDIS_PKTINFO_TYPE_PKT_CANCELID	8
165#define	NDIS_PKTINFO_TYPE_ORIG_NBLIST	9
166#define	NDIS_PKTINFO_TYPE_CACHE_NBLIST	10
167#define	NDIS_PKTINFO_TYPE_PKT_PAD	11
168
169/* Per-packet-info internal type */
170#define	NDIS_PKTINFO_IT_PKTINFO_ID	1
171/* Add more internal type here */
172
173/*
174 * RNDIS control messages
175 */
176
177/*
178 * Common header for RNDIS completion messages.
179 *
180 * NOTE: It does not apply to REMOTE_NDIS_RESET_CMPLT.
181 */
182struct rndis_comp_hdr {
183	uint32_t rm_type;
184	uint32_t rm_len;
185	uint32_t rm_rid;
186	uint32_t rm_status;
187};
188
189/* Initialize the device. */
190#define	REMOTE_NDIS_INITIALIZE_MSG	0x00000002
191#define	REMOTE_NDIS_INITIALIZE_CMPLT	0x80000002
192
193struct rndis_init_req {
194	uint32_t rm_type;
195	uint32_t rm_len;
196	uint32_t rm_rid;
197	uint32_t rm_ver_major;
198	uint32_t rm_ver_minor;
199	uint32_t rm_max_xfersz;
200};
201
202struct rndis_init_comp {
203	uint32_t rm_type;
204	uint32_t rm_len;
205	uint32_t rm_rid;
206	uint32_t rm_status;
207	uint32_t rm_ver_major;
208	uint32_t rm_ver_minor;
209	uint32_t rm_devflags;
210	uint32_t rm_medium;
211	uint32_t rm_pktmaxcnt;
212	uint32_t rm_pktmaxsz;
213	uint32_t rm_align;
214	uint32_t rm_aflistoffset;
215	uint32_t rm_aflistsz;
216};
217
218#define	RNDIS_INIT_COMP_SIZE_MIN	\
219	__offsetof(struct rndis_init_comp, rm_aflistsz)
220
221/* Halt the device.  No response sent. */
222#define	REMOTE_NDIS_HALT_MSG		0x00000003
223
224struct rndis_halt_req {
225	uint32_t rm_type;
226	uint32_t rm_len;
227	uint32_t rm_rid;
228};
229
230/* Send a query object. */
231#define	REMOTE_NDIS_QUERY_MSG		0x00000004
232#define	REMOTE_NDIS_QUERY_CMPLT		0x80000004
233
234struct rndis_query_req {
235	uint32_t rm_type;
236	uint32_t rm_len;
237	uint32_t rm_rid;
238	uint32_t rm_oid;
239	uint32_t rm_infobuflen;
240	uint32_t rm_infobufoffset;
241	uint32_t rm_devicevchdl;
242};
243
244#define	RNDIS_QUERY_REQ_INFOBUFOFFSET		\
245	(sizeof(struct rndis_query_req) -	\
246	 __offsetof(struct rndis_query_req, rm_rid))
247
248struct rndis_query_comp {
249	uint32_t rm_type;
250	uint32_t rm_len;
251	uint32_t rm_rid;
252	uint32_t rm_status;
253	uint32_t rm_infobuflen;
254	uint32_t rm_infobufoffset;
255};
256
257/* infobuf offset from the beginning of rndis_query_comp. */
258#define	RNDIS_QUERY_COMP_INFOBUFOFFSET_ABS(ofs)	\
259	((ofs) + __offsetof(struct rndis_query_req, rm_rid))
260
261/* Send a set object request. */
262#define	REMOTE_NDIS_SET_MSG		0x00000005
263#define	REMOTE_NDIS_SET_CMPLT		0x80000005
264
265struct rndis_set_req {
266	uint32_t rm_type;
267	uint32_t rm_len;
268	uint32_t rm_rid;
269	uint32_t rm_oid;
270	uint32_t rm_infobuflen;
271	uint32_t rm_infobufoffset;
272	uint32_t rm_devicevchdl;
273};
274
275#define	RNDIS_SET_REQ_INFOBUFOFFSET		\
276	(sizeof(struct rndis_set_req) -		\
277	 __offsetof(struct rndis_set_req, rm_rid))
278
279struct rndis_set_comp {
280	uint32_t rm_type;
281	uint32_t rm_len;
282	uint32_t rm_rid;
283	uint32_t rm_status;
284};
285
286/*
287 * Parameter used by OID_GEN_RNDIS_CONFIG_PARAMETER.
288 */
289#define	REMOTE_NDIS_SET_PARAM_NUMERIC	0x00000000
290#define	REMOTE_NDIS_SET_PARAM_STRING	0x00000002
291
292struct rndis_set_parameter {
293	uint32_t rm_nameoffset;
294	uint32_t rm_namelen;
295	uint32_t rm_type;
296	uint32_t rm_valueoffset;
297	uint32_t rm_valuelen;
298};
299
300/* Perform a soft reset on the device. */
301#define	REMOTE_NDIS_RESET_MSG		0x00000006
302#define	REMOTE_NDIS_RESET_CMPLT		0x80000006
303
304struct rndis_reset_req {
305	uint32_t rm_type;
306	uint32_t rm_len;
307	uint32_t rm_rid;
308};
309
310struct rndis_reset_comp {
311	uint32_t rm_type;
312	uint32_t rm_len;
313	uint32_t rm_status;
314	uint32_t rm_adrreset;
315};
316
317/* 802.3 link-state or undefined message error.  Sent by device. */
318#define	REMOTE_NDIS_INDICATE_STATUS_MSG	0x00000007
319
320struct rndis_status_msg {
321	uint32_t rm_type;
322	uint32_t rm_len;
323	uint32_t rm_status;
324	uint32_t rm_stbuflen;
325	uint32_t rm_stbufoffset;
326	/* rndis_diag_info */
327};
328
329/* stbuf offset from the beginning of rndis_status_msg. */
330#define	RNDIS_STBUFOFFSET_ABS(ofs)	\
331	((ofs) + __offsetof(struct rndis_status_msg, rm_status))
332
333/*
334 * Immediately after rndis_status_msg.rm_stbufoffset, if a control
335 * message is malformatted, or a packet message contains inappropriate
336 * content.
337 */
338struct rndis_diag_info {
339	uint32_t rm_diagstatus;
340	uint32_t rm_erroffset;
341};
342
343/* Keepalive messsage.  May be sent by device. */
344#define	REMOTE_NDIS_KEEPALIVE_MSG	0x00000008
345#define	REMOTE_NDIS_KEEPALIVE_CMPLT	0x80000008
346
347struct rndis_keepalive_req {
348	uint32_t rm_type;
349	uint32_t rm_len;
350	uint32_t rm_rid;
351};
352
353struct rndis_keepalive_comp {
354	uint32_t rm_type;
355	uint32_t rm_len;
356	uint32_t rm_rid;
357	uint32_t rm_status;
358};
359
360/* Packet filter bits used by OID_GEN_CURRENT_PACKET_FILTER */
361#define	NDIS_PACKET_TYPE_NONE			0x00000000
362#define	NDIS_PACKET_TYPE_DIRECTED		0x00000001
363#define	NDIS_PACKET_TYPE_MULTICAST		0x00000002
364#define	NDIS_PACKET_TYPE_ALL_MULTICAST		0x00000004
365#define	NDIS_PACKET_TYPE_BROADCAST		0x00000008
366#define	NDIS_PACKET_TYPE_SOURCE_ROUTING		0x00000010
367#define	NDIS_PACKET_TYPE_PROMISCUOUS		0x00000020
368#define	NDIS_PACKET_TYPE_SMT			0x00000040
369#define	NDIS_PACKET_TYPE_ALL_LOCAL		0x00000080
370#define	NDIS_PACKET_TYPE_GROUP			0x00001000
371#define	NDIS_PACKET_TYPE_ALL_FUNCTIONAL		0x00002000
372#define	NDIS_PACKET_TYPE_FUNCTIONAL		0x00004000
373#define	NDIS_PACKET_TYPE_MAC_FRAME		0x00008000
374
375/*
376 * Packet filter description for use with printf(9) %b identifier.
377 */
378#define	NDIS_PACKET_TYPES				\
379	"\20\1DIRECT\2MULTICAST\3ALLMULTI\4BROADCAST"	\
380	"\5SRCROUTE\6PROMISC\7SMT\10ALLLOCAL"		\
381	"\11GROUP\12ALLFUNC\13FUNC\14MACFRAME"
382
383/* RNDIS offsets */
384#define	RNDIS_HEADER_OFFSET	((uint32_t)sizeof(struct rndis_msghdr))
385#define	RNDIS_DATA_OFFSET	\
386    ((uint32_t)(sizeof(struct rndis_packet_msg) - RNDIS_HEADER_OFFSET))
387
388#endif	/* !_NET_RNDIS_H_ */
389