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