blob: 3545233d2c944a756126a575418a8737e2029c30 [file] [log] [blame]
Qiang XUe28d1fa2019-02-27 13:50:56 +08001/*
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 Jefferye73bd0a2023-01-25 10:39:57 +103017#include "ChassisIntrusionSensor.hpp"
18#include "Utils.hpp"
19
Ed Tanous1f978632023-02-28 18:16:39 -080020#include <boost/asio/io_context.hpp>
Patrick Venture96e97db2019-10-31 13:44:38 -070021#include <boost/container/flat_map.hpp>
Patrick Williams0c42f402021-08-27 16:05:45 -050022#include <phosphor-logging/lg2.hpp>
Qiang XUe28d1fa2019-02-27 13:50:56 +080023#include <sdbusplus/asio/connection.hpp>
24#include <sdbusplus/asio/object_server.hpp>
Qiang XUe28d1fa2019-02-27 13:50:56 +080025#include <sdbusplus/bus.hpp>
Patrick Venture96e97db2019-10-31 13:44:38 -070026#include <sdbusplus/bus/match.hpp>
Qiang XUe28d1fa2019-02-27 13:50:56 +080027#include <sdbusplus/exception.hpp>
28#include <sdbusplus/server.hpp>
29#include <sdbusplus/timer.hpp>
James Feist38fb5982020-05-28 10:09:54 -070030
31#include <array>
Ed Tanous8a57ec02020-10-09 12:46:52 -070032#include <charconv>
James Feist38fb5982020-05-28 10:09:54 -070033#include <chrono>
34#include <ctime>
35#include <fstream>
36#include <functional>
37#include <iostream>
38#include <memory>
Patrick Venture96e97db2019-10-31 13:44:38 -070039#include <stdexcept>
40#include <string>
41#include <utility>
42#include <vector>
Qiang XUe28d1fa2019-02-27 13:50:56 +080043
Ed Tanous8a57ec02020-10-09 12:46:52 -070044static constexpr bool debug = false;
Qiang XUe28d1fa2019-02-27 13:50:56 +080045
Zev Weiss054aad82022-08-18 01:37:34 -070046static constexpr const char* sensorType = "ChassisIntrusionSensor";
47static constexpr const char* nicType = "NIC";
Brandon Kim66558232021-11-09 16:53:08 -080048static constexpr auto nicTypes{std::to_array<const char*>({nicType})};
Qiang XUe28d1fa2019-02-27 13:50:56 +080049
Chau Ly95f49932023-04-19 09:44:55 +000050static const std::map<std::string, std::string> compatibleHwmonNames = {
51 {"Aspeed2600_Hwmon", "intrusion0_alarm"}
52 // Add compatible strings here for new hwmon intrusion detection
53 // drivers that have different hwmon names but would also like to
54 // use the available Hwmon class.
55};
56
Chau Lycebb28c2022-10-21 10:01:52 +000057static void createSensorsFromConfig(
58 boost::asio::io_context& io, sdbusplus::asio::object_server& objServer,
Lei YUba637932021-03-17 10:35:00 +080059 const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
Chau Lycebb28c2022-10-21 10:01:52 +000060 std::shared_ptr<ChassisIntrusionSensor>& pSensor)
Qiang XUe28d1fa2019-02-27 13:50:56 +080061{
62 // find matched configuration according to sensor type
63 ManagedObjectType sensorConfigurations;
64 bool useCache = false;
65
66 if (!getSensorConfiguration(sensorType, dbusConnection,
67 sensorConfigurations, useCache))
68 {
69 std::cerr << "error communicating to entity manager\n";
Chau Lycebb28c2022-10-21 10:01:52 +000070 return;
Qiang XUe28d1fa2019-02-27 13:50:56 +080071 }
72
73 const SensorData* sensorData = nullptr;
Zev Weissafd15042022-07-18 12:28:40 -070074 const std::pair<std::string, SensorBaseConfigMap>* baseConfiguration =
75 nullptr;
Qiang XUe28d1fa2019-02-27 13:50:56 +080076
Zev Weissf343b8a2022-08-12 18:21:01 -070077 for (const auto& [path, cfgData] : sensorConfigurations)
Qiang XUe28d1fa2019-02-27 13:50:56 +080078 {
79 baseConfiguration = nullptr;
Zev Weissf343b8a2022-08-12 18:21:01 -070080 sensorData = &cfgData;
Qiang XUe28d1fa2019-02-27 13:50:56 +080081
82 // match sensor type
Zev Weiss054aad82022-08-18 01:37:34 -070083 auto sensorBase = sensorData->find(configInterfaceName(sensorType));
Qiang XUe28d1fa2019-02-27 13:50:56 +080084 if (sensorBase == sensorData->end())
85 {
86 std::cerr << "error finding base configuration \n";
87 continue;
88 }
89
90 baseConfiguration = &(*sensorBase);
91
Chau Ly95f49932023-04-19 09:44:55 +000092 // judge class, "Gpio", "Hwmon" or "I2C"
Qiang XUe28d1fa2019-02-27 13:50:56 +080093 auto findClass = baseConfiguration->second.find("Class");
Chau Ly95f49932023-04-19 09:44:55 +000094 if (findClass != baseConfiguration->second.end())
Qiang XUe28d1fa2019-02-27 13:50:56 +080095 {
Chau Ly95f49932023-04-19 09:44:55 +000096 auto classString = std::get<std::string>(findClass->second);
97 if (classString == "Gpio")
98 {
99 auto findGpioPolarity =
100 baseConfiguration->second.find("GpioPolarity");
Qiang XUe28d1fa2019-02-27 13:50:56 +0800101
Chau Ly95f49932023-04-19 09:44:55 +0000102 if (findGpioPolarity == baseConfiguration->second.end())
103 {
104 std::cerr
105 << "error finding gpio polarity in configuration \n";
106 continue;
107 }
Qiang XUe28d1fa2019-02-27 13:50:56 +0800108
Chau Ly95f49932023-04-19 09:44:55 +0000109 try
Chau Lycebb28c2022-10-21 10:01:52 +0000110 {
Chau Ly95f49932023-04-19 09:44:55 +0000111 bool gpioInverted =
112 (std::get<std::string>(findGpioPolarity->second) ==
113 "Low");
114 pSensor = std::make_shared<ChassisIntrusionGpioSensor>(
115 io, objServer, gpioInverted);
116 pSensor->start();
117 if (debug)
118 {
119 std::cout
120 << "find chassis intrusion sensor polarity inverted "
121 "flag is "
122 << gpioInverted << "\n";
123 }
124 return;
Chau Lycebb28c2022-10-21 10:01:52 +0000125 }
Chau Ly95f49932023-04-19 09:44:55 +0000126 catch (const std::bad_variant_access& e)
Chau Lycebb28c2022-10-21 10:01:52 +0000127 {
Chau Ly95f49932023-04-19 09:44:55 +0000128 std::cerr << "invalid value for gpio info in config. \n";
129 continue;
Chau Lycebb28c2022-10-21 10:01:52 +0000130 }
Chau Ly95f49932023-04-19 09:44:55 +0000131 catch (const std::exception& e)
132 {
133 std::cerr << e.what() << std::endl;
134 continue;
135 }
Qiang XUe28d1fa2019-02-27 13:50:56 +0800136 }
Chau Ly95f49932023-04-19 09:44:55 +0000137 // If class string contains Hwmon string
138 else if (classString.find("Hwmon") != std::string::npos)
Qiang XUe28d1fa2019-02-27 13:50:56 +0800139 {
Chau Ly95f49932023-04-19 09:44:55 +0000140 std::string hwmonName;
141 std::map<std::string, std::string>::const_iterator
142 compatIterator = compatibleHwmonNames.find(classString);
143
144 if (compatIterator == compatibleHwmonNames.end())
145 {
146 std::cerr << "Hwmon Class string is not supported\n";
147 continue;
148 }
149
150 hwmonName = compatIterator->second;
151
152 try
153 {
154 pSensor = std::make_shared<ChassisIntrusionHwmonSensor>(
155 io, objServer, hwmonName);
156 pSensor->start();
157 return;
158 }
159 catch (const std::exception& e)
160 {
161 std::cerr << e.what() << std::endl;
162 continue;
163 }
Qiang XUe28d1fa2019-02-27 13:50:56 +0800164 }
Chau Ly95f49932023-04-19 09:44:55 +0000165 else
Qiang XUe28d1fa2019-02-27 13:50:56 +0800166 {
Chau Ly95f49932023-04-19 09:44:55 +0000167 auto findBus = baseConfiguration->second.find("Bus");
168 auto findAddress = baseConfiguration->second.find("Address");
169 if (findBus == baseConfiguration->second.end() ||
170 findAddress == baseConfiguration->second.end())
171 {
172 std::cerr
173 << "error finding bus or address in configuration \n";
174 continue;
175 }
176 try
177 {
178 int busId = std::get<uint64_t>(findBus->second);
179 int slaveAddr = std::get<uint64_t>(findAddress->second);
180 pSensor = std::make_shared<ChassisIntrusionPchSensor>(
181 io, objServer, busId, slaveAddr);
182 pSensor->start();
183 if (debug)
184 {
185 std::cout << "find matched bus " << busId
186 << ", matched slave addr " << slaveAddr
187 << "\n";
188 }
189 return;
190 }
191 catch (const std::bad_variant_access& e)
192 {
193 std::cerr
194 << "invalid value for bus or address in config. \n";
195 continue;
196 }
197 catch (const std::exception& e)
198 {
199 std::cerr << e.what() << std::endl;
200 continue;
201 }
Qiang XUe28d1fa2019-02-27 13:50:56 +0800202 }
Qiang XUe28d1fa2019-02-27 13:50:56 +0800203 }
204 }
205
Chau Ly95f49932023-04-19 09:44:55 +0000206 std::cerr << " Can't find matched I2C, GPIO or Hwmon configuration\n";
Chau Lycebb28c2022-10-21 10:01:52 +0000207
208 // Make sure nothing runs when there's failure in configuration for the
209 // sensor after rescan
210 if (pSensor)
211 {
212 std::cerr << " Reset the occupied sensor pointer\n";
213 pSensor = nullptr;
214 }
Qiang XUe28d1fa2019-02-27 13:50:56 +0800215}
216
Qiang XU88b7f282019-08-14 22:51:43 +0800217static constexpr bool debugLanLeash = false;
218boost::container::flat_map<int, bool> lanStatusMap;
Qiang XU74ddf862019-09-12 17:12:13 +0800219boost::container::flat_map<int, std::string> lanInfoMap;
Qiang XU88b7f282019-08-14 22:51:43 +0800220boost::container::flat_map<std::string, int> pathSuffixMap;
221
Lei YUba637932021-03-17 10:35:00 +0800222static void getNicNameInfo(
223 const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
Qiang XU74ddf862019-09-12 17:12:13 +0800224{
225 auto getter = std::make_shared<GetSensorConfiguration>(
Patrick Williams779c96a2023-05-10 07:50:42 -0500226 dbusConnection,
227 [](const ManagedObjectType& sensorConfigurations) {
228 // Get NIC name and save to map
229 lanInfoMap.clear();
230 for (const auto& [path, cfgData] : sensorConfigurations)
231 {
232 const std::pair<std::string, SensorBaseConfigMap>*
233 baseConfiguration = nullptr;
234
235 // find base configuration
236 auto sensorBase = cfgData.find(configInterfaceName(nicType));
237 if (sensorBase == cfgData.end())
Qiang XU74ddf862019-09-12 17:12:13 +0800238 {
Patrick Williams779c96a2023-05-10 07:50:42 -0500239 continue;
240 }
241 baseConfiguration = &(*sensorBase);
Qiang XU74ddf862019-09-12 17:12:13 +0800242
Patrick Williams779c96a2023-05-10 07:50:42 -0500243 auto findEthIndex = baseConfiguration->second.find("EthIndex");
244 auto findName = baseConfiguration->second.find("Name");
245
246 if (findEthIndex != baseConfiguration->second.end() &&
247 findName != baseConfiguration->second.end())
248 {
249 const auto* pEthIndex =
250 std::get_if<uint64_t>(&findEthIndex->second);
251 const auto* pName = std::get_if<std::string>(&findName->second);
252 if (pEthIndex != nullptr && pName != nullptr)
Qiang XU74ddf862019-09-12 17:12:13 +0800253 {
Patrick Williams779c96a2023-05-10 07:50:42 -0500254 lanInfoMap[*pEthIndex] = *pName;
255 if (debugLanLeash)
Qiang XU74ddf862019-09-12 17:12:13 +0800256 {
Patrick Williams779c96a2023-05-10 07:50:42 -0500257 std::cout << "find name of eth" << *pEthIndex << " is "
258 << *pName << "\n";
Qiang XU74ddf862019-09-12 17:12:13 +0800259 }
260 }
261 }
Patrick Williams779c96a2023-05-10 07:50:42 -0500262 }
Qiang XU74ddf862019-09-12 17:12:13 +0800263
Patrick Williams779c96a2023-05-10 07:50:42 -0500264 if (lanInfoMap.empty())
265 {
266 std::cerr << "can't find matched NIC name. \n";
267 }
Ed Tanous8a17c302021-09-02 15:07:11 -0700268 });
Qiang XU74ddf862019-09-12 17:12:13 +0800269
270 getter->getConfiguration(
271 std::vector<std::string>{nicTypes.begin(), nicTypes.end()});
272}
273
Patrick Williams92f8f512022-07-22 19:26:55 -0500274static void processLanStatusChange(sdbusplus::message_t& message)
Qiang XU88b7f282019-08-14 22:51:43 +0800275{
276 const std::string& pathName = message.get_path();
277 std::string interfaceName;
Zev Weissafd15042022-07-18 12:28:40 -0700278 SensorBaseConfigMap properties;
Qiang XU88b7f282019-08-14 22:51:43 +0800279 message.read(interfaceName, properties);
280
281 auto findStateProperty = properties.find("OperationalState");
282 if (findStateProperty == properties.end())
283 {
284 return;
285 }
Qiang XU74ddf862019-09-12 17:12:13 +0800286 std::string* pState =
287 std::get_if<std::string>(&(findStateProperty->second));
Qiang XU88b7f282019-08-14 22:51:43 +0800288 if (pState == nullptr)
289 {
290 std::cerr << "invalid OperationalState \n";
291 return;
292 }
293
294 bool newLanConnected = (*pState == "routable" || *pState == "carrier" ||
295 *pState == "degraded");
296
297 // get ethNum from path. /org/freedesktop/network1/link/_32 for eth0
Brad Bishopfbb44ad2019-11-08 09:42:37 -0500298 size_t pos = pathName.find("/_");
Qiang XU88b7f282019-08-14 22:51:43 +0800299 if (pos == std::string::npos || pathName.length() <= pos + 2)
300 {
301 std::cerr << "unexpected path name " << pathName << "\n";
302 return;
303 }
304 std::string suffixStr = pathName.substr(pos + 2);
305
306 auto findEthNum = pathSuffixMap.find(suffixStr);
307 if (findEthNum == pathSuffixMap.end())
308 {
309 std::cerr << "unexpected eth for suffixStr " << suffixStr << "\n";
310 return;
311 }
312 int ethNum = findEthNum->second;
Qiang XU74ddf862019-09-12 17:12:13 +0800313
314 // get lan status from map
Qiang XU88b7f282019-08-14 22:51:43 +0800315 auto findLanStatus = lanStatusMap.find(ethNum);
316 if (findLanStatus == lanStatusMap.end())
317 {
318 std::cerr << "unexpected eth " << ethNum << " in lanStatusMap \n";
319 return;
320 }
321 bool oldLanConnected = findLanStatus->second;
322
Qiang XU74ddf862019-09-12 17:12:13 +0800323 // get lan info from map
Ed Tanous2049bd22022-07-09 07:20:26 -0700324 std::string lanInfo;
325 if (!lanInfoMap.empty())
Qiang XU74ddf862019-09-12 17:12:13 +0800326 {
327 auto findLanInfo = lanInfoMap.find(ethNum);
328 if (findLanInfo == lanInfoMap.end())
329 {
330 std::cerr << "unexpected eth " << ethNum << " in lanInfoMap \n";
331 }
332 else
333 {
334 lanInfo = "(" + findLanInfo->second + ")";
335 }
336 }
337
Qiang XU88b7f282019-08-14 22:51:43 +0800338 if (debugLanLeash)
339 {
340 std::cout << "ethNum = " << ethNum << ", state = " << *pState
341 << ", oldLanConnected = "
342 << (oldLanConnected ? "true" : "false")
343 << ", newLanConnected = "
344 << (newLanConnected ? "true" : "false") << "\n";
345 }
346
347 if (oldLanConnected != newLanConnected)
348 {
Qiang XU74ddf862019-09-12 17:12:13 +0800349 std::string strEthNum = "eth" + std::to_string(ethNum) + lanInfo;
Ed Tanous2049bd22022-07-09 07:20:26 -0700350 const auto* strState = newLanConnected ? "connected" : "lost";
Patrick Williams779c96a2023-05-10 07:50:42 -0500351 const auto* strMsgId = newLanConnected ? "OpenBMC.0.1.LanRegained"
352 : "OpenBMC.0.1.LanLost";
Patrick Williams0c42f402021-08-27 16:05:45 -0500353
354 lg2::info("{ETHDEV} LAN leash {STATE}", "ETHDEV", strEthNum, "STATE",
355 strState, "REDFISH_MESSAGE_ID", strMsgId,
356 "REDFISH_MESSAGE_ARGS", strEthNum);
357
Qiang XU88b7f282019-08-14 22:51:43 +0800358 lanStatusMap[ethNum] = newLanConnected;
Qiang XU88b7f282019-08-14 22:51:43 +0800359 }
360}
361
Lei YUdd68d4a2021-03-16 22:17:23 +0800362/** @brief Initialize the lan status.
363 *
364 * @return true on success and false on failure
365 */
Lei YUba637932021-03-17 10:35:00 +0800366static bool initializeLanStatus(
367 const std::shared_ptr<sdbusplus::asio::connection>& conn)
Qiang XU88b7f282019-08-14 22:51:43 +0800368{
Qiang XU74ddf862019-09-12 17:12:13 +0800369 // init lan port name from configuration
370 getNicNameInfo(conn);
371
372 // get eth info from sysfs
Qiang XU88b7f282019-08-14 22:51:43 +0800373 std::vector<fs::path> files;
374 if (!findFiles(fs::path("/sys/class/net/"), R"(eth\d+/ifindex)", files))
375 {
376 std::cerr << "No eth in system\n";
Lei YUdd68d4a2021-03-16 22:17:23 +0800377 return false;
Qiang XU88b7f282019-08-14 22:51:43 +0800378 }
379
380 // iterate through all found eth files, and save ifindex
Ed Tanous8a57ec02020-10-09 12:46:52 -0700381 for (const fs::path& fileName : files)
Qiang XU88b7f282019-08-14 22:51:43 +0800382 {
383 if (debugLanLeash)
384 {
385 std::cout << "Reading " << fileName << "\n";
386 }
387 std::ifstream sysFile(fileName);
388 if (!sysFile.good())
389 {
390 std::cerr << "Failure reading " << fileName << "\n";
391 continue;
392 }
393 std::string line;
394 getline(sysFile, line);
395 const uint8_t ifindex = std::stoi(line);
396 // pathSuffix is ASCII of ifindex
397 const std::string& pathSuffix = std::to_string(ifindex + 30);
398
399 // extract ethNum
400 const std::string& fileStr = fileName.string();
401 const int pos = fileStr.find("eth");
402 const std::string& ethNumStr = fileStr.substr(pos + 3);
403 int ethNum = 0;
Ed Tanous8a57ec02020-10-09 12:46:52 -0700404 std::from_chars_result r = std::from_chars(
405 ethNumStr.data(), ethNumStr.data() + ethNumStr.size(), ethNum);
406 if (r.ec != std::errc())
Qiang XU88b7f282019-08-14 22:51:43 +0800407 {
408 std::cerr << "invalid ethNum string: " << ethNumStr << "\n";
409 continue;
410 }
411
412 // save pathSuffix
413 pathSuffixMap[pathSuffix] = ethNum;
414 if (debugLanLeash)
415 {
416 std::cout << "ethNum = " << std::to_string(ethNum)
417 << ", ifindex = " << line
418 << ", pathSuffix = " << pathSuffix << "\n";
419 }
420
Qiang XU74ddf862019-09-12 17:12:13 +0800421 // init lan connected status from networkd
Qiang XU88b7f282019-08-14 22:51:43 +0800422 conn->async_method_call(
423 [ethNum](boost::system::error_code ec,
424 const std::variant<std::string>& property) {
Ed Tanousbb679322022-05-16 16:10:00 -0700425 lanStatusMap[ethNum] = false;
426 if (ec)
427 {
428 std::cerr << "Error reading init status of eth" << ethNum
429 << "\n";
430 return;
431 }
432 const std::string* pState = std::get_if<std::string>(&property);
433 if (pState == nullptr)
434 {
435 std::cerr << "Unable to read lan status value\n";
436 return;
437 }
Patrick Williams779c96a2023-05-10 07:50:42 -0500438 bool isLanConnected = (*pState == "routable" ||
439 *pState == "carrier" ||
440 *pState == "degraded");
Ed Tanousbb679322022-05-16 16:10:00 -0700441 if (debugLanLeash)
442 {
443 std::cout << "ethNum = " << std::to_string(ethNum)
444 << ", init LAN status = "
445 << (isLanConnected ? "true" : "false") << "\n";
446 }
447 lanStatusMap[ethNum] = isLanConnected;
Qiang XU88b7f282019-08-14 22:51:43 +0800448 },
449 "org.freedesktop.network1",
450 "/org/freedesktop/network1/link/_" + pathSuffix,
451 "org.freedesktop.DBus.Properties", "Get",
452 "org.freedesktop.network1.Link", "OperationalState");
453 }
Lei YUdd68d4a2021-03-16 22:17:23 +0800454 return true;
Qiang XU88b7f282019-08-14 22:51:43 +0800455}
456
Qiang XUe28d1fa2019-02-27 13:50:56 +0800457int main()
458{
Chau Lycebb28c2022-10-21 10:01:52 +0000459 std::shared_ptr<ChassisIntrusionSensor> intrusionSensor;
Qiang XUe28d1fa2019-02-27 13:50:56 +0800460
461 // setup connection to dbus
Ed Tanous1f978632023-02-28 18:16:39 -0800462 boost::asio::io_context io;
Qiang XUe28d1fa2019-02-27 13:50:56 +0800463 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
Qiang XUe28d1fa2019-02-27 13:50:56 +0800464
465 // setup object server, define interface
466 systemBus->request_name("xyz.openbmc_project.IntrusionSensor");
467
Ed Tanous14ed5e92022-07-12 15:50:23 -0700468 sdbusplus::asio::object_server objServer(systemBus, true);
469
Chau Ly889af822023-02-20 07:13:52 +0000470 objServer.add_manager("/xyz/openbmc_project/Chassis");
Ed Tanous14ed5e92022-07-12 15:50:23 -0700471
Chau Lycebb28c2022-10-21 10:01:52 +0000472 createSensorsFromConfig(io, objServer, systemBus, intrusionSensor);
Qiang XUe28d1fa2019-02-27 13:50:56 +0800473
474 // callback to handle configuration change
Patrick Williams92f8f512022-07-22 19:26:55 -0500475 std::function<void(sdbusplus::message_t&)> eventHandler =
476 [&](sdbusplus::message_t& message) {
Ed Tanousbb679322022-05-16 16:10:00 -0700477 if (message.is_method_error())
478 {
479 std::cerr << "callback method error\n";
480 return;
481 }
Qiang XUe28d1fa2019-02-27 13:50:56 +0800482
Ed Tanousbb679322022-05-16 16:10:00 -0700483 std::cout << "rescan due to configuration change \n";
Chau Lycebb28c2022-10-21 10:01:52 +0000484 createSensorsFromConfig(io, objServer, systemBus, intrusionSensor);
Ed Tanousbb679322022-05-16 16:10:00 -0700485 };
Qiang XUe28d1fa2019-02-27 13:50:56 +0800486
Zev Weiss214d9712022-08-12 12:54:31 -0700487 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
488 setupPropertiesChangedMatches(
489 *systemBus, std::to_array<const char*>({sensorType}), eventHandler);
Qiang XUe28d1fa2019-02-27 13:50:56 +0800490
Lei YUdd68d4a2021-03-16 22:17:23 +0800491 if (initializeLanStatus(systemBus))
492 {
493 // add match to monitor lan status change
Patrick Williams92f8f512022-07-22 19:26:55 -0500494 sdbusplus::bus::match_t lanStatusMatch(
495 static_cast<sdbusplus::bus_t&>(*systemBus),
Lei YUdd68d4a2021-03-16 22:17:23 +0800496 "type='signal', member='PropertiesChanged',"
497 "arg0namespace='org.freedesktop.network1.Link'",
Patrick Williams92f8f512022-07-22 19:26:55 -0500498 [](sdbusplus::message_t& msg) { processLanStatusChange(msg); });
Lei YUdd68d4a2021-03-16 22:17:23 +0800499
500 // add match to monitor entity manager signal about nic name config
501 // change
Patrick Williams92f8f512022-07-22 19:26:55 -0500502 sdbusplus::bus::match_t lanConfigMatch(
503 static_cast<sdbusplus::bus_t&>(*systemBus),
Lei YUdd68d4a2021-03-16 22:17:23 +0800504 "type='signal', member='PropertiesChanged',path_namespace='" +
Zev Weiss054aad82022-08-18 01:37:34 -0700505 std::string(inventoryPath) + "',arg0namespace='" +
506 configInterfaceName(nicType) + "'",
Patrick Williams92f8f512022-07-22 19:26:55 -0500507 [&systemBus](sdbusplus::message_t& msg) {
Ed Tanousbb679322022-05-16 16:10:00 -0700508 if (msg.is_method_error())
509 {
510 std::cerr << "callback method error\n";
511 return;
512 }
513 getNicNameInfo(systemBus);
Lei YUdd68d4a2021-03-16 22:17:23 +0800514 });
515 }
Qiang XU88b7f282019-08-14 22:51:43 +0800516
Qiang XUe28d1fa2019-02-27 13:50:56 +0800517 io.run();
518
519 return 0;
520}