aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-08-06 14:22:04 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-08-06 14:22:04 +0000
commitc830fcb0e1d42c1300ebe78a8b33924054b63a87 (patch)
tree04a8b7a112fce02523c3ba78b11e8b9db3eb3164 /LUFA/Drivers
parent384848253274a7afa74e463a56e1257cf3b8924e (diff)
downloadlufa-c830fcb0e1d42c1300ebe78a8b33924054b63a87.tar.gz
lufa-c830fcb0e1d42c1300ebe78a8b33924054b63a87.tar.bz2
lufa-c830fcb0e1d42c1300ebe78a8b33924054b63a87.zip
Make Endpoint control transfers more reliable; early-abort when an incomplete packet is sent from the host (indicating end of transfer), add check for control reads to ensure that no more than wLength bytes are read from the interface.
Condense sequential printf_P/puts_P calls to single printf_P calls for size and clarity.
Diffstat (limited to 'LUFA/Drivers')
-rw-r--r--LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c
index a2a0c3bd5..f6afb6901 100644
--- a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c
+++ b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c
@@ -1,8 +1,12 @@
uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length)
{
- uint8_t* DataStream = (uint8_t*)(Buffer + TEMPLATE_BUFFER_OFFSET(Length));
+ uint8_t* DataStream = (uint8_t*)(Buffer + TEMPLATE_BUFFER_OFFSET(Length));
+ bool LastPacketFull = false;
- while (Length)
+ if (Length > USB_ControlRequest.wLength)
+ Length = USB_ControlRequest.wLength;
+
+ while (Length || LastPacketFull)
{
if (Endpoint_IsSETUPReceived())
return ENDPOINT_RWCSTREAM_HostAborted;
@@ -12,6 +16,8 @@ uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length)
if (Endpoint_IsOUTReceived())
{
+ LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
+
while (Length && Endpoint_BytesInEndpoint())
{
TEMPLATE_TRANSFER_BYTE(DataStream);
@@ -19,6 +25,9 @@ uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length)
}
Endpoint_ClearOUT();
+
+ if (!(LastPacketFull))
+ Length = 0;
}
}