Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "lpcsnoop/snoop.hpp" |
| 4 | |
| 5 | #include <boost/asio.hpp> |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 6 | #include <gpiod.hpp> |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 7 | #include <sdbusplus/asio/connection.hpp> |
| 8 | #include <sdbusplus/asio/object_server.hpp> |
| 9 | #include <sdbusplus/asio/property.hpp> |
| 10 | #include <sdbusplus/bus.hpp> |
| 11 | #include <sdbusplus/server.hpp> |
| 12 | #include <xyz/openbmc_project/Chassis/Buttons/HostSelector/server.hpp> |
| 13 | #include <xyz/openbmc_project/State/Boot/Raw/server.hpp> |
| 14 | |
Patrick Williams | 0ea7357 | 2023-05-10 07:50:44 -0500 | [diff] [blame] | 15 | #include <filesystem> |
| 16 | #include <iostream> |
Jonathan Doman | de7a6dd | 2023-05-03 10:54:08 -0700 | [diff] [blame] | 17 | #include <span> |
Patrick Williams | 0ea7357 | 2023-05-10 07:50:44 -0500 | [diff] [blame] | 18 | |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 19 | const std::string ipmiSnoopObject = "/xyz/openbmc_project/state/boot/raw"; |
| 20 | |
| 21 | const int hostParseIdx = 3; |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 22 | const int maxPosition = 4; |
| 23 | |
Jonathan Doman | de7a6dd | 2023-05-03 10:54:08 -0700 | [diff] [blame] | 24 | extern bool sevenSegmentLedEnabled; |
Kumar Thangavel | aee6540 | 2022-08-09 17:21:48 +0530 | [diff] [blame] | 25 | |
Jonathan Doman | de7a6dd | 2023-05-03 10:54:08 -0700 | [diff] [blame] | 26 | extern std::vector<gpiod::line> led_lines; |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 27 | |
| 28 | using Selector = |
| 29 | sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::HostSelector; |
| 30 | |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 31 | const std::string selectorService = "xyz.openbmc_project.Chassis.Buttons"; |
| 32 | const std::string selectorObject = |
| 33 | "/xyz/openbmc_project/Chassis/Buttons/HostSelector"; |
| 34 | const std::string selectorIface = |
| 35 | "xyz.openbmc_project.Chassis.Buttons.HostSelector"; |
| 36 | |
| 37 | const std::string rawObject = "/xyz/openbmc_project/state/boot"; |
| 38 | const std::string rawIface = "xyz.openbmc_project.State.Boot.Raw"; |
| 39 | const std::string rawService = "xyz.openbmc_project.State.Boot.Raw"; |
| 40 | |
Jonathan Doman | de7a6dd | 2023-05-03 10:54:08 -0700 | [diff] [blame] | 41 | int postCodeIpmiHandler(const std::string& snoopObject, |
| 42 | const std::string& snoopDbus, sdbusplus::bus_t& bus, |
| 43 | std::span<std::string> host); |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 44 | |
Jonathan Doman | de7a6dd | 2023-05-03 10:54:08 -0700 | [diff] [blame] | 45 | uint32_t getSelectorPosition(sdbusplus::bus_t& bus); |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 46 | |
| 47 | struct IpmiPostReporter : PostObject |
| 48 | { |
Patrick Williams | aebf87c | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 49 | IpmiPostReporter(sdbusplus::bus_t& bus, const char* objPath) : |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 50 | PostObject(bus, objPath), bus(bus), |
| 51 | propertiesChangedSignalRaw( |
| 52 | bus, |
| 53 | sdbusplus::bus::match::rules::propertiesChanged(objPath, rawIface), |
| 54 | |
Patrick Williams | aebf87c | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 55 | [this, &bus](sdbusplus::message_t& msg) { |
Cosmo Chou | fe51495 | 2024-09-05 01:08:58 +0800 | [diff] [blame^] | 56 | using primarycode_t = std::vector<uint8_t>; |
Patrick Williams | d62ef55 | 2024-08-16 15:20:42 -0400 | [diff] [blame] | 57 | using secondarycode_t = std::vector<uint8_t>; |
| 58 | using postcode_t = std::tuple<primarycode_t, secondarycode_t>; |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 59 | |
Patrick Williams | d62ef55 | 2024-08-16 15:20:42 -0400 | [diff] [blame] | 60 | /* sevenSegmentLedEnabled flag is set when GPIO pins are not |
| 61 | there 7 seg display for fewer platforms. So, the code for |
| 62 | postcode display and Get Selector position can be skipped in |
| 63 | those platforms. |
| 64 | */ |
| 65 | if (!sevenSegmentLedEnabled) |
Kumar Thangavel | aee6540 | 2022-08-09 17:21:48 +0530 | [diff] [blame] | 66 | { |
Patrick Williams | d62ef55 | 2024-08-16 15:20:42 -0400 | [diff] [blame] | 67 | return; |
Kumar Thangavel | aee6540 | 2022-08-09 17:21:48 +0530 | [diff] [blame] | 68 | } |
Patrick Williams | d62ef55 | 2024-08-16 15:20:42 -0400 | [diff] [blame] | 69 | |
| 70 | std::string objectName; |
| 71 | std::string InterfaceName; |
| 72 | std::map<std::string, std::variant<postcode_t>> msgData; |
| 73 | msg.read(InterfaceName, msgData); |
| 74 | |
| 75 | std::filesystem::path name(msg.get_path()); |
| 76 | objectName = name.filename(); |
| 77 | |
| 78 | std::string hostNumStr = objectName.substr(hostParseIdx); |
| 79 | size_t hostNum = std::stoi(hostNumStr); |
| 80 | |
| 81 | size_t position = getSelectorPosition(bus); |
| 82 | |
| 83 | if (position > maxPosition) |
| 84 | { |
| 85 | std::cerr << "Invalid position. Position should be 1 to 4 " |
| 86 | "for all hosts " |
| 87 | << std::endl; |
| 88 | } |
| 89 | |
| 90 | // Check if it was the Value property that changed. |
| 91 | auto valPropMap = msgData.find("Value"); |
| 92 | if (valPropMap == msgData.end()) |
| 93 | { |
| 94 | std::cerr << "Value property is not found " << std::endl; |
| 95 | return; |
| 96 | } |
Cosmo Chou | fe51495 | 2024-09-05 01:08:58 +0800 | [diff] [blame^] | 97 | auto postcode = |
Patrick Williams | d62ef55 | 2024-08-16 15:20:42 -0400 | [diff] [blame] | 98 | std::get<0>(std::get<postcode_t>(valPropMap->second)); |
| 99 | |
Cosmo Chou | fe51495 | 2024-09-05 01:08:58 +0800 | [diff] [blame^] | 100 | if (postcode.size() == 1) |
Patrick Williams | d62ef55 | 2024-08-16 15:20:42 -0400 | [diff] [blame] | 101 | { |
| 102 | if (position == hostNum) |
| 103 | { |
Patrick Williams | d62ef55 | 2024-08-16 15:20:42 -0400 | [diff] [blame] | 104 | // write postcode into seven segment display |
Cosmo Chou | fe51495 | 2024-09-05 01:08:58 +0800 | [diff] [blame^] | 105 | if (postCodeDisplay(postcode[0]) < 0) |
Patrick Williams | d62ef55 | 2024-08-16 15:20:42 -0400 | [diff] [blame] | 106 | { |
| 107 | fprintf(stderr, "Error in display the postcode\n"); |
| 108 | } |
| 109 | } |
| 110 | else |
| 111 | { |
| 112 | fprintf(stderr, "Host Selector Position and host " |
| 113 | "number is not matched..\n"); |
| 114 | } |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | fprintf(stderr, "invalid postcode value \n"); |
| 119 | } |
| 120 | }) |
Patrick Williams | 0ea7357 | 2023-05-10 07:50:44 -0500 | [diff] [blame] | 121 | {} |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 122 | |
Patrick Williams | aebf87c | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 123 | sdbusplus::bus_t& bus; |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 124 | sdbusplus::bus::match_t propertiesChangedSignalRaw; |
| 125 | int postCodeDisplay(uint8_t); |
Patrick Williams | aebf87c | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 126 | void getSelectorPositionSignal(sdbusplus::bus_t& bus); |
Kumar Thangavel | 0269eaf | 2021-08-11 15:45:18 +0530 | [diff] [blame] | 127 | }; |