1bffaa110SPrithvi Pai /* 2bffaa110SPrithvi Pai * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & 3bffaa110SPrithvi Pai * AFFILIATES. All rights reserved. 4bffaa110SPrithvi Pai * SPDX-License-Identifier: Apache-2.0 5bffaa110SPrithvi Pai */ 6bffaa110SPrithvi Pai 7bffaa110SPrithvi Pai #include "oemcommands.hpp" 8bffaa110SPrithvi Pai 9bffaa110SPrithvi Pai #include <ipmid/api.hpp> 10bffaa110SPrithvi Pai #include <ipmid/types.hpp> 11*6823fd46SPrithvi Pai #include <ipmid/utils.hpp> 12*6823fd46SPrithvi Pai #include <phosphor-logging/lg2.hpp> 13bffaa110SPrithvi Pai 14bffaa110SPrithvi Pai #include <cstdint> 15bffaa110SPrithvi Pai 16bffaa110SPrithvi Pai void registerBootstrapCredentialsOemCommands() __attribute__((constructor)); 17bffaa110SPrithvi Pai 18bffaa110SPrithvi Pai namespace ipmi 19bffaa110SPrithvi Pai { 20bffaa110SPrithvi Pai ipmi::RspType<uint8_t, uint8_t> ipmiGetUsbVendorIdProductId(uint8_t type) 21bffaa110SPrithvi Pai { 22bffaa110SPrithvi Pai constexpr uint8_t descriptorVendorId = 1; 23bffaa110SPrithvi Pai constexpr uint8_t descriptorProductId = 2; 24bffaa110SPrithvi Pai 25bffaa110SPrithvi Pai // IPMI OEM USB Linux Gadget info 26bffaa110SPrithvi Pai constexpr uint16_t usbVendorId = 0x0525; 27bffaa110SPrithvi Pai constexpr uint16_t usbProductId = 0xA4A2; 28bffaa110SPrithvi Pai 29bffaa110SPrithvi Pai if (type == descriptorVendorId) 30bffaa110SPrithvi Pai { 31bffaa110SPrithvi Pai return ipmi::responseSuccess(static_cast<uint8_t>(usbVendorId >> 8), 32bffaa110SPrithvi Pai static_cast<uint8_t>(usbVendorId & 0xFF)); 33bffaa110SPrithvi Pai } 34bffaa110SPrithvi Pai else if (type == descriptorProductId) 35bffaa110SPrithvi Pai { 36bffaa110SPrithvi Pai return ipmi::responseSuccess(static_cast<uint8_t>(usbProductId >> 8), 37bffaa110SPrithvi Pai static_cast<uint8_t>(usbProductId & 0xFF)); 38bffaa110SPrithvi Pai } 39bffaa110SPrithvi Pai return ipmi::responseInvalidFieldRequest(); 40bffaa110SPrithvi Pai } 41bffaa110SPrithvi Pai 426bf35ee6SPrithvi Pai ipmi::RspType<ipmi::message::Payload> ipmiGetUsbSerialNumber() 436bf35ee6SPrithvi Pai { 446bf35ee6SPrithvi Pai static constexpr uint8_t usbSerialNumber = 0x00; 456bf35ee6SPrithvi Pai ipmi::message::Payload usbSerialNumberPayload; 466bf35ee6SPrithvi Pai usbSerialNumberPayload.pack(usbSerialNumber); 476bf35ee6SPrithvi Pai return ipmi::responseSuccess(usbSerialNumberPayload); 486bf35ee6SPrithvi Pai } 496bf35ee6SPrithvi Pai 50*6823fd46SPrithvi Pai ipmi::RspType<ipmi::message::Payload> ipmiGetRedfishHostName( 51*6823fd46SPrithvi Pai ipmi::Context::ptr ctx) 52*6823fd46SPrithvi Pai { 53*6823fd46SPrithvi Pai std::string service{}; 54*6823fd46SPrithvi Pai constexpr auto networkConfigObj = "/xyz/openbmc_project/network/config"; 55*6823fd46SPrithvi Pai constexpr auto networkConfigIface = 56*6823fd46SPrithvi Pai "xyz.openbmc_project.Network.SystemConfiguration"; 57*6823fd46SPrithvi Pai boost::system::error_code ec = 58*6823fd46SPrithvi Pai ipmi::getService(ctx, networkConfigIface, networkConfigObj, service); 59*6823fd46SPrithvi Pai if (ec) 60*6823fd46SPrithvi Pai { 61*6823fd46SPrithvi Pai lg2::error("ipmiGetRedfishHostName failed to get Network SystemConfig " 62*6823fd46SPrithvi Pai "object: {STATUS}", 63*6823fd46SPrithvi Pai "STATUS", ec.message()); 64*6823fd46SPrithvi Pai return ipmi::responseResponseError(); 65*6823fd46SPrithvi Pai } 66*6823fd46SPrithvi Pai 67*6823fd46SPrithvi Pai std::string hostName{}; 68*6823fd46SPrithvi Pai ec = ipmi::getDbusProperty<std::string>( 69*6823fd46SPrithvi Pai ctx, service, networkConfigObj, networkConfigIface, "HostName", 70*6823fd46SPrithvi Pai hostName); 71*6823fd46SPrithvi Pai if (ec) 72*6823fd46SPrithvi Pai { 73*6823fd46SPrithvi Pai lg2::error("ipmiGetRedfishHostName failed to get HostName from Network " 74*6823fd46SPrithvi Pai "SystemConfig service: {STATUS}", 75*6823fd46SPrithvi Pai "STATUS", ec.message()); 76*6823fd46SPrithvi Pai return ipmi::responseResponseError(); 77*6823fd46SPrithvi Pai } 78*6823fd46SPrithvi Pai ipmi::message::Payload hostNamePayload; 79*6823fd46SPrithvi Pai hostNamePayload.pack( 80*6823fd46SPrithvi Pai std::vector<uint8_t>(hostName.begin(), hostName.end())); 81*6823fd46SPrithvi Pai return ipmi::responseSuccess(hostNamePayload); 82*6823fd46SPrithvi Pai } 83bffaa110SPrithvi Pai } // namespace ipmi 84bffaa110SPrithvi Pai 85bffaa110SPrithvi Pai void registerBootstrapCredentialsOemCommands() 86bffaa110SPrithvi Pai { 87bffaa110SPrithvi Pai ipmi::registerHandler( 88bffaa110SPrithvi Pai ipmi::prioOemBase, ipmi::groupNvidia, 89bffaa110SPrithvi Pai ipmi::bootstrap_credentials_oem::cmdGetUsbVendorIdProductId, 90bffaa110SPrithvi Pai ipmi::Privilege::Admin, ipmi::ipmiGetUsbVendorIdProductId); 916bf35ee6SPrithvi Pai 926bf35ee6SPrithvi Pai ipmi::registerHandler( 936bf35ee6SPrithvi Pai ipmi::prioOemBase, ipmi::groupNvidia, 946bf35ee6SPrithvi Pai ipmi::bootstrap_credentials_oem::cmdGetUsbSerialNumber, 956bf35ee6SPrithvi Pai ipmi::Privilege::Admin, ipmi::ipmiGetUsbSerialNumber); 96*6823fd46SPrithvi Pai 97*6823fd46SPrithvi Pai ipmi::registerHandler( 98*6823fd46SPrithvi Pai ipmi::prioOemBase, ipmi::groupNvidia, 99*6823fd46SPrithvi Pai ipmi::bootstrap_credentials_oem::cmdGetRedfishHostName, 100*6823fd46SPrithvi Pai ipmi::Privilege::Admin, ipmi::ipmiGetRedfishHostName); 101bffaa110SPrithvi Pai } 102