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