// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // 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-2025 Natalia Portillo // ****************************************************************************/ using System; using System.Diagnostics.CodeAnalysis; using Aaru.Decoders.ATA; namespace Aaru.Devices; [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] 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 /// 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 virtual int SendScsiCommand(Span cdb, ref byte[] buffer, uint timeout, ScsiDirection direction, out double duration, out bool sense) { duration = 0; sense = true; buffer = null; return -1; } /// 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 virtual int SendAtaCommand(AtaRegistersChs registers, out AtaErrorRegistersChs errorRegisters, AtaProtocol protocol, AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout, bool transferBlocks, out double duration, out bool sense) { duration = 0; sense = true; errorRegisters = default(AtaErrorRegistersChs); return -1; } /// 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 virtual int SendAtaCommand(AtaRegistersLba28 registers, out AtaErrorRegistersLba28 errorRegisters, AtaProtocol protocol, AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout, bool transferBlocks, out double duration, out bool sense) { errorRegisters = default(AtaErrorRegistersLba28); duration = 0; sense = true; return -1; } /// 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 virtual int SendAtaCommand(AtaRegistersLba48 registers, out AtaErrorRegistersLba48 errorRegisters, AtaProtocol protocol, AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout, bool transferBlocks, out double duration, out bool sense) { errorRegisters = default(AtaErrorRegistersLba48); duration = 0; sense = true; return -1; } /// 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 virtual 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 = 15) { response = null; duration = 0; sense = true; return -1; } /// /// Concatenates a queue of commands to be send to a remote SecureDigital or MultiMediaCard attached to an SDHCI /// controller /// /// List of commands /// Duration to execute all commands, in milliseconds /// Set to true if any of the commands returned an error status, false otherwise /// Maximum allowed time to execute a single command /// 0 if no error occurred, otherwise, errno public virtual int SendMultipleMmcCommands(MmcSingleCommand[] commands, out double duration, out bool sense, uint timeout = 15) { duration = 0; sense = true; return -1; } /// Closes then immediately reopens a device /// Returned error number if any public virtual bool ReOpen() => false; /// Reads data using operating system buffers. /// Data buffer /// Offset in remote device to start reading, in bytes /// Number of bytes to read /// Total time in milliseconds the reading took /// true if there was an error, false otherwise public virtual bool BufferedOsRead(out byte[] buffer, long offset, uint length, out double duration) { buffer = null; duration = 0; return false; } #region Nested type: MmcSingleCommand /// Encapsulates a single MMC command to send in a queue [SuppressMessage("ReSharper", "InconsistentNaming")] [SuppressMessage("ReSharper", "MemberCanBeInternal")] public class MmcSingleCommand { /// Command argument public uint argument; /// How many blocks to transfer public uint blocks; /// Size of block in bytes public uint blockSize; /// Buffer for MMC/SD command response public byte[] buffer; /// MMC/SD opcode public MmcCommands command; /// Flags indicating kind and place of response public MmcFlags flags; /// True if command should be preceded with CMD55 public bool isApplication; /// Response registers public uint[] response; /// True if data is sent from host to card public bool write; } #endregion }