blob: fc538acd356d8477efc722feb9914d43430c1247 [file]
// 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 "asset.hpp"
#include "google3/ec_commands.h"
#include <format>
#include <string>
#include <tuple>
#include <vector>
namespace google
{
namespace hoth
{
using internal::EcUtil;
namespace
{
constexpr std::string_view kFieldUnknown = "unknown";
constexpr std::string_view kProductNameH1B1P = "H1B1P";
constexpr std::string_view kProductNameH1B2P = "H1B2P";
constexpr std::string_view kProductNameH1D2P = "H1D2P";
constexpr std::string_view kPartNumberH1B1P = "07133954";
constexpr std::string_view kPartNumberH1B2P = "07138244";
constexpr std::string_view kPartNumberH1D2P = "G660-00438-01";
constexpr std::string kManufacturer = "Google";
constexpr std::string kModel = "Titan";
std::string_view GetRevisionName(uint16_t hardware_category)
{
switch (hardware_category)
{
case CRYPTA_HW_CAT_HOTH_B1:
return kProductNameH1B1P;
case CRYPTA_HW_CAT_HOTH_B2:
return kProductNameH1B2P;
case CRYPTA_HW_CAT_HOTH_D2:
return kProductNameH1D2P;
default:
return kFieldUnknown;
}
}
std::string_view GetPartNumber(uint16_t hardware_category)
{
switch (hardware_category)
{
case CRYPTA_HW_CAT_HOTH_B1:
return kPartNumberH1B1P;
case CRYPTA_HW_CAT_HOTH_B2:
return kPartNumberH1B2P;
case CRYPTA_HW_CAT_HOTH_D2:
return kPartNumberH1D2P;
default:
return kFieldUnknown;
}
}
std::string GetSerialNumber(const ec_response_chip_info& chip_info)
{
return std::format("{}-{:#16x}",
static_cast<uint16_t>(chip_info.hardware_category),
static_cast<uint64_t>(chip_info.hardware_identity));
}
} // namespace
Asset::Asset(sdbusplus::bus::bus& bus, const std::string& objPath,
const std::string& boardPath, EcUtil* ecUtil) :
AssetAssociationObject(bus, objPath.c_str(),
AssetAssociationObject::action::defer_emit)
{
ec_response_chip_info chip_info = ecUtil->getHothChipInfo();
/* Set Hoth Chip Info Properties */
partNumber(std::string(GetPartNumber(chip_info.hardware_category)), true);
subModel(std::string(GetRevisionName(chip_info.hardware_category)), true);
serialNumber(GetSerialNumber(chip_info), true);
manufacturer(kManufacturer, true);
model(kModel, true);
/* Set association with chassis/board object that contains the hoth */
associations({std::make_tuple("chassis", "assembly", boardPath)}, true);
AssetAssociationObject::emit_object_added();
}
} // namespace hoth
} // namespace google