1 package org.jscsi.target.scsi.cdb; 2 3 /** 4 * The OPERATION CODE of a Command Descriptor Block specifies the type of command the initiator wants the target to 5 * perform. 6 * <p> 7 * The OPERATION CODE of the {@link CommandDescriptorBlock} has a GROUP CODE field and a COMMAND CODE field. The 8 * three-bit GROUP CODE field provides for eight groups of command codes. The five-bit COMMAND CODE field provides for 9 * thirty-two command codes in each group. A total of 256 possible operation codes exist. 10 * <p> 11 * The value of the GROUP CODE field specifies the {@link CommandDescriptorBlock}'s length. 12 * 13 * @see CdbType 14 * @author Andreas Ergenzinger 15 */ 16 public enum ScsiOperationCode { 17 TEST_UNIT_READY((byte) 0x00), REQUEST_SENSE((byte) 0x03), FORMAT_UNIT((byte) 0x04), READ_6((byte) 0x08), WRITE_6((byte) 0x0a), INQUIRY((byte) 0x12), MODE_SELECT_6((byte) 0x15), MODE_SENSE_6((byte) 0x1a), SEND_DIAGNOSTIC((byte) 0x1d), READ_CAPACITY_10((byte) 0x25), READ_10((byte) 0x28), WRITE_10((byte) 0x2a), READ_CAPACITY_16((byte) 0x9e), REPORT_LUNS((byte) 0xa0); 18 19 /** 20 * The serialized value of the operation code. 21 */ 22 private final byte value; 23 24 /** 25 * Maps byte values/index positions to {@link ScsiOperationCode} constants. 26 */ 27 private static final ScsiOperationCode[] mapping = new ScsiOperationCode[256]; 28 static {// initialize mapping 29 final ScsiOperationCode[] values = values(); 30 int index; 31 for (ScsiOperationCode v : values) { 32 index = (v.value & 255); 33 mapping[index] = v; 34 } 35 } 36 37 /** 38 * Returns the {@link ScsiOperationCode} corresponding to the passed byte value. 39 * 40 * @param value the serialized value of a SCSI operation code 41 * @return the corresponding {@link ScsiOperationCode} or <code>null</code> if the passed value is not known by the 42 * jSCSI Target 43 */ 44 public static final ScsiOperationCode valueOf (final byte value) { 45 return mapping[value & 255]; 46 } 47 48 private ScsiOperationCode (final byte value) { 49 this.value = value; 50 } 51 52 /** 53 * Returns the serialized value of the operation code. 54 * 55 * @return the serialized value of the operation code 56 */ 57 public final byte value () { 58 return value; 59 } 60 61 /** 62 * The three-bit GROUP CODE field provides for eight groups of command codes. 63 * 64 * @return the three-bit GROUP CODE field 65 */ 66 public int getGroupCode () { 67 return (value >>> 5) & 7; 68 } 69 70 /** 71 * Returns the five-bit COMMAND CODE field. 72 * 73 * @return the five-bit COMMAND CODE field 74 */ 75 public int getCommandCode () { 76 return value & 31; 77 } 78 79 /** 80 * Returns the {@link CdbType} for this operation code. 81 * 82 * @return the {@link CdbType} for this operation code 83 */ 84 public CdbType getCdbType () { 85 return CdbType.getCdbType(this); 86 } 87 }