Commit 397c2f91 authored by Dean Camera's avatar Dean Camera

Merge over trunk changes to the 110528 BETA to form the 110528 release.

parent 2b09c428
......@@ -66,6 +66,9 @@ int main(void)
/* Setup hardware required for the bootloader */
SetupHardware();
/* Turn on first LED on the board to indicate that the bootloader has started */
LEDs_SetAllLEDs(LEDS_LED1);
/* Enable global interrupts so that the USB stack can function */
sei();
......@@ -100,6 +103,17 @@ void SetupHardware(void)
/* Initialize USB Subsystem */
USB_Init();
LEDs_Init();
/* Bootloader active LED toggle timer initialization */
TIMSK1 = (1 << TOIE1);
TCCR1B = ((1 << CS11) | (1 << CS10));
}
/** ISR to periodically toggle the LEDs on the board to indicate that the bootloader is active. */
ISR(TIMER1_OVF_vect, ISR_BLOCK)
{
LEDs_ToggleLEDs(LEDS_LED1 | LEDS_LED2);
}
/** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready
......@@ -134,6 +148,9 @@ void EVENT_USB_Device_ControlRequest(void)
return;
}
/* Activity - toggle indicator LEDs */
LEDs_ToggleLEDs(LEDS_LED1 | LEDS_LED2);
/* Process CDC specific control requests */
switch (USB_ControlRequest.bRequest)
{
......
......@@ -48,6 +48,7 @@
#include "Descriptors.h"
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/LEDs.h>
/* Macros: */
/** Version major of the CDC bootloader. */
......
......@@ -119,6 +119,9 @@ int main(void)
MCUCR &= ~(1 << JTD);
#endif
/* Turn on first LED on the board to indicate that the bootloader has started */
LEDs_SetAllLEDs(LEDS_LED1);
/* Enable global interrupts so that the USB stack can function */
sei();
......@@ -149,6 +152,11 @@ void SetupHardware(void)
/* Initialize the USB subsystem */
USB_Init();
LEDs_Init();
/* Bootloader active LED toggle timer initialization */
TIMSK1 = (1 << TOIE1);
TCCR1B = ((1 << CS11) | (1 << CS10));
}
/** Resets all configured hardware required for the bootloader back to their original states. */
......@@ -162,15 +170,18 @@ void ResetHardware(void)
MCUCR = 0;
}
/** ISR to periodically toggle the LEDs on the board to indicate that the bootloader is active. */
ISR(TIMER1_OVF_vect, ISR_BLOCK)
{
LEDs_ToggleLEDs(LEDS_LED1 | LEDS_LED2);
}
/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to
* the device from the USB host before passing along unhandled control requests to the library for processing
* internally.
*/
void EVENT_USB_Device_ControlRequest(void)
{
/* Get the size of the command and data from the wLength value */
SentCommand.DataSize = USB_ControlRequest.wLength;
{
/* Ignore any requests that aren't directed to the DFU interface */
if ((USB_ControlRequest.bmRequestType & (CONTROL_REQTYPE_TYPE | CONTROL_REQTYPE_RECIPIENT)) !=
(REQTYPE_CLASS | REQREC_INTERFACE))
......@@ -178,6 +189,12 @@ void EVENT_USB_Device_ControlRequest(void)
return;
}
/* Activity - toggle indicator LEDs */
LEDs_ToggleLEDs(LEDS_LED1 | LEDS_LED2);
/* Get the size of the command and data from the wLength value */
SentCommand.DataSize = USB_ControlRequest.wLength;
switch (USB_ControlRequest.bRequest)
{
case DFU_REQ_DNLOAD:
......
......@@ -50,6 +50,7 @@
#include "Descriptors.h"
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Board/LEDs.h>
/* Macros: */
/** Configuration define. Define this token to true to case the bootloader to reject all memory commands
......
......@@ -113,10 +113,18 @@ void EVENT_USB_Device_ControlRequest(void)
while (!(Endpoint_IsOUTReceived()));
/* Read in the write destination address */
#if (FLASHEND > 0xFFFF)
uint32_t PageAddress = ((uint32_t)Endpoint_Read_16_LE() << 8);
#else
uint16_t PageAddress = Endpoint_Read_16_LE();
#endif
/* Check if the command is a program page command, or a start application command */
#if (FLASHEND > 0xFFFF)
if ((uint16_t)(PageAddress >> 8) == COMMAND_STARTAPPLICATION)
#else
if (PageAddress == COMMAND_STARTAPPLICATION)
#endif
{
RunBootloader = false;
}
......
......@@ -59,7 +59,7 @@ int16_t DHCP_ProcessDHCPPacket(void* IPHeaderInStart,
DecodeDHCPHeader(DHCPHeaderInStart);
/* Zero out the response DHCP packet, as much of it legacy and left at 0 */
/* Zero out the response DHCP packet, as much of it is legacy and left at 0 */
memset(DHCPHeaderOUT, 0, sizeof(DHCP_Header_t));
/* Fill out the response DHCP packet */
......
......@@ -96,7 +96,6 @@ void Ethernet_ProcessPacket(Ethernet_Frame_Info_t* const FrameIN,
/* Set the response length in the buffer and indicate that a response is ready to be sent */
FrameOUT->FrameLength = (sizeof(Ethernet_Frame_Header_t) + RetSize);
FrameOUT->FrameInBuffer = true;
}
}
......@@ -104,7 +103,7 @@ void Ethernet_ProcessPacket(Ethernet_Frame_Info_t* const FrameIN,
if (RetSize != NO_PROCESS)
{
/* Clear the frame buffer */
FrameIN->FrameInBuffer = false;
FrameIN->FrameLength = 0;
}
}
......
......@@ -55,7 +55,8 @@ TCP_ConnectionState_t ConnectionStateTable[MAX_TCP_CONNECTIONS];
* level. If an application produces a response, this task constructs the appropriate Ethernet frame and places it into the Ethernet OUT
* buffer for later transmission.
*/
void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo)
void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
Ethernet_Frame_Info_t* const FrameOUT)
{
/* Run each application in sequence, to process incoming and generate outgoing packets */
for (uint8_t CSTableEntry = 0; CSTableEntry < MAX_TCP_CONNECTIONS; CSTableEntry++)
......@@ -73,11 +74,8 @@ void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo)
}
}
/* Get pointer to the output frame info struct for convenience */
Ethernet_Frame_Info_t* FrameOUT = &RNDISInterfaceInfo->State.FrameOUT;
/* Bail out early if there is already a frame waiting to be sent in the Ethernet OUT buffer */
if (FrameOUT->FrameInBuffer)
if (FrameOUT->FrameLength)
return;
/* Send response packets from each application as the TCP packet buffers are filled by the applications */
......@@ -147,7 +145,6 @@ void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo)
/* Set the response length in the buffer and indicate that a response is ready to be sent */
FrameOUT->FrameLength = PacketSize;
FrameOUT->FrameInBuffer = true;
ConnectionStateTable[CSTableEntry].Info.Buffer.Ready = false;
......
......@@ -228,7 +228,8 @@
} TCP_Header_t;
/* Function Prototypes: */
void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo);
void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
Ethernet_Frame_Info_t* const FrameOUT);
void TCP_Init(void);
bool TCP_SetPortState(const uint16_t Port,
const uint8_t State,
......
......@@ -63,6 +63,11 @@ USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface =
},
};
/** Global to store the incoming frame from the host before it is processed by the device. */
static Ethernet_Frame_Info_t FrameIN;
/** Global to store the outgoing frame created in the device before it is sent to the host. */
static Ethernet_Frame_Info_t FrameOUT;
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
......@@ -79,14 +84,23 @@ int main(void)
for (;;)
{
if (Ethernet_RNDIS_Interface.State.FrameIN.FrameInBuffer)
if (RNDIS_Device_IsPacketReceived(&Ethernet_RNDIS_Interface))
{
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
Ethernet_ProcessPacket(&Ethernet_RNDIS_Interface.State.FrameIN, &Ethernet_RNDIS_Interface.State.FrameOUT);
RNDIS_Device_ReadPacket(&Ethernet_RNDIS_Interface, &FrameIN.FrameData, &FrameIN.FrameLength);
Ethernet_ProcessPacket(&FrameIN, &FrameOUT);
if (FrameOUT.FrameLength)
{
RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface, &FrameOUT.FrameData, FrameOUT.FrameLength);
FrameOUT.FrameLength = 0;
}
LEDs_SetAllLEDs(LEDMASK_USB_READY);
}
TCP_TCPTask(&Ethernet_RNDIS_Interface);
TCP_TCPTask(&Ethernet_RNDIS_Interface, &FrameOUT);
RNDIS_Device_USBTask(&Ethernet_RNDIS_Interface);
USB_USBTask();
......
......@@ -59,7 +59,7 @@ int16_t DHCP_ProcessDHCPPacket(void* IPHeaderInStart,
DecodeDHCPHeader(DHCPHeaderInStart);
/* Zero out the response DHCP packet, as much of it legacy and left at 0 */
/* Zero out the response DHCP packet, as much of it is legacy and left at 0 */
memset(DHCPHeaderOUT, 0, sizeof(DHCP_Header_t));
/* Fill out the response DHCP packet */
......
......@@ -100,7 +100,6 @@ void Ethernet_ProcessPacket(void)
/* Set the response length in the buffer and indicate that a response is ready to be sent */
FrameOUT.FrameLength = (sizeof(Ethernet_Frame_Header_t) + RetSize);
FrameOUT.FrameInBuffer = true;
}
}
......@@ -108,7 +107,7 @@ void Ethernet_ProcessPacket(void)
if (RetSize != NO_PROCESS)
{
/* Clear the frame buffer */
FrameIN.FrameInBuffer = false;
FrameIN.FrameLength = 0;
}
}
......
......@@ -74,7 +74,7 @@ void TCP_Task(void)
}
/* Bail out early if there is already a frame waiting to be sent in the Ethernet OUT buffer */
if (FrameOUT.FrameInBuffer)
if (FrameOUT.FrameLength)
return;
/* Send response packets from each application as the TCP packet buffers are filled by the applications */
......@@ -144,7 +144,6 @@ void TCP_Task(void)
/* Set the response length in the buffer and indicate that a response is ready to be sent */
FrameOUT.FrameLength = PacketSize;
FrameOUT.FrameInBuffer = true;
ConnectionStateTable[CSTableEntry].Info.Buffer.Ready = false;
......
......@@ -204,7 +204,7 @@ void RNDIS_Task(void)
Endpoint_SelectEndpoint(CDC_RX_EPNUM);
/* Check if the data OUT endpoint contains data, and that the IN buffer is empty */
if (Endpoint_IsOUTReceived() && !(FrameIN.FrameInBuffer))
if (Endpoint_IsOUTReceived() && !(FrameIN.FrameLength))
{
/* Read in the packet message header */
Endpoint_Read_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL);
......@@ -224,16 +224,13 @@ void RNDIS_Task(void)
/* Store the size of the Ethernet frame */
FrameIN.FrameLength = RNDISPacketHeader.DataLength;
/* Indicate Ethernet IN buffer full */
FrameIN.FrameInBuffer = true;
}
/* Select the data IN endpoint */
Endpoint_SelectEndpoint(CDC_TX_EPNUM);
/* Check if the data IN endpoint is ready for more data, and that the IN buffer is full */
if (Endpoint_IsINReady() && FrameOUT.FrameInBuffer)
if (Endpoint_IsINReady() && FrameOUT.FrameLength)
{
/* Clear the packet header with all 0s so that the relevant fields can be filled */
memset(&RNDISPacketHeader, 0, sizeof(RNDIS_Packet_Message_t));
......@@ -254,7 +251,7 @@ void RNDIS_Task(void)
Endpoint_ClearIN();
/* Indicate Ethernet OUT buffer no longer full */
FrameOUT.FrameInBuffer = false;
FrameOUT.FrameLength = 0;
}
}
}
......@@ -273,7 +270,7 @@ void Ethernet_Task(void)
return;
/* Check if a frame has been written to the IN frame buffer */
if (FrameIN.FrameInBuffer)
if (FrameIN.FrameLength)
{
/* Indicate packet processing started */
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
......
......@@ -236,9 +236,7 @@ ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-l
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += -Wl,--relax
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,--rodata-writable
LDFLAGS += -Wl,--gc-sections --rodata-writable
LDFLAGS += -Wl,--direct-data
#LDFLAGS += -T linker_script.x
......
......@@ -73,7 +73,10 @@
/* Architecture specific utility includes: */
#if defined(__DOXYGEN__)
/** Type define for an unsigned integer the same width as the selected architecture's machine register. */
/** Type define for an unsigned integer the same width as the selected architecture's machine register.
* This is distinct from the non-specific standard int data type, whose width is machine dependant but
* which may not reflect the actual machine register width on some targets (e.g. AVR8).
*/
typedef MACHINE_REG_t uint_reg_t;
#elif (ARCH == ARCH_AVR8)
#include <avr/io.h>
......
......@@ -78,7 +78,7 @@
*
* \return Input value with the byte ordering reversed.
*/
#define SWAPENDIAN_16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
#define SWAPENDIAN_16(x) (uint16_t)((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
/** Swaps the byte ordering of a 32-bit value at compile-time. Do not use this macro for swapping byte orderings
* of dynamic values computed at runtime- use \ref SwapEndian_32() instead. The result of this macro can be used
......@@ -91,8 +91,8 @@
*
* \return Input value with the byte ordering reversed.
*/
#define SWAPENDIAN_32(x) ((((x) & 0xFF000000UL) >> 24UL) | (((x) & 0x00FF0000UL) >> 8UL) | \
(((x) & 0x0000FF00UL) << 8UL) | (((x) & 0x000000FFUL) << 24UL))
#define SWAPENDIAN_32(x) (uint32_t)((((x) & 0xFF000000UL) >> 24UL) | (((x) & 0x00FF0000UL) >> 8UL) | \
(((x) & 0x0000FF00UL) << 8UL) | (((x) & 0x000000FFUL) << 24UL))
#if defined(ARCH_BIG_ENDIAN) && !defined(le16_to_cpu)
#define le16_to_cpu(x) SwapEndian_16(x)
......
......@@ -145,10 +145,10 @@
CDC_CSCP_ATCommandProtocol = 0x01, /**< Descriptor Protocol value indicating that the device or interface
* belongs to the AT Command protocol of the CDC class.
*/
CDC_CSCP_NoSpecificProtocol = 0x00, /**< Descriptor Class value indicating that the device or interface
CDC_CSCP_NoSpecificProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface
* belongs to no specific protocol of the CDC class.
*/
CDC_CSCP_VendorSpecificProtocol = 0xFF, /**< Descriptor Class value indicating that the device or interface
CDC_CSCP_VendorSpecificProtocol = 0xFF, /**< Descriptor Protocol value indicating that the device or interface
* belongs to a vendor-specific protocol of the CDC class.
*/
CDC_CSCP_CDCDataClass = 0x0A, /**< Descriptor Class value indicating that the device or interface
......
......@@ -68,6 +68,9 @@
#endif
/* Macros: */
/** Additional error code for RNDIS functions when a device returns a logical command failure. */
#define RNDIS_ERROR_LOGICAL_CMD_FAILED 0x80
/** Implemented RNDIS Version Major. */
#define REMOTE_NDIS_VERSION_MAJOR 0x01
......@@ -205,25 +208,25 @@
};
/* Type Defines: */
/** \brief MAC Address Structure.
/** \brief Ethernet Frame Packet Information Structure.
*
* Type define for a physical MAC address of a device on a network.
* Type define for an Ethernet frame buffer data and information structure. This can be used to conveniently
* store both the size and data in an Ethernet frame.
*/
typedef struct
{
uint8_t Octets[6]; /**< Individual bytes of a MAC address */
} ATTR_PACKED MAC_Address_t;
uint8_t FrameData[ETHERNET_FRAME_SIZE_MAX]; /**< Ethernet frame contents. */
uint16_t FrameLength; /**< Length in bytes of the Ethernet frame stored in the buffer. */
} Ethernet_Frame_Info_t;
/** \brief RNDIS Ethernet Frame Packet Information Structure.
/** \brief MAC Address Structure.
*
* Type define for an Ethernet frame buffer data and information structure.
* Type define for a physical MAC address of a device on a network.
*/
typedef struct
{
uint8_t FrameData[ETHERNET_FRAME_SIZE_MAX]; /**< Ethernet frame contents. */
uint16_t FrameLength; /**< Length in bytes of the Ethernet frame stored in the buffer. */
bool FrameInBuffer; /**< Indicates if a frame is currently stored in the buffer. */
} ATTR_PACKED Ethernet_Frame_Info_t;
uint8_t Octets[6]; /**< Individual bytes of a MAC address */
} ATTR_PACKED MAC_Address_t;
/** \brief RNDIS Common Message Header Structure.
*
......
......@@ -163,8 +163,6 @@ void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo
if (USB_DeviceState != DEVICE_STATE_Configured)
return;
RNDIS_Message_Header_t* MessageHeader = (RNDIS_Message_Header_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer;
Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.NotificationEndpointNumber);
if (Endpoint_IsINReady() && RNDISInterfaceInfo->State.ResponseReady)
......@@ -184,50 +182,6 @@ void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo
RNDISInterfaceInfo->State.ResponseReady = false;
}
if ((RNDISInterfaceInfo->State.CurrRNDISState == RNDIS_Data_Initialized) && !(MessageHeader->MessageLength))
{
RNDIS_Packet_Message_t RNDISPacketHeader;
Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataOUTEndpointNumber);
if (Endpoint_IsOUTReceived() && !(RNDISInterfaceInfo->State.FrameIN.FrameInBuffer))
{
Endpoint_Read_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL);
if (RNDISPacketHeader.DataLength > ETHERNET_FRAME_SIZE_MAX)
{
Endpoint_StallTransaction();
return;
}
Endpoint_Read_Stream_LE(RNDISInterfaceInfo->State.FrameIN.FrameData, RNDISPacketHeader.DataLength, NULL);
Endpoint_ClearOUT();
RNDISInterfaceInfo->State.FrameIN.FrameLength = RNDISPacketHeader.DataLength;
RNDISInterfaceInfo->State.FrameIN.FrameInBuffer = true;
}
Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataINEndpointNumber);
if (Endpoint_IsINReady() && RNDISInterfaceInfo->State.FrameOUT.FrameInBuffer)
{
memset(&RNDISPacketHeader, 0, sizeof(RNDIS_Packet_Message_t));
RNDISPacketHeader.MessageType = REMOTE_NDIS_PACKET_MSG;
RNDISPacketHeader.MessageLength = (sizeof(RNDIS_Packet_Message_t) + RNDISInterfaceInfo->State.FrameOUT.FrameLength);
RNDISPacketHeader.DataOffset = (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t));
RNDISPacketHeader.DataLength = RNDISInterfaceInfo->State.FrameOUT.FrameLength;
Endpoint_Write_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL);
Endpoint_Write_Stream_LE(RNDISInterfaceInfo->State.FrameOUT.FrameData, RNDISPacketHeader.DataLength, NULL);
Endpoint_ClearIN();
RNDISInterfaceInfo->State.FrameOUT.FrameInBuffer = false;
}
}
}
void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo)
......@@ -493,5 +447,85 @@ static bool RNDIS_Device_ProcessNDISSet(USB_ClassInfo_RNDIS_Device_t* const RNDI
}
}
bool RNDIS_Device_IsPacketReceived(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) ||
(RNDISInterfaceInfo->State.CurrRNDISState != RNDIS_Data_Initialized))
{
return false;
}
Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataOUTEndpointNumber);
return Endpoint_IsOUTReceived();
}
uint8_t RNDIS_Device_ReadPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
void* Buffer,
uint16_t* const PacketLength)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) ||
(RNDISInterfaceInfo->State.CurrRNDISState != RNDIS_Data_Initialized))
{
return ENDPOINT_RWSTREAM_DeviceDisconnected;
}
Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataOUTEndpointNumber);
*PacketLength = 0;
if (!(Endpoint_IsOUTReceived()))
return ENDPOINT_RWSTREAM_NoError;
RNDIS_Packet_Message_t RNDISPacketHeader;
Endpoint_Read_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL);
if (RNDISPacketHeader.DataLength > ETHERNET_FRAME_SIZE_MAX)
{
Endpoint_StallTransaction();
return RNDIS_ERROR_LOGICAL_CMD_FAILED;
}
*PacketLength = (uint16_t)RNDISPacketHeader.DataLength;
Endpoint_Read_Stream_LE(Buffer, RNDISPacketHeader.DataLength, NULL);
Endpoint_ClearOUT();
return ENDPOINT_RWSTREAM_NoError;
}
uint8_t RNDIS_Device_SendPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
void* Buffer,
const uint16_t PacketLength)
{
uint8_t ErrorCode;
if ((USB_DeviceState != DEVICE_STATE_Configured) ||
(RNDISInterfaceInfo->State.CurrRNDISState != RNDIS_Data_Initialized))
{
return ENDPOINT_RWSTREAM_DeviceDisconnected;
}
Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataINEndpointNumber);
if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError)
return ErrorCode;
RNDIS_Packet_Message_t RNDISPacketHeader;
memset(&RNDISPacketHeader, 0, sizeof(RNDIS_Packet_Message_t));
RNDISPacketHeader.MessageType = REMOTE_NDIS_PACKET_MSG;
RNDISPacketHeader.MessageLength = (sizeof(RNDIS_Packet_Message_t) + PacketLength);
RNDISPacketHeader.DataOffset = (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t));
RNDISPacketHeader.DataLength = PacketLength;
Endpoint_Write_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL);
Endpoint_Write_Stream_LE(Buffer, PacketLength, NULL);
Endpoint_ClearIN();
return ENDPOINT_RWSTREAM_NoError;
}
#endif
......@@ -106,12 +106,6 @@
bool ResponseReady; /**< Internal flag indicating if a RNDIS message is waiting to be returned to the host. */
uint8_t CurrRNDISState; /**< Current RNDIS state of the adapter, a value from the \ref RNDIS_States_t enum. */
uint32_t CurrPacketFilter; /**< Current packet filter mode, used internally by the class driver. */
Ethernet_Frame_Info_t FrameIN; /**< Structure holding the last received Ethernet frame from the host, for user
* processing.
*/
Ethernet_Frame_Info_t FrameOUT; /**< Structure holding the next Ethernet frame to send to the host, populated by the
* user application.
*/
} State; /**< State data for the USB class interface within the device. All elements in this section
* are reset to their defaults when the interface is enumerated.
*/
......@@ -146,6 +140,48 @@
*/
void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
/** Determines if a packet is currently waiting for the device to read in and process.
*
* \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or the
* call will fail.
*
* \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class configuration and state.
*
* \return Boolean \c true if a packet is waiting to be read in by the host, \c false otherwise.
*/
bool RNDIS_Device_IsPacketReceived(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo);
/** Retrieves the next pending packet from the device, discarding the remainder of the RNDIS packet header to leave
* only the packet contents for processing by the device in the nominated buffer.
*
* \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or the
* call will fail.
*
* \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class configuration and state.
* \param[out] Buffer Pointer to a buffer where the packer data is to be written to.
* \param[out] PacketLength Pointer to where the length in bytes of the read packet is to be stored.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t RNDIS_Device_ReadPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
void* Buffer,
uint16_t* const PacketLength);
/** Sends the given packet to the attached RNDIS device, after adding a RNDIS packet message header.
*
* \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or the
* call will fail.
*
* \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class configuration and state.
* \param[in] Buffer Pointer to a buffer where the packer data is to be read from.
* \param[in] PacketLength Length in bytes of the packet to send.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t RNDIS_Device_SendPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
void* Buffer,
const uint16_t PacketLength);
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Function Prototypes: */
......
......@@ -315,7 +315,7 @@ uint8_t RNDIS_Host_InitializeDevice(USB_ClassInfo_RNDIS_Host_t* const RNDISInter
}
if (InitMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)
return RNDIS_COMMAND_FAILED;
return RNDIS_ERROR_LOGICAL_CMD_FAILED;
RNDISInterfaceInfo->State.DeviceMaxPacketSize = InitMessageResponse.MaxTransferSize;
......@@ -361,7 +361,7 @@ uint8_t RNDIS_Host_SetRNDISProperty(USB_ClassInfo_RNDIS_Host_t* const RNDISInter
}
if (SetMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)
return RNDIS_COMMAND_FAILED;
return RNDIS_ERROR_LOGICAL_CMD_FAILED;
return HOST_SENDCONTROL_Successful;
}
......@@ -403,7 +403,7 @@ uint8_t RNDIS_Host_QueryRNDISProperty(USB_ClassInfo_RNDIS_Host_t* const RNDISInt
}
if (QueryMessageResponseData.QueryMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS)
return RNDIS_COMMAND_FAILED;
return RNDIS_ERROR_LOGICAL_CMD_FAILED;
memcpy(Buffer, &QueryMessageResponseData.ContiguousBuffer, MaxLength);
......@@ -458,7 +458,8 @@ uint8_t RNDIS_Host_ReadPacket(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceIn
*PacketLength = (uint16_t)DeviceMessage.DataLength;
Pipe_Discard_Stream(DeviceMessage.DataOffset - (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)),
Pipe_Discard_Stream(DeviceMessage.DataOffset -
(sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)),
NULL);
Pipe_Read_Stream_LE(Buffer, *PacketLength, NULL);
...