Split command

This commit is contained in:
Uwe Seimet 2023-11-16 09:22:55 +01:00
parent f217aa156c
commit 760ee7bf43
4 changed files with 33 additions and 25 deletions

View File

@ -26,7 +26,7 @@ void PhaseExecutor::Reset() const
bus.SetATN(false);
}
bool PhaseExecutor::Execute(scsi_command cmd, span<uint8_t> cdb, span<uint8_t> buffer, int length_out, int length_in)
bool PhaseExecutor::Execute(scsi_command cmd, span<uint8_t> cdb, span<uint8_t> buffer, int length)
{
status = 0;
byte_count = 0;
@ -52,7 +52,7 @@ bool PhaseExecutor::Execute(scsi_command cmd, span<uint8_t> cdb, span<uint8_t> b
if (bus.GetREQ()) {
try {
if (Dispatch(cmd, cdb, buffer, length_out, length_in)) {
if (Dispatch(cmd, cdb, buffer, length)) {
now = chrono::steady_clock::now();
}
else {
@ -71,7 +71,7 @@ bool PhaseExecutor::Execute(scsi_command cmd, span<uint8_t> cdb, span<uint8_t> b
return false;
}
bool PhaseExecutor::Dispatch(scsi_command cmd, span<uint8_t> cdb, span<uint8_t> buffer, int length_out, int length_in)
bool PhaseExecutor::Dispatch(scsi_command cmd, span<uint8_t> cdb, span<uint8_t> buffer, int length)
{
const phase_t phase = bus.GetPhase();
@ -87,11 +87,11 @@ bool PhaseExecutor::Dispatch(scsi_command cmd, span<uint8_t> cdb, span<uint8_t>
break;
case phase_t::datain:
DataIn(buffer, length_in);
DataIn(buffer, length);
break;
case phase_t::dataout:
DataOut(buffer, length_out);
DataOut(buffer, length);
break;
case phase_t::msgin:

View File

@ -33,7 +33,7 @@ public:
~PhaseExecutor() = default;
void SetTarget(int, int);
bool Execute(scsi_command, span<uint8_t>, span<uint8_t>, int, int);
bool Execute(scsi_command, span<uint8_t>, span<uint8_t>, int);
int GetByteCount() const
{
@ -42,7 +42,7 @@ public:
private:
bool Dispatch(scsi_command, span<uint8_t>, span<uint8_t>, int, int);
bool Dispatch(scsi_command, span<uint8_t>, span<uint8_t>, int);
void Reset() const;

View File

@ -24,7 +24,7 @@ using namespace piscsi_interface;
bool ScsiExecutor::Execute(const string& filename, bool binary, PbResult& result, string& error)
{
int input_length = 0;
int length = 0;
if (binary) {
ifstream in(filename, ios::binary);
@ -33,10 +33,10 @@ bool ScsiExecutor::Execute(const string& filename, bool binary, PbResult& result
return false;
}
input_length = file_size(filename);
vector<char> b(input_length);
in.read(b.data(), input_length);
memcpy(buffer.data(), b.data(), input_length);
length = file_size(filename);
vector<char> b(length);
in.read(b.data(), length);
memcpy(buffer.data(), b.data(), length);
}
else {
ifstream in(filename);
@ -48,20 +48,26 @@ bool ScsiExecutor::Execute(const string& filename, bool binary, PbResult& result
stringstream buf;
buf << in.rdbuf();
const string json = buf.str();
input_length = json.size();
memcpy(buffer.data(), json.data(), input_length);
length = json.size();
memcpy(buffer.data(), json.data(), length);
}
array<uint8_t, 10> cdb = { };
cdb[1] = binary ? 0x0a : 0x05;
cdb[5] = static_cast<uint8_t>(input_length >> 8);
cdb[6] = static_cast<uint8_t>(input_length);
cdb[7] = static_cast<uint8_t>(buffer.size() >> 8);
cdb[8] = static_cast<uint8_t>(buffer.size());
cdb[1] = binary ? 0x00 : 0x01;
cdb[7] = static_cast<uint8_t>(length >> 8);
cdb[8] = static_cast<uint8_t>(length);
phase_executor->Execute(scsi_command::eCmdExecute, cdb, buffer, input_length, buffer.size());
if (!phase_executor->Execute(scsi_command::eCmdExecuteOperation, cdb, buffer, length)) {
error = "Can't execute operation";
return false;
}
const int length = phase_executor->GetByteCount();
if (!phase_executor->Execute(scsi_command::eCmdReadOperationResult, cdb, buffer, buffer.size())) {
error = "Can't read operation result";
return false;
}
length = phase_executor->GetByteCount();
if (binary) {
if (!result.ParseFromArray(buffer.data(), length)) {
@ -84,7 +90,7 @@ bool ScsiExecutor::ShutDown()
{
array<uint8_t, 6> cdb = { };
phase_executor->Execute(scsi_command::eCmdStartStop, cdb, buffer, 0, 0);
phase_executor->Execute(scsi_command::eCmdStartStop, cdb, buffer, 0);
return true;
}

View File

@ -108,8 +108,9 @@ enum class scsi_command {
eCmdReadCapacity16_ReadLong16 = 0x9E,
eCmdWriteLong16 = 0x9F,
eCmdReportLuns = 0xA0,
// Host services specific command
eCmdExecute = 0xC0
// Host services specific commands
eCmdExecuteOperation = 0xC0,
eCmdReadOperationResult = 0xC1
};
enum class status {
@ -187,5 +188,6 @@ static const unordered_map<scsi_command, pair<int, string>> command_mapping = {
{scsi_command::eCmdReadCapacity16_ReadLong16, make_pair(16, "ReadCapacity16/ReadLong16")},
{scsi_command::eCmdWriteLong16, make_pair(16, "WriteLong16")},
{scsi_command::eCmdReportLuns, make_pair(12, "ReportLuns")},
{ scsi_command::eCmdExecute, make_pair(10, "Execute") }};
{ scsi_command::eCmdExecuteOperation, make_pair(10, "ExecuteOperation")},
{ scsi_command::eCmdReadOperationResult, make_pair(10, "ReadOperationResult") }};
};