blob: 3594abbd5eb42d13c946a35d9b5bd8f777ce48d2 [file] [log] [blame]
Vernon Mauerya3702c12019-05-22 13:20:59 -07001/*
2// Copyright (c) 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
19#include <ipmid/api-types.hpp>
20#include <ipmid/utils.hpp>
21#include <phosphor-logging/log.hpp>
22#include <sdbusplus/bus.hpp>
23#include <sdbusplus/message.hpp>
24#include <sdbusplus/timer.hpp>
25#include <variantvisitors.hpp>
26#include <vector>
27
28#define FAN_SENSOR_NOT_PRESENT (0 << 0)
29#define FAN_SENSOR_PRESENT (1 << 0)
30#define FAN_NOT_PRESENT (0 << 1)
31#define FAN_PRESENT (1 << 1)
32
33namespace ipmi
34{
35
36// TODO: Service names may change. Worth to consider dynamic detection.
37static constexpr const char* fanService = "xyz.openbmc_project.FanSensor";
Jason M. Bills38d2b5a2019-06-03 16:26:11 -070038static constexpr const char* buttonService =
39 "xyz.openbmc_project.Chassis.Buttons";
Vernon Mauerya3702c12019-05-22 13:20:59 -070040static constexpr const char* ledServicePrefix =
41 "xyz.openbmc_project.LED.Controller.";
42
43static constexpr const char* ledPathPrefix =
44 "/xyz/openbmc_project/led/physical/";
45static constexpr const char* fanPwmPath =
46 "/xyz/openbmc_project/sensors/fan_pwm/Pwm_";
Richard Marian Thomaiyar147daec2019-06-15 07:43:48 +053047static constexpr const char* fanTachBasePath =
48 "/xyz/openbmc_project/sensors/fan_tach/";
Vernon Mauerya3702c12019-05-22 13:20:59 -070049
50static constexpr const char* fanIntf = "xyz.openbmc_project.Sensor.Value";
Jason M. Bills38d2b5a2019-06-03 16:26:11 -070051static constexpr const char* buttonIntf = "xyz.openbmc_project.Chassis.Buttons";
Vernon Mauerya3702c12019-05-22 13:20:59 -070052static constexpr const char* ledIntf = "xyz.openbmc_project.Led.Physical";
53
anil kumar appana98705b32019-09-11 14:15:50 +000054static constexpr const char* intrusionService =
55 "xyz.openbmc_project.IntrusionSensor";
56static constexpr const char* intrusionPath =
57 "/xyz/openbmc_project/Intrusion/Chassis_Intrusion";
58static constexpr const char* intrusionIntf =
59 "xyz.openbmc_project.Chassis.Intrusion";
60
Vernon Mauerya3702c12019-05-22 13:20:59 -070061static constexpr const char* busPropertyIntf =
62 "org.freedesktop.DBus.Properties";
63static constexpr const char* ledStateStr =
64 "xyz.openbmc_project.Led.Physical.Action."; // Comes with postfix Off/On
Vernon Mauerya3702c12019-05-22 13:20:59 -070065
Richard Marian Thomaiyar666dd012019-08-02 20:55:37 +053066static constexpr const char* specialModeService =
67 "xyz.openbmc_project.SpecialMode";
68static constexpr const char* specialModeObjPath =
69 "/xyz/openbmc_project/security/special_mode";
70static constexpr const char* specialModeIntf =
71 "xyz.openbmc_project.Security.SpecialMode";
72
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +053073enum class SpecialMode : uint8_t
74{
75 none = 0,
76 mfg = 1,
77#ifdef BMC_VALIDATION_UNSECURE_FEATURE
78 valUnsecure = 2
79#endif
80};
81
Vernon Mauerya3702c12019-05-22 13:20:59 -070082enum class SmActionGet : uint8_t
83{
84 sample = 0,
85 ignore = 1,
86 revert = 2
87};
88
89enum class SmActionSet : uint8_t
90{
91 forceDeasserted = 0,
92 forceAsserted = 1,
93 revert = 2
94};
95
96enum class SmSignalGet : uint8_t
97{
98 smPowerButton = 0,
99 smResetButton = 1,
100 smSleepButton,
Jason M. Bills38d2b5a2019-06-03 16:26:11 -0700101 smNMIButton = 3,
Vernon Mauerya3702c12019-05-22 13:20:59 -0700102 smChassisIntrusion = 4,
103 smPowerGood,
104 smPowerRequestGet,
105 smSleepRequestGet,
106 smFrbTimerHaltGet,
107 smForceUpdate,
108 smRingIndication,
109 smCarrierDetect,
110 smIdentifyButton = 0xc,
111 smFanPwmGet = 0xd,
112 smSignalReserved,
113 smFanTachometerGet = 0xf,
114 smNcsiDiag = 0x10,
Vernon Mauerya3702c12019-05-22 13:20:59 -0700115 smGetSignalMax
116};
117
118enum class SmSignalSet : uint8_t
119{
120 smPowerLed = 0,
121 smPowerFaultLed,
122 smClusterLed,
123 smDiskFaultLed,
124 smCoolingFaultLed,
125 smFanPowerSpeed = 5,
126 smPowerRequestSet,
127 smSleepRequestSet,
128 smAcpiSci,
129 smSpeaker,
130 smFanPackFaultLed,
131 smCpuFailLed,
132 smDimmFailLed,
133 smIdentifyLed,
134 smHddLed,
135 smSystemReadyLed,
136 smLcdBacklight = 0x10,
137 smSetSignalMax
138};
139
anil kumar appana98705b32019-09-11 14:15:50 +0000140/** @enum IntrusionStatus
141.*
142 * Intrusion Status
143 */
144enum class IntrusionStatus : uint8_t
145{
146 normal = 0,
147 hardwareIntrusion,
148 tamperingDetected
149};
150
Vernon Mauerya3702c12019-05-22 13:20:59 -0700151struct SetSmSignalReq
152{
153 SmSignalSet Signal;
154 uint8_t Instance;
155 SmActionSet Action;
156 uint8_t Value;
157};
158
Vernon Mauerya3702c12019-05-22 13:20:59 -0700159class LedProperty
160{
161 SmSignalSet signal;
162 std::string name;
163 std::string prevState;
164 std::string currentState;
165 bool isLocked;
166
167 public:
168 LedProperty(SmSignalSet signal_, std::string name_) :
169 signal(signal_), name(name_), prevState(""), isLocked(false)
170 {
171 }
172
173 LedProperty() = delete;
174
175 SmSignalSet getSignal() const
176 {
177 return signal;
178 }
179
180 void setLock(const bool& lock)
181 {
182 isLocked = lock;
183 }
184 void setPrevState(const std::string& state)
185 {
186 prevState = state;
187 }
188 void setCurrState(const std::string& state)
189 {
190 currentState = state;
191 }
192 std::string getCurrState() const
193 {
194 return currentState;
195 }
196 bool getLock() const
197 {
198 return isLocked;
199 }
200 std::string getPrevState() const
201 {
202 return prevState;
203 }
204 std::string getName() const
205 {
206 return name;
207 }
208};
209
210/** @class Manufacturing
211 *
212 * @brief Implemet commands to support Manufacturing Test Mode.
213 */
214class Manufacturing
215{
216 std::string path;
217 std::string gpioPaths[(uint8_t)SmSignalGet::smGetSignalMax];
218 std::vector<LedProperty> ledPropertyList;
219 void initData();
220
221 public:
222 Manufacturing();
223
224 ipmi_return_codes detectAccessLvl(ipmi_request_t request,
225 ipmi_data_len_t req_len);
226
227 LedProperty* findLedProperty(const SmSignalSet& signal)
228 {
229 auto it = std::find_if(ledPropertyList.begin(), ledPropertyList.end(),
230 [&signal](const LedProperty& led) {
231 return led.getSignal() == signal;
232 });
233 if (it != ledPropertyList.end())
234 {
235 return &(*it);
236 }
237 return nullptr;
238 }
239
240 std::string getLedPropertyName(const SmSignalSet signal)
241 {
242 LedProperty* led = findLedProperty(signal);
243 if (led != nullptr)
244 {
245 return led->getName();
246 }
247 else
248 {
249 return "";
250 }
251 }
252
Jason M. Bills38d2b5a2019-06-03 16:26:11 -0700253 int8_t getProperty(const std::string& service, const std::string& path,
254 const std::string& interface,
255 const std::string& propertyName, ipmi::Value* value);
256 int8_t setProperty(const std::string& service, const std::string& path,
257 const std::string& interface,
258 const std::string& propertyName, ipmi::Value value);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700259 int8_t disablePidControlService(const bool disable);
260
261 void revertTimerHandler();
262
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +0530263 SpecialMode getMfgMode(void)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700264 {
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +0530265 ipmi::Value mode;
266 if (getProperty(specialModeService, specialModeObjPath, specialModeIntf,
267 "SpecialMode", &mode) != 0)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700268 {
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +0530269 return SpecialMode::none;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700270 }
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +0530271 if (std::get<std::string>(mode) ==
272 "xyz.openbmc_project.Control.Security.SpecialMode.Modes."
273 "Manufacturing")
274 {
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +0530275 return SpecialMode::mfg;
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +0530276 }
Richard Marian Thomaiyar99d7d352019-11-11 12:11:35 +0530277#ifdef BMC_VALIDATION_UNSECURE_FEATURE
278 if (std::get<std::string>(mode) ==
279 "xyz.openbmc_project.Control.Security.SpecialMode.Modes."
280 "ValidationUnsecure")
281 {
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +0530282 return SpecialMode::valUnsecure;
Richard Marian Thomaiyar99d7d352019-11-11 12:11:35 +0530283 }
284#endif
Richard Marian Thomaiyarae13ac62019-12-17 15:45:12 +0530285 return SpecialMode::none;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700286 }
287
Vernon Mauerya3702c12019-05-22 13:20:59 -0700288 bool revertFanPWM = false;
289 bool revertLedCallback = false;
290 phosphor::Timer revertTimer;
Ayushi Smritid872a4a2019-10-15 10:20:11 +0530291 int mtmTestBeepFd = -1;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700292};
293
294} // namespace ipmi