blob: 71fc2aea8b45e8adfc38097c5c4bb6dd0b25e5e1 [file] [log] [blame]
Mohaimen Alsamarai35c1ac42021-04-20 13:16:42 -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 <bioscommands.hpp>
19
20namespace ipmi
21{
22 static void registerBIOSFunctions() __attribute__((constructor));
23
24 ipmi::RspType<std::vector<uint8_t>> FiiBIOSBootCount(boost::asio::yield_context yield, std::vector<uint8_t> reqParams)
25 {
26 bool op;
27 std::vector<uint8_t> boot_count;
28 uint32_t counter = 0, ret;
29
30 if (reqParams.empty())
31 {
32 phosphor::logging::log<phosphor::logging::level::ERR>(" Fii bios cmd : command format error.");
33
34 return ipmi::responseReqDataLenInvalid();
35 }
36
37 op = reqParams[0] & 0b11;
38 // check the boot count file exist or not
39 std::fstream fptr(BOOT_COUNT_FILE);
40
41 if (!fptr.is_open())
42 {
43 std::cerr << " Fii bios cmd : file didn't exist and try to create one\n";
44 ret = system("mkdir -p /etc/conf");
45 std::ofstream outfile (BOOT_COUNT_FILE);
46 outfile << "0" << std::endl;
47 outfile.close();
48 boot_count.push_back(static_cast<uint8_t>(counter));
49 boot_count.push_back(static_cast<uint8_t>(counter >> 8));
50 boot_count.push_back(static_cast<uint8_t>(counter >> 16));
51 boot_count.push_back(static_cast<uint8_t>(counter >> 24));
52 }
53 else
54 {
55 std::string str;
56 while (std::getline(fptr, str))
57 {
58 //boot_count.push_back(static_cast<uint8_t>(std::stoul(str)));
59 counter = (std::stoul(str));
60 //std::cerr << " Fii bios cmd : " << counter << std::endl;
61 }
62 boot_count.push_back(static_cast<uint8_t>(counter));
63 boot_count.push_back(static_cast<uint8_t>(counter >> 8));
64 boot_count.push_back(static_cast<uint8_t>(counter >> 16));
65 boot_count.push_back(static_cast<uint8_t>(counter >> 24));
66 fptr.close();
67 }
68 if (op == OP_CODE_READ)
69 {
70 return ipmi::responseSuccess(boot_count);
71 }
72 else if (op == OP_CODE_WRITE)
73 {
74 uint32_t value = 0;
75 if (reqParams.size() == 1)
76 {
77 value = boot_count[0] + (boot_count[1] << 8) + (boot_count[2] << 16) + (boot_count[3] << 24);
78 value += 1;
79 boot_count.clear();
80 boot_count.push_back(static_cast<uint8_t>(value));
81 boot_count.push_back(static_cast<uint8_t>(value >> 8));
82 boot_count.push_back(static_cast<uint8_t>(value >> 16));
83 boot_count.push_back(static_cast<uint8_t>(value >> 24));
84 }
85 else if (reqParams.size() == FII_CMD_BIOS_BOOT_COUNT_LEN)
86 {
87 value = reqParams[1] + + (reqParams[2] << 8) + (reqParams[3] << 16) + (reqParams[4] << 24);
88 boot_count.clear();
89 boot_count.insert(boot_count.begin(), reqParams.begin()+1, reqParams.end());
90 }
91 std::ofstream fptr_w(BOOT_COUNT_FILE, std::ios::out | std::ios::trunc);
92 fptr_w << value << std::endl;
93 fptr_w.close();
94 }
95 else
96 {
97 return ipmi::responseInvalidCommand();
98 }
99 return ipmi::responseSuccess(boot_count);
100 }
101
102 void registerBIOSFunctions()
103 {
104 std::fprintf(stderr, "Registering OEM:[0x34], Cmd:[%#04X] for Fii BIOS OEM Commands\n", FII_CMD_BIOS_BOOT_COUNT);
105 ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemThree, FII_CMD_BIOS_BOOT_COUNT, ipmi::Privilege::User,
106 FiiBIOSBootCount);
107
108 return;
109 }
110}