2015-10-19 04:32:16 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : EVPD.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-19 04:32:16 +01:00
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Component : Device structures decoders.
|
2015-10-19 04:32:16 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Decodes SCSI EVPDs.
|
2015-10-19 04:32:16 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
2015-10-19 04:32:16 +01:00
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
// Lesser General Public License for more details.
|
2015-10-19 04:32:16 +01:00
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2015-10-19 04:32:16 +01:00
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Copyright © 2011-2016 Natalia Portillo
|
2015-10-19 04:32:16 +01:00
|
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
|
2015-10-19 04:32:16 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Decoders.SCSI
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class EVPD
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Decodes VPD page 0x00: Supported VPD pages
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>A byte array containing all supported VPD pages.</returns>
|
|
|
|
|
|
/// <param name="page">Page 0x00.</param>
|
|
|
|
|
|
public static byte[] DecodePage00(byte[] page)
|
|
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(page == null)
|
2015-10-19 04:32:16 +01:00
|
|
|
|
return null;
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
|
|
|
|
|
if(page[1] != 0)
|
2015-10-19 04:32:16 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(page.Length != page[3] + 4)
|
2015-10-19 04:32:16 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] decoded = new byte[page.Length - 4];
|
|
|
|
|
|
|
|
|
|
|
|
Array.Copy(page, 4, decoded, 0, page.Length - 4);
|
|
|
|
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Decides VPD pages 0x01 to 0x7F: ASCII Information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>An ASCII string with the contents of the page.</returns>
|
|
|
|
|
|
/// <param name="page">Page 0x01-0x7F.</param>
|
|
|
|
|
|
public static string DecodeASCIIPage(byte[] page)
|
|
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(page == null)
|
2015-10-19 04:32:16 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(page[1] == 0 || page[1] > 0x7F)
|
2015-10-19 04:32:16 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(page.Length != page[3] + 4)
|
2015-10-19 04:32:16 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] ascii = new byte[page[4]];
|
|
|
|
|
|
|
|
|
|
|
|
Array.Copy(page, 5, ascii, 0, page[4]);
|
|
|
|
|
|
|
|
|
|
|
|
return StringHandlers.CToString(ascii);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Decodes VPD page 0x80: Unit Serial Number
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>The unit serial number.</returns>
|
|
|
|
|
|
/// <param name="page">Page 0x80.</param>
|
|
|
|
|
|
public static string DecodePage80(byte[] page)
|
|
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(page == null)
|
2015-10-19 04:32:16 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(page[1] != 0x80)
|
2015-10-19 04:32:16 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
|
if(page.Length != page[3] + 4)
|
2015-10-19 04:32:16 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] ascii = new byte[page.Length - 4];
|
|
|
|
|
|
|
|
|
|
|
|
Array.Copy(page, 4, ascii, 0, page.Length - 4);
|
|
|
|
|
|
|
|
|
|
|
|
return StringHandlers.CToString(ascii);
|
|
|
|
|
|
}
|
2016-10-13 04:01:39 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Decodes VPD page 0x82: ASCII implemented operating definition
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>ASCII implemented operating definition.</returns>
|
|
|
|
|
|
/// <param name="page">Page 0x82.</param>
|
|
|
|
|
|
public static string DecodePage82(byte[] page)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(page == null)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
if(page[1] != 0x82)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
if(page.Length != page[3] + 4)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] ascii = new byte[page.Length - 4];
|
|
|
|
|
|
|
|
|
|
|
|
Array.Copy(page, 4, ascii, 0, page.Length - 4);
|
|
|
|
|
|
|
|
|
|
|
|
return StringHandlers.CToString(ascii);
|
|
|
|
|
|
}
|
2015-10-19 04:32:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|