2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-01-11 19:40:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : HL-DT-ST.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2016-01-11 19:40:58 +00:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : HL-DT-ST vendor commands.
|
2016-01-11 19:40:58 +00:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Contains vendor commands for HL-DT-ST SCSI devices.
|
2016-01-11 19:40:58 +00: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
|
2016-01-11 19:40:58 +00: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.
|
2016-01-11 19:40:58 +00: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/>.
|
2016-01-11 19:40:58 +00:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2016-01-11 19:40:58 +00:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2023-10-16 21:38:11 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
2022-03-07 07:36:44 +00:00
|
|
|
using Aaru.Console;
|
2023-10-16 21:38:11 +02:00
|
|
|
using Aaru.Decoders.DVD;
|
|
|
|
|
using Aaru.Helpers;
|
2022-03-07 07:36:44 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Devices;
|
|
|
|
|
|
2022-03-26 18:31:04 +00:00
|
|
|
public partial class Device
|
2016-01-11 19:40:58 +00:00
|
|
|
{
|
2023-10-16 21:38:11 +02:00
|
|
|
readonly Sector _decoding = new();
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Reads a "raw" sector from DVD on HL-DT-ST drives.</summary>
|
|
|
|
|
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
|
|
|
|
|
/// <param name="buffer">Buffer where the HL-DT-ST READ DVD (RAW) response will be stored</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout in seconds.</param>
|
|
|
|
|
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
|
|
|
|
|
/// <param name="lba">Start block address.</param>
|
|
|
|
|
/// <param name="transferLength">How many blocks to read.</param>
|
2022-03-07 07:36:44 +00:00
|
|
|
public bool HlDtStReadRawDvd(out byte[] buffer, out byte[] senseBuffer, uint lba, uint transferLength, uint timeout,
|
|
|
|
|
out double duration)
|
2016-01-11 19:40:58 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
senseBuffer = new byte[64];
|
2023-10-03 23:12:01 +01:00
|
|
|
var cdb = new byte[12];
|
2022-03-06 13:29:38 +00:00
|
|
|
buffer = new byte[2064 * transferLength];
|
2016-01-11 19:40:58 +00:00
|
|
|
|
2023-10-16 21:38:11 +02:00
|
|
|
uint cacheDataOffset = 0x80000000 + (lba % 96 * 2064);
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.HlDtStVendor;
|
|
|
|
|
cdb[1] = 0x48;
|
|
|
|
|
cdb[2] = 0x49;
|
|
|
|
|
cdb[3] = 0x54;
|
|
|
|
|
cdb[4] = 0x01;
|
2023-10-16 21:38:11 +02:00
|
|
|
cdb[6] = (byte)((cacheDataOffset & 0xFF000000) >> 24);
|
|
|
|
|
cdb[7] = (byte)((cacheDataOffset & 0xFF0000) >> 16);
|
|
|
|
|
cdb[8] = (byte)((cacheDataOffset & 0xFF00) >> 8);
|
|
|
|
|
cdb[9] = (byte)(cacheDataOffset & 0xFF);
|
2022-03-06 13:29:38 +00:00
|
|
|
cdb[10] = (byte)((buffer.Length & 0xFF00) >> 8);
|
|
|
|
|
cdb[11] = (byte)(buffer.Length & 0xFF);
|
2016-01-11 19:40:58 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
|
|
|
|
out bool sense);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Error = LastError != 0;
|
2016-01-11 19:40:58 +00:00
|
|
|
|
2023-10-03 17:28:12 +01:00
|
|
|
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME, Localization.HL_DT_ST_READ_DVD_RAW_took_0_ms, duration);
|
2016-01-11 19:40:58 +00:00
|
|
|
|
2023-10-16 21:38:11 +02:00
|
|
|
if(!CheckSectorNumber(buffer, lba, transferLength))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if(_decoding.Scramble(buffer, transferLength, out byte[] scrambledBuffer) != ErrorNumber.NoError)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
buffer = scrambledBuffer;
|
2022-03-06 13:29:38 +00:00
|
|
|
return sense;
|
2016-01-11 19:40:58 +00:00
|
|
|
}
|
2023-10-16 21:38:11 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Makes sure the data's sector number is the one expected.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="buffer">Data buffer</param>
|
|
|
|
|
/// <param name="firstLba">First consecutive LBA of the buffer</param>
|
|
|
|
|
/// <param name="transferLength">How many blocks to in buffer</param>
|
|
|
|
|
/// <returns><c>false</c> if any sector is not matching expected value, else <c>true</c></returns>
|
|
|
|
|
static bool CheckSectorNumber(IReadOnlyList<byte> buffer, uint firstLba, uint transferLength)
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0; i < transferLength; i++)
|
|
|
|
|
{
|
|
|
|
|
byte[] sectorBuffer =
|
|
|
|
|
{
|
|
|
|
|
0x0, buffer[1 + (2064 * i)], buffer[2 + (2064 * i)], buffer[3 + (2064 * i)]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uint sectorNumber = BigEndianBitConverter.ToUInt32(sectorBuffer, 0);
|
|
|
|
|
|
|
|
|
|
if(sectorNumber != firstLba + i + 0x30000)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|