2022-02-10 18:54:48 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SCSI Target Emulator RaSCSI (*^..^*)
|
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
// A basic device with mode page support, to be used for subclassing
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "controllers/scsidev_ctrl.h"
|
|
|
|
#include "mode_page_device.h"
|
|
|
|
|
|
|
|
using namespace std;
|
2022-02-13 19:30:02 +00:00
|
|
|
using namespace scsi_defs;
|
2022-02-10 18:54:48 +00:00
|
|
|
|
2022-02-13 19:30:02 +00:00
|
|
|
ModePageDevice::ModePageDevice(const string& id) : PrimaryDevice(id)
|
2022-02-10 18:54:48 +00:00
|
|
|
{
|
2022-02-13 19:30:02 +00:00
|
|
|
dispatcher.AddCommand(eCmdModeSense6, "ModeSense6", &ModePageDevice::ModeSense6);
|
|
|
|
dispatcher.AddCommand(eCmdModeSense10, "ModeSense10", &ModePageDevice::ModeSense10);
|
|
|
|
dispatcher.AddCommand(eCmdModeSelect6, "ModeSelect6", &ModePageDevice::ModeSelect6);
|
|
|
|
dispatcher.AddCommand(eCmdModeSelect10, "ModeSelect10", &ModePageDevice::ModeSelect10);
|
2022-02-10 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ModePageDevice::Dispatch(SCSIDEV *controller)
|
|
|
|
{
|
2022-02-13 19:30:02 +00:00
|
|
|
// The superclass class handles the less specific commands
|
|
|
|
return dispatcher.Dispatch(this, controller) ? true : super::Dispatch(controller);
|
2022-02-10 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModePageDevice::ModeSense6(SASIDEV *controller)
|
|
|
|
{
|
|
|
|
ctrl->length = ModeSense6(ctrl->cmd, ctrl->buffer);
|
|
|
|
if (ctrl->length <= 0) {
|
|
|
|
controller->Error();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
controller->DataIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModePageDevice::ModeSense10(SASIDEV *controller)
|
|
|
|
{
|
|
|
|
ctrl->length = ModeSense10(ctrl->cmd, ctrl->buffer);
|
|
|
|
if (ctrl->length <= 0) {
|
|
|
|
controller->Error();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
controller->DataIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModePageDevice::ModeSelect(const DWORD* /*cdb*/, const BYTE *buf, int length)
|
|
|
|
{
|
|
|
|
ASSERT(buf);
|
|
|
|
ASSERT(length >= 0);
|
|
|
|
|
|
|
|
// cannot be set
|
|
|
|
SetStatusCode(STATUS_INVALIDPRM);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModePageDevice::ModeSelect6(SASIDEV *controller)
|
|
|
|
{
|
|
|
|
LOGTRACE("%s Unsupported mode page $%02X", __PRETTY_FUNCTION__, ctrl->buffer[0]);
|
|
|
|
|
|
|
|
ctrl->length = ModeSelectCheck6(ctrl->cmd);
|
|
|
|
if (ctrl->length <= 0) {
|
|
|
|
controller->Error();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
controller->DataOut();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModePageDevice::ModeSelect10(SASIDEV *controller)
|
|
|
|
{
|
|
|
|
LOGTRACE("%s Unsupported mode page $%02X", __PRETTY_FUNCTION__, ctrl->buffer[0]);
|
|
|
|
|
|
|
|
ctrl->length = ModeSelectCheck10(ctrl->cmd);
|
|
|
|
if (ctrl->length <= 0) {
|
|
|
|
controller->Error();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
controller->DataOut();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModePageDevice::ModeSelectCheck(const DWORD *cdb, int length)
|
|
|
|
{
|
|
|
|
// Error if save parameters are set for other types than of SCHD or SCRM
|
2022-02-21 20:01:17 +00:00
|
|
|
// TODO This assumption is not correct, and this code should be located elsewhere
|
2022-02-10 18:54:48 +00:00
|
|
|
if (!IsSCSIHD() && (cdb[1] & 0x01)) {
|
|
|
|
SetStatusCode(STATUS_INVALIDCDB);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModePageDevice::ModeSelectCheck6(const DWORD *cdb)
|
|
|
|
{
|
|
|
|
// Receive the data specified by the parameter length
|
|
|
|
return ModeSelectCheck(cdb, cdb[4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModePageDevice::ModeSelectCheck10(const DWORD *cdb)
|
|
|
|
{
|
|
|
|
// Receive the data specified by the parameter length
|
|
|
|
int length = cdb[7];
|
|
|
|
length <<= 8;
|
|
|
|
length |= cdb[8];
|
|
|
|
if (length > 0x800) {
|
|
|
|
length = 0x800;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ModeSelectCheck(cdb, length);
|
|
|
|
}
|