intrusionsensor: Refactor source code
This commit splits the intrusionsensor source code into a base class and
derived classes to dictate sensor of different methods. Only one method
of chassis intrusion detection is expected for one given system.
Tested with hwmon method on Ampere Mt.Mitchell platform which is
implemented in the patch:
https://gerrit.openbmc.org/c/openbmc/dbus-sensors/+/62775
Signed-off-by: Chau Ly <chaul@amperecomputing.com>
Change-Id: Ia2b71d897a27ee7c7955e233d060ad14d62be3a8
diff --git a/src/ChassisIntrusionSensor.cpp b/src/ChassisIntrusionSensor.cpp
index eb325fc..841259f 100644
--- a/src/ChassisIntrusionSensor.cpp
+++ b/src/ChassisIntrusionSensor.cpp
@@ -21,11 +21,13 @@
#include <systemd/sd-journal.h>
#include <unistd.h>
+#include <Utils.hpp>
#include <boost/asio/io_context.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <cerrno>
#include <chrono>
+#include <fstream>
#include <iostream>
#include <memory>
#include <string>
@@ -40,7 +42,11 @@
static constexpr bool debug = false;
-static constexpr unsigned int intrusionSensorPollSec = 1;
+static constexpr unsigned int defaultPollSec = 1;
+static constexpr unsigned int sensorFailedPollSec = 5;
+static unsigned int intrusionSensorPollSec = defaultPollSec;
+static constexpr const char* hwIntrusionValStr = "HardwareIntrusion";
+static constexpr const char* normalValStr = "Normal";
// SMLink Status Register
const static constexpr size_t pchStatusRegIntrusion = 0x04;
@@ -48,8 +54,10 @@
// Status bit field masks
const static constexpr size_t pchRegMaskIntrusion = 0x01;
-void ChassisIntrusionSensor::updateValue(const std::string& newValue)
+void ChassisIntrusionSensor::updateValue(const size_t& value)
{
+ std::string newValue = value != 0 ? hwIntrusionValStr : normalValStr;
+
// Take no action if value already equal
// Same semantics as Sensor::updateValue(const double&)
if (newValue == mValue)
@@ -57,6 +65,12 @@
return;
}
+ if constexpr (debug)
+ {
+ std::cout << "Update value from " << mValue << " to " << newValue
+ << "\n";
+ }
+
// indicate that it is internal set call
mInternalSet = true;
mIface->set_property("Status", newValue);
@@ -64,14 +78,14 @@
mValue = newValue;
- if (mOldValue == "Normal" && mValue != "Normal")
+ if (mOldValue == normalValStr && mValue != normalValStr)
{
sd_journal_send("MESSAGE=%s", "Chassis intrusion assert event",
"PRIORITY=%i", LOG_INFO, "REDFISH_MESSAGE_ID=%s",
"OpenBMC.0.1.ChassisIntrusionDetected", NULL);
mOldValue = mValue;
}
- else if (mOldValue != "Normal" && mValue == "Normal")
+ else if (mOldValue == hwIntrusionValStr && mValue == normalValStr)
{
sd_journal_send("MESSAGE=%s", "Chassis intrusion de-assert event",
"PRIORITY=%i", LOG_INFO, "REDFISH_MESSAGE_ID=%s",
@@ -80,128 +94,79 @@
}
}
-int ChassisIntrusionSensor::i2cReadFromPch(int busId, int slaveAddr)
+int ChassisIntrusionPchSensor::readSensor()
{
- std::string i2cBus = "/dev/i2c-" + std::to_string(busId);
-
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
- int fd = open(i2cBus.c_str(), O_RDWR | O_CLOEXEC);
- if (fd < 0)
- {
- std::cerr << "unable to open i2c device \n";
- return -1;
- }
-
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
- if (ioctl(fd, I2C_SLAVE_FORCE, slaveAddr) < 0)
- {
- std::cerr << "unable to set device address\n";
- close(fd);
- return -1;
- }
-
- unsigned long funcs = 0;
-
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
- if (ioctl(fd, I2C_FUNCS, &funcs) < 0)
- {
- std::cerr << "not support I2C_FUNCS \n";
- close(fd);
- return -1;
- }
-
- if ((funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA) == 0U)
- {
- std::cerr << "not support I2C_FUNC_SMBUS_READ_BYTE_DATA \n";
- close(fd);
- return -1;
- }
-
int32_t statusMask = pchRegMaskIntrusion;
int32_t statusReg = pchStatusRegIntrusion;
- int32_t statusValue = i2c_smbus_read_byte_data(fd, statusReg);
- if (debug)
+ int32_t value = i2c_smbus_read_byte_data(mBusFd, statusReg);
+ if constexpr (debug)
{
- std::cout << "\nRead bus " << busId << " addr " << slaveAddr
- << ", value = " << statusValue << "\n";
+ std::cout << "Pch type: raw value is " << value << "\n";
}
- close(fd);
-
- if (statusValue < 0)
+ if (value < 0)
{
std::cerr << "i2c_smbus_read_byte_data failed \n";
return -1;
}
// Get status value with mask
- int newValue = statusValue & statusMask;
+ value &= statusMask;
- if (debug)
+ if constexpr (debug)
{
- std::cout << "statusValue is " << statusValue << "\n";
- std::cout << "Intrusion sensor value is " << newValue << "\n";
+ std::cout << "Pch type: masked raw value is " << value << "\n";
}
-
- return newValue;
+ return value;
}
-void ChassisIntrusionSensor::pollSensorStatusByPch()
+void ChassisIntrusionPchSensor::pollSensorStatus()
{
+ std::weak_ptr<ChassisIntrusionPchSensor> weakRef = weak_from_this();
// setting a new experation implicitly cancels any pending async wait
mPollTimer.expires_after(std::chrono::seconds(intrusionSensorPollSec));
- mPollTimer.async_wait([&](const boost::system::error_code& ec) {
- // case of timer expired
- if (!ec)
- {
- int statusValue = i2cReadFromPch(mBusId, mSlaveAddr);
- std::string newValue =
- statusValue != 0 ? "HardwareIntrusion" : "Normal";
-
- if (newValue != "unknown" && mValue != newValue)
- {
- std::cout << "update value from " << mValue << " to "
- << newValue << "\n";
- updateValue(newValue);
- }
-
- // trigger next polling
- pollSensorStatusByPch();
- }
+ mPollTimer.async_wait([weakRef](const boost::system::error_code& ec) {
// case of being canceled
- else if (ec == boost::asio::error::operation_aborted)
+ if (ec == boost::asio::error::operation_aborted)
{
- std::cerr << "Timer of intrusion sensor is cancelled. Return \n";
+ std::cerr << "Timer of intrusion sensor is cancelled\n";
return;
}
+ std::shared_ptr<ChassisIntrusionPchSensor> self = weakRef.lock();
+ if (!self)
+ {
+ std::cerr << "ChassisIntrusionSensor no self\n";
+ return;
+ }
+ int value = self->readSensor();
+ if (value < 0)
+ {
+ intrusionSensorPollSec = sensorFailedPollSec;
+ }
+ else
+ {
+ intrusionSensorPollSec = defaultPollSec;
+ self->updateValue(value);
+ }
+ // trigger next polling
+ self->pollSensorStatus();
});
}
-void ChassisIntrusionSensor::readGpio()
+int ChassisIntrusionGpioSensor::readSensor()
{
mGpioLine.event_read();
auto value = mGpioLine.get_value();
-
- // set string defined in chassis redfish schema
- std::string newValue = value != 0 ? "HardwareIntrusion" : "Normal";
-
- if (debug)
+ if constexpr (debug)
{
- std::cout << "\nGPIO value is " << value << "\n";
- std::cout << "Intrusion sensor value is " << newValue << "\n";
+ std::cout << "Gpio type: raw value is " << value << "\n";
}
-
- if (newValue != "unknown" && mValue != newValue)
- {
- std::cout << "update value from " << mValue << " to " << newValue
- << "\n";
- updateValue(newValue);
- }
+ return value;
}
-void ChassisIntrusionSensor::pollSensorStatusByGpio(void)
+void ChassisIntrusionGpioSensor::pollSensorStatus()
{
mGpioFd.async_wait(boost::asio::posix::stream_descriptor::wait_read,
[this](const boost::system::error_code& ec) {
@@ -215,52 +180,17 @@
}
else
{
- readGpio();
+ int value = readSensor();
+ if (value >= 0)
+ {
+ updateValue(value);
+ }
+ // trigger next polling
+ pollSensorStatus();
}
- pollSensorStatusByGpio();
});
}
-void ChassisIntrusionSensor::initGpioDeviceFile()
-{
- mGpioLine = gpiod::find_line(mPinName);
- if (!mGpioLine)
- {
- std::cerr << "ChassisIntrusionSensor error finding gpio pin name: "
- << mPinName << "\n";
- return;
- }
-
- try
- {
-
- mGpioLine.request(
- {"ChassisIntrusionSensor", gpiod::line_request::EVENT_BOTH_EDGES,
- mGpioInverted ? gpiod::line_request::FLAG_ACTIVE_LOW : 0});
-
- // set string defined in chassis redfish schema
- auto value = mGpioLine.get_value();
- std::string newValue = value != 0 ? "HardwareIntrusion" : "Normal";
- updateValue(newValue);
-
- auto gpioLineFd = mGpioLine.event_get_fd();
- if (gpioLineFd < 0)
- {
- std::cerr << "ChassisIntrusionSensor failed to get " << mPinName
- << " fd\n";
- return;
- }
-
- mGpioFd.assign(gpioLineFd);
- }
- catch (const std::system_error&)
- {
- std::cerr << "ChassisInrtusionSensor error requesting gpio pin name: "
- << mPinName << "\n";
- return;
- }
-}
-
int ChassisIntrusionSensor::setSensorValue(const std::string& req,
std::string& propertyValue)
{
@@ -276,112 +206,110 @@
return 1;
}
-void ChassisIntrusionSensor::start(IntrusionSensorType type, int busId,
- int slaveAddr, bool gpioInverted)
+void ChassisIntrusionSensor::start()
{
- if (debug)
- {
- std::cerr << "enter ChassisIntrusionSensor::start, type = " << type
- << "\n";
- if (type == IntrusionSensorType::pch)
- {
- std::cerr << "busId = " << busId << ", slaveAddr = " << slaveAddr
- << "\n";
- }
- else if (type == IntrusionSensorType::gpio)
- {
- std::cerr << "gpio pinName = " << mPinName
- << ", gpioInverted = " << gpioInverted << "\n";
- }
- }
-
- if ((type == IntrusionSensorType::pch && busId == mBusId &&
- slaveAddr == mSlaveAddr) ||
- (type == IntrusionSensorType::gpio && gpioInverted == mGpioInverted &&
- mInitialized))
- {
- return;
- }
-
- mType = type;
- mBusId = busId;
- mSlaveAddr = slaveAddr;
- mGpioInverted = gpioInverted;
-
- if ((mType == IntrusionSensorType::pch && mBusId > 0 && mSlaveAddr > 0) ||
- (mType == IntrusionSensorType::gpio))
- {
- // initialize first if not initialized before
- if (!mInitialized)
- {
- mIface->register_property(
- "Status", mValue,
- [&](const std::string& req, std::string& propertyValue) {
- return setSensorValue(req, propertyValue);
- });
- mIface->initialize();
-
- if (mType == IntrusionSensorType::gpio)
- {
- initGpioDeviceFile();
- }
-
- mInitialized = true;
- }
-
- // start polling value
- if (mType == IntrusionSensorType::pch)
- {
- pollSensorStatusByPch();
- }
- else if (mType == IntrusionSensorType::gpio && mGpioLine)
- {
- std::cerr << "Start polling intrusion sensors\n";
- pollSensorStatusByGpio();
- }
- }
-
- // invalid para, release resource
- else
- {
- if (mInitialized)
- {
- if (mType == IntrusionSensorType::pch)
- {
- mPollTimer.cancel();
- }
- else if (mType == IntrusionSensorType::gpio)
- {
- mGpioFd.close();
- if (mGpioLine)
- {
- mGpioLine.release();
- }
- }
- mInitialized = false;
- }
- }
+ mIface->register_property(
+ "Status", mValue,
+ [&](const std::string& req, std::string& propertyValue) {
+ return setSensorValue(req, propertyValue);
+ });
+ mIface->initialize();
+ pollSensorStatus();
}
ChassisIntrusionSensor::ChassisIntrusionSensor(
- boost::asio::io_context& io,
- std::shared_ptr<sdbusplus::asio::dbus_interface> iface) :
- mIface(std::move(iface)),
- mValue("unknown"), mOldValue("unknown"), mPollTimer(io), mGpioFd(io)
-{}
+ sdbusplus::asio::object_server& objServer) :
+ mObjServer(objServer)
+{
+ mIface = mObjServer.add_interface("/xyz/openbmc_project/Chassis/Intrusion",
+ "xyz.openbmc_project.Chassis.Intrusion");
+}
+
+ChassisIntrusionPchSensor::ChassisIntrusionPchSensor(
+ boost::asio::io_context& io, sdbusplus::asio::object_server& objServer,
+ int busId, int slaveAddr) :
+ ChassisIntrusionSensor(objServer),
+ mPollTimer(io)
+{
+ if (busId < 0 || slaveAddr <= 0)
+ {
+ throw std::invalid_argument("Invalid i2c bus " + std::to_string(busId) +
+ " address " + std::to_string(slaveAddr) +
+ "\n");
+ }
+ mSlaveAddr = slaveAddr;
+ std::string devPath = "/dev/i2c-" + std::to_string(busId);
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
+ mBusFd = open(devPath.c_str(), O_RDWR | O_CLOEXEC);
+ if (mBusFd < 0)
+ {
+ throw std::invalid_argument("Unable to open " + devPath + "\n");
+ }
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
+ if (ioctl(mBusFd, I2C_SLAVE_FORCE, mSlaveAddr) < 0)
+ {
+ throw std::runtime_error("Unable to set device address\n");
+ }
+
+ unsigned long funcs = 0;
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
+ if (ioctl(mBusFd, I2C_FUNCS, &funcs) < 0)
+ {
+ throw std::runtime_error("Don't support I2C_FUNCS\n");
+ }
+
+ if ((funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA) == 0U)
+ {
+ throw std::runtime_error(
+ "Do not have I2C_FUNC_SMBUS_READ_BYTE_DATA \n");
+ }
+}
+
+ChassisIntrusionGpioSensor::ChassisIntrusionGpioSensor(
+ boost::asio::io_context& io, sdbusplus::asio::object_server& objServer,
+ bool gpioInverted) :
+ ChassisIntrusionSensor(objServer),
+ mGpioInverted(gpioInverted), mGpioFd(io)
+{
+ mGpioLine = gpiod::find_line(mPinName);
+ if (!mGpioLine)
+ {
+ throw std::invalid_argument("Error finding gpio pin name: " + mPinName +
+ "\n");
+ }
+ mGpioLine.request(
+ {"ChassisIntrusionSensor", gpiod::line_request::EVENT_BOTH_EDGES,
+ mGpioInverted ? gpiod::line_request::FLAG_ACTIVE_LOW : 0});
+
+ auto gpioLineFd = mGpioLine.event_get_fd();
+ if (gpioLineFd < 0)
+ {
+ throw std::invalid_argument("Failed to get " + mPinName + " fd\n");
+ }
+ mGpioFd.assign(gpioLineFd);
+}
ChassisIntrusionSensor::~ChassisIntrusionSensor()
{
- if (mType == IntrusionSensorType::pch)
+ mObjServer.remove_interface(mIface);
+}
+
+ChassisIntrusionPchSensor::~ChassisIntrusionPchSensor()
+{
+ mPollTimer.cancel();
+ if (close(mBusFd) < 0)
{
- mPollTimer.cancel();
+ std::cerr << "Failed to close fd " << std::to_string(mBusFd);
}
- else if (mType == IntrusionSensorType::gpio)
+}
+
+ChassisIntrusionGpioSensor::~ChassisIntrusionGpioSensor()
+{
+ mGpioFd.close();
+ if (mGpioLine)
{
- mGpioFd.close();
- if (mGpioLine)
- {
- mGpioLine.release();
- }
+ mGpioLine.release();
}
}
diff --git a/src/ChassisIntrusionSensor.hpp b/src/ChassisIntrusionSensor.hpp
index be71e3f..e690bd2 100644
--- a/src/ChassisIntrusionSensor.hpp
+++ b/src/ChassisIntrusionSensor.hpp
@@ -8,56 +8,69 @@
#include <memory>
#include <string>
-enum IntrusionSensorType
-{
- pch,
- gpio
-};
+namespace fs = std::filesystem;
class ChassisIntrusionSensor
{
public:
- ChassisIntrusionSensor(
- boost::asio::io_context& io,
- std::shared_ptr<sdbusplus::asio::dbus_interface> iface);
+ explicit ChassisIntrusionSensor(sdbusplus::asio::object_server& objServer);
- ~ChassisIntrusionSensor();
+ virtual ~ChassisIntrusionSensor();
- void start(IntrusionSensorType type, int busId, int slaveAddr,
- bool gpioInverted);
+ void start();
+
+ protected:
+ virtual int readSensor() = 0;
+ virtual void pollSensorStatus() = 0;
+ void updateValue(const size_t& value);
private:
- std::shared_ptr<sdbusplus::asio::dbus_interface> mIface;
- std::shared_ptr<sdbusplus::asio::connection> mDbusConn;
-
- IntrusionSensorType mType{IntrusionSensorType::gpio};
-
// intrusion status. 0: not intruded, 1: intruded
std::string mValue = "unknown";
std::string mOldValue = "unknown";
+ std::shared_ptr<sdbusplus::asio::dbus_interface> mIface;
+ sdbusplus::asio::object_server& mObjServer;
+ bool mOverridenState = false;
+ bool mInternalSet = false;
- // valid if it is PCH register via i2c
- int mBusId{-1};
+ int setSensorValue(const std::string& req, std::string& propertyValue);
+};
+
+class ChassisIntrusionPchSensor :
+ public ChassisIntrusionSensor,
+ public std::enable_shared_from_this<ChassisIntrusionPchSensor>
+{
+ public:
+ ChassisIntrusionPchSensor(boost::asio::io_context& io,
+ sdbusplus::asio::object_server& objServer,
+ int busId, int slaveAddr);
+
+ ~ChassisIntrusionPchSensor() override;
+
+ private:
+ int mBusFd{-1};
int mSlaveAddr{-1};
boost::asio::steady_timer mPollTimer;
+ int readSensor() override;
+ void pollSensorStatus() override;
+};
- // valid if it is via GPIO
+class ChassisIntrusionGpioSensor :
+ public ChassisIntrusionSensor,
+ public std::enable_shared_from_this<ChassisIntrusionGpioSensor>
+{
+ public:
+ ChassisIntrusionGpioSensor(boost::asio::io_context& io,
+ sdbusplus::asio::object_server& objServer,
+ bool gpioInverted);
+
+ ~ChassisIntrusionGpioSensor() override;
+
+ private:
bool mGpioInverted{false};
std::string mPinName = "CHASSIS_INTRUSION";
gpiod::line mGpioLine;
boost::asio::posix::stream_descriptor mGpioFd;
-
- // common members
- bool mOverridenState = false;
- bool mInternalSet = false;
-
- bool mInitialized = false;
-
- void updateValue(const std::string& newValue);
- static int i2cReadFromPch(int busId, int slaveAddr);
- void pollSensorStatusByPch();
- void readGpio();
- void pollSensorStatusByGpio();
- void initGpioDeviceFile();
- int setSensorValue(const std::string& req, std::string& propertyValue);
+ int readSensor() override;
+ void pollSensorStatus() override;
};
diff --git a/src/IntrusionSensorMain.cpp b/src/IntrusionSensorMain.cpp
index 5b3cd84..362ffce 100644
--- a/src/IntrusionSensorMain.cpp
+++ b/src/IntrusionSensorMain.cpp
@@ -47,12 +47,10 @@
static constexpr const char* nicType = "NIC";
static constexpr auto nicTypes{std::to_array<const char*>({nicType})};
-namespace fs = std::filesystem;
-
-static bool getIntrusionSensorConfig(
+static void createSensorsFromConfig(
+ boost::asio::io_context& io, sdbusplus::asio::object_server& objServer,
const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
- IntrusionSensorType* pType, int* pBusId, int* pSlaveAddr,
- bool* pGpioInverted)
+ std::shared_ptr<ChassisIntrusionSensor>& pSensor)
{
// find matched configuration according to sensor type
ManagedObjectType sensorConfigurations;
@@ -62,7 +60,7 @@
sensorConfigurations, useCache))
{
std::cerr << "error communicating to entity manager\n";
- return false;
+ return;
}
const SensorData* sensorData = nullptr;
@@ -90,16 +88,6 @@
if (findClass != baseConfiguration->second.end() &&
std::get<std::string>(findClass->second) == "Gpio")
{
- *pType = IntrusionSensorType::gpio;
- }
- else
- {
- *pType = IntrusionSensorType::pch;
- }
-
- // case to find GPIO info
- if (*pType == IntrusionSensorType::gpio)
- {
auto findGpioPolarity =
baseConfiguration->second.find("GpioPolarity");
@@ -111,27 +99,32 @@
try
{
- *pGpioInverted =
+ bool gpioInverted =
(std::get<std::string>(findGpioPolarity->second) == "Low");
+ pSensor = std::make_shared<ChassisIntrusionGpioSensor>(
+ io, objServer, gpioInverted);
+ pSensor->start();
+ if (debug)
+ {
+ std::cout
+ << "find chassis intrusion sensor polarity inverted "
+ "flag is "
+ << gpioInverted << "\n";
+ }
+ return;
}
catch (const std::bad_variant_access& e)
{
std::cerr << "invalid value for gpio info in config. \n";
continue;
}
-
- if (debug)
+ catch (const std::exception& e)
{
- std::cout << "find chassis intrusion sensor polarity inverted "
- "flag is "
- << *pGpioInverted << "\n";
+ std::cerr << e.what() << std::endl;
+ continue;
}
-
- return true;
}
-
- // case to find I2C info
- if (*pType == IntrusionSensorType::pch)
+ else
{
auto findBus = baseConfiguration->second.find("Bus");
auto findAddress = baseConfiguration->second.find("Address");
@@ -141,32 +134,42 @@
std::cerr << "error finding bus or address in configuration \n";
continue;
}
-
try
{
- *pBusId = std::get<uint64_t>(findBus->second);
- *pSlaveAddr = std::get<uint64_t>(findAddress->second);
+ int busId = std::get<uint64_t>(findBus->second);
+ int slaveAddr = std::get<uint64_t>(findAddress->second);
+ pSensor = std::make_shared<ChassisIntrusionPchSensor>(
+ io, objServer, busId, slaveAddr);
+ pSensor->start();
+ if (debug)
+ {
+ std::cout << "find matched bus " << busId
+ << ", matched slave addr " << slaveAddr << "\n";
+ }
+ return;
}
catch (const std::bad_variant_access& e)
{
std::cerr << "invalid value for bus or address in config. \n";
continue;
}
-
- if (debug)
+ catch (const std::exception& e)
{
- std::cout << "find matched bus " << *pBusId
- << ", matched slave addr " << *pSlaveAddr << "\n";
+ std::cerr << e.what() << std::endl;
+ continue;
}
- return true;
}
}
- std::cerr << "can't find matched I2C or GPIO configuration for intrusion "
- "sensor. \n";
- *pBusId = -1;
- *pSlaveAddr = -1;
- return false;
+ std::cerr << " Can't find matched I2C, GPIO configuration\n";
+
+ // Make sure nothing runs when there's failure in configuration for the
+ // sensor after rescan
+ if (pSensor)
+ {
+ std::cerr << " Reset the occupied sensor pointer\n";
+ pSensor = nullptr;
+ }
}
static constexpr bool debugLanLeash = false;
@@ -411,10 +414,7 @@
int main()
{
- int busId = -1;
- int slaveAddr = -1;
- bool gpioInverted = false;
- IntrusionSensorType type = IntrusionSensorType::gpio;
+ std::shared_ptr<ChassisIntrusionSensor> intrusionSensor;
// setup connection to dbus
boost::asio::io_context io;
@@ -427,17 +427,7 @@
objServer.add_manager("/xyz/openbmc_project/Chassis");
- std::shared_ptr<sdbusplus::asio::dbus_interface> ifaceChassis =
- objServer.add_interface("/xyz/openbmc_project/Chassis/Intrusion",
- "xyz.openbmc_project.Chassis.Intrusion");
-
- ChassisIntrusionSensor chassisIntrusionSensor(io, ifaceChassis);
-
- if (getIntrusionSensorConfig(systemBus, &type, &busId, &slaveAddr,
- &gpioInverted))
- {
- chassisIntrusionSensor.start(type, busId, slaveAddr, gpioInverted);
- }
+ createSensorsFromConfig(io, objServer, systemBus, intrusionSensor);
// callback to handle configuration change
std::function<void(sdbusplus::message_t&)> eventHandler =
@@ -449,11 +439,7 @@
}
std::cout << "rescan due to configuration change \n";
- if (getIntrusionSensorConfig(systemBus, &type, &busId, &slaveAddr,
- &gpioInverted))
- {
- chassisIntrusionSensor.start(type, busId, slaveAddr, gpioInverted);
- }
+ createSensorsFromConfig(io, objServer, systemBus, intrusionSensor);
};
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =