Skip to content

Commit

Permalink
Added Opalite, Pyrite, and Ruby support and QOL fixes
Browse files Browse the repository at this point in the history
Added Opalite, Pyrite, and Ruby support from @amotin sedutil fork. QOL and typo fixes from @Philzen.
  • Loading branch information
ChubbyAnt committed Jan 6, 2021
1 parent 7bb7c31 commit 5ad84d8
Show file tree
Hide file tree
Showing 70 changed files with 3,221 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ config.h.in
config.status
Makefile
sedutil-*.tar.*
linuxpba
#linuxpba
sedutil-cli

# GCC
Expand Down
197 changes: 192 additions & 5 deletions Common/DtaDev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ DtaDev::DtaDev()
DtaDev::~DtaDev()
{
}
uint8_t DtaDev::isRuby1()
{
LOG(D1) << "Entering DtaDev::isRuby1 " << (uint16_t) disk_info.Ruby10;
return disk_info.Ruby10;
}
uint8_t DtaDev::isPyrite2()
{
LOG(D1) << "Entering DtaDev::isPyrite2 " << (uint16_t) disk_info.Pyrite20;
return disk_info.Pyrite20;
}
uint8_t DtaDev::isPyrite1()
{
LOG(D1) << "Entering DtaDev::isPyrite1 " << (uint16_t) disk_info.Pyrite10;
return disk_info.Pyrite10;
}
uint8_t DtaDev::isOpalite()
{
LOG(D1) << "Entering DtaDev::isOpalite " << (uint16_t) disk_info.Opalite;
return disk_info.Opalite;
}
uint8_t DtaDev::isOpal2()
{
LOG(D1) << "Entering DtaDev::isOpal2 " << (uint16_t) disk_info.OPAL20;
Expand Down Expand Up @@ -80,6 +100,11 @@ uint8_t DtaDev::MBRDone()
LOG(D1) << "Entering DtaDev::MBRDone" << (uint16_t)disk_info.Locking_MBRDone;
return disk_info.Locking_MBRDone;
}
uint8_t DtaDev::MBRAbsent()
{
LOG(D1) << "Entering DtaDev::MBRAbsent" << (uint16_t)disk_info.Locking_MBRAbsent;
return disk_info.Locking_MBRAbsent;
}
uint8_t DtaDev::Locked()
{
LOG(D1) << "Entering DtaDev::Locked" << (uint16_t)disk_info.Locking_locked;
Expand Down Expand Up @@ -114,6 +139,8 @@ void DtaDev::discovery0()
uint8_t * epos, *cpos;
Discovery0Header * hdr;
Discovery0Features * body;
uint32_t len;

d0Response = discovery0buffer + IO_BUFFER_ALIGNMENT;
d0Response = (void *)((uintptr_t)d0Response & (uintptr_t)~(IO_BUFFER_ALIGNMENT - 1));
memset(d0Response, 0, MIN_BUFFER_LENGTH);
Expand All @@ -124,9 +151,14 @@ void DtaDev::discovery0()

epos = cpos = (uint8_t *) d0Response;
hdr = (Discovery0Header *) d0Response;
len = SWAP32(hdr->length);
if (len > MIN_BUFFER_LENGTH) {
LOG(D) << "Too long Discovery0 response: " << SWAP32(hdr->length);
len = MIN_BUFFER_LENGTH;
}
LOG(D3) << "Dumping D0Response";
IFLOG(D3) DtaHexDump(hdr, SWAP32(hdr->length));
epos = epos + SWAP32(hdr->length);
IFLOG(D3) DtaHexDump(hdr, len);
epos = epos + len;
cpos = cpos + 48; // TODO: check header version

do {
Expand All @@ -148,6 +180,7 @@ void DtaDev::discovery0()
disk_info.Locking_lockingSupported = body->locking.lockingSupported;
disk_info.Locking_MBRDone = body->locking.MBRDone;
disk_info.Locking_MBREnabled = body->locking.MBREnabled;
disk_info.Locking_MBRAbsent = body->locking.MBRAbsent;
disk_info.Locking_mediaEncrypt = body->locking.mediaEncryption;
break;
case FC_GEOMETRY: /* Geometry Features */
Expand All @@ -157,6 +190,11 @@ void DtaDev::discovery0()
disk_info.Geometry_logicalBlockSize = SWAP32(body->geometry.logicalBlockSize);
disk_info.Geometry_lowestAlignedLBA = SWAP64(body->geometry.lowestAlighedLBA);
break;
case FC_SECUREMSG: /* Secure Messaging */
disk_info.SecureMsg = 1;
disk_info.SecureMsg_activated = body->secureMsg.activated;
disk_info.SecureMsg_numberOfSPs = SWAP16(body->secureMsg.numberOfSPs);
break;
case FC_ENTERPRISE: /* Enterprise SSC */
disk_info.Enterprise = 1;
disk_info.ANY_OPAL_SSC = 1;
Expand All @@ -169,6 +207,7 @@ void DtaDev::discovery0()
disk_info.ANY_OPAL_SSC = 1;
disk_info.OPAL10_basecomID = SWAP16(body->opalv100.baseComID);
disk_info.OPAL10_numcomIDs = SWAP16(body->opalv100.numberComIDs);
disk_info.OPAL10_rangeCrossing = body->opalv100.rangeCrossing;
break;
case FC_SINGLEUSER: /* Single User Mode */
disk_info.SingleUser = 1;
Expand All @@ -194,6 +233,69 @@ void DtaDev::discovery0()
disk_info.OPAL20_numUsers = SWAP16(body->opalv200.numlockingUserAuth);
disk_info.OPAL20_rangeCrossing = body->opalv200.rangeCrossing;
break;
case FC_BLOCKSID: /* Block SID Authentication */
disk_info.BlockSID = 1;
disk_info.BlockSID_SIDBlockedState = body->blockSID.SIDBlockedState;
disk_info.BlockSID_SIDValueState = body->blockSID.SIDValueState;
disk_info.BlockSID_HardwareReset = body->blockSID.HardwareReset;
break;
case FC_NAMESPACE: /* Namespace */
disk_info.Namespace = 1;
disk_info.Namespace_MaximumKeyCount = SWAP32(body->ns.MaximumKeyCount);
disk_info.Namespace_UnusedKeyCount = SWAP32(body->ns.UnusedKeyCount);
disk_info.Namespace_MaximumRangesPerNamespace = SWAP32(body->ns.MaximumRangesPerNamespace);
break;
case FC_OPALITE: /* Opalite */
disk_info.Opalite = 1;
disk_info.ANY_OPAL_SSC = 1;
disk_info.Opalite_basecomID = SWAP16(body->opalite.baseCommID);
disk_info.Opalite_numcomIDs = SWAP16(body->opalite.numCommIDs);
disk_info.Opalite_initialPIN = body->opalite.initialPIN;
disk_info.Opalite_revertedPIN = body->opalite.revertedPIN;
break;
case FC_PYRITEV100: /* Pyrite V100 */
disk_info.Pyrite10 = 1;
disk_info.ANY_OPAL_SSC = 1;
disk_info.Pyrite10_basecomID = SWAP16(body->pyrite10.baseCommID);
disk_info.Pyrite10_numcomIDs = SWAP16(body->pyrite10.numCommIDs);
disk_info.Pyrite10_initialPIN = body->pyrite10.initialPIN;
disk_info.Pyrite10_revertedPIN = body->pyrite10.revertedPIN;
break;
case FC_PYRITEV200: /* Pyrite V200 */
disk_info.Pyrite20 = 1;
disk_info.ANY_OPAL_SSC = 1;
disk_info.Pyrite20_basecomID = SWAP16(body->pyrite20.baseCommID);
disk_info.Pyrite20_numcomIDs = SWAP16(body->pyrite20.numCommIDs);
disk_info.Pyrite20_initialPIN = body->pyrite20.initialPIN;
disk_info.Pyrite20_revertedPIN = body->pyrite20.revertedPIN;
break;
case FC_RUBYV100: /* Ruby V1.00 */
disk_info.Ruby10 = 1;
disk_info.ANY_OPAL_SSC = 1;
disk_info.Ruby10_basecomID = SWAP16(body->ruby10.baseCommID);
disk_info.Ruby10_numcomIDs = SWAP16(body->ruby10.numCommIDs);
disk_info.Ruby10_rangeCrossing = body->ruby10.rangeCrossing;
disk_info.Ruby10_numAdmins = SWAP16(body->ruby10.numlockingAdminAuth);
disk_info.Ruby10_numUsers = SWAP16(body->ruby10.numlockingUserAuth);
disk_info.Ruby10_initialPIN = body->ruby10.initialPIN;
disk_info.Ruby10_revertedPIN = body->ruby10.revertedPIN;
disk_info.Ruby10_PINonTPerRevert = body->ruby10.PINonTPerRevert;
break;
case FC_DATAREM: /* Supported Data Removal Mechanism */
disk_info.DataRem = 1;
disk_info.DataRem_processing = body->dataRem.processing;
disk_info.DataRem_supported = body->dataRem.supported;
disk_info.DataRem_format = body->dataRem.format;
for (int i = 0; i < 6; i++)
disk_info.DataRem_time[i] = SWAP16(body->dataRem.time[i]);
break;
case FC_NSGEOMETRY: /* Namespace Geometry Reporting */
disk_info.NSGeometry = 1;
disk_info.NSGeometry_align = body->nsgeometry.align;
disk_info.NSGeometry_alignmentGranularity = SWAP64(body->nsgeometry.alignmentGranularity);
disk_info.NSGeometry_logicalBlockSize = SWAP32(body->nsgeometry.logicalBlockSize);
disk_info.NSGeometry_lowestAlignedLBA = SWAP64(body->nsgeometry.lowestAlighedLBA);
break;
default:
if (0xbfff < (SWAP16(body->TPer.featureCode))) {
// silently ignore vendor specific segments as there is no public doc on them
Expand Down Expand Up @@ -240,6 +342,7 @@ void DtaDev::puke()
<< "LockingSupported = " << (disk_info.Locking_lockingSupported ? "Y, " : "N, ");
cout << "MBRDone = " << (disk_info.Locking_MBRDone ? "Y, " : "N, ")
<< "MBREnabled = " << (disk_info.Locking_MBREnabled ? "Y, " : "N, ")
<< "MBRAbsent = " << (disk_info.Locking_MBRAbsent ? "Y, " : "N, ")
<< "MediaEncrypt = " << (disk_info.Locking_mediaEncrypt ? "Y" : "N")
<< std::endl;
}
Expand All @@ -256,6 +359,13 @@ void DtaDev::puke()
<< ", Lowest Aligned LBA = " << disk_info.Geometry_lowestAlignedLBA
<< std::endl;
}
if (disk_info.SecureMsg) {

cout << "Secure Messaging function (" << HEXON(4) << FC_SECUREMSG << HEXOFF << ")" << std::endl;
cout << " Activated = " << (disk_info.SecureMsg_activated ? "Y, " : "N, ")
<< "Number of SPs = " << disk_info.SecureMsg_numberOfSPs
<< std::endl;
}
if (disk_info.Enterprise) {
cout << "Enterprise function (" << HEXON(4) << FC_ENTERPRISE << HEXOFF << ")" << std::endl;
cout << " Range crossing = " << (disk_info.Enterprise_rangeCrossing ? "Y, " : "N, ")
Expand All @@ -265,8 +375,9 @@ void DtaDev::puke()
}
if (disk_info.OPAL10) {
cout << "Opal V1.0 function (" << HEXON(4) << FC_OPALV100 << HEXOFF << ")" << std::endl;
cout << "Base comID = " << HEXON(4) << disk_info.OPAL10_basecomID << HEXOFF
cout << " Base comID = " << HEXON(4) << disk_info.OPAL10_basecomID << HEXOFF
<< ", comIDs = " << disk_info.OPAL10_numcomIDs
<< ", Range Crossing = " << (disk_info.OPAL10_rangeCrossing ? "Y" : "N")
<< std::endl;
}
if (disk_info.SingleUser) {
Expand All @@ -288,15 +399,91 @@ void DtaDev::puke()
if (disk_info.OPAL20) {
cout << "OPAL 2.0 function (" << HEXON(4) << FC_OPALV200 << ")" << HEXOFF << std::endl;
cout << " Base comID = " << HEXON(4) << disk_info.OPAL20_basecomID << HEXOFF;
cout << ", Initial PIN = " << HEXON(2) << disk_info.OPAL20_initialPIN << HEXOFF;
cout << ", Reverted PIN = " << HEXON(2) << disk_info.OPAL20_revertedPIN << HEXOFF;
cout << ", Initial PIN = " << HEXON(2) << static_cast<uint32_t>(disk_info.OPAL20_initialPIN) << HEXOFF;
cout << ", Reverted PIN = " << HEXON(2) << static_cast<uint32_t>(disk_info.OPAL20_revertedPIN) << HEXOFF;
cout << ", comIDs = " << disk_info.OPAL20_numcomIDs;
cout << std::endl;
cout << " Locking Admins = " << disk_info.OPAL20_numAdmins;
cout << ", Locking Users = " << disk_info.OPAL20_numUsers;
cout << ", Range Crossing = " << (disk_info.OPAL20_rangeCrossing ? "Y" : "N");
cout << std::endl;
}
if (disk_info.BlockSID) {
cout << "Block SID Authentication function (" << HEXON(4) << FC_BLOCKSID << ")" << HEXOFF << std::endl;
cout << " SID Blocked State = " << (disk_info.BlockSID_SIDBlockedState ? "Y" : "N");
cout << ", SID Value State = " << (disk_info.BlockSID_SIDValueState ? "Y" : "N");
cout << ", Hardware Reset = " << (disk_info.BlockSID_HardwareReset ? "Y" : "N");
cout << std::endl;
}
if (disk_info.Namespace) {
cout << "Namespace function (" << HEXON(4) << FC_NAMESPACE << ")" << HEXOFF << std::endl;
cout << " Maximum Key Count = " << disk_info.Namespace_MaximumKeyCount;
cout << ", Unused Key Count = " << disk_info.Namespace_UnusedKeyCount;
cout << ", Maximum Ranges Per Namespace = " << disk_info.Namespace_MaximumRangesPerNamespace;
cout << std::endl;
}
if (disk_info.Opalite) {
cout << "Opalite function (" << HEXON(4) << FC_OPALITE << ")" << HEXOFF << std::endl;
cout << " Base comID = " << HEXON(4) << disk_info.Opalite_basecomID << HEXOFF;
cout << ", comIDs = " << disk_info.Opalite_numcomIDs;
cout << ", Initial PIN = " << HEXON(2) << disk_info.Opalite_initialPIN << HEXOFF;
cout << ", Reverted PIN = " << HEXON(2) << disk_info.Opalite_revertedPIN << HEXOFF;
cout << std::endl;
}
if (disk_info.Pyrite10) {
cout << "Pyrite 1.0 function (" << HEXON(4) << FC_PYRITEV100 << ")" << HEXOFF << std::endl;
cout << " Base comID = " << HEXON(4) << disk_info.Pyrite10_basecomID << HEXOFF;
cout << ", comIDs = " << disk_info.Pyrite10_numcomIDs;
cout << ", Initial PIN = " << HEXON(2) << disk_info.Pyrite10_initialPIN << HEXOFF;
cout << ", Reverted PIN = " << HEXON(2) << disk_info.Pyrite10_revertedPIN << HEXOFF;
cout << std::endl;
}
if (disk_info.Pyrite20) {
cout << "Pyrite 2.0 function (" << HEXON(4) << FC_PYRITEV200 << ")" << HEXOFF << std::endl;
cout << " Base comID = " << HEXON(4) << disk_info.Pyrite20_basecomID << HEXOFF;
cout << ", comIDs = " << disk_info.Pyrite20_numcomIDs;
cout << ", Initial PIN = " << HEXON(2) << disk_info.Pyrite20_initialPIN << HEXOFF;
cout << ", Reverted PIN = " << HEXON(2) << disk_info.Pyrite20_revertedPIN << HEXOFF;
cout << std::endl;
}
if (disk_info.Ruby10) {
cout << "Ruby 1.0 function (" << HEXON(4) << FC_RUBYV100 << ")" << HEXOFF << std::endl;
cout << " Base comID = " << HEXON(4) << disk_info.Ruby10_basecomID << HEXOFF;
cout << ", comIDs = " << disk_info.Ruby10_numcomIDs;
cout << ", Initial PIN = " << HEXON(2) << disk_info.Ruby10_initialPIN << HEXOFF;
cout << ", Reverted PIN = " << HEXON(2) << disk_info.Ruby10_revertedPIN << HEXOFF;
cout << ", PINonTPerRevert = " << HEXON(2) << disk_info.Ruby10_PINonTPerRevert << HEXOFF;
cout << std::endl;
cout << " Locking Admins = " << disk_info.Ruby10_numAdmins;
cout << ", Locking Users = " << disk_info.Ruby10_numUsers;
cout << ", Range Crossing = " << (disk_info.Ruby10_rangeCrossing ? "Y" : "N");
cout << std::endl;
}
if (disk_info.DataRem) {
cout << "Supported Data Removal Mechanism function (" << HEXON(4) << FC_DATAREM << ")" << HEXOFF << std::endl;
cout << " Processing = " << (disk_info.DataRem_processing ? "Y" : "N");
string types[6] = { "Overwrite", "Block", "Crypto", "Unmap", "Reset Write Pointers", "Vendor Specific" };
for (int i = 0; i < 6; i++) {
if ((disk_info.DataRem_supported & (1 << i)) == 0)
continue;
cout << ", " << types[i];
cout << " = " << (disk_info.DataRem_time[i] * 2) <<
(((disk_info.DataRem_format & (1 << i)) == 0) ? "s " : "m ");
}
cout << std::endl;
}
if (disk_info.NSGeometry) {
cout << "Namespace Geometry function (" << HEXON(4) << FC_NSGEOMETRY << HEXOFF << ")" << std::endl;
cout << " Align = " << (disk_info.NSGeometry_align ? "Y, " : "N, ")
<< "Alignment Granularity = " << disk_info.NSGeometry_alignmentGranularity
<< " (" << // display bytes
(disk_info.NSGeometry_alignmentGranularity *
disk_info.NSGeometry_logicalBlockSize)
<< ")"
<< ", Logical Block size = " << disk_info.NSGeometry_logicalBlockSize
<< ", Lowest Aligned LBA = " << disk_info.NSGeometry_lowestAlignedLBA
<< std::endl;
}
if (disk_info.Unknown)
cout << "**** " << (uint16_t)disk_info.Unknown << " **** Unknown function codes IGNORED " << std::endl;
}
18 changes: 14 additions & 4 deletions Common/DtaDev.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ class DtaDev {
DtaDev();
/** Default destructor, does nothing*/
virtual ~DtaDev();
/** Does the device conform to the Ruby 1.0 SSC */
uint8_t isRuby1();
/** Does the device conform to the Pyrite 2.0 SSC */
uint8_t isPyrite2();
/** Does the device conform to the Pyrite 1.0 SSC */
uint8_t isPyrite1();
/** Does the device conform to the Opalite SSC */
uint8_t isOpalite();
/** Does the device conform to the OPAL 2.0 SSC */
uint8_t isOpal2();
/** Does the device conform to the OPAL 1.0 SSC */
Expand All @@ -50,6 +58,8 @@ class DtaDev {
uint8_t MBREnabled();
/** Is the MBRDone flag set */
uint8_t MBRDone();
/** Is the MBRAbsent flag set */
uint8_t MBRAbsent();
/** Is the Locked flag set */
uint8_t Locked();
/** Is the Locking SP enabled */
Expand Down Expand Up @@ -251,16 +261,16 @@ class DtaDev {
virtual uint8_t eraseLockingRange(uint8_t lockingrange, char * password) = 0;
/** Dumps an object for diagnostic purposes
* @param sp index into the OPALUID table for the SP the object is in
* @param auth the authority ti use for the dump
* @param pass the password for the suthority
* @param auth the authority to use for the dump
* @param pass the password for the authority
* @param objID the UID of the object to dump
* */
virtual uint8_t objDump(char *sp, char * auth, char *pass,
char * objID) = 0;
/** Issue any command to the drive for diagnostic purposes
* @param sp index into the OPALUID table for the SP the object is in
* @param auth the authority ti use for the dump
* @param pass the password for the suthority
* @param auth the authority to use for the dump
* @param pass the password for the authority
* @param invoker caller of the method
* @param method the method to call
* @param plist the parameter list for the command
Expand Down
Loading

0 comments on commit 5ad84d8

Please sign in to comment.