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 CDC class-specific code, Base Class E0h (Wireless Controller) */
148 #define USB_HOST_CDC_RNDIS_CLASS_CODE 0xE0U
149 /*! @brief RF Controller*/
150 #define USB_HOST_CDC_RNDIS_SUBCLASS_CODE 0x01U
151 /*Remote NDIS. */
152 #define USB_HOST_CDC_RNDIS_PROTOCOL_CODE 0x03U
153 
154 /*this is the minimum byte length of the buffer posted by host*/
155 
156 /*******************************************************************************
157  * RNDS class public structure, enumeration, macro, function
158  ******************************************************************************/
159 /*! @brief Define message structure for REMOTE_NDIS_INITIALIZE_MSG. */
160 typedef struct _rndis_init_msg_struct
161 {
162     uint32_t messageType;
163     uint32_t messageLength;
164     uint32_t requestID;
165     uint32_t majorVersion;
166     uint32_t minorVersion;
167     uint32_t maxTransferSize;
168 } rndis_init_msg_struct_t;
169 /*! @brief Define message structure for REMOTE_NDIS_HALT_MSG. */
170 typedef struct _rndis_halt_msg_struct
171 {
172     uint32_t messageType;
173     uint32_t messageLength;
174     uint32_t requestID;
175 } rndis_halt_msg_struct_t;
176 /*! @brief Define message structure for REMOTE_NDIS_QUERY_MSG. */
177 typedef struct _rndis_query_msg_struct
178 {
179     uint32_t messageType;
180     uint32_t messageLength;
181     uint32_t requestID;
182     uint32_t oid;
183     uint32_t informationBufferLength;
184     uint32_t informationBufferOffset;
185     uint32_t deviceVcHandle;
186 } rndis_query_msg_struct_t;
187 /*! @brief Define message structure for REMOTE_NDIS_SET_MSG. */
188 typedef struct _rndis_set_msg_struct
189 {
190     uint32_t messageType;
191     uint32_t messageLength;
192     uint32_t requestID;
193     uint32_t oid;
194     uint32_t informationBufferLength;
195     uint32_t informationBufferOffset;
196     uint32_t deviceVcHandle;
197 } rndis_set_msg_struct_t;
198 /*! @brief Define message structure for REMOTE_NDIS_RESET_MSG. */
199 typedef struct _rndis_reset_msg_struct
200 {
201     uint32_t messageType;
202     uint32_t messageLength;
203     uint32_t Reserved;
204 } rndis_reset_msg_struct_t;
205 /*! @brief Define message structure for REMOTE_NDIS_INDICATE_STATUS_MSG. */
206 typedef struct _rndis_indicate_status_msg_struct
207 {
208     uint32_t messageType;
209     uint32_t messageLength;
210     uint32_t status;
211     uint32_t statusBufferLength;
212     uint32_t statusBufferOffset;
213 } rndis_indicate_status_msg_struct_t;
214 /*! @brief Define message structure for REMOTE_NDIS_DIAGNOSTIC_MSG. */
215 typedef struct _rndis_diagnostic_msg_struct
216 {
217     uint32_t DiagStatus;
218     uint32_t ErrorOffset;
219 } rndis_diagnostic_msg_struct_t;
220 /*! @brief Define message structure for REMOTE_NDIS_KEEPALIVE_MSG. */
221 typedef struct _rndis_keepalive_msg_struct
222 {
223     uint32_t messageType;
224     uint32_t messageLength;
225     uint32_t requestID;
226 } rndis_keepalive_msg_struct_t;
227 /*! @brief Define message structure for REMOTE_NDIS_INITIALIZE_CMPLT. */
228 typedef struct _rndis_init_cmplt_struct
229 {
230     uint32_t messageType;
231     uint32_t messageLength;
232     uint32_t requestID;
233     uint32_t status;
234     uint32_t majorVersion;
235     uint32_t minorVersion;
236     uint32_t deviceFlags;
237     uint32_t medium;
238     uint32_t maxPacketsPerTransfer;
239     uint32_t maxTransferSize;
240     uint32_t packetAlignmentFactor;
241     uint32_t afListOffset;
242     uint32_t afListSize;
243 } rndis_init_cmplt_struct_t;
244 /*! @brief Define message structure for REMOTE_NDIS_QUERY_CMPLT. */
245 typedef struct _rndis_query_cmplt_struct
246 {
247     uint32_t messageType;
248     uint32_t messageLength;
249     uint32_t requestID;
250     uint32_t status;
251     uint32_t informationBufferLength;
252     uint32_t informationBufferOffset;
253 } rndis_query_cmplt_struct_t;
254 /*! @brief Define message structure for REMOTE_NDIS_SET_CMPLT. */
255 typedef struct _rndis_set_cmplt_struct
256 {
257     uint32_t messageType;
258     uint32_t messageLength;
259     uint32_t requestID;
260     uint32_t status;
261 } rndis_set_cmplt_struct_t;
262 /*! @brief Define message structure for REMOTE_NDIS_RESET_CMPLT. */
263 typedef struct _rndis_reset_cmplt_struct
264 {
265     uint32_t messageType;
266     uint32_t messageLength;
267     uint32_t status;
268     uint32_t addressingReset;
269 } rndis_reset_cmplt_struct_t;
270 
271 /*! @brief Define message structure for REMOTE_NDIS_KEEPALIVE_CMPLT. */
272 typedef struct _rndis_keepalive_cmplt_struct
273 {
274     uint32_t messageType;
275     uint32_t messageLength;
276     uint32_t requestID;
277     uint32_t status;
278 } rndis_keepalive_cmplt_struct_t;
279 /*! @brief Define message structure for RNDIS_PACKET_MSG. */
280 typedef struct _rndis_packet_msg_struct
281 {
282     uint32_t messageType;
283     uint32_t messageLength;
284     uint32_t dataOffset;
285     uint32_t dataLength;
286     uint32_t oobDataOffset;
287     uint32_t oobDataLength;
288     uint32_t numOOBDataElements;
289     uint32_t perPacketInfoOffset;
290     uint32_t perPacketInfoLength;
291     uint32_t vcHandle;
292     uint32_t reserved;
293     uint8_t dataBuffer[RNDIS_FRAME_MAX_FRAMELEN];
294 } rndis_packet_msg_struct_t;
295 /*! @brief Define RNDIS state. See MSDN for details. */
296 typedef enum _rndis_state_enum
297 {
298     /*! The host operating system is running, the device is connected to the host via the chosen
299      *bus transport, and the host is not yet configured to exchange any RNDIS messages.
300      */
301     RNDIS_UNINITIALIZED = 0,
302     /*! The host has successfully mapped and initialized the RNDIS protocol data and control channels
303      *on the bus transport
304      */
305     RNDIS_BUS_UNINITIALIZED,
306     /*!The host is configured to send and receive any of the RNDIS control messages for suitably
307      *configuring or querying the device, to receive status indications from the device, to reset
308      *the device, or to tear down the data and control channels.
309      */
310     RNDIS_INITIALIZED,
311     /*! This state is entered after the host has received REMOTE_NDIS_SET_CMPLT messages from the
312      *device in response to the REMOTE_NDIS_SET_MSG.
313      */
314     RNDIS_DATA_INITIALIZED,
315 } rndis_state_enum_t;
316 typedef struct _usb_host_rndis
317 {
318     usb_host_handle hostHandle;     /*!< This instance's related host handle.*/
319     usb_device_handle deviceHandle; /*!< This instance's related device handle.*/
320     uint32_t effective_version; /*!< The highest matching MajorVersion and MinorVersion values of the RNDIS protocol.*/
321     uint32_t max_transfer_size; /*!< The maximum size of the RNDIS message that can be exchanged between the host and
322                                    the device.*/
323     uint32_t max_packet_per_transaction; /*!< The maximum number of network packets per bus transaction.*/
324     uint32_t byte_alignmnet;             /*!< The byte alignment requirements in multi-packet transfers.*/
325 } usb_host_rndis_struct;
326 #ifdef __cplusplus
327 extern "C" {
328 #endif
329 
330 /*******************************************************************************
331  * API
332  ******************************************************************************/
333 
334 /*!
335  * @name USB CDC host class driver
336  * @{
337  */
338 extern usb_status_t USB_HostRndisInitMsg(usb_host_class_handle classHandle,
339                                          uint8_t *messageBuffer,
340                                          uint32_t messageBufferLength,
341                                          transfer_callback_t callbackFn,
342                                          void *callbackParam);
343 
344 extern usb_status_t USB_HostRndisQueryMsg(usb_host_class_handle classHandle,
345                                           uint32_t Oid,
346                                           uint8_t *messageBuffer,
347                                           uint32_t messageBufferLength,
348                                           uint32_t informationOffset,
349                                           uint32_t informationLength,
350                                           uint8_t *OIDInputBuffer,
351                                           transfer_callback_t callbackFn,
352                                           void *callbackParam);
353 extern usb_status_t USB_HostRndisSetMsg(usb_host_class_handle classHandle,
354                                         uint32_t Oid,
355                                         uint8_t *messageBuffer,
356                                         uint32_t messageBufferLength,
357                                         uint32_t informationOffset,
358                                         uint32_t informationLength,
359                                         uint32_t *OIDInputBuffer,
360                                         transfer_callback_t callbackFn,
361                                         void *callbackParam);
362 
363 extern usb_status_t USB_HostRndisHaltMsg(usb_host_class_handle classHandle,
364                                          uint8_t *messageBuffer,
365                                          uint32_t messageBufferLength,
366                                          transfer_callback_t callbackFn,
367                                          void *callbackParam);
368 
369 extern usb_status_t USB_HostRndisResetMsg(usb_host_class_handle classHandle,
370                                           uint8_t *messageBuffer,
371                                           uint32_t messageBufferLength,
372                                           transfer_callback_t callbackFn,
373                                           void *callbackParam);
374 extern usb_status_t USB_HostRndisSendDataMsg(usb_host_class_handle classHandle,
375                                              uint8_t *messageBuffer,
376                                              uint32_t messageBufferLength,
377                                              uint32_t oobDataOffset,
378                                              uint32_t oobDataLength,
379                                              uint32_t numOOBDataElements,
380                                              uint32_t perPacketInfoOffset,
381                                              uint32_t perPacketInfoLength,
382                                              uint8_t *dataBuffer,
383                                              uint32_t dataLength,
384                                              transfer_callback_t callbackFn,
385                                              void *callbackParam);
386 extern usb_status_t USB_HostRndisRecvDataMsg(usb_host_class_handle classHandle,
387                                              uint8_t *buffer,
388                                              uint32_t bufferLength,
389                                              transfer_callback_t callbackFn,
390                                              void *callbackParam);
391 /*@}*/
392 
393 #ifdef __cplusplus
394 }
395 #endif
396 /*@}*/
397 
398 #endif /*__USB_HOST_CDC_H__*/
399