/* // Copyright (c) 2019 Intel Corporation // // 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 #include #include #include #include #include #include #include namespace ipmi { void registerMultiNodeFunctions() __attribute__((constructor)); std::optional getMultiNodeInfo(std::string name) { auto pdbus = getSdBus(); try { std::string service = getService(*pdbus, multiNodeIntf, multiNodeObjPath); Value dbusValue = getDbusProperty(*pdbus, service, multiNodeObjPath, multiNodeIntf, name); return std::get(dbusValue); } catch (const std::exception& e) { phosphor::logging::log( "getMultiNodeInfo: can't get multi node info from dbus!", phosphor::logging::entry("ERR=%s", e.what())); return std::nullopt; } } std::optional getMultiNodeRole() { auto pdbus = getSdBus(); try { std::string service = getService(*pdbus, multiNodeIntf, multiNodeObjPath); Value dbusValue = getDbusProperty(*pdbus, service, multiNodeObjPath, multiNodeIntf, "NodeRole"); std::string valueStr = std::get(dbusValue); uint8_t value; if (valueStr == "single") value = static_cast(NodeRole::single); else if (valueStr == "master") value = static_cast(NodeRole::master); else if (valueStr == "slave") value = static_cast(NodeRole::slave); else if (valueStr == "arbitrating") value = static_cast(NodeRole::arbitrating); return value; } catch (const std::exception& e) { phosphor::logging::log( "getMultiNodeRole: can't get multi node role from dbus!", phosphor::logging::entry("ERR=%s", e.what())); return std::nullopt; } } ipmi::RspType ipmiGetMultiNodePresence() { std::optional nodeInfo = getMultiNodeInfo("NodePresence"); if (!nodeInfo) { return ipmi::responseResponseError(); } return ipmi::responseSuccess(*nodeInfo); } ipmi::RspType ipmiGetMultiNodeId() { std::optional nodeInfo = getMultiNodeInfo("NodeId"); if (!nodeInfo) { return ipmi::responseResponseError(); } return ipmi::responseSuccess(*nodeInfo); } ipmi::RspType ipmiGetMultiNodeRole() { std::optional nodeInfo = getMultiNodeRole(); if (!nodeInfo) { return ipmi::responseResponseError(); } return ipmi::responseSuccess(*nodeInfo); } void registerMultiNodeFunctions(void) { phosphor::logging::log( "Registering MultiNode commands"); ipmi::registerHandler( ipmi::prioOemBase, ipmi::netFnOemOne, static_cast(IPMINetfnMultiNodeCmd::cmdGetMultiNodePresence), ipmi::Privilege::User, ipmiGetMultiNodePresence); ipmi::registerHandler( ipmi::prioOemBase, ipmi::netFnOemOne, static_cast(IPMINetfnMultiNodeCmd::cmdGetMultiNodeId), ipmi::Privilege::User, ipmiGetMultiNodeId); ipmi::registerHandler( ipmi::prioOemBase, ipmi::netFnOemOne, static_cast(IPMINetfnMultiNodeCmd::cmdGetMultiNodeRole), ipmi::Privilege::User, ipmiGetMultiNodeRole); } } // namespace ipmi