1 package org.jscsi.target.scsi.inquiry;
2
3
4 import org.jscsi.target.scsi.cdb.InquiryCDB;
5
6
7 /**
8 * Using the <code>INQUIRY</code> SCSI command, the initiator can request the target to return vital product data (VPD)
9 * pages. The specific VPD page is determined by the value of the {@link InquiryCDB#pageCode} field.
10 * <p>
11 * To find out which page was requested, first create a new {@link PageCode} object using the value provided in the
12 * command descriptor block's PAGE CODE field, and then call its {@link #getVitalProductDataPageName()} method. This
13 * complicated approach is necessary, since some VPD pages are associated with more than just one page code.
14 *
15 * @author Andreas Ergenzinger
16 */
17 public class PageCode {
18
19 /**
20 * The value of the PAGE CODE field.
21 */
22 private final int value;
23
24 /**
25 * Creates a new {@link PageCode} object.
26 *
27 * @param value the value of the PAGE CODE field
28 */
29 public PageCode (final byte value) {
30 this.value = 255 & value;
31 }
32
33 /**
34 * Returns the value of the PAGE CODE field.
35 *
36 * @return the value of the PAGE CODE field
37 */
38 public final byte getValue () {
39 return (byte) value;
40 }
41
42 /**
43 * Returns the VPD page name associated with the PAGE CODE {@link #value}.
44 *
45 * @return the VPD page name associated with the PAGE CODE {@link #value}
46 */
47 public final VitalProductDataPageName getVitalProductDataPageName () {
48 if (value == 0x00) return VitalProductDataPageName.SUPPORTED_VPD_PAGES;// mandatory
49 if (0x01 <= value && value <= 0x7f) return VitalProductDataPageName.ASCII_INFORMATION;
50 if (value == 0x80) return VitalProductDataPageName.UNIT_SERIAL_NUMBER;
51 if (value == 0x81 || value == 0x82) return VitalProductDataPageName.OBSOLETE;
52 if (value == 0x83) return VitalProductDataPageName.DEVICE_IDENTIFICATION;// mandatory
53 if (value == 0x84) return VitalProductDataPageName.SOFTWARE_INTERFACE_IDENTIFICATION;
54 if (value == 0x85) return VitalProductDataPageName.MANAGEMENT_NETWORK_ADDRESSES;
55 if (value == 0x86) return VitalProductDataPageName.EXTENDED_INQUIRY_DATA;
56 if (value == 0x87) return VitalProductDataPageName.MODE_PAGE_POLICY;
57 if (value == 0x88) return VitalProductDataPageName.SCSI_PORTS;
58 if (0x89 <= value && value <= 0xaf) return VitalProductDataPageName.RESERVED;
59 if (0xb0 <= value && value <= 0xbf)
60 return VitalProductDataPageName.DEVICE_TYPE_SPECIFIC;
61 else
62 return VitalProductDataPageName.VENDOR_SPECIFIC;
63 }
64
65 /**
66 * An enumeration of unique identifiers for Vital Product Data Pages.
67 *
68 * @author Andreas Ergenzinger
69 */
70 public enum VitalProductDataPageName {
71 /**
72 * {@link PageCode} value 0x00
73 */
74 SUPPORTED_VPD_PAGES, // mandatory
75 /**
76 * {@link PageCode} values 0x01-0x7f
77 */
78 ASCII_INFORMATION,
79 /**
80 * {@link PageCode} value 0x80
81 */
82 UNIT_SERIAL_NUMBER,
83 /**
84 * {@link PageCode} values 0x81-0x82
85 */
86 OBSOLETE,
87 /**
88 * {@link PageCode} value 0x83
89 */
90 DEVICE_IDENTIFICATION, // mandatory
91 /**
92 * {@link PageCode} value 0x84
93 */
94 SOFTWARE_INTERFACE_IDENTIFICATION,
95 /**
96 * {@link PageCode} value 0x85
97 */
98 MANAGEMENT_NETWORK_ADDRESSES,
99 /**
100 * {@link PageCode} value 0x86
101 */
102 EXTENDED_INQUIRY_DATA,
103 /**
104 * {@link PageCode} value 0x87
105 */
106 MODE_PAGE_POLICY,
107 /**
108 * {@link PageCode} value 0x88
109 */
110 SCSI_PORTS,
111 /**
112 * {@link PageCode} values 0x89-0xaf
113 */
114 RESERVED,
115 /**
116 * {@link PageCode} values 0xb0-0xbf
117 */
118 DEVICE_TYPE_SPECIFIC,
119 /**
120 * {@link PageCode} values 0xc0-0xff
121 */
122 VENDOR_SPECIFIC
123 }
124
125 @Override
126 public String toString () {
127 return "0x" + Integer.toHexString(value);
128 }
129 }