Better decoding of SecureDigital Card Register.

This commit is contained in:
2020-12-12 20:50:52 +00:00
parent 5b9b6fab59
commit 027f9d4dc7

View File

@@ -40,17 +40,30 @@ namespace Aaru.Decoders.SecureDigital
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")] SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public class SCR public class SCR
{ {
public byte BusWidth; public BusWidth BusWidth;
public byte CommandSupport; public CommandSupport CommandSupport;
public bool DataStatusAfterErase; public bool DataStatusAfterErase;
public byte ExtendedSecurity; public byte ExtendedSecurity;
public byte[] ManufacturerReserved; public byte[] ManufacturerReserved;
public byte Security; public byte Security;
public byte Spec; public byte Spec;
public bool Spec3; public bool Spec3;
public bool Spec4; public bool Spec4;
public byte SpecX; public byte SpecX;
public byte Structure; public byte Structure;
}
[Flags]
public enum BusWidth : byte
{
OneBit = 1 << 0, FourBit = 1 << 2
}
[Flags]
public enum CommandSupport : byte
{
SpeedClassControl = 1 << 0, SetBlockCount = 1 << 1, ExtensionRegisterSingleBlock = 1 << 2,
ExtensionRegisterMultiBlock = 1 << 3
} }
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "InconsistentNaming")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "InconsistentNaming")]
@@ -82,12 +95,12 @@ namespace Aaru.Decoders.SecureDigital
Spec = (byte)(response[0] & 0x0F), Spec = (byte)(response[0] & 0x0F),
DataStatusAfterErase = (response[1] & 0x80) == 0x80, DataStatusAfterErase = (response[1] & 0x80) == 0x80,
Security = (byte)((response[1] & 0x70) >> 4), Security = (byte)((response[1] & 0x70) >> 4),
BusWidth = (byte)(response[1] & 0x0F), BusWidth = (BusWidth)(response[1] & 0x0F),
Spec3 = (response[2] & 0x80) == 0x80, Spec3 = (response[2] & 0x80) == 0x80,
ExtendedSecurity = (byte)((response[2] & 0x78) >> 3), ExtendedSecurity = (byte)((response[2] & 0x78) >> 3),
Spec4 = (response[2] & 0x04) == 0x04, Spec4 = (response[2] & 0x04) == 0x04,
SpecX = (byte)(((response[2] & 0x03) << 2) + ((response[3] & 0xC0) >> 6)), SpecX = (byte)(((response[2] & 0x03) << 2) + ((response[3] & 0xC0) >> 6)),
CommandSupport = (byte)(response[3] & 0x0F), CommandSupport = (CommandSupport)(response[3] & 0x0F),
ManufacturerReserved = new byte[4] ManufacturerReserved = new byte[4]
}; };
@@ -107,39 +120,57 @@ namespace Aaru.Decoders.SecureDigital
if(scr.Structure != 0) if(scr.Structure != 0)
sb.AppendFormat("\tUnknown register version {0}", scr.Structure).AppendLine(); sb.AppendFormat("\tUnknown register version {0}", scr.Structure).AppendLine();
if(scr.Spec == 0 && switch(scr.Spec)
scr.Spec3 == false && {
scr.Spec4 == false && case 0 when scr.Spec3 == false && scr.Spec4 == false && scr.SpecX == 0:
scr.SpecX == 0) sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 1.0x");
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 1.0x");
else if(scr.Spec == 1 && break;
scr.Spec3 == false && case 1 when scr.Spec3 == false && scr.Spec4 == false && scr.SpecX == 0:
scr.Spec4 == false && sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 1.10");
scr.SpecX == 0)
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 1.10"); break;
else if(scr.Spec == 2 && case 2 when scr.Spec3 == false && scr.Spec4 == false && scr.SpecX == 0:
scr.Spec3 == false && sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 2.00");
scr.Spec4 == false &&
scr.SpecX == 0) break;
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 2.00"); case 2 when scr.Spec3 && scr.Spec4 == false && scr.SpecX == 0:
else if(scr.Spec == 2 && sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 3.0x");
scr.Spec3 &&
scr.Spec4 == false && break;
scr.SpecX == 0) case 2 when scr.Spec3 && scr.Spec4 && scr.SpecX == 0:
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 3.0x"); sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 4.xx");
else if(scr.Spec == 2 &&
scr.Spec3 && break;
scr.Spec4 && case 2 when scr.Spec3:
scr.SpecX == 0) switch(scr.SpecX)
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 4.xx"); {
else if(scr.Spec == 2 && case 1:
scr.Spec3 && sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 5.xx");
scr.SpecX == 1)
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 5.xx"); break;
else case 2:
sb. sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 6.xx");
AppendFormat("\tDevice follows SecureDigital Physical Layer Specification with unknown version {0}.{1}.{2}.{3}",
scr.Spec, scr.Spec3, scr.Spec4, scr.SpecX).AppendLine(); break;
case 3:
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 7.xx");
break;
case 4:
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 8.xx");
break;
}
break;
default:
sb.
AppendFormat("\tDevice follows SecureDigital Physical Layer Specification with unknown version {0}.{1}.{2}.{3}",
scr.Spec, scr.Spec3, scr.Spec4, scr.SpecX).AppendLine();
break;
}
switch(scr.Security) switch(scr.Security)
{ {
@@ -170,25 +201,25 @@ namespace Aaru.Decoders.SecureDigital
break; break;
} }
if((scr.BusWidth & 0x01) == 0x01) if(scr.BusWidth.HasFlag(BusWidth.OneBit))
sb.AppendLine("\tDevice supports 1-bit data bus"); sb.AppendLine("\tDevice supports 1-bit data bus");
if((scr.BusWidth & 0x04) == 0x04) if(scr.BusWidth.HasFlag(BusWidth.FourBit))
sb.AppendLine("\tDevice supports 4-bit data bus"); sb.AppendLine("\tDevice supports 4-bit data bus");
if(scr.ExtendedSecurity != 0) if(scr.ExtendedSecurity != 0)
sb.AppendLine("\tDevice supports extended security"); sb.AppendLine("\tDevice supports extended security");
if((scr.CommandSupport & 0x08) == 0x08) if(scr.CommandSupport.HasFlag(CommandSupport.ExtensionRegisterMultiBlock))
sb.AppendLine("\tDevice supports extension register multi-block commands"); sb.AppendLine("\tDevice supports extension register multi-block commands");
if((scr.CommandSupport & 0x04) == 0x04) if(scr.CommandSupport.HasFlag(CommandSupport.ExtensionRegisterSingleBlock))
sb.AppendLine("\tDevice supports extension register single-block commands"); sb.AppendLine("\tDevice supports extension register single-block commands");
if((scr.CommandSupport & 0x02) == 0x02) if(scr.CommandSupport.HasFlag(CommandSupport.SetBlockCount))
sb.AppendLine("\tDevice supports set block count command"); sb.AppendLine("\tDevice supports set block count command");
if((scr.CommandSupport & 0x01) == 0x01) if(scr.CommandSupport.HasFlag(CommandSupport.SpeedClassControl))
sb.AppendLine("\tDevice supports speed class control command"); sb.AppendLine("\tDevice supports speed class control command");
return sb.ToString(); return sb.ToString();