From badbca579115d3305e1c95141e65689f90798019 Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Sun, 22 Jul 2012 13:32:39 +0000
Subject: [PATCH] Fixed endianess issues in the RNDIS host class driver for UC3
 devices (thanks to Andrew Chu). Fix broken build for UC3 devices when
 ORDERED_EP_CONFIG compile time option is set.

---
 LUFA/DoxygenPages/ChangeLog.txt              | 1 +
 LUFA/Drivers/USB/Class/Host/RNDISClassHost.c | 4 ++--
 LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c         | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/LUFA/DoxygenPages/ChangeLog.txt b/LUFA/DoxygenPages/ChangeLog.txt
index 999af82e1..91005999f 100644
--- a/LUFA/DoxygenPages/ChangeLog.txt
+++ b/LUFA/DoxygenPages/ChangeLog.txt
@@ -69,6 +69,7 @@
   *   - Fixed swapped Little Endian/Big Endian endpoint and pipe write code for the UC3 devices (thanks to Andrew Chu)
   *   - Fixed the JTAG_DISABLE() macro clearing all other bits in MCUSR when called
   *   - Fixed incorrect Micropendous board LED driver LEDs_SetAllLEDs() and LEDs_ChangeLEDs() function implementations (thanks to MitchJS)
+  *   - Fixed endianess issues in the RNDIS host class driver for UC3 devices (thanks to Andrew Chu)  
   *  - Library Applications:
   *   - Fixed error in the AVRISP-MKII programmer when ISP mode is used at 64KHz (thanks to Ben R. Porter)
   *   - Fixed AVRISP-MKII programmer project failing to compile for the U4 chips when VTARGET_ADC_CHANNEL is defined to an invalid channel and NO_VTARGET_DETECT is
diff --git a/LUFA/Drivers/USB/Class/Host/RNDISClassHost.c b/LUFA/Drivers/USB/Class/Host/RNDISClassHost.c
index e457b5dff..c5687511d 100644
--- a/LUFA/Drivers/USB/Class/Host/RNDISClassHost.c
+++ b/LUFA/Drivers/USB/Class/Host/RNDISClassHost.c
@@ -315,7 +315,7 @@ uint8_t RNDIS_Host_SetRNDISProperty(USB_ClassInfo_RNDIS_Host_t* const RNDISInter
 	memcpy(&SetMessageData.ContiguousBuffer, Buffer, Length);
 
 	if ((ErrorCode = RNDIS_SendEncapsulatedCommand(RNDISInterfaceInfo, &SetMessageData,
-	                                               SetMessageData.SetMessage.MessageLength)) != HOST_SENDCONTROL_Successful)
+	                                               (sizeof(RNDIS_Set_Message_t) + Length))) != HOST_SENDCONTROL_Successful)
 	{
 		return ErrorCode;
 	}
@@ -424,7 +424,7 @@ uint8_t RNDIS_Host_ReadPacket(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceIn
 
 	*PacketLength = (uint16_t)le32_to_cpu(DeviceMessage.DataLength);
 
-	Pipe_Discard_Stream(DeviceMessage.DataOffset -
+	Pipe_Discard_Stream(le32_to_cpu(DeviceMessage.DataOffset) -
 	                    (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)),
 	                    NULL);
 
diff --git a/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c
index 23c004db3..5b17455ab 100644
--- a/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c
+++ b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c
@@ -87,7 +87,7 @@ bool Pipe_ConfigurePipe(const uint8_t Address,
 	                                ((uint32_t)Token << AVR32_USBB_PTOKEN_OFFSET) |
 	                                ((Banks > 1) ? AVR32_USBB_PBK_MASK : 0)       |
 	                                Pipe_BytesToEPSizeMask(Size) |
-	                                ((EndpointNumber & PIPE_EPNUM_MASK) << AVR32_USBB_PEPNUM_OFFSET));
+	                                ((uint32_t)Number << AVR32_USBB_PEPNUM_OFFSET));
 
 	Pipe_SetInfiniteINRequests();
 
-- 
GitLab