def marshall_datain(cls, data):
        """
        Marshall the ReadCapacity16 datain.

        :param data: a dict
        :return result: a byte array
        """
        result = bytearray(8)
        encode_dict(data,
                    cls._datain_bits,
                    result)

        for _esp in data['element_status_pages']:
            _r = bytearray(8)
            encode_dict(_esp,
                        cls._element_status_page_bits,
                        _r)

            _edl = 12 + 4
            if _esp['pvoltag']:
                _edl += 36
            if _esp['avoltag']:
                _edl += 36

            for _ed in _esp['element_descriptors']:
                _rr = bytearray(12)
                encode_dict(_ed,
                            cls._element_status_descriptor_bits,
                            _rr)
                if _esp['element_type'] == cls.ELEMENT_TYPE.DATA_TRANSFER:
                    encode_dict(_ed,
                                cls._data_transfer_descriptor_bits,
                                _rr)
                if _esp['element_type'] == cls.ELEMENT_TYPE.STORAGE:
                    encode_dict(_ed,
                                cls._storage_descriptor_bits,
                                _rr)
                if _esp['element_type'] == cls.ELEMENT_TYPE.IMPORT_EXPORT:
                    encode_dict(_ed,
                                cls._import_export_descriptor_bits,
                                _rr)
                _r += _rr
                if _esp['pvoltag']:
                    _rr = bytearray(36)
                    _r += _rr
                if _esp['avoltag']:
                    _rr = bytearray(36)
                    _r += _rr
                _rr = bytearray(4)
                _r += _rr

            _r[2:4] = scsi_int_to_ba(_edl, 2)
            _r[5:8] = scsi_int_to_ba(len(_r) - 8, 3)
            result += _r

        result[5:8] = scsi_int_to_ba(len(result) - 8, 3)
        return result
    def marshall_datain(data):
        """
        Marshall the ReadCapacity16 datain.

        :param data: a dict
        :return result: a byte array
        """
        result = bytearray(8)
        encode_dict(data,
                    ReadElementStatus._datain_bits,
                    result)

        for _esp in data['element_status_pages']:
            _r = bytearray(8)
            encode_dict(_esp,
                        ReadElementStatus._element_status_page_bits,
                        _r)

            _edl = 12 + 4
            if _esp['pvoltag']:
                _edl += 36
            if _esp['avoltag']:
                _edl += 36

            for _ed in _esp['element_descriptors']:
                _rr = bytearray(12)
                encode_dict(_ed,
                            ReadElementStatus._element_status_descriptor_bits,
                            _rr)
                if _esp['element_type'] == readelementstatus_enums.ELEMENT_TYPE.DATA_TRANSFER:
                    encode_dict(_ed,
                                ReadElementStatus._data_transfer_descriptor_bits,
                                _rr)
                if _esp['element_type'] == readelementstatus_enums.ELEMENT_TYPE.STORAGE:
                    encode_dict(_ed,
                                ReadElementStatus._storage_descriptor_bits,
                                _rr)
                if _esp['element_type'] == readelementstatus_enums.ELEMENT_TYPE.IMPORT_EXPORT:
                    encode_dict(_ed,
                                ReadElementStatus._import_export_descriptor_bits,
                                _rr)
                _r += _rr
                if _esp['pvoltag']:
                    _rr = bytearray(36)
                    _r += _rr
                if _esp['avoltag']:
                    _rr = bytearray(36)
                    _r += _rr
                _rr = bytearray(4)
                _r += _rr

            _r[2:4] = scsi_int_to_ba(_edl, 2)
            _r[5:8] = scsi_int_to_ba(len(_r) - 8, 3)
            result += _r

        result[5:8] = scsi_int_to_ba(len(result) - 8, 3)
        return result
    def execute(self, cdb, dataout, datain, sense):
        datain[0] = 15  # mode data length
        datain[1] = 0  # medium type: BLOCK_DEVICE
        datain[2] = 0x90  # device specific parameter
        datain[3] = 0  # block descriptor length

        datain[4] = 0x8a  # PS=1 SPF=0 PAGECODE=0x0a
        datain[5] = 10  # Parameter List Length

        datain[6] = 0x9f  # tst:4 tmdf_only:1 dpicz:1 d_Sense:1 gltsd:1 rlec:1
        datain[7] = 0x9e  # qam:9 nuar:1 qerr:3
        datain[8] = 0xf8  # vs:1 rac:1 uaic:3 swp:1
        datain[9] = 0xf7  # ato:1 tas:1 atmpe:1 rwwp:1 am:7
        datain[12:14] = scsi_int_to_ba(500, 2)  # busy timeout:500
        datain[14:16] = scsi_int_to_ba(700, 2)  # ext:700
    def execute(self, cdb, dataout, datain, sense):
        datain[0] = 15    # mode data length
        datain[1] = 0     # medium type: BLOCK_DEVICE
        datain[2] = 0x90  # device specific parameter
        datain[3] = 0     # block descriptor length

        datain[4] = 0x8a  # PS=1 SPF=0 PAGECODE=0x0a
        datain[5] = 10    # Parameter List Length

        datain[6] = 0x9f  # tst:4 tmdf_only:1 dpicz:1 d_Sense:1 gltsd:1 rlec:1
        datain[7] = 0x9e  # qam:9 nuar:1 qerr:3
        datain[8] = 0xf8  # vs:1 rac:1 uaic:3 swp:1
        datain[9] = 0xf7  # ato:1 tas:1 atmpe:1 rwwp:1 am:7
        datain[12:14] = scsi_int_to_ba(500, 2)  # busy timeout:500
        datain[14:16] = scsi_int_to_ba(700, 2)  # ext:700
