1 /**
2  * \file rndis_protocol.h
3  *         RNDIS Defines
4  *
5  * \author
6  *         Colin O'Flynn <coflynn@newae.com>
7  *
8  * \addtogroup usbstick
9  */
10 
11 /* Copyright (c) 2008  Colin O'Flynn
12 
13    Redistribution and use in source and binary forms, with or without
14    modification, are permitted provided that the following conditions are met:
15 
16    * Redistributions of source code must retain the above copyright
17      notice, this list of conditions and the following disclaimer.
18    * Redistributions in binary form must reproduce the above copyright
19      notice, this list of conditions and the following disclaimer in
20      the documentation and/or other materials provided with the
21      distribution.
22    * Neither the name of the copyright holders nor the names of
23      contributors may be used to endorse or promote products derived
24      from this software without specific prior written permission.
25 
26   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36   POSSIBILITY OF SUCH DAMAGE.
37 */
38 
39 #ifndef _RNDIS_H
40 #define _RNDIS_H
41 
42 /**
43   \addtogroup RNDIS
44   @{
45   */
46 
47 #include <stdint.h>
48 
49 #define RNDIS_MAJOR_VERSION 1
50 #define RNDIS_MINOR_VERSION 0
51 
52 #define RNDIS_STATUS_SUCCESS          0X00000000
53 #define RNDIS_STATUS_FAILURE          0XC0000001
54 #define RNDIS_STATUS_INVALID_DATA     0XC0010015
55 #define RNDIS_STATUS_NOT_SUPPORTED    0XC00000BB
56 #define RNDIS_STATUS_MEDIA_CONNECT    0X4001000B
57 #define RNDIS_STATUS_MEDIA_DISCONNECT 0X4001000C
58 
59 /* Message set for Connectionless (802.3) Devices */
60 #define REMOTE_NDIS_PACKET_MSG          0x00000001
61 #define REMOTE_NDIS_INITIALIZE_MSG      0X00000002
62 #define REMOTE_NDIS_HALT_MSG            0X00000003
63 #define REMOTE_NDIS_QUERY_MSG           0X00000004
64 #define REMOTE_NDIS_SET_MSG             0X00000005
65 #define REMOTE_NDIS_RESET_MSG           0X00000006
66 #define REMOTE_NDIS_INDICATE_STATUS_MSG 0X00000007
67 #define REMOTE_NDIS_KEEPALIVE_MSG       0X00000008
68 #define REMOTE_NDIS_INITIALIZE_CMPLT    0X80000002
69 #define REMOTE_NDIS_QUERY_CMPLT         0X80000004
70 #define REMOTE_NDIS_SET_CMPLT           0X80000005
71 #define REMOTE_NDIS_RESET_CMPLT         0X80000006
72 #define REMOTE_NDIS_KEEPALIVE_CMPLT     0X80000008
73 
74 typedef uint32_t rndis_MessageType_t;
75 typedef uint32_t rndis_MessageLength_t;
76 typedef uint32_t rndis_RequestId_t;
77 typedef uint32_t rndis_MajorVersion_t;
78 typedef uint32_t rndis_MinorVersion_t;
79 typedef uint32_t rndis_MaxTransferSize_t;
80 typedef uint32_t rndis_Status_t;
81 
82 /* Device Flags */
83 #define RNDIS_DF_CONNECTIONLESS      0x00000001
84 #define RNDIS_DF_CONNECTION_ORIENTED 0x00000002
85 typedef uint32_t rndis_DeviceFlags_t;
86 
87 /* Mediums */
88 #define RNDIS_MEDIUM_802_3 0x00000000
89 typedef uint32_t rndis_Medium_t;
90 
91 typedef uint32_t rndis_MaxPacketsPerTransfer_t;
92 typedef uint32_t rndis_PacketAlignmentFactor_t;
93 typedef uint32_t rndis_AfListOffset_t;
94 typedef uint32_t rndis_AfListSize_t;
95 
96 /*** Remote NDIS Generic Message type ***/
97 typedef struct {
98     rndis_MessageType_t MessageType;
99     rndis_MessageLength_t MessageLength;
100 } rndis_generic_msg_t;
101 
102 /*** Remote NDIS Initialize Message ***/
103 typedef struct {
104     rndis_MessageType_t MessageType;
105     rndis_MessageLength_t MessageLength;
106     rndis_RequestId_t RequestId;
107     rndis_MajorVersion_t MajorVersion;
108     rndis_MinorVersion_t MinorVersion;
109     rndis_MaxTransferSize_t MaxTransferSize;
110 } rndis_initialize_msg_t;
111 
112 /* Response: */
113 typedef struct {
114     rndis_MessageType_t MessageType;
115     rndis_MessageLength_t MessageLength;
116     rndis_RequestId_t RequestId;
117     rndis_Status_t Status;
118     rndis_MajorVersion_t MajorVersion;
119     rndis_MinorVersion_t MinorVersion;
120     rndis_DeviceFlags_t DeviceFlags;
121     rndis_Medium_t Medium;
122     rndis_MaxPacketsPerTransfer_t MaxPacketsPerTransfer;
123     rndis_MaxTransferSize_t MaxTransferSize;
124     rndis_PacketAlignmentFactor_t PacketAlignmentFactor;
125     rndis_AfListOffset_t AfListOffset;
126     rndis_AfListSize_t AfListSize;
127 } rndis_initialize_cmplt_t;
128 
129 /*** Remote NDIS Halt Message ***/
130 typedef struct {
131     rndis_MessageType_t MessageType;
132     rndis_MessageLength_t MessageLength;
133     rndis_RequestId_t RequestId;
134 } rndis_halt_msg_t;
135 
136 typedef uint32_t rndis_Oid_t;
137 typedef uint32_t rndis_InformationBufferLength_t;
138 typedef uint32_t rndis_InformationBufferOffset_t;
139 typedef uint32_t rndis_DeviceVcHandle_t;
140 
141 /*** Remote NDIS Query Message ***/
142 typedef struct {
143     rndis_MessageType_t MessageType;
144     rndis_MessageLength_t MessageLength;
145     rndis_RequestId_t RequestId;
146     rndis_Oid_t Oid;
147     rndis_InformationBufferLength_t InformationBufferLength;
148     rndis_InformationBufferOffset_t InformationBufferOffset;
149     rndis_DeviceVcHandle_t DeviceVcHandle;
150 } rndis_query_msg_t;
151 
152 /* Response: */
153 
154 typedef struct {
155     rndis_MessageType_t MessageType;
156     rndis_MessageLength_t MessageLength;
157     rndis_RequestId_t RequestId;
158     rndis_Status_t Status;
159     rndis_InformationBufferLength_t InformationBufferLength;
160     rndis_InformationBufferOffset_t InformationBufferOffset;
161 } rndis_query_cmplt_t;
162 
163 /*** Remote NDIS Set Message ***/
164 typedef struct {
165     rndis_MessageType_t MessageType;
166     rndis_MessageLength_t MessageLength;
167     rndis_RequestId_t RequestId;
168     rndis_Oid_t Oid;
169     rndis_InformationBufferLength_t InformationBufferLength;
170     rndis_InformationBufferOffset_t InformationBufferOffset;
171     rndis_DeviceVcHandle_t DeviceVcHandle;
172 } rndis_set_msg_t;
173 
174 /* Response */
175 typedef struct {
176     rndis_MessageType_t MessageType;
177     rndis_MessageLength_t MessageLength;
178     rndis_RequestId_t RequestId;
179     rndis_Status_t Status;
180 } rndis_set_cmplt_t;
181 
182 /* Information buffer layout for OID_GEN_RNDIS_CONFIG_PARAMETER */
183 typedef uint32_t rndis_ParameterNameOffset_t;
184 typedef uint32_t rndis_ParameterNameLength_t;
185 typedef uint32_t rndis_ParameterType_t;
186 typedef uint32_t rndis_ParameterValueOffset_t;
187 typedef uint32_t rndis_ParameterValueLength_t;
188 
189 #define PARAMETER_TYPE_STRING    2
190 #define PARAMETER_TYPE_NUMERICAL 0
191 
192 typedef struct {
193     rndis_ParameterNameOffset_t ParameterNameOffset;
194     rndis_ParameterNameLength_t ParameterNameLength;
195     rndis_ParameterType_t ParameterType;
196     rndis_ParameterValueOffset_t ParameterValueOffset;
197     rndis_ParameterValueLength_t ParameterValueLength;
198 } rndis_config_parameter_t;
199 
200 typedef uint32_t rndis_Reserved_t;
201 
202 /*** Remote NDIS Soft Reset Message ***/
203 typedef struct {
204     rndis_MessageType_t MessageType;
205     rndis_MessageLength_t MessageLength;
206     rndis_Reserved_t Reserved;
207 } rndis_reset_msg_t;
208 
209 typedef uint32_t rndis_AddressingReset_t;
210 
211 /* Response: */
212 typedef struct {
213     rndis_MessageType_t MessageType;
214     rndis_MessageLength_t MessageLength;
215     rndis_Status_t Status;
216     rndis_AddressingReset_t AddressingReset;
217 } rndis_reset_cmplt_t;
218 
219 /*** Remote NDIS Indicate Status Message ***/
220 typedef struct {
221     rndis_MessageType_t MessageType;
222     rndis_MessageLength_t MessageLength;
223     rndis_Status_t Status;
224     rndis_Status_t StatusBufferLength;
225     rndis_Status_t StatusBufferOffset;
226 } rndis_indicate_status_t;
227 
228 typedef uint32_t rndis_DiagStatus_t;
229 typedef uint32_t rndis_ErrorOffset_t;
230 
231 typedef struct {
232     rndis_DiagStatus_t DiagStatus;
233     rndis_ErrorOffset_t ErrorOffset;
234 } rndis_diagnostic_info_t;
235 
236 /*** Remote NDIS Keepalive Message */
237 typedef struct {
238     rndis_MessageType_t MessageType;
239     rndis_MessageLength_t MessageLength;
240     rndis_RequestId_t RequestId;
241 } rndis_keepalive_msg_t;
242 
243 /* Response: */
244 typedef struct {
245     rndis_MessageType_t MessageType;
246     rndis_MessageLength_t MessageLength;
247     rndis_RequestId_t RequestId;
248     rndis_Status_t Status;
249 } rndis_keepalive_cmplt_t;
250 
251 /*** Remote NDIS Data Packet ***/
252 
253 typedef uint32_t rndis_DataOffset_t;
254 typedef uint32_t rndis_DataLength_t;
255 typedef uint32_t rndis_OOBDataOffset_t;
256 typedef uint32_t rndis_OOBDataLength_t;
257 typedef uint32_t rndis_NumOOBDataElements_t;
258 typedef uint32_t rndis_PerPacketInfoOffset_t;
259 typedef uint32_t rndis_PerPacketInfoLength_t;
260 
261 typedef struct {
262     rndis_MessageType_t MessageType;
263     rndis_MessageLength_t MessageLength;
264     rndis_DataOffset_t DataOffset;
265     rndis_DataLength_t DataLength;
266     rndis_OOBDataOffset_t OOBDataOffset;
267     rndis_OOBDataLength_t OOBDataLength;
268     rndis_NumOOBDataElements_t NumOOBDataElements;
269     rndis_PerPacketInfoOffset_t PerPacketInfoOffset;
270     rndis_PerPacketInfoLength_t PerPacketInfoLength;
271     rndis_DeviceVcHandle_t DeviceVcHandle;
272     rndis_Reserved_t Reserved;
273 } rndis_data_packet_t;
274 
275 typedef uint32_t rndis_ClassInformationOffset_t;
276 typedef uint32_t rndis_Size_t;
277 typedef uint32_t rndis_Type_t;
278 
279 typedef struct {
280     rndis_Size_t Size;
281     rndis_Type_t Type;
282     rndis_ClassInformationOffset_t ClassInformationType;
283 } rndis_OOB_packet_t;
284 
285 #include "ndis.h"
286 
287 typedef enum rnids_state_e {
288     rndis_uninitialized,
289     rndis_initialized,
290     rndis_data_initialized
291 } rndis_state_t;
292 
293 typedef struct {
294     uint32_t txok;
295     uint32_t rxok;
296     uint32_t txbad;
297     uint32_t rxbad;
298 } usb_eth_stat_t;
299 
300 #endif /* _RNDIS_H */
301 
302 /** @} */
303