Synchronise with the 090605 release.
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / RNDIS.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 /** \ingroup Group_USBDeviceClassDrivers
32 * @defgroup Group_USBClassRNDISDevice RNDIS Device Class Driver - LUFA/Drivers/Class/Device/RNDIS.h
33 *
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
37 *
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.
41 *
42 * @{
43 */
44
45 #ifndef _RNDIS_CLASS_H_
46 #define _RNDIS_CLASS_H_
47
48 /* Includes: */
49 #include <string.h>
50
51 #include "../../USB.h"
52 #include "RNDISConstants.h"
53
54 /* Enable C linkage for C++ Compilers: */
55 #if defined(__cplusplus)
56 extern "C" {
57 #endif
58
59 /* Macros: */
60 /** Implemented RNDIS Version Major */
61 #define REMOTE_NDIS_VERSION_MAJOR 0x01
62
63 /** Implemented RNDIS Version Minor */
64 #define REMOTE_NDIS_VERSION_MINOR 0x00
65
66 /** RNDIS request to issue a host-to-device NDIS command */
67 #define REQ_SendEncapsulatedCommand 0x00
68
69 /** RNDIS request to issue a device-to-host NDIS response */
70 #define REQ_GetEncapsulatedResponse 0x01
71
72 #define RNDIS_MESSAGE_BUFFER_SIZE 128
73
74 #define ETHERNET_FRAME_SIZE_MAX 1500
75
76 #define NOTIF_ResponseAvailable 1
77
78 /* Enums: */
79 /** Enum for the possible NDIS adapter states. */
80 enum RNDIS_States_t
81 {
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 */
85 };
86
87 /** Enum for the NDIS hardware states */
88 enum NDIS_Hardware_Status_t
89 {
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 */
95 };
96
97 /* Type Defines: */
98 /** Type define for a physical MAC address of a device on a network */
99 typedef struct
100 {
101 uint8_t Octets[6]; /**< Individual bytes of a MAC address */
102 } MAC_Address_t;
103
104 /** Type define for a RNDIS message header, sent before RNDIS messages */
105 typedef struct
106 {
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;
110
111 /** Type define for an Ethernet frame buffer. */
112 typedef struct
113 {
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;
118
119 /** Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter */
120 typedef struct
121 {
122 uint32_t MessageType;
123 uint32_t MessageLength;
124 uint32_t DataOffset;
125 uint32_t DataLength;
126 uint32_t OOBDataOffset;
127 uint32_t OOBDataLength;
128 uint32_t NumOOBDataElements;
129 uint32_t PerPacketInfoOffset;
130 uint32_t PerPacketInfoLength;
131 uint32_t VcHandle;
132 uint32_t Reserved;
133 } RNDIS_PACKET_MSG_t;
134
135 typedef struct
136 {
137 uint8_t ControlInterfaceNumber; /**< Interface number of the CDC control interface within the device */
138
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 */
141
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 */
144
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 */
147
148 char* AdapterVendorDescription;
149 MAC_Address_t AdapterMACAddress;
150
151 uint8_t RNDISMessageBuffer[RNDIS_MESSAGE_BUFFER_SIZE];
152 bool ResponseReady;
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;
158
159 /** Type define for a RNDIS Initialize command message */
160 typedef struct
161 {
162 uint32_t MessageType;
163 uint32_t MessageLength;
164 uint32_t RequestId;
165
166 uint32_t MajorVersion;
167 uint32_t MinorVersion;
168 uint32_t MaxTransferSize;
169 } RNDIS_INITIALIZE_MSG_t;
170
171 /** Type define for a RNDIS Initialize complete response message */
172 typedef struct
173 {
174 uint32_t MessageType;
175 uint32_t MessageLength;
176 uint32_t RequestId;
177 uint32_t Status;
178
179 uint32_t MajorVersion;
180 uint32_t MinorVersion;
181 uint32_t DeviceFlags;
182 uint32_t Medium;
183 uint32_t MaxPacketsPerTransfer;
184 uint32_t MaxTransferSize;
185 uint32_t PacketAlignmentFactor;
186 uint32_t AFListOffset;
187 uint32_t AFListSize;
188 } RNDIS_INITIALIZE_CMPLT_t;
189
190 /** Type define for a RNDIS Keepalive command message */
191 typedef struct
192 {
193 uint32_t MessageType;
194 uint32_t MessageLength;
195 uint32_t RequestId;
196 } RNDIS_KEEPALIVE_MSG_t;
197
198 /** Type define for a RNDIS Keepalive complete message */
199 typedef struct
200 {
201 uint32_t MessageType;
202 uint32_t MessageLength;
203 uint32_t RequestId;
204 uint32_t Status;
205 } RNDIS_KEEPALIVE_CMPLT_t;
206
207 /** Type define for a RNDIS Reset complete message */
208 typedef struct
209 {
210 uint32_t MessageType;
211 uint32_t MessageLength;
212 uint32_t Status;
213
214 uint32_t AddressingReset;
215 } RNDIS_RESET_CMPLT_t;
216
217 /** Type define for a RNDIS Set command message */
218 typedef struct
219 {
220 uint32_t MessageType;
221 uint32_t MessageLength;
222 uint32_t RequestId;
223
224 uint32_t Oid;
225 uint32_t InformationBufferLength;
226 uint32_t InformationBufferOffset;
227 uint32_t DeviceVcHandle;
228 } RNDIS_SET_MSG_t;
229
230 /** Type define for a RNDIS Set complete response message */
231 typedef struct
232 {
233 uint32_t MessageType;
234 uint32_t MessageLength;
235 uint32_t RequestId;
236 uint32_t Status;
237 } RNDIS_SET_CMPLT_t;
238
239 /** Type define for a RNDIS Query command message */
240 typedef struct
241 {
242 uint32_t MessageType;
243 uint32_t MessageLength;
244 uint32_t RequestId;
245
246 uint32_t Oid;
247 uint32_t InformationBufferLength;
248 uint32_t InformationBufferOffset;
249 uint32_t DeviceVcHandle;
250 } RNDIS_QUERY_MSG_t;
251
252 /** Type define for a RNDIS Query complete response message */
253 typedef struct
254 {
255 uint32_t MessageType;
256 uint32_t MessageLength;
257 uint32_t RequestId;
258 uint32_t Status;
259
260 uint32_t InformationBufferLength;
261 uint32_t InformationBufferOffset;
262 } RNDIS_QUERY_CMPLT_t;
263
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);
272 #endif
273
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);
277
278 /* Disable C linkage for C++ Compilers: */
279 #if defined(__cplusplus)
280 }
281 #endif
282
283 #endif
284
285 /** @} */