Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 3 | #include "types.hpp" |
| 4 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 5 | #include <libpldm/base.h> |
| 6 | #include <libpldm/bios.h> |
| 7 | #include <libpldm/platform.h> |
| 8 | #include <libpldm/utils.h> |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | #include <systemd/sd-bus.h> |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 11 | #include <unistd.h> |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 12 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 13 | #include <nlohmann/json.hpp> |
| 14 | #include <sdbusplus/server.hpp> |
| 15 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
| 16 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 17 | #include <exception> |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 18 | #include <filesystem> |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 19 | #include <iostream> |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 20 | #include <string> |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 21 | #include <variant> |
| 22 | #include <vector> |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 23 | |
vkaverap@in.ibm.com | 9138c20 | 2023-05-19 07:50:47 -0500 | [diff] [blame] | 24 | using microsec = std::chrono::microseconds; |
| 25 | using sec = std::chrono::seconds; |
| 26 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 27 | namespace pldm |
| 28 | { |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 29 | namespace utils |
| 30 | { |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 31 | namespace fs = std::filesystem; |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 32 | using Json = nlohmann::json; |
Tom Joseph | e5268cd | 2021-09-07 13:04:03 +0530 | [diff] [blame] | 33 | constexpr bool Tx = true; |
| 34 | constexpr bool Rx = false; |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 35 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 36 | /** @struct CustomFD |
| 37 | * |
| 38 | * RAII wrapper for file descriptor. |
| 39 | */ |
| 40 | struct CustomFD |
| 41 | { |
| 42 | CustomFD(const CustomFD&) = delete; |
| 43 | CustomFD& operator=(const CustomFD&) = delete; |
| 44 | CustomFD(CustomFD&&) = delete; |
| 45 | CustomFD& operator=(CustomFD&&) = delete; |
| 46 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 47 | CustomFD(int fd) : fd(fd) {} |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 48 | |
| 49 | ~CustomFD() |
| 50 | { |
| 51 | if (fd >= 0) |
| 52 | { |
| 53 | close(fd); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | int operator()() const |
| 58 | { |
| 59 | return fd; |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | int fd = -1; |
| 64 | }; |
| 65 | |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 66 | /** @brief Calculate the pad for PLDM data |
| 67 | * |
| 68 | * @param[in] data - Length of the data |
| 69 | * @return - uint8_t - number of pad bytes |
| 70 | */ |
| 71 | uint8_t getNumPadBytes(uint32_t data); |
| 72 | |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 73 | /** @brief Convert uint64 to date |
| 74 | * |
| 75 | * @param[in] data - time date of uint64 |
| 76 | * @param[out] year - year number in dec |
| 77 | * @param[out] month - month number in dec |
| 78 | * @param[out] day - day of the month in dec |
| 79 | * @param[out] hour - number of hours in dec |
| 80 | * @param[out] min - number of minutes in dec |
| 81 | * @param[out] sec - number of seconds in dec |
| 82 | * @return true if decode success, false if decode faild |
| 83 | */ |
| 84 | bool uintToDate(uint64_t data, uint16_t* year, uint8_t* month, uint8_t* day, |
| 85 | uint8_t* hour, uint8_t* min, uint8_t* sec); |
| 86 | |
| 87 | /** @brief Convert effecter data to structure of set_effecter_state_field |
| 88 | * |
| 89 | * @param[in] effecterData - the date of effecter |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 90 | * @param[in] effecterCount - the number of individual sets of effecter |
| 91 | * information |
| 92 | * @return[out] parse success and get a valid set_effecter_state_field |
| 93 | * structure, return nullopt means parse failed |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 94 | */ |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 95 | std::optional<std::vector<set_effecter_state_field>> |
| 96 | parseEffecterData(const std::vector<uint8_t>& effecterData, |
| 97 | uint8_t effecterCount); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 98 | |
| 99 | /** |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 100 | * @brief creates an error log |
| 101 | * @param[in] errorMsg - the error message |
| 102 | */ |
| 103 | void reportError(const char* errorMsg); |
| 104 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 105 | /** @brief Convert any Decimal number to BCD |
| 106 | * |
| 107 | * @tparam[in] decimal - Decimal number |
| 108 | * @return Corresponding BCD number |
| 109 | */ |
| 110 | template <typename T> |
| 111 | T decimalToBcd(T decimal) |
| 112 | { |
| 113 | T bcd = 0; |
| 114 | T rem = 0; |
| 115 | auto cnt = 0; |
| 116 | |
| 117 | while (decimal) |
| 118 | { |
| 119 | rem = decimal % 10; |
| 120 | bcd = bcd + (rem << cnt); |
| 121 | decimal = decimal / 10; |
| 122 | cnt += 4; |
| 123 | } |
| 124 | |
| 125 | return bcd; |
| 126 | } |
| 127 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 128 | constexpr auto dbusProperties = "org.freedesktop.DBus.Properties"; |
Pavithra Barithaya | 47180ac | 2020-10-28 02:12:05 -0500 | [diff] [blame] | 129 | constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper"; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 130 | |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 131 | struct DBusMapping |
| 132 | { |
| 133 | std::string objectPath; //!< D-Bus object path |
| 134 | std::string interface; //!< D-Bus interface |
| 135 | std::string propertyName; //!< D-Bus property name |
| 136 | std::string propertyType; //!< D-Bus property type |
| 137 | }; |
| 138 | |
| 139 | using PropertyValue = |
| 140 | std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 141 | uint64_t, double, std::string, std::vector<std::string>>; |
Deepak Kodihalli | 6b1d1ca | 2020-04-27 07:24:51 -0500 | [diff] [blame] | 142 | using DbusProp = std::string; |
| 143 | using DbusChangedProps = std::map<DbusProp, PropertyValue>; |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 144 | using DBusInterfaceAdded = std::vector< |
| 145 | std::pair<pldm::dbus::Interface, |
| 146 | std::vector<std::pair<pldm::dbus::Property, |
| 147 | std::variant<pldm::dbus::Property>>>>>; |
Manojkiran Eda | 1ef62c3 | 2021-04-24 07:23:18 +0530 | [diff] [blame] | 148 | using ObjectPath = std::string; |
| 149 | using ServiceName = std::string; |
| 150 | using Interfaces = std::vector<std::string>; |
| 151 | using MapperServiceMap = std::vector<std::pair<ServiceName, Interfaces>>; |
| 152 | using GetSubTreeResponse = std::vector<std::pair<ObjectPath, MapperServiceMap>>; |
Sridevi Ramesh | eefe49b | 2022-06-27 11:51:02 -0500 | [diff] [blame] | 153 | using PropertyMap = std::map<std::string, PropertyValue>; |
| 154 | using InterfaceMap = std::map<std::string, PropertyMap>; |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 155 | |
| 156 | /** |
| 157 | * @brief The interface for DBusHandler |
| 158 | */ |
| 159 | class DBusHandlerInterface |
| 160 | { |
| 161 | public: |
| 162 | virtual ~DBusHandlerInterface() = default; |
| 163 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 164 | virtual std::string getService(const char* path, |
| 165 | const char* interface) const = 0; |
Manojkiran Eda | 1ef62c3 | 2021-04-24 07:23:18 +0530 | [diff] [blame] | 166 | virtual GetSubTreeResponse |
| 167 | getSubtree(const std::string& path, int depth, |
| 168 | const std::vector<std::string>& ifaceList) const = 0; |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 169 | |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 170 | virtual void setDbusProperty(const DBusMapping& dBusMap, |
| 171 | const PropertyValue& value) const = 0; |
John Wang | 9e24242 | 2020-03-05 08:37:50 +0800 | [diff] [blame] | 172 | |
| 173 | virtual PropertyValue |
| 174 | getDbusPropertyVariant(const char* objPath, const char* dbusProp, |
| 175 | const char* dbusInterface) const = 0; |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 176 | }; |
| 177 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 178 | /** |
| 179 | * @class DBusHandler |
| 180 | * |
| 181 | * Wrapper class to handle the D-Bus calls |
| 182 | * |
| 183 | * This class contains the APIs to handle the D-Bus calls |
| 184 | * to cater the request from pldm requester. |
| 185 | * A class is created to mock the apis in the test cases |
| 186 | */ |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 187 | class DBusHandler : public DBusHandlerInterface |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 188 | { |
| 189 | public: |
George Liu | 0e02c32 | 2020-01-01 09:41:51 +0800 | [diff] [blame] | 190 | /** @brief Get the bus connection. */ |
| 191 | static auto& getBus() |
| 192 | { |
| 193 | static auto bus = sdbusplus::bus::new_default(); |
| 194 | return bus; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * @brief Get the DBUS Service name for the input dbus path |
John Wang | 9e24242 | 2020-03-05 08:37:50 +0800 | [diff] [blame] | 199 | * |
George Liu | 0e02c32 | 2020-01-01 09:41:51 +0800 | [diff] [blame] | 200 | * @param[in] path - DBUS object path |
| 201 | * @param[in] interface - DBUS Interface |
John Wang | 9e24242 | 2020-03-05 08:37:50 +0800 | [diff] [blame] | 202 | * |
George Liu | 0e02c32 | 2020-01-01 09:41:51 +0800 | [diff] [blame] | 203 | * @return std::string - the dbus service name |
John Wang | 9e24242 | 2020-03-05 08:37:50 +0800 | [diff] [blame] | 204 | * |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 205 | * @throw sdbusplus::exception_t when it fails |
George Liu | 0e02c32 | 2020-01-01 09:41:51 +0800 | [diff] [blame] | 206 | */ |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 207 | std::string getService(const char* path, |
| 208 | const char* interface) const override; |
George Liu | 0e02c32 | 2020-01-01 09:41:51 +0800 | [diff] [blame] | 209 | |
Manojkiran Eda | 1ef62c3 | 2021-04-24 07:23:18 +0530 | [diff] [blame] | 210 | /** |
| 211 | * @brief Get the Subtree response from the mapper |
| 212 | * |
| 213 | * @param[in] path - DBUS object path |
| 214 | * @param[in] depth - Search depth |
| 215 | * @param[in] ifaceList - list of the interface that are being |
| 216 | * queried from the mapper |
| 217 | * |
| 218 | * @return GetSubTreeResponse - the mapper subtree response |
| 219 | * |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 220 | * @throw sdbusplus::exception_t when it fails |
Manojkiran Eda | 1ef62c3 | 2021-04-24 07:23:18 +0530 | [diff] [blame] | 221 | */ |
| 222 | GetSubTreeResponse |
| 223 | getSubtree(const std::string& path, int depth, |
| 224 | const std::vector<std::string>& ifaceList) const override; |
| 225 | |
John Wang | 9e24242 | 2020-03-05 08:37:50 +0800 | [diff] [blame] | 226 | /** @brief Get property(type: variant) from the requested dbus |
| 227 | * |
| 228 | * @param[in] objPath - The Dbus object path |
| 229 | * @param[in] dbusProp - The property name to get |
| 230 | * @param[in] dbusInterface - The Dbus interface |
| 231 | * |
| 232 | * @return The value of the property(type: variant) |
| 233 | * |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 234 | * @throw sdbusplus::exception_t when it fails |
John Wang | 9e24242 | 2020-03-05 08:37:50 +0800 | [diff] [blame] | 235 | */ |
| 236 | PropertyValue |
| 237 | getDbusPropertyVariant(const char* objPath, const char* dbusProp, |
| 238 | const char* dbusInterface) const override; |
George Liu | 0e02c32 | 2020-01-01 09:41:51 +0800 | [diff] [blame] | 239 | |
John Wang | 9e24242 | 2020-03-05 08:37:50 +0800 | [diff] [blame] | 240 | /** @brief The template function to get property from the requested dbus |
| 241 | * path |
| 242 | * |
| 243 | * @tparam Property - Excepted type of the property on dbus |
| 244 | * |
| 245 | * @param[in] objPath - The Dbus object path |
| 246 | * @param[in] dbusProp - The property name to get |
| 247 | * @param[in] dbusInterface - The Dbus interface |
| 248 | * |
| 249 | * @return The value of the property |
| 250 | * |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 251 | * @throw sdbusplus::exception_t when dbus request fails |
John Wang | 9e24242 | 2020-03-05 08:37:50 +0800 | [diff] [blame] | 252 | * std::bad_variant_access when \p Property and property on dbus do |
| 253 | * not match |
| 254 | */ |
John Wang | 92b3c97 | 2019-10-17 11:06:41 +0800 | [diff] [blame] | 255 | template <typename Property> |
| 256 | auto getDbusProperty(const char* objPath, const char* dbusProp, |
| 257 | const char* dbusInterface) |
| 258 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 259 | auto VariantValue = getDbusPropertyVariant(objPath, dbusProp, |
| 260 | dbusInterface); |
John Wang | 92b3c97 | 2019-10-17 11:06:41 +0800 | [diff] [blame] | 261 | return std::get<Property>(VariantValue); |
| 262 | } |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 263 | |
| 264 | /** @brief Set Dbus property |
| 265 | * |
| 266 | * @param[in] dBusMap - Object path, property name, interface and property |
| 267 | * type for the D-Bus object |
| 268 | * @param[in] value - The value to be set |
John Wang | 9e24242 | 2020-03-05 08:37:50 +0800 | [diff] [blame] | 269 | * |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 270 | * @throw sdbusplus::exception_t when it fails |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 271 | */ |
| 272 | void setDbusProperty(const DBusMapping& dBusMap, |
| 273 | const PropertyValue& value) const override; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 274 | }; |
| 275 | |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 276 | /** @brief Fetch parent D-Bus object based on pathname |
| 277 | * |
| 278 | * @param[in] dbusObj - child D-Bus object |
| 279 | * |
| 280 | * @return std::string - the parent D-Bus object path |
| 281 | */ |
| 282 | inline std::string findParent(const std::string& dbusObj) |
| 283 | { |
| 284 | fs::path p(dbusObj); |
| 285 | return p.parent_path().string(); |
| 286 | } |
| 287 | |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 288 | /** @brief Read (static) MCTP EID of host firmware from a file |
| 289 | * |
| 290 | * @return uint8_t - MCTP EID |
| 291 | */ |
| 292 | uint8_t readHostEID(); |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 293 | |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 294 | /** @brief Convert a value in the JSON to a D-Bus property value |
| 295 | * |
| 296 | * @param[in] type - type of the D-Bus property |
| 297 | * @param[in] value - value in the JSON file |
| 298 | * |
| 299 | * @return PropertyValue - the D-Bus property value |
| 300 | */ |
| 301 | PropertyValue jsonEntryToDbusVal(std::string_view type, |
| 302 | const nlohmann::json& value); |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 303 | |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 304 | /** @brief Find State Effecter PDR |
| 305 | * @param[in] tid - PLDM terminus ID. |
| 306 | * @param[in] entityID - entity that can be associated with PLDM State set. |
| 307 | * @param[in] stateSetId - value that identifies PLDM State set. |
| 308 | * @param[in] repo - pointer to BMC's primary PDR repo. |
| 309 | * @return array[array[uint8_t]] - StateEffecterPDRs |
| 310 | */ |
| 311 | std::vector<std::vector<uint8_t>> findStateEffecterPDR(uint8_t tid, |
| 312 | uint16_t entityID, |
| 313 | uint16_t stateSetId, |
| 314 | const pldm_pdr* repo); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 315 | /** @brief Find State Sensor PDR |
| 316 | * @param[in] tid - PLDM terminus ID. |
| 317 | * @param[in] entityID - entity that can be associated with PLDM State set. |
| 318 | * @param[in] stateSetId - value that identifies PLDM State set. |
| 319 | * @param[in] repo - pointer to BMC's primary PDR repo. |
| 320 | * @return array[array[uint8_t]] - StateSensorPDRs |
| 321 | */ |
| 322 | std::vector<std::vector<uint8_t>> findStateSensorPDR(uint8_t tid, |
| 323 | uint16_t entityID, |
| 324 | uint16_t stateSetId, |
| 325 | const pldm_pdr* repo); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 326 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 327 | /** @brief Find sensor id from a state sensor PDR |
| 328 | * |
| 329 | * @param[in] pdrRepo - PDR repository |
| 330 | * @param[in] tid - terminus id |
| 331 | * @param[in] entityType - entity type |
| 332 | * @param[in] entityInstance - entity instance number |
| 333 | * @param[in] containerId - container id |
| 334 | * @param[in] stateSetId - state set id |
| 335 | * |
| 336 | * @return uint16_t - the sensor id |
| 337 | */ |
| 338 | uint16_t findStateSensorId(const pldm_pdr* pdrRepo, uint8_t tid, |
| 339 | uint16_t entityType, uint16_t entityInstance, |
| 340 | uint16_t containerId, uint16_t stateSetId); |
| 341 | |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 342 | /** @brief Find effecter id from a state effecter pdr |
| 343 | * @param[in] pdrRepo - PDR repository |
| 344 | * @param[in] entityType - entity type |
| 345 | * @param[in] entityInstance - entity instance number |
| 346 | * @param[in] containerId - container id |
| 347 | * @param[in] stateSetId - state set id |
Sampa Misra | a4a9616 | 2020-07-14 05:33:46 -0500 | [diff] [blame] | 348 | * @param[in] localOrRemote - true for checking local repo and false for remote |
| 349 | * repo |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 350 | * |
| 351 | * @return uint16_t - the effecter id |
| 352 | */ |
| 353 | uint16_t findStateEffecterId(const pldm_pdr* pdrRepo, uint16_t entityType, |
| 354 | uint16_t entityInstance, uint16_t containerId, |
Sampa Misra | a4a9616 | 2020-07-14 05:33:46 -0500 | [diff] [blame] | 355 | uint16_t stateSetId, bool localOrRemote); |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 356 | |
Chicago Duan | fe4d88b | 2020-06-12 16:44:13 +0800 | [diff] [blame] | 357 | /** @brief Emit the sensor event signal |
| 358 | * |
| 359 | * @param[in] tid - the terminus id |
| 360 | * @param[in] sensorId - sensorID value of the sensor |
| 361 | * @param[in] sensorOffset - Identifies which state sensor within a |
| 362 | * composite state sensor the event is being returned for |
| 363 | * @param[in] eventState - The event state value from the state change that |
| 364 | * triggered the event message |
| 365 | * @param[in] previousEventState - The event state value for the state from |
| 366 | * which the present event state was entered. |
| 367 | * @return PLDM completion code |
| 368 | */ |
| 369 | int emitStateSensorEventSignal(uint8_t tid, uint16_t sensorId, |
| 370 | uint8_t sensorOffset, uint8_t eventState, |
| 371 | uint8_t previousEventState); |
| 372 | |
Sridevi Ramesh | ae28bc7 | 2020-12-10 07:21:16 -0600 | [diff] [blame] | 373 | /** @brief Print the buffer |
| 374 | * |
Tom Joseph | e5268cd | 2021-09-07 13:04:03 +0530 | [diff] [blame] | 375 | * @param[in] isTx - True if the buffer is an outgoing PLDM message, false if |
| 376 | the buffer is an incoming PLDM message |
| 377 | * @param[in] buffer - Buffer to print |
Sridevi Ramesh | ae28bc7 | 2020-12-10 07:21:16 -0600 | [diff] [blame] | 378 | * |
| 379 | * @return - None |
| 380 | */ |
Tom Joseph | e5268cd | 2021-09-07 13:04:03 +0530 | [diff] [blame] | 381 | void printBuffer(bool isTx, const std::vector<uint8_t>& buffer); |
Sridevi Ramesh | ae28bc7 | 2020-12-10 07:21:16 -0600 | [diff] [blame] | 382 | |
Tom Joseph | 5492207 | 2021-06-19 02:45:46 -0700 | [diff] [blame] | 383 | /** @brief Convert the buffer to std::string |
| 384 | * |
| 385 | * If there are characters that are not printable characters, it is replaced |
| 386 | * with space(0x20). |
| 387 | * |
| 388 | * @param[in] var - pointer to data and length of the data |
| 389 | * |
| 390 | * @return std::string equivalent of variable field |
| 391 | */ |
| 392 | std::string toString(const struct variable_field& var); |
| 393 | |
George Liu | 872f0f6 | 2021-11-25 16:26:16 +0800 | [diff] [blame] | 394 | /** @brief Split strings according to special identifiers |
| 395 | * |
| 396 | * We can split the string according to the custom identifier(';', ',', '&' or |
| 397 | * others) and store it to vector. |
| 398 | * |
| 399 | * @param[in] srcStr - The string to be split |
| 400 | * @param[in] delim - The custom identifier |
| 401 | * @param[in] trimStr - The first and last string to be trimmed |
| 402 | * |
| 403 | * @return std::vector<std::string> Vectors are used to store strings |
| 404 | */ |
| 405 | std::vector<std::string> split(std::string_view srcStr, std::string_view delim, |
| 406 | std::string_view trimStr = ""); |
Manojkiran Eda | ef77305 | 2021-07-29 09:29:28 +0530 | [diff] [blame] | 407 | /** @brief Get the current system time in readable format |
| 408 | * |
| 409 | * @return - std::string equivalent of the system time |
| 410 | */ |
| 411 | std::string getCurrentSystemTime(); |
George Liu | 872f0f6 | 2021-11-25 16:26:16 +0800 | [diff] [blame] | 412 | |
Sridevi Ramesh | eefe49b | 2022-06-27 11:51:02 -0500 | [diff] [blame] | 413 | /** @brief checks if the FRU is actually present. |
| 414 | * @param[in] objPath - FRU object path. |
| 415 | * |
| 416 | * @return bool to indicate presence or absence of FRU. |
| 417 | */ |
| 418 | bool checkForFruPresence(const std::string& objPath); |
| 419 | |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 420 | } // namespace utils |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 421 | } // namespace pldm |