blob: 1dc907da723fe8d0f37e31f2b2930f1a31a9d9d7 [file] [log] [blame]
Kumar Thangavel41ad4ff2020-06-11 10:31:07 +05301/*
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>
Kumar Thangavelad049242020-08-31 22:27:33 +053026#include <variant>
Kumar Thangavel41ad4ff2020-06-11 10:31:07 +053027#include <iostream>
28
29namespace ipmi
30{
31
32using namespace phosphor::logging;
33
34static void registerBICFunctions() __attribute__((constructor));
35
36extern message::Response::ptr executeIpmiCommand(message::Request::ptr);
37
38//----------------------------------------------------------------------
39// ipmiOemBicHandler (IPMI/Section - ) (CMD_OEM_BIC_INFO)
40// This Function will handle BIC request for netfn=0x38 and cmd=1
41// send the response back to the sender.
42//----------------------------------------------------------------------
43
44ipmi::RspType<std::array<uint8_t, 3>, uint8_t, uint2_t, uint6_t, uint8_t,
45 uint8_t, ipmi::message::Payload>
46 ipmiOemBicHandler(ipmi::Context::ptr ctx, std::array<uint8_t, 3> iana,
47 uint8_t interface, uint2_t lun, uint6_t netFnReq,
48 uint8_t cmdReq, std::vector<uint8_t> data)
49{
50
51 ipmi::message::Response::ptr res;
52
53 // Updating the correct netfn and cmd in the ipmi Context
54 ctx->netFn = ((uint8_t)netFnReq);
55 ctx->cmd = cmdReq;
56
57 // creating ipmi message request for calling executeIpmiCommand function
58 auto req = std::make_shared<ipmi::message::Request>(
59 ctx, std::forward<std::vector<uint8_t>>(data));
60
61 // Calling executeIpmiCommand request function
62 res = ipmi::executeIpmiCommand(req);
63
64 // sending the response with headers and payload
65 return ipmi::responseSuccess(iana, interface, lun, ++netFnReq, cmdReq,
66 res->cc, res->payload);
67}
68
Kumar Thangavelad049242020-08-31 22:27:33 +053069//----------------------------------------------------------------------
70// ipmiOemPostCodeHandler (CMD_OEM_BIC_POST_BUFFER_INFO)
71// This Function will handle BIC incomming postcode from multi-host for
72// netfn=0x38 and cmd=0x08 send the response back to the sender.
73//----------------------------------------------------------------------
74
75ipmi::RspType<std::array<uint8_t, 3>, uint8_t>
76 ipmiOemPostCodeHandler(ipmi::Context::ptr ctx, std::array<uint8_t, 3> iana,
77 uint8_t interface, uint8_t data)
78{
79 // creating bus connection
80 auto conn = getSdBus();
81
82 try
83 {
84 // storing post code as varaint
85 std::variant<uint64_t> postCode = static_cast<uint64_t>(data);
86
87 // creating dbus objects for 1 to N process
88 std::string dbusObjStr = dbusObj + std::to_string((ctx->hostIdx + 1));
89
90 // creating method call to update postd value
91 auto method = conn->new_method_call(
92 "xyz.openbmc_project.State.Boot.Raw", dbusObjStr.c_str(),
93 "org.freedesktop.DBus.Properties", "Set");
94
95 // Adding paramters to method call
96 method.append(dbusService, "Value", postCode);
97
98 // Invoke method call function
99 auto reply = conn->call(method);
100
101 // sending the success response with headers
102 return ipmi::responseSuccess(iana, interface);
103 }
104 catch (std::exception& e)
105 {
106 phosphor::logging::log<phosphor::logging::level::ERR>(
107 "post code handler error\n");
108
109 // sending the Error response
110 return ipmi::responseResponseError();
111 }
112}
113
Kumar Thangavel41ad4ff2020-06-11 10:31:07 +0530114static void registerBICFunctions(void)
115{
116
117 phosphor::logging::log<phosphor::logging::level::INFO>(
118 "Registering BIC commands");
119
120 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFive,
121 cmdOemBicInfo, ipmi::Privilege::User,
122 ipmiOemBicHandler);
Kumar Thangavelad049242020-08-31 22:27:33 +0530123 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFive,
124 cmdOemSendPostBufferToBMC, ipmi::Privilege::User,
125 ipmiOemPostCodeHandler);
Kumar Thangavel41ad4ff2020-06-11 10:31:07 +0530126 return;
127}
128
129} // namespace ipmi