1 /*
2  * Copyright 2018 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef __USB_HOST_CDC_RNDIS_H__
9 #define __USB_HOST_CDC_RNDIS_H__
10 
11 /*!
12  * @addtogroup usb_host_cdc_rnds_drv
13  * @{
14  */
15 
16 /*******************************************************************************
17  * Definitions
18  ******************************************************************************/
19 /* general OIDs  */
20 #define OID_GEN_SUPPORTED_LIST (0x00010101U)
21 #define OID_GEN_HARDWARE_STATUS (0x00010102U)
22 #define OID_GEN_MEDIA_SUPPORTED (0x00010103U)
23 #define OID_GEN_MEDIA_IN_USE (0x00010104U)
24 #define OID_GEN_MAXIMUM_LOOKAHEAD (0x00010105U)
25 #define OID_GEN_MAXIMUM_FRAME_SIZE (0x00010106U)
26 #define OID_GEN_LINK_SPEED (0x00010107U)
27 #define OID_GEN_TRANSMIT_BUFFER_SPACE (0x00010108U)
28 #define OID_GEN_RECEIVE_BUFFER_SPACE (0x00010109U)
29 #define OID_GEN_TRANSMIT_BLOCK_SIZE (0x0001010AU)
30 #define OID_GEN_RECEIVE_BLOCK_SIZE (0x0001010BU)
31 #define OID_GEN_VENDOR_ID (0x0001010CU)
32 #define OID_GEN_VENDOR_DESCRIPTION (0x0001010DU)
33 #define OID_GEN_CURRENT_PACKET_FILTER (0x0001010EU)
34 #define OID_GEN_CURRENT_LOOKAHEAD (0x0001010FU)
35 #define OID_GEN_DRIVER_VERSION (0x00010110U)
36 #define OID_GEN_MAXIMUM_TOTAL_SIZE (0x00010111U)
37 #define OID_GEN_PROTOCOL_OPTIONS (0x00010112U)
38 #define OID_GEN_MAC_OPTIONS (0x00010113U)
39 #define OID_GEN_MEDIA_CONNECT_STATUS (0x00010114U)
40 #define OID_GEN_MAXIMUM_SEND_PACKETS (0x00010115U)
41 #define OID_GEN_VENDOR_DRIVER_VERSION (0x00010116U)
42 #define OID_GEN_SUPPORTED_GUIDS (0x00010117U)
43 #define OID_GEN_NETWORK_LAYER_ADDRESSES (0x00010118U)
44 #define OID_GEN_TRANSPORT_HEADER_OFFSET (0x00010119U)
45 #define OID_GEN_MACHINE_NAME (0x0001021AU)
46 #define OID_GEN_RNDIS_CONFIG_PARAMETER (0x0001021BU)
47 #define OID_GEN_VLAN_ID                   (0x0001021C
48 /*general statistic OIdS */
49 #define OID_GEN_XMIT_OK (0x00020101U)
50 #define OID_GEN_RCV_OK (0x00020102U)
51 #define OID_GEN_XMIT_ERROR (0x00020103U)
52 #define OID_GEN_RCV_ERROR (0x00020104U)
53 #define OID_GEN_RCV_NO_BUFFER (0x00020105U)
54 
55 /* 802.3 OIDs(Ethernet)  */
56 #define OID_802_3_PERMANENT_ADDRESS (0x01010101)
57 #define OID_802_3_CURRENT_ADDRESS (0x01010102)
58 #define OID_802_3_MULTICAST_LIST (0x01010103)
59 #define OID_802_3_MAXIMUM_LIST_SIZE (0x01010104)
60 #define OID_802_3_MAC_OPTIONS (0x01010105)
61 
62 #define OID_802_3_RCV_ERROR_ALIGNMENT (0x01020101)
63 #define OID_802_3_XMIT_ONE_COLLISION (0x01020102)
64 #define OID_802_3_XMIT_MORE_COLLISIONS (0x01020103)
65 
66 #define OID_802_3_XMIT_DEFERRED (0x01020201)
67 #define OID_802_3_XMIT_MAX_COLLISIONS (0x01020202)
68 #define OID_802_3_RCV_OVERRUN (0x01020203)
69 #define OID_802_3_XMIT_UNDERRUN (0x01020204)
70 #define OID_802_3_XMIT_HEARTBEAT_FAILURE (0x01020205)
71 #define OID_802_3_XMIT_TIMES_CRS_LOST (0x01020206)
72 #define OID_802_3_XMIT_LATE_COLLISIONS (0x01020207)
73 
74 /*RNDIS message types*/
75 #define REMOTE_NDIS_PACKET_MSG (0x00000001U)
76 #define REMOTE_NDIS_INITIALIZE_MSG (0x00000002U)
77 #define REMOTE_NDIS_INITIALIZE_CMPLT (0x80000002U)
78 #define REMOTE_NDIS_HALT_MSG (0x00000003U)
79 #define REMOTE_NDIS_QUERY_MSG (0x00000004U)
80 #define REMOTE_NDIS_QUERY_CMPLT (0x80000004U)
81 #define REMOTE_NDIS_SET_MSG (0x00000005U)
82 #define REMOTE_NDIS_SET_CMPLT (0x80000005U)
83 #define REMOTE_NDIS_RESET_MSG (0x00000006U)
84 #define REMOTE_NDIS_RESET_CMPLT (0x80000006U)
85 #define REMOTE_NDIS_INDICATE_STATUS_MSG (0x00000007U)
86 #define REMOTE_NDIS_KEEPALIVE_MSG (0x00000008U)
87 #define REMOTE_NDIS_KEEPALIVE_CMPLT (0x80000008U)
88 
89 /*Status Values */
90 /*! Success.*/
91 #define RNDIS_STATUS_SUCCESS (0x00000000U)
92 /*! Unspecified error*/
93 #define RNDIS_STATUS_FAILURE (0xC0000001U)
94 /*! Invalid data error. */
95 #define RNDIS_STATUS_INVALID_DATA (0xC0010015U)
96 /*! Unsupported request error */
97 #define RNDIS_STATUS_NOT_SUPPORTED (0xC00000BBU)
98 /*! Device is connected to a network medium */
99 #define RNDIS_STATUS_MEDIA_CONNECT (0x4001000BU)
100 /*! Device is disconnected from the medium */
101 #define RNDIS_STATUS_MEDIA_DISCONNECT (0x4001000CU)
102 
103 #define NDIS_PACKET_TYPE_DIRECTED (0x0001U)
104 /*! Multicast address packets sent to addresses in the multicast address list.
105  * A protocol driver can receive Ethernet (802.3) multicast packets or
106  * Token Ring (802.5) functional address packets by specifying the multicast or
107  * functional address packet type. Setting the multicast address list or
108  * functional address determines which multicast address
109  * groups the NIC driver enables.
110  */
111 #define NDIS_PACKET_TYPE_MULTICAST (0x0002U)
112 /*! All multicast address packets, not just the ones enumerated in the
113  * multicast address list.
114  */
115 #define NDIS_PACKET_TYPE_ALL_MULTICAST (0x0004U)
116 /*! Broadcast packets. */
117 #define NDIS_PACKET_TYPE_BROADCAST (0x0008U)
118 /*! All source routing packets. If the protocol driver sets this bit,
119  * the NDIS library attempts to act as a source routing bridge.
120  */
121 #define NDIS_PACKET_TYPE_SOURCE_ROUTING (0x0010U)
122 /*! Specifies all packets.*/
123 #define NDIS_PACKET_TYPE_PROMISCUOUS (0x0020U)
124 /*! SMT packets that an FDDI NIC receives. */
125 #define NDIS_PACKET_TYPE_SMT (0x0040U)
126 
127 /*! Size of INITIALIZE_MSG. */
128 #define RNDIS_INITIALIZE_MSG_SIZE (24U)
129 /*! RSize of QUERY_MSG. */
130 #define RNDIS_QUERY_MSG_SIZE (28U)
131 /*! Size of SET_MSG. */
132 #define RNDIS_SET_MSG_SIZE (28U)
133 /*! Size of RESET_MSG. */
134 #define RNDIS_RESET_MSG_SIZE (12U)
135 /*! Size of KEEPALIVE_MSG. */
136 #define RNDIS_KEEPALIVE_MSG_SIZE (12U)
137 /*! Size of DATA_MSG_HEADER. */
138 #define RNDIS_DAT_MSG_HEADER_SIZE (44U)
139 
140 /*! RNDIS Version */
141 #define RNDIS_MAJOR_VERSION (0x5U)
142 /*! RNDIS Version */
143 #define RNDIS_MINOR_VERSION (0x0U)
144 #define RNDIS_MAX_TRANSFER_PACKET_SIZE (0x4000U)
145 #define RNDIS_FRAME_MAX_FRAMELEN (1518U) /*!< Default maximum Ethernet frame size. */
146 
147 /*! @brief Communications Device class-specific code, Base Class 02h (Communications and CDC Control) */
148 #define USB_HOST_CDC_RNDIS_CLASS_CODE (0x02U)
149 /*! @brief Communication Interface Class SubClass code for Abstract Control Model */
150 #define USB_HOST_CDC_RNDIS_SUBCLASS_CODE (0x02U)
151 /*! @brief Communication Interface Class Protocol code for vendor specific protocol */
152 #define USB_HOST_CDC_RNDIS_PROTOCOL_CODE (0xFFU)
153 
154 /*! @brief Wireless Controller class-specific code, Base Class E0h (Wireless Controller) */
155 #define USB_HOST_WC_RNDIS_CLASS_CODE (0xE0U)
156 /*! @brief Wireless Controller Class SubClass code */
157 #define USB_HOST_WC_RNDIS_SUBCLASS_CODE (0x01U)
158 /*! @brief Wireless Controller Class Protocol code for Remote NDIS */
159 #define USB_HOST_WC_RNDIS_PROTOCOL_CODE (0x03U)
160 
161 /*! @brief Miscellaneous class-specific code, Base Class EFh (Miscellaneous) */
162 #define USB_HOST_MISC_RNDIS_CLASS_CODE (0xEFU)
163 /*! @brief Miscellaneous Class SubClass code */
164 #define USB_HOST_MISC_RNDIS_SUBCLASS_CODE (0x04U)
165 /*! @brief Miscellaneous Class Protocol code for RNDIS over Ethernet */
166 #define USB_HOST_MISC_RNDIS_PROTOCOL_CODE (0x01U)
167 
168 /*this is the minimum byte length of the buffer posted by host*/
169 
170 /*******************************************************************************
171  * RNDS class public structure, enumeration, macro, function
172  ******************************************************************************/
173 /*! @brief Define message structure for REMOTE_NDIS_INITIALIZE_MSG. */
174 typedef struct _rndis_init_msg_struct
175 {
176     uint32_t messageType;
177     uint32_t messageLength;
178     uint32_t requestID;
179     uint32_t majorVersion;
180     uint32_t minorVersion;
181     uint32_t maxTransferSize;
182 } rndis_init_msg_struct_t;
183 /*! @brief Define message structure for REMOTE_NDIS_HALT_MSG. */
184 typedef struct _rndis_halt_msg_struct
185 {
186     uint32_t messageType;
187     uint32_t messageLength;
188     uint32_t requestID;
189 } rndis_halt_msg_struct_t;
190 /*! @brief Define message structure for REMOTE_NDIS_QUERY_MSG. */
191 typedef struct _rndis_query_msg_struct
192 {
193     uint32_t messageType;
194     uint32_t messageLength;
195     uint32_t requestID;
196     uint32_t oid;
197     uint32_t informationBufferLength;
198     uint32_t informationBufferOffset;
199     uint32_t deviceVcHandle;
200 } rndis_query_msg_struct_t;
201 /*! @brief Define message structure for REMOTE_NDIS_SET_MSG. */
202 typedef struct _rndis_set_msg_struct
203 {
204     uint32_t messageType;
205     uint32_t messageLength;
206     uint32_t requestID;
207     uint32_t oid;
208     uint32_t informationBufferLength;
209     uint32_t informationBufferOffset;
210     uint32_t deviceVcHandle;
211 } rndis_set_msg_struct_t;
212 /*! @brief Define message structure for REMOTE_NDIS_RESET_MSG. */
213 typedef struct _rndis_reset_msg_struct
214 {
215     uint32_t messageType;
216     uint32_t messageLength;
217     uint32_t Reserved;
218 } rndis_reset_msg_struct_t;
219 /*! @brief Define message structure for REMOTE_NDIS_INDICATE_STATUS_MSG. */
220 typedef struct _rndis_indicate_status_msg_struct
221 {
222     uint32_t messageType;
223     uint32_t messageLength;
224     uint32_t status;
225     uint32_t statusBufferLength;
226     uint32_t statusBufferOffset;
227 } rndis_indicate_status_msg_struct_t;
228 /*! @brief Define message structure for REMOTE_NDIS_DIAGNOSTIC_MSG. */
229 typedef struct _rndis_diagnostic_msg_struct
230 {
231     uint32_t DiagStatus;
232     uint32_t ErrorOffset;
233 } rndis_diagnostic_msg_struct_t;
234 /*! @brief Define message structure for REMOTE_NDIS_KEEPALIVE_MSG. */
235 typedef struct _rndis_keepalive_msg_struct
236 {
237     uint32_t messageType;
238     uint32_t messageLength;
239     uint32_t requestID;
240 } rndis_keepalive_msg_struct_t;
241 /*! @brief Define message structure for REMOTE_NDIS_INITIALIZE_CMPLT. */
242 typedef struct _rndis_init_cmplt_struct
243 {
244     uint32_t messageType;
245     uint32_t messageLength;
246     uint32_t requestID;
247     uint32_t status;
248     uint32_t majorVersion;
249     uint32_t minorVersion;
250     uint32_t deviceFlags;
251     uint32_t medium;
252     uint32_t maxPacketsPerTransfer;
253     uint32_t maxTransferSize;
254     uint32_t packetAlignmentFactor;
255     uint32_t afListOffset;
256     uint32_t afListSize;
257 } rndis_init_cmplt_struct_t;
258 /*! @brief Define message structure for REMOTE_NDIS_QUERY_CMPLT. */
259 typedef struct _rndis_query_cmplt_struct
260 {
261     uint32_t messageType;
262     uint32_t messageLength;
263     uint32_t requestID;
264     uint32_t status;
265     uint32_t informationBufferLength;
266     uint32_t informationBufferOffset;
267 } rndis_query_cmplt_struct_t;
268 /*! @brief Define message structure for REMOTE_NDIS_SET_CMPLT. */
269 typedef struct _rndis_set_cmplt_struct
270 {
271     uint32_t messageType;
272     uint32_t messageLength;
273     uint32_t requestID;
274     uint32_t status;
275 } rndis_set_cmplt_struct_t;
276 /*! @brief Define message structure for REMOTE_NDIS_RESET_CMPLT. */
277 typedef struct _rndis_reset_cmplt_struct
278 {
279     uint32_t messageType;
280     uint32_t messageLength;
281     uint32_t status;
282     uint32_t addressingReset;
283 } rndis_reset_cmplt_struct_t;
284 
285 /*! @brief Define message structure for REMOTE_NDIS_KEEPALIVE_CMPLT. */
286 typedef struct _rndis_keepalive_cmplt_struct
287 {
288     uint32_t messageType;
289     uint32_t messageLength;
290     uint32_t requestID;
291     uint32_t status;
292 } rndis_keepalive_cmplt_struct_t;
293 /*! @brief Define message structure for RNDIS_PACKET_MSG. */
294 typedef struct _rndis_packet_msg_struct
295 {
296     uint32_t messageType;
297     uint32_t messageLength;
298     uint32_t dataOffset;
299     uint32_t dataLength;
300     uint32_t oobDataOffset;
301     uint32_t oobDataLength;
302     uint32_t numOOBDataElements;
303     uint32_t perPacketInfoOffset;
304     uint32_t perPacketInfoLength;
305     uint32_t vcHandle;
306     uint32_t reserved;
307     uint8_t dataBuffer[RNDIS_FRAME_MAX_FRAMELEN];
308 } rndis_packet_msg_struct_t;
309 /*! @brief Define RNDIS state. See MSDN for details. */
310 typedef enum _rndis_state_enum
311 {
312     /*! The host operating system is running, the device is connected to the host via the chosen
313      *bus transport, and the host is not yet configured to exchange any RNDIS messages.
314      */
315     RNDIS_UNINITIALIZED = 0,
316     /*! The host has successfully mapped and initialized the RNDIS protocol data and control channels
317      *on the bus transport
318      */
319     RNDIS_BUS_UNINITIALIZED,
320     /*!The host is configured to send and receive any of the RNDIS control messages for suitably
321      *configuring or querying the device, to receive status indications from the device, to reset
322      *the device, or to tear down the data and control channels.
323      */
324     RNDIS_INITIALIZED,
325     /*! This state is entered after the host has received REMOTE_NDIS_SET_CMPLT messages from the
326      *device in response to the REMOTE_NDIS_SET_MSG.
327      */
328     RNDIS_DATA_INITIALIZED,
329 } rndis_state_enum_t;
330 typedef struct _usb_host_rndis
331 {
332     usb_host_handle hostHandle;     /*!< This instance's related host handle.*/
333     usb_device_handle deviceHandle; /*!< This instance's related device handle.*/
334     uint32_t effective_version; /*!< The highest matching MajorVersion and MinorVersion values of the RNDIS protocol.*/
335     uint32_t max_transfer_size; /*!< The maximum size of the RNDIS message that can be exchanged between the host and
336                                    the device.*/
337     uint32_t max_packet_per_transaction; /*!< The maximum number of network packets per bus transaction.*/
338     uint32_t byte_alignmnet;             /*!< The byte alignment requirements in multi-packet transfers.*/
339 } usb_host_rndis_struct;
340 #ifdef __cplusplus
341 extern "C" {
342 #endif
343 
344 /*******************************************************************************
345  * API
346  ******************************************************************************/
347 
348 /*!
349  * @name USB CDC host class driver
350  * @{
351  */
352 extern usb_status_t USB_HostRndisInitMsg(usb_host_class_handle classHandle,
353                                          uint8_t *messageBuffer,
354                                          uint32_t messageBufferLength,
355                                          transfer_callback_t callbackFn,
356                                          void *callbackParam);
357 
358 extern usb_status_t USB_HostRndisQueryMsg(usb_host_class_handle classHandle,
359                                           uint32_t Oid,
360                                           uint8_t *messageBuffer,
361                                           uint32_t messageBufferLength,
362                                           uint32_t informationOffset,
363                                           uint32_t informationLength,
364                                           uint8_t *OIDInputBuffer,
365                                           transfer_callback_t callbackFn,
366                                           void *callbackParam);
367 extern usb_status_t USB_HostRndisSetMsg(usb_host_class_handle classHandle,
368                                         uint32_t Oid,
369                                         uint8_t *messageBuffer,
370                                         uint32_t messageBufferLength,
371                                         uint32_t informationOffset,
372                                         uint32_t informationLength,
373                                         uint32_t *OIDInputBuffer,
374                                         transfer_callback_t callbackFn,
375                                         void *callbackParam);
376 
377 extern usb_status_t USB_HostRndisHaltMsg(usb_host_class_handle classHandle,
378                                          uint8_t *messageBuffer,
379                                          uint32_t messageBufferLength,
380                                          transfer_callback_t callbackFn,
381                                          void *callbackParam);
382 
383 extern usb_status_t USB_HostRndisResetMsg(usb_host_class_handle classHandle,
384                                           uint8_t *messageBuffer,
385                                           uint32_t messageBufferLength,
386                                           transfer_callback_t callbackFn,
387                                           void *callbackParam);
388 extern usb_status_t USB_HostRndisSendDataMsg(usb_host_class_handle classHandle,
389                                              uint8_t *messageBuffer,
390                                              uint32_t messageBufferLength,
391                                              uint32_t oobDataOffset,
392                                              uint32_t oobDataLength,
393                                              uint32_t numOOBDataElements,
394                                              uint32_t perPacketInfoOffset,
395                                              uint32_t perPacketInfoLength,
396                                              uint8_t *dataBuffer,
397                                              uint32_t dataLength,
398                                              transfer_callback_t callbackFn,
399                                              void *callbackParam);
400 extern usb_status_t USB_HostRndisRecvDataMsg(usb_host_class_handle classHandle,
401                                              uint8_t *buffer,
402                                              uint32_t bufferLength,
403                                              transfer_callback_t callbackFn,
404                                              void *callbackParam);
405 /*@}*/
406 
407 #ifdef __cplusplus
408 }
409 #endif
410 /*@}*/
411 
412 #endif /*__USB_HOST_CDC_H__*/
413