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 #ifndef _RNDIS_CLASS_H_
32 #define _RNDIS_CLASS_H_
37 #include "../../USB.h"
38 #include "RNDISConstants.h"
41 /** Implemented RNDIS Version Major */
42 #define REMOTE_NDIS_VERSION_MAJOR 0x01
44 /** Implemented RNDIS Version Minor */
45 #define REMOTE_NDIS_VERSION_MINOR 0x00
47 /** RNDIS request to issue a host-to-device NDIS command */
48 #define REQ_SendEncapsulatedCommand 0x00
50 /** RNDIS request to issue a device-to-host NDIS response */
51 #define REQ_GetEncapsulatedResponse 0x01
53 #define RNDIS_MESSAGE_BUFFER_SIZE 128
55 #define ETHERNET_FRAME_SIZE_MAX 1500
57 #define NOTIF_ResponseAvailable 1
60 /** Enum for the possible NDIS adapter states. */
63 RNDIS_Uninitialized
= 0, /**< Adapter currently uninitialized */
64 RNDIS_Initialized
= 1, /**< Adapter currently initialized but not ready for data transfers */
65 RNDIS_Data_Initialized
= 2, /**< Adapter currently initialized and ready for data transfers */
68 /** Enum for the NDIS hardware states */
69 enum NDIS_Hardware_Status_t
71 NdisHardwareStatusReady
, /**< Hardware Ready to accept commands from the host */
72 NdisHardwareStatusInitializing
, /**< Hardware busy initializing */
73 NdisHardwareStatusReset
, /**< Hardware reset */
74 NdisHardwareStatusClosing
, /**< Hardware currently closing */
75 NdisHardwareStatusNotReady
/**< Hardware not ready to accept commands from the host */
79 /** Type define for a physical MAC address of a device on a network */
82 uint8_t Octets
[6]; /**< Individual bytes of a MAC address */
85 /** Type define for a RNDIS message header, sent before RNDIS messages */
88 uint32_t MessageType
; /**< RNDIS message type, a REMOTE_NDIS_*_MSG constant */
89 uint32_t MessageLength
; /**< Total length of the RNDIS message, in bytes */
90 } RNDIS_Message_Header_t
;
92 /** Type define for an Ethernet frame buffer. */
95 uint8_t FrameData
[ETHERNET_FRAME_SIZE_MAX
]; /**< Ethernet frame contents */
96 uint16_t FrameLength
; /**< Length in bytes of the Ethernet frame stored in the buffer */
97 bool FrameInBuffer
; /**< Indicates if a frame is currently stored in the buffer */
98 } Ethernet_Frame_Info_t
;
100 /** Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter */
103 uint32_t MessageType
;
104 uint32_t MessageLength
;
107 uint32_t OOBDataOffset
;
108 uint32_t OOBDataLength
;
109 uint32_t NumOOBDataElements
;
110 uint32_t PerPacketInfoOffset
;
111 uint32_t PerPacketInfoLength
;
114 } RNDIS_PACKET_MSG_t
;
118 uint8_t ControlInterfaceNumber
; /**< Interface number of the CDC control interface within the device */
120 uint8_t DataINEndpointNumber
; /**< Endpoint number of the CDC interface's IN data endpoint */
121 uint16_t DataINEndpointSize
; /**< Size in bytes of the CDC interface's IN data endpoint */
123 uint8_t DataOUTEndpointNumber
; /**< Endpoint number of the CDC interface's OUT data endpoint */
124 uint16_t DataOUTEndpointSize
; /**< Size in bytes of the CDC interface's OUT data endpoint */
126 uint8_t NotificationEndpointNumber
; /**< Endpoint number of the CDC interface's IN notification endpoint, if used */
127 uint16_t NotificationEndpointSize
; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */
129 char* AdapterVendorDescription
;
130 MAC_Address_t AdapterMACAddress
;
132 uint8_t RNDISMessageBuffer
[RNDIS_MESSAGE_BUFFER_SIZE
];
134 uint8_t CurrRNDISState
;
135 uint32_t CurrPacketFilter
;
136 Ethernet_Frame_Info_t FrameIN
;
137 Ethernet_Frame_Info_t FrameOUT
;
138 } USB_ClassInfo_RNDIS_t
;
140 /** Type define for a RNDIS Initialize command message */
143 uint32_t MessageType
;
144 uint32_t MessageLength
;
147 uint32_t MajorVersion
;
148 uint32_t MinorVersion
;
149 uint32_t MaxTransferSize
;
150 } RNDIS_INITIALIZE_MSG_t
;
152 /** Type define for a RNDIS Initialize complete response message */
155 uint32_t MessageType
;
156 uint32_t MessageLength
;
160 uint32_t MajorVersion
;
161 uint32_t MinorVersion
;
162 uint32_t DeviceFlags
;
164 uint32_t MaxPacketsPerTransfer
;
165 uint32_t MaxTransferSize
;
166 uint32_t PacketAlignmentFactor
;
167 uint32_t AFListOffset
;
169 } RNDIS_INITIALIZE_CMPLT_t
;
171 /** Type define for a RNDIS Keepalive command message */
174 uint32_t MessageType
;
175 uint32_t MessageLength
;
177 } RNDIS_KEEPALIVE_MSG_t
;
179 /** Type define for a RNDIS Keepalive complete message */
182 uint32_t MessageType
;
183 uint32_t MessageLength
;
186 } RNDIS_KEEPALIVE_CMPLT_t
;
188 /** Type define for a RNDIS Reset complete message */
191 uint32_t MessageType
;
192 uint32_t MessageLength
;
195 uint32_t AddressingReset
;
196 } RNDIS_RESET_CMPLT_t
;
198 /** Type define for a RNDIS Set command message */
201 uint32_t MessageType
;
202 uint32_t MessageLength
;
206 uint32_t InformationBufferLength
;
207 uint32_t InformationBufferOffset
;
208 uint32_t DeviceVcHandle
;
211 /** Type define for a RNDIS Set complete response message */
214 uint32_t MessageType
;
215 uint32_t MessageLength
;
220 /** Type define for a RNDIS Query command message */
223 uint32_t MessageType
;
224 uint32_t MessageLength
;
228 uint32_t InformationBufferLength
;
229 uint32_t InformationBufferOffset
;
230 uint32_t DeviceVcHandle
;
233 /** Type define for a RNDIS Query complete response message */
236 uint32_t MessageType
;
237 uint32_t MessageLength
;
241 uint32_t InformationBufferLength
;
242 uint32_t InformationBufferOffset
;
243 } RNDIS_QUERY_CMPLT_t
;
245 /* Function Prototypes: */
246 #if defined(INCLUDE_FROM_RNDIS_CLASS_C)
247 static void USB_RNDIS_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
248 static bool USB_RNDIS_ProcessNDISQuery(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
,
249 uint32_t OId
, void* QueryData
, uint16_t QuerySize
,
250 void* ResponseData
, uint16_t* ResponseSize
);
251 static bool USB_RNDIS_ProcessNDISSet(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
, uint32_t OId
,
252 void* SetData
, uint16_t SetSize
);
255 void USB_RNDIS_USBTask(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
256 bool USB_RNDIS_ConfigureEndpoints(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
257 void USB_RNDIS_ProcessControlPacket(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
258 void USB_RNDIS_USBTask(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);