3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
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.
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
33 * RNDOS Device commands, to issue RNDIS commands to the device for
34 * the control and data transfer between the host and RNDIS device.
37 #include "RNDISCommands.h"
39 uint32_t RequestID
= 0;
41 uint8_t RNDIS_SendEncapsulatedCommand(void* Buffer
, uint16_t Length
)
43 USB_ControlRequest
= (USB_Request_Header_t
)
45 .bmRequestType
= (REQDIR_HOSTTODEVICE
| REQTYPE_CLASS
| REQREC_INTERFACE
),
46 .bRequest
= REQ_SendEncapsulatedCommand
,
52 /* Select the control pipe for the request transfer */
53 Pipe_SelectPipe(PIPE_CONTROLPIPE
);
55 return USB_Host_SendControlRequest(Buffer
);
58 uint8_t RNDIS_GetEncapsulatedResponse(void* Buffer
, uint16_t Length
)
60 USB_ControlRequest
= (USB_Request_Header_t
)
62 .bmRequestType
= (REQDIR_DEVICETOHOST
| REQTYPE_CLASS
| REQREC_INTERFACE
),
63 .bRequest
= REQ_GetEncapsulatedResponse
,
69 /* Select the control pipe for the request transfer */
70 Pipe_SelectPipe(PIPE_CONTROLPIPE
);
72 return USB_Host_SendControlRequest(Buffer
);
75 uint8_t RNDIS_KeepAlive(void)
79 RNDIS_KeepAlive_Message_t KeepAliveMessage
;
80 RNDIS_KeepAlive_Complete_t KeepAliveMessageResponse
;
82 KeepAliveMessage
.MessageType
= REMOTE_NDIS_KEEPALIVE_MSG
;
83 KeepAliveMessage
.MessageLength
= sizeof(RNDIS_KeepAlive_Message_t
);
84 KeepAliveMessage
.RequestId
= RequestID
++;
86 if ((ErrorCode
= RNDIS_SendEncapsulatedCommand(&KeepAliveMessage
,
87 sizeof(RNDIS_KeepAlive_Message_t
))) != HOST_SENDCONTROL_Successful
)
92 if ((ErrorCode
= RNDIS_GetEncapsulatedResponse(&KeepAliveMessageResponse
,
93 sizeof(RNDIS_KeepAlive_Complete_t
))) != HOST_SENDCONTROL_Successful
)
98 return HOST_SENDCONTROL_Successful
;
101 uint8_t RNDIS_InitializeDevice(uint16_t MaxPacketSize
, RNDIS_Initialize_Complete_t
* InitMessageResponse
)
105 RNDIS_Initialize_Message_t InitMessage
;
107 InitMessage
.MessageType
= REMOTE_NDIS_INITIALIZE_MSG
;
108 InitMessage
.MessageLength
= sizeof(RNDIS_Initialize_Message_t
);
109 InitMessage
.RequestId
= RequestID
++;
110 InitMessage
.MajorVersion
= REMOTE_NDIS_VERSION_MAJOR
;
111 InitMessage
.MinorVersion
= REMOTE_NDIS_VERSION_MINOR
;
112 InitMessage
.MaxTransferSize
= sizeof(RNDIS_Packet_Message_t
) + MaxPacketSize
;
114 if ((ErrorCode
= RNDIS_SendEncapsulatedCommand(&InitMessage
,
115 sizeof(RNDIS_Initialize_Message_t
))) != HOST_SENDCONTROL_Successful
)
120 if ((ErrorCode
= RNDIS_GetEncapsulatedResponse(InitMessageResponse
,
121 sizeof(RNDIS_Initialize_Complete_t
))) != HOST_SENDCONTROL_Successful
)
126 return HOST_SENDCONTROL_Successful
;
129 uint8_t RNDIS_SetRNDISProperty(uint32_t Oid
, void* Buffer
, uint16_t Length
)
135 RNDIS_Set_Message_t SetMessage
;
136 uint8_t ContigiousBuffer
[Length
];
139 RNDIS_Set_Complete_t SetMessageResponse
;
141 SetMessageData
.SetMessage
.MessageType
= REMOTE_NDIS_SET_MSG
;
142 SetMessageData
.SetMessage
.MessageLength
= sizeof(RNDIS_Set_Message_t
) + Length
;
143 SetMessageData
.SetMessage
.RequestId
= RequestID
++;
145 SetMessageData
.SetMessage
.Oid
= Oid
;
146 SetMessageData
.SetMessage
.InformationBufferLength
= Length
;
147 SetMessageData
.SetMessage
.InformationBufferOffset
= 0;
148 SetMessageData
.SetMessage
.DeviceVcHandle
= 0;
150 memcpy(&SetMessageData
.ContigiousBuffer
, Buffer
, Length
);
152 if ((ErrorCode
= RNDIS_SendEncapsulatedCommand(&SetMessageData
,
153 SetMessageData
.SetMessage
.MessageLength
)) != HOST_SENDCONTROL_Successful
)
158 if ((ErrorCode
= RNDIS_GetEncapsulatedResponse(&SetMessageResponse
,
159 sizeof(RNDIS_Set_Complete_t
))) != HOST_SENDCONTROL_Successful
)
164 return HOST_SENDCONTROL_Successful
;
167 uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid
, void* Buffer
, uint16_t Length
)
171 RNDIS_Query_Message_t QueryMessage
;
175 RNDIS_Query_Complete_t QueryMessageResponse
;
176 uint8_t ContigiousBuffer
[Length
];
177 } QueryMessageResponseData
;
179 QueryMessage
.MessageType
= REMOTE_NDIS_QUERY_MSG
;
180 QueryMessage
.MessageLength
= sizeof(RNDIS_Query_Message_t
);
181 QueryMessage
.RequestId
= RequestID
++;
183 QueryMessage
.Oid
= Oid
;
184 QueryMessage
.InformationBufferLength
= Length
;
185 QueryMessage
.InformationBufferOffset
= 0;
186 QueryMessage
.DeviceVcHandle
= 0;
188 if ((ErrorCode
= RNDIS_SendEncapsulatedCommand(&QueryMessage
,
189 sizeof(RNDIS_Query_Message_t
))) != HOST_SENDCONTROL_Successful
)
194 if ((ErrorCode
= RNDIS_GetEncapsulatedResponse(&QueryMessageResponseData
,
195 sizeof(QueryMessageResponseData
))) != HOST_SENDCONTROL_Successful
)
200 memcpy(Buffer
, &QueryMessageResponseData
.ContigiousBuffer
, Length
);
202 return HOST_SENDCONTROL_Successful
;
205 uint8_t RNDIS_GetPacketSize(uint16_t* PacketSize
)
209 RNDIS_Packet_Message_t DeviceMessage
;
211 if ((ErrorCode
= Pipe_Read_Stream_LE(&DeviceMessage
, sizeof(RNDIS_Packet_Message_t
))) != PIPE_RWSTREAM_NoError
)
216 *PacketSize
= (uint16_t)DeviceMessage
.DataLength
;
218 return PIPE_RWSTREAM_NoError
;