Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | |
| 5 | #include <map> |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 6 | #include <sdbusplus/server.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 7 | #include <string> |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 8 | #include <variant> |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 9 | |
| 10 | namespace ipmi |
| 11 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 12 | |
| 13 | using DbusObjectPath = std::string; |
| 14 | using DbusService = std::string; |
| 15 | using DbusInterface = std::string; |
| 16 | using DbusObjectInfo = std::pair<DbusObjectPath, DbusService>; |
| 17 | using DbusProperty = std::string; |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 18 | |
Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 19 | using Association = std::tuple<std::string, std::string, std::string>; |
| 20 | |
| 21 | using Value = |
| 22 | std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, |
| 23 | uint64_t, double, std::string, std::vector<Association>>; |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 24 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 25 | using PropertyMap = std::map<DbusProperty, Value>; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 26 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 27 | using ObjectTree = |
| 28 | std::map<DbusObjectPath, std::map<DbusService, std::vector<DbusInterface>>>; |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 29 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 30 | using InterfaceList = std::vector<std::string>; |
| 31 | |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 32 | using DbusInterfaceMap = std::map<DbusInterface, PropertyMap>; |
| 33 | |
| 34 | using ObjectValueTree = |
| 35 | std::map<sdbusplus::message::object_path, DbusInterfaceMap>; |
| 36 | |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 37 | namespace sensor |
| 38 | { |
| 39 | |
| 40 | using Offset = uint8_t; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 41 | |
Dhruvaraj Subhashchandran | e84841c | 2017-08-22 07:40:27 -0500 | [diff] [blame] | 42 | /** |
| 43 | * @enum SkipAssertion |
| 44 | * Matching value for skipping the update |
| 45 | */ |
| 46 | enum class SkipAssertion |
| 47 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 48 | NONE, // No skip defined |
| 49 | ASSERT, // Skip on Assert |
| 50 | DEASSERT, // Skip on Deassert |
Dhruvaraj Subhashchandran | e84841c | 2017-08-22 07:40:27 -0500 | [diff] [blame] | 51 | }; |
| 52 | |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 53 | struct Values |
| 54 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 55 | SkipAssertion skip; |
| 56 | Value assert; |
| 57 | Value deassert; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 58 | }; |
| 59 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 60 | /** |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 61 | * @enum PreReqValues |
| 62 | * Pre-req conditions for a property. |
| 63 | */ |
| 64 | struct PreReqValues |
| 65 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 66 | Value assert; // Value in case of assert. |
| 67 | Value deassert; // Value in case of deassert. |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | using PreReqOffsetValueMap = std::map<Offset, PreReqValues>; |
| 71 | |
| 72 | /** |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 73 | * @struct SetSensorReadingReq |
| 74 | * |
| 75 | * IPMI Request data for Set Sensor Reading and Event Status Command |
| 76 | */ |
| 77 | struct SetSensorReadingReq |
| 78 | { |
| 79 | uint8_t number; |
| 80 | uint8_t operation; |
| 81 | uint8_t reading; |
| 82 | uint8_t assertOffset0_7; |
| 83 | uint8_t assertOffset8_14; |
| 84 | uint8_t deassertOffset0_7; |
| 85 | uint8_t deassertOffset8_14; |
| 86 | uint8_t eventData1; |
| 87 | uint8_t eventData2; |
| 88 | uint8_t eventData3; |
| 89 | } __attribute__((packed)); |
| 90 | |
| 91 | /** |
| 92 | * @struct GetReadingResponse |
| 93 | * |
| 94 | * IPMI response data for Get Sensor Reading command. |
| 95 | */ |
| 96 | struct GetReadingResponse |
| 97 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 98 | uint8_t reading; //!< Sensor reading. |
| 99 | uint8_t operation; //!< Sensor scanning status / reading state. |
| 100 | uint8_t assertOffset0_7; //!< Discrete assertion states(0-7). |
| 101 | uint8_t assertOffset8_14; //!< Discrete assertion states(8-14). |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 102 | } __attribute__((packed)); |
| 103 | |
| 104 | constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory"; |
| 105 | |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 106 | struct GetSensorResponse |
| 107 | { |
| 108 | uint8_t reading; // sensor reading |
| 109 | bool readingOrStateUnavailable; // 1 = reading/state unavailable |
| 110 | bool scanningEnabled; // 0 = sensor scanning disabled |
| 111 | bool allEventMessagesEnabled; // 0 = All Event Messages disabled |
| 112 | uint8_t thresholdLevelsStates; // threshold/discrete sensor states |
| 113 | uint8_t discreteReadingSensorStates; // discrete-only, optional states |
| 114 | }; |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 115 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 116 | using OffsetValueMap = std::map<Offset, Values>; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 117 | |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 118 | using DbusPropertyValues = std::pair<PreReqOffsetValueMap, OffsetValueMap>; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 119 | |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 120 | using DbusPropertyMap = std::map<DbusProperty, DbusPropertyValues>; |
| 121 | |
| 122 | using DbusInterfaceMap = std::map<DbusInterface, DbusPropertyMap>; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 123 | |
| 124 | using InstancePath = std::string; |
| 125 | using Type = uint8_t; |
| 126 | using ReadingType = uint8_t; |
Emily Shaffer | 10f4959 | 2017-05-10 12:01:10 -0700 | [diff] [blame] | 127 | using Multiplier = uint16_t; |
Tom Joseph | 0a1301c | 2018-02-16 08:27:00 +0530 | [diff] [blame] | 128 | using OffsetB = int16_t; |
| 129 | using Exponent = int8_t; |
Emily Shaffer | 4001191 | 2018-10-09 12:06:04 -0700 | [diff] [blame] | 130 | using ScaledOffset = double; |
Emily Shaffer | 6223561 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 131 | using Scale = int16_t; |
| 132 | using Unit = std::string; |
Tom Joseph | b0adbcd | 2018-01-24 11:51:29 +0530 | [diff] [blame] | 133 | using EntityType = uint8_t; |
| 134 | using EntityInst = uint8_t; |
| 135 | using SensorName = std::string; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 136 | |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 137 | enum class Mutability |
| 138 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 139 | Read = 1 << 0, |
| 140 | Write = 1 << 1, |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | inline Mutability operator|(Mutability lhs, Mutability rhs) |
| 144 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 145 | return static_cast<Mutability>(static_cast<uint8_t>(lhs) | |
| 146 | static_cast<uint8_t>(rhs)); |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | inline Mutability operator&(Mutability lhs, Mutability rhs) |
| 150 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 151 | return static_cast<Mutability>(static_cast<uint8_t>(lhs) & |
| 152 | static_cast<uint8_t>(rhs)); |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 155 | struct Info |
| 156 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 157 | EntityType entityType; |
| 158 | EntityInst instance; |
| 159 | Type sensorType; |
| 160 | InstancePath sensorPath; |
| 161 | DbusInterface sensorInterface; |
| 162 | ReadingType sensorReadingType; |
| 163 | Multiplier coefficientM; |
| 164 | OffsetB coefficientB; |
| 165 | Exponent exponentB; |
| 166 | ScaledOffset scaledOffset; |
| 167 | Exponent exponentR; |
| 168 | bool hasScale; |
| 169 | Scale scale; |
| 170 | Unit unit; |
| 171 | std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc; |
| 172 | std::function<GetSensorResponse(const Info&)> getFunc; |
| 173 | Mutability mutability; |
Jeremy Kerr | be4ffa8 | 2020-08-10 16:17:37 +0800 | [diff] [blame] | 174 | SensorName sensorName; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 175 | std::function<SensorName(const Info&)> sensorNameFunc; |
| 176 | DbusInterfaceMap propertyInterfaces; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | using Id = uint8_t; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 180 | using IdInfoMap = std::map<Id, Info>; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 181 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 182 | using PropertyMap = ipmi::PropertyMap; |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 183 | |
| 184 | using InterfaceMap = std::map<DbusInterface, PropertyMap>; |
| 185 | |
| 186 | using Object = sdbusplus::message::object_path; |
| 187 | using ObjectMap = std::map<Object, InterfaceMap>; |
| 188 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 189 | using IpmiUpdateData = sdbusplus::message::message; |
| 190 | |
Tom Joseph | dd78a1d | 2017-05-05 11:04:29 +0530 | [diff] [blame] | 191 | struct SelData |
| 192 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 193 | Id sensorID; |
| 194 | Type sensorType; |
| 195 | ReadingType eventReadingType; |
| 196 | Offset eventOffset; |
Tom Joseph | dd78a1d | 2017-05-05 11:04:29 +0530 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | using InventoryPath = std::string; |
| 200 | |
| 201 | using InvObjectIDMap = std::map<InventoryPath, SelData>; |
| 202 | |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 203 | enum class ThresholdMask |
| 204 | { |
| 205 | NON_CRITICAL_LOW_MASK = 0x01, |
| 206 | CRITICAL_LOW_MASK = 0x02, |
| 207 | NON_CRITICAL_HIGH_MASK = 0x08, |
| 208 | CRITICAL_HIGH_MASK = 0x10, |
| 209 | }; |
| 210 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 211 | static constexpr uint8_t maxContainedEntities = 4; |
| 212 | using ContainedEntitiesArray = |
| 213 | std::array<std::pair<uint8_t, uint8_t>, maxContainedEntities>; |
| 214 | |
| 215 | struct EntityInfo |
| 216 | { |
| 217 | uint8_t containerEntityId; |
| 218 | uint8_t containerEntityInstance; |
| 219 | bool isList; |
| 220 | bool isLinked; |
| 221 | ContainedEntitiesArray containedEntities; |
| 222 | }; |
| 223 | |
| 224 | using EntityInfoMap = std::map<Id, EntityInfo>; |
| 225 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 226 | } // namespace sensor |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 227 | |
| 228 | namespace network |
| 229 | { |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 230 | constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"; |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 231 | |
| 232 | constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4; |
| 233 | constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16; |
| 234 | |
| 235 | constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00"; |
| 236 | constexpr auto DEFAULT_ADDRESS = "0.0.0.0"; |
| 237 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 238 | } // namespace network |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 239 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 240 | } // namespace ipmi |