// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // // Filename : Commands.cs // Author(s) : Natalia Portillo // // Component : Direct device access. // // --[ Description ] ---------------------------------------------------------- // // Sends commands to devices. // // --[ License ] -------------------------------------------------------------- // // 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 // License, or (at your option) any later version. // // 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. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, see . // // ---------------------------------------------------------------------------- // Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ using DiscImageChef.Decoders.ATA; namespace DiscImageChef.Devices { public partial class Device { /// /// Sends a SCSI command to this device /// /// 0 if no error occurred, otherwise, errno /// SCSI CDB /// Buffer for SCSI command response /// Buffer with the SCSI sense /// Timeout in seconds /// SCSI command transfer direction /// Time it took to execute the command in milliseconds /// True if SCSI command returned non-OK status and contains SCSI sense public int SendScsiCommand(byte[] cdb, ref byte[] buffer, out byte[] senseBuffer, uint timeout, ScsiDirection direction, out double duration, out bool sense) { return Command.SendScsiCommand(platformID, fd, cdb, ref buffer, out senseBuffer, timeout, direction, out duration, out sense); } /// /// Sends an ATA/ATAPI command to this device using CHS addressing /// /// 0 if no error occurred, otherwise, errno /// ATA registers. /// Status/error registers. /// ATA Protocol. /// Indicates which register indicates the transfer length /// Buffer for ATA/ATAPI command response /// Timeout in seconds /// If set to true, transfer is indicated in blocks, otherwise, it is indicated in bytes. /// Time it took to execute the command in milliseconds /// True if ATA/ATAPI command returned non-OK status public int SendAtaCommand(AtaRegistersCHS registers, out AtaErrorRegistersCHS errorRegisters, AtaProtocol protocol, AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout, bool transferBlocks, out double duration, out bool sense) { return Command.SendAtaCommand(platformID, fd, registers, out errorRegisters, protocol, transferRegister, ref buffer, timeout, transferBlocks, out duration, out sense); } /// /// Sends an ATA/ATAPI command to this device using 28-bit LBA addressing /// /// 0 if no error occurred, otherwise, errno /// ATA registers. /// Status/error registers. /// ATA Protocol. /// Indicates which register indicates the transfer length /// Buffer for ATA/ATAPI command response /// Timeout in seconds /// If set to true, transfer is indicated in blocks, otherwise, it is indicated in bytes. /// Time it took to execute the command in milliseconds /// True if ATA/ATAPI command returned non-OK status public int SendAtaCommand(AtaRegistersLBA28 registers, out AtaErrorRegistersLBA28 errorRegisters, AtaProtocol protocol, AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout, bool transferBlocks, out double duration, out bool sense) { return Command.SendAtaCommand(platformID, fd, registers, out errorRegisters, protocol, transferRegister, ref buffer, timeout, transferBlocks, out duration, out sense); } /// /// Sends an ATA/ATAPI command to this device using 48-bit LBA addressing /// /// 0 if no error occurred, otherwise, errno /// ATA registers. /// Status/error registers. /// ATA Protocol. /// Indicates which register indicates the transfer length /// Buffer for ATA/ATAPI command response /// Timeout in seconds /// If set to true, transfer is indicated in blocks, otherwise, it is indicated in bytes. /// Time it took to execute the command in milliseconds /// True if ATA/ATAPI command returned non-OK status public int SendAtaCommand(AtaRegistersLBA48 registers, out AtaErrorRegistersLBA48 errorRegisters, AtaProtocol protocol, AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout, bool transferBlocks, out double duration, out bool sense) { return Command.SendAtaCommand(platformID, fd, registers, out errorRegisters, protocol, transferRegister, ref buffer, timeout, transferBlocks, out duration, out sense); } /// /// Sends a MMC/SD command to this device /// /// The result of the command. /// MMC/SD opcode /// Buffer for MMC/SD command response /// Timeout in seconds /// Time it took to execute the command in milliseconds /// True if MMC/SD returned non-OK status /// True if data is sent from host to card /// True if command should be preceded with CMD55 /// Flags indicating kind and place of response /// How many blocks to transfer /// Command argument /// Response registers /// Size of block in bytes public int SendMmcCommand(MmcCommands command, bool write, bool isApplication, MmcFlags flags, uint argument, uint blockSize, uint blocks, ref byte[] buffer, out uint[] response, out double duration, out bool sense, uint timeout = 0) { if(command == MmcCommands.SendCID && cachedCid != null) { System.DateTime start = System.DateTime.Now; buffer = new byte[cachedCid.Length]; System.Array.Copy(cachedCid, buffer, buffer.Length); response = new uint[4]; sense = false; System.DateTime end = System.DateTime.Now; duration = (end - start).TotalMilliseconds; return 0; } if(command == MmcCommands.SendCSD && cachedCid != null) { System.DateTime start = System.DateTime.Now; buffer = new byte[cachedCsd.Length]; System.Array.Copy(cachedCsd, buffer, buffer.Length); response = new uint[4]; sense = false; System.DateTime end = System.DateTime.Now; duration = (end - start).TotalMilliseconds; return 0; } if(command == (MmcCommands)SecureDigitalCommands.SendSCR && cachedScr != null) { System.DateTime start = System.DateTime.Now; buffer = new byte[cachedScr.Length]; System.Array.Copy(cachedScr, buffer, buffer.Length); response = new uint[4]; sense = false; System.DateTime end = System.DateTime.Now; duration = (end - start).TotalMilliseconds; return 0; } if((command == (MmcCommands)SecureDigitalCommands.SendOperatingCondition || command == MmcCommands.SendOpCond) && cachedOcr != null) { System.DateTime start = System.DateTime.Now; buffer = new byte[cachedOcr.Length]; System.Array.Copy(cachedOcr, buffer, buffer.Length); response = new uint[4]; sense = false; System.DateTime end = System.DateTime.Now; duration = (end - start).TotalMilliseconds; return 0; } return Command.SendMmcCommand(platformID, fd, command, write, isApplication, flags, argument, blockSize, blocks, ref buffer, out response, out duration, out sense, timeout); } } }