blob: 68d576376f389cb01e31d9fe1cb1f30faf71c22c [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.
#include "version.hpp"
#include "google3/ec_commands.h"
#include "message_util.hpp"
#include <stdplus/print.hpp>
#include <stdplus/raw.hpp>
#include <xyz/openbmc_project/Control/Hoth/error.hpp>
#include <span>
#include <stdexcept>
#include <vector>
namespace google
{
namespace hoth
{
using sdbusplus::error::xyz::openbmc_project::control::hoth::ResponseFailure;
using internal::EC_RES_SUCCESS;
using internal::HostCommand;
using internal::RspHeader;
static ec_response_get_version getHothVersion(HostCommand* hostCmd)
{
uint8_t request = 0;
std::vector<uint8_t> buf =
hostCmd->sendCommand(EC_CMD_GET_VERSION, 0, &request, sizeof(request));
// Extract the response header out when returning the span
std::span<const uint8_t> output = buf;
auto& rsp = stdplus::raw::extractRef<RspHeader>(output);
if (rsp.result != EC_RES_SUCCESS)
{
stdplus::print(
stderr, "Version command received a bad response from Hoth {:#x}\n",
static_cast<uint8_t>(rsp.result));
throw ResponseFailure();
}
return stdplus::raw::copyFrom<ec_response_get_version>(output);
}
std::string RoVersion::version() const
{
ec_response_get_version resp = getHothVersion(RoVersion::hostCmd);
return resp.version_string_ro;
}
std::string RwVersion::version() const
{
ec_response_get_version resp = getHothVersion(RwVersion::hostCmd);
return resp.version_string_rw;
}
} // namespace hoth
} // namespace google