1 package org.jscsi.target.scsi.cdb; 2 3 /** 4 * The {@link CdbType} determines the length of a serialized {@link CommandDescriptorBlock} (CDB) object. 5 * <p> 6 * The first 3 bytes (the group code) of the CDB's {@link ScsiOperationCode} field specify the {@link CdbType}. 7 * 8 * @author Andreas Ergenzinger 9 */ 10 public enum CdbType { 11 /** 12 * The CDB is 6 bytes long. 13 */ 14 SIX_BYTE_COMMANDS, 15 /** 16 * The CDB is 10 bytes long. 17 */ 18 TEN_BYTE_COMMANDS, 19 /** 20 * The CDB is 12 bytes long. 21 */ 22 TWELVE_BYTE_COMMANDS, 23 /** 24 * The CDB is 16 bytes long. 25 */ 26 SIXTEEN_BYTE_COMMANDS, 27 /** 28 * The CDB length is not determined by the CDB's {@link ScsiOperationCode} field. 29 */ 30 VARIABLE_LENGTH_COMMANDS, 31 /** 32 * The CDB length is vendor-specific. 33 */ 34 VENDOR_SPECIFIC; 35 36 /** 37 * Returns the {@link CdbType} for the passed {@link ScsiOperationCode}. 38 * 39 * @param scsiOpCode determines CDB length 40 * @return the appropriate {@link CdbType} 41 */ 42 public static CdbType getCdbType (ScsiOperationCode scsiOpCode) { 43 final int groupCode = scsiOpCode.getGroupCode(); 44 45 switch (groupCode) { 46 case 0 :// 000b 47 return SIX_BYTE_COMMANDS; 48 case 1 :// 001b 49 case 2 :// 010b 50 return TEN_BYTE_COMMANDS; 51 case 3 :// 011b 52 return VARIABLE_LENGTH_COMMANDS; 53 case 4 :// 100b 54 return SIXTEEN_BYTE_COMMANDS; 55 case 5 :// 101b 56 return TWELVE_BYTE_COMMANDS; 57 case 6 :// 110b 58 case 7 :// 111b 59 return VENDOR_SPECIFIC; 60 default : 61 return null;// this really should not happen! 62 } 63 } 64 65 }