| // Copyright 2024 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #include "fake_bus.hpp" |
| |
| #include "message_util.hpp" |
| #include "payload_update_common.hpp" |
| |
| #include <sdbusplus/bus.hpp> |
| #include <sdbusplus/message.hpp> |
| #include <stdplus/raw.hpp> |
| #include <xyz/openbmc_project/Control/Hoth/server.hpp> |
| |
| #include <chrono> |
| #include <cstring> |
| #include <iostream> |
| #include <string> |
| #include <string_view> |
| #include <utility> |
| |
| namespace google::hoth::tools |
| { |
| bool FakeBus::sendPayloadAndVerify(const std::string& /*hothId*/, |
| const std::string& /*path*/) |
| { |
| if (options.resetRequired && !resetHeld) |
| { |
| return false; |
| } |
| if (options.injectPayloadFail) |
| { |
| std::cout << "Send payload failed." << '\n'; |
| return false; |
| } |
| nextHalfVersion = options.newVersion; |
| std::cout << "Payload sent." << '\n'; |
| return verifyPayload(); |
| } |
| |
| bool FakeBus::sendStaticWPPayloadAndVerify(const std::string& /*hothId*/, |
| const std::string& /*path*/) |
| { |
| if (options.resetRequired && !resetHeld) |
| { |
| return false; |
| } |
| if (options.injectPayloadFail) |
| { |
| std::cout << "Send payload failed." << '\n'; |
| return false; |
| } |
| nextHalfVersion = options.newVersion; |
| std::cout << "Payload sent." << '\n'; |
| return verifyPayload(); |
| } |
| |
| bool FakeBus::activatePayload(const std::string& /*hothId*/) |
| { |
| if (options.injectActivateFail) |
| { |
| std::cout << "Activate payload failed." << '\n'; |
| return false; |
| } |
| return true; |
| } |
| |
| bool FakeBus::deactivatePayload(const std::string& /*hothId*/) |
| { |
| if (options.injectDeactivateFail) |
| { |
| std::cout << "Deactivate payload failed." << '\n'; |
| return false; |
| } |
| return true; |
| } |
| |
| bool FakeBus::confirmPayload(const std::string& /*hothId*/) |
| { |
| return true; |
| } |
| |
| bool FakeBus::eraseStagingArea(const std::string& /*hothId*/) |
| { |
| if (options.resetRequired && !resetHeld) |
| { |
| return false; |
| } |
| if (options.injectInvalidAreaSize) |
| { |
| std::cout << "Invalid staging area size" << '\n'; |
| return false; |
| } |
| std::cout << "Erased." << '\n'; |
| return true; |
| } |
| |
| bool FakeBus::setTargetResetOption(const std::string& /*hothId*/, |
| ec_target_reset_option option) |
| { |
| if (option == EC_TARGET_RESET_OPTION_SET) |
| { |
| resetHeld = true; |
| } |
| else if (option == EC_TARGET_RESET_OPTION_RELEASE) |
| { |
| resetHeld = false; |
| } |
| else |
| { |
| return false; |
| } |
| return true; |
| } |
| |
| std::optional<std::string> |
| FakeBus::getPayloadVersion(const std::string& /*hothId*/, |
| payload_update::VersionType type) |
| { |
| if (options.injectVersionFail) |
| { |
| std::cout << "Failed to get payload version" << '\n'; |
| return {}; |
| } |
| std::cerr << "Active half: 0" << '\n'; |
| std::cerr << "Version[0]: " << fake_bus::kActiveHalfVersion << '\n'; |
| std::cerr << "Version[1]: " << nextHalfVersion << '\n'; |
| if (type == payload_update::VersionType::kActiveHalf) |
| { |
| return fake_bus::kActiveHalfVersion; |
| } |
| return nextHalfVersion; |
| } |
| |
| bool FakeBus::verifyPayload() const { |
| if (options.injectVerifyPayloadFail) { |
| std::cout << "Verify payload failed." << '\n'; |
| return false; |
| } |
| return true; |
| } |
| |
| bool FakeBus::setSpsPassthrough(const std::string& /*hothId*/, |
| const bool /*enable*/) |
| { |
| if (options.injectSpsPassthroughFail) |
| { |
| std::cout << "Failed to set SPS passthrough mode" << '\n'; |
| return false; |
| } |
| return true; |
| } |
| |
| std::optional<bool> FakeBus::getSpsPassthrough(const std::string& /*hothId*/) |
| { |
| return true; |
| } |
| |
| } // namespace google::hoth::tools |