summaryrefslogtreecommitdiffstats
path: root/types.hpp
blob: 41dddd92b3c780506274b5914e22a2270cd906c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#pragma once

#include <stdint.h>

#include <map>
#include <string>

#include <sdbusplus/server.hpp>

namespace ipmi
{

using DbusObjectPath = std::string;
using DbusService = std::string;
using DbusInterface = std::string;
using DbusObjectInfo = std::pair<DbusObjectPath, DbusService>;
using DbusProperty = std::string;

using Value = sdbusplus::message::variant<bool, uint8_t, int16_t,
                                          uint16_t, int32_t, uint32_t,
                                          int64_t, uint64_t, std::string>;

using PropertyMap = std::map<DbusProperty, Value>;

using ObjectTree = std::map<DbusObjectPath,
                            std::map<DbusService, std::vector<DbusInterface>>>;

using InterfaceList = std::vector<std::string>;

namespace sensor
{

using Offset = uint8_t;

struct Values
{
   Value assert;
   Value deassert;
};

/**
 * @struct SetSensorReadingReq
 *
 * IPMI Request data for Set Sensor Reading and Event Status Command
 */
struct SetSensorReadingReq
{
    uint8_t number;
    uint8_t operation;
    uint8_t reading;
    uint8_t assertOffset0_7;
    uint8_t assertOffset8_14;
    uint8_t deassertOffset0_7;
    uint8_t deassertOffset8_14;
    uint8_t eventData1;
    uint8_t eventData2;
    uint8_t eventData3;
} __attribute__((packed));

/**
 * @struct GetReadingResponse
 *
 * IPMI response data for Get Sensor Reading command.
 */
struct GetReadingResponse
{
    uint8_t reading;            //!< Sensor reading.
    uint8_t operation;          //!< Sensor scanning status / reading state.
    uint8_t assertOffset0_7;    //!< Discrete assertion states(0-7).
    uint8_t assertOffset8_14;   //!< Discrete assertion states(8-14).
} __attribute__((packed));

constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory";

using GetSensorResponse = std::array<uint8_t, sizeof(GetReadingResponse)>;

using OffsetValueMap = std::map<Offset,Values>;

using DbusPropertyMap = std::map<DbusProperty,OffsetValueMap>;

using DbusInterfaceMap = std::map<DbusInterface,DbusPropertyMap>;

using InstancePath = std::string;
using Type = uint8_t;
using ReadingType = uint8_t;
using Multiplier = uint16_t;
using OffsetB = uint16_t;
using Exponent = uint8_t;
using ScaledOffset = int64_t;

enum class Mutability
{
   Read = 1 << 0,
   Write = 1 << 1,
};

inline Mutability operator|(Mutability lhs, Mutability rhs)
{
  return static_cast<Mutability>(
      static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
}

inline Mutability operator&(Mutability lhs, Mutability rhs)
{
  return static_cast<Mutability>(
      static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
}

struct Info
{
   Type sensorType;
   InstancePath sensorPath;
   DbusInterface sensorInterface;
   ReadingType sensorReadingType;
   Multiplier coefficientM;
   OffsetB coefficientB;
   Exponent exponentB;
   ScaledOffset scaledOffset;
   std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
   std::function<GetSensorResponse(const Info&)> getFunc;
   Mutability mutability;
   DbusInterfaceMap propertyInterfaces;
};

using Id = uint8_t;
using IdInfoMap = std::map<Id,Info>;

using PropertyMap = ipmi::PropertyMap;

using InterfaceMap = std::map<DbusInterface, PropertyMap>;

using Object = sdbusplus::message::object_path;
using ObjectMap = std::map<Object, InterfaceMap>;

using IpmiUpdateData = sdbusplus::message::message;

struct SelData
{
   Id sensorID;
   Type sensorType;
   ReadingType eventReadingType;
   Offset eventOffset;
};

using InventoryPath = std::string;

using InvObjectIDMap = std::map<InventoryPath, SelData>;

}// namespace sensor

namespace network
{

constexpr auto MAC_ADDRESS_FORMAT = "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx";
constexpr auto IP_ADDRESS_FORMAT = "%u.%u.%u.%u";
constexpr auto PREFIX_FORMAT = "%hhd";
constexpr auto ADDR_TYPE_FORMAT = "%hhx";

constexpr auto IPV4_ADDRESS_SIZE_BYTE = 4;
constexpr auto IPV6_ADDRESS_SIZE_BYTE = 16;

constexpr auto DEFAULT_MAC_ADDRESS = "00:00:00:00:00:00";
constexpr auto DEFAULT_ADDRESS = "0.0.0.0";

constexpr auto MAC_ADDRESS_SIZE_BYTE = 6;
constexpr auto VLAN_SIZE_BYTE = 2;
constexpr auto IPSRC_SIZE_BYTE = 1;
constexpr auto BITS_32 = 32;
constexpr auto MASK_32_BIT = 0xFFFFFFFF;
constexpr auto VLAN_ID_MASK = 0x00000FFF;
constexpr auto VLAN_ENABLE_MASK = 0x8000;

enum class IPOrigin: uint8_t
{
    UNSPECIFIED = 0,
    STATIC = 1,
    DHCP = 2,
};


}//namespace network
}//namespace ipmi
OpenPOWER on IntegriCloud