James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2017 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 | |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 17 | #include "dbus-sensor_config.h" |
| 18 | |
Zev Weiss | dabd48d | 2022-08-03 15:43:17 -0700 | [diff] [blame^] | 19 | #include <DeviceMgmt.hpp> |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 20 | #include <Utils.hpp> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 21 | #include <boost/container/flat_map.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 22 | #include <sdbusplus/asio/connection.hpp> |
| 23 | #include <sdbusplus/asio/object_server.hpp> |
| 24 | #include <sdbusplus/bus/match.hpp> |
| 25 | |
James Feist | 24f02f2 | 2019-04-15 11:05:39 -0700 | [diff] [blame] | 26 | #include <filesystem> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 27 | #include <fstream> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 28 | #include <memory> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 29 | #include <regex> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 30 | #include <stdexcept> |
| 31 | #include <string> |
| 32 | #include <utility> |
| 33 | #include <variant> |
| 34 | #include <vector> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 35 | |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 36 | namespace fs = std::filesystem; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 37 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 38 | static bool powerStatusOn = false; |
James Feist | fc94b21 | 2019-02-06 16:14:51 -0800 | [diff] [blame] | 39 | static bool biosHasPost = false; |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 40 | static bool manufacturingMode = false; |
James Feist | 58295ad | 2019-05-30 15:01:41 -0700 | [diff] [blame] | 41 | |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 42 | static std::unique_ptr<sdbusplus::bus::match_t> powerMatch = nullptr; |
| 43 | static std::unique_ptr<sdbusplus::bus::match_t> postMatch = nullptr; |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 44 | |
Jason Ling | 100c20b | 2020-08-11 14:50:33 -0700 | [diff] [blame] | 45 | /** |
| 46 | * return the contents of a file |
| 47 | * @param[in] hwmonFile - the path to the file to read |
| 48 | * @return the contents of the file as a string or nullopt if the file could not |
| 49 | * be opened. |
| 50 | */ |
| 51 | |
| 52 | std::optional<std::string> openAndRead(const std::string& hwmonFile) |
| 53 | { |
| 54 | std::string fileVal; |
| 55 | std::ifstream fileStream(hwmonFile); |
| 56 | if (!fileStream.is_open()) |
| 57 | { |
| 58 | return std::nullopt; |
| 59 | } |
| 60 | std::getline(fileStream, fileVal); |
| 61 | return fileVal; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * given a hwmon temperature base name if valid return the full path else |
| 66 | * nullopt |
| 67 | * @param[in] directory - the hwmon sysfs directory |
| 68 | * @param[in] permitSet - a set of labels or hwmon basenames to permit. If this |
| 69 | * is empty then *everything* is permitted. |
| 70 | * @return a string to the full path of the file to create a temp sensor with or |
| 71 | * nullopt to indicate that no sensor should be created for this basename. |
| 72 | */ |
| 73 | std::optional<std::string> |
| 74 | getFullHwmonFilePath(const std::string& directory, |
| 75 | const std::string& hwmonBaseName, |
| 76 | const std::set<std::string>& permitSet) |
| 77 | { |
| 78 | std::optional<std::string> result; |
| 79 | std::string filename; |
| 80 | if (permitSet.empty()) |
| 81 | { |
| 82 | result = directory + "/" + hwmonBaseName + "_input"; |
| 83 | return result; |
| 84 | } |
| 85 | filename = directory + "/" + hwmonBaseName + "_label"; |
| 86 | auto searchVal = openAndRead(filename); |
| 87 | if (!searchVal) |
| 88 | { |
| 89 | /* if the hwmon temp doesn't have a corresponding label file |
| 90 | * then use the hwmon temperature base name |
| 91 | */ |
| 92 | searchVal = hwmonBaseName; |
| 93 | } |
| 94 | if (permitSet.find(*searchVal) != permitSet.end()) |
| 95 | { |
| 96 | result = directory + "/" + hwmonBaseName + "_input"; |
| 97 | } |
| 98 | return result; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * retrieve a set of basenames and labels to allow sensor creation for. |
| 103 | * @param[in] config - a map representing the configuration for a specific |
| 104 | * device |
| 105 | * @return a set of basenames and labels to allow sensor creation for. An empty |
| 106 | * set indicates that everything is permitted. |
| 107 | */ |
| 108 | std::set<std::string> getPermitSet(const SensorBaseConfigMap& config) |
| 109 | { |
| 110 | auto permitAttribute = config.find("Labels"); |
| 111 | std::set<std::string> permitSet; |
| 112 | if (permitAttribute != config.end()) |
| 113 | { |
| 114 | try |
| 115 | { |
| 116 | auto val = |
| 117 | std::get<std::vector<std::string>>(permitAttribute->second); |
| 118 | |
| 119 | permitSet.insert(std::make_move_iterator(val.begin()), |
| 120 | std::make_move_iterator(val.end())); |
| 121 | } |
| 122 | catch (const std::bad_variant_access& err) |
| 123 | { |
| 124 | std::cerr << err.what() |
| 125 | << ":PermitList does not contain a list, wrong " |
| 126 | "variant type.\n"; |
| 127 | } |
| 128 | } |
| 129 | return permitSet; |
| 130 | } |
| 131 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 132 | bool getSensorConfiguration( |
| 133 | const std::string& type, |
| 134 | const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 135 | ManagedObjectType& resp) |
| 136 | { |
| 137 | return getSensorConfiguration(type, dbusConnection, resp, false); |
| 138 | } |
| 139 | |
| 140 | bool getSensorConfiguration( |
| 141 | const std::string& type, |
| 142 | const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 143 | ManagedObjectType& resp, bool useCache) |
| 144 | { |
| 145 | static ManagedObjectType managedObj; |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 146 | std::string typeIntf = configInterfaceName(type); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 147 | |
| 148 | if (!useCache) |
| 149 | { |
| 150 | managedObj.clear(); |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 151 | sdbusplus::message_t getManagedObjects = |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 152 | dbusConnection->new_method_call( |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 153 | entityManagerName, "/", "org.freedesktop.DBus.ObjectManager", |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 154 | "GetManagedObjects"); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 155 | try |
| 156 | { |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 157 | sdbusplus::message_t reply = |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 158 | dbusConnection->call(getManagedObjects); |
Yoo, Jae Hyun | 0e02205 | 2018-10-15 14:05:37 -0700 | [diff] [blame] | 159 | reply.read(managedObj); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 160 | } |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 161 | catch (const sdbusplus::exception_t& e) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 162 | { |
Jason Ling | 5747fab | 2019-10-02 16:46:23 -0700 | [diff] [blame] | 163 | std::cerr << "While calling GetManagedObjects on service:" |
| 164 | << entityManagerName << " exception name:" << e.name() |
| 165 | << "and description:" << e.description() |
| 166 | << " was thrown\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 167 | return false; |
| 168 | } |
| 169 | } |
| 170 | for (const auto& pathPair : managedObj) |
| 171 | { |
Zev Weiss | fd3d5f7 | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 172 | for (const auto& [intf, cfg] : pathPair.second) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 173 | { |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 174 | if (intf.starts_with(typeIntf)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 175 | { |
Zev Weiss | 79d8aef | 2022-08-17 21:45:44 -0700 | [diff] [blame] | 176 | resp.emplace(pathPair); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 177 | break; |
| 178 | } |
| 179 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 180 | } |
| 181 | return true; |
| 182 | } |
| 183 | |
Lei YU | 6a4e973 | 2021-10-20 13:27:34 +0800 | [diff] [blame] | 184 | bool findFiles(const fs::path& dirPath, std::string_view matchString, |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 185 | std::vector<fs::path>& foundPaths, int symlinkDepth) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 186 | { |
Lei YU | 6a4e973 | 2021-10-20 13:27:34 +0800 | [diff] [blame] | 187 | std::error_code ec; |
| 188 | if (!fs::exists(dirPath, ec)) |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 189 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 190 | return false; |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 191 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 192 | |
Lei YU | 6a4e973 | 2021-10-20 13:27:34 +0800 | [diff] [blame] | 193 | std::vector<std::regex> matchPieces; |
| 194 | |
| 195 | size_t pos = 0; |
| 196 | std::string token; |
| 197 | // Generate the regex expressions list from the match we were given |
| 198 | while ((pos = matchString.find('/')) != std::string::npos) |
| 199 | { |
| 200 | token = matchString.substr(0, pos); |
| 201 | matchPieces.emplace_back(token); |
| 202 | matchString.remove_prefix(pos + 1); |
| 203 | } |
| 204 | matchPieces.emplace_back(std::string{matchString}); |
| 205 | |
| 206 | // Check if the match string contains directories, and skip the match of |
| 207 | // subdirectory if not |
| 208 | if (matchPieces.size() <= 1) |
| 209 | { |
| 210 | std::regex search(std::string{matchString}); |
| 211 | std::smatch match; |
| 212 | for (auto p = fs::recursive_directory_iterator( |
| 213 | dirPath, fs::directory_options::follow_directory_symlink); |
| 214 | p != fs::recursive_directory_iterator(); ++p) |
| 215 | { |
| 216 | std::string path = p->path().string(); |
| 217 | if (!is_directory(*p)) |
| 218 | { |
| 219 | if (std::regex_search(path, match, search)) |
| 220 | { |
| 221 | foundPaths.emplace_back(p->path()); |
| 222 | } |
| 223 | } |
| 224 | if (p.depth() >= symlinkDepth) |
| 225 | { |
| 226 | p.disable_recursion_pending(); |
| 227 | } |
| 228 | } |
| 229 | return true; |
| 230 | } |
| 231 | |
| 232 | // The match string contains directories, verify each level of sub |
| 233 | // directories |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 234 | for (auto p = fs::recursive_directory_iterator( |
| 235 | dirPath, fs::directory_options::follow_directory_symlink); |
| 236 | p != fs::recursive_directory_iterator(); ++p) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 237 | { |
Lei YU | 6a4e973 | 2021-10-20 13:27:34 +0800 | [diff] [blame] | 238 | std::vector<std::regex>::iterator matchPiece = matchPieces.begin(); |
| 239 | fs::path::iterator pathIt = p->path().begin(); |
| 240 | for (const fs::path& dir : dirPath) |
| 241 | { |
| 242 | if (dir.empty()) |
| 243 | { |
| 244 | // When the path ends with '/', it gets am empty path |
| 245 | // skip such case. |
| 246 | break; |
| 247 | } |
| 248 | pathIt++; |
| 249 | } |
| 250 | |
| 251 | while (pathIt != p->path().end()) |
| 252 | { |
| 253 | // Found a path deeper than match. |
| 254 | if (matchPiece == matchPieces.end()) |
| 255 | { |
| 256 | p.disable_recursion_pending(); |
| 257 | break; |
| 258 | } |
| 259 | std::smatch match; |
| 260 | std::string component = pathIt->string(); |
| 261 | std::regex regexPiece(*matchPiece); |
| 262 | if (!std::regex_match(component, match, regexPiece)) |
| 263 | { |
| 264 | // path prefix doesn't match, no need to iterate further |
| 265 | p.disable_recursion_pending(); |
| 266 | break; |
| 267 | } |
| 268 | matchPiece++; |
| 269 | pathIt++; |
| 270 | } |
| 271 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 272 | if (!is_directory(*p)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 273 | { |
Lei YU | 6a4e973 | 2021-10-20 13:27:34 +0800 | [diff] [blame] | 274 | if (matchPiece == matchPieces.end()) |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 275 | { |
| 276 | foundPaths.emplace_back(p->path()); |
| 277 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 278 | } |
Lei YU | 6a4e973 | 2021-10-20 13:27:34 +0800 | [diff] [blame] | 279 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 280 | if (p.depth() >= symlinkDepth) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 281 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 282 | p.disable_recursion_pending(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 287 | |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 288 | bool isPowerOn(void) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 289 | { |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 290 | if (!powerMatch) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 291 | { |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 292 | throw std::runtime_error("Power Match Not Created"); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 293 | } |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 294 | return powerStatusOn; |
| 295 | } |
| 296 | |
James Feist | fc94b21 | 2019-02-06 16:14:51 -0800 | [diff] [blame] | 297 | bool hasBiosPost(void) |
| 298 | { |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 299 | if (!postMatch) |
James Feist | fc94b21 | 2019-02-06 16:14:51 -0800 | [diff] [blame] | 300 | { |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 301 | throw std::runtime_error("Post Match Not Created"); |
James Feist | fc94b21 | 2019-02-06 16:14:51 -0800 | [diff] [blame] | 302 | } |
| 303 | return biosHasPost; |
| 304 | } |
| 305 | |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 306 | bool readingStateGood(const PowerState& powerState) |
| 307 | { |
| 308 | if (powerState == PowerState::on && !isPowerOn()) |
| 309 | { |
| 310 | return false; |
| 311 | } |
| 312 | if (powerState == PowerState::biosPost && (!hasBiosPost() || !isPowerOn())) |
| 313 | { |
| 314 | return false; |
| 315 | } |
| 316 | |
| 317 | return true; |
| 318 | } |
| 319 | |
James Feist | 8aeffd9 | 2020-09-14 12:08:28 -0700 | [diff] [blame] | 320 | static void |
| 321 | getPowerStatus(const std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 322 | size_t retries = 2) |
| 323 | { |
| 324 | conn->async_method_call( |
| 325 | [conn, retries](boost::system::error_code ec, |
| 326 | const std::variant<std::string>& state) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 327 | if (ec) |
| 328 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 329 | if (retries != 0U) |
James Feist | 8aeffd9 | 2020-09-14 12:08:28 -0700 | [diff] [blame] | 330 | { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 331 | auto timer = std::make_shared<boost::asio::steady_timer>( |
| 332 | conn->get_io_context()); |
| 333 | timer->expires_after(std::chrono::seconds(15)); |
| 334 | timer->async_wait( |
| 335 | [timer, conn, retries](boost::system::error_code) { |
| 336 | getPowerStatus(conn, retries - 1); |
| 337 | }); |
James Feist | 8aeffd9 | 2020-09-14 12:08:28 -0700 | [diff] [blame] | 338 | return; |
| 339 | } |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 340 | |
| 341 | // we commonly come up before power control, we'll capture the |
| 342 | // property change later |
| 343 | std::cerr << "error getting power status " << ec.message() << "\n"; |
| 344 | return; |
| 345 | } |
Zev Weiss | 6c106d6 | 2022-08-17 20:50:00 -0700 | [diff] [blame] | 346 | powerStatusOn = std::get<std::string>(state).ends_with(".Running"); |
James Feist | 8aeffd9 | 2020-09-14 12:08:28 -0700 | [diff] [blame] | 347 | }, |
| 348 | power::busname, power::path, properties::interface, properties::get, |
| 349 | power::interface, power::property); |
| 350 | } |
| 351 | |
| 352 | static void |
| 353 | getPostStatus(const std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 354 | size_t retries = 2) |
| 355 | { |
| 356 | conn->async_method_call( |
| 357 | [conn, retries](boost::system::error_code ec, |
| 358 | const std::variant<std::string>& state) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 359 | if (ec) |
| 360 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 361 | if (retries != 0U) |
James Feist | 8aeffd9 | 2020-09-14 12:08:28 -0700 | [diff] [blame] | 362 | { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 363 | auto timer = std::make_shared<boost::asio::steady_timer>( |
| 364 | conn->get_io_context()); |
| 365 | timer->expires_after(std::chrono::seconds(15)); |
| 366 | timer->async_wait( |
| 367 | [timer, conn, retries](boost::system::error_code) { |
| 368 | getPostStatus(conn, retries - 1); |
| 369 | }); |
James Feist | 8aeffd9 | 2020-09-14 12:08:28 -0700 | [diff] [blame] | 370 | return; |
| 371 | } |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 372 | // we commonly come up before power control, we'll capture the |
| 373 | // property change later |
| 374 | std::cerr << "error getting post status " << ec.message() << "\n"; |
| 375 | return; |
| 376 | } |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 377 | const auto& value = std::get<std::string>(state); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 378 | biosHasPost = (value != "Inactive") && |
| 379 | (value != "xyz.openbmc_project.State.OperatingSystem." |
| 380 | "Status.OSStatus.Inactive"); |
James Feist | 8aeffd9 | 2020-09-14 12:08:28 -0700 | [diff] [blame] | 381 | }, |
| 382 | post::busname, post::path, properties::interface, properties::get, |
| 383 | post::interface, post::property); |
| 384 | } |
| 385 | |
Zev Weiss | 88cb29d | 2022-05-09 03:46:15 +0000 | [diff] [blame] | 386 | void setupPowerMatchCallback( |
| 387 | const std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 388 | std::function<void(PowerState type, bool state)>&& hostStatusCallback) |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 389 | { |
James Feist | 43d32fe | 2019-09-04 10:35:20 -0700 | [diff] [blame] | 390 | static boost::asio::steady_timer timer(conn->get_io_context()); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 391 | // create a match for powergood changes, first time do a method call to |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 392 | // cache the correct value |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 393 | if (powerMatch) |
| 394 | { |
| 395 | return; |
| 396 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 397 | |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 398 | powerMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 399 | static_cast<sdbusplus::bus_t&>(*conn), |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 400 | "type='signal',interface='" + std::string(properties::interface) + |
| 401 | "',path='" + std::string(power::path) + "',arg0='" + |
| 402 | std::string(power::interface) + "'", |
Zev Weiss | 88cb29d | 2022-05-09 03:46:15 +0000 | [diff] [blame] | 403 | [hostStatusCallback](sdbusplus::message_t& message) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 404 | std::string objectName; |
| 405 | boost::container::flat_map<std::string, std::variant<std::string>> |
| 406 | values; |
| 407 | message.read(objectName, values); |
| 408 | auto findState = values.find(power::property); |
| 409 | if (findState != values.end()) |
| 410 | { |
Zev Weiss | 6c106d6 | 2022-08-17 20:50:00 -0700 | [diff] [blame] | 411 | bool on = |
| 412 | std::get<std::string>(findState->second).ends_with(".Running"); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 413 | if (!on) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 414 | { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 415 | timer.cancel(); |
| 416 | powerStatusOn = false; |
Zev Weiss | 88cb29d | 2022-05-09 03:46:15 +0000 | [diff] [blame] | 417 | hostStatusCallback(PowerState::on, powerStatusOn); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 418 | return; |
| 419 | } |
| 420 | // on comes too quickly |
| 421 | timer.expires_after(std::chrono::seconds(10)); |
Zev Weiss | 88cb29d | 2022-05-09 03:46:15 +0000 | [diff] [blame] | 422 | timer.async_wait( |
| 423 | [hostStatusCallback](boost::system::error_code ec) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 424 | if (ec == boost::asio::error::operation_aborted) |
James Feist | 43d32fe | 2019-09-04 10:35:20 -0700 | [diff] [blame] | 425 | { |
James Feist | 43d32fe | 2019-09-04 10:35:20 -0700 | [diff] [blame] | 426 | return; |
| 427 | } |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 428 | if (ec) |
| 429 | { |
| 430 | std::cerr << "Timer error " << ec.message() << "\n"; |
| 431 | return; |
| 432 | } |
| 433 | powerStatusOn = true; |
Zev Weiss | 88cb29d | 2022-05-09 03:46:15 +0000 | [diff] [blame] | 434 | hostStatusCallback(PowerState::on, powerStatusOn); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 435 | }); |
| 436 | } |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 437 | }); |
| 438 | |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 439 | postMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 440 | static_cast<sdbusplus::bus_t&>(*conn), |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 441 | "type='signal',interface='" + std::string(properties::interface) + |
| 442 | "',path='" + std::string(post::path) + "',arg0='" + |
| 443 | std::string(post::interface) + "'", |
Zev Weiss | 88cb29d | 2022-05-09 03:46:15 +0000 | [diff] [blame] | 444 | [hostStatusCallback](sdbusplus::message_t& message) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 445 | std::string objectName; |
| 446 | boost::container::flat_map<std::string, std::variant<std::string>> |
| 447 | values; |
| 448 | message.read(objectName, values); |
| 449 | auto findState = values.find(post::property); |
| 450 | if (findState != values.end()) |
| 451 | { |
| 452 | auto& value = std::get<std::string>(findState->second); |
| 453 | biosHasPost = (value != "Inactive") && |
| 454 | (value != "xyz.openbmc_project.State.OperatingSystem." |
| 455 | "Status.OSStatus.Inactive"); |
Zev Weiss | 88cb29d | 2022-05-09 03:46:15 +0000 | [diff] [blame] | 456 | hostStatusCallback(PowerState::biosPost, biosHasPost); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 457 | } |
James Feist | 52497fd | 2019-06-07 13:01:33 -0700 | [diff] [blame] | 458 | }); |
James Feist | fc94b21 | 2019-02-06 16:14:51 -0800 | [diff] [blame] | 459 | |
James Feist | 8aeffd9 | 2020-09-14 12:08:28 -0700 | [diff] [blame] | 460 | getPowerStatus(conn); |
| 461 | getPostStatus(conn); |
James Feist | 3f0e876 | 2018-11-27 11:30:42 -0800 | [diff] [blame] | 462 | } |
James Feist | 87d713a | 2018-12-06 16:06:24 -0800 | [diff] [blame] | 463 | |
Zev Weiss | 88cb29d | 2022-05-09 03:46:15 +0000 | [diff] [blame] | 464 | void setupPowerMatch(const std::shared_ptr<sdbusplus::asio::connection>& conn) |
| 465 | { |
| 466 | setupPowerMatchCallback(conn, [](PowerState, bool) {}); |
| 467 | } |
| 468 | |
James Feist | 87d713a | 2018-12-06 16:06:24 -0800 | [diff] [blame] | 469 | // replaces limits if MinReading and MaxReading are found. |
| 470 | void findLimits(std::pair<double, double>& limits, |
| 471 | const SensorBaseConfiguration* data) |
| 472 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 473 | if (data == nullptr) |
James Feist | 87d713a | 2018-12-06 16:06:24 -0800 | [diff] [blame] | 474 | { |
| 475 | return; |
| 476 | } |
| 477 | auto maxFind = data->second.find("MaxReading"); |
| 478 | auto minFind = data->second.find("MinReading"); |
| 479 | |
| 480 | if (minFind != data->second.end()) |
| 481 | { |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 482 | limits.first = std::visit(VariantToDoubleVisitor(), minFind->second); |
James Feist | 87d713a | 2018-12-06 16:06:24 -0800 | [diff] [blame] | 483 | } |
| 484 | if (maxFind != data->second.end()) |
| 485 | { |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 486 | limits.second = std::visit(VariantToDoubleVisitor(), maxFind->second); |
James Feist | 87d713a | 2018-12-06 16:06:24 -0800 | [diff] [blame] | 487 | } |
James Feist | fc94b21 | 2019-02-06 16:14:51 -0800 | [diff] [blame] | 488 | } |
James Feist | 82bac4c | 2019-03-11 11:16:53 -0700 | [diff] [blame] | 489 | |
| 490 | void createAssociation( |
| 491 | std::shared_ptr<sdbusplus::asio::dbus_interface>& association, |
| 492 | const std::string& path) |
| 493 | { |
| 494 | if (association) |
| 495 | { |
Lei YU | 6a4e973 | 2021-10-20 13:27:34 +0800 | [diff] [blame] | 496 | fs::path p(path); |
James Feist | d2543f8 | 2019-04-09 11:10:06 -0700 | [diff] [blame] | 497 | |
James Feist | 82bac4c | 2019-03-11 11:16:53 -0700 | [diff] [blame] | 498 | std::vector<Association> associations; |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 499 | associations.emplace_back("chassis", "all_sensors", |
| 500 | p.parent_path().string()); |
James Feist | 2adc95c | 2019-09-30 14:55:28 -0700 | [diff] [blame] | 501 | association->register_property("Associations", associations); |
James Feist | 82bac4c | 2019-03-11 11:16:53 -0700 | [diff] [blame] | 502 | association->initialize(); |
| 503 | } |
James Feist | 43d32fe | 2019-09-04 10:35:20 -0700 | [diff] [blame] | 504 | } |
Cheng C Yang | 5580f2f | 2019-09-19 09:01:47 +0800 | [diff] [blame] | 505 | |
| 506 | void setInventoryAssociation( |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 507 | const std::shared_ptr<sdbusplus::asio::dbus_interface>& association, |
AppaRao Puli | c82213c | 2020-02-27 01:24:58 +0530 | [diff] [blame] | 508 | const std::string& path, |
| 509 | const std::vector<std::string>& chassisPaths = std::vector<std::string>()) |
Cheng C Yang | 5580f2f | 2019-09-19 09:01:47 +0800 | [diff] [blame] | 510 | { |
| 511 | if (association) |
| 512 | { |
Lei YU | 6a4e973 | 2021-10-20 13:27:34 +0800 | [diff] [blame] | 513 | fs::path p(path); |
Cheng C Yang | 5580f2f | 2019-09-19 09:01:47 +0800 | [diff] [blame] | 514 | std::vector<Association> associations; |
AppaRao Puli | c82213c | 2020-02-27 01:24:58 +0530 | [diff] [blame] | 515 | std::string objPath(p.parent_path().string()); |
| 516 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 517 | associations.emplace_back("inventory", "sensors", objPath); |
| 518 | associations.emplace_back("chassis", "all_sensors", objPath); |
AppaRao Puli | c82213c | 2020-02-27 01:24:58 +0530 | [diff] [blame] | 519 | |
| 520 | for (const std::string& chassisPath : chassisPaths) |
| 521 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 522 | associations.emplace_back("chassis", "all_sensors", chassisPath); |
AppaRao Puli | c82213c | 2020-02-27 01:24:58 +0530 | [diff] [blame] | 523 | } |
| 524 | |
James Feist | 2adc95c | 2019-09-30 14:55:28 -0700 | [diff] [blame] | 525 | association->register_property("Associations", associations); |
Cheng C Yang | 5580f2f | 2019-09-19 09:01:47 +0800 | [diff] [blame] | 526 | association->initialize(); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | void createInventoryAssoc( |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 531 | const std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 532 | const std::shared_ptr<sdbusplus::asio::dbus_interface>& association, |
Cheng C Yang | 5580f2f | 2019-09-19 09:01:47 +0800 | [diff] [blame] | 533 | const std::string& path) |
| 534 | { |
| 535 | if (!association) |
| 536 | { |
| 537 | return; |
| 538 | } |
AppaRao Puli | c82213c | 2020-02-27 01:24:58 +0530 | [diff] [blame] | 539 | |
Cheng C Yang | 5580f2f | 2019-09-19 09:01:47 +0800 | [diff] [blame] | 540 | conn->async_method_call( |
| 541 | [association, path](const boost::system::error_code ec, |
AppaRao Puli | c82213c | 2020-02-27 01:24:58 +0530 | [diff] [blame] | 542 | const std::vector<std::string>& invSysObjPaths) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 543 | if (ec) |
| 544 | { |
| 545 | // In case of error, set the default associations and |
| 546 | // initialize the association Interface. |
| 547 | setInventoryAssociation(association, path); |
| 548 | return; |
| 549 | } |
| 550 | setInventoryAssociation(association, path, invSysObjPaths); |
Cheng C Yang | 5580f2f | 2019-09-19 09:01:47 +0800 | [diff] [blame] | 551 | }, |
| 552 | mapper::busName, mapper::path, mapper::interface, "GetSubTreePaths", |
| 553 | "/xyz/openbmc_project/inventory/system", 2, |
| 554 | std::array<std::string, 1>{ |
| 555 | "xyz.openbmc_project.Inventory.Item.System"}); |
| 556 | } |
Zbigniew Kurzynski | 63f3866 | 2020-06-09 13:02:11 +0200 | [diff] [blame] | 557 | |
| 558 | std::optional<double> readFile(const std::string& thresholdFile, |
| 559 | const double& scaleFactor) |
| 560 | { |
| 561 | std::string line; |
| 562 | std::ifstream labelFile(thresholdFile); |
| 563 | if (labelFile.good()) |
| 564 | { |
| 565 | std::getline(labelFile, line); |
| 566 | labelFile.close(); |
| 567 | |
| 568 | try |
| 569 | { |
| 570 | return std::stod(line) / scaleFactor; |
| 571 | } |
| 572 | catch (const std::invalid_argument&) |
| 573 | { |
| 574 | return std::nullopt; |
| 575 | } |
| 576 | } |
| 577 | return std::nullopt; |
| 578 | } |
| 579 | |
| 580 | std::optional<std::tuple<std::string, std::string, std::string>> |
Lei YU | 6a4e973 | 2021-10-20 13:27:34 +0800 | [diff] [blame] | 581 | splitFileName(const fs::path& filePath) |
Zbigniew Kurzynski | 63f3866 | 2020-06-09 13:02:11 +0200 | [diff] [blame] | 582 | { |
| 583 | if (filePath.has_filename()) |
| 584 | { |
| 585 | const auto fileName = filePath.filename().string(); |
Zbigniew Kurzynski | 63f3866 | 2020-06-09 13:02:11 +0200 | [diff] [blame] | 586 | |
Zbigniew Kurzynski | dd64800 | 2020-07-10 16:44:16 +0200 | [diff] [blame] | 587 | size_t numberPos = std::strcspn(fileName.c_str(), "1234567890"); |
| 588 | size_t itemPos = std::strcspn(fileName.c_str(), "_"); |
| 589 | |
| 590 | if (numberPos > 0 && itemPos > numberPos && fileName.size() > itemPos) |
Zbigniew Kurzynski | 63f3866 | 2020-06-09 13:02:11 +0200 | [diff] [blame] | 591 | { |
Zbigniew Kurzynski | dd64800 | 2020-07-10 16:44:16 +0200 | [diff] [blame] | 592 | return std::make_optional( |
| 593 | std::make_tuple(fileName.substr(0, numberPos), |
| 594 | fileName.substr(numberPos, itemPos - numberPos), |
| 595 | fileName.substr(itemPos + 1, fileName.size()))); |
Zbigniew Kurzynski | 63f3866 | 2020-06-09 13:02:11 +0200 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | return std::nullopt; |
Zbigniew Kurzynski | dd64800 | 2020-07-10 16:44:16 +0200 | [diff] [blame] | 599 | } |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 600 | |
Arun P. Mohanan | 45f844a | 2021-11-03 22:18:09 +0530 | [diff] [blame] | 601 | static void handleSpecialModeChange(const std::string& manufacturingModeStatus) |
| 602 | { |
| 603 | manufacturingMode = false; |
| 604 | if (manufacturingModeStatus == "xyz.openbmc_project.Control.Security." |
| 605 | "SpecialMode.Modes.Manufacturing") |
| 606 | { |
| 607 | manufacturingMode = true; |
| 608 | } |
Ed Tanous | 74cffa8 | 2022-01-25 13:00:28 -0800 | [diff] [blame] | 609 | if (validateUnsecureFeature == 1) |
Arun P. Mohanan | 45f844a | 2021-11-03 22:18:09 +0530 | [diff] [blame] | 610 | { |
| 611 | if (manufacturingModeStatus == "xyz.openbmc_project.Control.Security." |
| 612 | "SpecialMode.Modes.ValidationUnsecure") |
| 613 | { |
| 614 | manufacturingMode = true; |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 619 | void setupManufacturingModeMatch(sdbusplus::asio::connection& conn) |
| 620 | { |
Arun P. Mohanan | 45f844a | 2021-11-03 22:18:09 +0530 | [diff] [blame] | 621 | namespace rules = sdbusplus::bus::match::rules; |
| 622 | static constexpr const char* specialModeInterface = |
| 623 | "xyz.openbmc_project.Security.SpecialMode"; |
| 624 | |
| 625 | const std::string filterSpecialModeIntfAdd = |
| 626 | rules::interfacesAdded() + |
| 627 | rules::argNpath(0, "/xyz/openbmc_project/security/special_mode"); |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 628 | static std::unique_ptr<sdbusplus::bus::match_t> specialModeIntfMatch = |
| 629 | std::make_unique<sdbusplus::bus::match_t>(conn, |
| 630 | filterSpecialModeIntfAdd, |
| 631 | [](sdbusplus::message_t& m) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 632 | sdbusplus::message::object_path path; |
| 633 | using PropertyMap = |
| 634 | boost::container::flat_map<std::string, std::variant<std::string>>; |
| 635 | boost::container::flat_map<std::string, PropertyMap> interfaceAdded; |
| 636 | m.read(path, interfaceAdded); |
| 637 | auto intfItr = interfaceAdded.find(specialModeInterface); |
| 638 | if (intfItr == interfaceAdded.end()) |
| 639 | { |
| 640 | return; |
| 641 | } |
| 642 | PropertyMap& propertyList = intfItr->second; |
| 643 | auto itr = propertyList.find("SpecialMode"); |
| 644 | if (itr == propertyList.end()) |
| 645 | { |
| 646 | std::cerr << "error getting SpecialMode property " |
| 647 | << "\n"; |
| 648 | return; |
| 649 | } |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 650 | auto* manufacturingModeStatus = std::get_if<std::string>(&itr->second); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 651 | handleSpecialModeChange(*manufacturingModeStatus); |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 652 | }); |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 653 | |
Arun P. Mohanan | 45f844a | 2021-11-03 22:18:09 +0530 | [diff] [blame] | 654 | const std::string filterSpecialModeChange = |
| 655 | rules::type::signal() + rules::member("PropertiesChanged") + |
| 656 | rules::interface("org.freedesktop.DBus.Properties") + |
| 657 | rules::argN(0, specialModeInterface); |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 658 | static std::unique_ptr<sdbusplus::bus::match_t> specialModeChangeMatch = |
| 659 | std::make_unique<sdbusplus::bus::match_t>(conn, filterSpecialModeChange, |
| 660 | [](sdbusplus::message_t& m) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 661 | std::string interfaceName; |
| 662 | boost::container::flat_map<std::string, std::variant<std::string>> |
| 663 | propertiesChanged; |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 664 | |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 665 | m.read(interfaceName, propertiesChanged); |
| 666 | auto itr = propertiesChanged.find("SpecialMode"); |
| 667 | if (itr == propertiesChanged.end()) |
| 668 | { |
| 669 | return; |
| 670 | } |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 671 | auto* manufacturingModeStatus = std::get_if<std::string>(&itr->second); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 672 | handleSpecialModeChange(*manufacturingModeStatus); |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 673 | }); |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 674 | |
Arun P. Mohanan | 45f844a | 2021-11-03 22:18:09 +0530 | [diff] [blame] | 675 | conn.async_method_call( |
| 676 | [](const boost::system::error_code ec, |
| 677 | const std::variant<std::string>& getManufactMode) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 678 | if (ec) |
| 679 | { |
| 680 | std::cerr << "error getting SpecialMode status " << ec.message() |
| 681 | << "\n"; |
| 682 | return; |
| 683 | } |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 684 | const auto* manufacturingModeStatus = |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 685 | std::get_if<std::string>(&getManufactMode); |
| 686 | handleSpecialModeChange(*manufacturingModeStatus); |
Arun P. Mohanan | 45f844a | 2021-11-03 22:18:09 +0530 | [diff] [blame] | 687 | }, |
| 688 | "xyz.openbmc_project.SpecialMode", |
| 689 | "/xyz/openbmc_project/security/special_mode", |
| 690 | "org.freedesktop.DBus.Properties", "Get", specialModeInterface, |
| 691 | "SpecialMode"); |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | bool getManufacturingMode() |
| 695 | { |
| 696 | return manufacturingMode; |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 697 | } |
Zev Weiss | 214d971 | 2022-08-12 12:54:31 -0700 | [diff] [blame] | 698 | |
| 699 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> |
| 700 | setupPropertiesChangedMatches( |
| 701 | sdbusplus::asio::connection& bus, std::span<const char* const> types, |
| 702 | const std::function<void(sdbusplus::message_t&)>& handler) |
| 703 | { |
| 704 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches; |
| 705 | for (const char* type : types) |
| 706 | { |
| 707 | auto match = std::make_unique<sdbusplus::bus::match_t>( |
| 708 | static_cast<sdbusplus::bus_t&>(bus), |
| 709 | "type='signal',member='PropertiesChanged',path_namespace='" + |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 710 | std::string(inventoryPath) + "',arg0namespace='" + |
| 711 | configInterfaceName(type) + "'", |
Zev Weiss | 214d971 | 2022-08-12 12:54:31 -0700 | [diff] [blame] | 712 | handler); |
| 713 | matches.emplace_back(std::move(match)); |
| 714 | } |
| 715 | return matches; |
| 716 | } |
Zev Weiss | dabd48d | 2022-08-03 15:43:17 -0700 | [diff] [blame^] | 717 | |
| 718 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> |
| 719 | setupPropertiesChangedMatches( |
| 720 | sdbusplus::asio::connection& bus, const I2CDeviceTypeMap& typeMap, |
| 721 | const std::function<void(sdbusplus::message_t&)>& handler) |
| 722 | { |
| 723 | std::vector<const char*> types; |
| 724 | types.reserve(typeMap.size()); |
| 725 | for (const auto& [type, dt] : typeMap) |
| 726 | { |
| 727 | types.push_back(type.data()); |
| 728 | } |
| 729 | return setupPropertiesChangedMatches(bus, {types}, handler); |
| 730 | } |