/src/pldm/fw-update/package_parser.hpp
Line | Count | Source |
1 | | #pragma once |
2 | | |
3 | | #include "common/types.hpp" |
4 | | |
5 | | #include <libpldm/firmware_update.h> |
6 | | |
7 | | #include <cstdint> |
8 | | #include <memory> |
9 | | #include <vector> |
10 | | |
11 | | namespace pldm |
12 | | { |
13 | | |
14 | | namespace fw_update |
15 | | { |
16 | | |
17 | | /** @class PackageParser |
18 | | * |
19 | | * PackageParser is the class for parsing the PLDM firmware update package. |
20 | | */ |
21 | | class PackageParser |
22 | | { |
23 | | public: |
24 | | PackageParser() = delete; |
25 | | PackageParser(const PackageParser&) = delete; |
26 | | PackageParser(PackageParser&&) = default; |
27 | | PackageParser& operator=(const PackageParser&) = delete; |
28 | | PackageParser& operator=(PackageParser&&) = delete; |
29 | 0 | ~PackageParser() = default; |
30 | | |
31 | | /** @brief Constructor |
32 | | * |
33 | | * @param[in] pkgHeaderSize - Size of package header section |
34 | | * @param[in] pkgVersion - Package version |
35 | | * @param[in] componentBitmapBitLength - The number of bits used to |
36 | | * represent the bitmap in the |
37 | | * ApplicableComponents field for a |
38 | | * matching device. |
39 | | */ |
40 | | explicit PackageParser(PackageHeaderSize pkgHeaderSize, |
41 | | const PackageVersion& pkgVersion, |
42 | | ComponentBitmapBitLength componentBitmapBitLength) : |
43 | 0 | pkgHeaderSize(pkgHeaderSize), pkgVersion(pkgVersion), |
44 | 0 | componentBitmapBitLength(componentBitmapBitLength) |
45 | 0 | {} |
46 | | |
47 | | /** @brief Parse the firmware update package header |
48 | | * |
49 | | * @param[in] pkgHdr - Package header |
50 | | * @param[in] pkgSize - Size of the firmware update package |
51 | | * |
52 | | * @note Throws exception is parsing fails |
53 | | */ |
54 | | void parse(const std::vector<uint8_t>& pkgHdr, uintmax_t pkgSize); |
55 | | |
56 | | /** @brief Get firmware device ID records from the package |
57 | | * |
58 | | * @return if parsing the package is successful, return firmware device ID |
59 | | * records |
60 | | */ |
61 | | const FirmwareDeviceIDRecords& getFwDeviceIDRecords() const |
62 | 0 | { |
63 | 0 | return fwDeviceIDRecords; |
64 | 0 | } |
65 | | |
66 | | /** @brief Get component image information from the package |
67 | | * |
68 | | * @return if parsing the package is successful, return component image |
69 | | * information |
70 | | */ |
71 | | const ComponentImageInfos& getComponentImageInfos() const |
72 | 0 | { |
73 | 0 | return componentImageInfos; |
74 | 0 | } |
75 | | |
76 | | /** @brief Device identifiers of the managed FDs */ |
77 | | const PackageHeaderSize pkgHeaderSize; |
78 | | |
79 | | /** @brief Package version string */ |
80 | | const PackageVersion pkgVersion; |
81 | | |
82 | | protected: |
83 | | /** @brief Parse the firmware device identification area |
84 | | * |
85 | | * @param[in] deviceIdRecCount - count of firmware device ID records |
86 | | * @param[in] pkgHdr - firmware package header |
87 | | * @param[in] offset - offset in package header which is the start of the |
88 | | * firmware device identification area |
89 | | * |
90 | | * @return On success return the offset which is the end of the firmware |
91 | | * device identification area, on error throw exception. |
92 | | */ |
93 | | size_t parseFDIdentificationArea(DeviceIDRecordCount deviceIdRecCount, |
94 | | const std::vector<uint8_t>& pkgHdr, |
95 | | size_t offset); |
96 | | |
97 | | /** @brief Parse the component image information area |
98 | | * |
99 | | * @param[in] compImageCount - component image count |
100 | | * @param[in] pkgHdr - firmware package header |
101 | | * @param[in] offset - offset in package header which is the start of the |
102 | | * component image information area |
103 | | * |
104 | | * @return On success return the offset which is the end of the component |
105 | | * image information area, on error throw exception. |
106 | | */ |
107 | | size_t parseCompImageInfoArea(ComponentImageCount compImageCount, |
108 | | const std::vector<uint8_t>& pkgHdr, |
109 | | size_t offset); |
110 | | |
111 | | /** @brief Validate the total size of the package |
112 | | * |
113 | | * Verify the total size of the package is the sum of package header and |
114 | | * the size of each component. |
115 | | * |
116 | | * @param[in] pkgSize - firmware update package size |
117 | | * |
118 | | * @note Throws exception if validation fails |
119 | | */ |
120 | | void validatePkgTotalSize(uintmax_t pkgSize); |
121 | | |
122 | | /** @brief Firmware Device ID Records in the package */ |
123 | | FirmwareDeviceIDRecords fwDeviceIDRecords; |
124 | | |
125 | | /** @brief Component Image Information in the package */ |
126 | | ComponentImageInfos componentImageInfos; |
127 | | |
128 | | /** @brief The number of bits that will be used to represent the bitmap in |
129 | | * the ApplicableComponents field for matching device. The value |
130 | | * shall be a multiple of 8 and be large enough to contain a bit |
131 | | * for each component in the package. |
132 | | */ |
133 | | const ComponentBitmapBitLength componentBitmapBitLength; |
134 | | }; |
135 | | |
136 | | /** @brief Parse the package header information |
137 | | * |
138 | | * @param[in] pkgHdrInfo - package header information section in the package |
139 | | * |
140 | | * @return On success return the PackageParser for the header format version |
141 | | * on failure return nullptr |
142 | | */ |
143 | | std::unique_ptr<PackageParser> parsePkgHeader(std::vector<uint8_t>& pkgHdrInfo); |
144 | | |
145 | | } // namespace fw_update |
146 | | |
147 | | } // namespace pldm |