Пример #5
0
    def execute(self, cmd):
        cmd.datain[0] = 15  # mode data length
        cmd.datain[2] = 0  # medium type: BLOCK_DEVICE
        cmd.datain[3] = 0x90  # device specific parameter
        cmd.datain[6] = 0  # block descriptor length

        cmd.datain[8] = 0x8a  # PS=1 SPF=0 PAGECODE=0x0a
        cmd.datain[9] = 10  # Parameter List Length

        cmd.datain[
            10] = 0x9f  # tst:4 tmdf_only:1 dpicz:1 d_Sense:1 gltsd:1 rlec:1
        cmd.datain[11] = 0x9e  # qam:9 nuar:1 qerr:3
        cmd.datain[12] = 0xf8  # vs:1 rac:1 uaic:3 swp:1
        cmd.datain[13] = 0xf7  # ato:1 tas:1 atmpe:1 rwwp:1 am:7
        cmd.datain[16:18] = scsi_int_to_ba(500, 2)  # busy timeout:500
        cmd.datain[18:20] = scsi_int_to_ba(700, 2)  # ext:700
Пример #6
0
    def marshall_datain(cls, data):
        """
        Marshall the Inquiry datain.

        :param data: a dict with data
        :return result: a byte array
        """
        if 'page_code' not in data:
            result = bytearray(96)
            convert.encode_dict(data, cls._datain_bits, result)
            convert.encode_dict(data, cls._standard_bits, result)
            return result

        result = bytearray(4)
        convert.encode_dict(data, cls._datain_bits, result)
        convert.encode_dict(data, cls._pagecode_bits, result)
        if data['page_code'] == cls.VPD.LOGICAL_BLOCK_PROVISIONING:
            result += bytearray(4)
            convert.encode_dict(data, cls._logical_block_provisioning_bits,
                                result)
        if data['page_code'] == cls.VPD.UNIT_SERIAL_NUMBER:
            result += data['unit_serial_number']
        if data['page_code'] == cls.VPD.REFERRALS:
            result += bytearray(12)
            convert.encode_dict(data, cls._referrals_bits, result)
        if data['page_code'] == cls.VPD.EXTENDED_INQUIRY_DATA:
            result += bytearray(60)
            convert.encode_dict(data, cls._extended_bits, result)
        if data['page_code'] == cls.VPD.DEVICE_IDENTIFICATION:
            for _dd in data['designator_descriptors']:
                _r = cls.marshall_designation_descriptor(_dd)
                result += _r

        result[2:4] = convert.scsi_int_to_ba(len(result) - 4, 2)
        return result
Пример #7
0
    def marshall_datain(data):
        """
        Marshall the ReadCapacity16 datain.
        """
        result = bytearray(8)
        if not 'lbas' in data:
            result[:4] = scsi_int_to_ba(len(result) - 4, 4)
            return result

        for l in data['lbas']:
            _r = bytearray(16)
            encode_dict(l, GetLBAStatus._datain_bits, _r)
            result += _r

        result[:4] = scsi_int_to_ba(len(result) - 4, 4)
        return result
Пример #8
0
    def marshall_datain(data):
        """
        Marshall the Inquiry datain.
        """
        if 'page_code' not in data:
            result = bytearray(96)
            encode_dict(data, Inquiry._datain_bits, result)
            encode_dict(data, Inquiry._standard_bits, result)
            result[8:16] = data['t10_vendor_identification']
            result[16:32] = data['product_identification']
            result[32:36] = data['product_revision_level']
            return result

        result = bytearray(4)
        encode_dict(data, Inquiry._datain_bits, result)
        encode_dict(data, Inquiry._pagecode_bits, result)

        if data['page_code'] == inquiry_enums.VPD.LOGICAL_BLOCK_PROVISIONING:
            result += bytearray(4)
            encode_dict(data, Inquiry._logical_block_provisioning_bits, result)
        if data['page_code'] == inquiry_enums.VPD.UNIT_SERIAL_NUMBER:
            result += data['unit_serial_number']
        if data['page_code'] == inquiry_enums.VPD.REFERRALS:
            result += bytearray(12)
            encode_dict(data, Inquiry._referrals_bits, result)
        if data['page_code'] == inquiry_enums.VPD.EXTENDED_INQUIRY_DATA:
            result += bytearray(60)
            encode_dict(data, Inquiry._extended_bits, result)
        if data['page_code'] == inquiry_enums.VPD.DEVICE_IDENTIFICATION:
            for _dd in data['designator_descriptors']:
                _r = Inquiry.marshall_designation_descriptor(_dd)
                result += _r

        result[2:4] = scsi_int_to_ba(len(result) - 4, 2)
        return result
Пример #9
0
    def marshall_datain(data):
        """
        Marshall the ReportLuns datain.
        """
        result = bytearray(8)
        if not 'luns' in data:
            result[:4] = scsi_int_to_ba(len(result) - 4, 4)
            return result

        for l in data['luns']:
            _r = bytearray(8)
            encode_dict(l, ReportLuns._datain_bits, _r)
            result += _r

        result[:4] = scsi_int_to_ba(len(result) - 4, 4)
        return result
Пример #10
0
    def marshall_datain(data):
        """
        Marshall the GetLBAStatus datain.
        """
        result = bytearray(8)
        if not 'lbas' in data:
            result[:4] = scsi_int_to_ba(len(result) - 4, 4)
            return result

        for l in data['lbas']:
            _r = bytearray(16)
            encode_dict(l, GetLBAStatus._datain_bits, _r)
            result += _r

        result[:4] = scsi_int_to_ba(len(result) - 4, 4)
        return result
