forked from mfulz_github/qmk_firmware
Fixed Endpoint_Write_Control_* functions writing more data than expected by the host, causing it to panic (thanks to Johannes Raschke).
This commit is contained in:
parent
13935a31b9
commit
6a8e27f7ee
|
@ -350,7 +350,7 @@ static void WriteNextResponseByte(const uint8_t Response)
|
||||||
/* Select the IN endpoint so that the next data byte can be written */
|
/* Select the IN endpoint so that the next data byte can be written */
|
||||||
Endpoint_SelectEndpoint(CDC_TX_EPNUM);
|
Endpoint_SelectEndpoint(CDC_TX_EPNUM);
|
||||||
|
|
||||||
/* If OUT endpoint empty, clear it and wait for the next packet from the host */
|
/* If IN endpoint full, clear it and wait util ready for the next packet to the host */
|
||||||
if (!(Endpoint_IsReadWriteAllowed()))
|
if (!(Endpoint_IsReadWriteAllowed()))
|
||||||
{
|
{
|
||||||
Endpoint_ClearIN();
|
Endpoint_ClearIN();
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
#define BOOTLOADER_HWVERSION_MINOR 0x00
|
#define BOOTLOADER_HWVERSION_MINOR 0x00
|
||||||
|
|
||||||
/** Eight character bootloader firmware identifier reported to the host when requested */
|
/** Eight character bootloader firmware identifier reported to the host when requested */
|
||||||
#define SOFTWARE_IDENTIFIER "LUFA-CDC"
|
#define SOFTWARE_IDENTIFIER "LUFACDC"
|
||||||
|
|
||||||
/* Event Handlers: */
|
/* Event Handlers: */
|
||||||
/** Indicates that this module will catch the USB_Disconnect event when thrown by the library. */
|
/** Indicates that this module will catch the USB_Disconnect event when thrown by the library. */
|
||||||
|
|
|
@ -198,7 +198,7 @@ USB_Descriptor_String_t LanguageString =
|
||||||
*/
|
*/
|
||||||
USB_Descriptor_String_t ProductString =
|
USB_Descriptor_String_t ProductString =
|
||||||
{
|
{
|
||||||
.Header = {.Size = USB_STRING_LEN(15), .Type = DTYPE_String},
|
.Header = {.Size = USB_STRING_LEN(18), .Type = DTYPE_String},
|
||||||
|
|
||||||
.UnicodeString = L"AVR CDC Bootloader"
|
.UnicodeString = L"AVR CDC Bootloader"
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 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 LastPacketFull = false;
|
||||||
bool ShortTransfer = (Length < USB_ControlRequest.wLength);
|
|
||||||
|
if (Length > USB_ControlRequest.wLength)
|
||||||
|
Length = USB_ControlRequest.wLength;
|
||||||
|
|
||||||
while (Length && !(Endpoint_IsOUTReceived()))
|
while (Length && !(Endpoint_IsOUTReceived()))
|
||||||
{
|
{
|
||||||
|
@ -309,7 +311,7 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
|
||||||
if (Endpoint_IsOUTReceived())
|
if (Endpoint_IsOUTReceived())
|
||||||
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;
|
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;
|
||||||
|
|
||||||
if (LastPacketFull || ShortTransfer)
|
if (LastPacketFull)
|
||||||
{
|
{
|
||||||
while (!(Endpoint_IsINReady()));
|
while (!(Endpoint_IsINReady()));
|
||||||
Endpoint_ClearIN();
|
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);
|
uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);
|
||||||
bool LastPacketFull = false;
|
bool LastPacketFull = false;
|
||||||
bool ShortTransfer = (Length < USB_ControlRequest.wLength);
|
|
||||||
|
|
||||||
|
if (Length > USB_ControlRequest.wLength)
|
||||||
|
Length = USB_ControlRequest.wLength;
|
||||||
|
|
||||||
while (Length && !(Endpoint_IsOUTReceived()))
|
while (Length && !(Endpoint_IsOUTReceived()))
|
||||||
{
|
{
|
||||||
while (!(Endpoint_IsINReady()));
|
if (Endpoint_IsINReady())
|
||||||
|
|
||||||
while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
|
|
||||||
{
|
{
|
||||||
Endpoint_Write_Byte(*(DataStream--));
|
while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
|
||||||
Length--;
|
{
|
||||||
|
Endpoint_Write_Byte(*(DataStream--));
|
||||||
|
Length--;
|
||||||
|
}
|
||||||
|
|
||||||
|
LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
|
||||||
|
Endpoint_ClearIN();
|
||||||
}
|
}
|
||||||
|
|
||||||
LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
|
|
||||||
Endpoint_ClearIN();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Endpoint_IsOUTReceived())
|
if (Endpoint_IsOUTReceived())
|
||||||
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;
|
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;
|
||||||
|
|
||||||
if (LastPacketFull || ShortTransfer)
|
if (LastPacketFull)
|
||||||
{
|
{
|
||||||
while (!(Endpoint_IsINReady()));
|
while (!(Endpoint_IsINReady()));
|
||||||
Endpoint_ClearIN();
|
Endpoint_ClearIN();
|
||||||
|
@ -360,15 +365,16 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)
|
||||||
|
|
||||||
while (Length)
|
while (Length)
|
||||||
{
|
{
|
||||||
while (!(Endpoint_IsOUTReceived()));
|
if (Endpoint_IsOUTReceived())
|
||||||
|
|
||||||
while (Length && Endpoint_BytesInEndpoint())
|
|
||||||
{
|
{
|
||||||
*(DataStream++) = Endpoint_Read_Byte();
|
while (Length && Endpoint_BytesInEndpoint())
|
||||||
Length--;
|
{
|
||||||
|
*(DataStream++) = Endpoint_Read_Byte();
|
||||||
|
Length--;
|
||||||
|
}
|
||||||
|
|
||||||
|
Endpoint_ClearOUT();
|
||||||
}
|
}
|
||||||
|
|
||||||
Endpoint_ClearOUT();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!(Endpoint_IsINReady()));
|
while (!(Endpoint_IsINReady()));
|
||||||
|
@ -382,15 +388,16 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)
|
||||||
|
|
||||||
while (Length)
|
while (Length)
|
||||||
{
|
{
|
||||||
while (!(Endpoint_IsOUTReceived()));
|
if (Endpoint_IsOUTReceived())
|
||||||
|
|
||||||
while (Length && Endpoint_BytesInEndpoint())
|
|
||||||
{
|
{
|
||||||
*(DataStream--) = Endpoint_Read_Byte();
|
while (Length && Endpoint_BytesInEndpoint())
|
||||||
Length--;
|
{
|
||||||
|
*(DataStream--) = Endpoint_Read_Byte();
|
||||||
|
Length--;
|
||||||
|
}
|
||||||
|
|
||||||
|
Endpoint_ClearOUT();
|
||||||
}
|
}
|
||||||
|
|
||||||
Endpoint_ClearOUT();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!(Endpoint_IsINReady()));
|
while (!(Endpoint_IsINReady()));
|
||||||
|
|
Loading…
Reference in New Issue