mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
General cleanup and refactor.
This commit is contained in:
112
SCSI/EVPD.cs
112
SCSI/EVPD.cs
@@ -30,6 +30,8 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace Aaru.Decoders.SCSI;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -40,8 +42,6 @@ using Aaru.CommonTypes.Structs.Devices.ATA;
|
||||
using Aaru.CommonTypes.Structs.Devices.SCSI;
|
||||
using Aaru.Helpers;
|
||||
|
||||
namespace Aaru.Decoders.SCSI;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
|
||||
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global"),
|
||||
SuppressMessage("ReSharper", "UnassignedField.Global")]
|
||||
@@ -58,7 +58,7 @@ public static class EVPD
|
||||
if(page.Length != page[3] + 4)
|
||||
return null;
|
||||
|
||||
byte[] decoded = new byte[page.Length - 4];
|
||||
var decoded = new byte[page.Length - 4];
|
||||
|
||||
Array.Copy(page, 4, decoded, 0, page.Length - 4);
|
||||
|
||||
@@ -80,7 +80,7 @@ public static class EVPD
|
||||
if(page.Length != page[3] + 4)
|
||||
return null;
|
||||
|
||||
byte[] ascii = new byte[page[4]];
|
||||
var ascii = new byte[page[4]];
|
||||
|
||||
Array.Copy(page, 5, ascii, 0, page[4]);
|
||||
|
||||
@@ -98,11 +98,11 @@ public static class EVPD
|
||||
if(page.Length != page[3] + 4)
|
||||
return null;
|
||||
|
||||
byte[] ascii = new byte[page.Length - 4];
|
||||
var ascii = new byte[page.Length - 4];
|
||||
|
||||
Array.Copy(page, 4, ascii, 0, page.Length - 4);
|
||||
|
||||
for(int i = 0; i < ascii.Length - 1; i++)
|
||||
for(var i = 0; i < ascii.Length - 1; i++)
|
||||
if(ascii[i] < 0x20)
|
||||
return null;
|
||||
|
||||
@@ -120,7 +120,7 @@ public static class EVPD
|
||||
if(page.Length != page[3] + 4)
|
||||
return null;
|
||||
|
||||
byte[] ascii = new byte[page.Length - 4];
|
||||
var ascii = new byte[page.Length - 4];
|
||||
|
||||
Array.Copy(page, 4, ascii, 0, page.Length - 4);
|
||||
|
||||
@@ -136,7 +136,7 @@ public static class EVPD
|
||||
if(page.Length != page[3] + 4)
|
||||
return null;
|
||||
|
||||
byte[] ascii = new byte[page.Length - 4];
|
||||
var ascii = new byte[page.Length - 4];
|
||||
|
||||
Array.Copy(page, 4, ascii, 0, page.Length - 4);
|
||||
|
||||
@@ -153,7 +153,7 @@ public static class EVPD
|
||||
if(page.Length != 12)
|
||||
return 0;
|
||||
|
||||
byte[] bitmap = new byte[8];
|
||||
var bitmap = new byte[8];
|
||||
|
||||
Array.Copy(page, 4, bitmap, 0, 8);
|
||||
|
||||
@@ -170,7 +170,7 @@ public static class EVPD
|
||||
if(page.Length != page[3] + 4)
|
||||
return null;
|
||||
|
||||
byte[] ascii = new byte[page.Length - 4];
|
||||
var ascii = new byte[page.Length - 4];
|
||||
|
||||
Array.Copy(page, 4, ascii, 0, page.Length - 4);
|
||||
|
||||
@@ -187,8 +187,8 @@ public static class EVPD
|
||||
if(page.Length != page[3] + 4)
|
||||
return null;
|
||||
|
||||
byte[] element = new byte[page.Length - 4];
|
||||
var sb = new StringBuilder();
|
||||
var element = new byte[page.Length - 4];
|
||||
var sb = new StringBuilder();
|
||||
|
||||
foreach(byte b in element)
|
||||
sb.AppendFormat("{0:X2}", b);
|
||||
@@ -237,8 +237,8 @@ public static class EVPD
|
||||
Default = (ScsiDefinitions)(pageResponse[5] & 0x7F)
|
||||
};
|
||||
|
||||
int position = 6;
|
||||
List<ScsiDefinitions> definitions = new List<ScsiDefinitions>();
|
||||
var position = 6;
|
||||
var definitions = new List<ScsiDefinitions>();
|
||||
|
||||
while(position < pageResponse.Length)
|
||||
{
|
||||
@@ -394,8 +394,8 @@ public static class EVPD
|
||||
PageLength = (byte)(pageResponse[3] + 4)
|
||||
};
|
||||
|
||||
int position = 4;
|
||||
List<IdentificatonDescriptor> descriptors = new List<IdentificatonDescriptor>();
|
||||
var position = 4;
|
||||
var descriptors = new List<IdentificatonDescriptor>();
|
||||
|
||||
while(position < pageResponse.Length)
|
||||
{
|
||||
@@ -604,7 +604,7 @@ public static class EVPD
|
||||
{
|
||||
sb.AppendFormat("\tIEEE EUI-64: {0:X2}", descriptor.Binary[0]);
|
||||
|
||||
for(int i = 1; i < descriptor.Binary.Length; i++)
|
||||
for(var i = 1; i < descriptor.Binary.Length; i++)
|
||||
sb.AppendFormat(":{0:X2}", descriptor.Binary[i]);
|
||||
|
||||
sb.AppendLine();
|
||||
@@ -619,7 +619,7 @@ public static class EVPD
|
||||
{
|
||||
sb.AppendFormat("\tNAA: {0:X2}", descriptor.Binary[0]);
|
||||
|
||||
for(int i = 1; i < descriptor.Binary.Length; i++)
|
||||
for(var i = 1; i < descriptor.Binary.Length; i++)
|
||||
sb.AppendFormat(":{0:X2}", descriptor.Binary[i]);
|
||||
|
||||
sb.AppendLine();
|
||||
@@ -661,7 +661,7 @@ public static class EVPD
|
||||
{
|
||||
sb.AppendFormat("\tMD5 logical unit identifier: {0:x2}", descriptor.Binary[0]);
|
||||
|
||||
for(int i = 1; i < descriptor.Binary.Length; i++)
|
||||
for(var i = 1; i < descriptor.Binary.Length; i++)
|
||||
sb.AppendFormat("{0:x2}", descriptor.Binary[i]);
|
||||
|
||||
sb.AppendLine();
|
||||
@@ -753,10 +753,8 @@ public static class EVPD
|
||||
|
||||
break;
|
||||
case ProtocolIdentifiers.SSA:
|
||||
sb.
|
||||
AppendFormat("\tProtocol (SSA) specific descriptor with unknown format (hex): {0}",
|
||||
PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40)).
|
||||
AppendLine();
|
||||
sb.AppendFormat("\tProtocol (SSA) specific descriptor with unknown format (hex): {0}",
|
||||
PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40)).AppendLine();
|
||||
|
||||
break;
|
||||
case ProtocolIdentifiers.SCSIe:
|
||||
@@ -765,9 +763,8 @@ public static class EVPD
|
||||
|
||||
break;
|
||||
case ProtocolIdentifiers.UAS:
|
||||
sb.
|
||||
AppendFormat("\tProtocol (UAS) specific descriptor: USB address {0} interface {1}",
|
||||
descriptor.Binary[0] & 0x7F, descriptor.Binary[2]).AppendLine();
|
||||
sb.AppendFormat("\tProtocol (UAS) specific descriptor: USB address {0} interface {1}",
|
||||
descriptor.Binary[0] & 0x7F, descriptor.Binary[2]).AppendLine();
|
||||
|
||||
break;
|
||||
default:
|
||||
@@ -798,10 +795,9 @@ public static class EVPD
|
||||
|
||||
break;
|
||||
default:
|
||||
sb.
|
||||
AppendFormat("Inquiry descriptor type {2} contains unknown kind {1} of data (hex): {0}",
|
||||
PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40),
|
||||
(byte)descriptor.CodeSet, (byte)descriptor.Type).AppendLine();
|
||||
sb.AppendFormat("Inquiry descriptor type {2} contains unknown kind {1} of data (hex): {0}",
|
||||
PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40),
|
||||
(byte)descriptor.CodeSet, (byte)descriptor.Type).AppendLine();
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -854,8 +850,8 @@ public static class EVPD
|
||||
PageLength = (byte)(pageResponse[3] + 4)
|
||||
};
|
||||
|
||||
int position = 4;
|
||||
List<SoftwareIdentifier> identifiers = new List<SoftwareIdentifier>();
|
||||
var position = 4;
|
||||
var identifiers = new List<SoftwareIdentifier>();
|
||||
|
||||
while(position < pageResponse.Length)
|
||||
{
|
||||
@@ -897,7 +893,7 @@ public static class EVPD
|
||||
{
|
||||
sb.AppendFormat("\t{0:X2}", identifier.Identifier[0]);
|
||||
|
||||
for(int i = 1; i < identifier.Identifier.Length; i++)
|
||||
for(var i = 1; i < identifier.Identifier.Length; i++)
|
||||
sb.AppendFormat(":{0:X2}", identifier.Identifier[i]);
|
||||
|
||||
sb.AppendLine();
|
||||
@@ -910,9 +906,14 @@ public static class EVPD
|
||||
#region EVPD Page 0x85: Management Network Addresses page
|
||||
public enum NetworkServiceTypes : byte
|
||||
{
|
||||
Unspecified = 0, StorageConf = 1, Diagnostics = 2,
|
||||
Status = 3, Logging = 4, CodeDownload = 5,
|
||||
CopyService = 6, Administrative = 7
|
||||
Unspecified = 0,
|
||||
StorageConf = 1,
|
||||
Diagnostics = 2,
|
||||
Status = 3,
|
||||
Logging = 4,
|
||||
CodeDownload = 5,
|
||||
CopyService = 6,
|
||||
Administrative = 7
|
||||
}
|
||||
|
||||
public struct NetworkDescriptor
|
||||
@@ -960,8 +961,8 @@ public static class EVPD
|
||||
PageLength = (ushort)((pageResponse[2] << 8) + pageResponse[3] + 4)
|
||||
};
|
||||
|
||||
int position = 4;
|
||||
List<NetworkDescriptor> descriptors = new List<NetworkDescriptor>();
|
||||
var position = 4;
|
||||
var descriptors = new List<NetworkDescriptor>();
|
||||
|
||||
while(position < pageResponse.Length)
|
||||
{
|
||||
@@ -1069,9 +1070,8 @@ public static class EVPD
|
||||
|
||||
break;
|
||||
default:
|
||||
sb.AppendFormat("Address of unknown type {1}: {0}",
|
||||
StringHandlers.CToString(descriptor.Address), (byte)descriptor.Type).
|
||||
AppendLine();
|
||||
sb.AppendFormat("Address of unknown type {1}: {0}", StringHandlers.CToString(descriptor.Address),
|
||||
(byte)descriptor.Type).AppendLine();
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -1322,8 +1322,8 @@ public static class EVPD
|
||||
sb.AppendLine("Device supports vendor specific activation for new microcode");
|
||||
|
||||
if(page.ExtendedTestMinutes > 0)
|
||||
sb.AppendFormat("Extended self-test takes {0} to complete",
|
||||
TimeSpan.FromMinutes(page.ExtendedTestMinutes)).AppendLine();
|
||||
sb.AppendFormat("Extended self-test takes {0} to complete", TimeSpan.FromMinutes(page.ExtendedTestMinutes)).
|
||||
AppendLine();
|
||||
|
||||
if(page.MaximumSenseLength > 0)
|
||||
sb.AppendFormat("Device supports a maximum of {0} bytes for sense data", page.MaximumSenseLength).
|
||||
@@ -1406,11 +1406,10 @@ public static class EVPD
|
||||
sb.AppendLine("SCSI to ATA Translation Layer Data:");
|
||||
|
||||
sb.AppendFormat("\tTranslation layer vendor: {0}",
|
||||
VendorString.Prettify(StringHandlers.CToString(page.VendorIdentification).Trim())).
|
||||
AppendLine();
|
||||
VendorString.Prettify(StringHandlers.CToString(page.VendorIdentification).Trim())).AppendLine();
|
||||
|
||||
sb.AppendFormat("\tTranslation layer name: {0}",
|
||||
StringHandlers.CToString(page.ProductIdentification).Trim()).AppendLine();
|
||||
sb.AppendFormat("\tTranslation layer name: {0}", StringHandlers.CToString(page.ProductIdentification).Trim()).
|
||||
AppendLine();
|
||||
|
||||
sb.AppendFormat("\tTranslation layer release level: {0}",
|
||||
StringHandlers.CToString(page.ProductRevisionLevel).Trim()).AppendLine();
|
||||
@@ -1686,13 +1685,12 @@ public static class EVPD
|
||||
|
||||
break;
|
||||
case 0xC5:
|
||||
sb.AppendFormat("\tBoard Serial Number: {0}", StringHandlers.CToString(page.SerialNumber)).
|
||||
AppendLine();
|
||||
sb.AppendFormat("\tBoard Serial Number: {0}", StringHandlers.CToString(page.SerialNumber)).AppendLine();
|
||||
|
||||
break;
|
||||
case 0xC6:
|
||||
sb.AppendFormat("\tBase Mechanical Serial Number: {0}",
|
||||
StringHandlers.CToString(page.SerialNumber)).AppendLine();
|
||||
sb.AppendFormat("\tBase Mechanical Serial Number: {0}", StringHandlers.CToString(page.SerialNumber)).
|
||||
AppendLine();
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -1781,7 +1779,7 @@ public static class EVPD
|
||||
CartridgeSerialNumber = new byte[32]
|
||||
};
|
||||
|
||||
byte[] buf = new byte[8];
|
||||
var buf = new byte[8];
|
||||
Array.Copy(pageResponse, 24, buf, 0, 8);
|
||||
decoded.InitiatorID = BitConverter.ToUInt64(buf.Reverse().ToArray(), 0);
|
||||
Array.Copy(pageResponse, 32, decoded.CartridgeSerialNumber, 0, 32);
|
||||
@@ -2068,8 +2066,7 @@ public static class EVPD
|
||||
sb.AppendFormat("\tManufacturing serial number: {0}", StringHandlers.CToString(page.ManufacturingSerial)).
|
||||
AppendLine();
|
||||
|
||||
sb.AppendFormat("\tReported serial number: {0}", StringHandlers.CToString(page.ReportedSerial)).
|
||||
AppendLine();
|
||||
sb.AppendFormat("\tReported serial number: {0}", StringHandlers.CToString(page.ReportedSerial)).AppendLine();
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
@@ -2198,10 +2195,9 @@ public static class EVPD
|
||||
if(pageResponse[4] != pageResponse[3] - 1)
|
||||
return null;
|
||||
|
||||
List<byte> array = new List<byte>();
|
||||
var array = new List<byte>();
|
||||
|
||||
const string fwRegExStr =
|
||||
@"Firmware Rev\s+=\s+(?<fw>\d+\.\d+)\s+Build date\s+=\s+(?<date>(\w|\d|\s*.)*)\s*$";
|
||||
const string fwRegExStr = @"Firmware Rev\s+=\s+(?<fw>\d+\.\d+)\s+Build date\s+=\s+(?<date>(\w|\d|\s*.)*)\s*$";
|
||||
|
||||
const string fwcRegExStr = @"FW_CONF\s+=\s+(?<value>0x[0-9A-Fa-f]{8})\s*$";
|
||||
const string servoRegExStr = @"Servo\s+Rev\s+=\s+(?<version>\d+\.\d+)\s*$";
|
||||
@@ -2209,7 +2205,7 @@ public static class EVPD
|
||||
var fwcRegEx = new Regex(fwcRegExStr);
|
||||
var servoRegEx = new Regex(servoRegExStr);
|
||||
|
||||
for(int pos = 5; pos < pageResponse.Length; pos++)
|
||||
for(var pos = 5; pos < pageResponse.Length; pos++)
|
||||
if(pageResponse[pos] == 0x00)
|
||||
{
|
||||
string str = StringHandlers.CToString(array.ToArray());
|
||||
|
||||
Reference in New Issue
Block a user