Пример #11
0
    def marshall_datain(data):
        """
        Marshall the Inquiry datain.
        """
        if 'page_code' not in data:
            result = bytearray(96)
            encode_dict(data, Inquiry._datain_bits, result)
            encode_dict(data, Inquiry._standard_bits, result)
            result[8:16] = data['t10_vendor_identification']
            result[16:32] = data['product_identification']
            result[32:36] = data['product_revision_level']
            return result

        result = bytearray(4)
        encode_dict(data, Inquiry._datain_bits, result)
        encode_dict(data, Inquiry._pagecode_bits, result)

        if data['page_code'] == inquiry_enums.VPD.LOGICAL_BLOCK_PROVISIONING:
            result += bytearray(4)
            encode_dict(data, Inquiry._logical_block_provisioning_bits, result)
        if data['page_code'] == inquiry_enums.VPD.UNIT_SERIAL_NUMBER:
            result += data['unit_serial_number']
        if data['page_code'] == inquiry_enums.VPD.REFERRALS:
            result += bytearray(12)
            encode_dict(data, Inquiry._referrals_bits, result)
        if data['page_code'] == inquiry_enums.VPD.EXTENDED_INQUIRY_DATA:
            result += bytearray(60)
            encode_dict(data, Inquiry._extended_bits, result)
        if data['page_code'] == inquiry_enums.VPD.DEVICE_IDENTIFICATION:
            for _dd in data['designator_descriptors']:
                _r = Inquiry.marshall_designation_descriptor(_dd)
                result += _r

        result[2:4] = scsi_int_to_ba(len(result) - 4, 2)
        return result
Пример #12
0
    def execute(self, cmd):
        cmd.datain[0] = 15  # mode data length
        cmd.datain[1] = 0  # medium type: BLOCK_DEVICE
        cmd.datain[2] = 0x90  # device specific parameter
        cmd.datain[3] = 0  # block descriptor length

        cmd.datain[4] = 0x82  # PS=1 SPF=0 PAGECODE=0x02
        cmd.datain[5] = 0x0e

        cmd.datain[6] = 122  # bfr:122
        cmd.datain[7] = 123  # ber:123
        cmd.datain[8:10] = scsi_int_to_ba(2371, 2)  # bil
        cmd.datain[10:12] = scsi_int_to_ba(2372, 2)  # dtl
        cmd.datain[12:14] = scsi_int_to_ba(2373, 2)  # ctl
        cmd.datain[14:16] = scsi_int_to_ba(2374, 2)  # mbs
        cmd.datain[16] = 0xff  # emdp:1 fa:7 dimm:1 dtdc:7
        cmd.datain[18:20] = scsi_int_to_ba(2375, 2)  # fbs
Пример #13
0
    def execute(self, cdb, dataout, datain, sense):
        datain[0] = 0x00  # QUAL:0 TYPE:0
        datain[1] = 0x83  # device identifier
        datain[2] = 0x00
        datain[3] = 0x00
        pos = 4
        
        # Designation Descriptor: T10_VENDOR_ID
        t10 = bytearray(8)
        t10[0] = ord('T')
        t10[1] = ord('e')
        t10[2] = ord('s')
        t10[3] = ord('t')
        t10[4] = ord(' ')
        t10[5] = ord('T')
        t10[6] = ord('1')
        t10[7] = ord('0')
        dd = bytearray(4)
        dd += t10
        dd[0] = 0x52  # iSCSI, ASCII
        dd[1] = 0xa1  # AssociatedWithTargetDevice, T10_VENDOR_ID
        dd[3] = len(t10)
        datain[pos:pos + len(dd)] = dd
        pos += len(dd)

        # Designation Descriptor: EUI-64, 8 byte version
        eui = bytearray(8)
        # IEEE company identifier
        eui[0] = 0x11
        eui[1] = 0x22
        eui[2] = 0x33
        # vendor specific
        eui[3] = ord('a')
        eui[4] = ord('b')
        eui[5] = ord('c')
        eui[6] = ord('d')
        eui[7] = ord('e')
        dd = bytearray(4)
        dd += eui
        dd[0] = 0x01  # BINARY
        dd[1] = 0x22  # AssociatedWithTargetDevice, EUI-64
        dd[2:4] = scsi_int_to_ba(len(t10), 2)
        datain[pos:pos + len(dd)] = dd
        pos += len(dd)

        datain[2:4] = scsi_int_to_ba(pos - 4, 2)
