in pci_vpd_lib/pci_vpd_lib.py [0:0]
def _read_resource_dt_header(self, f):
checksum = 0
buf = bytearray(f.read(1))
# not enough data, return END tag
if len(buf) < 1:
return (0xF, 0, 0)
checksum = self._combine_checksum(checksum, buf)
# handle small resource data type
if (buf[0] & 0x80) == 0:
# small resource data type header just one byte with mask
# 0b0XXXXYYY, where XXXX is a tag id and YYY is length
tag = (buf[0] & 0b1111000) >> 3
length = buf[0] & 0b111
return (tag, length, checksum)
else:
# large resource data type header consists of three bytes
# first one is 0b1XXXXXXX, where XXXXXXX is a tag id and
# next two bytes are length with first of the two being least
# significant
tag = buf[0] & 0x7F
# read the length
buf = bytearray(f.read(2))
# handle not enough data
if len(buf) < 2:
return (0xF, 0, 0)
checksum = self._combine_checksum(checksum, buf)
return (tag, buf[0] + buf[1] * 256, checksum)