2 # Module that encodes and decodes a FMP_PAYLOAD_HEADER with a payload.
3 # The FMP_PAYLOAD_HEADER is processed by the FmpPayloadHeaderLib in the
6 # Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
7 # This program and the accompanying materials
8 # are licensed and made available under the terms and conditions of the BSD License
9 # which accompanies this distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 def _SIGNATURE_32 (A
, B
, C
, D
):
23 return struct
.unpack ('=I',bytearray (A
+ B
+ C
+ D
, 'ascii'))[0]
25 def _SIGNATURE_32_TO_STRING (Signature
):
26 return struct
.pack ("<I", Signature
).decode ()
28 class FmpPayloadHeaderClass (object):
34 # UINT32 LowestSupportedVersion;
35 # } FMP_PAYLOAD_HEADER;
37 # #define FMP_PAYLOAD_HEADER_SIGNATURE SIGNATURE_32 ('M', 'S', 'S', '1')
39 _StructFormat
= '<IIII'
40 _StructSize
= struct
.calcsize (_StructFormat
)
42 _FMP_PAYLOAD_HEADER_SIGNATURE
= _SIGNATURE_32 ('M', 'S', 'S', '1')
46 self
.Signature
= self
._FMP
_PAYLOAD
_HEADER
_SIGNATURE
47 self
.HeaderSize
= self
._StructSize
48 self
.FwVersion
= 0x00000000
49 self
.LowestSupportedVersion
= 0x00000000
53 FmpPayloadHeader
= struct
.pack (
58 self
.LowestSupportedVersion
61 return FmpPayloadHeader
+ self
.Payload
63 def Decode (self
, Buffer
):
64 if len (Buffer
) < self
._StructSize
:
66 (Signature
, HeaderSize
, FwVersion
, LowestSupportedVersion
) = \
69 Buffer
[0:self
._StructSize
]
71 if Signature
!= self
._FMP
_PAYLOAD
_HEADER
_SIGNATURE
:
73 if HeaderSize
< self
._StructSize
:
75 self
.Signature
= Signature
76 self
.HeaderSize
= HeaderSize
77 self
.FwVersion
= FwVersion
78 self
.LowestSupportedVersion
= LowestSupportedVersion
79 self
.Payload
= Buffer
[self
.HeaderSize
:]
87 print ('FMP_PAYLOAD_HEADER.Signature = {Signature:08X} ({SignatureString})'.format (Signature
= self
.Signature
, SignatureString
= _SIGNATURE_32_TO_STRING (self
.Signature
)))
88 print ('FMP_PAYLOAD_HEADER.HeaderSize = {HeaderSize:08X}'.format (HeaderSize
= self
.HeaderSize
))
89 print ('FMP_PAYLOAD_HEADER.FwVersion = {FwVersion:08X}'.format (FwVersion
= self
.FwVersion
))
90 print ('FMP_PAYLOAD_HEADER.LowestSupportedVersion = {LowestSupportedVersion:08X}'.format (LowestSupportedVersion
= self
.LowestSupportedVersion
))
91 print ('sizeof (Payload) = {Size:08X}'.format (Size
= len (self
.Payload
)))