aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers/USB/LowLevel/Endpoint.c
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-05-02 13:05:25 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-05-02 13:05:25 +0000
commit6a8e27f7ee43169b9f6eb928b12e00d6306618ff (patch)
treee918ffd16c91005992cf83583812bef4571dd338 /LUFA/Drivers/USB/LowLevel/Endpoint.c
parent13935a31b9bb1360c9e46c0893e77e0c47761cb9 (diff)
downloadlufa-6a8e27f7ee43169b9f6eb928b12e00d6306618ff.tar.gz
lufa-6a8e27f7ee43169b9f6eb928b12e00d6306618ff.tar.bz2
lufa-6a8e27f7ee43169b9f6eb928b12e00d6306618ff.zip
Fixed Endpoint_Write_Control_* functions writing more data than expected by the host, causing it to panic (thanks to Johannes Raschke).
Diffstat (limited to 'LUFA/Drivers/USB/LowLevel/Endpoint.c')
-rw-r--r--LUFA/Drivers/USB/LowLevel/Endpoint.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.c b/LUFA/Drivers/USB/LowLevel/Endpoint.c
index a872a00ff..f4f2bdc0b 100644
--- a/LUFA/Drivers/USB/LowLevel/Endpoint.c
+++ b/LUFA/Drivers/USB/LowLevel/Endpoint.c
@@ -288,9 +288,11 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
{
- uint8_t* DataStream = (uint8_t*)Buffer;
+ uint8_t* DataStream = (uint8_t*)Buffer;
bool LastPacketFull = false;
- bool ShortTransfer = (Length < USB_ControlRequest.wLength);
+
+ if (Length > USB_ControlRequest.wLength)
+ Length = USB_ControlRequest.wLength;
while (Length && !(Endpoint_IsOUTReceived()))
{
@@ -309,7 +311,7 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
if (Endpoint_IsOUTReceived())
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;
- if (LastPacketFull || ShortTransfer)
+ if (LastPacketFull)
{
while (!(Endpoint_IsINReady()));
Endpoint_ClearIN();
@@ -324,26 +326,29 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
{
uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);
bool LastPacketFull = false;
- bool ShortTransfer = (Length < USB_ControlRequest.wLength);
+ if (Length > USB_ControlRequest.wLength)
+ Length = USB_ControlRequest.wLength;
+
while (Length && !(Endpoint_IsOUTReceived()))
{
- while (!(Endpoint_IsINReady()));
-
- while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
+ if (Endpoint_IsINReady())
{
- Endpoint_Write_Byte(*(DataStream--));
- Length--;
+ while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
+ {
+ Endpoint_Write_Byte(*(DataStream--));
+ Length--;
+ }
+
+ LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
+ Endpoint_ClearIN();
}
-
- LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
- Endpoint_ClearIN();
}
if (Endpoint_IsOUTReceived())
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;
- if (LastPacketFull || ShortTransfer)
+ if (LastPacketFull)
{
while (!(Endpoint_IsINReady()));
Endpoint_ClearIN();
@@ -360,15 +365,16 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)
while (Length)
{
- while (!(Endpoint_IsOUTReceived()));
-
- while (Length && Endpoint_BytesInEndpoint())
+ if (Endpoint_IsOUTReceived())
{
- *(DataStream++) = Endpoint_Read_Byte();
- Length--;
+ while (Length && Endpoint_BytesInEndpoint())
+ {
+ *(DataStream++) = Endpoint_Read_Byte();
+ Length--;
+ }
+
+ Endpoint_ClearOUT();
}
-
- Endpoint_ClearOUT();
}
while (!(Endpoint_IsINReady()));
@@ -382,15 +388,16 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)
while (Length)
{
- while (!(Endpoint_IsOUTReceived()));
-
- while (Length && Endpoint_BytesInEndpoint())
+ if (Endpoint_IsOUTReceived())
{
- *(DataStream--) = Endpoint_Read_Byte();
- Length--;
+ while (Length && Endpoint_BytesInEndpoint())
+ {
+ *(DataStream--) = Endpoint_Read_Byte();
+ Length--;
+ }
+
+ Endpoint_ClearOUT();
}
-
- Endpoint_ClearOUT();
}
while (!(Endpoint_IsINReady()));