Merge branch 'master' of ssh://webhost.codesrc.com/home/michael/projects/SCSI2SD
[SCSI2SD.git] / software / SCSI2SD / src / scsi.c
index e8aa0aa..48b4c6d 100755 (executable)
@@ -264,6 +264,7 @@ static void process_Command()
        control = scsiDev.cdb[scsiDev.cdbLen - 1];\r
 \r
        scsiDev.cmdCount++;\r
+       TargetConfig* cfg = scsiDev.target->cfg;\r
 \r
        if (unlikely(scsiDev.resetFlag))\r
        {\r
@@ -273,7 +274,7 @@ static void process_Command()
                return;\r
        }\r
        else if (scsiDev.parityError &&\r
-               (scsiDev.target->cfg->flags & CONFIG_ENABLE_PARITY) &&\r
+               (cfg->flags & CONFIG_ENABLE_PARITY) &&\r
                (scsiDev.compatMode >= COMPAT_SCSI2))\r
        {\r
                scsiDev.target->sense.code = ABORTED_COMMAND;\r
@@ -326,7 +327,7 @@ static void process_Command()
        // on receiving the unit attention response on boot, thus\r
        // triggering another unit attention condition.\r
        else if (scsiDev.target->unitAttention &&\r
-               (scsiDev.target->cfg->flags & CONFIG_ENABLE_UNIT_ATTENTION))\r
+               (cfg->flags & CONFIG_ENABLE_UNIT_ATTENTION))\r
        {\r
                scsiDev.target->sense.code = UNIT_ATTENTION;\r
                scsiDev.target->sense.asc = scsiDev.target->unitAttention;\r
@@ -352,6 +353,14 @@ static void process_Command()
        {\r
                enter_Status(CONFLICT);\r
        }\r
+       // Handle odd device types first that may override basic read and\r
+       // write commands. Will fall-through to generic disk handling.\r
+       else if (((cfg->deviceType == CONFIG_OPTICAL) && scsiCDRomCommand()) ||\r
+               ((cfg->deviceType == CONFIG_SEQUENTIAL) && scsiTapeCommand()) ||\r
+               ((cfg->deviceType == CONFIG_MO) && scsiMOCommand()))\r
+       {\r
+               // Already handled.\r
+       }\r
        else if (scsiDiskCommand())\r
        {\r
                // Already handled.\r
@@ -374,9 +383,7 @@ static void process_Command()
        {\r
                scsiReadBuffer();\r
        }\r
-       else if (\r
-               !scsiCDRomCommand() &&\r
-               !scsiModeCommand())\r
+       else if (!scsiModeCommand())\r
        {\r
                scsiDev.target->sense.code = ILLEGAL_REQUEST;\r
                scsiDev.target->sense.asc = INVALID_COMMAND_OPERATION_CODE;\r
@@ -560,6 +567,10 @@ static void process_SelectionPhase()
                        target->unitAttention = 0;\r
                        scsiDev.compatMode = COMPAT_SCSI1;\r
                }\r
+               else if (!(target->cfg->flags & CONFIG_ENABLE_SCSI2))\r
+               {\r
+                       scsiDev.compatMode = COMPAT_SCSI1;\r
+               }\r
                else if (scsiDev.compatMode == COMPAT_UNKNOWN)\r
                {\r
                        scsiDev.compatMode = COMPAT_SCSI2;\r
@@ -723,7 +734,7 @@ static void process_MessageOut()
                        // Discard bytes.\r
                        extmsg[i] = scsiReadByte();\r
                }\r
-               \r
+\r
                if (extmsg[0] == 3 && msgLen == 2) // Wide Data Request\r
                {\r
                        // Negotiate down to 8bit\r
@@ -731,7 +742,7 @@ static void process_MessageOut()
                        static const uint8_t WDTR[] = {0x01, 0x02, 0x03, 0x00};\r
                        scsiWrite(WDTR, sizeof(WDTR));\r
                }\r
-               else if (extmsg[0] == 1 && msgLen == 5) // Synchronous data request\r
+               else if (extmsg[0] == 1 && msgLen == 3) // Synchronous data request\r
                {\r
                        // Negotiate back to async\r
                        scsiEnterPhase(MESSAGE_IN);\r