// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Plextor.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Plextor vendor commands
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Description
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using DiscImageChef.Console;
namespace DiscImageChef.Devices
{
public partial class Device
{
///
/// Sends the Plextor READ CD-DA command
///
/// true if the command failed and contains the sense buffer.
/// Buffer where the Plextor READ CD-DA response will be stored
/// Sense buffer.
/// Timeout in seconds.
/// Duration in milliseconds it took for the device to execute the command.
/// Start block address.
/// How many blocks to read.
/// Block size.
/// Subchannel selection.
public bool PlextorReadCdDa(out byte[] buffer, out byte[] senseBuffer, uint lba, uint blockSize, uint transferLength, PlextorSubchannel subchannel, uint timeout, out double duration)
{
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.ReadCdDa;
cdb[2] = (byte)((lba & 0xFF000000) >> 24);
cdb[3] = (byte)((lba & 0xFF0000) >> 16);
cdb[4] = (byte)((lba & 0xFF00) >> 8);
cdb[5] = (byte)(lba & 0xFF);
cdb[6] = (byte)((transferLength & 0xFF000000) >> 24);
cdb[7] = (byte)((transferLength & 0xFF0000) >> 16);
cdb[8] = (byte)((transferLength & 0xFF00) >> 8);
cdb[9] = (byte)(transferLength & 0xFF);
cdb[10] = (byte)subchannel;
buffer = new byte[blockSize * transferLength];
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "READ CD-DA took {0} ms.", duration);
return sense;
}
///
/// Reads a "raw" sector from DVD on Plextor drives. Does it reading drive's cache.
///
/// true if the command failed and contains the sense buffer.
/// Buffer where the Plextor READ DVD (RAW) response will be stored
/// Sense buffer.
/// Timeout in seconds.
/// Duration in milliseconds it took for the device to execute the command.
/// Start block address.
/// How many blocks to read.
public bool PlextorReadRawDvd(out byte[] buffer, out byte[] senseBuffer, uint lba, uint transferLength, uint timeout, out double duration)
{
senseBuffer = new byte[32];
byte[] cdb = new byte[10];
buffer = new byte[2064 * transferLength];
bool sense;
cdb[0] = (byte)ScsiCommands.ReadBuffer;
cdb[1] = 0x02;
cdb[3] = (byte)((lba & 0xFF0000) >> 16);
cdb[4] = (byte)((lba & 0xFF00) >> 8);
cdb[5] = (byte)(lba & 0xFF);
cdb[3] = (byte)((buffer.Length & 0xFF0000) >> 16);
cdb[4] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[5] = (byte)(buffer.Length & 0xFF);
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "Plextor READ DVD (RAW) took {0} ms.", duration);
return sense;
}
///
/// Reads the statistics EEPROM from Plextor CD recorders
///
/// true, if EEPROM is correctly read, false otherwise.
/// Buffer.
/// Sense buffer.
/// Timeout.
/// Duration.
public bool PlextorReadEepromCDR(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
{
buffer = new byte[256];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.Plextor_ReadEeprom;
cdb[8] = 1;
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR READ EEPROM took {0} ms.", duration);
return sense;
}
///
/// Reads the statistics EEPROM from Plextor PX-708 and PX-712 recorders
///
/// true, if EEPROM is correctly read, false otherwise.
/// Buffer.
/// Sense buffer.
/// Timeout.
/// Duration.
public bool PlextorReadEeprom(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
{
buffer = new byte[512];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.Plextor_ReadEeprom;
cdb[8] = 2;
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR READ EEPROM took {0} ms.", duration);
return sense;
}
///
/// Reads a block from the statistics EEPROM from Plextor DVD recorders
///
/// true, if EEPROM is correctly read, false otherwise.
/// Buffer.
/// Sense buffer.
/// EEPROM block to read
/// How many bytes are in the EEPROM block
/// Timeout.
/// Duration.
public bool PlextorReadEepromBlock(out byte[] buffer, out byte[] senseBuffer, byte block, ushort blockSize, uint timeout, out double duration)
{
buffer = new byte[blockSize];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.Plextor_ReadEeprom;
cdb[1] = 1;
cdb[7] = block;
cdb[8] = (byte)((blockSize & 0xFF00) >> 8);
cdb[9] = (byte)(blockSize & 0xFF);
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR READ EEPROM took {0} ms.", duration);
return sense;
}
///
/// Gets speeds set by Plextor PoweRec
///
/// true, if speeds were got correctly, false otherwise.
/// Sense buffer.
/// Selected write speed.
/// Max speed for currently inserted media.
/// Last actual speed.
/// Timeout.
/// Duration.
public bool PlextorGetSpeeds(out byte[] senseBuffer, out ushort selected, out ushort max, out ushort last, uint timeout, out double duration)
{
byte[] buf = new byte[10];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
selected = 0;
max = 0;
last = 0;
cdb[0] = (byte)ScsiCommands.Plextor_PoweRec;
cdb[9] = (byte)buf.Length;
lastError = SendScsiCommand(cdb, ref buf, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR POWEREC GET SPEEDS took {0} ms.", duration);
if(!sense && !error)
{
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
selected = BigEndianBitConverter.ToUInt16(buf, 4);
max = BigEndianBitConverter.ToUInt16(buf, 6);
last = BigEndianBitConverter.ToUInt16(buf, 8);
}
return sense;
}
///
/// Gets the Plextor PoweRec status
///
/// true, if PoweRec is supported, false otherwise.
/// Sense buffer.
/// PoweRec is enabled.
/// PoweRec recommended speed.
/// Timeout.
/// Duration.
public bool PlextorGetPoweRec(out byte[] senseBuffer, out bool enabled, out ushort speed, uint timeout, out double duration)
{
byte[] buf = new byte[8];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
enabled = false;
speed = 0;
cdb[0] = (byte)ScsiCommands.Plextor_Extend2;
cdb[1] = (byte)PlextorSubCommands.GetMode;
cdb[9] = (byte)buf.Length;
lastError = SendScsiCommand(cdb, ref buf, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR POWEREC GET SPEEDS took {0} ms.", duration);
if(!sense && !error)
{
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
enabled = buf[2] != 0;
speed = BigEndianBitConverter.ToUInt16(buf, 4);
}
return sense;
}
///
/// Gets the Plextor SilentMode status
///
/// true, if SilentMode is supported, false otherwise.
/// Buffer.
/// Sense buffer.
/// Timeout.
/// Duration.
public bool PlextorGetSilentMode(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
{
buffer = new byte[8];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.Plextor_Extend;
cdb[1] = (byte)PlextorSubCommands.GetMode;
cdb[2] = (byte)PlextorSubCommands.Silent;
cdb[3] = 4;
cdb[10] = (byte)buffer.Length;
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET SILENT MODE took {0} ms.", duration);
return sense;
}
///
/// Gets the Plextor GigaRec status
///
/// true, if GigaRec is supported, false otherwise.
/// Buffer.
/// Sense buffer.
/// Timeout.
/// Duration.
public bool PlextorGetGigaRec(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
{
buffer = new byte[8];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.Plextor_Extend;
cdb[1] = (byte)PlextorSubCommands.GetMode;
cdb[2] = (byte)PlextorSubCommands.GigaRec;
cdb[10] = (byte)buffer.Length;
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET GIGAREC took {0} ms.", duration);
return sense;
}
///
/// Gets the Plextor VariRec status
///
/// true, if VariRec is supported, false otherwise.
/// Buffer.
/// Sense buffer.
/// Timeout.
/// Duration.
public bool PlextorGetVariRec(out byte[] buffer, out byte[] senseBuffer, bool dvd, uint timeout, out double duration)
{
buffer = new byte[8];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.Plextor_Extend;
cdb[1] = (byte)PlextorSubCommands.GetMode;
cdb[2] = (byte)PlextorSubCommands.VariRec;
cdb[10] = (byte)buffer.Length;
if(dvd)
cdb[3] = 0x12;
else
cdb[3] = 0x02;
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET VARIREC took {0} ms.", duration);
return sense;
}
///
/// Gets the Plextor SecuRec status
///
/// true, if SecuRec is supported, false otherwise.
/// Buffer.
/// Sense buffer.
/// Timeout.
/// Duration.
public bool PlextorGetSecuRec(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
{
buffer = new byte[8];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.Plextor_Extend;
cdb[2] = (byte)PlextorSubCommands.SecuRec;
cdb[10] = (byte)buffer.Length;
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET SECUREC took {0} ms.", duration);
return sense;
}
///
/// Gets the Plextor SpeedRead status
///
/// true, if SpeedRead is supported, false otherwise.
/// Buffer.
/// Sense buffer.
/// Timeout.
/// Duration.
public bool PlextorGetSpeedRead(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
{
buffer = new byte[8];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.Plextor_Extend;
cdb[1] = (byte)PlextorSubCommands.GetMode;
cdb[2] = (byte)PlextorSubCommands.SpeedRead;
cdb[10] = (byte)buffer.Length;
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET SPEEDREAD took {0} ms.", duration);
return sense;
}
///
/// Gets the Plextor CD-R and multi-session hiding status
///
/// true, if CD-R and multi-session hiding is supported, false otherwise.
/// Buffer.
/// Sense buffer.
/// Timeout.
/// Duration.
public bool PlextorGetHiding(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
{
buffer = new byte[8];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.Plextor_Extend;
cdb[1] = (byte)PlextorSubCommands.GetMode;
cdb[2] = (byte)PlextorSubCommands.SessionHide;
cdb[9] = (byte)buffer.Length;
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET SINGLE-SESSION / HIDE CD-R took {0} ms.", duration);
return sense;
}
///
/// Gets the Plextor DVD+ book bitsetting status
///
/// true, if DVD+ book bitsetting is supported, false otherwise.
/// Buffer.
/// Sense buffer.
/// Timeout.
/// Duration.
public bool PlextorGetBitsetting(out byte[] buffer, out byte[] senseBuffer, bool dualLayer, uint timeout, out double duration)
{
buffer = new byte[8];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.Plextor_Extend;
cdb[1] = (byte)PlextorSubCommands.GetMode;
cdb[2] = (byte)PlextorSubCommands.BitSet;
cdb[9] = (byte)buffer.Length;
if(dualLayer)
cdb[3] = (byte)PlextorSubCommands.BitSetRDL;
else
cdb[3] = (byte)PlextorSubCommands.BitSetR;
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET BOOK BITSETTING took {0} ms.", duration);
return sense;
}
///
/// Gets the Plextor DVD+ test writing status
///
/// true, if DVD+ test writing is supported, false otherwise.
/// Buffer.
/// Sense buffer.
/// Timeout.
/// Duration.
public bool PlextorGetTestWriteDvdPlus(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
{
buffer = new byte[8];
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
bool sense;
cdb[0] = (byte)ScsiCommands.Plextor_Extend;
cdb[1] = (byte)PlextorSubCommands.GetMode;
cdb[2] = (byte)PlextorSubCommands.TestWriteDvdPlus;
cdb[10] = (byte)buffer.Length;
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET TEST WRITE DVD+ took {0} ms.", duration);
return sense;
}
}
}