| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| IdentificationDescriptor |
|
| 1.0;1 |
| 1 | package org.jscsi.target.scsi.inquiry; | |
| 2 | ||
| 3 | ||
| 4 | import java.nio.ByteBuffer; | |
| 5 | ||
| 6 | import org.jscsi.target.scsi.ISerializable; | |
| 7 | import org.jscsi.target.util.BitManip; | |
| 8 | ||
| 9 | ||
| 10 | /** | |
| 11 | * Instances of this class contain information identifying the logical unit, SCSI target device containing the logical | |
| 12 | * unit, or access path (i.e., target port) used by the command and returned parameter data. | |
| 13 | * | |
| 14 | * @author Andreas Ergenzinger | |
| 15 | */ | |
| 16 | public final class IdentificationDescriptor implements ISerializable { | |
| 17 | ||
| 18 | /** | |
| 19 | * The total length of all bytes which are not part of the IDENTIFIER field. | |
| 20 | */ | |
| 21 | private static final int HEADER_LENGTH = 4; | |
| 22 | ||
| 23 | /** | |
| 24 | * The PROTOCOL IDENTIFIER field may indicate the SCSI transport protocol to which the identification descriptor | |
| 25 | * applies. If the ASSOCIATION field contains a value other than 01b (i.e., target port) or 10b (i.e., SCSI target | |
| 26 | * device) or the PIV bit is set to zero, then the PROTOCOL IDENTIFIER field contents are reserved. If the | |
| 27 | * ASSOCIATION field contains a value of 01b or 10b and the PIV bit is set to one, then the PROTOCOL IDENTIFIER | |
| 28 | * field shall contain one of the values defined in SPC-3 to indicate the SCSI transport protocol to which the | |
| 29 | * identification descriptor applies. | |
| 30 | */ | |
| 31 | private final ProtocolIdentifier protocolIdentifier; | |
| 32 | ||
| 33 | /** | |
| 34 | * The CODE SET field indicates the code set used for the IDENTIFIER field. | |
| 35 | */ | |
| 36 | private final CodeSet codeSet; | |
| 37 | ||
| 38 | /** | |
| 39 | * A protocol identifier valid (PIV) bit set to zero indicates the PROTOCOL IDENTIFIER field contents are reserved. | |
| 40 | * If the ASSOCIATION field contains a value of 01b or 10b, then a PIV bit set to one indicates the PROTOCOL | |
| 41 | * IDENTIFIER field contains a valid protocol identifier. | |
| 42 | * <p> | |
| 43 | * If the ASSOCIATION field contains a value other than 01b or 10b, then the PIV bit contents are reserved. | |
| 44 | */ | |
| 45 | private final boolean protocolIdentifierValid; | |
| 46 | ||
| 47 | /** | |
| 48 | * The ASSOCIATION field indicates the entity with which the IDENTIFIER field is associated. | |
| 49 | */ | |
| 50 | private final Association association; | |
| 51 | ||
| 52 | /** | |
| 53 | * The IDENTIFIER TYPE field indicates the format and assignment authority for the identifier. | |
| 54 | */ | |
| 55 | private final IdentifierType identifierType; | |
| 56 | ||
| 57 | /** | |
| 58 | * The IDENTIFIER field contains identifying information about the represented entity. | |
| 59 | */ | |
| 60 | private final Identifier identifier; | |
| 61 | ||
| 62 | 0 | public IdentificationDescriptor (final ProtocolIdentifier protocolIdentifier, final CodeSet codeSet, final boolean protocolIdentifierValid, final Association association, final IdentifierType identifierType, final Identifier identifier) { |
| 63 | 0 | this.protocolIdentifier = protocolIdentifier; |
| 64 | 0 | this.codeSet = codeSet; |
| 65 | 0 | this.protocolIdentifierValid = protocolIdentifierValid; |
| 66 | 0 | this.association = association; |
| 67 | 0 | this.identifierType = identifierType; |
| 68 | 0 | this.identifier = identifier; |
| 69 | 0 | } |
| 70 | ||
| 71 | public void serialize (ByteBuffer byteBuffer, int index) { | |
| 72 | ||
| 73 | // byte 0 | |
| 74 | 0 | byteBuffer.position(index); |
| 75 | 0 | byte b = (byte) (((protocolIdentifier.getValue() & 15) << 4) | (codeSet.getValue() & 15)); |
| 76 | 0 | byteBuffer.put(b); |
| 77 | ||
| 78 | // byte 1 | |
| 79 | 0 | b = (byte) (((association.getValue() & 3) << 4) | (identifierType.getValue() & 15)); |
| 80 | 0 | b = BitManip.getByteWithBitSet(b, 7, protocolIdentifierValid); |
| 81 | 0 | byteBuffer.put(b); |
| 82 | ||
| 83 | // byte 2 is reserved | |
| 84 | 0 | byteBuffer.put((byte) 0); |
| 85 | ||
| 86 | // byte 3 | |
| 87 | 0 | byteBuffer.put((byte) identifier.size());// identifier length |
| 88 | ||
| 89 | // identifier | |
| 90 | 0 | identifier.serialize(byteBuffer, index + HEADER_LENGTH); |
| 91 | 0 | } |
| 92 | ||
| 93 | public int size () { | |
| 94 | 0 | return identifier.size() + HEADER_LENGTH; |
| 95 | } | |
| 96 | } |