// Copyright 2022 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 "config.h"

#include "pcie_bifurcation.hpp"

#include "commands.hpp"
#include "errors.hpp"
#include "handler.hpp"

#include <fmt/format.h>

#include <ipmid/api-types.hpp>

#include <span>
#include <vector>

namespace google
{
namespace ipmi
{

namespace
{
#ifndef MAX_IPMI_BUFFER
#define MAX_IPMI_BUFFER 64
#endif
} // namespace

struct PcieBifurcationRequest
{
    uint8_t pcieIndex;
} __attribute__((packed));

Resp pcieBifurcation(std::span<const uint8_t> data, HandlerInterface* handler)
{
    if (data.size() < sizeof(struct PcieBifurcationRequest))
    {
        fmt::print(stderr, "Invalid command length: {}\n",
                   static_cast<uint32_t>(data.size()));
        return ::ipmi::responseReqDataLenInvalid();
    }

    auto bifurcation = handler->pcieBifurcation(/*index=*/data[0]);

    int length = sizeof(struct PcieBifurcationReply) + bifurcation.size();

    if (length > MAX_IPMI_BUFFER)
    {
        std::fprintf(stderr, "Response would overflow response buffer\n");
        return ::ipmi::responseInvalidCommand();
    }

    std::vector<std::uint8_t> reply;
    reply.reserve(bifurcation.size() + sizeof(struct PcieBifurcationReply));
    reply.emplace_back(bifurcation.size()); /* bifurcationLength */
    reply.insert(reply.end(), bifurcation.begin(),
                 bifurcation.end());        /* bifurcation */

    return ::ipmi::responseSuccess(SysOEMCommands::SysPCIeSlotBifurcation,
                                   reply);
}
} // namespace ipmi
} // namespace google
