blob: 2ba89c1f28446ceecb7b73b6e22a66deb44f8bf3 [file] [log] [blame]
// 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.
#pragma once
#include "google3/host_commands.h"
#include "dbus_interface.hpp"
#include "message_util.hpp"
#include "payload_update.hpp"
#include "payload_update_common.hpp"
#include <sdbusplus/bus.hpp>
#include <sdbusplus/message.hpp>
#include <xyz/openbmc_project/Control/Hoth/server.hpp>
#include <optional>
#include <span>
#include <string>
#include <vector>
namespace google::hoth::tools
{
struct PayloadVersionResponse
{
google::hoth::internal::RspHeader header;
payload_status_response status;
};
struct SpsPassthroughStatusResponse
{
google::hoth::internal::RspHeader header;
ec_response_sps_passthrough_status status;
};
struct TargetResetRequest
{
google::hoth::internal::ReqHeader header;
ec_request_reset_target request;
};
struct PayloadConfirmRequest
{
google::hoth::internal::ReqHeader header;
google::hoth::internal::ConfirmRequest request;
};
class HothDBus : public DBusInterface
{
public:
using FirmwareUpdateStatus = sdbusplus::xyz::openbmc_project::Control::
server::Hoth::FirmwareUpdateStatus;
HothDBus() : dbus(sdbusplus::bus::new_system())
{}
std::optional<std::string>
getPayloadVersion(const std::string& hothId,
payload_update::VersionType type) override;
bool sendPayloadAndVerify(const std::string& hothId,
const std::string& payloadFile) override;
bool sendStaticWPPayloadAndVerify(const std::string& hothId,
const std::string& payloadFile) override;
bool activatePayload(const std::string& hothId) override;
bool deactivatePayload(const std::string& hothId) override;
bool confirmPayload(const std::string& hothId) override;
bool eraseStagingArea(const std::string& hothId) override;
bool setTargetResetOption(const std::string& hothId,
ec_target_reset_option option) override;
bool setSpsPassthrough(const std::string& hothId,
bool enable) override;
std::optional<bool> getSpsPassthrough(const std::string& hothId) override;
bool expectConfirmPayload() override;
private:
template <typename... Vargs>
sdbusplus::message::message callMethod(const char* method,
const std::string& hothId,
Vargs&&... vargs);
template <typename T, typename... Vargs>
void callMethodAndRead(const char* method, const std::string& hothId,
T& value, Vargs&&... vargs);
FirmwareUpdateStatus getVerifyPayloadStatus(const std::string& hothId);
FirmwareUpdateStatus getSendPayloadStatus(const std::string& hothId);
bool verifyPayload(const std::string& hothId);
sdbusplus::bus::bus dbus;
};
} // namespace google::hoth::tools