Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 17 | #include "ChassisIntrusionSensor.hpp" |
| 18 | |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 19 | #include <fcntl.h> |
| 20 | #include <sys/ioctl.h> |
Matt Simmering | 79a160b | 2022-11-14 16:50:48 -0800 | [diff] [blame^] | 21 | #include <systemd/sd-journal.h> |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 22 | #include <unistd.h> |
| 23 | |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 24 | #include <boost/asio/io_context.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 25 | #include <sdbusplus/asio/object_server.hpp> |
| 26 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 27 | #include <cerrno> |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 28 | #include <chrono> |
| 29 | #include <iostream> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 30 | #include <memory> |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 31 | #include <string> |
| 32 | #include <thread> |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 33 | #include <utility> |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 34 | |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 35 | extern "C" |
| 36 | { |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 37 | #include <i2c/smbus.h> |
| 38 | #include <linux/i2c-dev.h> |
| 39 | } |
| 40 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 41 | static constexpr bool debug = false; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 42 | |
| 43 | static constexpr unsigned int intrusionSensorPollSec = 1; |
| 44 | |
| 45 | // SMLink Status Register |
| 46 | const static constexpr size_t pchStatusRegIntrusion = 0x04; |
| 47 | |
| 48 | // Status bit field masks |
| 49 | const static constexpr size_t pchRegMaskIntrusion = 0x01; |
| 50 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 51 | void ChassisIntrusionSensor::updateValue(const std::string& newValue) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 52 | { |
Josh Lehan | 833661a | 2020-03-04 17:35:41 -0800 | [diff] [blame] | 53 | // Take no action if value already equal |
| 54 | // Same semantics as Sensor::updateValue(const double&) |
| 55 | if (newValue == mValue) |
| 56 | { |
| 57 | return; |
| 58 | } |
| 59 | |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 60 | // indicate that it is internal set call |
| 61 | mInternalSet = true; |
| 62 | mIface->set_property("Status", newValue); |
Richard Marian Thomaiyar | af6b87c | 2019-04-03 23:54:28 +0530 | [diff] [blame] | 63 | mInternalSet = false; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 64 | |
| 65 | mValue = newValue; |
| 66 | |
| 67 | if (mOldValue == "Normal" && mValue != "Normal") |
| 68 | { |
Matt Simmering | 79a160b | 2022-11-14 16:50:48 -0800 | [diff] [blame^] | 69 | sd_journal_send("MESSAGE=%s", "Chassis intrusion assert event", |
| 70 | "PRIORITY=%i", LOG_INFO, "REDFISH_MESSAGE_ID=%s", |
| 71 | "OpenBMC.0.1.ChassisIntrusionDetected", NULL); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 72 | mOldValue = mValue; |
| 73 | } |
| 74 | else if (mOldValue != "Normal" && mValue == "Normal") |
| 75 | { |
Matt Simmering | 79a160b | 2022-11-14 16:50:48 -0800 | [diff] [blame^] | 76 | sd_journal_send("MESSAGE=%s", "Chassis intrusion de-assert event", |
| 77 | "PRIORITY=%i", LOG_INFO, "REDFISH_MESSAGE_ID=%s", |
| 78 | "OpenBMC.0.1.ChassisIntrusionReset", NULL); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 79 | mOldValue = mValue; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | int ChassisIntrusionSensor::i2cReadFromPch(int busId, int slaveAddr) |
| 84 | { |
| 85 | std::string i2cBus = "/dev/i2c-" + std::to_string(busId); |
| 86 | |
Ed Tanous | 99c4409 | 2022-01-14 09:59:09 -0800 | [diff] [blame] | 87 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 88 | int fd = open(i2cBus.c_str(), O_RDWR | O_CLOEXEC); |
| 89 | if (fd < 0) |
| 90 | { |
| 91 | std::cerr << "unable to open i2c device \n"; |
| 92 | return -1; |
| 93 | } |
Ed Tanous | 99c4409 | 2022-01-14 09:59:09 -0800 | [diff] [blame] | 94 | |
| 95 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 96 | if (ioctl(fd, I2C_SLAVE_FORCE, slaveAddr) < 0) |
| 97 | { |
| 98 | std::cerr << "unable to set device address\n"; |
| 99 | close(fd); |
| 100 | return -1; |
| 101 | } |
| 102 | |
| 103 | unsigned long funcs = 0; |
Ed Tanous | 99c4409 | 2022-01-14 09:59:09 -0800 | [diff] [blame] | 104 | |
| 105 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 106 | if (ioctl(fd, I2C_FUNCS, &funcs) < 0) |
| 107 | { |
| 108 | std::cerr << "not support I2C_FUNCS \n"; |
| 109 | close(fd); |
| 110 | return -1; |
| 111 | } |
| 112 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 113 | if ((funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA) == 0U) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 114 | { |
| 115 | std::cerr << "not support I2C_FUNC_SMBUS_READ_BYTE_DATA \n"; |
| 116 | close(fd); |
| 117 | return -1; |
| 118 | } |
| 119 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 120 | int32_t statusMask = pchRegMaskIntrusion; |
| 121 | int32_t statusReg = pchStatusRegIntrusion; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 122 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 123 | int32_t statusValue = i2c_smbus_read_byte_data(fd, statusReg); |
| 124 | if (debug) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 125 | { |
| 126 | std::cout << "\nRead bus " << busId << " addr " << slaveAddr |
| 127 | << ", value = " << statusValue << "\n"; |
| 128 | } |
| 129 | |
| 130 | close(fd); |
| 131 | |
| 132 | if (statusValue < 0) |
| 133 | { |
| 134 | std::cerr << "i2c_smbus_read_byte_data failed \n"; |
| 135 | return -1; |
| 136 | } |
| 137 | |
| 138 | // Get status value with mask |
| 139 | int newValue = statusValue & statusMask; |
| 140 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 141 | if (debug) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 142 | { |
| 143 | std::cout << "statusValue is " << statusValue << "\n"; |
| 144 | std::cout << "Intrusion sensor value is " << newValue << "\n"; |
| 145 | } |
| 146 | |
| 147 | return newValue; |
| 148 | } |
| 149 | |
| 150 | void ChassisIntrusionSensor::pollSensorStatusByPch() |
| 151 | { |
| 152 | // setting a new experation implicitly cancels any pending async wait |
Ed Tanous | 83db50c | 2023-03-01 10:20:24 -0800 | [diff] [blame] | 153 | mPollTimer.expires_after(std::chrono::seconds(intrusionSensorPollSec)); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 154 | |
| 155 | mPollTimer.async_wait([&](const boost::system::error_code& ec) { |
| 156 | // case of timer expired |
| 157 | if (!ec) |
| 158 | { |
| 159 | int statusValue = i2cReadFromPch(mBusId, mSlaveAddr); |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 160 | std::string newValue = |
| 161 | statusValue != 0 ? "HardwareIntrusion" : "Normal"; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 162 | |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 163 | if (newValue != "unknown" && mValue != newValue) |
| 164 | { |
| 165 | std::cout << "update value from " << mValue << " to " |
| 166 | << newValue << "\n"; |
| 167 | updateValue(newValue); |
| 168 | } |
| 169 | |
| 170 | // trigger next polling |
| 171 | pollSensorStatusByPch(); |
| 172 | } |
| 173 | // case of being canceled |
| 174 | else if (ec == boost::asio::error::operation_aborted) |
| 175 | { |
| 176 | std::cerr << "Timer of intrusion sensor is cancelled. Return \n"; |
| 177 | return; |
| 178 | } |
| 179 | }); |
| 180 | } |
| 181 | |
| 182 | void ChassisIntrusionSensor::readGpio() |
| 183 | { |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 184 | mGpioLine.event_read(); |
| 185 | auto value = mGpioLine.get_value(); |
| 186 | |
| 187 | // set string defined in chassis redfish schema |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 188 | std::string newValue = value != 0 ? "HardwareIntrusion" : "Normal"; |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 189 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 190 | if (debug) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 191 | { |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 192 | std::cout << "\nGPIO value is " << value << "\n"; |
| 193 | std::cout << "Intrusion sensor value is " << newValue << "\n"; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 194 | } |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 195 | |
| 196 | if (newValue != "unknown" && mValue != newValue) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 197 | { |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 198 | std::cout << "update value from " << mValue << " to " << newValue |
| 199 | << "\n"; |
| 200 | updateValue(newValue); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
| 204 | void ChassisIntrusionSensor::pollSensorStatusByGpio(void) |
| 205 | { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 206 | mGpioFd.async_wait(boost::asio::posix::stream_descriptor::wait_read, |
| 207 | [this](const boost::system::error_code& ec) { |
| 208 | if (ec == boost::system::errc::bad_file_descriptor) |
| 209 | { |
| 210 | return; // we're being destroyed |
| 211 | } |
| 212 | if (ec) |
| 213 | { |
| 214 | std::cerr << "Error on GPIO based intrusion sensor wait event\n"; |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | readGpio(); |
| 219 | } |
| 220 | pollSensorStatusByGpio(); |
| 221 | }); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 222 | } |
| 223 | |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 224 | void ChassisIntrusionSensor::initGpioDeviceFile() |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 225 | { |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 226 | mGpioLine = gpiod::find_line(mPinName); |
| 227 | if (!mGpioLine) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 228 | { |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 229 | std::cerr << "ChassisIntrusionSensor error finding gpio pin name: " |
| 230 | << mPinName << "\n"; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 231 | return; |
| 232 | } |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 233 | |
| 234 | try |
| 235 | { |
| 236 | |
| 237 | mGpioLine.request( |
| 238 | {"ChassisIntrusionSensor", gpiod::line_request::EVENT_BOTH_EDGES, |
| 239 | mGpioInverted ? gpiod::line_request::FLAG_ACTIVE_LOW : 0}); |
| 240 | |
| 241 | // set string defined in chassis redfish schema |
| 242 | auto value = mGpioLine.get_value(); |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 243 | std::string newValue = value != 0 ? "HardwareIntrusion" : "Normal"; |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 244 | updateValue(newValue); |
| 245 | |
| 246 | auto gpioLineFd = mGpioLine.event_get_fd(); |
| 247 | if (gpioLineFd < 0) |
| 248 | { |
| 249 | std::cerr << "ChassisIntrusionSensor failed to get " << mPinName |
| 250 | << " fd\n"; |
| 251 | return; |
| 252 | } |
| 253 | |
| 254 | mGpioFd.assign(gpioLineFd); |
| 255 | } |
Patrick Williams | 26601e8 | 2021-10-06 12:43:25 -0500 | [diff] [blame] | 256 | catch (const std::system_error&) |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 257 | { |
| 258 | std::cerr << "ChassisInrtusionSensor error requesting gpio pin name: " |
| 259 | << mPinName << "\n"; |
| 260 | return; |
| 261 | } |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | int ChassisIntrusionSensor::setSensorValue(const std::string& req, |
| 265 | std::string& propertyValue) |
| 266 | { |
Richard Marian Thomaiyar | af6b87c | 2019-04-03 23:54:28 +0530 | [diff] [blame] | 267 | if (!mInternalSet) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 268 | { |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 269 | propertyValue = req; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 270 | mOverridenState = true; |
| 271 | } |
Richard Marian Thomaiyar | af6b87c | 2019-04-03 23:54:28 +0530 | [diff] [blame] | 272 | else if (!mOverridenState) |
| 273 | { |
| 274 | propertyValue = req; |
| 275 | } |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 276 | return 1; |
| 277 | } |
| 278 | |
| 279 | void ChassisIntrusionSensor::start(IntrusionSensorType type, int busId, |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 280 | int slaveAddr, bool gpioInverted) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 281 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 282 | if (debug) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 283 | { |
| 284 | std::cerr << "enter ChassisIntrusionSensor::start, type = " << type |
| 285 | << "\n"; |
| 286 | if (type == IntrusionSensorType::pch) |
| 287 | { |
| 288 | std::cerr << "busId = " << busId << ", slaveAddr = " << slaveAddr |
| 289 | << "\n"; |
| 290 | } |
| 291 | else if (type == IntrusionSensorType::gpio) |
| 292 | { |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 293 | std::cerr << "gpio pinName = " << mPinName |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 294 | << ", gpioInverted = " << gpioInverted << "\n"; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | if ((type == IntrusionSensorType::pch && busId == mBusId && |
| 299 | slaveAddr == mSlaveAddr) || |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 300 | (type == IntrusionSensorType::gpio && gpioInverted == mGpioInverted && |
| 301 | mInitialized)) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 302 | { |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | mType = type; |
| 307 | mBusId = busId; |
| 308 | mSlaveAddr = slaveAddr; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 309 | mGpioInverted = gpioInverted; |
| 310 | |
| 311 | if ((mType == IntrusionSensorType::pch && mBusId > 0 && mSlaveAddr > 0) || |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 312 | (mType == IntrusionSensorType::gpio)) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 313 | { |
| 314 | // initialize first if not initialized before |
| 315 | if (!mInitialized) |
| 316 | { |
| 317 | mIface->register_property( |
| 318 | "Status", mValue, |
| 319 | [&](const std::string& req, std::string& propertyValue) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 320 | return setSensorValue(req, propertyValue); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 321 | }); |
| 322 | mIface->initialize(); |
| 323 | |
| 324 | if (mType == IntrusionSensorType::gpio) |
| 325 | { |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 326 | initGpioDeviceFile(); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | mInitialized = true; |
| 330 | } |
| 331 | |
| 332 | // start polling value |
| 333 | if (mType == IntrusionSensorType::pch) |
| 334 | { |
| 335 | pollSensorStatusByPch(); |
| 336 | } |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 337 | else if (mType == IntrusionSensorType::gpio && mGpioLine) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 338 | { |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 339 | std::cerr << "Start polling intrusion sensors\n"; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 340 | pollSensorStatusByGpio(); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | // invalid para, release resource |
| 345 | else |
| 346 | { |
| 347 | if (mInitialized) |
| 348 | { |
| 349 | if (mType == IntrusionSensorType::pch) |
| 350 | { |
| 351 | mPollTimer.cancel(); |
| 352 | } |
| 353 | else if (mType == IntrusionSensorType::gpio) |
| 354 | { |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 355 | mGpioFd.close(); |
| 356 | if (mGpioLine) |
| 357 | { |
| 358 | mGpioLine.release(); |
| 359 | } |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 360 | } |
| 361 | mInitialized = false; |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | ChassisIntrusionSensor::ChassisIntrusionSensor( |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 367 | boost::asio::io_context& io, |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 368 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface) : |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 369 | mIface(std::move(iface)), |
Ed Tanous | b429f31 | 2022-06-27 16:09:53 -0700 | [diff] [blame] | 370 | mValue("unknown"), mOldValue("unknown"), mPollTimer(io), mGpioFd(io) |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 371 | {} |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 372 | |
| 373 | ChassisIntrusionSensor::~ChassisIntrusionSensor() |
| 374 | { |
| 375 | if (mType == IntrusionSensorType::pch) |
| 376 | { |
| 377 | mPollTimer.cancel(); |
| 378 | } |
| 379 | else if (mType == IntrusionSensorType::gpio) |
| 380 | { |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 381 | mGpioFd.close(); |
| 382 | if (mGpioLine) |
| 383 | { |
| 384 | mGpioLine.release(); |
| 385 | } |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 386 | } |
| 387 | } |