Kumar Thangavel | 41ad4ff | 2020-06-11 10:31:07 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 Intel Corporation. |
| 3 | * Copyright (c) 2018-present Facebook. |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <ipmid/api.hpp> |
| 19 | #include <ipmid/api-types.hpp> |
| 20 | |
| 21 | #include <commandutils.hpp> |
| 22 | #include <biccommands.hpp> |
| 23 | #include <phosphor-logging/log.hpp> |
| 24 | |
| 25 | #include <vector> |
| 26 | #include <iostream> |
| 27 | |
| 28 | namespace ipmi |
| 29 | { |
| 30 | |
| 31 | using namespace phosphor::logging; |
| 32 | |
| 33 | static void registerBICFunctions() __attribute__((constructor)); |
| 34 | |
| 35 | extern message::Response::ptr executeIpmiCommand(message::Request::ptr); |
| 36 | |
| 37 | //---------------------------------------------------------------------- |
| 38 | // ipmiOemBicHandler (IPMI/Section - ) (CMD_OEM_BIC_INFO) |
| 39 | // This Function will handle BIC request for netfn=0x38 and cmd=1 |
| 40 | // send the response back to the sender. |
| 41 | //---------------------------------------------------------------------- |
| 42 | |
| 43 | ipmi::RspType<std::array<uint8_t, 3>, uint8_t, uint2_t, uint6_t, uint8_t, |
| 44 | uint8_t, ipmi::message::Payload> |
| 45 | ipmiOemBicHandler(ipmi::Context::ptr ctx, std::array<uint8_t, 3> iana, |
| 46 | uint8_t interface, uint2_t lun, uint6_t netFnReq, |
| 47 | uint8_t cmdReq, std::vector<uint8_t> data) |
| 48 | { |
| 49 | |
| 50 | ipmi::message::Response::ptr res; |
| 51 | |
| 52 | // Updating the correct netfn and cmd in the ipmi Context |
| 53 | ctx->netFn = ((uint8_t)netFnReq); |
| 54 | ctx->cmd = cmdReq; |
| 55 | |
| 56 | // creating ipmi message request for calling executeIpmiCommand function |
| 57 | auto req = std::make_shared<ipmi::message::Request>( |
| 58 | ctx, std::forward<std::vector<uint8_t>>(data)); |
| 59 | |
| 60 | // Calling executeIpmiCommand request function |
| 61 | res = ipmi::executeIpmiCommand(req); |
| 62 | |
| 63 | // sending the response with headers and payload |
| 64 | return ipmi::responseSuccess(iana, interface, lun, ++netFnReq, cmdReq, |
| 65 | res->cc, res->payload); |
| 66 | } |
| 67 | |
| 68 | static void registerBICFunctions(void) |
| 69 | { |
| 70 | |
| 71 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 72 | "Registering BIC commands"); |
| 73 | |
| 74 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFive, |
| 75 | cmdOemBicInfo, ipmi::Privilege::User, |
| 76 | ipmiOemBicHandler); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | } // namespace ipmi |