Minor documentation page updates.
[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 #ifndef _RNDIS_CLASS_H_
32 #define _RNDIS_CLASS_H_
33
34 /* Includes: */
35 #include <string.h>
36
37 #include "../../USB.h"
38 #include "RNDISConstants.h"
39
40 /* Enable C linkage for C++ Compilers: */
41 #if defined(__cplusplus)
42 extern "C" {
43 #endif
44
45 /* Macros: */
46 /** Implemented RNDIS Version Major */
47 #define REMOTE_NDIS_VERSION_MAJOR 0x01
48
49 /** Implemented RNDIS Version Minor */
50 #define REMOTE_NDIS_VERSION_MINOR 0x00
51
52 /** RNDIS request to issue a host-to-device NDIS command */
53 #define REQ_SendEncapsulatedCommand 0x00
54
55 /** RNDIS request to issue a device-to-host NDIS response */
56 #define REQ_GetEncapsulatedResponse 0x01
57
58 #define RNDIS_MESSAGE_BUFFER_SIZE 128
59
60 #define ETHERNET_FRAME_SIZE_MAX 1500
61
62 #define NOTIF_ResponseAvailable 1
63
64 /* Enums: */
65 /** Enum for the possible NDIS adapter states. */
66 enum RNDIS_States_t
67 {
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 */
71 };
72
73 /** Enum for the NDIS hardware states */
74 enum NDIS_Hardware_Status_t
75 {
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 */
81 };
82
83 /* Type Defines: */
84 /** Type define for a physical MAC address of a device on a network */
85 typedef struct
86 {
87 uint8_t Octets[6]; /**< Individual bytes of a MAC address */
88 } MAC_Address_t;
89
90 /** Type define for a RNDIS message header, sent before RNDIS messages */
91 typedef struct
92 {
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;
96
97 /** Type define for an Ethernet frame buffer. */
98 typedef struct
99 {
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;
104
105 /** Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter */
106 typedef struct
107 {
108 uint32_t MessageType;
109 uint32_t MessageLength;
110 uint32_t DataOffset;
111 uint32_t DataLength;
112 uint32_t OOBDataOffset;
113 uint32_t OOBDataLength;
114 uint32_t NumOOBDataElements;
115 uint32_t PerPacketInfoOffset;
116 uint32_t PerPacketInfoLength;
117 uint32_t VcHandle;
118 uint32_t Reserved;
119 } RNDIS_PACKET_MSG_t;
120
121 typedef struct
122 {
123 uint8_t ControlInterfaceNumber; /**< Interface number of the CDC control interface within the device */
124
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 */
127
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 */
130
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 */
133
134 char* AdapterVendorDescription;
135 MAC_Address_t AdapterMACAddress;
136
137 uint8_t RNDISMessageBuffer[RNDIS_MESSAGE_BUFFER_SIZE];
138 bool ResponseReady;
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;
144
145 /** Type define for a RNDIS Initialize command message */
146 typedef struct
147 {
148 uint32_t MessageType;
149 uint32_t MessageLength;
150 uint32_t RequestId;
151
152 uint32_t MajorVersion;
153 uint32_t MinorVersion;
154 uint32_t MaxTransferSize;
155 } RNDIS_INITIALIZE_MSG_t;
156
157 /** Type define for a RNDIS Initialize complete response message */
158 typedef struct
159 {
160 uint32_t MessageType;
161 uint32_t MessageLength;
162 uint32_t RequestId;
163 uint32_t Status;
164
165 uint32_t MajorVersion;
166 uint32_t MinorVersion;
167 uint32_t DeviceFlags;
168 uint32_t Medium;
169 uint32_t MaxPacketsPerTransfer;
170 uint32_t MaxTransferSize;
171 uint32_t PacketAlignmentFactor;
172 uint32_t AFListOffset;
173 uint32_t AFListSize;
174 } RNDIS_INITIALIZE_CMPLT_t;
175
176 /** Type define for a RNDIS Keepalive command message */
177 typedef struct
178 {
179 uint32_t MessageType;
180 uint32_t MessageLength;
181 uint32_t RequestId;
182 } RNDIS_KEEPALIVE_MSG_t;
183
184 /** Type define for a RNDIS Keepalive complete message */
185 typedef struct
186 {
187 uint32_t MessageType;
188 uint32_t MessageLength;
189 uint32_t RequestId;
190 uint32_t Status;
191 } RNDIS_KEEPALIVE_CMPLT_t;
192
193 /** Type define for a RNDIS Reset complete message */
194 typedef struct
195 {
196 uint32_t MessageType;
197 uint32_t MessageLength;
198 uint32_t Status;
199
200 uint32_t AddressingReset;
201 } RNDIS_RESET_CMPLT_t;
202
203 /** Type define for a RNDIS Set command message */
204 typedef struct
205 {
206 uint32_t MessageType;
207 uint32_t MessageLength;
208 uint32_t RequestId;
209
210 uint32_t Oid;
211 uint32_t InformationBufferLength;
212 uint32_t InformationBufferOffset;
213 uint32_t DeviceVcHandle;
214 } RNDIS_SET_MSG_t;
215
216 /** Type define for a RNDIS Set complete response message */
217 typedef struct
218 {
219 uint32_t MessageType;
220 uint32_t MessageLength;
221 uint32_t RequestId;
222 uint32_t Status;
223 } RNDIS_SET_CMPLT_t;
224
225 /** Type define for a RNDIS Query command message */
226 typedef struct
227 {
228 uint32_t MessageType;
229 uint32_t MessageLength;
230 uint32_t RequestId;
231
232 uint32_t Oid;
233 uint32_t InformationBufferLength;
234 uint32_t InformationBufferOffset;
235 uint32_t DeviceVcHandle;
236 } RNDIS_QUERY_MSG_t;
237
238 /** Type define for a RNDIS Query complete response message */
239 typedef struct
240 {
241 uint32_t MessageType;
242 uint32_t MessageLength;
243 uint32_t RequestId;
244 uint32_t Status;
245
246 uint32_t InformationBufferLength;
247 uint32_t InformationBufferOffset;
248 } RNDIS_QUERY_CMPLT_t;
249
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);
258 #endif
259
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);
263
264 /* Disable C linkage for C++ Compilers: */
265 #if defined(__cplusplus)
266 }
267 #endif
268
269 #endif