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