Commit of new class abstraction APIs for all device demos other than the MIDI demo...
[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 /* Macros: */
41 /** Implemented RNDIS Version Major */
42 #define REMOTE_NDIS_VERSION_MAJOR 0x01
43
44 /** Implemented RNDIS Version Minor */
45 #define REMOTE_NDIS_VERSION_MINOR 0x00
46
47 /** RNDIS request to issue a host-to-device NDIS command */
48 #define REQ_SendEncapsulatedCommand 0x00
49
50 /** RNDIS request to issue a device-to-host NDIS response */
51 #define REQ_GetEncapsulatedResponse 0x01
52
53 #define RNDIS_MESSAGE_BUFFER_SIZE 128
54
55 #define ETHERNET_FRAME_SIZE_MAX 1500
56
57 #define NOTIF_ResponseAvailable 1
58
59 /* Enums: */
60 /** Enum for the possible NDIS adapter states. */
61 enum RNDIS_States_t
62 {
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 */
66 };
67
68 /** Enum for the NDIS hardware states */
69 enum NDIS_Hardware_Status_t
70 {
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 */
76 };
77
78 /* Type Defines: */
79 /** Type define for a physical MAC address of a device on a network */
80 typedef struct
81 {
82 uint8_t Octets[6]; /**< Individual bytes of a MAC address */
83 } MAC_Address_t;
84
85 /** Type define for a RNDIS message header, sent before RNDIS messages */
86 typedef struct
87 {
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;
91
92 /** Type define for an Ethernet frame buffer. */
93 typedef struct
94 {
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;
99
100 /** Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter */
101 typedef struct
102 {
103 uint32_t MessageType;
104 uint32_t MessageLength;
105 uint32_t DataOffset;
106 uint32_t DataLength;
107 uint32_t OOBDataOffset;
108 uint32_t OOBDataLength;
109 uint32_t NumOOBDataElements;
110 uint32_t PerPacketInfoOffset;
111 uint32_t PerPacketInfoLength;
112 uint32_t VcHandle;
113 uint32_t Reserved;
114 } RNDIS_PACKET_MSG_t;
115
116 typedef struct
117 {
118 uint8_t ControlInterfaceNumber; /**< Interface number of the CDC control interface within the device */
119
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 */
122
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 */
125
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 */
128
129 char* AdapterVendorDescription;
130 MAC_Address_t AdapterMACAddress;
131
132 uint8_t RNDISMessageBuffer[RNDIS_MESSAGE_BUFFER_SIZE];
133 bool ResponseReady;
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;
139
140 /** Type define for a RNDIS Initialize command message */
141 typedef struct
142 {
143 uint32_t MessageType;
144 uint32_t MessageLength;
145 uint32_t RequestId;
146
147 uint32_t MajorVersion;
148 uint32_t MinorVersion;
149 uint32_t MaxTransferSize;
150 } RNDIS_INITIALIZE_MSG_t;
151
152 /** Type define for a RNDIS Initialize complete response message */
153 typedef struct
154 {
155 uint32_t MessageType;
156 uint32_t MessageLength;
157 uint32_t RequestId;
158 uint32_t Status;
159
160 uint32_t MajorVersion;
161 uint32_t MinorVersion;
162 uint32_t DeviceFlags;
163 uint32_t Medium;
164 uint32_t MaxPacketsPerTransfer;
165 uint32_t MaxTransferSize;
166 uint32_t PacketAlignmentFactor;
167 uint32_t AFListOffset;
168 uint32_t AFListSize;
169 } RNDIS_INITIALIZE_CMPLT_t;
170
171 /** Type define for a RNDIS Keepalive command message */
172 typedef struct
173 {
174 uint32_t MessageType;
175 uint32_t MessageLength;
176 uint32_t RequestId;
177 } RNDIS_KEEPALIVE_MSG_t;
178
179 /** Type define for a RNDIS Keepalive complete message */
180 typedef struct
181 {
182 uint32_t MessageType;
183 uint32_t MessageLength;
184 uint32_t RequestId;
185 uint32_t Status;
186 } RNDIS_KEEPALIVE_CMPLT_t;
187
188 /** Type define for a RNDIS Reset complete message */
189 typedef struct
190 {
191 uint32_t MessageType;
192 uint32_t MessageLength;
193 uint32_t Status;
194
195 uint32_t AddressingReset;
196 } RNDIS_RESET_CMPLT_t;
197
198 /** Type define for a RNDIS Set command message */
199 typedef struct
200 {
201 uint32_t MessageType;
202 uint32_t MessageLength;
203 uint32_t RequestId;
204
205 uint32_t Oid;
206 uint32_t InformationBufferLength;
207 uint32_t InformationBufferOffset;
208 uint32_t DeviceVcHandle;
209 } RNDIS_SET_MSG_t;
210
211 /** Type define for a RNDIS Set complete response message */
212 typedef struct
213 {
214 uint32_t MessageType;
215 uint32_t MessageLength;
216 uint32_t RequestId;
217 uint32_t Status;
218 } RNDIS_SET_CMPLT_t;
219
220 /** Type define for a RNDIS Query command message */
221 typedef struct
222 {
223 uint32_t MessageType;
224 uint32_t MessageLength;
225 uint32_t RequestId;
226
227 uint32_t Oid;
228 uint32_t InformationBufferLength;
229 uint32_t InformationBufferOffset;
230 uint32_t DeviceVcHandle;
231 } RNDIS_QUERY_MSG_t;
232
233 /** Type define for a RNDIS Query complete response message */
234 typedef struct
235 {
236 uint32_t MessageType;
237 uint32_t MessageLength;
238 uint32_t RequestId;
239 uint32_t Status;
240
241 uint32_t InformationBufferLength;
242 uint32_t InformationBufferOffset;
243 } RNDIS_QUERY_CMPLT_t;
244
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);
253 #endif
254
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);
259
260 #endif