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