--- /dev/null
+/*\r
+ LUFA Library\r
+ Copyright (C) Dean Camera, 2009.\r
+ \r
+ dean [at] fourwalledcubicle [dot] com\r
+ www.fourwalledcubicle.com\r
+*/\r
+\r
+/*\r
+ Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+ Permission to use, copy, modify, and distribute this software\r
+ and its documentation for any purpose and without fee is hereby\r
+ granted, provided that the above copyright notice appear in all\r
+ copies and that both that the copyright notice and this\r
+ permission notice and warranty disclaimer appear in supporting\r
+ documentation, and that the name of the author not be used in\r
+ advertising or publicity pertaining to distribution of the\r
+ software without specific, written prior permission.\r
+\r
+ The author disclaim all warranties with regard to this\r
+ software, including all implied warranties of merchantability\r
+ and fitness. In no event shall the author be liable for any\r
+ special, indirect or consequential damages or any damages\r
+ whatsoever resulting from loss of use, data or profits, whether\r
+ in an action of contract, negligence or other tortious action,\r
+ arising out of or in connection with the use or performance of\r
+ this software.\r
+*/\r
+\r
+/** \file\r
+ *\r
+ * RNDOS Device commands, to issue RNDIS commands to the device for\r
+ * the control and data transfer between the host and RNDIS device.\r
+ */\r
+\r
+#include "RNDISCommands.h"\r
+\r
+uint32_t RequestID = 0;\r
+\r
+uint8_t RNDIS_SendEncapsulatedCommand(void* Buffer, uint16_t Length)\r
+{\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
+ {\r
+ .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
+ .bRequest = REQ_SendEncapsulatedCommand,\r
+ .wValue = 0,\r
+ .wIndex = 0,\r
+ .wLength = Length,\r
+ };\r
+ \r
+ printf("==== RNDIS CONTROL REQUEST ====\r\n");\r
+ uint8_t* Data = Buffer;\r
+ for (uint16_t i = 0; i < Length / 8; i++)\r
+ {\r
+ for (uint16_t j = 0; (j < 8) && i*8+j < Length; j++)\r
+ printf("%02X ", *(Data++));\r
+ \r
+ printf("\r\n");\r
+ }\r
+ printf("==== ********************* ====\r\n");\r
+\r
+ /* Select the control pipe for the request transfer */\r
+ Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
+ return USB_Host_SendControlRequest(Buffer);\r
+}\r
+\r
+uint8_t RNDIS_GetEncapsulatedResponse(void* Buffer, uint16_t Length)\r
+{\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
+ {\r
+ .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),\r
+ .bRequest = REQ_GetEncapsulatedResponse,\r
+ .wValue = 0,\r
+ .wIndex = 0,\r
+ .wLength = Length,\r
+ };\r
+ \r
+ /* Select the control pipe for the request transfer */\r
+ Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
+ return USB_Host_SendControlRequest(Buffer);\r
+}\r
+\r
+uint8_t RNDIS_InitializeDevice(uint16_t MaxPacketSize, RNDIS_Initialize_Complete_t* InitMessageResponse)\r
+{\r
+ uint8_t ErrorCode;\r
+\r
+ RNDIS_Initialize_Message_t InitMessage;\r
+\r
+ InitMessage.MessageType = REMOTE_NDIS_INITIALIZE_MSG;\r
+ InitMessage.MessageLength = sizeof(RNDIS_Initialize_Message_t);\r
+ InitMessage.RequestId = RequestID++;\r
+ InitMessage.MajorVersion = REMOTE_NDIS_VERSION_MAJOR;\r
+ InitMessage.MinorVersion = REMOTE_NDIS_VERSION_MINOR;\r
+ InitMessage.MaxTransferSize = sizeof(RNDIS_Packet_Message_t) + MaxPacketSize;\r
+ \r
+ if ((ErrorCode = RNDIS_SendEncapsulatedCommand(&InitMessage,\r
+ sizeof(RNDIS_Initialize_Message_t))) != HOST_SENDCONTROL_Successful)\r
+ {\r
+ return ErrorCode;\r
+ }\r
+ \r
+ if ((ErrorCode = RNDIS_GetEncapsulatedResponse(InitMessageResponse,\r
+ sizeof(RNDIS_Initialize_Complete_t))) != HOST_SENDCONTROL_Successful)\r
+ {\r
+ return ErrorCode;\r
+ }\r
+ \r
+ return HOST_SENDCONTROL_Successful;\r
+}\r
+\r
+uint8_t RNDIS_SetRNDISProperty(uint32_t Oid, void* Buffer, uint16_t Length)\r
+{\r
+ uint8_t ErrorCode;\r
+\r
+ struct\r
+ {\r
+ RNDIS_Set_Message_t SetMessage;\r
+ uint8_t ContigiousBuffer[Length];\r
+ } SetMessageData;\r
+ \r
+ RNDIS_Set_Complete_t SetMessageResponse;\r
+ \r
+ SetMessageData.SetMessage.MessageType = REMOTE_NDIS_SET_MSG;\r
+ SetMessageData.SetMessage.MessageLength = sizeof(RNDIS_Set_Message_t) + Length;\r
+ SetMessageData.SetMessage.RequestId = RequestID++;\r
+ \r
+ SetMessageData.SetMessage.Oid = Oid;\r
+ SetMessageData.SetMessage.InformationBufferLength = Length;\r
+ SetMessageData.SetMessage.InformationBufferOffset = 0;\r
+ SetMessageData.SetMessage.DeviceVcHandle = 0;\r
+\r
+\r
+ if ((ErrorCode = RNDIS_SendEncapsulatedCommand(&SetMessageData,\r
+ SetMessageData.SetMessage.MessageLength)) != HOST_SENDCONTROL_Successful)\r
+ {\r
+ return ErrorCode;\r
+ }\r
+ \r
+ if ((ErrorCode = RNDIS_GetEncapsulatedResponse(&SetMessageResponse,\r
+ sizeof(RNDIS_Set_Complete_t))) != HOST_SENDCONTROL_Successful)\r
+ {\r
+ return ErrorCode;\r
+ }\r
+\r
+ return HOST_SENDCONTROL_Successful;\r
+}\r