1 /*
2 // Copyright (c) 2017 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #pragma once
18 #include "sensorhandler.hpp"
19 
20 #include <cstdint>
21 
22 #define USING_ENTITY_MANAGER_DECORATORS
23 
24 static constexpr uint8_t ipmiSdrVersion = 0x51;
25 
26 namespace dynamic_sensors::ipmi::sel
27 {
28 static constexpr uint8_t selOperationSupport = 0x02;
29 static constexpr uint8_t systemEvent = 0x02;
30 static constexpr size_t systemEventSize = 3;
31 static constexpr uint8_t oemTsEventFirst = 0xC0;
32 static constexpr uint8_t oemTsEventLast = 0xDF;
33 static constexpr size_t oemTsEventSize = 9;
34 static constexpr uint8_t oemEventFirst = 0xE0;
35 static constexpr uint8_t oemEventLast = 0xFF;
36 static constexpr size_t oemEventSize = 13;
37 static constexpr uint8_t eventMsgRev = 0x04;
38 } // namespace dynamic_sensors::ipmi::sel
39 
40 enum class SdrRepositoryInfoOps : uint8_t
41 {
42     allocCommandSupported = 0x1,
43     reserveSDRRepositoryCommandSupported = 0x2,
44     partialAddSDRSupported = 0x4,
45     deleteSDRSupported = 0x8,
46     reserved = 0x10,
47     modalLSB = 0x20,
48     modalMSB = 0x40,
49     overflow = 0x80
50 };
51 
52 enum class GetFRUAreaAccessType : uint8_t
53 {
54     byte = 0x0,
55     words = 0x1
56 };
57 
58 enum class SensorUnits : uint8_t
59 {
60     unspecified = 0x0,
61     degreesC = 0x1,
62     volts = 0x4,
63     amps = 0x5,
64     watts = 0x6,
65     rpm = 0x12,
66 };
67 
68 #pragma pack(push, 1)
69 struct FRUHeader
70 {
71     uint8_t commonHeaderFormat;
72     uint8_t internalOffset;
73     uint8_t chassisOffset;
74     uint8_t boardOffset;
75     uint8_t productOffset;
76     uint8_t multiRecordOffset;
77     uint8_t pad;
78     uint8_t checksum;
79 };
80 #pragma pack(pop)
81 
82 #pragma pack(push, 1)
83 struct Type12Record
84 {
85     get_sdr::SensorDataRecordHeader header;
86     uint8_t slaveAddress;
87     uint8_t channelNumber;
88     uint8_t powerStateNotification;
89     uint8_t deviceCapabilities;
90     // define reserved bytes explicitly. The uint24_t is silently expanded to
91     // uint32_t, which ruins the byte alignment required by this structure.
92     uint8_t reserved[3];
93     uint8_t entityID;
94     uint8_t entityInstance;
95     uint8_t oem;
96     uint8_t typeLengthCode;
97     char name[16];
98 
99     Type12Record(uint16_t recordID, uint8_t address, uint8_t chNumber,
100                  uint8_t pwrStateNotification, uint8_t capabilities,
101                  uint8_t eid, uint8_t entityInst, uint8_t mfrDefined,
102                  const std::string& sensorname) :
103         slaveAddress(address),
104         channelNumber(chNumber), powerStateNotification(pwrStateNotification),
105         deviceCapabilities(capabilities), reserved{}, entityID(eid),
106         entityInstance(entityInst), oem(mfrDefined)
107     {
108         get_sdr::header::set_record_id(recordID, &header);
109         header.sdr_version = ipmiSdrVersion;
110         header.record_type = 0x12;
111         size_t nameLen = std::min(sensorname.size(), sizeof(name));
112         header.record_length = sizeof(Type12Record) -
113                                sizeof(get_sdr::SensorDataRecordHeader) -
114                                sizeof(name) + nameLen;
115         typeLengthCode = 0xc0 | nameLen;
116         std::copy(sensorname.begin(), sensorname.begin() + nameLen, name);
117     }
118 };
119 #pragma pack(pop)
120 
121 namespace ipmi
122 {
123 namespace storage
124 {
125 
126 constexpr const size_t type12Count = 2;
127 ipmi_ret_t getFruSdrs(ipmi::Context::ptr ctx, size_t index,
128                       get_sdr::SensorDataFruRecord& resp);
129 
130 ipmi_ret_t getFruSdrCount(ipmi::Context::ptr ctx, size_t& count);
131 
132 std::vector<uint8_t>
133     getType8SDRs(ipmi::sensor::EntityInfoMap::const_iterator& entity,
134                  uint16_t recordId);
135 std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId);
136 std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId);
137 } // namespace storage
138 } // namespace ipmi
139