Пример #14
0
    def execute(self, cmd):
        cmd.datain[0] = 0x00  # QUAL:0 TYPE:0
        cmd.datain[1] = 0x83  # device identifier
        cmd.datain[2] = 0x00
        cmd.datain[3] = 0x00
        pos = 4
        
        # Designation Descriptor: T10_VENDOR_ID
        t10 = bytearray(8)
        t10[0] = ord('T')
        t10[1] = ord('e')
        t10[2] = ord('s')
        t10[3] = ord('t')
        t10[4] = ord(' ')
        t10[5] = ord('T')
        t10[6] = ord('1')
        t10[7] = ord('0')
        dd = bytearray(4)
        dd += t10
        dd[0] = 0x52  # iSCSI, ASCII
        dd[1] = 0xa1  # AssociatedWithTargetDevice, T10_VENDOR_ID
        dd[3] = len(t10)
        cmd.datain[pos:pos + len(dd)] = dd
        pos += len(dd)

        # Designation Descriptor: EUI-64, 8 byte version
        eui = bytearray(8)
        # IEEE company identifier
        eui[0] = 0x11
        eui[1] = 0x22
        eui[2] = 0x33
        # vendor specific
        eui[3] = ord('a')
        eui[4] = ord('b')
        eui[5] = ord('c')
        eui[6] = ord('d')
        eui[7] = ord('e')
        dd = bytearray(4)
        dd += eui
        dd[0] = 0x01  # BINARY
        dd[1] = 0x22  # AssociatedWithTargetDevice, EUI-64
        dd[2:4] = scsi_int_to_ba(len(t10), 2)
        cmd.datain[pos:pos + len(dd)] = dd
        pos += len(dd)

        cmd.datain[2:4] = scsi_int_to_ba(pos - 4, 2)
    def execute(self, cdb, dataout, datain, sense):
        datain[0] = 15    # mode data length
        datain[2] = 0     # medium type: BLOCK_DEVICE
        datain[3] = 0x90  # device specific parameter
        datain[6] = 0     # block descriptor length

        datain[8] = 0x82  # PS=1 SPF=0 PAGECODE=0x02
        datain[9] = 0x0e

        datain[10] = 122                          # bfr:122
        datain[11] = 123                          # ber:123
        datain[12:14] = scsi_int_to_ba(2371, 2)   # bil
        datain[14:16] = scsi_int_to_ba(2372, 2)  # dtl
        datain[16:18] = scsi_int_to_ba(2373, 2)  # ctl
        datain[18:20] = scsi_int_to_ba(2374, 2)  # mbs
        datain[20] = 0xff                        # emdp:1 fa:7 dimm:1 dtdc:7
        datain[22:24] = scsi_int_to_ba(2375, 2)  # fbs
Пример #16
0
    def execute(self, cdb, dataout, datain, sense):
        datain[0] = 0x00  # QUAL:0 TYPE:0
        datain[1] = 0x83  # device identifier
        datain[2] = 0x00
        datain[3] = 0x00
        pos = 4
        
        # Designation Descriptor: T10_VENDOR_ID
        t10 = bytearray(8)
        t10[0] = 'T'
        t10[1] = 'e'
        t10[2] = 's'
        t10[3] = 't'
        t10[4] = ' '
        t10[5] = 'T'
        t10[6] = '1'
        t10[7] = '0'
        dd = bytearray(4)
        dd += t10
        dd[0] = 0x52  # iSCSI, ASCII
        dd[1] = 0xa1  # AssociatedWithTargetDevice, T10_VENDOR_ID
        dd[3] = len(t10)
        datain[pos:pos + len(dd)] = dd
        pos += len(dd)

        # Designation Descriptor: EUI-64, 8 byte version
        eui = bytearray(8)
        # IEEE company identifier
        eui[0] = 0x11
        eui[1] = 0x22
        eui[2] = 0x33
        # vendor specific
        eui[3] = 'a'
        eui[4] = 'b'
        eui[5] = 'c'
        eui[6] = 'd'
        eui[7] = 'e'
        dd = bytearray(4)
        dd += eui
        dd[0] = 0x01  # BINARY
        dd[1] = 0x22  # AssociatedWithTargetDevice, EUI-64
        dd[2:4] = scsi_int_to_ba(len(t10), 2)
        datain[pos:pos + len(dd)] = dd
        pos += len(dd)

        datain[2:4] = scsi_int_to_ba(pos - 4, 2)
    def execute(self, cdb, dataout, datain, sense):
        datain[0] = 15    # mode data length
        datain[1] = 0     # medium type: BLOCK_DEVICE
        datain[2] = 0x90  # device specific parameter
        datain[3] = 0     # block descriptor length

        datain[4] = 0x82  # PS=1 SPF=0 PAGECODE=0x02
        datain[5] = 0x0e

        datain[6] = 122                          # bfr:122
        datain[7] = 123                          # ber:123
        datain[8:10] = scsi_int_to_ba(2371, 2)   # bil
        datain[10:12] = scsi_int_to_ba(2372, 2)  # dtl
        datain[12:14] = scsi_int_to_ba(2373, 2)  # ctl
        datain[14:16] = scsi_int_to_ba(2374, 2)  # mbs
        datain[16] = 0xff                        # emdp:1 fa:7 dimm:1 dtdc:7
        datain[18:20] = scsi_int_to_ba(2375, 2)  # fbs
