From 1fb9e37ec53b51c73b35849e366a603fc2ae8573 Mon Sep 17 00:00:00 2001 From: joevt Date: Tue, 31 Oct 2023 00:42:17 -0700 Subject: [PATCH] scsidevice: Add check_lun. This will create a CHECK_CONDITON if the LUN doesn't match. --- devices/common/scsi/scsi.h | 6 ++++++ devices/common/scsi/scsidevice.cpp | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/devices/common/scsi/scsi.h b/devices/common/scsi/scsi.h index fe4b2f8..78292f4 100644 --- a/devices/common/scsi/scsi.h +++ b/devices/common/scsi/scsi.h @@ -182,6 +182,7 @@ public: virtual int xfer_data(); virtual int send_data(uint8_t* dst_ptr, int count); virtual int rcv_data(const uint8_t* src_ptr, const int count); + virtual bool check_lun(); virtual bool prepare_data() = 0; virtual bool get_more_data() = 0; @@ -202,7 +203,12 @@ protected: int data_size; int incoming_size; uint8_t status; + int sense; + int asc; + int ascq; + int sksv; + int field; ScsiBus* bus_obj; diff --git a/devices/common/scsi/scsidevice.cpp b/devices/common/scsi/scsidevice.cpp index b02d373..b41c5d5 100644 --- a/devices/common/scsi/scsidevice.cpp +++ b/devices/common/scsi/scsidevice.cpp @@ -216,3 +216,19 @@ int ScsiDevice::rcv_data(const uint8_t* src_ptr, const int count) return count; } + +bool ScsiDevice::check_lun() +{ + if (this->cmd_buf[1] >> 5 != this->lun) { + LOG_F(ERROR, "%s: non-matching LUN", this->name.c_str()); + this->status = ScsiStatus::CHECK_CONDITION; + this->sense = ScsiSense::ILLEGAL_REQ; + this->asc = 0x25; // Logical Unit Not Supported + this->ascq = 0; + this->sksv = 0; + this->field = 0; + this->switch_phase(ScsiPhase::STATUS); + return false; + } + return true; +}