Code reformat.

This commit is contained in:
2019-11-25 00:54:38 +00:00
parent a5c650440d
commit d864bfab6c
116 changed files with 16544 additions and 19331 deletions

View File

@@ -36,28 +36,27 @@ using System.Text;
namespace DiscImageChef.Decoders.SecureDigital
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public class CID
{
public byte Manufacturer;
public string ApplicationID;
public byte CRC;
public byte Manufacturer;
public ushort ManufacturingDate;
public string ProductName;
public byte ProductRevision;
public uint ProductSerialNumber;
public ushort ManufacturingDate;
public byte CRC;
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Decoders
{
public static CID DecodeCID(uint[] response)
{
if(response?.Length != 4) return null;
if(response?.Length != 4)
return null;
byte[] data = new byte[16];
@@ -75,16 +74,17 @@ namespace DiscImageChef.Decoders.SecureDigital
public static CID DecodeCID(byte[] response)
{
if(response?.Length != 16) return null;
if(response?.Length != 16)
return null;
CID cid = new CID
var cid = new CID
{
Manufacturer = response[0],
ProductRevision = response[8],
Manufacturer = response[0], ProductRevision = response[8],
ProductSerialNumber = BitConverter.ToUInt32(response, 9),
ManufacturingDate = (ushort)(((response[13] & 0x0F) << 4) + response[14]),
CRC = (byte)((response[15] & 0xFE) >> 1)
};
byte[] tmp = new byte[2];
Array.Copy(response, 1, tmp, 0, 2);
cid.ApplicationID = StringHandlers.CToString(tmp);
@@ -97,20 +97,25 @@ namespace DiscImageChef.Decoders.SecureDigital
public static string PrettifyCID(CID cid)
{
if(cid == null) return null;
if(cid == null)
return null;
StringBuilder sb = new StringBuilder();
var sb = new StringBuilder();
sb.AppendLine("SecureDigital Device Identification Register:");
sb.AppendFormat("\tManufacturer: {0}", VendorString.Prettify(cid.Manufacturer)).AppendLine();
sb.AppendFormat("\tApplication ID: {0}", cid.ApplicationID).AppendLine();
sb.AppendFormat("\tProduct name: {0}", cid.ProductName).AppendLine();
sb.AppendFormat("\tProduct revision: {0:X2}.{1:X2}", (cid.ProductRevision & 0xF0) >> 4,
cid.ProductRevision & 0x0F).AppendLine();
sb.AppendFormat("\tProduct serial number: {0}", cid.ProductSerialNumber).AppendLine();
sb.AppendFormat("\tDevice manufactured month {0} of {1}", (cid.ManufacturingDate & 0xF00) >> 8,
(cid.ManufacturingDate & 0xFF) + 2000)
.AppendLine();
(cid.ManufacturingDate & 0xFF) + 2000).
AppendLine();
sb.AppendFormat("\tCID CRC: 0x{0:X2}", cid.CRC).AppendLine();
return sb.ToString();

View File

@@ -36,49 +36,48 @@ using System.Text;
namespace DiscImageChef.Decoders.SecureDigital
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public class CSD
{
public byte Structure;
public byte TAAC;
public byte NSAC;
public byte Speed;
public ushort Classes;
public byte ReadBlockLength;
public bool ReadsPartialBlocks;
public bool WriteMisalignment;
public bool ReadMisalignment;
public bool Copy;
public byte CRC;
public bool DSRImplemented;
public uint Size;
public byte ReadCurrentAtVddMin;
public byte ReadCurrentAtVddMax;
public byte WriteCurrentAtVddMin;
public byte WriteCurrentAtVddMax;
public byte SizeMultiplier;
public bool EraseBlockEnable;
public byte EraseSectorSize;
public byte WriteProtectGroupSize;
public bool WriteProtectGroupEnable;
public byte WriteSpeedFactor;
public byte WriteBlockLength;
public bool WritesPartialBlocks;
public bool FileFormatGroup;
public bool Copy;
public bool PermanentWriteProtect;
public bool TemporaryWriteProtect;
public byte FileFormat;
public byte CRC;
public bool FileFormatGroup;
public byte NSAC;
public bool PermanentWriteProtect;
public byte ReadBlockLength;
public byte ReadCurrentAtVddMax;
public byte ReadCurrentAtVddMin;
public bool ReadMisalignment;
public bool ReadsPartialBlocks;
public uint Size;
public byte SizeMultiplier;
public byte Speed;
public byte Structure;
public byte TAAC;
public bool TemporaryWriteProtect;
public byte WriteBlockLength;
public byte WriteCurrentAtVddMax;
public byte WriteCurrentAtVddMin;
public bool WriteMisalignment;
public bool WriteProtectGroupEnable;
public byte WriteProtectGroupSize;
public bool WritesPartialBlocks;
public byte WriteSpeedFactor;
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Decoders
{
public static CSD DecodeCSD(uint[] response)
{
if(response?.Length != 4) return null;
if(response?.Length != 4)
return null;
byte[] data = new byte[16];
@@ -96,21 +95,20 @@ namespace DiscImageChef.Decoders.SecureDigital
public static CSD DecodeCSD(byte[] response)
{
if(response?.Length != 16) return null;
if(response?.Length != 16)
return null;
CSD csd = new CSD
var csd = new CSD
{
Structure = (byte)((response[0] & 0xC0) >> 6),
TAAC = response[1],
Structure = (byte)((response[0] & 0xC0) >> 6), TAAC = response[1],
NSAC = response[2],
Speed = response[3],
Classes = (ushort)((response[4] << 4) + ((response[5] & 0xF0) >> 4)),
ReadBlockLength = (byte)(response[5] & 0x0F),
ReadsPartialBlocks = (response[6] & 0x80) == 0x80,
WriteMisalignment = (response[6] & 0x40) == 0x40,
ReadMisalignment = (response[6] & 0x20) == 0x20,
DSRImplemented = (response[6] & 0x10) == 0x10,
EraseBlockEnable = (response[10] & 0x40) == 0x40,
ReadBlockLength = (byte)(response[5] & 0x0F), ReadsPartialBlocks = (response[6] & 0x80) == 0x80,
WriteMisalignment = (response[6] & 0x40) == 0x40,
ReadMisalignment = (response[6] & 0x20) == 0x20,
DSRImplemented = (response[6] & 0x10) == 0x10,
EraseBlockEnable = (response[10] & 0x40) == 0x40,
EraseSectorSize = (byte)(((response[10] & 0x3F) << 1) + ((response[11] & 0x80) >> 7)),
WriteProtectGroupSize = (byte)(response[11] & 0x7F),
WriteProtectGroupEnable = (response[12] & 0x80) == 0x80,
@@ -122,41 +120,48 @@ namespace DiscImageChef.Decoders.SecureDigital
PermanentWriteProtect = (response[14] & 0x20) == 0x20,
TemporaryWriteProtect = (response[14] & 0x10) == 0x10,
FileFormat = (byte)((response[14] & 0x0C) >> 2),
CRC = (byte)((response[15] & 0xFE) >> 1)
CRC =
(byte)((response[15] & 0xFE) >> 1)
};
if(csd.Structure == 0)
{
csd.Size =
(ushort)(((response[6] & 0x03) << 10) + (response[7] << 2) + ((response[8] & 0xC0) >> 6));
csd.ReadCurrentAtVddMin = (byte)((response[8] & 0x38) >> 3);
csd.ReadCurrentAtVddMax = (byte)(response[8] & 0x07);
csd.WriteCurrentAtVddMin = (byte)((response[9] & 0xE0) >> 5);
csd.WriteCurrentAtVddMax = (byte)((response[9] & 0x1C) >> 2);
csd.SizeMultiplier = (byte)(((response[9] & 0x03) << 1) + ((response[10] & 0x80) >> 7));
}
else csd.Size = (uint)(((response[7] & 0x3F) << 16) + (response[8] << 8) + response[9]);
else
csd.Size = (uint)(((response[7] & 0x3F) << 16) + (response[8] << 8) + response[9]);
return csd;
}
public static string PrettifyCSD(CSD csd)
{
if(csd == null) return null;
if(csd == null)
return null;
double unitFactor = 0;
double multiplier = 0;
string unit = "";
StringBuilder sb = new StringBuilder();
var sb = new StringBuilder();
sb.AppendLine("SecureDigital Device Specific Data Register:");
switch(csd.Structure)
{
case 0:
sb.AppendLine("\tRegister version 1.0");
break;
case 1:
sb.AppendLine("\tRegister version 2.0");
break;
}
@@ -165,34 +170,42 @@ namespace DiscImageChef.Decoders.SecureDigital
case 0:
unit = "ns";
unitFactor = 1;
break;
case 1:
unit = "ns";
unitFactor = 10;
break;
case 2:
unit = "ns";
unitFactor = 100;
break;
case 3:
unit = "μs";
unitFactor = 1;
break;
case 4:
unit = "μs";
unitFactor = 10;
break;
case 5:
unit = "μs";
unitFactor = 100;
break;
case 6:
unit = "ms";
unitFactor = 1;
break;
case 7:
unit = "ms";
unitFactor = 10;
break;
}
@@ -200,51 +213,67 @@ namespace DiscImageChef.Decoders.SecureDigital
{
case 0:
multiplier = 0;
break;
case 1:
multiplier = 1;
break;
case 2:
multiplier = 1.2;
break;
case 3:
multiplier = 1.3;
break;
case 4:
multiplier = 1.5;
break;
case 5:
multiplier = 2;
break;
case 6:
multiplier = 2.5;
break;
case 7:
multiplier = 3;
break;
case 8:
multiplier = 3.5;
break;
case 9:
multiplier = 4;
break;
case 10:
multiplier = 4.5;
break;
case 11:
multiplier = 5;
break;
case 12:
multiplier = 5.5;
break;
case 13:
multiplier = 6;
break;
case 14:
multiplier = 7;
break;
case 15:
multiplier = 8;
break;
}
@@ -254,23 +283,29 @@ namespace DiscImageChef.Decoders.SecureDigital
sb.AppendFormat("\tClock dependent part of data access is {0} clock cycles", csd.NSAC * 100).AppendLine();
unit = "MBit/s";
switch(csd.Speed & 0x07)
{
case 0:
unitFactor = 0.1;
break;
case 1:
unitFactor = 1;
break;
case 2:
unitFactor = 10;
break;
case 3:
unitFactor = 100;
break;
default:
unit = "unknown";
unitFactor = 0;
break;
}
@@ -278,51 +313,67 @@ namespace DiscImageChef.Decoders.SecureDigital
{
case 0:
multiplier = 0;
break;
case 1:
multiplier = 1;
break;
case 2:
multiplier = 1.2;
break;
case 3:
multiplier = 1.3;
break;
case 4:
multiplier = 1.5;
break;
case 5:
multiplier = 2;
break;
case 6:
multiplier = 2.6;
break;
case 7:
multiplier = 3;
break;
case 8:
multiplier = 3.5;
break;
case 9:
multiplier = 4;
break;
case 10:
multiplier = 4.5;
break;
case 11:
multiplier = 5.2;
break;
case 12:
multiplier = 5.5;
break;
case 13:
multiplier = 6;
break;
case 14:
multiplier = 7;
break;
case 15:
multiplier = 8;
break;
}
@@ -330,6 +381,7 @@ namespace DiscImageChef.Decoders.SecureDigital
sb.AppendFormat("\tDevice's transfer speed: {0}{1}", result, unit).AppendLine();
unit = "";
for(int cl = 0, mask = 1; cl <= 11; cl++, mask <<= 1)
if((csd.Classes & mask) == mask)
unit += $" {cl}";
@@ -337,12 +389,17 @@ namespace DiscImageChef.Decoders.SecureDigital
sb.AppendFormat("\tDevice support command classes {0}", unit).AppendLine();
sb.AppendFormat("\tRead block length is {0} bytes", Math.Pow(2, csd.ReadBlockLength)).AppendLine();
if(csd.ReadsPartialBlocks) sb.AppendLine("\tDevice allows reading partial blocks");
if(csd.ReadsPartialBlocks)
sb.AppendLine("\tDevice allows reading partial blocks");
if(csd.WriteMisalignment) sb.AppendLine("\tWrite commands can cross physical block boundaries");
if(csd.ReadMisalignment) sb.AppendLine("\tRead commands can cross physical block boundaries");
if(csd.WriteMisalignment)
sb.AppendLine("\tWrite commands can cross physical block boundaries");
if(csd.DSRImplemented) sb.AppendLine("\tDevice implements configurable driver stage");
if(csd.ReadMisalignment)
sb.AppendLine("\tRead commands can cross physical block boundaries");
if(csd.DSRImplemented)
sb.AppendLine("\tDevice implements configurable driver stage");
if(csd.Structure == 0)
{
@@ -350,23 +407,31 @@ namespace DiscImageChef.Decoders.SecureDigital
sb.AppendFormat("\tDevice has {0} blocks", (int)result).AppendLine();
result = (csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2) * Math.Pow(2, csd.ReadBlockLength);
if(result > 1073741824)
sb.AppendFormat("\tDevice has {0} GiB", result / 1073741824.0).AppendLine();
else if(result > 1048576) sb.AppendFormat("\tDevice has {0} MiB", result / 1048576.0).AppendLine();
else if(result > 1024) sb.AppendFormat("\tDevice has {0} KiB", result / 1024.0).AppendLine();
else sb.AppendFormat("\tDevice has {0} bytes", result).AppendLine();
else if(result > 1048576)
sb.AppendFormat("\tDevice has {0} MiB", result / 1048576.0).AppendLine();
else if(result > 1024)
sb.AppendFormat("\tDevice has {0} KiB", result / 1024.0).AppendLine();
else
sb.AppendFormat("\tDevice has {0} bytes", result).AppendLine();
}
else
{
sb.AppendFormat("\tDevice has {0} blocks", (csd.Size + 1) * 1024).AppendLine();
result = ((ulong)csd.Size + 1) * 1024 * 512;
if(result > 1099511627776)
sb.AppendFormat("\tDevice has {0} TiB", result / 1099511627776.0).AppendLine();
else if(result > 1073741824)
sb.AppendFormat("\tDevice has {0} GiB", result / 1073741824.0).AppendLine();
else if(result > 1048576) sb.AppendFormat("\tDevice has {0} MiB", result / 1048576.0).AppendLine();
else if(result > 1024) sb.AppendFormat("\tDevice has {0} KiB", result / 1024.0).AppendLine();
else sb.AppendFormat("\tDevice has {0} bytes", result).AppendLine();
else if(result > 1048576)
sb.AppendFormat("\tDevice has {0} MiB", result / 1048576.0).AppendLine();
else if(result > 1024)
sb.AppendFormat("\tDevice has {0} KiB", result / 1024.0).AppendLine();
else
sb.AppendFormat("\tDevice has {0} bytes", result).AppendLine();
}
if(csd.Structure == 0)
@@ -375,27 +440,35 @@ namespace DiscImageChef.Decoders.SecureDigital
{
case 0:
sb.AppendLine("\tDevice uses a maximum of 0.5mA for reading at minimum voltage");
break;
case 1:
sb.AppendLine("\tDevice uses a maximum of 1mA for reading at minimum voltage");
break;
case 2:
sb.AppendLine("\tDevice uses a maximum of 5mA for reading at minimum voltage");
break;
case 3:
sb.AppendLine("\tDevice uses a maximum of 10mA for reading at minimum voltage");
break;
case 4:
sb.AppendLine("\tDevice uses a maximum of 25mA for reading at minimum voltage");
break;
case 5:
sb.AppendLine("\tDevice uses a maximum of 35mA for reading at minimum voltage");
break;
case 6:
sb.AppendLine("\tDevice uses a maximum of 60mA for reading at minimum voltage");
break;
case 7:
sb.AppendLine("\tDevice uses a maximum of 100mA for reading at minimum voltage");
break;
}
@@ -403,27 +476,35 @@ namespace DiscImageChef.Decoders.SecureDigital
{
case 0:
sb.AppendLine("\tDevice uses a maximum of 1mA for reading at maximum voltage");
break;
case 1:
sb.AppendLine("\tDevice uses a maximum of 5mA for reading at maximum voltage");
break;
case 2:
sb.AppendLine("\tDevice uses a maximum of 10mA for reading at maximum voltage");
break;
case 3:
sb.AppendLine("\tDevice uses a maximum of 25mA for reading at maximum voltage");
break;
case 4:
sb.AppendLine("\tDevice uses a maximum of 35mA for reading at maximum voltage");
break;
case 5:
sb.AppendLine("\tDevice uses a maximum of 45mA for reading at maximum voltage");
break;
case 6:
sb.AppendLine("\tDevice uses a maximum of 80mA for reading at maximum voltage");
break;
case 7:
sb.AppendLine("\tDevice uses a maximum of 200mA for reading at maximum voltage");
break;
}
@@ -431,27 +512,35 @@ namespace DiscImageChef.Decoders.SecureDigital
{
case 0:
sb.AppendLine("\tDevice uses a maximum of 0.5mA for writing at minimum voltage");
break;
case 1:
sb.AppendLine("\tDevice uses a maximum of 1mA for writing at minimum voltage");
break;
case 2:
sb.AppendLine("\tDevice uses a maximum of 5mA for writing at minimum voltage");
break;
case 3:
sb.AppendLine("\tDevice uses a maximum of 10mA for writing at minimum voltage");
break;
case 4:
sb.AppendLine("\tDevice uses a maximum of 25mA for writing at minimum voltage");
break;
case 5:
sb.AppendLine("\tDevice uses a maximum of 35mA for writing at minimum voltage");
break;
case 6:
sb.AppendLine("\tDevice uses a maximum of 60mA for writing at minimum voltage");
break;
case 7:
sb.AppendLine("\tDevice uses a maximum of 100mA for writing at minimum voltage");
break;
}
@@ -459,31 +548,40 @@ namespace DiscImageChef.Decoders.SecureDigital
{
case 0:
sb.AppendLine("\tDevice uses a maximum of 1mA for writing at maximum voltage");
break;
case 1:
sb.AppendLine("\tDevice uses a maximum of 5mA for writing at maximum voltage");
break;
case 2:
sb.AppendLine("\tDevice uses a maximum of 10mA for writing at maximum voltage");
break;
case 3:
sb.AppendLine("\tDevice uses a maximum of 25mA for writing at maximum voltage");
break;
case 4:
sb.AppendLine("\tDevice uses a maximum of 35mA for writing at maximum voltage");
break;
case 5:
sb.AppendLine("\tDevice uses a maximum of 45mA for writing at maximum voltage");
break;
case 6:
sb.AppendLine("\tDevice uses a maximum of 80mA for writing at maximum voltage");
break;
case 7:
sb.AppendLine("\tDevice uses a maximum of 200mA for writing at maximum voltage");
break;
}
if(csd.EraseBlockEnable) sb.AppendLine("\tDevice can erase multiple blocks");
if(csd.EraseBlockEnable)
sb.AppendLine("\tDevice can erase multiple blocks");
// TODO: Check specification
sb.AppendFormat("\tDevice must erase a minimum of {0} blocks at a time",
@@ -492,46 +590,57 @@ namespace DiscImageChef.Decoders.SecureDigital
if(csd.WriteProtectGroupEnable)
{
sb.AppendLine("\tDevice can write protect regions");
// TODO: Check specification
unitFactor = Convert.ToDouble(csd.WriteProtectGroupSize);
sb.AppendFormat("\tDevice can write protect a minimum of {0} blocks at a time", (int)(result + 1))
.AppendLine();
sb.AppendFormat("\tDevice can write protect a minimum of {0} blocks at a time", (int)(result + 1)).
AppendLine();
}
else sb.AppendLine("\tDevice can't write protect regions");
else
sb.AppendLine("\tDevice can't write protect regions");
}
sb.AppendFormat("\tWriting is {0} times slower than reading", Math.Pow(2, csd.WriteSpeedFactor))
.AppendLine();
sb.AppendFormat("\tWriting is {0} times slower than reading", Math.Pow(2, csd.WriteSpeedFactor)).
AppendLine();
sb.AppendFormat("\tWrite block length is {0} bytes", Math.Pow(2, csd.WriteBlockLength)).AppendLine();
if(csd.WritesPartialBlocks) sb.AppendLine("\tDevice allows writing partial blocks");
if(csd.WritesPartialBlocks)
sb.AppendLine("\tDevice allows writing partial blocks");
if(!csd.Copy) sb.AppendLine("\tDevice contents are original");
if(!csd.Copy)
sb.AppendLine("\tDevice contents are original");
if(csd.PermanentWriteProtect) sb.AppendLine("\tDevice is permanently write protected");
if(csd.PermanentWriteProtect)
sb.AppendLine("\tDevice is permanently write protected");
if(csd.TemporaryWriteProtect) sb.AppendLine("\tDevice is temporarily write protected");
if(csd.TemporaryWriteProtect)
sb.AppendLine("\tDevice is temporarily write protected");
if(!csd.FileFormatGroup)
switch(csd.FileFormat)
{
case 0:
sb.AppendLine("\tDevice is formatted like a hard disk");
break;
case 1:
sb.AppendLine("\tDevice is formatted like a floppy disk using Microsoft FAT");
break;
case 2:
sb.AppendLine("\tDevice uses Universal File Format");
break;
default:
sb.AppendFormat("\tDevice uses unknown file format code {0}", csd.FileFormat).AppendLine();
break;
}
else
sb.AppendFormat("\tDevice uses unknown file format code {0} and file format group 1", csd.FileFormat)
.AppendLine();
sb.AppendFormat("\tDevice uses unknown file format code {0} and file format group 1", csd.FileFormat).
AppendLine();
sb.AppendFormat("\tCSD CRC: 0x{0:X2}", csd.CRC).AppendLine();

View File

@@ -36,74 +36,90 @@ using System.Text;
namespace DiscImageChef.Decoders.SecureDigital
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "UnassignedField.Global")]
[SuppressMessage("ReSharper", "NotAccessedField.Global")]
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "UnassignedField.Global"),
SuppressMessage("ReSharper", "NotAccessedField.Global")]
public class OCR
{
public bool PowerUp;
public bool CCS;
public bool UHS;
public bool LowPower;
public bool OneEight;
public bool PowerUp;
public bool ThreeFive;
public bool ThreeFour;
public bool ThreeOne;
public bool ThreeThree;
public bool ThreeTwo;
public bool ThreeOne;
public bool ThreeZero;
public bool TwoNine;
public bool TwoEight;
public bool TwoNine;
public bool TwoSeven;
public bool LowPower;
public bool UHS;
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Decoders
{
public static OCR DecodeOCR(uint response) =>
new OCR
{
PowerUp = (response & 0x80000000) == 0x80000000,
CCS = (response & 0x40000000) == 0x40000000,
UHS = (response & 0x20000000) == 0x20000000,
OneEight = (response & 0x01000000) == 0x01000000,
ThreeFive = (response & 0x00800000) == 0x00800000,
ThreeFour = (response & 0x00400000) == 0x00400000,
ThreeThree = (response & 0x00200000) == 0x00200000,
ThreeTwo = (response & 0x00100000) == 0x00100000,
ThreeOne = (response & 0x00080000) == 0x00080000,
ThreeZero = (response & 0x00040000) == 0x00040000,
TwoNine = (response & 0x00020000) == 0x00020000,
TwoEight = (response & 0x00010000) == 0x00010000,
TwoSeven = (response & 0x00008000) == 0x00008000,
LowPower = (response & 0x00000080) == 0x00000080
};
public static OCR DecodeOCR(uint response) => new OCR
{
PowerUp = (response & 0x80000000) == 0x80000000, CCS = (response & 0x40000000) == 0x40000000,
UHS = (response & 0x20000000) == 0x20000000, OneEight = (response & 0x01000000) == 0x01000000,
ThreeFive = (response & 0x00800000) == 0x00800000, ThreeFour = (response & 0x00400000) == 0x00400000,
ThreeThree = (response & 0x00200000) == 0x00200000, ThreeTwo = (response & 0x00100000) == 0x00100000,
ThreeOne = (response & 0x00080000) == 0x00080000, ThreeZero = (response & 0x00040000) == 0x00040000,
TwoNine = (response & 0x00020000) == 0x00020000, TwoEight = (response & 0x00010000) == 0x00010000,
TwoSeven = (response & 0x00008000) == 0x00008000, LowPower = (response & 0x00000080) == 0x00000080
};
public static OCR DecodeOCR(byte[] response) =>
response?.Length != 4 ? null : DecodeOCR(BitConverter.ToUInt32(response, 0));
public static string PrettifyOCR(OCR ocr)
{
if(ocr == null) return null;
if(ocr == null)
return null;
StringBuilder sb = new StringBuilder();
var sb = new StringBuilder();
sb.AppendLine("SecureDigital Operation Conditions Register:");
if(!ocr.PowerUp) sb.AppendLine("\tDevice is powering up");
if(ocr.CCS) sb.AppendLine("\tDevice is SDHC, SDXC or higher");
if(ocr.UHS) sb.AppendLine("\tDevice is UHS-II or higher");
if(ocr.ThreeFive) sb.AppendLine("\tDevice can work with supply 3.5~3.6V");
if(ocr.ThreeFour) sb.AppendLine("\tDevice can work with supply 3.4~3.5V");
if(ocr.ThreeThree) sb.AppendLine("\tDevice can work with supply 3.3~3.4V");
if(ocr.ThreeTwo) sb.AppendLine("\tDevice can work with supply 3.2~3.3V");
if(ocr.ThreeOne) sb.AppendLine("\tDevice can work with supply 3.1~3.2V");
if(ocr.TwoNine) sb.AppendLine("\tDevice can work with supply 2.9~3.0V");
if(ocr.TwoEight) sb.AppendLine("\tDevice can work with supply 2.8~2.9V");
if(ocr.TwoSeven) sb.AppendLine("\tDevice can work with supply 2.7~2.8V");
if(ocr.OneEight) sb.AppendLine("\tDevice can switch to work with 1.8V supply");
if(ocr.LowPower) sb.AppendLine("\tDevice is in low power mode");
if(!ocr.PowerUp)
sb.AppendLine("\tDevice is powering up");
if(ocr.CCS)
sb.AppendLine("\tDevice is SDHC, SDXC or higher");
if(ocr.UHS)
sb.AppendLine("\tDevice is UHS-II or higher");
if(ocr.ThreeFive)
sb.AppendLine("\tDevice can work with supply 3.5~3.6V");
if(ocr.ThreeFour)
sb.AppendLine("\tDevice can work with supply 3.4~3.5V");
if(ocr.ThreeThree)
sb.AppendLine("\tDevice can work with supply 3.3~3.4V");
if(ocr.ThreeTwo)
sb.AppendLine("\tDevice can work with supply 3.2~3.3V");
if(ocr.ThreeOne)
sb.AppendLine("\tDevice can work with supply 3.1~3.2V");
if(ocr.TwoNine)
sb.AppendLine("\tDevice can work with supply 2.9~3.0V");
if(ocr.TwoEight)
sb.AppendLine("\tDevice can work with supply 2.8~2.9V");
if(ocr.TwoSeven)
sb.AppendLine("\tDevice can work with supply 2.7~2.8V");
if(ocr.OneEight)
sb.AppendLine("\tDevice can switch to work with 1.8V supply");
if(ocr.LowPower)
sb.AppendLine("\tDevice is in low power mode");
return sb.ToString();
}

View File

@@ -36,32 +36,30 @@ using System.Text;
namespace DiscImageChef.Decoders.SecureDigital
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "NotAccessedField.Global")]
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public class SCR
{
public byte Structure;
public byte Spec;
public bool DataStatusAfterErase;
public byte Security;
public byte BusWidth;
public bool Spec3;
public byte CommandSupport;
public bool DataStatusAfterErase;
public byte ExtendedSecurity;
public byte[] ManufacturerReserved;
public byte Security;
public byte Spec;
public bool Spec3;
public bool Spec4;
public byte SpecX;
public byte CommandSupport;
public byte[] ManufacturerReserved;
public byte Structure;
}
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "InconsistentNaming")]
public static partial class Decoders
{
public static SCR DecodeSCR(uint[] response)
{
if(response?.Length != 2) return null;
if(response?.Length != 2)
return null;
byte[] data = new byte[8];
@@ -75,22 +73,22 @@ namespace DiscImageChef.Decoders.SecureDigital
public static SCR DecodeSCR(byte[] response)
{
if(response?.Length != 8) return null;
if(response?.Length != 8)
return null;
SCR scr = new SCR
var scr = new SCR
{
Structure = (byte)((response[0] & 0xF0) >> 4),
Spec = (byte)(response[0] & 0x0F),
DataStatusAfterErase = (response[1] & 0x80) == 0x80,
Structure = (byte)((response[0] & 0xF0) >> 4), Spec = (byte)(response[0] & 0x0F),
DataStatusAfterErase = (response[1] & 0x80) == 0x80,
Security = (byte)((response[1] & 0x70) >> 4),
BusWidth = (byte)(response[1] & 0x0F),
Spec3 = (response[2] & 0x80) == 0x80,
ExtendedSecurity = (byte)((response[2] & 0x78) >> 3),
Spec4 = (response[2] & 0x04) == 0x04,
SpecX = (byte)(((response[2] & 0x03) << 2) + ((response[3] & 0xC0) >> 6)),
CommandSupport = (byte)(response[3] & 0x0F),
ManufacturerReserved = new byte[4]
CommandSupport = (byte)(response[3] & 0x0F), ManufacturerReserved = new byte[4]
};
Array.Copy(response, 4, scr.ManufacturerReserved, 0, 4);
return scr;
@@ -98,63 +96,98 @@ namespace DiscImageChef.Decoders.SecureDigital
public static string PrettifySCR(SCR scr)
{
if(scr == null) return null;
if(scr == null)
return null;
StringBuilder sb = new StringBuilder();
var sb = new StringBuilder();
sb.AppendLine("SecureDigital Device Configuration Register:");
if(scr.Structure != 0) sb.AppendFormat("\tUnknown register version {0}", scr.Structure).AppendLine();
if(scr.Structure != 0)
sb.AppendFormat("\tUnknown register version {0}", scr.Structure).AppendLine();
if(scr.Spec == 0 && scr.Spec3 == false && scr.Spec4 == false && scr.SpecX == 0)
if(scr.Spec == 0 &&
scr.Spec3 == false &&
scr.Spec4 == false &&
scr.SpecX == 0)
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 1.0x");
else if(scr.Spec == 1 && scr.Spec3 == false && scr.Spec4 == false && scr.SpecX == 0)
else if(scr.Spec == 1 &&
scr.Spec3 == false &&
scr.Spec4 == false &&
scr.SpecX == 0)
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 1.10");
else if(scr.Spec == 2 && scr.Spec3 == false && scr.Spec4 == false && scr.SpecX == 0)
else if(scr.Spec == 2 &&
scr.Spec3 == false &&
scr.Spec4 == false &&
scr.SpecX == 0)
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 2.00");
else if(scr.Spec == 2 && scr.Spec3 && scr.Spec4 == false && scr.SpecX == 0)
else if(scr.Spec == 2 &&
scr.Spec3 &&
scr.Spec4 == false &&
scr.SpecX == 0)
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 3.0x");
else if(scr.Spec == 2 && scr.Spec3 && scr.Spec4 && scr.SpecX == 0)
else if(scr.Spec == 2 &&
scr.Spec3 &&
scr.Spec4 &&
scr.SpecX == 0)
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 4.xx");
else if(scr.Spec == 2 && scr.Spec3 && scr.SpecX == 1)
else if(scr.Spec == 2 &&
scr.Spec3 &&
scr.SpecX == 1)
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 5.xx");
else
sb
.AppendFormat("\tDevice follows SecureDigital Physical Layer Specification with unknown version {0}.{1}.{2}.{3}",
sb.
AppendFormat("\tDevice follows SecureDigital Physical Layer Specification with unknown version {0}.{1}.{2}.{3}",
scr.Spec, scr.Spec3, scr.Spec4, scr.SpecX).AppendLine();
switch(scr.Security)
{
case 0:
sb.AppendLine("\tDevice does not support CPRM");
break;
case 1:
sb.AppendLine("\tDevice does not use CPRM");
break;
case 2:
sb.AppendLine("\tDevice uses CPRM according to specification version 1.01");
break;
case 3:
sb.AppendLine("\tDevice uses CPRM according to specification version 2.00");
break;
case 4:
sb.AppendLine("\tDevice uses CPRM according to specification version 3.xx");
break;
default:
sb.AppendFormat("\tDevice uses unknown CPRM specification with code {0}", scr.Security)
.AppendLine();
sb.AppendFormat("\tDevice uses unknown CPRM specification with code {0}", scr.Security).
AppendLine();
break;
}
if((scr.BusWidth & 0x01) == 0x01) sb.AppendLine("\tDevice supports 1-bit data bus");
if((scr.BusWidth & 0x04) == 0x04) sb.AppendLine("\tDevice supports 4-bit data bus");
if((scr.BusWidth & 0x01) == 0x01)
sb.AppendLine("\tDevice supports 1-bit data bus");
if(scr.ExtendedSecurity != 0) sb.AppendLine("\tDevice supports extended security");
if((scr.BusWidth & 0x04) == 0x04)
sb.AppendLine("\tDevice supports 4-bit data bus");
if(scr.ExtendedSecurity != 0)
sb.AppendLine("\tDevice supports extended security");
if((scr.CommandSupport & 0x08) == 0x08)
sb.AppendLine("\tDevice supports extension register multi-block commands");
if((scr.CommandSupport & 0x04) == 0x04)
sb.AppendLine("\tDevice supports extension register single-block commands");
if((scr.CommandSupport & 0x02) == 0x02) sb.AppendLine("\tDevice supports set block count command");
if((scr.CommandSupport & 0x01) == 0x01) sb.AppendLine("\tDevice supports speed class control command");
if((scr.CommandSupport & 0x02) == 0x02)
sb.AppendLine("\tDevice supports set block count command");
if((scr.CommandSupport & 0x01) == 0x01)
sb.AppendLine("\tDevice supports speed class control command");
return sb.ToString();
}

View File

@@ -38,11 +38,11 @@ namespace DiscImageChef.Decoders.SecureDigital
{
switch(sdVendorId)
{
case 0x02: return "Kingston";
case 0x03: return "Sandisk";
case 0x27: return "CnMemory";
case 0xAA: return "QEMU";
default: return $"Unknown manufacturer ID 0x{sdVendorId:X2}";
case 0x02: return"Kingston";
case 0x03: return"Sandisk";
case 0x27: return"CnMemory";
case 0xAA: return"QEMU";
default: return$"Unknown manufacturer ID 0x{sdVendorId:X2}";
}
}
}