Skip to content

Commit

Permalink
Pull Xbox SS dump loop out of cmd.ixx
Browse files Browse the repository at this point in the history
This pulls the loop out of cmd.ixx when dumping the security sector from
an XGD
  • Loading branch information
tbejos committed Aug 23, 2024
1 parent 11971f9 commit dd81526
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
11 changes: 6 additions & 5 deletions dvd/dvd_dump.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ export bool redumper_dump_dvd(Context &ctx, const Options &options, DumpMode dum
{
std::vector<uint8_t> security_sector(0x800);

status = cmd_kreon_get_security_sector(*ctx.sptd, security_sector);
if(status.status_code)
throw_line("failed to get security sectors, SCSI ({})", SPTD::StatusMessage(status));
bool complete_ss = xbox_get_security_sector(*ctx.sptd, security_sector);
if(!complete_ss)
LOG("warning: could not get complete security sector, attempting to continue");

// store security sector
if(dump_mode == DumpMode::DUMP)
Expand Down Expand Up @@ -478,8 +478,9 @@ export bool redumper_dump_dvd(Context &ctx, const Options &options, DumpMode dum

if(dump_mode == DumpMode::DUMP)
{
// store cleaned security sector
write_vector(security_sector_fn, security_sector);
// don't write cleaned version if security sector incomplete
if(complete_ss)
write_vector(security_sector_fn, security_sector);
}
else if(!options.force_refine)
{
Expand Down
22 changes: 4 additions & 18 deletions scsi/cmd.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -447,34 +447,22 @@ SPTD::Status cmd_get_configuration(SPTD &sptd)
}


export SPTD::Status cmd_kreon_get_security_sector(SPTD &sptd, std::vector<uint8_t> &response_data)
export SPTD::Status cmd_kreon_get_security_sector(SPTD &sptd, std::vector<uint8_t> &response_data, uint8_t ss_val)
{
SPTD::Status status;

// AD 00 FF 02 FD FF FE 00 08 00 xx C0
CDB12_ReadDiscStructure cdb = {};
cdb.operation_code = (uint8_t)CDB_OperationCode::READ_DISC_STRUCTURE;
*(uint32_t *)cdb.address = endian_swap<uint32_t>(0xFF02FDFF);
cdb.layer_number = 0xFE;
*(uint16_t *)cdb.allocation_length = endian_swap<uint16_t>((uint16_t)response_data.size());
cdb.reserved2 = ss_val;
cdb.control = 0xC0;

const uint8_t kreon_ss_vals[4] = { 0x01, 0x03, 0x05, 0x07 };
for(auto ss_val : kreon_ss_vals)
{
cdb.reserved2 = ss_val;
status = sptd.sendCommand(&cdb, sizeof(cdb), response_data.data(), response_data.size());
if(status.status_code)
break;
}

return status;
return sptd.sendCommand(&cdb, sizeof(cdb), response_data.data(), response_data.size());
}

export SPTD::Status cmd_kreon_set_lock_state(SPTD &sptd, KREON_LockState lock_state)
{
SPTD::Status status;

// FF 08 01 01 (Legacy)
// FF 08 01 11 xx
bool is_legacy = (lock_state == KREON_LockState::LEGACY);
Expand All @@ -492,9 +480,7 @@ export SPTD::Status cmd_kreon_set_lock_state(SPTD &sptd, KREON_LockState lock_st
cdb.extended = (uint8_t)lock_state;
}

status = sptd.sendCommand(&cdb, sizeof(cdb), nullptr, 0);

return status;
return sptd.sendCommand(&cdb, sizeof(cdb), nullptr, 0);
}

}
24 changes: 24 additions & 0 deletions utils/xbox.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ module;
#include <algorithm>
#include <cstdint>
#include <vector>
#include "throw_line.hh"

export module utils.xbox;

import scsi.cmd;
import scsi.mmc;
import scsi.sptd;
import utils.endian;


Expand Down Expand Up @@ -121,4 +124,25 @@ export void clean_xbox_security_sector(std::vector<uint8_t> &security_sector)
}
}

export bool xbox_get_security_sector(SPTD &sptd, std::vector<uint8_t> &response_data)
{
SPTD::Status status;

const uint8_t ss_vals[4] = { 0x01, 0x03, 0x05, 0x07 };
for(int i = 0; i < sizeof(ss_vals); ++i)
{
status = cmd_kreon_get_security_sector(sptd, response_data, ss_vals[i]);
if(status.status_code)
{
// fail if cannot get initial response
if(i == 0)
throw_line("failed to get security sector, SCSI ({})", SPTD::StatusMessage(status));

return false;
}
}

return true;
}

}

0 comments on commit dd81526

Please sign in to comment.