Add Fii oem command
Signed-off-by: mohaimen alsamarai <mohaimen.alsamarai@fii-na.com>
Change-Id: I1b9113367f71d9484688b3d7fe4a923007fe31e2
diff --git a/src/systemcommands.cpp b/src/systemcommands.cpp
new file mode 100644
index 0000000..eb5a578
--- /dev/null
+++ b/src/systemcommands.cpp
@@ -0,0 +1,70 @@
+/********************************************************************************
+* HON HAI Precision IND.Co., LTD. *
+* Personal Computer & Enterprise Product Business Group *
+* Enterprise Product Business Gro:qup *
+* *
+* Copyright (c) 2010 by FOXCONN/CESBG/CABG/SRD. All rights reserved. *
+* All data and information contained in this document is confidential *
+* and proprietary information of FOXCONN/CESBG/CABG/SRD and all rights *
+* are reserved. By accepting this material the recipient agrees that *
+* the information contained therein is held in confidence and in trust *
+* and will not be used, copied, reproduced in whole or in part, nor its *
+* contents revealed in any manner to others without the express written *
+* permission of FOXCONN/CESBG/CABG/SRD. *
+* *
+********************************************************************************/
+
+#include <common.hpp>
+#include <systemcommands.hpp>
+
+#include <stdio.h>
+
+namespace ipmi
+{
+static void registerSystemFunctions() __attribute__((constructor));
+
+ipmi::RspType<std::vector<uint8_t>> FiiSysPCIeInfo(boost::asio::yield_context yield)
+{
+ std::vector<uint8_t> rsp;
+ char buffer[128], *token;
+ uint32_t value;
+ FILE *pipe = popen(PCIEINFO_COMMAND, "r");
+
+ // Read pcie bifurcation information
+ // it return two bytes, 1st byte bifurcation, 2nd byte present pin
+ if (!pipe) throw std::runtime_error("popen() failed !!!");
+ while (fgets(buffer, sizeof(buffer), pipe) != NULL)
+ {
+ std::cerr << " Command : " << buffer << std::endl;
+ }
+ pclose(pipe);
+
+ token = std::strtok(buffer, " ");
+ if (token == NULL)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Fii system cmd : Error geting PCIe Info came back null");
+ ipmi::responseUnspecifiedError();
+ }
+ token = std::strtok(NULL, " ");
+ while (token != NULL)
+ {
+ //std::cerr << " Command token: " << token << std::endl;
+ value = std::stoul(token, nullptr, 16);
+ //std::cerr << " Command value: " << value << ":" << std::hex << value << std::endl;
+ rsp.push_back(static_cast<uint8_t>(value & 0xFF));
+ token = std::strtok(NULL, " ");
+ }
+
+ return ipmi::responseSuccess(rsp);
+}
+
+void registerSystemFunctions()
+{
+ std::fprintf(stderr, "Registering OEM:[0x34], Cmd:[%#04X] for Fii System OEM Commands\n", FII_CMD_SYS_PCIE_INFO);
+ ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemThree, FII_CMD_SYS_PCIE_INFO, ipmi::Privilege::User,
+ FiiSysPCIeInfo);
+
+ return;
+}
+}