oemcommands.cpp (4ae63e71c53db34cff1648100a6fe4559c1b7132) | oemcommands.cpp (2405ae98b39a97e9d7753d8dc5c673a4a8885b85) |
---|---|
1/* 2 * Copyright (c) 2018 Intel Corporation. 3 * Copyright (c) 2018-present Facebook. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18#include "xyz/openbmc_project/Common/error.hpp" | 1/* 2 * Copyright (c) 2018 Intel Corporation. 3 * Copyright (c) 2018-present Facebook. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18#include "xyz/openbmc_project/Common/error.hpp" |
19#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp> 20#include <xyz/openbmc_project/Control/Boot/Source/server.hpp> 21#include <xyz/openbmc_project/Control/Boot/Type/server.hpp> | |
22 | 19 |
20#include <commandutils.hpp> 21#include <ipmid/api-types.hpp> |
|
23#include <ipmid/api.hpp> 24#include <ipmid/utils.hpp> | 22#include <ipmid/api.hpp> 23#include <ipmid/utils.hpp> |
25#include <commandutils.hpp> | |
26#include <nlohmann/json.hpp> 27#include <oemcommands.hpp> 28#include <phosphor-logging/log.hpp> 29#include <sdbusplus/bus.hpp> | 24#include <nlohmann/json.hpp> 25#include <oemcommands.hpp> 26#include <phosphor-logging/log.hpp> 27#include <sdbusplus/bus.hpp> |
28#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp> 29#include <xyz/openbmc_project/Control/Boot/Source/server.hpp> 30#include <xyz/openbmc_project/Control/Boot/Type/server.hpp> |
|
30 | 31 |
31#include <ipmid/api.hpp> 32#include <ipmid/api-types.hpp> 33 | |
34#include <array> 35#include <cstring> 36#include <fstream> 37#include <iomanip> 38#include <iostream> | 32#include <array> 33#include <cstring> 34#include <fstream> 35#include <iomanip> 36#include <iostream> |
37#include <regex> |
|
39#include <sstream> 40#include <string> 41#include <vector> | 38#include <sstream> 39#include <string> 40#include <vector> |
42#include <regex> | |
43 44#define SIZE_IANA_ID 3 45 46namespace ipmi 47{ 48 49using namespace phosphor::logging; 50 --- 74 unchanged lines hidden (view full) --- 125 log<level::ERR>("No Object has implemented the IP interface", 126 entry("INTERFACE=%s", interface.c_str())); 127 } 128 129 DbusObjectInfo objectInfo; 130 131 for (auto& object : objectTree) 132 { | 41 42#define SIZE_IANA_ID 3 43 44namespace ipmi 45{ 46 47using namespace phosphor::logging; 48 --- 74 unchanged lines hidden (view full) --- 123 log<level::ERR>("No Object has implemented the IP interface", 124 entry("INTERFACE=%s", interface.c_str())); 125 } 126 127 DbusObjectInfo objectInfo; 128 129 for (auto& object : objectTree) 130 { |
133 auto variant = 134 ipmi::getDbusProperty(bus, object.second.begin()->first, 135 object.first, IP_INTERFACE, "Type"); | 131 auto variant = ipmi::getDbusProperty(bus, object.second.begin()->first, 132 object.first, IP_INTERFACE, 133 "Type"); |
136 if (std::get<std::string>(variant) != protocol) 137 { 138 continue; 139 } 140 141 variant = ipmi::getDbusProperty(bus, object.second.begin()->first, 142 object.first, IP_INTERFACE, "Address"); 143 --- 57 unchanged lines hidden (view full) --- 201static constexpr auto bootSourceProp = "BootSource"; 202static constexpr auto bootModeProp = "BootMode"; 203static constexpr auto bootTypeProp = "BootType"; 204static constexpr auto bootEnableProp = "Enabled"; 205 206std::tuple<std::string, std::string> objPath(size_t id) 207{ 208 std::string hostName = "host" + std::to_string(id); | 134 if (std::get<std::string>(variant) != protocol) 135 { 136 continue; 137 } 138 139 variant = ipmi::getDbusProperty(bus, object.second.begin()->first, 140 object.first, IP_INTERFACE, "Address"); 141 --- 57 unchanged lines hidden (view full) --- 199static constexpr auto bootSourceProp = "BootSource"; 200static constexpr auto bootModeProp = "BootMode"; 201static constexpr auto bootTypeProp = "BootType"; 202static constexpr auto bootEnableProp = "Enabled"; 203 204std::tuple<std::string, std::string> objPath(size_t id) 205{ 206 std::string hostName = "host" + std::to_string(id); |
209 std::string bootObjPath = 210 "/xyz/openbmc_project/control/" + hostName + "/boot"; | 207 std::string bootObjPath = "/xyz/openbmc_project/control/" + hostName + 208 "/boot"; |
211 return std::make_tuple(std::move(bootObjPath), std::move(hostName)); 212} 213 214} // namespace boot 215 216//---------------------------------------------------------------------- 217// Helper functions for storing oem data 218//---------------------------------------------------------------------- --- 617 unchanged lines hidden (view full) --- 836 224; // The length must be lower than IPMB limitation 837 size_t startIndex = 0; 838 839 std::vector<std::tuple<uint64_t, std::vector<uint8_t>>> postCodes; 840 std::vector<uint8_t> resData; 841 842 auto conn = getSdBus(); 843 /* Get the post codes by calling GetPostCodes method */ | 209 return std::make_tuple(std::move(bootObjPath), std::move(hostName)); 210} 211 212} // namespace boot 213 214//---------------------------------------------------------------------- 215// Helper functions for storing oem data 216//---------------------------------------------------------------------- --- 617 unchanged lines hidden (view full) --- 834 224; // The length must be lower than IPMB limitation 835 size_t startIndex = 0; 836 837 std::vector<std::tuple<uint64_t, std::vector<uint8_t>>> postCodes; 838 std::vector<uint8_t> resData; 839 840 auto conn = getSdBus(); 841 /* Get the post codes by calling GetPostCodes method */ |
844 auto msg = 845 conn->new_method_call(postCodeService.c_str(), postCodeObjPath.c_str(), 846 postCodeInterface, "GetPostCodes"); | 842 auto msg = conn->new_method_call(postCodeService.c_str(), 843 postCodeObjPath.c_str(), postCodeInterface, 844 "GetPostCodes"); |
847 msg.append(lastestPostCodeIndex); 848 849 try 850 { 851 auto reply = conn->call(msg); 852 reply.read(postCodes); 853 } 854 catch (const sdbusplus::exception::SdBusError& e) --- 35 unchanged lines hidden (view full) --- 890 891 // SETTING BOOT MODE PROPERTY 892 uint8_t bootModeBit = data[0] & 0x04; 893 auto bootValue = ipmi::boot::modeIpmiToDbus.at(bootModeBit); 894 895 std::string bootOption = 896 sdbusplus::message::convert_to_string<boot::BootMode>(bootValue); 897 | 845 msg.append(lastestPostCodeIndex); 846 847 try 848 { 849 auto reply = conn->call(msg); 850 reply.read(postCodes); 851 } 852 catch (const sdbusplus::exception::SdBusError& e) --- 35 unchanged lines hidden (view full) --- 888 889 // SETTING BOOT MODE PROPERTY 890 uint8_t bootModeBit = data[0] & 0x04; 891 auto bootValue = ipmi::boot::modeIpmiToDbus.at(bootModeBit); 892 893 std::string bootOption = 894 sdbusplus::message::convert_to_string<boot::BootMode>(bootValue); 895 |
898 std::string service = 899 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath); | 896 std::string service = getService(*dbus, ipmi::boot::bootModeIntf, 897 bootObjPath); |
900 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf, 901 ipmi::boot::bootModeProp, bootOption); 902 903 // SETTING BOOT SOURCE PROPERTY 904 auto bootOrder = ipmi::boot::sourceIpmiToDbus.at(data[1]); 905 std::string bootSource = 906 sdbusplus::message::convert_to_string<boot::BootSource>(bootOrder); 907 --- 44 unchanged lines hidden (view full) --- 952} 953 954//---------------------------------------------------------------------- 955// Set Boot Order (CMD_OEM_SET_BOOT_ORDER) 956//---------------------------------------------------------------------- 957ipmi::RspType<std::vector<uint8_t>> 958 ipmiOemSetBootOrder(ipmi::Context::ptr ctx, std::vector<uint8_t> data) 959{ | 898 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf, 899 ipmi::boot::bootModeProp, bootOption); 900 901 // SETTING BOOT SOURCE PROPERTY 902 auto bootOrder = ipmi::boot::sourceIpmiToDbus.at(data[1]); 903 std::string bootSource = 904 sdbusplus::message::convert_to_string<boot::BootSource>(bootOrder); 905 --- 44 unchanged lines hidden (view full) --- 950} 951 952//---------------------------------------------------------------------- 953// Set Boot Order (CMD_OEM_SET_BOOT_ORDER) 954//---------------------------------------------------------------------- 955ipmi::RspType<std::vector<uint8_t>> 956 ipmiOemSetBootOrder(ipmi::Context::ptr ctx, std::vector<uint8_t> data) 957{ |
960 | |
961 uint8_t bootSeq[SIZE_BOOT_ORDER]; 962 size_t len = data.size(); 963 964 if (len != SIZE_BOOT_ORDER) 965 { 966 phosphor::logging::log<phosphor::logging::level::ERR>( 967 "Invalid Boot order length received"); 968 return ipmi::responseReqDataLenInvalid(); --- 33 unchanged lines hidden (view full) --- 1002 return ipmi::responseInvalidCommand(); 1003 } 1004 auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId); 1005 1006 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); 1007 1008 // GETTING PROPERTY OF MODE INTERFACE 1009 | 958 uint8_t bootSeq[SIZE_BOOT_ORDER]; 959 size_t len = data.size(); 960 961 if (len != SIZE_BOOT_ORDER) 962 { 963 phosphor::logging::log<phosphor::logging::level::ERR>( 964 "Invalid Boot order length received"); 965 return ipmi::responseReqDataLenInvalid(); --- 33 unchanged lines hidden (view full) --- 999 return ipmi::responseInvalidCommand(); 1000 } 1001 auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId); 1002 1003 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); 1004 1005 // GETTING PROPERTY OF MODE INTERFACE 1006 |
1010 std::string service = 1011 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath); 1012 Value variant = 1013 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf, 1014 ipmi::boot::bootModeProp); | 1007 std::string service = getService(*dbus, ipmi::boot::bootModeIntf, 1008 bootObjPath); 1009 Value variant = getDbusProperty(*dbus, service, bootObjPath, 1010 ipmi::boot::bootModeIntf, 1011 ipmi::boot::bootModeProp); |
1015 1016 auto bootMode = sdbusplus::message::convert_from_string<boot::BootMode>( 1017 std::get<std::string>(variant)); 1018 1019 uint8_t bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode); 1020 1021 // GETTING PROPERTY OF TYPE INTERFACE 1022 1023 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath); | 1012 1013 auto bootMode = sdbusplus::message::convert_from_string<boot::BootMode>( 1014 std::get<std::string>(variant)); 1015 1016 uint8_t bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode); 1017 1018 // GETTING PROPERTY OF TYPE INTERFACE 1019 1020 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath); |
1024 variant = 1025 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf, 1026 ipmi::boot::bootTypeProp); | 1021 variant = getDbusProperty(*dbus, service, bootObjPath, 1022 ipmi::boot::bootTypeIntf, 1023 ipmi::boot::bootTypeProp); |
1027 1028 auto bootType = sdbusplus::message::convert_from_string<boot::BootType>( 1029 std::get<std::string>(variant)); 1030 1031 // Get the valid bit from boot enabled property 1032 service = getService(*dbus, ipmi::boot::bootEnableIntf, bootObjPath); | 1024 1025 auto bootType = sdbusplus::message::convert_from_string<boot::BootType>( 1026 std::get<std::string>(variant)); 1027 1028 // Get the valid bit from boot enabled property 1029 service = getService(*dbus, ipmi::boot::bootEnableIntf, bootObjPath); |
1033 variant = 1034 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootEnableIntf, 1035 ipmi::boot::bootEnableProp); | 1030 variant = getDbusProperty(*dbus, service, bootObjPath, 1031 ipmi::boot::bootEnableIntf, 1032 ipmi::boot::bootEnableProp); |
1036 1037 bool validFlag = std::get<bool>(variant); 1038 1039 uint8_t bootTypeVal = ipmi::boot::typeDbusToIpmi.at(bootType); 1040 1041 uint8_t bootVal = bootOption | bootTypeVal; 1042 1043 if (validFlag) --- 248 unchanged lines hidden (view full) --- 1292#if BIC_ENABLED 1293ipmi::RspType<> ipmiOemSetSystemGuid(ipmi::Context::ptr ctx, 1294 std::vector<uint8_t> reqData) 1295{ 1296 std::vector<uint8_t> respData; 1297 1298 if (reqData.size() != GUID_SIZE) // 16bytes 1299 { | 1033 1034 bool validFlag = std::get<bool>(variant); 1035 1036 uint8_t bootTypeVal = ipmi::boot::typeDbusToIpmi.at(bootType); 1037 1038 uint8_t bootVal = bootOption | bootTypeVal; 1039 1040 if (validFlag) --- 248 unchanged lines hidden (view full) --- 1289#if BIC_ENABLED 1290ipmi::RspType<> ipmiOemSetSystemGuid(ipmi::Context::ptr ctx, 1291 std::vector<uint8_t> reqData) 1292{ 1293 std::vector<uint8_t> respData; 1294 1295 if (reqData.size() != GUID_SIZE) // 16bytes 1296 { |
1300 | |
1301 return ipmi::responseReqDataLenInvalid(); 1302 } 1303 1304 uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2; 1305 1306 if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData)) 1307 return ipmi::responseUnspecifiedError(); 1308 --- 904 unchanged lines hidden --- | 1297 return ipmi::responseReqDataLenInvalid(); 1298 } 1299 1300 uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2; 1301 1302 if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData)) 1303 return ipmi::responseUnspecifiedError(); 1304 --- 904 unchanged lines hidden --- |