xref: /openbmc/pldm/common/types.hpp (revision c40d4a68684a114b6a26adeca40b49146aa2c319)
1 #pragma once
2 
3 #include <sdbusplus/message/types.hpp>
4 
5 #include <bitset>
6 #include <cstdint>
7 #include <map>
8 #include <set>
9 #include <string>
10 #include <unordered_map>
11 #include <variant>
12 #include <vector>
13 
14 namespace pldm
15 {
16 
17 using Availability = bool;
18 using eid = uint8_t;
19 using UUID = std::string;
20 using Request = std::vector<uint8_t>;
21 using Response = std::vector<uint8_t>;
22 using MCTPMsgTypes = std::vector<uint8_t>;
23 using Command = uint8_t;
24 
25 /** @brief MCTP Endpoint Medium type in string
26  *         Reserved for future purpose
27  */
28 
29 using MctpMedium = std::string;
30 /** @brief Type definition of MCTP Network Index.
31  *         uint32_t is used as defined in MCTP Endpoint D-Bus Interface
32  */
33 using NetworkId = uint32_t;
34 
35 /** @brief Type definition of MCTP name in string
36  */
37 using MctpInfoName = std::optional<std::string>;
38 
39 /** @brief Type definition of MCTP interface information between two endpoints.
40  *         eid : Endpoint EID in byte. Defined to match with MCTP D-Bus
41  *               interface
42  *         UUID : Endpoint UUID which is used to different the endpoints
43  *         MctpMedium: Endpoint MCTP Medium info (Resersed)
44  *         NetworkId: MCTP network index
45  *         name: Alias name of the endpoint, e.g. BMC, NIC, etc.
46  */
47 using MctpInfo = std::tuple<eid, UUID, MctpMedium, NetworkId, MctpInfoName>;
48 
49 /** @brief Type definition of MCTP endpoint D-Bus properties in
50  *         xyz.openbmc_project.MCTP.Endpoint D-Bus interface.
51  *
52  *         NetworkId: MCTP network index
53  *         eid : Endpoint EID in byte. Defined to match with MCTP D-Bus
54  *               interface
55  *         MCTPMsgTypes: MCTP message types
56  */
57 using MctpEndpointProps = std::tuple<NetworkId, eid, MCTPMsgTypes>;
58 
59 /** @brief Type defined for list of MCTP interface information
60  */
61 using MctpInfos = std::vector<MctpInfo>;
62 
63 /**
64  * In `Table 2 - Special endpoint IDs` of DSP0236.
65  * EID from 1 to 7 is reserved EID. So the start valid EID is 8
66  */
67 #define MCTP_START_VALID_EID 8
68 constexpr uint8_t BmcMctpEid = 8;
69 
70 #define PLDM_PLATFORM_GETPDR_MAX_RECORD_BYTES 1024
71 /* default the max event message buffer size BMC supported to 4K bytes */
72 #define PLDM_PLATFORM_EVENT_MSG_MAX_BUFFER_SIZE 4096
73 /* DSP0248 section16.9 EventMessageBufferSize Command, the default message
74  * buffer size is 256 bytes
75  */
76 #define PLDM_PLATFORM_DEFAULT_MESSAGE_BUFFER_SIZE 256
77 
78 namespace dbus
79 {
80 
81 using ObjectPath = std::string;
82 using Service = std::string;
83 using Interface = std::string;
84 using Interfaces = std::vector<std::string>;
85 using Property = std::string;
86 using PropertyType = std::string;
87 using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
88                            int64_t, uint64_t, double, std::string,
89                            std::vector<uint8_t>, std::vector<uint64_t>>;
90 
91 using PropertyMap = std::map<Property, Value>;
92 using InterfaceMap = std::map<Interface, PropertyMap>;
93 using ObjectValueTree = std::map<sdbusplus::message::object_path, InterfaceMap>;
94 
95 } // namespace dbus
96 
97 /** @brief Binding of MCTP endpoint EID to Entity Manager's D-Bus object path
98  */
99 using Configurations = std::map<dbus::ObjectPath, MctpInfo>;
100 
101 namespace fw_update
102 {
103 
104 // Descriptor definition
105 using DescriptorType = uint16_t;
106 using DescriptorData = std::vector<uint8_t>;
107 using VendorDefinedDescriptorTitle = std::string;
108 using VendorDefinedDescriptorData = std::vector<uint8_t>;
109 using VendorDefinedDescriptorInfo =
110     std::tuple<VendorDefinedDescriptorTitle, VendorDefinedDescriptorData>;
111 using Descriptors =
112     std::multimap<DescriptorType,
113                   std::variant<DescriptorData, VendorDefinedDescriptorInfo>>;
114 using DownstreamDeviceIndex = uint16_t;
115 using DownstreamDeviceInfo =
116     std::unordered_map<DownstreamDeviceIndex, Descriptors>;
117 
118 using DescriptorMap = std::unordered_map<eid, Descriptors>;
119 using DownstreamDescriptorMap = std::unordered_map<eid, DownstreamDeviceInfo>;
120 
121 // Component information
122 using CompClassification = uint16_t;
123 using CompIdentifier = uint16_t;
124 using CompKey = std::pair<CompClassification, CompIdentifier>;
125 using CompClassificationIndex = uint8_t;
126 using ComponentInfo = std::map<CompKey, CompClassificationIndex>;
127 using ComponentInfoMap = std::unordered_map<eid, ComponentInfo>;
128 
129 // PackageHeaderInformation
130 using PackageHeaderSize = size_t;
131 using PackageVersion = std::string;
132 using ComponentBitmapBitLength = uint16_t;
133 using PackageHeaderChecksum = uint32_t;
134 
135 // FirmwareDeviceIDRecords
136 using DeviceIDRecordCount = uint8_t;
137 using DeviceUpdateOptionFlags = std::bitset<32>;
138 using ApplicableComponents = std::vector<size_t>;
139 using ComponentImageSetVersion = std::string;
140 using FirmwareDevicePackageData = std::vector<uint8_t>;
141 using FirmwareDeviceIDRecord =
142     std::tuple<DeviceUpdateOptionFlags, ApplicableComponents,
143                ComponentImageSetVersion, Descriptors,
144                FirmwareDevicePackageData>;
145 using FirmwareDeviceIDRecords = std::vector<FirmwareDeviceIDRecord>;
146 
147 // ComponentImageInformation
148 using ComponentImageCount = uint16_t;
149 using CompComparisonStamp = uint32_t;
150 using CompOptions = std::bitset<16>;
151 using ReqCompActivationMethod = std::bitset<16>;
152 using CompLocationOffset = uint32_t;
153 using CompSize = uint32_t;
154 using CompVersion = std::string;
155 using ComponentImageInfo =
156     std::tuple<CompClassification, CompIdentifier, CompComparisonStamp,
157                CompOptions, ReqCompActivationMethod, CompLocationOffset,
158                CompSize, CompVersion>;
159 using ComponentImageInfos = std::vector<ComponentImageInfo>;
160 
161 enum class ComponentImageInfoPos : size_t
162 {
163     CompClassificationPos = 0,
164     CompIdentifierPos = 1,
165     CompComparisonStampPos = 2,
166     CompOptionsPos = 3,
167     ReqCompActivationMethodPos = 4,
168     CompLocationOffsetPos = 5,
169     CompSizePos = 6,
170     CompVersionPos = 7,
171 };
172 
173 } // namespace fw_update
174 
175 namespace pdr
176 {
177 
178 using EID = uint8_t;
179 using TerminusHandle = uint16_t;
180 using TerminusID = uint8_t;
181 using SensorID = uint16_t;
182 using EntityType = uint16_t;
183 using EntityInstance = uint16_t;
184 using ContainerID = uint16_t;
185 using StateSetId = uint16_t;
186 using CompositeCount = uint8_t;
187 using SensorOffset = uint8_t;
188 using EventState = uint8_t;
189 using TerminusValidity = uint8_t;
190 
191 //!< Subset of the State Set that is supported by a effecter/sensor
192 using PossibleStates = std::set<uint8_t>;
193 //!< Subset of the State Set that is supported by each effecter/sensor in a
194 //!< composite efffecter/sensor
195 using CompositeSensorStates = std::vector<PossibleStates>;
196 using EntityInfo = std::tuple<ContainerID, EntityType, EntityInstance>;
197 using SensorInfo =
198     std::tuple<EntityInfo, CompositeSensorStates, std::vector<StateSetId>>;
199 
200 } // namespace pdr
201 
202 } // namespace pldm
203