3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
31 /** \ingroup Group_USBDeviceClassDrivers
32 * @defgroup Group_USBClassRNDISDevice RNDIS Device Class Driver - LUFA/Drivers/Class/Device/RNDIS.h
34 * \section Sec_Dependencies Module Source Dependencies
35 * The following files must be built with any user project that uses this module:
36 * - LUFA/Drivers/USB/Class/Device/HID.c
38 * \section Module Description
39 * Functions, macros, variables, enums and types related to the management of USB RNDIS Ethernet
40 * interfaces within a USB device.
45 #ifndef _RNDIS_CLASS_H_
46 #define _RNDIS_CLASS_H_
51 #include "../../USB.h"
52 #include "RNDISConstants.h"
54 /* Enable C linkage for C++ Compilers: */
55 #if defined(__cplusplus)
60 /** Implemented RNDIS Version Major */
61 #define REMOTE_NDIS_VERSION_MAJOR 0x01
63 /** Implemented RNDIS Version Minor */
64 #define REMOTE_NDIS_VERSION_MINOR 0x00
66 /** RNDIS request to issue a host-to-device NDIS command */
67 #define REQ_SendEncapsulatedCommand 0x00
69 /** RNDIS request to issue a device-to-host NDIS response */
70 #define REQ_GetEncapsulatedResponse 0x01
72 #define RNDIS_MESSAGE_BUFFER_SIZE 128
74 #define ETHERNET_FRAME_SIZE_MAX 1500
76 #define NOTIF_ResponseAvailable 1
79 /** Enum for the possible NDIS adapter states. */
82 RNDIS_Uninitialized
= 0, /**< Adapter currently uninitialized */
83 RNDIS_Initialized
= 1, /**< Adapter currently initialized but not ready for data transfers */
84 RNDIS_Data_Initialized
= 2, /**< Adapter currently initialized and ready for data transfers */
87 /** Enum for the NDIS hardware states */
88 enum NDIS_Hardware_Status_t
90 NdisHardwareStatusReady
, /**< Hardware Ready to accept commands from the host */
91 NdisHardwareStatusInitializing
, /**< Hardware busy initializing */
92 NdisHardwareStatusReset
, /**< Hardware reset */
93 NdisHardwareStatusClosing
, /**< Hardware currently closing */
94 NdisHardwareStatusNotReady
/**< Hardware not ready to accept commands from the host */
98 /** Type define for a physical MAC address of a device on a network */
101 uint8_t Octets
[6]; /**< Individual bytes of a MAC address */
104 /** Type define for a RNDIS message header, sent before RNDIS messages */
107 uint32_t MessageType
; /**< RNDIS message type, a REMOTE_NDIS_*_MSG constant */
108 uint32_t MessageLength
; /**< Total length of the RNDIS message, in bytes */
109 } RNDIS_Message_Header_t
;
111 /** Type define for an Ethernet frame buffer. */
114 uint8_t FrameData
[ETHERNET_FRAME_SIZE_MAX
]; /**< Ethernet frame contents */
115 uint16_t FrameLength
; /**< Length in bytes of the Ethernet frame stored in the buffer */
116 bool FrameInBuffer
; /**< Indicates if a frame is currently stored in the buffer */
117 } Ethernet_Frame_Info_t
;
119 /** Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter */
122 uint32_t MessageType
;
123 uint32_t MessageLength
;
126 uint32_t OOBDataOffset
;
127 uint32_t OOBDataLength
;
128 uint32_t NumOOBDataElements
;
129 uint32_t PerPacketInfoOffset
;
130 uint32_t PerPacketInfoLength
;
133 } RNDIS_PACKET_MSG_t
;
137 uint8_t ControlInterfaceNumber
; /**< Interface number of the CDC control interface within the device */
139 uint8_t DataINEndpointNumber
; /**< Endpoint number of the CDC interface's IN data endpoint */
140 uint16_t DataINEndpointSize
; /**< Size in bytes of the CDC interface's IN data endpoint */
142 uint8_t DataOUTEndpointNumber
; /**< Endpoint number of the CDC interface's OUT data endpoint */
143 uint16_t DataOUTEndpointSize
; /**< Size in bytes of the CDC interface's OUT data endpoint */
145 uint8_t NotificationEndpointNumber
; /**< Endpoint number of the CDC interface's IN notification endpoint, if used */
146 uint16_t NotificationEndpointSize
; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */
148 char* AdapterVendorDescription
;
149 MAC_Address_t AdapterMACAddress
;
151 uint8_t RNDISMessageBuffer
[RNDIS_MESSAGE_BUFFER_SIZE
];
153 uint8_t CurrRNDISState
;
154 uint32_t CurrPacketFilter
;
155 Ethernet_Frame_Info_t FrameIN
;
156 Ethernet_Frame_Info_t FrameOUT
;
157 } USB_ClassInfo_RNDIS_t
;
159 /** Type define for a RNDIS Initialize command message */
162 uint32_t MessageType
;
163 uint32_t MessageLength
;
166 uint32_t MajorVersion
;
167 uint32_t MinorVersion
;
168 uint32_t MaxTransferSize
;
169 } RNDIS_INITIALIZE_MSG_t
;
171 /** Type define for a RNDIS Initialize complete response message */
174 uint32_t MessageType
;
175 uint32_t MessageLength
;
179 uint32_t MajorVersion
;
180 uint32_t MinorVersion
;
181 uint32_t DeviceFlags
;
183 uint32_t MaxPacketsPerTransfer
;
184 uint32_t MaxTransferSize
;
185 uint32_t PacketAlignmentFactor
;
186 uint32_t AFListOffset
;
188 } RNDIS_INITIALIZE_CMPLT_t
;
190 /** Type define for a RNDIS Keepalive command message */
193 uint32_t MessageType
;
194 uint32_t MessageLength
;
196 } RNDIS_KEEPALIVE_MSG_t
;
198 /** Type define for a RNDIS Keepalive complete message */
201 uint32_t MessageType
;
202 uint32_t MessageLength
;
205 } RNDIS_KEEPALIVE_CMPLT_t
;
207 /** Type define for a RNDIS Reset complete message */
210 uint32_t MessageType
;
211 uint32_t MessageLength
;
214 uint32_t AddressingReset
;
215 } RNDIS_RESET_CMPLT_t
;
217 /** Type define for a RNDIS Set command message */
220 uint32_t MessageType
;
221 uint32_t MessageLength
;
225 uint32_t InformationBufferLength
;
226 uint32_t InformationBufferOffset
;
227 uint32_t DeviceVcHandle
;
230 /** Type define for a RNDIS Set complete response message */
233 uint32_t MessageType
;
234 uint32_t MessageLength
;
239 /** Type define for a RNDIS Query command message */
242 uint32_t MessageType
;
243 uint32_t MessageLength
;
247 uint32_t InformationBufferLength
;
248 uint32_t InformationBufferOffset
;
249 uint32_t DeviceVcHandle
;
252 /** Type define for a RNDIS Query complete response message */
255 uint32_t MessageType
;
256 uint32_t MessageLength
;
260 uint32_t InformationBufferLength
;
261 uint32_t InformationBufferOffset
;
262 } RNDIS_QUERY_CMPLT_t
;
264 /* Function Prototypes: */
265 #if defined(INCLUDE_FROM_RNDIS_CLASS_C)
266 static void USB_RNDIS_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
267 static bool USB_RNDIS_ProcessNDISQuery(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
,
268 uint32_t OId
, void* QueryData
, uint16_t QuerySize
,
269 void* ResponseData
, uint16_t* ResponseSize
);
270 static bool USB_RNDIS_ProcessNDISSet(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
, uint32_t OId
,
271 void* SetData
, uint16_t SetSize
);
274 bool USB_RNDIS_ConfigureEndpoints(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
275 void USB_RNDIS_ProcessControlPacket(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
276 void USB_RNDIS_USBTask(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
278 /* Disable C linkage for C++ Compilers: */
279 #if defined(__cplusplus)