xref: /openbmc/pldm/common/types.hpp (revision 97a0f48258ff6faefabb14224b9f344eda0abd82)
1 #pragma once
2 
3 #include <sdbusplus/message/types.hpp>
4 
5 #include <bitset>
6 #include <cstdint>
7 #include <functional>
8 #include <map>
9 #include <memory>
10 #include <set>
11 #include <string>
12 #include <unordered_map>
13 #include <variant>
14 #include <vector>
15 
16 namespace pldm
17 {
18 
19 using Availability = bool;
20 using eid = uint8_t;
21 using UUID = std::string;
22 using Request = std::vector<uint8_t>;
23 using Response = std::vector<uint8_t>;
24 using MCTPMsgTypes = std::vector<uint8_t>;
25 using Command = uint8_t;
26 
27 /** @brief MCTP Endpoint Medium type in string
28  *         Reserved for future purpose
29  */
30 
31 using MctpMedium = std::string;
32 /** @brief Type definition of MCTP Network Index.
33  *         uint32_t is used as defined in MCTP Endpoint D-Bus Interface
34  */
35 using NetworkId = uint32_t;
36 
37 /** @brief Type definition of MCTP name in string
38  */
39 using MctpInfoName = std::optional<std::string>;
40 
41 /** @brief Type definition of MCTP interface information between two endpoints.
42  *         eid : Endpoint EID in byte. Defined to match with MCTP D-Bus
43  *               interface
44  *         UUID : Endpoint UUID which is used to different the endpoints
45  *         MctpMedium: Endpoint MCTP Medium info (Resersed)
46  *         NetworkId: MCTP network index
47  *         name: Alias name of the endpoint, e.g. BMC, NIC, etc.
48  */
49 using MctpInfo = std::tuple<eid, UUID, MctpMedium, NetworkId, MctpInfoName>;
50 
51 /** @brief Type definition of MCTP endpoint D-Bus properties in
52  *         xyz.openbmc_project.MCTP.Endpoint D-Bus interface.
53  *
54  *         NetworkId: MCTP network index
55  *         eid : Endpoint EID in byte. Defined to match with MCTP D-Bus
56  *               interface
57  *         MCTPMsgTypes: MCTP message types
58  */
59 using MctpEndpointProps = std::tuple<NetworkId, eid, MCTPMsgTypes>;
60 
61 /** @brief Type defined for list of MCTP interface information
62  */
63 using MctpInfos = std::vector<MctpInfo>;
64 
65 /**
66  * In `Table 2 - Special endpoint IDs` of DSP0236.
67  * EID from 1 to 7 is reserved EID. So the start valid EID is 8
68  */
69 #define MCTP_START_VALID_EID 8
70 constexpr uint8_t BmcMctpEid = 8;
71 
72 #define PLDM_PLATFORM_GETPDR_MAX_RECORD_BYTES 1024
73 /* default the max event message buffer size BMC supported to 4K bytes */
74 #define PLDM_PLATFORM_EVENT_MSG_MAX_BUFFER_SIZE 4096
75 /* DSP0248 section16.9 EventMessageBufferSize Command, the default message
76  * buffer size is 256 bytes
77  */
78 #define PLDM_PLATFORM_DEFAULT_MESSAGE_BUFFER_SIZE 256
79 
80 namespace dbus
81 {
82 
83 using ObjectPath = std::string;
84 using Service = std::string;
85 using Interface = std::string;
86 using Interfaces = std::vector<std::string>;
87 using Property = std::string;
88 using PropertyType = std::string;
89 using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
90                            int64_t, uint64_t, double, std::string,
91                            std::vector<uint8_t>, std::vector<uint64_t>>;
92 
93 using PropertyMap = std::map<Property, Value>;
94 using InterfaceMap = std::map<Interface, PropertyMap>;
95 using ObjectValueTree = std::map<sdbusplus::message::object_path, InterfaceMap>;
96 
97 } // namespace dbus
98 
99 /** @brief Binding of MCTP endpoint EID to Entity Manager's D-Bus object path
100  */
101 using Configurations = std::map<dbus::ObjectPath, MctpInfo>;
102 
103 namespace fw_update
104 {
105 using InventoryPath = std::string;
106 using SoftwareName = std::string;
107 
108 // Descriptor definition
109 using DescriptorType = uint16_t;
110 using DescriptorData = std::vector<uint8_t>;
111 using VendorDefinedDescriptorTitle = std::string;
112 using VendorDefinedDescriptorData = std::vector<uint8_t>;
113 using VendorDefinedDescriptorInfo =
114     std::tuple<VendorDefinedDescriptorTitle, VendorDefinedDescriptorData>;
115 using Descriptors =
116     std::multimap<DescriptorType,
117                   std::variant<DescriptorData, VendorDefinedDescriptorInfo>>;
118 using DownstreamDeviceIndex = uint16_t;
119 using DownstreamDeviceInfo =
120     std::unordered_map<DownstreamDeviceIndex, Descriptors>;
121 
122 using DescriptorMap = std::unordered_map<eid, Descriptors>;
123 using DownstreamDescriptorMap = std::unordered_map<eid, DownstreamDeviceInfo>;
124 
125 // Component information
126 using CompClassification = uint16_t;
127 using CompIdentifier = uint16_t;
128 using SoftwareIdentifier = std::pair<eid, CompIdentifier>;
129 using CompKey = std::pair<CompClassification, CompIdentifier>;
130 using CompClassificationIndex = uint8_t;
131 using ComponentInfo = std::map<CompKey, CompClassificationIndex>;
132 using ComponentInfoMap = std::unordered_map<eid, ComponentInfo>;
133 
134 // PackageHeaderInformation
135 using PackageHeaderSize = size_t;
136 using PackageVersion = std::string;
137 using ComponentBitmapBitLength = uint16_t;
138 using PackageHeaderChecksum = uint32_t;
139 
140 // FirmwareDeviceIDRecords
141 using DeviceIDRecordCount = uint8_t;
142 using DeviceUpdateOptionFlags = std::bitset<32>;
143 using ApplicableComponents = std::vector<size_t>;
144 using ComponentImageSetVersion = std::string;
145 using FirmwareDevicePackageData = std::vector<uint8_t>;
146 using FirmwareDeviceIDRecord =
147     std::tuple<DeviceUpdateOptionFlags, ApplicableComponents,
148                ComponentImageSetVersion, Descriptors,
149                FirmwareDevicePackageData>;
150 using FirmwareDeviceIDRecords = std::vector<FirmwareDeviceIDRecord>;
151 
152 // ComponentImageInformation
153 using ComponentImageCount = uint16_t;
154 using CompComparisonStamp = uint32_t;
155 using CompOptions = std::bitset<16>;
156 using ReqCompActivationMethod = std::bitset<16>;
157 using CompLocationOffset = uint32_t;
158 using CompSize = uint32_t;
159 using CompVersion = std::string;
160 using ComponentImageInfo =
161     std::tuple<CompClassification, CompIdentifier, CompComparisonStamp,
162                CompOptions, ReqCompActivationMethod, CompLocationOffset,
163                CompSize, CompVersion>;
164 using ComponentImageInfos = std::vector<ComponentImageInfo>;
165 
166 enum class ComponentImageInfoPos : size_t
167 {
168     CompClassificationPos = 0,
169     CompIdentifierPos = 1,
170     CompComparisonStampPos = 2,
171     CompOptionsPos = 3,
172     ReqCompActivationMethodPos = 4,
173     CompLocationOffsetPos = 5,
174     CompSizePos = 6,
175     CompVersionPos = 7,
176 };
177 
178 } // namespace fw_update
179 
180 namespace pdr
181 {
182 
183 using EID = uint8_t;
184 using TerminusHandle = uint16_t;
185 using TerminusID = uint8_t;
186 using SensorID = uint16_t;
187 using EntityType = uint16_t;
188 using EntityInstance = uint16_t;
189 using ContainerID = uint16_t;
190 using StateSetId = uint16_t;
191 using CompositeCount = uint8_t;
192 using SensorOffset = uint8_t;
193 using EventState = uint8_t;
194 using TerminusValidity = uint8_t;
195 using EffecterID = uint16_t;
196 using EntityName = std::string;
197 using SensorCount = uint8_t;
198 using NameLanguageTag = std::string;
199 using SensorName = std::string;
200 using SensorAuxiliaryNames = std::tuple<
201     SensorID, SensorCount,
202     std::vector<std::vector<std::pair<NameLanguageTag, SensorName>>>>;
203 using AuxiliaryNames = std::vector<std::pair<NameLanguageTag, std::string>>;
204 
205 /** @struct EntityKey
206  *
207  *  EntityKey uniquely identifies the PLDM entity and a combination of Entity
208  *  Type, Entity Instance Number, Entity Container ID
209  *
210  */
211 struct EntityKey
212 {
213     EntityType type;            //!< Entity type
214     EntityInstance instanceIdx; //!< Entity instance number
215     ContainerID containerId;    //!< Entity container ID
216 
operator ==pldm::pdr::EntityKey217     bool operator==(const EntityKey& e) const
218     {
219         return ((type == e.type) && (instanceIdx == e.instanceIdx) &&
220                 (containerId == e.containerId));
221     }
222 };
223 
224 using EntityKey = struct EntityKey;
225 using EntityAuxiliaryNames = std::tuple<EntityKey, AuxiliaryNames>;
226 
227 //!< Subset of the State Set that is supported by a effecter/sensor
228 using PossibleStates = std::set<uint8_t>;
229 //!< Subset of the State Set that is supported by each effecter/sensor in a
230 //!< composite efffecter/sensor
231 using CompositeSensorStates = std::vector<PossibleStates>;
232 using EntityInfo = std::tuple<ContainerID, EntityType, EntityInstance>;
233 using SensorInfo =
234     std::tuple<EntityInfo, CompositeSensorStates, std::vector<StateSetId>>;
235 
236 } // namespace pdr
237 
238 namespace bios
239 {
240 
241 using AttributeName = std::string;
242 using AttributeType = std::string;
243 using ReadonlyStatus = bool;
244 using DisplayName = std::string;
245 using Description = std::string;
246 using MenuPath = std::string;
247 using CurrentValue = std::variant<int64_t, std::string>;
248 using DefaultValue = std::variant<int64_t, std::string>;
249 using OptionString = std::string;
250 using OptionValue = std::variant<int64_t, std::string>;
251 using ValueDisplayName = std::string;
252 using Option =
253     std::vector<std::tuple<OptionString, OptionValue, ValueDisplayName>>;
254 using BIOSTableObj =
255     std::tuple<AttributeType, ReadonlyStatus, DisplayName, Description,
256                MenuPath, CurrentValue, DefaultValue, Option>;
257 using BaseBIOSTable = std::map<AttributeName, BIOSTableObj>;
258 using PendingObj = std::tuple<AttributeType, CurrentValue>;
259 using PendingAttributes = std::map<AttributeName, PendingObj>;
260 using Callback = std::function<void()>;
261 
262 } // namespace bios
263 
264 } // namespace pldm
265