mikroSDK Reference Manual
rndis.h
Go to the documentation of this file.
1
31#ifndef _RNDIS_H
32#define _RNDIS_H
33
34//Dependencies
35#include "core/net.h"
36#include "error.h"
37
38//MAC address
39#ifndef RNDIS_MAC_ADDR
40 #define RNDIS_MAC_ADDR "02-00-00-12-34-02"
41#endif
42
43//Vendor description
44#ifndef RNDIS_VENDOR_DESCRIPTION
45 #define RNDIS_VENDOR_DESCRIPTION "Unknown"
46#endif
47
48//RNDIS versions
49#define RNDIS_MAJOR_VERSION 1
50#define RNDIS_MINOR_VERSION 0
51
52//Maximum transfer size
53#define RNDIS_MAX_TRANSFER_SIZE 2048
54
55//RNDIS message types
56#define RNDIS_PACKET_MSG 0x00000001
57#define RNDIS_INITIALIZE_MSG 0x00000002
58#define RNDIS_INITIALIZE_CMPLT 0x80000002
59#define RNDIS_HALT_MSG 0x00000003
60#define RNDIS_QUERY_MSG 0x00000004
61#define RNDIS_QUERY_CMPLT 0x80000004
62#define RNDIS_SET_MSG 0x00000005
63#define RNDIS_SET_CMPLT 0x80000005
64#define RNDIS_RESET_MSG 0x00000006
65#define RNDIS_RESET_CMPLT 0x80000006
66#define RNDIS_INDICATE_STATUS_MSG 0x00000007
67#define RNDIS_KEEPALIVE_MSG 0x00000008
68#define RNDIS_KEEPALIVE_CMPLT 0x80000008
69
70//RNDIS device notifications
71#define RNDIS_NOTIFICATION_RESP_AVAILABLE 0x00000001
72
73//RNDIS status values
74#define RNDIS_STATUS_SUCCESS 0x00000000
75#define RNDIS_STATUS_FAILURE 0xC0000001
76#define RNDIS_STATUS_INVALID_DATA 0xC0010015
77#define RNDIS_STATUS_NOT_SUPPORTED 0xC00000BB
78#define RNDIS_STATUS_MEDIA_CONNECT 0x4001000B
79#define RNDIS_STATUS_MEDIA_DISCONNECT 0x4001000C
80
81//Device flags
82#define RNDIS_DF_CONNECTIONLESS 0x00000001
83#define RNDIS_DF_CONNECTION_ORIENTED 0x00000002
84
85//Support medium
86#define RNDIS_MEDIUM_802_3 0x00000000
87
88//General objects (required)
89#define OID_GEN_SUPPORTED_LIST 0x00010101
90#define OID_GEN_HARDWARE_STATUS 0x00010102
91#define OID_GEN_MEDIA_SUPPORTED 0x00010103
92#define OID_GEN_MEDIA_IN_USE 0x00010104
93#define OID_GEN_MAXIMUM_LOOKAHEAD 0x00010105
94#define OID_GEN_MAXIMUM_FRAME_SIZE 0x00010106
95#define OID_GEN_LINK_SPEED 0x00010107
96#define OID_GEN_TRANSMIT_BUFFER_SPACE 0x00010108
97#define OID_GEN_RECEIVE_BUFFER_SPACE 0x00010109
98#define OID_GEN_TRANSMIT_BLOCK_SIZE 0x0001010A
99#define OID_GEN_RECEIVE_BLOCK_SIZE 0x0001010B
100#define OID_GEN_VENDOR_ID 0x0001010C
101#define OID_GEN_VENDOR_DESCRIPTION 0x0001010D
102#define OID_GEN_CURRENT_PACKET_FILTER 0x0001010E
103#define OID_GEN_CURRENT_LOOKAHEAD 0x0001010F
104#define OID_GEN_DRIVER_VERSION 0x00010110
105#define OID_GEN_MAXIMUM_TOTAL_SIZE 0x00010111
106#define OID_GEN_PROTOCOL_OPTIONS 0x00010112
107#define OID_GEN_MAC_OPTIONS 0x00010113
108#define OID_GEN_MEDIA_CONNECT_STATUS 0x00010114
109#define OID_GEN_MAXIMUM_SEND_PACKETS 0x00010115
110#define OID_GEN_VENDOR_DRIVER_VERSION 0x00010116
111#define OID_GEN_SUPPORTED_GUIDS 0x00010117
112#define OID_GEN_NETWORK_LAYER_ADDRESSES 0x00010118
113#define OID_GEN_TRANSPORT_HEADER_OFFSET 0x00010119
114#define OID_GEN_MACHINE_NAME 0x0001021A
115#define OID_GEN_RNDIS_CONFIG_PARAMETER 0x0001021B
116#define OID_GEN_VLAN_ID 0x0001021C
117
118//General objects (optional)
119#define OID_GEN_MEDIA_CAPABILITIES 0x00010201
120#define OID_GEN_PHYSICAL_MEDIUM 0x00010202
121
122//Statistics objects (required)
123#define OID_GEN_XMIT_OK 0x00020101
124#define OID_GEN_RCV_OK 0x00020102
125#define OID_GEN_XMIT_ERROR 0x00020103
126#define OID_GEN_RCV_ERROR 0x00020104
127#define OID_GEN_RCV_NO_BUFFER 0x00020105
128
129//Statistics objects (optional)
130#define OID_GEN_DIRECTED_BYTES_XMIT 0x00020201
131#define OID_GEN_DIRECTED_FRAMES_XMIT 0x00020202
132#define OID_GEN_MULTICAST_BYTES_XMIT 0x00020203
133#define OID_GEN_MULTICAST_FRAMES_XMIT 0x00020204
134#define OID_GEN_BROADCAST_BYTES_XMIT 0x00020205
135#define OID_GEN_BROADCAST_FRAMES_XMIT 0x00020206
136#define OID_GEN_DIRECTED_BYTES_RCV 0x00020207
137#define OID_GEN_DIRECTED_FRAMES_RCV 0x00020208
138#define OID_GEN_MULTICAST_BYTES_RCV 0x00020209
139#define OID_GEN_MULTICAST_FRAMES_RCV 0x0002020A
140#define OID_GEN_BROADCAST_BYTES_RCV 0x0002020B
141#define OID_GEN_BROADCAST_FRAMES_RCV 0x0002020C
142#define OID_GEN_RCV_CRC_ERROR 0x0002020D
143#define OID_GEN_TRANSMIT_QUEUE_LENGTH 0x0002020E
144
145//Ethernet objects (required)
146#define OID_802_3_PERMANENT_ADDRESS 0x01010101
147#define OID_802_3_CURRENT_ADDRESS 0x01010102
148#define OID_802_3_MULTICAST_LIST 0x01010103
149#define OID_802_3_MAXIMUM_LIST_SIZE 0x01010104
150#define OID_802_3_MAC_OPTIONS 0x01010105
151#define OID_802_3_RCV_ERROR_ALIGNMENT 0x01020101
152#define OID_802_3_XMIT_ONE_COLLISION 0x01020102
153#define OID_802_3_XMIT_MORE_COLLISIONS 0x01020103
154#define OID_802_3_XMIT_DEFERRED 0x01020201
155#define OID_802_3_XMIT_MAX_COLLISIONS 0x01020202
156#define OID_802_3_RCV_OVERRUN 0x01020203
157#define OID_802_3_XMIT_UNDERRUN 0x01020204
158#define OID_802_3_XMIT_HEARTBEAT_FAILURE 0x01020205
159#define OID_802_3_XMIT_TIMES_CRS_LOST 0x01020206
160#define OID_802_3_XMIT_LATE_COLLISIONS 0x01020207
161
162//Hardware status of the underlying NIC
163#define RNDIS_HARDWARE_STATUS_READY 0x00000000
164#define RNDIS_HARDWARE_STATUS_INITIALIZING 0x00000001
165#define RNDIS_HARDWARE_STATUS_RESET 0x00000002
166#define RNDIS_HARDWARE_STATUS_CLOSING 0x00000003
167#define RNDIS_HARDWARE_STATUS_NOT_READY 0x00000004
168
169//Media types
170#define RNDIS_MEDIUM_802_3 0x00000000
171
172//Media state
173#define RNDIS_MEDIA_STATE_CONNECTED 0x00000000
174#define RNDIS_MEDIA_STATE_DISCONNECTED 0x00000001
175
176//Packet filter
177#define RNDIS_PACKET_TYPE_DIRECTED 0x00000001
178#define RNDIS_PACKET_TYPE_MULTICAST 0x00000002
179#define RNDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004
180#define RNDIS_PACKET_TYPE_BROADCAST 0x00000008
181#define RNDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010
182#define RNDIS_PACKET_TYPE_PROMISCUOUS 0x00000020
183#define RNDIS_PACKET_TYPE_SMT 0x00000040
184#define RNDIS_PACKET_TYPE_ALL_LOCAL 0x00000080
185#define RNDIS_PACKET_TYPE_GROUP 0x00000100
186#define RNDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200
187#define RNDIS_PACKET_TYPE_FUNCTIONAL 0x00000400
188#define RNDIS_PACKET_TYPE_MAC_FRAME 0x00000800
189
190
195typedef enum
196{
197 RNDIS_STATE_UNINITIALIZED = 0,
198 RNDIS_STATE_BUS_INITIALIZED = 1,
199 RNDIS_STATE_INITIALIZED = 2,
200 RNDIS_STATE_DATA_INITIALIZED = 3
201} RndisState;
202
203
208typedef struct
209{
210 uint32_t messageType; //0-3
211 uint32_t messageLength; //4-7
212} RndisMsg;
213
214
219typedef struct
220{
221 uint32_t messageType; //0-3
222 uint32_t messageLength; //4-7
223 uint32_t requestId; //8-11
224 uint32_t majorVersion; //12-15
225 uint32_t minorVersion; //16-19
226 uint32_t maxTransferSize; //20-23
228
229
234typedef struct
235{
236 uint32_t messageType; //0-3
237 uint32_t messageLength; //4-7
238 uint32_t requestId; //8-11
240
241
246typedef struct
247{
248 uint32_t messageType; //0-3
249 uint32_t messageLength; //4-7
250 uint32_t requestId; //8-11
251 uint32_t oid; //12-15
252 uint32_t infoBufferLength; //16-19
253 uint32_t infoBufferOffset; //20-23
254 uint32_t reserved; //24-27
255 uint8_t oidInputBuffer[]; //28
257
258
263typedef struct
264{
265 uint32_t messageType; //0-3
266 uint32_t messageLength; //4-7
267 uint32_t requestId; //8-11
268 uint32_t oid; //12-15
269 uint32_t infoBufferLength; //16-19
270 uint32_t infoBufferOffset; //20-23
271 uint32_t reserved; //24-27
272 uint8_t oidInputBuffer[]; //28
274
275
280typedef struct
281{
282 uint32_t messageType; //0-3
283 uint32_t messageLength; //4-7
284 uint32_t reserved; //8-11
286
287
292typedef struct
293{
294 uint32_t messageType; //0-3
295 uint32_t messageLength; //4-7
296 uint32_t status; //8-11
297 uint32_t statusBufferLength; //12-15
298 uint32_t statusBufferOffset; //16-19
299 uint8_t diagnosticInfoBuffer[]; //20
301
302
307typedef struct
308{
309 uint32_t diagStatus; //0-3
310 uint32_t errorOffset; //4-7
312
313
318typedef struct
319{
320 uint32_t messageType; //0-3
321 uint32_t messageLength; //4-7
322 uint32_t requestId; //8-11
324
325
330typedef struct
331{
332 uint32_t messageType; //0-3
333 uint32_t messageLength; //4-7
334 uint32_t requestId; //8-11
335 uint32_t status; //12-15
336 uint32_t majorVersion; //16-19
337 uint32_t minorVersion; //20-23
338 uint32_t deviceFlags; //24-27
339 uint32_t medium; //28-31
340 uint32_t maxPacketsPerTransfer; //32-35
341 uint32_t maxTransferSize; //36-39
342 uint32_t packetAlignmentFactor; //40-43
343 uint32_t afListOffset; //44-47
344 uint32_t afListSize; //48-51
346
347
352typedef struct
353{
354 uint32_t messageType; //0-3
355 uint32_t messageLength; //4-7
356 uint32_t requestId; //8-11
357 uint32_t status; //12-15
358 uint32_t infoBufferLength; //16-19
359 uint32_t infoBufferOffset; //20-23
360 uint8_t oidInputBuffer[]; //24
362
363
368typedef struct
369{
370 uint32_t messageType; //0-3
371 uint32_t messageLength; //4-7
372 uint32_t requestId; //8-11
373 uint32_t status; //12-15
375
376
381typedef struct
382{
383 uint32_t messageType; //0-3
384 uint32_t messageLength; //4-7
385 uint32_t status; //8-11
386 uint32_t addressingReset; //12-15
388
389
394typedef struct
395{
396 uint32_t messageType; //0-3
397 uint32_t messageLength; //4-7
398 uint32_t requestId; //8-11
399 uint32_t status; //12-15
401
402
407typedef struct
408{
409 uint32_t messageType; //0-3
410 uint32_t messageLength; //4-7
411 uint32_t dataOffset; //8-11
412 uint32_t dataLength; //12-15
413 uint32_t oobDataOffset; //16-19
414 uint32_t oobDataLength; //20-23
415 uint32_t numOobDataElements; //24-27
416 uint32_t perPacketInfoOffset; //28-31
417 uint32_t perPacketInfoLength; //32-35
418 uint32_t vcHandle; //36-39
419 uint32_t reserved; //40-43
420 uint8_t payload[]; //44
422
423
428typedef struct
429{
430 uint32_t size; //0-3
431 uint32_t type; //4-7
432 uint32_t classInfoOffset; //8-11
433 uint8_t oobData[]; //12
435
436
441typedef struct
442{
443 uint32_t size; //0-3
444 uint32_t type; //4-7
445 uint32_t perPacketInfoOffset; //8-11
446 uint8_t perPacketData[]; //12
448
449
454typedef struct
455{
456 uint32_t notification; //0-3
457 uint32_t reserved; //4-7
459
460
465typedef struct
466{
467 RndisState state;
468 bool_t linkEvent;
469 bool_t linkState;
470 bool_t txState;
471 bool_t rxState;
472 uint32_t packetFilter;
473 uint8_t rxBuffer[RNDIS_MAX_TRANSFER_SIZE];
474 size_t rxBufferLen;
475 uint8_t encapsulatedResp[RNDIS_MAX_TRANSFER_SIZE];
476 size_t encapsulatedRespLen;
477
478 uint32_t data[512 / 4];
479 uint8_t CmdOpCode;
480 uint8_t CmdLength;
482
483//Global variables
484extern RndisContext rndisContext;
485
486//RNDIS related functions
487void rndisInit(void);
488
489error_t rndisProcessMsg(const RndisMsg *message, size_t length);
490error_t rndisProcessInitializeMsg(const RndisInitializeMsg *message, size_t length);
491error_t rndisProcessHaltMsg(const RndisHaltMsg *message, size_t length);
492error_t rndisProcessQueryMsg(const RndisQueryMsg *message, size_t length);
493error_t rndisProcessSetMsg(const RndisSetMsg *message, size_t length);
494error_t rndisProcessResetMsg(const RndisResetMsg *message, size_t length);
495error_t rndisProcessKeepAliveMsg(const RndisKeepAliveMsg *message, size_t length);
496
497error_t rndisFormatHaltMsg(void);
498error_t rndisFormatIndicateStatusMsg(uint32_t status);
499
500error_t rndisFormatInitializeCmplt(uint32_t requestId);
501error_t rndisFormatQueryCmplt(uint32_t requestId, uint32_t status, uint32_t length);
502error_t rndisFormatSetCmplt(uint32_t requestId, uint32_t status);
503error_t rndisFormatResetCmplt(void);
504error_t rndisFormatKeepAliveCmplt(uint32_t requestId);
505
506error_t rndisSendNotification(uint32_t notification);
507
508void rndisChangeState(RndisState newState);
509
510#endif
Error codes description.
error_t
Error codes.
Definition error.h:43
TCP/IP stack core.
RndisState
RNDIS states.
Definition rndis.h:196
RNDIS context.
Definition rndis.h:466
Diagnostic information.
Definition rndis.h:308
RNDIS Halt message.
Definition rndis.h:235
RNDIS Indicate Status message.
Definition rndis.h:293
Response to a RNDIS Initialize message.
Definition rndis.h:331
RNDIS Initialize message.
Definition rndis.h:220
Response to a RNDIS Keep-Alive message.
Definition rndis.h:395
RNDIS Keep-Alive message.
Definition rndis.h:319
Generic RNDIS message.
Definition rndis.h:209
Device notification message.
Definition rndis.h:455
Out-of-band data record.
Definition rndis.h:429
RNDIS Packet message.
Definition rndis.h:408
Per-packet information data record.
Definition rndis.h:442
Response to a RNDIS Query message.
Definition rndis.h:353
RNDIS Query message.
Definition rndis.h:247
Response to a RNDIS Reset message.
Definition rndis.h:382
RNDIS Reset message.
Definition rndis.h:281
Response to a RNDIS Set message.
Definition rndis.h:369
RNDIS Set message.
Definition rndis.h:264