Пример #18
0
    def marshall_datain(cls, data):
        """
        Marshall the ModeSense10 datain.

        :param data: a dict
        :return result: a byte array
        """
        result = bytearray(8)
        encode_dict(data,
                    cls.MODESENSE10.mode_parameter_header_bits,
                    result)

        # mode page header
        for mp in data['mode_pages']:
            if not mp['spf']:
                _d = bytearray(2)
                encode_dict(mp,
                            cls.MODESENSE10.page_zero_bits,
                            _d)
            else:
                _d = bytearray(4)
                encode_dict(mp,
                            cls.MODESENSE10.sub_page_bits,
                            _d)

            if mp['page_code'] == cls.PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT:
                _mpd = bytearray(18)
                encode_dict(mp,
                            cls.MODESENSE10.element_address_bits,
                            _mpd)
            if mp['page_code'] == cls.PAGE_CODE.CONTROL:
                if not mp['spf']:
                    _mpd = bytearray(10)
                    encode_dict(mp,
                                cls.MODESENSE10.control_bits,
                                _mpd)
                elif mp['sub_page_code'] == 1:
                    _mpd = bytearray(28)
                    encode_dict(mp,
                                cls.MODESENSE10.control_extension_1_bits,
                                _mpd)
            if mp['page_code'] == cls.PAGE_CODE.DISCONNECT_RECONNECT:
                if not mp['spf']:
                    _mpd = bytearray(14)
                    encode_dict(mp,
                                cls.MODESENSE10.disconnect_reconnect_bits,
                                _mpd)

            if not mp['spf']:
                _d[1] = len(_mpd)
            else:
                _d[2:4] = scsi_int_to_ba(len(_mpd), 2)

            result += _d
            result += _mpd

        result[0] = len(result) - 1
        return result
    def marshall_datain(data):
        """
        Marshall the ModeSense10 datain.

        :param data: a dict
        :return result: a byte array
        """
        result = bytearray(8)
        encode_dict(data,
                    MODESENSE10.mode_parameter_header_bits,
                    result)

        # mode page header
        for mp in data['mode_pages']:
            if not mp['spf']:
                _d = bytearray(2)
                encode_dict(mp,
                            MODESENSE10.page_zero_bits,
                            _d)
            else:
                _d = bytearray(4)
                encode_dict(mp,
                            MODESENSE10.sub_page_bits,
                            _d)

            if mp['page_code'] == PAGE_CODE.ELEMENT_ADDRESS_ASSIGNMENT:
                _mpd = bytearray(18)
                encode_dict(mp,
                            MODESENSE10.element_address_bits,
                            _mpd)
            if mp['page_code'] == PAGE_CODE.CONTROL:
                if not mp['spf']:
                    _mpd = bytearray(10)
                    encode_dict(mp,
                                MODESENSE10.control_bits,
                                _mpd)
                elif mp['sub_page_code'] == 1:
                    _mpd = bytearray(28)
                    encode_dict(mp,
                                MODESENSE10.control_extension_1_bits,
                                _mpd)
            if mp['page_code'] == PAGE_CODE.DISCONNECT_RECONNECT:
                if not mp['spf']:
                    _mpd = bytearray(14)
                    encode_dict(mp,
                                MODESENSE10.disconnect_reconnect_bits,
                                _mpd)

            if not mp['spf']:
                _d[1] = len(_mpd)
            else:
                _d[2:4] = scsi_int_to_ba(len(_mpd), 2)

            result += _d
            result += _mpd

        result[0] = len(result) - 1
        return result
    def marshall_datain(data):
        """
        Marshall the ReportPriority datain.
        """
        result = bytearray(4)
        if not 'priority_descriptors' in data:
            result[:4] = scsi_int_to_ba(len(result), 4)
            return result

        for l in data['priority_descriptors']:
            _r = bytearray(len(l))
            _dict = dict(ReportPriority._datain_bits.copy)
            _dict.update({'transport_id': [hex(scsi_ba_to_int(len(l) - 8)), 8], })
            encode_dict(l, _dict, _r)
            result += _r

        result[:4] = scsi_int_to_ba(len(result), 4)
        return result
    def execute(self, cdb, dataout, datain, sense):
        datain[0:8] = bytearray(8)
        pos = 8

        lbas = bytearray(16)
        lbas[0:8] = scsi_int_to_ba(1023, 8)
        lbas[8:12] = scsi_int_to_ba(27, 4)
        lbas[12] = 0
        datain[pos:pos + len(lbas)] = lbas
        pos += len(lbas)

        lbas = bytearray(16)
        lbas[0:8] = scsi_int_to_ba(200000, 8)
        lbas[8:12] = scsi_int_to_ba(9999, 4)
        lbas[12] = 1
        datain[pos:pos + len(lbas)] = lbas
        pos += len(lbas)

        datain[0:4] = scsi_int_to_ba(pos - 4, 4)
    def execute(self, cdb, dataout, datain, sense):
        datain[0:8] = bytearray(8)
        pos = 8

        lbas = bytearray(16)
        lbas[0:8] = scsi_int_to_ba(1023, 8)
        lbas[8:12] = scsi_int_to_ba(27, 4)
        lbas[12] = 0
        datain[pos:pos + len(lbas)] = lbas
        pos += len(lbas)

        lbas = bytearray(16)
        lbas[0:8] = scsi_int_to_ba(200000, 8)
        lbas[8:12] = scsi_int_to_ba(9999, 4)
        lbas[12] = 1
        datain[pos:pos + len(lbas)] = lbas
        pos += len(lbas)

        datain[0:4] = scsi_int_to_ba(pos - 4, 4)
    def execute(self, cmd):
        cmd.datain[0:8] = bytearray(8)
        pos = 8

        lbas = bytearray(16)
        lbas[0:8] = scsi_int_to_ba(1023, 8)
        lbas[8:12] = scsi_int_to_ba(27, 4)
        lbas[12] = 0
        cmd.datain[pos:pos + len(lbas)] = lbas
        pos += len(lbas)

        lbas = bytearray(16)
        lbas[0:8] = scsi_int_to_ba(200000, 8)
        lbas[8:12] = scsi_int_to_ba(9999, 4)
        lbas[12] = 1
        cmd.datain[pos:pos + len(lbas)] = lbas
        pos += len(lbas)

        cmd.datain[0:4] = scsi_int_to_ba(pos - 4, 4)
    def execute(self, cmd):
        cmd.datain[0:8] = bytearray(8)
        pos = 8

        lbas = bytearray(16)
        lbas[0:8] = scsi_int_to_ba(1023, 8)
        lbas[8:12] = scsi_int_to_ba(27, 4)
        lbas[12] = 0
        cmd.datain[pos:pos + len(lbas)] = lbas
        pos += len(lbas)

        lbas = bytearray(16)
        lbas[0:8] = scsi_int_to_ba(200000, 8)
        lbas[8:12] = scsi_int_to_ba(9999, 4)
        lbas[12] = 1
        cmd.datain[pos:pos + len(lbas)] = lbas
        pos += len(lbas)

        cmd.datain[0:4] = scsi_int_to_ba(pos - 4, 4)
    def marshall_datain(cls, data):
        """
        Marshall the GetLBAStatus datain.

        :param data: a dict
        :return result: a byte array
        """
        result = bytearray(8)
        if 'lbas' not in data:
            result[:4] = scsi_int_to_ba(len(result) - 4, 4)
            return result

        for l in data['lbas']:
            _r = bytearray(16)
            encode_dict(l, cls._datain_bits, _r)

            result += _r

        result[:4] = scsi_int_to_ba(len(result) - 4, 4)
        return result
    def marshall_datain(data):
        """
        Marshall the ReportPriority datain.
        """
        result = bytearray(4)
        if not 'priority_descriptors' in data:
            result[:4] = scsi_int_to_ba(len(result), 4)
            return result

        for l in data['priority_descriptors']:
            _r = bytearray(len(l))
            _dict = dict(ReportPriority._datain_bits.copy)
            _dict.update({
                'transport_id': [hex(scsi_ba_to_int(len(l) - 8)), 8],
            })
            encode_dict(l, _dict, _r)
            result += _r

        result[:4] = scsi_int_to_ba(len(result), 4)
        return result
