Skip to content

Commit 3525ea0

Browse files
committed
Check boot mode to validate parameter HostNumber
Identify boot mode of the system using an existing dbus service. Boot mode for Single Node [2P-Default] is 0 and it is 1 for Multi-Node [2x1P]. Check the URL for resource bios_active and parameter HostNumber. If the boot mode is Multi-Node [2x1P] and HostNumber is 0, return an error. 0 is not a valid parameter HostNumber value for the resource bios_active on Multi-Node [2x1P] systems. Tested: Verified on Multi-Node [2x1P] and Single Node [2P-Default] systems. Signed-off-by: Shirish Pargaonkar <[email protected]>
1 parent 7a9dfd3 commit 3525ea0

File tree

1 file changed

+73
-31
lines changed

1 file changed

+73
-31
lines changed

redfish-core/lib/update_service.hpp

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,38 +1375,11 @@ inline void
13751375
});
13761376
}
13771377

1378-
inline void handleUpdateServiceFirmwareInventoryGet(
1379-
App& app, const crow::Request& req,
1380-
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1381-
const std::string& param)
1378+
inline void processUpdateServiceFirmwareInventoryGet(
1379+
uint16_t hostNumber,
1380+
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1381+
const std::string& param)
13821382
{
1383-
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1384-
{
1385-
return;
1386-
}
1387-
1388-
boost::urls::url_view urlView = req.url();
1389-
uint16_t hostNumber;
1390-
1391-
for (const auto& parameter : urlView.params())
1392-
{
1393-
if (parameter.key == "HostNumber" && !parameter.value.empty())
1394-
{
1395-
try
1396-
{
1397-
int temp = std::stoi(std::string(parameter.value));
1398-
hostNumber = static_cast<uint16_t>(temp);
1399-
}
1400-
catch (const std::exception& e)
1401-
{
1402-
BMCWEB_LOG_WARNING("Invalid HostNumber format: {}",
1403-
parameter.value);
1404-
hostNumber = 0;
1405-
}
1406-
break;
1407-
}
1408-
}
1409-
14101383
if (hostNumber > 2)
14111384
{
14121385
messages::actionParameterNotSupported(
@@ -1479,6 +1452,75 @@ inline void handleUpdateServiceFirmwareInventoryGet(
14791452
});
14801453
}
14811454

1455+
void getBootMode(
1456+
uint16_t hostNumber,
1457+
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1458+
const std::string& param)
1459+
{
1460+
sdbusplus::asio::getProperty<uint16_t>
1461+
(*crow::connections::systemBus,
1462+
"xyz.openbmc_project.Settings",
1463+
"/xyz/openbmc_project/control/HostMode",
1464+
"xyz.openbmc_project.Control.HostMode",
1465+
"CurrentMode",
1466+
[hostNumber, asyncResp, param](const boost::system::error_code& ec, const uint16_t& bmode) {
1467+
if (ec) {
1468+
BMCWEB_LOG_ERROR("Current boot mode error: {}", ec.message());
1469+
messages::internalError(asyncResp->res);
1470+
return;
1471+
}
1472+
1473+
if (bmode == 1) {
1474+
BMCWEB_LOG_ERROR("Invalid HostNumber {} for the mode {}", hostNumber, bmode);
1475+
messages::actionParameterNotSupported(
1476+
asyncResp->res, std::to_string(hostNumber), "HostNumber");
1477+
return;
1478+
}
1479+
BMCWEB_LOG_DEBUG("boot mode: {}", bmode);
1480+
processUpdateServiceFirmwareInventoryGet(hostNumber, asyncResp, param);
1481+
}
1482+
);
1483+
}
1484+
1485+
inline void handleUpdateServiceFirmwareInventoryGet(
1486+
App& app, const crow::Request& req,
1487+
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1488+
const std::string& param)
1489+
{
1490+
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1491+
{
1492+
return;
1493+
}
1494+
1495+
boost::urls::url_view urlView = req.url();
1496+
uint16_t hostNumber = 0;
1497+
1498+
for (const auto& parameter : urlView.params()) {
1499+
if (parameter.key == "HostNumber") {
1500+
if (!parameter.value.empty()) {
1501+
try {
1502+
int temp = std::stoi(std::string(parameter.value));
1503+
hostNumber = static_cast<uint16_t>(temp);
1504+
if (hostNumber == 0)
1505+
getBootMode(hostNumber, asyncResp, param);
1506+
}
1507+
catch (const std::exception& e) {
1508+
BMCWEB_LOG_ERROR("Invalid HostNumber format: {}", parameter.value);
1509+
messages::actionParameterValueFormatError(
1510+
asyncResp->res, parameter.value, "HostNumber", "");
1511+
return;
1512+
}
1513+
} else {
1514+
BMCWEB_LOG_ERROR("Missing HostNumber");
1515+
messages::actionParameterMissing(asyncResp->res, "HostNumber", "");
1516+
return;
1517+
}
1518+
}
1519+
}
1520+
1521+
processUpdateServiceFirmwareInventoryGet(hostNumber, asyncResp, param);
1522+
}
1523+
14821524
inline void requestRoutesUpdateService(App& app)
14831525
{
14841526
BMCWEB_ROUTE(

0 commit comments

Comments
 (0)