blob: c8e9da72a4c2a680d9dfe3b62bfa0eadee2db756 [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 <stdplus/raw.hpp>
#include <cstdint>
#include <numeric>
#include <span>
#include <vector>
namespace ipmi_hoth
{
namespace internal
{
/** @class HothUtil
* @brief An interface to Hoth SKM HSS operation
* @details Translate Hoth requests to bytes array commands and analyze
* Hoth responses.
*/
class HothUtil
{
public:
virtual ~HothUtil() {};
/** @brief Calculates the checksum for an EC request with the given
* |contents|
* @param one or more spans (or vectors) of bytes
* @returns the checksum for a message with the given |contents|
*/
template <typename... Ts>
static uint8_t calculateChecksum(Ts&&... ts)
{
return (std::accumulate(std::begin(ts), std::end(ts), 0) + ...);
}
/** @brief Wrap the EC SKM HSS request by serializing the concatenation of
* an EC request header and payload
* @param request: the EC SKM HSS request
* @returns the serialized EC request
*/
virtual std::vector<uint8_t>
wrapECSKMHSSRequest(std::span<const uint8_t> request) = 0;
/** @brief Wrap the EC SKM HSS read request
* @param slot: the slot number in Hoth
* @returns the serialized EC request
*/
virtual std::vector<uint8_t> readSKMHSS(uint32_t slot) = 0;
/** @brief Wrap the EC SKM HSS write request
* @param slot: the slot number in Hoth
* @data data: SKM HSS bytes
* @returns the serialized EC request
*/
virtual std::vector<uint8_t> writeSKMHSS(uint32_t slot,
std::span<const uint8_t> data) = 0;
/** @brief Wrap the EC SKM HSS delete request
* @param slot: the slot number in Hoth
* @returns the serialized EC request
*/
virtual std::vector<uint8_t> deleteSKMHSS(uint32_t slot) = 0;
/** @brief Validate the EC response and extract the payload by stripping off
* the header
* @param rsp: bytes array representing response received from EC
* @returns return the payload in an EC response iff the EC response is
* valid.
*/
virtual std::span<const uint8_t>
payloadECResponse(std::span<const uint8_t> rsp) = 0;
};
} // namespace internal
} // namespace ipmi_hoth