blob: 56affca818d62007c437106affa6dd6a17fcc0ea [file] [log] [blame]
Qiang XUe28d1fa2019-02-27 13:50:56 +08001#pragma once
2
James Feist8086aba2020-08-25 16:00:59 -07003#include <boost/asio/deadline_timer.hpp>
4#include <boost/asio/io_service.hpp>
ZhikuiRenba8a8bf2020-01-09 15:55:43 -08005#include <gpiod.hpp>
Qiang XUe28d1fa2019-02-27 13:50:56 +08006#include <sdbusplus/asio/object_server.hpp>
James Feist38fb5982020-05-28 10:09:54 -07007
8#include <memory>
Patrick Venturefd6ba732019-10-31 14:27:39 -07009#include <string>
Qiang XUe28d1fa2019-02-27 13:50:56 +080010
11enum IntrusionSensorType
12{
13 pch,
14 gpio
15};
16
17class ChassisIntrusionSensor
18{
19 public:
20 ChassisIntrusionSensor(
21 boost::asio::io_service& io,
22 std::shared_ptr<sdbusplus::asio::dbus_interface> iface);
23
24 ~ChassisIntrusionSensor();
25
26 void start(IntrusionSensorType type, int busId, int slaveAddr,
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080027 bool gpioInverted);
Qiang XUe28d1fa2019-02-27 13:50:56 +080028
29 private:
30 std::shared_ptr<sdbusplus::asio::dbus_interface> mIface;
31 std::shared_ptr<sdbusplus::asio::connection> mDbusConn;
32
Ed Tanousb429f312022-06-27 16:09:53 -070033 IntrusionSensorType mType{IntrusionSensorType::gpio};
Qiang XUe28d1fa2019-02-27 13:50:56 +080034
35 // intrusion status. 0: not intruded, 1: intruded
36 std::string mValue = "unknown";
37 std::string mOldValue = "unknown";
38
39 // valid if it is PCH register via i2c
Ed Tanousb429f312022-06-27 16:09:53 -070040 int mBusId{-1};
41 int mSlaveAddr{-1};
Qiang XUe28d1fa2019-02-27 13:50:56 +080042 boost::asio::deadline_timer mPollTimer;
43
44 // valid if it is via GPIO
Ed Tanousb429f312022-06-27 16:09:53 -070045 bool mGpioInverted{false};
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080046 std::string mPinName = "CHASSIS_INTRUSION";
47 gpiod::line mGpioLine;
48 boost::asio::posix::stream_descriptor mGpioFd;
Qiang XUe28d1fa2019-02-27 13:50:56 +080049
50 // common members
Qiang XUe28d1fa2019-02-27 13:50:56 +080051 bool mOverridenState = false;
52 bool mInternalSet = false;
53
54 bool mInitialized = false;
55
Ed Tanous8a57ec02020-10-09 12:46:52 -070056 void updateValue(const std::string& newValue);
Ed Tanous2049bd22022-07-09 07:20:26 -070057 static int i2cReadFromPch(int busId, int slaveAddr);
Qiang XUe28d1fa2019-02-27 13:50:56 +080058 void pollSensorStatusByPch();
59 void readGpio();
60 void pollSensorStatusByGpio();
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080061 void initGpioDeviceFile();
Qiang XUe28d1fa2019-02-27 13:50:56 +080062 int setSensorValue(const std::string& req, std::string& propertyValue);
63};