Device mode class driver callbacks are now fired before the control request status...
[pub/USBasp.git] / Demos / Host / LowLevel / MassStorageHost / Lib / MassStoreCommands.c
index 1deefbc..be92d69 100644 (file)
@@ -1,21 +1,21 @@
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting\r
-  documentation, and that the name of the author not be used in\r
-  advertising or publicity pertaining to distribution of the\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, distribute, and sell this \r
+  software and its documentation for any purpose is hereby granted\r
+  without fee, provided that the above copyright notice appear in \r
+  all copies and that both that the copyright notice and this\r
+  permission notice and warranty disclaimer appear in supporting \r
+  documentation, and that the name of the author not be used in \r
+  advertising or publicity pertaining to distribution of the \r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
@@ -50,7 +50,6 @@
 #define  INCLUDE_FROM_MASSSTORE_COMMANDS_C\r
 #include "MassStoreCommands.h"\r
 \r
-/* Globals: */\r
 /** Current Tag value used in issued CBWs to the device. This is automatically incremented\r
  *  each time a command is sent, and is not externally accessible.\r
  */\r
@@ -238,7 +237,7 @@ static uint8_t MassStore_GetReturnedStatus(CommandStatusWrapper_t* SCSICommandSt
 {\r
        uint8_t ErrorCode = PIPE_RWSTREAM_NoError;\r
 \r
-       /* If an error in the command ocurred, abort */\r
+       /* If an error in the command occurred, abort */\r
        if ((ErrorCode = MassStore_WaitForDataReceived()) != PIPE_RWSTREAM_NoError)\r
          return ErrorCode;\r
 \r
@@ -288,13 +287,17 @@ uint8_t MassStore_MassStorageReset(void)
 /** Issues a Mass Storage class specific request to determine the index of the highest numbered Logical\r
  *  Unit in the attached device.\r
  *\r
+ *  \note Some devices do not support this request, and will STALL it when issued. To get around this,\r
+ *        on unsupported devices the max LUN index will be reported as zero and no error will be returned\r
+ *        if the device STALLs the request.\r
+ *\r
  *  \param[out] MaxLUNIndex  Pointer to the location that the maximum LUN index value should be stored\r
  *\r
  *  \return A value from the USB_Host_SendControlErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails\r
  */\r
 uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex)\r
 {\r
-       uint8_t ErrorCode;\r
+       uint8_t ErrorCode = HOST_SENDCONTROL_Successful;\r
 \r
        USB_ControlRequest = (USB_Request_Header_t)\r
                {\r
@@ -314,7 +317,10 @@ uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex)
                Pipe_ClearStall();\r
        \r
                /* Some faulty Mass Storage devices don't implement the GET_MAX_LUN request, so assume a single LUN */\r
-               *MaxLUNIndex = 0;       \r
+               *MaxLUNIndex = 0;\r
+               \r
+               /* Clear the error, and pretend the request executed correctly if the device STALLed it */\r
+               ErrorCode = HOST_SENDCONTROL_Successful;\r
        }\r
        \r
        return ErrorCode;\r