Пример #27
0
    def marshall_datain(cls, data):
        """
        Marshall the ReportLuns datain.

        :param data: a dict
        :return result: a byte array
        """
        result = bytearray(8)
        if 'luns' not in data:
            result[:4] = scsi_int_to_ba(len(result) - 4, 4)
            return result

        for l in data['luns']:
            _r = bytearray(8)
            encode_dict(l,
                        cls._datain_bits,
                        _r)

            result += _r
        result[:4] = scsi_int_to_ba(len(result) - 4, 4)
        return result
    def execute(self, cdb, dataout, datain, sense):
        datain[0] = 15    # mode data length
        datain[1] = 0     # medium type: BLOCK_DEVICE
        datain[2] = 0x90  # device specific parameter
        datain[3] = 0     # block descriptor length

        datain[4] = 0xca                       # PS=1 SPF=1 PAGECODE=0x0a
        datain[5] = 1                          # subpage:1
        datain[6:8] = scsi_int_to_ba(0x1c, 2)  # page length

        datain[8] = 0x07  # tcmod:1 scsip:1 ialuae:1
        datain[9] = 0x0f  # icp:15
        datain[10] = 29   # msdl:29
    def execute(self, cdb, dataout, datain, sense):
        datain[0] = 15    # mode data length
        datain[2] = 0     # medium type: BLOCK_DEVICE
        datain[3] = 0x90  # device specific parameter
        datain[6] = 0     # block descriptor length

        datain[8] = 0xca                       # PS=1 SPF=1 PAGECODE=0x0a
        datain[9] = 1                          # subpage:1
        datain[10:12] = scsi_int_to_ba(0x1c, 2)  # page length

        datain[12] = 0x07  # tcmod:1 scsip:1 ialuae:1
        datain[13] = 0x0f  # icp:15
        datain[14] = 29   # msdl:29
Пример #30
0
    def execute(self, cmd):
        cmd.datain[0] = 15  # mode data length
        cmd.datain[1] = 0  # medium type: BLOCK_DEVICE
        cmd.datain[2] = 0x90  # device specific parameter
        cmd.datain[3] = 0  # block descriptor length

        cmd.datain[4] = 0xca  # PS=1 SPF=1 PAGECODE=0x0a
        cmd.datain[5] = 1  # subpage:1
        cmd.datain[6:8] = scsi_int_to_ba(0x1c, 2)  # page length

        cmd.datain[8] = 0x07  # tcmod:1 scsip:1 ialuae:1
        cmd.datain[9] = 0x0f  # icp:15
        cmd.datain[10] = 29  # msdl:29
Пример #31
0
    def marshall_datain(cls, data):
        """
        Marshall the Inquiry datain.

        :param data: a dict with data
        :return result: a byte array
        """
        if 'page_code' not in data:
            result = bytearray(96)
            convert.encode_dict(data,
                                cls._datain_bits,
                                result)
            convert.encode_dict(data,
                                cls._standard_bits,
                                result)
            return result

        result = bytearray(4)
        convert.encode_dict(data,
                            cls._datain_bits,
                            result)
        convert.encode_dict(data,
                            cls._pagecode_bits,
                            result)
        if data['page_code'] == cls.VPD.LOGICAL_BLOCK_PROVISIONING:
            result += bytearray(4)
            convert.encode_dict(data,
                                cls._logical_block_provisioning_bits,
                                result)
        if data['page_code'] == cls.VPD.UNIT_SERIAL_NUMBER:
            result += data['unit_serial_number']
        if data['page_code'] == cls.VPD.REFERRALS:
            result += bytearray(12)
            convert.encode_dict(data,
                                cls._referrals_bits,
                                result)
        if data['page_code'] == cls.VPD.EXTENDED_INQUIRY_DATA:
            result += bytearray(60)
            convert.encode_dict(data,
                                cls._extended_bits,
                                result)
        if data['page_code'] == cls.VPD.DEVICE_IDENTIFICATION:
            for _dd in data['designator_descriptors']:
                _r = cls.marshall_designation_descriptor(_dd)
                result += _r

        result[2:4] = convert.scsi_int_to_ba(len(result) - 4, 2)
        return result
