1 /* 2 SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org> 3 SPDX-License-Identifier: GPL-2.0-or-later 4 */ 5 #ifndef _K3B_SCSI_COMMAND_H_ 6 #define _K3B_SCSI_COMMAND_H_ 7 8 #include "k3bdevice.h" 9 10 #include <qglobal.h> 11 #include <QString> 12 13 namespace K3b { 14 namespace Device 15 { 16 const unsigned char MMC_BLANK = 0xA1; 17 const unsigned char MMC_CLOSE_TRACK_SESSION = 0x5B; 18 const unsigned char MMC_ERASE = 0x2C; 19 const unsigned char MMC_FORMAT_UNIT = 0x04; 20 const unsigned char MMC_GET_CONFIGURATION = 0x46; 21 const unsigned char MMC_GET_EVENT_STATUS_NOTIFICATION = 0x4A; 22 const unsigned char MMC_GET_PERFORMANCE = 0xAC; 23 const unsigned char MMC_INQUIRY = 0x12; 24 const unsigned char MMC_LOAD_UNLOAD_MEDIUM = 0xA6; 25 const unsigned char MMC_MECHANISM_STATUS = 0xBD; 26 const unsigned char MMC_MODE_SELECT = 0x55; 27 const unsigned char MMC_MODE_SENSE = 0x5A; 28 const unsigned char MMC_PAUSE_RESUME = 0x4B; 29 const unsigned char MMC_PLAY_AUDIO_10 = 0x45; 30 const unsigned char MMC_PLAY_AUDIO_12 = 0xA5; 31 const unsigned char MMC_PLAY_AUDIO_MSF = 0x47; 32 const unsigned char MMC_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E; 33 const unsigned char MMC_READ_10 = 0x28; 34 const unsigned char MMC_READ_12 = 0xA8; 35 const unsigned char MMC_READ_BUFFER = 0x3C; 36 const unsigned char MMC_READ_BUFFER_CAPACITY = 0x5C; 37 const unsigned char MMC_READ_CAPACITY = 0x25; 38 const unsigned char MMC_READ_CD = 0xBE; 39 const unsigned char MMC_READ_CD_MSF = 0xB9; 40 const unsigned char MMC_READ_DISC_INFORMATION = 0x51; 41 const unsigned char MMC_READ_DVD_STRUCTURE = 0xAD; 42 const unsigned char MMC_READ_DISC_STRUCTURE = 0xAD; /**< READ DVD STRUCTURE has been renamed to READ DISC STRUCTURE in MMC5 */ 43 const unsigned char MMC_READ_FORMAT_CAPACITIES = 0x23; 44 const unsigned char MMC_READ_SUB_CHANNEL = 0x42; 45 const unsigned char MMC_READ_TOC_PMA_ATIP = 0x43; 46 const unsigned char MMC_READ_TRACK_INFORMATION = 0x52; 47 const unsigned char MMC_REPAIR_TRACK = 0x58; 48 const unsigned char MMC_REPORT_KEY = 0xA4; 49 const unsigned char MMC_REQUEST_SENSE = 0x03; 50 const unsigned char MMC_RESERVE_TRACK = 0x53; 51 const unsigned char MMC_SCAN = 0xBA; 52 const unsigned char MMC_SEEK_10 = 0x2B; 53 const unsigned char MMC_SEND_CUE_SHEET = 0x5D; 54 const unsigned char MMC_SEND_DVD_STRUCTURE = 0xBF; 55 const unsigned char MMC_SEND_KEY = 0xA3; 56 const unsigned char MMC_SEND_OPC_INFORMATION = 0x54; 57 const unsigned char MMC_SET_SPEED = 0xBB; 58 const unsigned char MMC_SET_READ_AHEAD = 0xA7; 59 const unsigned char MMC_SET_STREAMING = 0xB6; 60 const unsigned char MMC_START_STOP_UNIT = 0x1B; 61 const unsigned char MMC_STOP_PLAY_SCAN = 0x4E; 62 const unsigned char MMC_SYNCHRONIZE_CACHE = 0x35; 63 const unsigned char MMC_TEST_UNIT_READY = 0x00; 64 const unsigned char MMC_VERIFY_10 = 0x2F; 65 const unsigned char MMC_WRITE_10 = 0x2A; 66 const unsigned char MMC_WRITE_12 = 0xAA; 67 const unsigned char MMC_WRITE_AND_VERIFY_10 = 0x2E; 68 const unsigned char MMC_WRITE_BUFFER = 0x3B; 69 70 QString commandString( const unsigned char& command ); 71 72 enum TransportDirection { 73 TR_DIR_NONE, 74 TR_DIR_READ, 75 TR_DIR_WRITE 76 }; 77 78 class ScsiCommand 79 { 80 public: 81 explicit ScsiCommand( const Device* ); 82 ~ScsiCommand(); 83 84 /** 85 * Enables or disables printing of debugging messages for failed 86 * commands. 87 * 88 * Default is enabled. 89 */ enableErrorMessages(bool b)90 void enableErrorMessages( bool b ) { m_printErrors = b; } 91 92 void clear(); 93 94 unsigned char& operator[]( size_t ); 95 96 // TODO: use this 97 /* union ErrorCode { */ 98 /* K3b::Device::quint32 code; */ 99 /* struct { */ 100 /* K3b::Device::quint8 errorCode; */ 101 /* K3b::Device::quint8 senseKey; */ 102 /* K3b::Device::quint8 asc; */ 103 /* K3b::Device::quint8 ascq; */ 104 /* } details; */ 105 /* }; */ 106 107 /** 108 * \return 0 on success, -1 if the device could not be opened, and 109 * an error code otherwise. The error code is constructed from 110 * the scsi error code, the sense key, asc, and ascq. These four values are 111 * combined into the lower 32 bit of an integer in the order used above. 112 */ 113 int transport( TransportDirection dir = TR_DIR_NONE, 114 void* = 0, 115 size_t len = 0 ); 116 117 private: 118 static QString senseKeyToString( int key ); 119 void debugError( int command, int errorCode, int senseKey, int asc, int ascq ); 120 121 class Private; 122 Private *d; 123 const Device* m_device; 124 125 bool m_printErrors; 126 }; 127 } 128 } 129 130 #endif 131