Skip to content

Commit

Permalink
scsi: correctly send back sense data for non-0 LUN scenarios
Browse files Browse the repository at this point in the history
Fixes #112
  • Loading branch information
erichelgeson committed Feb 8, 2024
1 parent aa77d67 commit 39efa85
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/SCSI2SD/src/firmware/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#include "scsi2sd_time.h"
#include "bsp.h"
#include "cdrom.h"
//#include "debug.h"
// #include "debug.h"
// #include "log.h"
#include "network.h"
#include "tape.h"
#include "mo.h"
Expand Down Expand Up @@ -412,7 +413,14 @@ static void process_Command()
}
else if (command == 0x12)
{
s2s_scsiInquiry();
if(scsiDev.lun)
{
scsiDev.target->sense.code = ILLEGAL_REQUEST;
scsiDev.target->sense.asc = LOGICAL_UNIT_NOT_SUPPORTED;
enter_Status(CHECK_CONDITION);
} else {
s2s_scsiInquiry();
}
}
else if (command == 0x03)
{
Expand Down Expand Up @@ -545,6 +553,13 @@ static void process_Command()
// Newer initiators won't be specifying 0 anyway.
if (allocLength == 0) allocLength = 4;

// If we receve a stand alone REQUEST SENSE to a bad LUN we still need to respond
// with LUN not supported. SCSI-2 Spec 7.5.3.
if (scsiDev.lun && scsiDev.lastStatus != CHECK_CONDITION)
{
scsiDev.target->sense.code = ILLEGAL_REQUEST;
scsiDev.target->sense.asc = LOGICAL_UNIT_NOT_SUPPORTED;
}
memset(scsiDev.data, 0, 256); // Max possible alloc length
scsiDev.data[0] = 0xF0;
scsiDev.data[2] = scsiDev.target->sense.code & 0x0F;
Expand Down

0 comments on commit 39efa85

Please sign in to comment.