Fixed Endpoint_Write_Control_* functions writing more data than expected by the host...
authorDean Camera <dean@fourwalledcubicle.com>
Sat, 2 May 2009 13:05:25 +0000 (13:05 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Sat, 2 May 2009 13:05:25 +0000 (13:05 +0000)
Bootloaders/CDC/BootloaderCDC.c
Bootloaders/CDC/BootloaderCDC.h
Bootloaders/CDC/Descriptors.c
LUFA/Drivers/USB/LowLevel/Endpoint.c

index ef8707d..f36c4fc 100644 (file)
@@ -350,7 +350,7 @@ static void WriteNextResponseByte(const uint8_t Response)
        /* Select the IN endpoint so that the next data byte can be written */\r
        Endpoint_SelectEndpoint(CDC_TX_EPNUM);\r
        \r
-       /* If OUT endpoint empty, clear it and wait for the next packet from the host */\r
+       /* If IN endpoint full, clear it and wait util ready for the next packet to the host */\r
        if (!(Endpoint_IsReadWriteAllowed()))\r
        {\r
                Endpoint_ClearIN();\r
index 7669b83..e302a39 100644 (file)
@@ -82,7 +82,7 @@
                #define BOOTLOADER_HWVERSION_MINOR   0x00\r
 \r
                /** Eight character bootloader firmware identifier reported to the host when requested */\r
-               #define SOFTWARE_IDENTIFIER          "LUFA-CDC"\r
+               #define SOFTWARE_IDENTIFIER          "LUFACDC"\r
 \r
        /* Event Handlers: */\r
                /** Indicates that this module will catch the USB_Disconnect event when thrown by the library. */\r
index e9787cf..06088d8 100644 (file)
@@ -198,7 +198,7 @@ USB_Descriptor_String_t LanguageString =
  */\r
 USB_Descriptor_String_t ProductString =\r
 {\r
-       .Header                 = {.Size = USB_STRING_LEN(15), .Type = DTYPE_String},\r
+       .Header                 = {.Size = USB_STRING_LEN(18), .Type = DTYPE_String},\r
                \r
        .UnicodeString          = L"AVR CDC Bootloader"\r
 };\r
index a872a00..f4f2bdc 100644 (file)
@@ -288,9 +288,11 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
 \r
 uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)\r
 {\r
-       uint8_t* DataStream    = (uint8_t*)Buffer;\r
+       uint8_t* DataStream     = (uint8_t*)Buffer;\r
        bool     LastPacketFull = false;\r
-       bool     ShortTransfer = (Length < USB_ControlRequest.wLength);\r
+       \r
+       if (Length > USB_ControlRequest.wLength)\r
+         Length = USB_ControlRequest.wLength;\r
        \r
        while (Length && !(Endpoint_IsOUTReceived()))\r
        {\r
@@ -309,7 +311,7 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
        if (Endpoint_IsOUTReceived())\r
          return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
        \r
-       if (LastPacketFull || ShortTransfer)\r
+       if (LastPacketFull)\r
        {\r
                while (!(Endpoint_IsINReady()));\r
                Endpoint_ClearIN();\r
@@ -324,26 +326,29 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
 {\r
        uint8_t* DataStream     = (uint8_t*)(Buffer + Length - 1);\r
        bool     LastPacketFull = false;\r
-       bool     ShortTransfer  = (Length < USB_ControlRequest.wLength);\r
        \r
+       if (Length > USB_ControlRequest.wLength)\r
+         Length = USB_ControlRequest.wLength;\r
+\r
        while (Length && !(Endpoint_IsOUTReceived()))\r
        {\r
-               while (!(Endpoint_IsINReady()));\r
-               \r
-               while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
+               if (Endpoint_IsINReady())\r
                {\r
-                       Endpoint_Write_Byte(*(DataStream--));\r
-                       Length--;\r
+                       while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
+                       {\r
+                               Endpoint_Write_Byte(*(DataStream--));\r
+                               Length--;\r
+                       }\r
+                       \r
+                       LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
+                       Endpoint_ClearIN();\r
                }\r
-               \r
-               LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
-               Endpoint_ClearIN();\r
        }\r
        \r
        if (Endpoint_IsOUTReceived())\r
          return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
        \r
-       if (LastPacketFull || ShortTransfer)\r
+       if (LastPacketFull)\r
        {\r
                while (!(Endpoint_IsINReady()));\r
                Endpoint_ClearIN();\r
@@ -360,15 +365,16 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)
        \r
        while (Length)\r
        {\r
-               while (!(Endpoint_IsOUTReceived()));\r
-               \r
-               while (Length && Endpoint_BytesInEndpoint())\r
+               if (Endpoint_IsOUTReceived())\r
                {\r
-                       *(DataStream++) = Endpoint_Read_Byte();\r
-                       Length--;\r
+                       while (Length && Endpoint_BytesInEndpoint())\r
+                       {\r
+                               *(DataStream++) = Endpoint_Read_Byte();\r
+                               Length--;\r
+                       }\r
+                       \r
+                       Endpoint_ClearOUT();\r
                }\r
-               \r
-               Endpoint_ClearOUT();\r
        }\r
        \r
        while (!(Endpoint_IsINReady()));\r
@@ -382,15 +388,16 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)
        \r
        while (Length)\r
        {\r
-               while (!(Endpoint_IsOUTReceived()));\r
-               \r
-               while (Length && Endpoint_BytesInEndpoint())\r
+               if (Endpoint_IsOUTReceived())\r
                {\r
-                       *(DataStream--) = Endpoint_Read_Byte();\r
-                       Length--;\r
+                       while (Length && Endpoint_BytesInEndpoint())\r
+                       {\r
+                               *(DataStream--) = Endpoint_Read_Byte();\r
+                               Length--;\r
+                       }\r
+                       \r
+                       Endpoint_ClearOUT();\r
                }\r
-               \r
-               Endpoint_ClearOUT();\r
        }\r
        \r
        while (!(Endpoint_IsINReady()));\r