Coverage Report - org.jscsi.target.scsi.inquiry.PageCode
 
Classes in this File Line Coverage Branch Coverage Complexity
PageCode
0%
0/19
0%
0/32
8
PageCode$VitalProductDataPageName
0%
0/14
N/A
8
 
 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  0
     public PageCode (final byte value) {
 30  0
         this.value = 255 & value;
 31  0
     }
 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  0
         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  0
         if (value == 0x00) return VitalProductDataPageName.SUPPORTED_VPD_PAGES;// mandatory
 49  0
         if (0x01 <= value && value <= 0x7f) return VitalProductDataPageName.ASCII_INFORMATION;
 50  0
         if (value == 0x80) return VitalProductDataPageName.UNIT_SERIAL_NUMBER;
 51  0
         if (value == 0x81 || value == 0x82) return VitalProductDataPageName.OBSOLETE;
 52  0
         if (value == 0x83) return VitalProductDataPageName.DEVICE_IDENTIFICATION;// mandatory
 53  0
         if (value == 0x84) return VitalProductDataPageName.SOFTWARE_INTERFACE_IDENTIFICATION;
 54  0
         if (value == 0x85) return VitalProductDataPageName.MANAGEMENT_NETWORK_ADDRESSES;
 55  0
         if (value == 0x86) return VitalProductDataPageName.EXTENDED_INQUIRY_DATA;
 56  0
         if (value == 0x87) return VitalProductDataPageName.MODE_PAGE_POLICY;
 57  0
         if (value == 0x88) return VitalProductDataPageName.SCSI_PORTS;
 58  0
         if (0x89 <= value && value <= 0xaf) return VitalProductDataPageName.RESERVED;
 59  0
         if (0xb0 <= value && value <= 0xbf)
 60  0
             return VitalProductDataPageName.DEVICE_TYPE_SPECIFIC;
 61  
         else
 62  0
             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  0
     public enum VitalProductDataPageName {
 71  
         /**
 72  
          * {@link PageCode} value 0x00
 73  
          */
 74  0
         SUPPORTED_VPD_PAGES, // mandatory
 75  
         /**
 76  
          * {@link PageCode} values 0x01-0x7f
 77  
          */
 78  0
         ASCII_INFORMATION,
 79  
         /**
 80  
          * {@link PageCode} value 0x80
 81  
          */
 82  0
         UNIT_SERIAL_NUMBER,
 83  
         /**
 84  
          * {@link PageCode} values 0x81-0x82
 85  
          */
 86  0
         OBSOLETE,
 87  
         /**
 88  
          * {@link PageCode} value 0x83
 89  
          */
 90  0
         DEVICE_IDENTIFICATION, // mandatory
 91  
         /**
 92  
          * {@link PageCode} value 0x84
 93  
          */
 94  0
         SOFTWARE_INTERFACE_IDENTIFICATION,
 95  
         /**
 96  
          * {@link PageCode} value 0x85
 97  
          */
 98  0
         MANAGEMENT_NETWORK_ADDRESSES,
 99  
         /**
 100  
          * {@link PageCode} value 0x86
 101  
          */
 102  0
         EXTENDED_INQUIRY_DATA,
 103  
         /**
 104  
          * {@link PageCode} value 0x87
 105  
          */
 106  0
         MODE_PAGE_POLICY,
 107  
         /**
 108  
          * {@link PageCode} value 0x88
 109  
          */
 110  0
         SCSI_PORTS,
 111  
         /**
 112  
          * {@link PageCode} values 0x89-0xaf
 113  
          */
 114  0
         RESERVED,
 115  
         /**
 116  
          * {@link PageCode} values 0xb0-0xbf
 117  
          */
 118  0
         DEVICE_TYPE_SPECIFIC,
 119  
         /**
 120  
          * {@link PageCode} values 0xc0-0xff
 121  
          */
 122  0
         VENDOR_SPECIFIC
 123  
     }
 124  
 
 125  
     @Override
 126  
     public String toString () {
 127  0
         return "0x" + Integer.toHexString(value);
 128  
     }
 129  
 }