Пример #32
0
    def marshall_designator(type, data):
        if type == inquiry_enums.DESIGNATOR.VENDOR_SPECIFIC:
            return data['vendor_specific']

        if type == inquiry_enums.DESIGNATOR.T10_VENDOR_ID:
            return data['t10_vendor_id'] + data['vendor_specific_id']

        if type == inquiry_enums.DESIGNATOR.EUI_64:
            if 'identifier_extension' in data:
                return data['identifier_extension'] + \
                    scsi_int_to_ba(data['ieee_company_id'], 3) + \
                    data['vendor_specific_extension_id']
            if 'directory_id' in data:
                return scsi_int_to_ba(data['ieee_company_id'], 3) + \
                    data['vendor_specific_extension_id'] + \
                    data['directory_id']

            return scsi_int_to_ba(data['ieee_company_id'], 3) + \
                data['vendor_specific_extension_id']

        if type == inquiry_enums.DESIGNATOR.NAA:
            _r = bytearray(16)
            decode_bits(data, Inquiry._naa_type_bits, _r)
            if data['naa'] == inquiry_enums.NAA.IEEE_EXTENDED:
                encode_dict(data, Inquiry._naa_ieee_extended_bits, _r)
                return _r[:8]
            if data['naa'] == inquiry_enums.NAA.LOCALLY_ASSIGNED:
                encode_dict(data, Inquiry._naa_locally_assigned_bits, _r)
                return _r[:8]
            if data['naa'] == inquiry_enums.NAA.IEEE_REGISTERED:
                encode_dict(data, Inquiry._naa_ieee_registered_bits, _r)
                return _r[:8]
            if data['naa'] == inquiry_enums.NAA.IEEE_REGISTERED_EXTENDED:
                encode_dict(data, Inquiry._naa_ieee_registered_extended_bits,
                            _r)
                return _r[:16]

        if type == inquiry_enums.DESIGNATOR.RELATIVE_TARGET_PORT_IDENTIFIER:
            _r = bytearray(4)
            encode_dict(data, Inquiry._relative_port_bits, _r)
            return _r

        if type == inquiry_enums.DESIGNATOR.TARGET_PORTAL_GROUP:
            _r = bytearray(4)
            encode_dict(data, Inquiry._target_portal_group_bits, _r)
            return _r

        if type == inquiry_enums.DESIGNATOR.LOGICAL_UNIT_GROUP:
            _r = bytearray(4)
            encode_dict(data, Inquiry._logical_unit_group_bits, _r)
            return _r

        if type == inquiry_enums.DESIGNATOR.MD5_LOGICAL_IDENTIFIER:
            return data['md5_logical_identifier']

        if type == inquiry_enums.DESIGNATOR.SCSI_NAME_STRING:
            return ['scsi_name_string']

        if type == inquiry_enums.DESIGNATOR.PCI_EXPRESS_ROUTING_ID:
            _r = bytearray(8)
            encode_dict(data, Inquiry._pci_express_routing_id_bits, _r)
            return _r
    def execute(self, cdb, dataout, datain, sense):
        # element status header data
        data = bytearray(8)
        data[0:2] = scsi_int_to_ba(12, 2)  # first element address reported
        data[2:4] = scsi_int_to_ba(3, 2)   # number of elements available

        # first element status page, containing one element
        _d = bytearray(8)
        _d[0] = READELEMENTSTATUS.ELEMENT_TYPE.STORAGE
        _d[1] = 0x00

        _dd = bytearray(12 + 4)
        _dd[0:2] = scsi_int_to_ba(12, 2)    # element address
        _dd[2] = 0x0d                       # access, expect, full
        _dd[4] = 55                         # additional sense code
        _dd[5] = 56                         # additional sense code qualifier
        _dd[9] = 0xca                       # svalid, invert, ed medium-type==2
        _dd[10:12] = scsi_int_to_ba(27, 2)  # storage element address
        _d += _dd

        _d[2:4] = scsi_int_to_ba(len(_dd), 2)
        _d[5:8] = scsi_int_to_ba(1 * len(_dd), 3)
        data += _d

        # second element status page, containing two elements
        _d = bytearray(8)
        _d[0] = READELEMENTSTATUS.ELEMENT_TYPE.DATA_TRANSFER
        _d[1] = 0x00

        # first element
        _dd = bytearray(12 + 4)
        _dd[0:2] = scsi_int_to_ba(13, 2)    # element address
        _dd[2] = 0x0c                       # access, expect
        _dd[4] = 55                         # additional sense code
        _dd[5] = 56                         # additional sense code qualifier
        _dd[9] = 0xcf                       # svalid, invert, ed medium-type==7
        _dd[10:12] = scsi_int_to_ba(28, 2)  # storage element address
        _d += _dd

        # second element
        _dd = bytearray(12 + 4)
        _dd[0:2] = scsi_int_to_ba(14, 2)    # element address
        _dd[2] = 0x08                       # access
        _dd[4] = 55                         # additional sense code
        _dd[5] = 56                         # additional sense code qualifier
        _dd[9] = 0x86                       # svalid, medium-type==6
        _dd[10:12] = scsi_int_to_ba(29, 2)  # storage element address
        _d += _dd

        _d[2:4] = scsi_int_to_ba(len(_dd), 2)
        _d[5:8] = scsi_int_to_ba(2 * len(_dd), 3)
        data += _d

        data[5:8] = scsi_int_to_ba(len(data) - 8, 3)
        datain[:len(data)] = data[:]
