mohaimen.alsamarai@fii-na.corp-partner.google.com | 163226e | 2021-04-16 13:54:15 -0500 | [diff] [blame^] | 1 | /******************************************************************************** |
| 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 | |
| 20 | namespace 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 | return ipmi::responseReqDataLenInvalid(); |
| 34 | } |
| 35 | |
| 36 | op = reqParams[0] & 0b11; |
| 37 | // check the boot count file exist or not |
| 38 | std::fstream fptr(BOOT_COUNT_FILE); |
| 39 | |
| 40 | if (!fptr.is_open()) |
| 41 | { |
| 42 | std::cerr << " Fii bios cmd : file didn't exist and try to create one\n"; |
| 43 | ret = system("mkdir -p /etc/conf"); |
| 44 | std::ofstream outfile (BOOT_COUNT_FILE); |
| 45 | outfile << "0" << std::endl; |
| 46 | outfile.close(); |
| 47 | boot_count.push_back(static_cast<uint8_t>(counter)); |
| 48 | boot_count.push_back(static_cast<uint8_t>(counter >> 8)); |
| 49 | boot_count.push_back(static_cast<uint8_t>(counter >> 16)); |
| 50 | boot_count.push_back(static_cast<uint8_t>(counter >> 24)); |
| 51 | return ipmi::responseSuccess(boot_count); |
| 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 | boot_count[0] += 1; |
| 78 | value = boot_count[0] + (boot_count[1] << 8) + (boot_count[2] << 16) + (boot_count[3] << 24); |
| 79 | } |
| 80 | else if (reqParams.size() == FII_CMD_BIOS_BOOT_COUNT_LEN) |
| 81 | { |
| 82 | value = reqParams[1] + + (reqParams[2] << 8) + (reqParams[3] << 16) + (reqParams[4] << 24); |
| 83 | boot_count.clear(); |
| 84 | boot_count.insert(boot_count.begin(), reqParams.begin()+1, reqParams.end()); |
| 85 | } |
| 86 | std::ofstream fptr_w(BOOT_COUNT_FILE, std::ios::out | std::ios::trunc); |
| 87 | fptr_w << value << std::endl; |
| 88 | fptr_w.close(); |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | return ipmi::responseInvalidCommand(); |
| 93 | } |
| 94 | return ipmi::responseSuccess(boot_count); |
| 95 | } |
| 96 | |
| 97 | void registerBIOSFunctions() |
| 98 | { |
| 99 | std::fprintf(stderr, "Registering OEM:[0x34], Cmd:[%#04X] for Fii BIOS OEM Commands\n", FII_CMD_BIOS_BOOT_COUNT); |
| 100 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemThree, FII_CMD_BIOS_BOOT_COUNT, ipmi::Privilege::User, |
| 101 | FiiBIOSBootCount); |
| 102 | |
| 103 | return; |
| 104 | } |
| 105 | } |