scsidevice: Add check_lun.

This will create a CHECK_CONDITON if the LUN doesn't match.
This commit is contained in:
joevt 2023-10-31 00:42:17 -07:00 committed by dingusdev
parent bcd057d45b
commit 1fb9e37ec5
2 changed files with 22 additions and 0 deletions

View File

@ -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;

View File

@ -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;
}