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