Update copyright year to 2010.
[pub/USBasp.git] / Demos / Device / LowLevel / RNDISEthernet / Lib / RNDIS.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all 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 /** \file
32 *
33 * Header file for RNDIS.c.
34 */
35
36 #ifndef _RNDIS_H_
37 #define _RNDIS_H_
38
39 /* Includes: */
40 #include <avr/io.h>
41 #include <stdbool.h>
42
43 #include "RNDISEthernet.h"
44 #include "RNDISConstants.h"
45 #include "Ethernet.h"
46
47 /* Macros: */
48 /** Implemented RNDIS Version Major */
49 #define REMOTE_NDIS_VERSION_MAJOR 0x01
50
51 /** Implemented RNDIS Version Minor */
52 #define REMOTE_NDIS_VERSION_MINOR 0x00
53
54 /** RNDIS request to issue a host-to-device NDIS command */
55 #define REQ_SendEncapsulatedCommand 0x00
56
57 /** RNDIS request to issue a device-to-host NDIS response */
58 #define REQ_GetEncapsulatedResponse 0x01
59
60 /* Enums: */
61 /** Enum for the possible NDIS adapter states. */
62 enum RNDIS_States_t
63 {
64 RNDIS_Uninitialized = 0, /**< Adapter currently uninitialized */
65 RNDIS_Initialized = 1, /**< Adapter currently initialized but not ready for data transfers */
66 RNDIS_Data_Initialized = 2, /**< Adapter currently initialized and ready for data transfers */
67 };
68
69 /** Enum for the NDIS hardware states */
70 enum NDIS_Hardware_Status_t
71 {
72 NdisHardwareStatusReady, /**< Hardware Ready to accept commands from the host */
73 NdisHardwareStatusInitializing, /**< Hardware busy initializing */
74 NdisHardwareStatusReset, /**< Hardware reset */
75 NdisHardwareStatusClosing, /**< Hardware currently closing */
76 NdisHardwareStatusNotReady /**< Hardware not ready to accept commands from the host */
77 };
78
79 /* Type Defines: */
80 /** Type define for a RNDIS message header, sent before RNDIS messages */
81 typedef struct
82 {
83 uint32_t MessageType; /**< RNDIS message type, a REMOTE_NDIS_*_MSG constant */
84 uint32_t MessageLength; /**< Total length of the RNDIS message, in bytes */
85 } RNDIS_Message_Header_t;
86
87 /** Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter */
88 typedef struct
89 {
90 uint32_t MessageType;
91 uint32_t MessageLength;
92 uint32_t DataOffset;
93 uint32_t DataLength;
94 uint32_t OOBDataOffset;
95 uint32_t OOBDataLength;
96 uint32_t NumOOBDataElements;
97 uint32_t PerPacketInfoOffset;
98 uint32_t PerPacketInfoLength;
99 uint32_t VcHandle;
100 uint32_t Reserved;
101 } RNDIS_Packet_Message_t;
102
103 /** Type define for a RNDIS Initialize command message */
104 typedef struct
105 {
106 uint32_t MessageType;
107 uint32_t MessageLength;
108 uint32_t RequestId;
109
110 uint32_t MajorVersion;
111 uint32_t MinorVersion;
112 uint32_t MaxTransferSize;
113 } RNDIS_Initialize_Message_t;
114
115 /** Type define for a RNDIS Initialize complete response message */
116 typedef struct
117 {
118 uint32_t MessageType;
119 uint32_t MessageLength;
120 uint32_t RequestId;
121 uint32_t Status;
122
123 uint32_t MajorVersion;
124 uint32_t MinorVersion;
125 uint32_t DeviceFlags;
126 uint32_t Medium;
127 uint32_t MaxPacketsPerTransfer;
128 uint32_t MaxTransferSize;
129 uint32_t PacketAlignmentFactor;
130 uint32_t AFListOffset;
131 uint32_t AFListSize;
132 } RNDIS_Initialize_Complete_t;
133
134 /** Type define for a RNDIS Keepalive command message */
135 typedef struct
136 {
137 uint32_t MessageType;
138 uint32_t MessageLength;
139 uint32_t RequestId;
140 } RNDIS_KeepAlive_Message_t;
141
142 /** Type define for a RNDIS Keepalive complete message */
143 typedef struct
144 {
145 uint32_t MessageType;
146 uint32_t MessageLength;
147 uint32_t RequestId;
148 uint32_t Status;
149 } RNDIS_KeepAlive_Complete_t;
150
151 /** Type define for a RNDIS Reset complete message */
152 typedef struct
153 {
154 uint32_t MessageType;
155 uint32_t MessageLength;
156 uint32_t Status;
157
158 uint32_t AddressingReset;
159 } RNDIS_Reset_Complete_t;
160
161 /** Type define for a RNDIS Set command message */
162 typedef struct
163 {
164 uint32_t MessageType;
165 uint32_t MessageLength;
166 uint32_t RequestId;
167
168 uint32_t Oid;
169 uint32_t InformationBufferLength;
170 uint32_t InformationBufferOffset;
171 uint32_t DeviceVcHandle;
172 } RNDIS_Set_Message_t;
173
174 /** Type define for a RNDIS Set complete response message */
175 typedef struct
176 {
177 uint32_t MessageType;
178 uint32_t MessageLength;
179 uint32_t RequestId;
180 uint32_t Status;
181 } RNDIS_Set_Complete_t;
182
183 /** Type define for a RNDIS Query command message */
184 typedef struct
185 {
186 uint32_t MessageType;
187 uint32_t MessageLength;
188 uint32_t RequestId;
189
190 uint32_t Oid;
191 uint32_t InformationBufferLength;
192 uint32_t InformationBufferOffset;
193 uint32_t DeviceVcHandle;
194 } RNDIS_Query_Message_t;
195
196 /** Type define for a RNDIS Query complete response message */
197 typedef struct
198 {
199 uint32_t MessageType;
200 uint32_t MessageLength;
201 uint32_t RequestId;
202 uint32_t Status;
203
204 uint32_t InformationBufferLength;
205 uint32_t InformationBufferOffset;
206 } RNDIS_Query_Complete_t;
207
208 /* External Variables: */
209 extern uint8_t RNDISMessageBuffer[];
210 extern RNDIS_Message_Header_t* MessageHeader;
211 extern bool ResponseReady;
212 extern uint8_t CurrRNDISState;
213
214 /* Function Prototypes: */
215 void ProcessRNDISControlMessage(void);
216
217 #if defined(INCLUDE_FROM_RNDIS_C)
218 static bool ProcessNDISQuery(uint32_t OId, void* QueryData, uint16_t QuerySize,
219 void* ResponseData, uint16_t* ResponseSize);
220 static bool ProcessNDISSet(uint32_t OId, void* SetData, uint16_t SetSize);
221 #endif
222
223 #endif