+++ /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
- /* 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_SendKeepAlive(void)\r
-{\r
- uint8_t ErrorCode;\r
-\r
- RNDIS_KeepAlive_Message_t KeepAliveMessage;\r
- RNDIS_KeepAlive_Complete_t KeepAliveMessageResponse;\r
- \r
- KeepAliveMessage.MessageType = REMOTE_NDIS_KEEPALIVE_MSG;\r
- KeepAliveMessage.MessageLength = sizeof(RNDIS_KeepAlive_Message_t);\r
- KeepAliveMessage.RequestId = RequestID++;\r
-\r
- if ((ErrorCode = RNDIS_SendEncapsulatedCommand(&KeepAliveMessage,\r
- sizeof(RNDIS_KeepAlive_Message_t))) != HOST_SENDCONTROL_Successful)\r
- {\r
- return ErrorCode;\r
- }\r
- \r
- if ((ErrorCode = RNDIS_GetEncapsulatedResponse(&KeepAliveMessageResponse,\r
- sizeof(RNDIS_KeepAlive_Complete_t))) != HOST_SENDCONTROL_Successful)\r
- {\r
- return ErrorCode;\r
- }\r
- \r
- return HOST_SENDCONTROL_Successful;\r
-}\r
-\r
-uint8_t RNDIS_InitializeDevice(uint16_t HostMaxPacketSize, uint16_t* DeviceMaxPacketSize)\r
-{\r
- uint8_t ErrorCode;\r
-\r
- RNDIS_Initialize_Message_t InitMessage;\r
- RNDIS_Initialize_Complete_t InitMessageResponse;\r
-\r
- InitMessage.MessageType = REMOTE_NDIS_INITIALIZE_MSG;\r
- InitMessage.MessageLength = sizeof(RNDIS_Initialize_Message_t);\r
- InitMessage.RequestId = RequestID++;\r
-\r
- InitMessage.MajorVersion = REMOTE_NDIS_VERSION_MAJOR;\r
- InitMessage.MinorVersion = REMOTE_NDIS_VERSION_MINOR;\r
- InitMessage.MaxTransferSize = HostMaxPacketSize;\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
- if (InitMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)\r
- return RNDIS_COMMAND_FAILED;\r
- \r
- *DeviceMaxPacketSize = InitMessageResponse.MaxTransferSize;\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 = (sizeof(RNDIS_Set_Message_t) - sizeof(RNDIS_Message_Header_t));\r
- SetMessageData.SetMessage.DeviceVcHandle = 0;\r
- \r
- memcpy(&SetMessageData.ContigiousBuffer, Buffer, Length);\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
- if (SetMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)\r
- return RNDIS_COMMAND_FAILED;\r
- \r
- return HOST_SENDCONTROL_Successful;\r
-}\r
-\r
-uint8_t RNDIS_QueryRNDISProperty(uint32_t Oid, void* Buffer, uint16_t MaxLength)\r
-{\r
- uint8_t ErrorCode;\r
-\r
- RNDIS_Query_Message_t QueryMessage;\r
-\r
- struct\r
- {\r
- RNDIS_Query_Complete_t QueryMessageResponse;\r
- uint8_t ContigiousBuffer[MaxLength];\r
- } QueryMessageResponseData;\r
-\r
- QueryMessage.MessageType = REMOTE_NDIS_QUERY_MSG;\r
- QueryMessage.MessageLength = sizeof(RNDIS_Query_Message_t);\r
- QueryMessage.RequestId = RequestID++;\r
- \r
- QueryMessage.Oid = Oid;\r
- QueryMessage.InformationBufferLength = 0;\r
- QueryMessage.InformationBufferOffset = 0;\r
- QueryMessage.DeviceVcHandle = 0;\r
-\r
- if ((ErrorCode = RNDIS_SendEncapsulatedCommand(&QueryMessage,\r
- sizeof(RNDIS_Query_Message_t))) != HOST_SENDCONTROL_Successful)\r
- {\r
- return ErrorCode;\r
- }\r
- \r
- if ((ErrorCode = RNDIS_GetEncapsulatedResponse(&QueryMessageResponseData,\r
- sizeof(QueryMessageResponseData))) != HOST_SENDCONTROL_Successful)\r
- {\r
- return ErrorCode;\r
- }\r
-\r
- if (QueryMessageResponseData.QueryMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)\r
- return RNDIS_COMMAND_FAILED;\r
-\r
- memcpy(Buffer, &QueryMessageResponseData.ContigiousBuffer, MaxLength);\r
-\r
- return HOST_SENDCONTROL_Successful;\r
-}\r
-\r
-uint8_t RNDIS_GetPacketLength(uint16_t* PacketLength)\r
-{\r
- uint8_t ErrorCode;\r
-\r
- RNDIS_Packet_Message_t DeviceMessage;\r
- \r
- if ((ErrorCode = Pipe_Read_Stream_LE(&DeviceMessage, sizeof(RNDIS_Packet_Message_t))) != PIPE_RWSTREAM_NoError)\r
- {\r
- return ErrorCode;\r
- }\r
-\r
- *PacketLength = (uint16_t)DeviceMessage.DataLength;\r
- \r
- Pipe_Discard_Stream(DeviceMessage.DataOffset - (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)));\r
- \r
- return PIPE_RWSTREAM_NoError;\r
-}\r