blob: e0f129fe39c4b02c1d3405fa422a2463540ff87f [file] [log] [blame]
Austin Schuh41baf202022-01-01 14:33:40 -08001/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27/** \ingroup ClassDriver_CDC Communication Device Class (CDC)
28 * \defgroup CDC_RNDIS Remote Network Driver Interface Specification (RNDIS)
29 * @{
30 * \defgroup CDC_RNDIS_Common Common Definitions
31 * @{ */
32
33#ifndef _TUSB_CDC_RNDIS_H_
34#define _TUSB_CDC_RNDIS_H_
35
36#include "cdc.h"
37
38#ifdef __cplusplus
39 extern "C" {
40#endif
41
42#ifdef __CC_ARM
43#pragma diag_suppress 66 // Suppress Keil warnings #66-D: enumeration value is out of "int" range
44#endif
45
46/// RNDIS Message Types
47typedef enum
48{
49 RNDIS_MSG_PACKET = 0x00000001UL, ///< The host and device use this to send network data to one another.
50
51 RNDIS_MSG_INITIALIZE = 0x00000002UL, ///< Sent by the host to initialize the device.
52 RNDIS_MSG_INITIALIZE_CMPLT = 0x80000002UL, ///< Device response to an initialize message.
53
54 RNDIS_MSG_HALT = 0x00000003UL, ///< Sent by the host to halt the device. This does not have a response. It is optional for the device to send this message to the host.
55
56 RNDIS_MSG_QUERY = 0x00000004UL, ///< Sent by the host to send a query OID.
57 RNDIS_MSG_QUERY_CMPLT = 0x80000004UL, ///< Device response to a query OID.
58
59 RNDIS_MSG_SET = 0x00000005UL, ///< Sent by the host to send a set OID.
60 RNDIS_MSG_SET_CMPLT = 0x80000005UL, ///< Device response to a set OID.
61
62 RNDIS_MSG_RESET = 0x00000006UL, ///< Sent by the host to perform a soft reset on the device.
63 RNDIS_MSG_RESET_CMPLT = 0x80000006UL, ///< Device response to reset message.
64
65 RNDIS_MSG_INDICATE_STATUS = 0x00000007UL, ///< Sent by the device to indicate its status or an error when an unrecognized message is received.
66
67 RNDIS_MSG_KEEP_ALIVE = 0x00000008UL, ///< During idle periods, sent every few seconds by the host to check that the device is still responsive. It is optional for the device to send this message to check if the host is active.
68 RNDIS_MSG_KEEP_ALIVE_CMPLT = 0x80000008UL ///< The device response to a keepalivemessage. The host can respond with this message to a keepalive message from the device when the device implements the optional KeepAliveTimer.
69}rndis_msg_type_t;
70
71/// RNDIS Message Status Values
72typedef enum
73{
74 RNDIS_STATUS_SUCCESS = 0x00000000UL, ///< Success
75 RNDIS_STATUS_FAILURE = 0xC0000001UL, ///< Unspecified error
76 RNDIS_STATUS_INVALID_DATA = 0xC0010015UL, ///< Invalid data error
77 RNDIS_STATUS_NOT_SUPPORTED = 0xC00000BBUL, ///< Unsupported request error
78 RNDIS_STATUS_MEDIA_CONNECT = 0x4001000BUL, ///< Device is connected to a network medium.
79 RNDIS_STATUS_MEDIA_DISCONNECT = 0x4001000CUL ///< Device is disconnected from the medium.
80}rndis_msg_status_t;
81
82#ifdef __CC_ARM
83#pragma diag_default 66 // return Keil 66 to normal severity
84#endif
85
86//--------------------------------------------------------------------+
87// MESSAGE STRUCTURE
88//--------------------------------------------------------------------+
89
90//------------- Initialize -------------//
91/// \brief Initialize Message
92/// \details This message MUST be sent by the host to initialize the device.
93typedef struct {
94 uint32_t type ; ///< Message type, must be \ref RNDIS_MSG_INITIALIZE
95 uint32_t length ; ///< Message length in bytes, must be 0x18
96 uint32_t request_id ; ///< A 32-bit integer value, generated by the host, used to match the host's sent request to the response from the device.
97 uint32_t major_version ; ///< The major version of the RNDIS Protocol implemented by the host.
98 uint32_t minor_version ; ///< The minor version of the RNDIS Protocol implemented by the host
99 uint32_t max_xfer_size ; ///< The maximum size, in bytes, of any single bus data transfer that the host expects to receive from the device.
100}rndis_msg_initialize_t;
101
102/// \brief Initialize Complete Message
103/// \details This message MUST be sent by the device in response to an initialize message.
104typedef struct {
105 uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_INITIALIZE_CMPLT
106 uint32_t length ; ///< Message length in bytes, must be 0x30
107 uint32_t request_id ; ///< A 32-bit integer value from \a request_id field of the \ref rndis_msg_initialize_t to which this message is a response.
108 uint32_t status ; ///< The initialization status of the device, has value from \ref rndis_msg_status_t
109 uint32_t major_version ; ///< the highest-numbered RNDIS Protocol version supported by the device.
110 uint32_t minor_version ; ///< the highest-numbered RNDIS Protocol version supported by the device.
111 uint32_t device_flags ; ///< MUST be set to 0x000000010. Other values are reserved for future use.
112 uint32_t medium ; ///< is 0x00 for RNDIS_MEDIUM_802_3
113 uint32_t max_packet_per_xfer ; ///< The maximum number of concatenated \ref RNDIS_MSG_PACKET messages that the device can handle in a single bus transfer to it. This value MUST be at least 1.
114 uint32_t max_xfer_size ; ///< The maximum size, in bytes, of any single bus data transfer that the device expects to receive from the host.
115 uint32_t packet_alignment_factor ; ///< The byte alignment the device expects for each RNDIS message that is part of a multimessage transfer to it. The value is specified as an exponent of 2; for example, the host uses 2<SUP>{PacketAlignmentFactor}</SUP> as the alignment value.
116 uint32_t reserved[2] ;
117} rndis_msg_initialize_cmplt_t;
118
119//------------- Query -------------//
120/// \brief Query Message
121/// \details This message MUST be sent by the host to query an OID.
122typedef struct {
123 uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_QUERY
124 uint32_t length ; ///< Message length in bytes, including the header and the \a oid_buffer
125 uint32_t request_id ; ///< A 32-bit integer value, generated by the host, used to match the host's sent request to the response from the device.
126 uint32_t oid ; ///< The integer value of the host operating system-defined identifier, for the parameter of the device being queried for.
127 uint32_t buffer_length ; ///< The length, in bytes, of the input data required for the OID query. This MUST be set to 0 when there is no input data associated with the OID.
128 uint32_t buffer_offset ; ///< The offset, in bytes, from the beginning of \a request_id field where the input data for the query is located in the message. This value MUST be set to 0 when there is no input data associated with the OID.
129 uint32_t reserved ;
130 uint8_t oid_buffer[] ; ///< Flexible array contains the input data supplied by the host, required for the OID query request processing by the device, as per the host NDIS specification.
131} rndis_msg_query_t, rndis_msg_set_t;
132
133TU_VERIFY_STATIC(sizeof(rndis_msg_query_t) == 28, "Make sure flexible array member does not affect layout");
134
135/// \brief Query Complete Message
136/// \details This message MUST be sent by the device in response to a query OID message.
137typedef struct {
138 uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_QUERY_CMPLT
139 uint32_t length ; ///< Message length in bytes, including the header and the \a oid_buffer
140 uint32_t request_id ; ///< A 32-bit integer value from \a request_id field of the \ref rndis_msg_query_t to which this message is a response.
141 uint32_t status ; ///< The status of processing for the query request, has value from \ref rndis_msg_status_t.
142 uint32_t buffer_length ; ///< The length, in bytes, of the data in the response to the query. This MUST be set to 0 when there is no OIDInputBuffer.
143 uint32_t buffer_offset ; ///< The offset, in bytes, from the beginning of \a request_id field where the response data for the query is located in the message. This MUST be set to 0 when there is no \ref oid_buffer.
144 uint8_t oid_buffer[] ; ///< Flexible array member contains the response data to the OID query request as specified by the host.
145} rndis_msg_query_cmplt_t;
146
147TU_VERIFY_STATIC(sizeof(rndis_msg_query_cmplt_t) == 24, "Make sure flexible array member does not affect layout");
148
149//------------- Reset -------------//
150/// \brief Reset Message
151/// \details This message MUST be sent by the host to perform a soft reset on the device.
152typedef struct {
153 uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_RESET
154 uint32_t length ; ///< Message length in bytes, MUST be 0x06
155 uint32_t reserved ;
156} rndis_msg_reset_t;
157
158/// \brief Reset Complete Message
159/// \details This message MUST be sent by the device in response to a reset message.
160typedef struct {
161 uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_RESET_CMPLT
162 uint32_t length ; ///< Message length in bytes, MUST be 0x10
163 uint32_t status ; ///< The status of processing for the \ref rndis_msg_reset_t, has value from \ref rndis_msg_status_t.
164 uint32_t addressing_reset ; ///< This field indicates whether the addressing information, which is the multicast address list or packet filter, has been lost during the reset operation. This MUST be set to 0x00000001 if the device requires that the host to resend addressing information or MUST be set to zero otherwise.
165} rndis_msg_reset_cmplt_t;
166
167//typedef struct {
168// uint32_t type;
169// uint32_t length;
170// uint32_t status;
171// uint32_t buffer_length;
172// uint32_t buffer_offset;
173// uint32_t diagnostic_status; // optional
174// uint32_t diagnostic_error_offset; // optional
175// uint32_t status_buffer[0]; // optional
176//} rndis_msg_indicate_status_t;
177
178/// \brief Keep Alive Message
179/// \details This message MUST be sent by the host to check that device is still responsive. It is optional for the device to send this message to check if the host is active
180typedef struct {
181 uint32_t type ; ///< Message Type
182 uint32_t length ; ///< Message length in bytes, MUST be 0x10
183 uint32_t request_id ;
184} rndis_msg_keep_alive_t, rndis_msg_halt_t;
185
186/// \brief Set Complete Message
187/// \brief This message MUST be sent in response to a the request message
188typedef struct {
189 uint32_t type ; ///< Message Type
190 uint32_t length ; ///< Message length in bytes, MUST be 0x10
191 uint32_t request_id ; ///< must be the same as requesting message
192 uint32_t status ; ///< The status of processing for the request message request by the device to which this message is the response.
193} rndis_msg_set_cmplt_t, rndis_msg_keep_alive_cmplt_t;
194
195/// \brief Packet Data Message
196/// \brief This message MUST be used by the host and the device to send network data to one another.
197typedef struct {
198 uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_PACKET
199 uint32_t length ; ///< Message length in bytes, The total length of this RNDIS message including the header, payload, and padding.
200 uint32_t data_offset ; ///< Specifies the offset, in bytes, from the start of this \a data_offset field of this message to the start of the data. This MUST be an integer multiple of 4.
201 uint32_t data_length ; ///< Specifies the number of bytes in the payload of this message.
202 uint32_t out_of_band_data_offet ; ///< Specifies the offset, in bytes, of the first out-of-band data record from the start of the DataOffset field in this message. MUST be an integer multiple of 4 when out-of-band data is present or set to 0 otherwise. When there are multiple out-ofband data records, each subsequent record MUST immediately follow the previous out-of-band data record.
203 uint32_t out_of_band_data_length ; ///< Specifies, in bytes, the total length of the out-of-band data.
204 uint32_t num_out_of_band_data_elements ; ///< Specifies the number of out-of-band records in this message.
205 uint32_t per_packet_info_offset ; ///< Specifies the offset, in bytes, of the start of per-packet-info data record from the start of the \a data_offset field in this message. MUST be an integer multiple of 4 when per-packet-info data record is present or MUST be set to 0 otherwise. When there are multiple per-packet-info data records, each subsequent record MUST immediately follow the previous record.
206 uint32_t per_packet_info_length ; ///< Specifies, in bytes, the total length of per-packetinformation contained in this message.
207 uint32_t reserved[2] ;
208 uint32_t payload[0] ; ///< Network data contained in this message.
209
210 // uint8_t padding[0]
211 // Additional bytes of zeros added at the end of the message to comply with
212 // the internal and external padding requirements. Internal padding SHOULD be as per the
213 // specification of the out-of-band data record and per-packet-info data record. The external
214 //padding size SHOULD be determined based on the PacketAlignmentFactor field specification
215 //in REMOTE_NDIS_INITIALIZE_CMPLT message by the device, when multiple
216 //REMOTE_NDIS_PACKET_MSG messages are bundled together in a single bus-native message.
217 //In this case, all but the very last REMOTE_NDIS_PACKET_MSG MUST respect the
218 //PacketAlignmentFactor field.
219
220 // rndis_msg_packet_t [0] : (optional) more packet if multiple packet per bus transaction is supported
221} rndis_msg_packet_t;
222
223
224typedef struct {
225 uint32_t size ; ///< Length, in bytes, of this header and appended data and padding. This value MUST be an integer multiple of 4.
226 uint32_t type ; ///< MUST be as per host operating system specification.
227 uint32_t offset ; ///< The byte offset from the beginning of this record to the beginning of data.
228 uint32_t data[0] ; ///< Flexible array contains data
229} rndis_msg_out_of_band_data_t, rndis_msg_per_packet_info_t;
230
231//--------------------------------------------------------------------+
232// NDIS Object ID
233//--------------------------------------------------------------------+
234
235/// NDIS Object ID
236typedef enum
237{
238 //------------- General Required OIDs -------------//
239 RNDIS_OID_GEN_SUPPORTED_LIST = 0x00010101, ///< List of supported OIDs
240 RNDIS_OID_GEN_HARDWARE_STATUS = 0x00010102, ///< Hardware status
241 RNDIS_OID_GEN_MEDIA_SUPPORTED = 0x00010103, ///< Media types supported (encoded)
242 RNDIS_OID_GEN_MEDIA_IN_USE = 0x00010104, ///< Media types in use (encoded)
243 RNDIS_OID_GEN_MAXIMUM_LOOKAHEAD = 0x00010105, ///<
244 RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE = 0x00010106, ///< Maximum frame size in bytes
245 RNDIS_OID_GEN_LINK_SPEED = 0x00010107, ///< Link speed in units of 100 bps
246 RNDIS_OID_GEN_TRANSMIT_BUFFER_SPACE = 0x00010108, ///< Transmit buffer space
247 RNDIS_OID_GEN_RECEIVE_BUFFER_SPACE = 0x00010109, ///< Receive buffer space
248 RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE = 0x0001010A, ///< Minimum amount of storage, in bytes, that a single packet occupies in the transmit buffer space of the NIC
249 RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE = 0x0001010B, ///< Amount of storage, in bytes, that a single packet occupies in the receive buffer space of the NIC
250 RNDIS_OID_GEN_VENDOR_ID = 0x0001010C, ///< Vendor NIC code
251 RNDIS_OID_GEN_VENDOR_DESCRIPTION = 0x0001010D, ///< Vendor network card description
252 RNDIS_OID_GEN_CURRENT_PACKET_FILTER = 0x0001010E, ///< Current packet filter (encoded)
253 RNDIS_OID_GEN_CURRENT_LOOKAHEAD = 0x0001010F, ///< Current lookahead size in bytes
254 RNDIS_OID_GEN_DRIVER_VERSION = 0x00010110, ///< NDIS version number used by the driver
255 RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE = 0x00010111, ///< Maximum total packet length in bytes
256 RNDIS_OID_GEN_PROTOCOL_OPTIONS = 0x00010112, ///< Optional protocol flags (encoded)
257 RNDIS_OID_GEN_MAC_OPTIONS = 0x00010113, ///< Optional NIC flags (encoded)
258 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS = 0x00010114, ///< Whether the NIC is connected to the network
259 RNDIS_OID_GEN_MAXIMUM_SEND_PACKETS = 0x00010115, ///< The maximum number of send packets the driver can accept per call to its MiniportSendPacketsfunction
260
261 //------------- General Optional OIDs -------------//
262 RNDIS_OID_GEN_VENDOR_DRIVER_VERSION = 0x00010116, ///< Vendor-assigned version number of the driver
263 RNDIS_OID_GEN_SUPPORTED_GUIDS = 0x00010117, ///< The custom GUIDs (Globally Unique Identifier) supported by the miniport driver
264 RNDIS_OID_GEN_NETWORK_LAYER_ADDRESSES = 0x00010118, ///< List of network-layer addresses associated with the binding between a transport and the driver
265 RNDIS_OID_GEN_TRANSPORT_HEADER_OFFSET = 0x00010119, ///< Size of packets' additional headers
266 RNDIS_OID_GEN_MEDIA_CAPABILITIES = 0x00010201, ///<
267 RNDIS_OID_GEN_PHYSICAL_MEDIUM = 0x00010202, ///< Physical media supported by the miniport driver (encoded)
268
269 //------------- 802.3 Objects (Ethernet) -------------//
270 RNDIS_OID_802_3_PERMANENT_ADDRESS = 0x01010101, ///< Permanent station address
271 RNDIS_OID_802_3_CURRENT_ADDRESS = 0x01010102, ///< Current station address
272 RNDIS_OID_802_3_MULTICAST_LIST = 0x01010103, ///< Current multicast address list
273 RNDIS_OID_802_3_MAXIMUM_LIST_SIZE = 0x01010104, ///< Maximum size of multicast address list
274} rndis_oid_type_t;
275
276/// RNDIS Packet Filter Bits \ref RNDIS_OID_GEN_CURRENT_PACKET_FILTER.
277typedef enum
278{
279 RNDIS_PACKET_TYPE_DIRECTED = 0x00000001, ///< Directed packets. Directed packets contain a destination address equal to the station address of the NIC.
280 RNDIS_PACKET_TYPE_MULTICAST = 0x00000002, ///< Multicast address packets sent to addresses in the multicast address list.
281 RNDIS_PACKET_TYPE_ALL_MULTICAST = 0x00000004, ///< All multicast address packets, not just the ones enumerated in the multicast address list.
282 RNDIS_PACKET_TYPE_BROADCAST = 0x00000008, ///< Broadcast packets.
283 RNDIS_PACKET_TYPE_SOURCE_ROUTING = 0x00000010, ///< All source routing packets. If the protocol driver sets this bit, the NDIS library attempts to act as a source routing bridge.
284 RNDIS_PACKET_TYPE_PROMISCUOUS = 0x00000020, ///< Specifies all packets regardless of whether VLAN filtering is enabled or not and whether the VLAN identifier matches or not.
285 RNDIS_PACKET_TYPE_SMT = 0x00000040, ///< SMT packets that an FDDI NIC receives.
286 RNDIS_PACKET_TYPE_ALL_LOCAL = 0x00000080, ///< All packets sent by installed protocols and all packets indicated by the NIC that is identified by a given NdisBindingHandle.
287 RNDIS_PACKET_TYPE_GROUP = 0x00001000, ///< Packets sent to the current group address.
288 RNDIS_PACKET_TYPE_ALL_FUNCTIONAL = 0x00002000, ///< All functional address packets, not just the ones in the current functional address.
289 RNDIS_PACKET_TYPE_FUNCTIONAL = 0x00004000, ///< Functional address packets sent to addresses included in the current functional address.
290 RNDIS_PACKET_TYPE_MAC_FRAME = 0x00008000, ///< NIC driver frames that a Token Ring NIC receives.
291 RNDIS_PACKET_TYPE_NO_LOCAL = 0x00010000,
292} rndis_packet_filter_type_t;
293
294#ifdef __cplusplus
295 }
296#endif
297
298#endif /* _TUSB_CDC_RNDIS_H_ */
299
300/** @} */
301/** @} */