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"
40 /* Enable C linkage for C++ Compilers: */
41 #if defined(__cplusplus)
46 /** Implemented RNDIS Version Major */
47 #define REMOTE_NDIS_VERSION_MAJOR 0x01
49 /** Implemented RNDIS Version Minor */
50 #define REMOTE_NDIS_VERSION_MINOR 0x00
52 /** RNDIS request to issue a host-to-device NDIS command */
53 #define REQ_SendEncapsulatedCommand 0x00
55 /** RNDIS request to issue a device-to-host NDIS response */
56 #define REQ_GetEncapsulatedResponse 0x01
58 #define RNDIS_MESSAGE_BUFFER_SIZE 128
60 #define ETHERNET_FRAME_SIZE_MAX 1500
62 #define NOTIF_ResponseAvailable 1
65 /** Enum for the possible NDIS adapter states. */
68 RNDIS_Uninitialized
= 0, /**< Adapter currently uninitialized */
69 RNDIS_Initialized
= 1, /**< Adapter currently initialized but not ready for data transfers */
70 RNDIS_Data_Initialized
= 2, /**< Adapter currently initialized and ready for data transfers */
73 /** Enum for the NDIS hardware states */
74 enum NDIS_Hardware_Status_t
76 NdisHardwareStatusReady
, /**< Hardware Ready to accept commands from the host */
77 NdisHardwareStatusInitializing
, /**< Hardware busy initializing */
78 NdisHardwareStatusReset
, /**< Hardware reset */
79 NdisHardwareStatusClosing
, /**< Hardware currently closing */
80 NdisHardwareStatusNotReady
/**< Hardware not ready to accept commands from the host */
84 /** Type define for a physical MAC address of a device on a network */
87 uint8_t Octets
[6]; /**< Individual bytes of a MAC address */
90 /** Type define for a RNDIS message header, sent before RNDIS messages */
93 uint32_t MessageType
; /**< RNDIS message type, a REMOTE_NDIS_*_MSG constant */
94 uint32_t MessageLength
; /**< Total length of the RNDIS message, in bytes */
95 } RNDIS_Message_Header_t
;
97 /** Type define for an Ethernet frame buffer. */
100 uint8_t FrameData
[ETHERNET_FRAME_SIZE_MAX
]; /**< Ethernet frame contents */
101 uint16_t FrameLength
; /**< Length in bytes of the Ethernet frame stored in the buffer */
102 bool FrameInBuffer
; /**< Indicates if a frame is currently stored in the buffer */
103 } Ethernet_Frame_Info_t
;
105 /** Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter */
108 uint32_t MessageType
;
109 uint32_t MessageLength
;
112 uint32_t OOBDataOffset
;
113 uint32_t OOBDataLength
;
114 uint32_t NumOOBDataElements
;
115 uint32_t PerPacketInfoOffset
;
116 uint32_t PerPacketInfoLength
;
119 } RNDIS_PACKET_MSG_t
;
123 uint8_t ControlInterfaceNumber
; /**< Interface number of the CDC control interface within the device */
125 uint8_t DataINEndpointNumber
; /**< Endpoint number of the CDC interface's IN data endpoint */
126 uint16_t DataINEndpointSize
; /**< Size in bytes of the CDC interface's IN data endpoint */
128 uint8_t DataOUTEndpointNumber
; /**< Endpoint number of the CDC interface's OUT data endpoint */
129 uint16_t DataOUTEndpointSize
; /**< Size in bytes of the CDC interface's OUT data endpoint */
131 uint8_t NotificationEndpointNumber
; /**< Endpoint number of the CDC interface's IN notification endpoint, if used */
132 uint16_t NotificationEndpointSize
; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */
134 char* AdapterVendorDescription
;
135 MAC_Address_t AdapterMACAddress
;
137 uint8_t RNDISMessageBuffer
[RNDIS_MESSAGE_BUFFER_SIZE
];
139 uint8_t CurrRNDISState
;
140 uint32_t CurrPacketFilter
;
141 Ethernet_Frame_Info_t FrameIN
;
142 Ethernet_Frame_Info_t FrameOUT
;
143 } USB_ClassInfo_RNDIS_t
;
145 /** Type define for a RNDIS Initialize command message */
148 uint32_t MessageType
;
149 uint32_t MessageLength
;
152 uint32_t MajorVersion
;
153 uint32_t MinorVersion
;
154 uint32_t MaxTransferSize
;
155 } RNDIS_INITIALIZE_MSG_t
;
157 /** Type define for a RNDIS Initialize complete response message */
160 uint32_t MessageType
;
161 uint32_t MessageLength
;
165 uint32_t MajorVersion
;
166 uint32_t MinorVersion
;
167 uint32_t DeviceFlags
;
169 uint32_t MaxPacketsPerTransfer
;
170 uint32_t MaxTransferSize
;
171 uint32_t PacketAlignmentFactor
;
172 uint32_t AFListOffset
;
174 } RNDIS_INITIALIZE_CMPLT_t
;
176 /** Type define for a RNDIS Keepalive command message */
179 uint32_t MessageType
;
180 uint32_t MessageLength
;
182 } RNDIS_KEEPALIVE_MSG_t
;
184 /** Type define for a RNDIS Keepalive complete message */
187 uint32_t MessageType
;
188 uint32_t MessageLength
;
191 } RNDIS_KEEPALIVE_CMPLT_t
;
193 /** Type define for a RNDIS Reset complete message */
196 uint32_t MessageType
;
197 uint32_t MessageLength
;
200 uint32_t AddressingReset
;
201 } RNDIS_RESET_CMPLT_t
;
203 /** Type define for a RNDIS Set command message */
206 uint32_t MessageType
;
207 uint32_t MessageLength
;
211 uint32_t InformationBufferLength
;
212 uint32_t InformationBufferOffset
;
213 uint32_t DeviceVcHandle
;
216 /** Type define for a RNDIS Set complete response message */
219 uint32_t MessageType
;
220 uint32_t MessageLength
;
225 /** Type define for a RNDIS Query command message */
228 uint32_t MessageType
;
229 uint32_t MessageLength
;
233 uint32_t InformationBufferLength
;
234 uint32_t InformationBufferOffset
;
235 uint32_t DeviceVcHandle
;
238 /** Type define for a RNDIS Query complete response message */
241 uint32_t MessageType
;
242 uint32_t MessageLength
;
246 uint32_t InformationBufferLength
;
247 uint32_t InformationBufferOffset
;
248 } RNDIS_QUERY_CMPLT_t
;
250 /* Function Prototypes: */
251 #if defined(INCLUDE_FROM_RNDIS_CLASS_C)
252 static void USB_RNDIS_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
253 static bool USB_RNDIS_ProcessNDISQuery(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
,
254 uint32_t OId
, void* QueryData
, uint16_t QuerySize
,
255 void* ResponseData
, uint16_t* ResponseSize
);
256 static bool USB_RNDIS_ProcessNDISSet(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
, uint32_t OId
,
257 void* SetData
, uint16_t SetSize
);
260 bool USB_RNDIS_ConfigureEndpoints(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
261 void USB_RNDIS_ProcessControlPacket(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
262 void USB_RNDIS_USBTask(USB_ClassInfo_RNDIS_t
* RNDISInterfaceInfo
);
264 /* Disable C linkage for C++ Compilers: */
265 #if defined(__cplusplus)