File indexing completed on 2024-04-21 04:49:44

0001 /*
0002     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 #ifndef _K3B_SCSI_COMMAND_H_
0006 #define _K3B_SCSI_COMMAND_H_
0007 
0008 #include "k3bdevice.h"
0009 
0010 #include <qglobal.h>
0011 #include <QString>
0012 
0013 namespace K3b {
0014     namespace Device
0015     {
0016         const unsigned char MMC_BLANK = 0xA1;
0017         const unsigned char MMC_CLOSE_TRACK_SESSION = 0x5B;
0018         const unsigned char MMC_ERASE = 0x2C;
0019         const unsigned char MMC_FORMAT_UNIT = 0x04;
0020         const unsigned char MMC_GET_CONFIGURATION = 0x46;
0021         const unsigned char MMC_GET_EVENT_STATUS_NOTIFICATION = 0x4A;
0022         const unsigned char MMC_GET_PERFORMANCE = 0xAC;
0023         const unsigned char MMC_INQUIRY = 0x12;
0024         const unsigned char MMC_LOAD_UNLOAD_MEDIUM = 0xA6;
0025         const unsigned char MMC_MECHANISM_STATUS = 0xBD;
0026         const unsigned char MMC_MODE_SELECT = 0x55;
0027         const unsigned char MMC_MODE_SENSE = 0x5A;
0028         const unsigned char MMC_PAUSE_RESUME = 0x4B;
0029         const unsigned char MMC_PLAY_AUDIO_10 = 0x45;
0030         const unsigned char MMC_PLAY_AUDIO_12 = 0xA5;
0031         const unsigned char MMC_PLAY_AUDIO_MSF = 0x47;
0032         const unsigned char MMC_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E;
0033         const unsigned char MMC_READ_10 = 0x28;
0034         const unsigned char MMC_READ_12 = 0xA8;
0035         const unsigned char MMC_READ_BUFFER = 0x3C;
0036         const unsigned char MMC_READ_BUFFER_CAPACITY = 0x5C;
0037         const unsigned char MMC_READ_CAPACITY = 0x25;
0038         const unsigned char MMC_READ_CD = 0xBE;
0039         const unsigned char MMC_READ_CD_MSF = 0xB9;
0040         const unsigned char MMC_READ_DISC_INFORMATION = 0x51;
0041         const unsigned char MMC_READ_DVD_STRUCTURE = 0xAD;
0042         const unsigned char MMC_READ_DISC_STRUCTURE = 0xAD; /**< READ DVD STRUCTURE has been renamed to READ DISC STRUCTURE in MMC5 */
0043         const unsigned char MMC_READ_FORMAT_CAPACITIES = 0x23;
0044         const unsigned char MMC_READ_SUB_CHANNEL = 0x42;
0045         const unsigned char MMC_READ_TOC_PMA_ATIP = 0x43;
0046         const unsigned char MMC_READ_TRACK_INFORMATION = 0x52;
0047         const unsigned char MMC_REPAIR_TRACK = 0x58;
0048         const unsigned char MMC_REPORT_KEY = 0xA4;
0049         const unsigned char MMC_REQUEST_SENSE = 0x03;
0050         const unsigned char MMC_RESERVE_TRACK = 0x53;
0051         const unsigned char MMC_SCAN = 0xBA;
0052         const unsigned char MMC_SEEK_10 = 0x2B;
0053         const unsigned char MMC_SEND_CUE_SHEET = 0x5D;
0054         const unsigned char MMC_SEND_DVD_STRUCTURE = 0xBF;
0055         const unsigned char MMC_SEND_KEY = 0xA3;
0056         const unsigned char MMC_SEND_OPC_INFORMATION = 0x54;
0057         const unsigned char MMC_SET_SPEED = 0xBB;
0058         const unsigned char MMC_SET_READ_AHEAD = 0xA7;
0059         const unsigned char MMC_SET_STREAMING = 0xB6;
0060         const unsigned char MMC_START_STOP_UNIT = 0x1B;
0061         const unsigned char MMC_STOP_PLAY_SCAN = 0x4E;
0062         const unsigned char MMC_SYNCHRONIZE_CACHE = 0x35;
0063         const unsigned char MMC_TEST_UNIT_READY = 0x00;
0064         const unsigned char MMC_VERIFY_10 = 0x2F;
0065         const unsigned char MMC_WRITE_10 = 0x2A;
0066         const unsigned char MMC_WRITE_12 = 0xAA;
0067         const unsigned char MMC_WRITE_AND_VERIFY_10 = 0x2E;
0068         const unsigned char MMC_WRITE_BUFFER = 0x3B;
0069 
0070         QString commandString( const unsigned char& command );
0071 
0072         enum TransportDirection {
0073             TR_DIR_NONE,
0074             TR_DIR_READ,
0075             TR_DIR_WRITE
0076         };
0077 
0078         class ScsiCommand
0079         {
0080         public:
0081             explicit ScsiCommand( const Device* );
0082             ~ScsiCommand();
0083 
0084             /**
0085              * Enables or disables printing of debugging messages for failed
0086              * commands.
0087              *
0088              * Default is enabled.
0089              */
0090             void enableErrorMessages( bool b ) { m_printErrors = b; }
0091 
0092             void clear();
0093 
0094             unsigned char& operator[]( size_t );
0095 
0096             // TODO: use this
0097 /*       union ErrorCode { */
0098 /*  K3b::Device::quint32 code; */
0099 /*  struct { */
0100 /*    K3b::Device::quint8 errorCode; */
0101 /*    K3b::Device::quint8 senseKey; */
0102 /*    K3b::Device::quint8 asc; */
0103 /*    K3b::Device::quint8 ascq; */
0104 /*  } details; */
0105 /*       }; */
0106 
0107             /**
0108              * \return 0 on success, -1 if the device could not be opened, and
0109              *         an error code otherwise. The error code is constructed from
0110              *         the scsi error code, the sense key, asc, and ascq. These four values are
0111              *         combined into the lower 32 bit of an integer in the order used above.
0112              */
0113             int transport( TransportDirection dir = TR_DIR_NONE,
0114                            void* = 0,
0115                            size_t len = 0 );
0116 
0117         private:
0118             static QString senseKeyToString( int key );
0119             void debugError( int command, int errorCode, int senseKey, int asc, int ascq );
0120 
0121             class Private;
0122             Private *d;
0123             const Device* m_device;
0124 
0125             bool m_printErrors;
0126         };
0127     }
0128 }
0129 
0130 #endif