Some minor whitespace corrections.
[pub/USBasp.git] / Demos / Device / LowLevel / RNDISEthernet / Lib / 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 /** \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 /** Physical MAC Address of the USB network adapter */
49 #define ADAPTER_MAC_ADDRESS {0x02, 0x00, 0x02, 0x00, 0x02, 0x00}
50
51 /** Implemented RNDIS Version Major */
52 #define REMOTE_NDIS_VERSION_MAJOR 0x01
53
54 /** Implemented RNDIS Version Minor */
55 #define REMOTE_NDIS_VERSION_MINOR 0x00
56
57 /** RNDIS request to issue a host-to-device NDIS command */
58 #define REQ_SendEncapsulatedCommand 0x00
59
60 /** RNDIS request to issue a device-to-host NDIS response */
61 #define REQ_GetEncapsulatedResponse 0x01
62
63 /* Enums: */
64 /** Enum for the possible NDIS adapter states. */
65 enum RNDIS_States_t
66 {
67 RNDIS_Uninitialized = 0, /**< Adapter currently uninitialized */
68 RNDIS_Initialized = 1, /**< Adapter currently initialized but not ready for data transfers */
69 RNDIS_Data_Initialized = 2, /**< Adapter currently initialized and ready for data transfers */
70 };
71
72 /** Enum for the NDIS hardware states */
73 enum NDIS_Hardware_Status_t
74 {
75 NdisHardwareStatusReady, /**< Hardware Ready to accept commands from the host */
76 NdisHardwareStatusInitializing, /**< Hardware busy initializing */
77 NdisHardwareStatusReset, /**< Hardware reset */
78 NdisHardwareStatusClosing, /**< Hardware currently closing */
79 NdisHardwareStatusNotReady /**< Hardware not ready to accept commands from the host */
80 };
81
82 /* Type Defines: */
83 /** Type define for a RNDIS message header, sent before RNDIS messages */
84 typedef struct
85 {
86 uint32_t MessageType; /**< RNDIS message type, a REMOTE_NDIS_*_MSG constant */
87 uint32_t MessageLength; /**< Total length of the RNDIS message, in bytes */
88 } RNDIS_Message_Header_t;
89
90 /** Type define for a RNDIS packet message, used to encapsulate Ethernet packets sent to and from the adapter */
91 typedef struct
92 {
93 uint32_t MessageType;
94 uint32_t MessageLength;
95 uint32_t DataOffset;
96 uint32_t DataLength;
97 uint32_t OOBDataOffset;
98 uint32_t OOBDataLength;
99 uint32_t NumOOBDataElements;
100 uint32_t PerPacketInfoOffset;
101 uint32_t PerPacketInfoLength;
102 uint32_t VcHandle;
103 uint32_t Reserved;
104 } RNDIS_PACKET_MSG_t;
105
106 /** Type define for a RNDIS Initialize command message */
107 typedef struct
108 {
109 uint32_t MessageType;
110 uint32_t MessageLength;
111 uint32_t RequestId;
112
113 uint32_t MajorVersion;
114 uint32_t MinorVersion;
115 uint32_t MaxTransferSize;
116 } RNDIS_INITIALIZE_MSG_t;
117
118 /** Type define for a RNDIS Initialize complete response message */
119 typedef struct
120 {
121 uint32_t MessageType;
122 uint32_t MessageLength;
123 uint32_t RequestId;
124 uint32_t Status;
125
126 uint32_t MajorVersion;
127 uint32_t MinorVersion;
128 uint32_t DeviceFlags;
129 uint32_t Medium;
130 uint32_t MaxPacketsPerTransfer;
131 uint32_t MaxTransferSize;
132 uint32_t PacketAlignmentFactor;
133 uint32_t AFListOffset;
134 uint32_t AFListSize;
135 } RNDIS_INITIALIZE_CMPLT_t;
136
137 /** Type define for a RNDIS Keepalive command message */
138 typedef struct
139 {
140 uint32_t MessageType;
141 uint32_t MessageLength;
142 uint32_t RequestId;
143 } RNDIS_KEEPALIVE_MSG_t;
144
145 /** Type define for a RNDIS Keepalive complete message */
146 typedef struct
147 {
148 uint32_t MessageType;
149 uint32_t MessageLength;
150 uint32_t RequestId;
151 uint32_t Status;
152 } RNDIS_KEEPALIVE_CMPLT_t;
153
154 /** Type define for a RNDIS Reset complete message */
155 typedef struct
156 {
157 uint32_t MessageType;
158 uint32_t MessageLength;
159 uint32_t Status;
160
161 uint32_t AddressingReset;
162 } RNDIS_RESET_CMPLT_t;
163
164 /** Type define for a RNDIS Set command message */
165 typedef struct
166 {
167 uint32_t MessageType;
168 uint32_t MessageLength;
169 uint32_t RequestId;
170
171 uint32_t Oid;
172 uint32_t InformationBufferLength;
173 uint32_t InformationBufferOffset;
174 uint32_t DeviceVcHandle;
175 } RNDIS_SET_MSG_t;
176
177 /** Type define for a RNDIS Set complete response message */
178 typedef struct
179 {
180 uint32_t MessageType;
181 uint32_t MessageLength;
182 uint32_t RequestId;
183 uint32_t Status;
184 } RNDIS_SET_CMPLT_t;
185
186 /** Type define for a RNDIS Query command message */
187 typedef struct
188 {
189 uint32_t MessageType;
190 uint32_t MessageLength;
191 uint32_t RequestId;
192
193 uint32_t Oid;
194 uint32_t InformationBufferLength;
195 uint32_t InformationBufferOffset;
196 uint32_t DeviceVcHandle;
197 } RNDIS_QUERY_MSG_t;
198
199 /** Type define for a RNDIS Query complete response message */
200 typedef struct
201 {
202 uint32_t MessageType;
203 uint32_t MessageLength;
204 uint32_t RequestId;
205 uint32_t Status;
206
207 uint32_t InformationBufferLength;
208 uint32_t InformationBufferOffset;
209 } RNDIS_QUERY_CMPLT_t;
210
211 /* External Variables: */
212 extern uint8_t RNDISMessageBuffer[];
213 extern RNDIS_Message_Header_t* MessageHeader;
214 extern bool ResponseReady;
215 extern uint8_t CurrRNDISState;
216
217 /* Function Prototypes: */
218 void ProcessRNDISControlMessage(void);
219
220 #if defined(INCLUDE_FROM_RNDIS_C)
221 static bool ProcessNDISQuery(uint32_t OId, void* QueryData, uint16_t QuerySize,
222 void* ResponseData, uint16_t* ResponseSize);
223 static bool ProcessNDISSet(uint32_t OId, void* SetData, uint16_t SetSize);
224 #endif
225
226 #endif