blob: eb5a57881266618f38ca88879c5556cfdf614159 [file] [log] [blame]
mohaimen.alsamarai@fii-na.corp-partner.google.com163226e2021-04-16 13:54:15 -05001/********************************************************************************
2* HON HAI Precision IND.Co., LTD. *
3* Personal Computer & Enterprise Product Business Group *
4* Enterprise Product Business Gro:qup *
5* *
6* Copyright (c) 2010 by FOXCONN/CESBG/CABG/SRD. All rights reserved. *
7* All data and information contained in this document is confidential *
8* and proprietary information of FOXCONN/CESBG/CABG/SRD and all rights *
9* are reserved. By accepting this material the recipient agrees that *
10* the information contained therein is held in confidence and in trust *
11* and will not be used, copied, reproduced in whole or in part, nor its *
12* contents revealed in any manner to others without the express written *
13* permission of FOXCONN/CESBG/CABG/SRD. *
14* *
15********************************************************************************/
16
17#include <common.hpp>
18#include <systemcommands.hpp>
19
20#include <stdio.h>
21
22namespace ipmi
23{
24static void registerSystemFunctions() __attribute__((constructor));
25
26ipmi::RspType<std::vector<uint8_t>> FiiSysPCIeInfo(boost::asio::yield_context yield)
27{
28 std::vector<uint8_t> rsp;
29 char buffer[128], *token;
30 uint32_t value;
31 FILE *pipe = popen(PCIEINFO_COMMAND, "r");
32
33 // Read pcie bifurcation information
34 // it return two bytes, 1st byte bifurcation, 2nd byte present pin
35 if (!pipe) throw std::runtime_error("popen() failed !!!");
36 while (fgets(buffer, sizeof(buffer), pipe) != NULL)
37 {
38 std::cerr << " Command : " << buffer << std::endl;
39 }
40 pclose(pipe);
41
42 token = std::strtok(buffer, " ");
43 if (token == NULL)
44 {
45 phosphor::logging::log<phosphor::logging::level::ERR>(
46 "Fii system cmd : Error geting PCIe Info came back null");
47 ipmi::responseUnspecifiedError();
48 }
49 token = std::strtok(NULL, " ");
50 while (token != NULL)
51 {
52 //std::cerr << " Command token: " << token << std::endl;
53 value = std::stoul(token, nullptr, 16);
54 //std::cerr << " Command value: " << value << ":" << std::hex << value << std::endl;
55 rsp.push_back(static_cast<uint8_t>(value & 0xFF));
56 token = std::strtok(NULL, " ");
57 }
58
59 return ipmi::responseSuccess(rsp);
60}
61
62void registerSystemFunctions()
63{
64 std::fprintf(stderr, "Registering OEM:[0x34], Cmd:[%#04X] for Fii System OEM Commands\n", FII_CMD_SYS_PCIE_INFO);
65 ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemThree, FII_CMD_SYS_PCIE_INFO, ipmi::Privilege::User,
66 FiiSysPCIeInfo);
67
68 return;
69}
70}