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> |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 8 | |
| 9 | namespace ipmi |
| 10 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 11 | |
| 12 | using DbusObjectPath = std::string; |
| 13 | using DbusService = std::string; |
| 14 | using DbusInterface = std::string; |
| 15 | using DbusObjectInfo = std::pair<DbusObjectPath, DbusService>; |
| 16 | using DbusProperty = std::string; |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 17 | |
James Feist | 006d33c | 2018-06-15 11:36:27 -0700 | [diff] [blame] | 18 | using Value = sdbusplus::message::variant<bool, uint8_t, int16_t, uint16_t, |
| 19 | int32_t, uint32_t, int64_t, uint64_t, |
| 20 | 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 | |
| 103 | using GetSensorResponse = std::array<uint8_t, sizeof(GetReadingResponse)>; |
| 104 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 105 | using OffsetValueMap = std::map<Offset, Values>; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 106 | |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 107 | using DbusPropertyValues = std::pair<PreReqOffsetValueMap, OffsetValueMap>; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 108 | |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 109 | using DbusPropertyMap = std::map<DbusProperty, DbusPropertyValues>; |
| 110 | |
| 111 | using DbusInterfaceMap = std::map<DbusInterface, DbusPropertyMap>; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 112 | |
| 113 | using InstancePath = std::string; |
| 114 | using Type = uint8_t; |
| 115 | using ReadingType = uint8_t; |
Emily Shaffer | 10f4959 | 2017-05-10 12:01:10 -0700 | [diff] [blame] | 116 | using Multiplier = uint16_t; |
Tom Joseph | 0a1301c | 2018-02-16 08:27:00 +0530 | [diff] [blame] | 117 | using OffsetB = int16_t; |
| 118 | using Exponent = int8_t; |
Emily Shaffer | 4001191 | 2018-10-09 12:06:04 -0700 | [diff] [blame] | 119 | using ScaledOffset = double; |
Emily Shaffer | 6223561 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 120 | using Scale = int16_t; |
| 121 | using Unit = std::string; |
Tom Joseph | b0adbcd | 2018-01-24 11:51:29 +0530 | [diff] [blame] | 122 | using EntityType = uint8_t; |
| 123 | using EntityInst = uint8_t; |
| 124 | using SensorName = std::string; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 125 | |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 126 | enum class Mutability |
| 127 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 128 | Read = 1 << 0, |
| 129 | Write = 1 << 1, |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | inline Mutability operator|(Mutability lhs, Mutability rhs) |
| 133 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 134 | return static_cast<Mutability>(static_cast<uint8_t>(lhs) | |
| 135 | static_cast<uint8_t>(rhs)); |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | inline Mutability operator&(Mutability lhs, Mutability rhs) |
| 139 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 140 | return static_cast<Mutability>(static_cast<uint8_t>(lhs) & |
| 141 | static_cast<uint8_t>(rhs)); |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 144 | struct Info |
| 145 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 146 | EntityType entityType; |
| 147 | EntityInst instance; |
| 148 | Type sensorType; |
| 149 | InstancePath sensorPath; |
| 150 | DbusInterface sensorInterface; |
| 151 | ReadingType sensorReadingType; |
| 152 | Multiplier coefficientM; |
| 153 | OffsetB coefficientB; |
| 154 | Exponent exponentB; |
| 155 | ScaledOffset scaledOffset; |
| 156 | Exponent exponentR; |
| 157 | bool hasScale; |
| 158 | Scale scale; |
| 159 | Unit unit; |
| 160 | std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc; |
| 161 | std::function<GetSensorResponse(const Info&)> getFunc; |
| 162 | Mutability mutability; |
| 163 | std::function<SensorName(const Info&)> sensorNameFunc; |
| 164 | DbusInterfaceMap propertyInterfaces; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | using Id = uint8_t; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 168 | using IdInfoMap = std::map<Id, Info>; |
Ratan Gupta | 0065905 | 2017-02-23 17:29:08 +0530 | [diff] [blame] | 169 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 170 | using PropertyMap = ipmi::PropertyMap; |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 171 | |
| 172 | using InterfaceMap = std::map<DbusInterface, PropertyMap>; |
| 173 | |
| 174 | using Object = sdbusplus::message::object_path; |
| 175 | using ObjectMap = std::map<Object, InterfaceMap>; |
| 176 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 177 | using IpmiUpdateData = sdbusplus::message::message; |
| 178 | |
Tom Joseph | dd78a1d | 2017-05-05 11:04:29 +0530 | [diff] [blame] | 179 | struct SelData |
| 180 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 181 | Id sensorID; |
| 182 | Type sensorType; |
| 183 | ReadingType eventReadingType; |
| 184 | Offset eventOffset; |
Tom Joseph | dd78a1d | 2017-05-05 11:04:29 +0530 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | using InventoryPath = std::string; |
| 188 | |
| 189 | using InvObjectIDMap = std::map<InventoryPath, SelData>; |
| 190 | |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 191 | enum class ThresholdMask |
| 192 | { |
| 193 | NON_CRITICAL_LOW_MASK = 0x01, |
| 194 | CRITICAL_LOW_MASK = 0x02, |
| 195 | NON_CRITICAL_HIGH_MASK = 0x08, |
| 196 | CRITICAL_HIGH_MASK = 0x10, |
| 197 | }; |
| 198 | |
Jaghathiswari Rankappagounder Natarajan | 9c11894 | 2019-02-12 13:22:55 -0800 | [diff] [blame] | 199 | static constexpr uint8_t maxContainedEntities = 4; |
| 200 | using ContainedEntitiesArray = |
| 201 | std::array<std::pair<uint8_t, uint8_t>, maxContainedEntities>; |
| 202 | |
| 203 | struct EntityInfo |
| 204 | { |
| 205 | uint8_t containerEntityId; |
| 206 | uint8_t containerEntityInstance; |
| 207 | bool isList; |
| 208 | bool isLinked; |
| 209 | ContainedEntitiesArray containedEntities; |
| 210 | }; |
| 211 | |
| 212 | using EntityInfoMap = std::map<Id, EntityInfo>; |
| 213 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 214 | } // namespace sensor |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 215 | |
| 216 | namespace network |
| 217 | { |
Patrick Venture | c01edf2 | 2017-12-22 14:03:06 -0800 | [diff] [blame] | 218 | using ChannelEthMap = std::map<int, std::string>; |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 219 | |
| 220 | constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"; |
| 221 | constexpr auto IP_ADDRESS_FORMAT = "%u.%u.%u.%u"; |
| 222 | constexpr auto PREFIX_FORMAT = "%hhd"; |
| 223 | constexpr auto ADDR_TYPE_FORMAT = "%hhx"; |
| 224 | |
| 225 | constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4; |
| 226 | constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16; |
| 227 | |
| 228 | constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00"; |
| 229 | constexpr auto DEFAULT_ADDRESS = "0.0.0.0"; |
| 230 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 231 | constexpr auto MAC_ADDRESS_SIZE_BYTE = 6; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 232 | constexpr auto VLAN_SIZE_BYTE = 2; |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 233 | constexpr auto IPSRC_SIZE_BYTE = 1; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 234 | constexpr auto BITS_32 = 32; |
| 235 | constexpr auto MASK_32_BIT = 0xFFFFFFFF; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 236 | constexpr auto VLAN_ID_MASK = 0x00000FFF; |
| 237 | constexpr auto VLAN_ENABLE_MASK = 0x8000; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 238 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 239 | enum class IPOrigin : uint8_t |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 240 | { |
| 241 | UNSPECIFIED = 0, |
| 242 | STATIC = 1, |
| 243 | DHCP = 2, |
| 244 | }; |
| 245 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 246 | } // namespace network |
| 247 | } // namespace ipmi |