Пример #34
0
    def marshall_designator(type, data):
        if type == inquiry_enums.DESIGNATOR.VENDOR_SPECIFIC:
            return data['vendor_specific']

        if type == inquiry_enums.DESIGNATOR.T10_VENDOR_ID:
            return data['t10_vendor_id'] + data['vendor_specific_id']

        if type == inquiry_enums.DESIGNATOR.EUI_64:
            if 'identifier_extension' in data:
                return data['identifier_extension'] + \
                    scsi_int_to_ba(data['ieee_company_id'], 3) + \
                    data['vendor_specific_extension_id']
            if 'directory_id' in data:
                return scsi_int_to_ba(data['ieee_company_id'], 3) + \
                    data['vendor_specific_extension_id'] + \
                    data['directory_id']

            return scsi_int_to_ba(data['ieee_company_id'], 3) + \
                data['vendor_specific_extension_id']

        if type == inquiry_enums.DESIGNATOR.NAA:
            _r = bytearray(16)
            decode_bits(data, Inquiry._naa_type_bits, _r)
            if data['naa'] == inquiry_enums.NAA.IEEE_EXTENDED:
                encode_dict(data, Inquiry._naa_ieee_extended_bits, _r)
                return _r[:8]
            if data['naa'] == inquiry_enums.NAA.LOCALLY_ASSIGNED:
                encode_dict(data, Inquiry._naa_locally_assigned_bits, _r)
                return _r[:8]
            if data['naa'] == inquiry_enums.NAA.IEEE_REGISTERED:
                encode_dict(data, Inquiry._naa_ieee_registered_bits, _r)
                return _r[:8]
            if data['naa'] == inquiry_enums.NAA.IEEE_REGISTERED_EXTENDED:
                encode_dict(data, Inquiry._naa_ieee_registered_extended_bits, _r)
                return _r[:16]

        if type == inquiry_enums.DESIGNATOR.RELATIVE_TARGET_PORT_IDENTIFIER:
            _r = bytearray(4)
            encode_dict(data, Inquiry._relative_port_bits, _r)
            return _r

        if type == inquiry_enums.DESIGNATOR.TARGET_PORTAL_GROUP:
            _r = bytearray(4)
            encode_dict(data, Inquiry._target_portal_group_bits, _r)
            return _r

        if type == inquiry_enums.DESIGNATOR.LOGICAL_UNIT_GROUP:
            _r = bytearray(4)
            encode_dict(data, Inquiry._logical_unit_group_bits, _r)
            return _r

        if type == inquiry_enums.DESIGNATOR.MD5_LOGICAL_IDENTIFIER:
            return data['md5_logical_identifier']

        if type == inquiry_enums.DESIGNATOR.SCSI_NAME_STRING:
            return ['scsi_name_string']

        if type == inquiry_enums.DESIGNATOR.PCI_EXPRESS_ROUTING_ID:
            _r = bytearray(8)
            encode_dict(data, Inquiry._pci_express_routing_id_bits, _r)
            return _r
    def execute(self, cdb, dataout, datain, sense):
        # element status header data
        data = bytearray(8)
        data[0:2] = scsi_int_to_ba(12, 2)  # first element address reported
        data[2:4] = scsi_int_to_ba(3, 2)  # number of elements available

        # first element status page, containing one element
        _d = bytearray(8)
        _d[0] = READELEMENTSTATUS.ELEMENT_TYPE.STORAGE
        _d[1] = 0x00

        _dd = bytearray(12 + 4)
        _dd[0:2] = scsi_int_to_ba(12, 2)  # element address
        _dd[2] = 0x0d  # access, expect, full
        _dd[4] = 55  # additional sense code
        _dd[5] = 56  # additional sense code qualifier
        _dd[9] = 0xca  # svalid, invert, ed medium-type==2
        _dd[10:12] = scsi_int_to_ba(27, 2)  # storage element address
        _d += _dd

        _d[2:4] = scsi_int_to_ba(len(_dd), 2)
        _d[5:8] = scsi_int_to_ba(1 * len(_dd), 3)
        data += _d

        # second element status page, containing two elements
        _d = bytearray(8)
        _d[0] = READELEMENTSTATUS.ELEMENT_TYPE.DATA_TRANSFER
        _d[1] = 0x00

        # first element
        _dd = bytearray(12 + 4)
        _dd[0:2] = scsi_int_to_ba(13, 2)  # element address
        _dd[2] = 0x0c  # access, expect
        _dd[4] = 55  # additional sense code
        _dd[5] = 56  # additional sense code qualifier
        _dd[9] = 0xcf  # svalid, invert, ed medium-type==7
        _dd[10:12] = scsi_int_to_ba(28, 2)  # storage element address
        _d += _dd

        # second element
        _dd = bytearray(12 + 4)
        _dd[0:2] = scsi_int_to_ba(14, 2)  # element address
        _dd[2] = 0x08  # access
        _dd[4] = 55  # additional sense code
        _dd[5] = 56  # additional sense code qualifier
        _dd[9] = 0x86  # svalid, medium-type==6
        _dd[10:12] = scsi_int_to_ba(29, 2)  # storage element address
        _d += _dd

        _d[2:4] = scsi_int_to_ba(len(_dd), 2)
        _d[5:8] = scsi_int_to_ba(2 * len(_dd), 3)
        data += _d

        data[5:8] = scsi_int_to_ba(len(data) - 8, 3)
        datain[:len(data)] = data[:]