scsi_decoder.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifndef _SCSI_DECODER_H_
00048 #define _SCSI_DECODER_H_
00049
00050
00051
00052
00053
00054
00055 typedef struct
00056 {
00057 U8 key;
00058 U8 asc;
00059 U8 ascq;
00060 } s_scsi_sense;
00061
00062
00063
00064
00065 Bool scsi_decode_command (void);
00066
00067
00068
00069
00070
00071 #define SBC_CMD_TEST_UNIT_READY (0x00)
00072 #define SBC_CMD_REQUEST_SENSE (0x03)
00073 #define SBC_CMD_FORMAT_UNIT (0x04)
00074 #define SBC_CMD_READ_6 (0x08)
00075 #define SBC_CMD_INQUIRY (0x12)
00076 #define SBC_CMD_MODE_SELECT_6 (0x15)
00077 #define SBC_CMD_MODE_SENSE_6 (0x1A)
00078 #define SBC_CMD_START_STOP_UNIT (0x1B)
00079 #define SBC_CMD_RECEIVE_DIAGNOSTICS (0x1C)
00080 #define SBC_CMD_SEND_DIAGNOSTIC (0x1D)
00081 #define SBC_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL (0x1E)
00082 #define SBC_CMD_READ_LONG (0x23)
00083 #define SBC_CMD_READ_CAPACITY (0x25)
00084 #define SBC_CMD_READ_CD_ROM_CAPACITY (0x25)
00085 #define SBC_CMD_READ_10 (0x28)
00086 #define SBC_CMD_WRITE_10 (0x2A)
00087 #define SBC_CMD_VERIFY_10 (0x2F)
00088 #define SBC_CMD_SYNCHRONIZE_CACHE (0x35)
00089 #define SBC_CMD_WRITE_BUFFER (0x3B)
00090 #define SBC_CMD_CHANGE_DEFINITION (0x40)
00091 #define SBC_CMD_READ_TOC (0x43)
00092 #define SBC_CMD_MODE_SELECT_10 (0x55)
00093 #define SBC_CMD_RESERVE_10 (0x56)
00094 #define SBC_CMD_RELEASE_10 (0x57)
00095 #define SBC_CMD_MODE_SENSE_10 (0x5A)
00096
00097 #define SBC_CONTROL_BYTE (0x00)
00098 #define SBC_CMD_DIR_IN (0x80)
00099 #define SBC_CMD_DIR_OUT (0x00)
00100
00101
00102
00103
00104
00105 #define SBC_SENSE_KEY_NO_SENSE (0x00)
00106 #define SBC_SENSE_KEY_RECOVERED_ERROR (0x01)
00107 #define SBC_SENSE_KEY_NOT_READY (0x02)
00108 #define SBC_SENSE_KEY_MEDIUM_ERROR (0x03)
00109 #define SBC_SENSE_KEY_HARDWARE_ERROR (0x04)
00110 #define SBC_SENSE_KEY_ILLEGAL_REQUEST (0x05)
00111 #define SBC_SENSE_KEY_UNIT_ATTENTION (0x06)
00112 #define SBC_SENSE_KEY_DATA_PROTECT (0x07)
00113 #define SBC_SENSE_KEY_BLANK_CHECK (0x08)
00114 #define SBC_SENSE_KEY_VENDOR_SPECIFIC (0x09)
00115 #define SBC_SENSE_KEY_COPY_ABORTED (0x0A)
00116 #define SBC_SENSE_KEY_ABORTED_COMMAND (0x0B)
00117 #define SBC_SENSE_KEY_VOLUME_OVERFLOW (0x0D)
00118 #define SBC_SENSE_KEY_MISCOMPARE (0x0E)
00119
00120
00121
00122
00123 #define SBC_ASC_NO_ADDITIONAL_SENSE_INFORMATION (0x00)
00124 #define SBC_ASC_LOGICAL_UNIT_NOT_READY (0x04)
00125 #define SBC_ASC_INVALID_FIELD_IN_CDB (0x24)
00126 #define SBC_ASC_WRITE_PROTECTED (0x27)
00127 #define SBC_ASC_FORMAT_ERROR (0x31)
00128 #define SBC_ASC_INVALID_COMMAND_OPERATION_CODE (0x20)
00129 #define SBC_ASC_NOT_READY_TO_READY_CHANGE (0x28)
00130 #define SBC_ASC_MEDIUM_NOT_PRESENT (0x3A)
00131
00132
00133
00134
00135 #define SBC_ASCQ_FORMAT_COMMAND_FAILED (0x01)
00136 #define SBC_ASCQ_INITIALIZING_COMMAND_REQUIRED (0x02)
00137 #define SBC_ASCQ_OPERATION_IN_PROGRESS (0x07)
00138
00139
00140
00141
00142
00143 #define SBC_RESPONSE_CODE_SENSE (0x70)
00144 #define SBC_ADDITIONAL_SENSE_LENGTH (0x0A)
00145 #define SBC_COMMAND_SPECIFIC_INFORMATION_3 (0x00)
00146 #define SBC_COMMAND_SPECIFIC_INFORMATION_2 (0x00)
00147 #define SBC_COMMAND_SPECIFIC_INFORMATION_1 (0x00)
00148 #define SBC_COMMAND_SPECIFIC_INFORMATION_0 (0x00)
00149 #define SBC_FIELD_REPLACEABLE_UNIT_CODE (0x00)
00150 #define SBC_SENSE_KEY_SPECIFIC_2 (0x00)
00151 #define SBC_SENSE_KEY_SPECIFIC_1 (0x00)
00152 #define SBC_SENSE_KEY_SPECIFIC_0 (0x00)
00153
00154
00155 #define SBC_READ_CAPACITY_LENGTH (0x08)
00156
00157
00158
00159
00160
00161
00162
00163 #define SBC_DEFAULT_MEDIUM_TYPE (0x00)
00164 #define SBC_FLEXIBLE_DISK_SINGLE_SIDED_UNSPECIFIED (0x01)
00165 #define SBC_FLEXIBLE_DISK_DOUBLE_SIDED_UNSPECIFIED (0x02)
00166
00167 #define SBC_MEDIUM_TYPE SBC_DEFAULT_MEDIUM_TYPE
00168
00169 #define SBC_DEV_SPEC_PARAM_WR_ENABLE (0x00)
00170 #define SBC_DEV_SPEC_PARAM_WR_PROTECT (0x80)
00171 #define SBC_BLOCK_DESCRIPTOR_LENGTH (0x00)
00172
00173 #define SBC_MSK_DBD (0x08)
00174 #define SBC_MSK_PAGE_CONTROL (0xC0)
00175 #define SBC_MSK_PAGE_CODE (0x3F)
00176
00177
00178
00179 #define SBC_PAGE_CODE_READ_WRITE_ERROR_RECOVERY (0x01)
00180 #define SBC_PAGE_CODE_FORMAT_DEVICE (0x03)
00181 #define SBC_PAGE_CODE_FLEXIBLE_DISK (0x05)
00182 #define SBC_PAGE_CODE_INFORMATIONAL_EXCEPTIONS (0x1C)
00183 #define SBC_PAGE_CODE_ALL (0x3F)
00184
00185
00186 #define SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS (0x0A)
00187 #define SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY (0x0A)
00188 #define SBC_PAGE_LENGTH_FLEXIBLE_DISK (0x1E)
00189 #define SBC_PAGE_LENGTH_FORMAT_DEVICE (0x16)
00190
00191
00192
00193 #define SBC_MODE_DATA_LENGTH_INFORMATIONAL_EXCEPTIONS (SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS + 2 + 3)
00194 #define SBC_MODE_DATA_LENGTH_READ_WRITE_ERROR_RECOVERY (SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY + 2 + 3 )
00195 #define SBC_MODE_DATA_LENGTH_FLEXIBLE_DISK (SBC_PAGE_LENGTH_FLEXIBLE_DISK + 2 + 3 )
00196 #define SBC_MODE_DATA_LENGTH_FORMAT_DEVICE (SBC_PAGE_LENGTH_FORMAT_DEVICE + 2 + 3 )
00197
00198 #define SBC_MODE_DATA_LENGTH_CODE_ALL (SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY + 2 + \
00199 SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS + 2 + \
00200 SBC_BLOCK_DESCRIPTOR_LENGTH + \
00201 + 3 )
00202
00203
00204
00205 #define SBC_MRIE (0x05)
00206
00207
00208 #define SBC_TRACK_PER_ZONE_MSB (0x00)
00209 #define SBC_TRACK_PER_ZONE_LSB (0x00)
00210 #define SBC_ALTERNATE_SECTORS_PER_ZONE_MSB (0x00)
00211 #define SBC_ALTERNATE_SECTORS_PER_ZONE_LSB (0x00)
00212 #define SBC_ALTERNATE_TRACK_PER_ZONE_MSB (0x00)
00213 #define SBC_ALTERNATE_TRACK_PER_ZONE_LSB (0x00)
00214 #define SBC_ALTERNATE_TRACK_PER_LU_MSB (0x00)
00215 #define SBC_ALTERNATE_TRACK_PER_LU_LSB (0x00)
00216
00217
00218 #define SBC_TRANSFER_RATE_MSB (0x13)
00219 #define SBC_TRANSFER_RATE_LSB (0x88)
00220
00221
00222
00223
00224
00225
00226
00227 #define SBC_NUMBER_OF_HEAD (0x04)
00228 #define SBC_SECTOR_PER_TRACK (0x20)
00229 #define SBC_DATA_BYTE_PER_SECTOR_MSB (0x02)
00230 #define SBC_DATA_BYTE_PER_SECTOR_LSB (0x00)
00231 #define SBC_NUMBER_OF_CYLINDERS_MSB (0x01)
00232 #define SBC_NUMBER_OF_CYLINDERS_LSB (0xE9)
00233 #define SBC_STARTING_CYLINDER_WRITE_COMPENSATION_MSB (0x00)
00234 #define SBC_STARTING_CYLINDER_WRITE_COMPENSATION_LSB (0x00)
00235 #define SBC_STARTING_CYLINDER_REDUCED_WRITE_MSB (0x00)
00236 #define SBC_STARTING_CYLINDER_REDUCED_WRITE_LSB (0x00)
00237 #define SBC_DEVICE_STEP_RATE_MSB (0x00)
00238 #define SBC_DEVICE_STEP_RATE_LSB (0x00)
00239 #define SBC_DEVICE_STEP_PULSE_WIDTH (0x00)
00240 #define SBC_HEAD_SETTLE_DELAY_MSB (0x00)
00241 #define SBC_HEAD_SETTLE_DELAY_LSB (0x00)
00242 #define SBC_MOTOR_ON_DELAY (0x00)
00243 #define SBC_MOTOR_OFF_DELAY (0x00)
00244 #define SBC_STEP_PULSE_PER_CYLINDER (0x00)
00245 #define SBC_WRITE_COMPENSATION (0x00)
00246 #define SBC_HEAD_LOAD_DELAY (0x00)
00247 #define SBC_HEAD_UNLOAD_DELAY (0x00)
00248 #define SBC_PIN34_PIN2 (0x00)
00249 #define SBC_PIN4_PIN1 (0x00)
00250 #define SBC_MEDIUM_ROTATION_RATE_MSB (0x00)
00251 #define SBC_MEDIUM_ROTATION_RATE_LSB (0x00)
00252
00253
00254 #define SBC_READ_RETRY_COUNT (0x03)
00255 #define SBC_WRITE_RETRY_COUNT (0x80)
00256 #define SBC_CORRECTION_SPAN (0x00)
00257 #define SBC_HEAD_OFFSET_COUNT (0x00)
00258 #define SBC_DATA_STROBE_OFFSET (0x00)
00259 #define SBC_RECOVERY_LIMIT_MSB (0x00)
00260 #define SBC_RECOVERY_LIMIT_LSB (0x00)
00261
00262
00263
00264
00265 #define SBC_MAX_INQUIRY_DATA (0x60) // value ?
00266
00267 struct sbc_st_std_inquiry_data
00268 {
00269 Byte DeviceType : 5;
00270 Byte PeripheralQualifier : 3;
00271
00272 Byte Reserved1 : 7;
00273 Byte RemovableMedia : 1;
00274
00275 Byte Version;
00276
00277 Byte Reserved3 : 5;
00278 Byte NormACA : 1;
00279 Byte Obsolete0 : 1;
00280 Byte AERC : 1;
00281
00282 Byte Reserved4[3];
00283
00284 Byte SoftReset : 1;
00285 Byte CommandQueue : 1;
00286 Byte Reserved5 : 1;
00287 Byte LinkedCommands : 1;
00288 Byte Synchronous : 1;
00289 Byte Wide16Bit : 1;
00290 Byte Wide32Bit : 1;
00291 Byte RelativeAddressing : 1;
00292 };
00293
00294
00295
00296
00297 #define Sbc_send_failed() (g_scsi_status = COMMAND_FAILED)
00298 #define Sbc_send_check_condition() (g_scsi_status = CHECK_CONDITION)
00299 #define Sbc_send_good() (g_scsi_status = COMMAND_PASSED)
00300
00301
00302
00303
00304
00305
00306 #define Sbc_build_sense(skey, sasc, sascq) ( g_scsi_sense.key = skey, \
00307 g_scsi_sense.asc = sasc, \
00308 g_scsi_sense.ascq = sascq )
00309
00310 #define Sbc_valid_write_usb(length) ( Usb_send_in(), \
00311 g_scsi_data_remaining -= length )
00312
00313
00314 #define COMMAND_PASSED 0x00
00315 #define COMMAND_FAILED 0x01
00316 #define CHECK_CONDITION 0x02
00317 #define PHASE_ERROR 0x02
00318
00319
00320 Bool sbc_inquiry (void);
00321 Bool sbc_mode_sense( Bool sense_10 );
00322 Bool sbc_mode_select_6 (void);
00323 Bool sbc_request_sense (void);
00324 Bool sbc_format (void);
00325 Bool sbc_write_10 (void);
00326 Bool sbc_read_10 (void);
00327 Bool sbc_test_unit_ready(void);
00328 Bool sbc_read_capacity(void);
00329 Bool sbc_prevent_allow_medium_removal(void);
00330
00331 void sbc_lun_status_is_good(void);
00332 void sbc_lun_status_is_busy_or_change(void);
00333 void sbc_lun_status_is_not_present(void);
00334 void sbc_lun_status_is_fail(void);
00335 void sbc_lun_status_is_protected(void);
00336
00337 #endif
00338