def __new__(cls, camera, frame): """ Convert a phloxar-dc1394 frame into a Frame instance. :param camera: :param frame: :return: """ dtype = ARRAY(c_byte, frame.contents.image_bytes) buf = dtype.from_address(frame.contents.image) width, height = frame.contents.size pixels = width * height endian = frame.contents.little_endian and '<' or '>' type_str = '%su%i' % (endian, frame.contents.image_bytes / pixels) img = ndarray.__new__(cls, shape=(height, width), dtype=type_str, buffer=buf) img.frame_id = frame.contents.id img.frames_behind = frame.contents.frames_behind img.position = frame.contents.position img.packet_size = frame.contents.packet_size img.packets_per_frame = frame.contents.packet_per_frame img.timestamp = frame.contents.timestamp img.video_mode = video_modes[frame.contents.video_mode] img.data_depth = frame.contents.data_depth img.color_coding = color_codings[frame.contents.color_coding] img.color_filter = frame.contents.color_filter img.yuv_byte_order = frame.contents.yuv_byte_order img.stride = frame.contents.stride # save camera and frame for enqueue() img._frame = frame img._cam = camera return img
class ifr_ifru(Union): _fields_ = [('ifru_addr', sockaddr), ('ifru_dstaddr', sockaddr), ('ifru_broadaddr', sockaddr), ('ifru_netmask', sockaddr), ('ifru_hwaddr', sockaddr), ('ifru_flags', c_short), ('ifru_ivalue', c_int), ('ifru_mtu', c_int), ('ifru_map', ifmap), ('ifru_slave', ARRAY(c_char, 16)), ('ifru_newname', ARRAY(c_char, 16)), ('ifru_data', c_char_p)]
def __new__(cls, camera, frame): """ Convert a dc1394 frame into an Frame instance. """ dtyp = ARRAY(c_byte, frame.contents.image_bytes) buf = dtyp.from_address(frame.contents.image) width, height = frame.contents.size pixels = width*height endianess = frame.contents.little_endian and "<" or ">" typ_string = "%su%i" % (endianess, frame.contents.image_bytes/pixels) img = ndarray.__new__(cls, shape=(height, width), dtype=typ_string, buffer=buf) img.frame_id = frame.contents.id img.frames_behind = frame.contents.frames_behind img.position = frame.contents.position img.packet_size = frame.contents.packet_size img.packets_per_frame = frame.contents.packets_per_frame img.timestamp = frame.contents.timestamp img.video_mode = video_mode_vals[frame.contents.video_mode] img.data_depth = frame.contents.data_depth img.color_coding = color_coding_vals[frame.contents.color_coding] img.color_filter = frame.contents.color_filter img.yuv_byte_order = frame.contents.yuv_byte_order img.stride = frame.contents.stride # save camera and frame for enqueue() img._frame = frame img._cam = camera return img
class FlashMap(Structure): FLASH_MAP_SIGNATURE = 'FLMP' FLASH_MAP_ATTRIBUTES = { "PRIMARY_REGION": 0x00000000, "BACKUP_REGION": 0x00000001, } FLASH_MAP_DESC_FLAGS = { "TOP_SWAP": 0x00000001, "REDUNDANT": 0x00000002, "NON_REDUNDANT": 0x00000004, "NON_VOLATILE": 0x00000008, "COMPRESSED": 0x00000010, "BACKUP": 0x00000040, } _pack_ = 1 _fields_ = [ ('sig', ARRAY(c_char, 4)), ('version', c_uint16), ('length', c_uint16), ('attributes', c_uint8), ('reserved', ARRAY(c_char, 3)), ('romsize', c_uint32), ]
def __new__(cls, camera, frame): """ Convert a dc1394 frame into an Frame instance. """ dtyp = ARRAY(c_byte, frame.contents.image_bytes) buf = dtyp.from_address(frame.contents.image) width, height = frame.contents.size pixels = width * height endianess = frame.contents.little_endian and "<" or ">" typ_string = "%su%i" % (endianess, frame.contents.image_bytes / pixels) img = ndarray.__new__(cls, shape=(height, width), dtype=typ_string, buffer=buf) img.frame_id = frame.contents.id img.frames_behind = frame.contents.frames_behind img.position = frame.contents.position img.packet_size = frame.contents.packet_size img.packets_per_frame = frame.contents.packets_per_frame img.timestamp = frame.contents.timestamp img.video_mode = video_mode_vals[frame.contents.video_mode] img.data_depth = frame.contents.data_depth img.color_coding = color_coding_vals[frame.contents.color_coding] img.color_filter = frame.contents.color_filter img.yuv_byte_order = frame.contents.yuv_byte_order img.stride = frame.contents.stride # save camera and frame for enqueue() img._frame = frame img._cam = camera return img
class InAddr6Union(Union): """Struct `in_addr6` from `<netinet6/in6.h>`.""" _fields_ = [ ('u6_addr8', ARRAY(uint8_t, 16)), ('u6_addr16', ARRAY(uint16_t, 8)), ('u6_addr32', ARRAY(uint32_t, 4)), ]
class KEY_USAGE_STRUCTURE(Structure): _pack_ = 1 _fields_ = [ ("key_usage", ARRAY(c_uint8, 16)), ("key_reserved", ARRAY(c_uint8, 16)), ("key_policy", c_uint8), ("key_hash_algorithm", c_uint8), ("key_hash_size", c_uint16), ("key_hash", ARRAY(c_uint8, 64)), ]
class SUBPART_DIR_HEADER(Structure): _pack_ = 1 _fields_ = [ ('header_marker', ARRAY(c_char, 4)), ('num_of_entries', c_uint32), ('header_version', c_uint8), ('entry_version', c_uint8), ('header_length', c_uint8), ('checksum', c_uint8), ('sub_part_name', ARRAY(c_char, 4)), ]
class SUBPART_DIR_HEADER(Structure): _pack_ = 1 _fields_ = [ ('HeaderMarker', ARRAY(c_char, 4)), ('NumOfEntries', c_uint32), ('HeaderVersion', c_uint8), ('EntryVersion', c_uint8), ('HeaderLength', c_uint8), ('Checksum', c_uint8), ('SubPartName', ARRAY(c_char, 4)), ]
class SIGNATURE_HDR (Structure): _pack_ = 1 _fields_ = [ ('Identifier', ARRAY(c_char, 4)), ('SigSize', c_uint16), ('SigType', c_uint8), ('HashAlg', c_uint8), ('Signature', ARRAY(c_uint8, 0)), ] def __init__(self): self.Identifier = b'SIGN'
class PUB_KEY_HDR (Structure): _pack_ = 1 _fields_ = [ ('Identifier', ARRAY(c_char, 4)), # signature ('P', 'U', 'B', 'K') ('KeySize', c_uint16), # Length of Public Key ('KeyType', c_uint8), # RSA or ECC ('Reserved', ARRAY(c_uint8, 1)), ('KeyData', ARRAY(c_uint8, 0)), ] def __init__(self): self.Identifier = b'PUBK'
class CDATA_BLOB_HEADER(Structure): ATTR_SIGNED = 1 << 0 ATTR_MERGED = 1 << 7 _pack_ = 1 _fields_ = [ ('Signature', ARRAY(c_char, 4)), ('HeaderLength', c_uint8), ('Attribute', c_uint8), ('Reserved', ARRAY(c_char, 2)), ('UsedLength', c_uint32), ('TotalLength', c_uint32), ]
class EFI_FIRMWARE_VOLUME_HEADER(Structure): _fields_ = [ ("ZeroVector", ARRAY(c_uint8, 16)), ("FileSystemGuid", ARRAY(c_uint8, 16)), ("FvLength", c_uint64), ("Signature", ARRAY(c_char, 4)), ("Attributes", c_uint32), ("HeaderLength", c_uint16), ("Checksum", c_uint16), ("ExtHeaderOffset", c_uint16), ("Reserved", c_uint8), ("Revision", c_uint8), ]
class FIRMWARE_KEY_MANIFEST(Structure): number_of_keys = 1 _pack_ = 1 _fields_ = [ ("manifest_header", FIRMWARE_MANIFEST_HEADER), ("extension_type", c_uint32), ("extension_length", c_uint32), ("key_manifest_type", c_uint32), ("key_manifest_svn", c_uint32), ("oem_id", c_uint16), ("key_manifest_id", c_uint8), ("reserved", c_uint8), ("reserved2", ARRAY(c_uint8, 12)), ("num_of_keys", c_uint32), ("key_usage_array", ARRAY(KEY_USAGE_STRUCTURE, number_of_keys)), ]
class PyTupleObject(Structure): _fields_ = [ ('ob_refcnt', c_size_t), ('ob_type', py_object), ('ob_size', c_size_t), ('ob_item', ARRAY(py_object, 1)), ]
class BPDT_HEADER(Structure): _pack_ = 1 _fields_ = [ ('Signature', c_uint32), ('DescCnt', c_uint16), ('Version', c_uint16), ('XorSum', c_uint32), ('IfwiVer', c_uint32), ('Reserved', ARRAY(c_uint8, 8)) ]
class FTW_HEADER(Structure): _fields_ = [ ("Signature", ARRAY(c_uint8, 16)), ("Crc", c_uint32), ("Reserved", c_uint32), ("WriteQueueSize", c_uint64), ]
def make_compound_ctype(self, varname): """ Create a ctypes type that corresponds to a compound type in memory. """ # look up the type name compoundname = self.get_var_type(varname) nfields = self.inq_compound(compoundname) # for all the fields look up the type, rank and shape fields = [] for i in range(nfields): (fieldname, fieldtype, fieldrank, fieldshape) = self.inq_compound_field(compoundname, i) assert fieldrank <= 1 fieldctype = CTYPESMAP[fieldtype] if fieldrank == 1: fieldctype = fieldctype * fieldshape[0] fields.append((fieldname, fieldctype)) # create a new structure class COMPOUND(Structure): _fields_ = fields # if we have a rank 1 array, create an array rank = self.get_var_rank(varname) assert rank <= 1, "we can't handle >=2 dimensional compounds yet" if rank == 1: shape = self.get_var_shape(varname) valtype = POINTER(ARRAY(COMPOUND, shape[0])) else: valtype = POINTER(COMPOUND) # return the custom type return valtype
def encode(self, requestor_id: int, request_sequence_number: int, ran_function_id: int, call_process_id: bytes, control_header: bytes, control_message: bytes, control_ack_request: int) -> Tuple[int, bytes]: """ Function that creates and returns a payload according to e2ap's RICControlRequestMessage. Raise Exception when the payload of RICControlRequestMessage cannot be created. Parameters ---------- requestor_id: int request_sequence_number: int ran_function_id: int call_process_id: bytes control_header: bytes control_message: bytes control_ack_request: int Returns Tuple[int, bytes] int : RICControlRequestMessage type payload length bytes : RICControlRequestMessage type payload ------- """ call_process_id_buffer = ARRAY(c_uint8, len(call_process_id))() for idx in range(len(call_process_id)): call_process_id_buffer[idx] = c_uint8(call_process_id[idx]) call_header_buffer = ARRAY(c_uint8, len(control_header))() for idx in range(len(control_header)): call_header_buffer[idx] = c_uint8(control_header[idx]) call_message_buffer = ARRAY(c_uint8, len(control_message))() for idx in range(len(control_message)): call_message_buffer[idx] = c_uint8(control_message[idx]) buf = ARRAY(c_uint8, 1024)() size: int = _asn1_encode_controlReqMsg(buf, c_size_t(1024), c_long(requestor_id), c_long(request_sequence_number), c_long(ran_function_id), call_process_id_buffer, c_size_t( len(call_process_id_buffer)), call_header_buffer, c_size_t(len(call_header_buffer)), call_message_buffer, c_size_t(len(call_message_buffer)), c_long(control_ack_request)) if size < 0: raise Exception("Could not create payload.") return size, bytes(buf)
class FIRMWARE_BLOB_MANIFEST(Structure): _pack_ = 1 _fields_ = [ ("manifest_header", FIRMWARE_MANIFEST_HEADER), ("extension_type", c_uint32), ("extension_length", c_uint32), ("package_name", c_uint32), ("version_control_num", c_uint64), ("usage_bitmap", ARRAY(c_uint8, 16)), ("svn", c_uint32), ("fw_type", c_uint8), ("fw_subtype", c_uint8), ("reserved", c_uint16), ("num_of_devices", c_uint32), ("device_list", ARRAY(c_uint32, 8)), ("metadata_entries", ARRAY(METADATA_ENTRY, 1)), ]
class BIOS_ENTRY(Structure): _pack_ = 1 _fields_ = [ ('Name', ARRAY(c_char, 4)), ('Offset', c_uint32), ('Length', c_uint32), ('Reserved', c_uint32), ]
class SUBPART_DIR_ENTRY(Structure): _pack_ = 1 _fields_ = [ ("name", ARRAY(c_char, 12)), ("offset", c_uint32), ("length", c_uint32), ("module_type", c_uint32), ]
class EFI_GUID_DEFINED_SECTION(Structure): _fields_ = [ ("SectionDefinitionGuid", ARRAY(c_uint8, 16)), ("DataOffset", c_uint16), ("Attributes", c_uint16), ("Type", c_uint8), ("Attributes", c_uint8), ]
class BIOS_ENTRY(Structure): _pack_ = 1 _fields_ = [ ('name', ARRAY(c_char, 4)), ('offset', c_uint32), ('length', c_uint32), ('reserved', c_uint32), ]
class FLASH_MAP_DESC(Structure): _pack_ = 1 _fields_ = [ ('sig', ARRAY(c_char, 4)), ('flags', c_uint32), ('offset', c_uint32), ('size', c_uint32), ]
class FlashMapDesc(Structure): _pack_ = 1 _fields_ = [ ('sig', ARRAY(c_char, 4)), ('flags', c_uint32), ('offset', c_uint32), ('size', c_uint32), ]
def __init__(self, peers=None): if peers is None: self.length = c_int(0) self.peers = c_void_p() else: peer_length = len(peers) peer_array = ARRAY(c_int, peer_length) self.length = c_int(peer_length) self.peers = cast(c_void_p, peer_array(peers))
class SUBPART_DIR_ENTRY(Structure): _pack_ = 1 _fields_ = [ ('entry_name', ARRAY(c_char, 12)), ('entry_offset', c_uint32, 24), ('reserved1', c_uint32, 8), ('entry_size', c_uint32), ('reserved2', c_uint32), ]
class SUBPART_DIR_ENTRY(Structure): _pack_ = 1 _fields_ = [ ('EntryName', ARRAY(c_char, 12)), ('EntryOffset', c_uint32, 24), ('Reserved1', c_uint32, 8), ('EntrySize', c_uint32), ('Reserved2', c_uint32), ]
class SPI_DESCRIPTOR(Structure): DESC_SIGNATURE = 0x0FF0A55A FLASH_REGIONS = { "descriptor": 0x0, "bios": 0x4, "txe": 0x8, "pdr": 0x10, "dev_expansion": 0x14, } _pack_ = 1 _fields_ = [ ('Reserved', ARRAY(c_char, 16)), ('FlValSig', c_uint32), ('FlMap0', c_uint32), ('FlMap1', c_uint32), ('FlMap2', c_uint32), ('Remaining', ARRAY(c_char, 0x1000 - 0x20)), ]
class VARIABLE_STORE_HEADER(Structure): _fields_ = [ ("Signature", ARRAY(c_uint8, 16)), ("Size", c_uint32), ("Format", c_uint8), ("State", c_uint8), ("Reserved", c_uint16), ("Reserved1", c_uint32), ]