summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomaiyar, Richard Marian <richard.marian.thomaiyar@intel.com>2019-08-06 19:55:08 +0300
committerGerrit Code Review <gerrit@localhost>2019-08-06 19:55:08 +0300
commitf1f953eb57d5d9d4fdbd1f68ceb5a224ae7918d8 (patch)
treefcc988f7772a68d1ed480db4386c8b661d71332d
parent55721c44f723d074684e797a0f81674698282839 (diff)
parent4c64b1593dc059486c6f39c7c9a50c445af1e21c (diff)
downloadprovingground-f1f953eb57d5d9d4fdbd1f68ceb5a224ae7918d8.tar.xz
Merge "[mfg]: Manufacutring timeout & timer reset update"
-rw-r--r--special-mode-mgr/include/specialmodemgr.hpp5
-rw-r--r--special-mode-mgr/src/specialmodemgr.cpp50
2 files changed, 33 insertions, 22 deletions
diff --git a/special-mode-mgr/include/specialmodemgr.hpp b/special-mode-mgr/include/specialmodemgr.hpp
index a5f23fd..2f0183b 100644
--- a/special-mode-mgr/include/specialmodemgr.hpp
+++ b/special-mode-mgr/include/specialmodemgr.hpp
@@ -16,8 +16,8 @@
#pragma once
-#include <boost/asio/deadline_timer.hpp>
#include <sdbusplus/asio/object_server.hpp>
+#include <chrono>
static constexpr const char* strSpecialMode = "SpecialMode";
@@ -35,11 +35,12 @@ class SpecialModeMgr
std::shared_ptr<sdbusplus::asio::connection> conn;
std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
uint8_t specialMode = none;
- std::unique_ptr<boost::asio::deadline_timer> timer = nullptr;
+ std::unique_ptr<boost::asio::steady_timer> timer = nullptr;
std::unique_ptr<sdbusplus::bus::match::match> intfAddMatchRule = nullptr;
std::unique_ptr<sdbusplus::bus::match::match> propUpdMatchRule = nullptr;
void addSpecialModeProperty();
void checkAndAddSpecialModeProperty(const std::string& provMode);
+ void updateTimer(int countInSeconds);
public:
void setSpecialModeValue(uint8_t value) const
diff --git a/special-mode-mgr/src/specialmodemgr.cpp b/special-mode-mgr/src/specialmodemgr.cpp
index 217705a..1e3ba3a 100644
--- a/special-mode-mgr/src/specialmodemgr.cpp
+++ b/special-mode-mgr/src/specialmodemgr.cpp
@@ -36,6 +36,7 @@ static constexpr const char* restrictionModeIntf =
"xyz.openbmc_project.Control.Security.RestrictionMode";
static constexpr const char* restrictionModeProperty = "RestrictionMode";
+static constexpr int mtmAllowedTime = 15 * 60; // 15 minutes
using VariantValue =
std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t,
@@ -46,7 +47,7 @@ SpecialModeMgr::SpecialModeMgr(
std::shared_ptr<sdbusplus::asio::connection>& conn_) :
io(io_),
server(srv_), conn(conn_),
- timer(std::make_unique<boost::asio::deadline_timer>(io))
+ timer(std::make_unique<boost::asio::steady_timer>(io))
{
// Following condition must match to indicate specialMode.
@@ -169,7 +170,6 @@ void SpecialModeMgr::checkAndAddSpecialModeProperty(const std::string& provMode)
addSpecialModeProperty();
return;
}
- constexpr int mtmAllowedTime = 12 * 60 * 60; // 12 hours
int specialModeLockoutSeconds = 0;
if (mtmAllowedTime > sysInfo.uptime)
{
@@ -181,24 +181,7 @@ void SpecialModeMgr::checkAndAddSpecialModeProperty(const std::string& provMode)
{
return;
}
- timer->expires_from_now(
- boost::posix_time::seconds(specialModeLockoutSeconds));
- timer->async_wait([this](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- // timer aborted
- return;
- }
- else if (ec)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Error in special mode "
- "timer");
- return;
- }
- iface->set_property(strSpecialMode,
- static_cast<uint8_t>(manufacturingExpired));
- });
+ updateTimer(specialModeLockoutSeconds);
}
void SpecialModeMgr::addSpecialModeProperty()
@@ -219,9 +202,36 @@ void SpecialModeMgr::addSpecialModeProperty()
},
// Override get
[this](const uint8_t& mode) { return specialMode; });
+ iface->register_method("ResetTimer", [this]() {
+ if (specialMode == manufacturingMode)
+ {
+ updateTimer(mtmAllowedTime);
+ }
+ return;
+ });
iface->initialize(true);
}
+void SpecialModeMgr::updateTimer(int countInSeconds)
+{
+ timer->expires_after(std::chrono::seconds(countInSeconds));
+ timer->async_wait([this](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ // timer aborted
+ return;
+ }
+ else if (ec)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error in special mode timer");
+ return;
+ }
+ iface->set_property(strSpecialMode,
+ static_cast<uint8_t>(manufacturingExpired));
+ });
+}
+
int main()
{
boost::asio::io_service io;