blob: 2be224a183913f6d1d8099e567c38a84c6e39140 [file] [log] [blame]
/*
* Copyright 2018 Google Inc.
*
* 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 "updatehelper.hpp"
#include <cstring>
#include <vector>
namespace
{
// Output a vector of bytes consisted of the command header and given input.
// Precondition: packet must be preallocated with kFlashCommandHdrSizeBytes.
void constructFlashIpmiPacket(int command, const uint8_t* payload,
int payload_size, std::vector<uint8_t>* packet)
{
struct CommandHdr hdr;
std::memset(&hdr, 0, sizeof(hdr));
hdr.command = OEM_FLASH_UPDATE_BT_COMMAND;
hdr.subcommand = command;
#ifdef ENABLE_GOOGLE
hdr.netfn = NETFN_OEM;
std::memcpy(&hdr.oen, OEN_GOOGLE, sizeof(OEN_GOOGLE));
#else
hdr.netfn = NETFN_FIRMWARE;
#endif
std::memcpy(packet->data(), &hdr, sizeof(hdr));
if (payload != nullptr && payload_size > 0)
{
packet->insert(packet->end(), payload, payload + payload_size);
}
}
} // namespace
/*
* For use with BT Flash commands with payloads
*/
struct IpmiResponse
IpmiUpdateHelper::SendCommand(int command,
const std::vector<uint8_t>& payload)
{
std::vector<uint8_t> packet(kFlashCommandHdrSizeBytes);
constructFlashIpmiPacket(command, payload.data(), payload.size(), &packet);
return raw->Raw(packet);
}
/*
* For use with BT Flash commands that are only the command itself.
*/
struct IpmiResponse IpmiUpdateHelper::SendEmptyCommand(int command)
{
return SendCommand(command, {});
}