blob: 3b45da09c3e4f894a525649d010886dba5a81a3a [file] [log] [blame]
Dung Cao956cbfc2021-06-11 09:24:57 +00001/*
2 * Copyright (c) 2018-2021 Ampere Computing LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <bridgingcommands.hpp>
18#include <ipmid/api.hpp>
19#include <ipmid/utils.hpp>
20#include <phosphor-logging/log.hpp>
21#include <sdbusplus/bus.hpp>
22#include <sdbusplus/bus/match.hpp>
23#include <sdbusplus/message.hpp>
24#include <user_channel/channel_layer.hpp>
25
26#include <bitset>
27#include <cstring>
28#include <vector>
29
30static Bridging bridging;
31static bool eventMessageBufferFlag = false;
32
33void Bridging::clearResponseQueue()
34{
35 responseQueue.clear();
36}
37
38void Bridging::insertMessageInQueue(IpmbResponse msg)
39{
40 responseQueue.insert(responseQueue.end(), std::move(msg));
41}
42
43void Bridging::eraseMessageFromQueue()
44{
45 responseQueue.erase(responseQueue.begin());
46}
47
48IpmbResponse Bridging::getMessageFromQueue()
49{
50 return responseQueue.front();
51}
52
53std::size_t Bridging::getResponseQueueSize()
54{
55 return responseQueue.size();
56}
57
58/** @brief This command is used to flush unread data from the receive
59 * message queue
60 * @param receiveMessage - clear receive message queue
61 * @param eventMsgBufFull - clear event message buffer full
62 * @param reserved2 - reserved bit
63 * @param watchdogTimeout - clear watchdog pre-timeout interrupt flag
64 * @param reserved1 - reserved bit
65 * @param oem0 - clear OEM 0 data
66 * @param oem1 - clear OEM 1 data
67 * @param oem2 - clear OEM 2 data
68
69 * @return IPMI completion code on success
70 */
71ipmi::RspType<> ipmiAppClearMessageFlags(ipmi::Context::ptr ctx,
72 bool receiveMessage,
73 bool eventMsgBufFull, bool reserved2,
Hieu Huynh90a4fb82022-08-02 07:21:03 +000074 bool, bool reserved1,
75 bool, bool, bool)
Dung Cao956cbfc2021-06-11 09:24:57 +000076{
77 ipmi::ChannelInfo chInfo;
78
79 try
80 {
81 getChannelInfo(ctx->channel, chInfo);
82 }
83 catch (sdbusplus::exception_t& e)
84 {
85 phosphor::logging::log<phosphor::logging::level::ERR>(
86 "ipmiAppClearMessageFlags: Failed to get Channel Info",
87 phosphor::logging::entry("MSG: %s", e.description()));
88 return ipmi::responseUnspecifiedError();
89 }
90 if (chInfo.mediumType !=
91 static_cast<uint8_t>(ipmi::EChannelMediumType::smbusV20))
92 {
93 phosphor::logging::log<phosphor::logging::level::ERR>(
94 "ipmiAppClearMessageFlags: Error - supported only in SSIF "
95 "interface");
96 return ipmi::responseCommandNotAvailable();
97 }
98
99 if (reserved1 || reserved2)
100 {
101 return ipmi::responseInvalidFieldRequest();
102 }
103
104 if (receiveMessage)
105 {
106 bridging.clearResponseQueue();
107 }
108
109 if (eventMessageBufferFlag != true && eventMsgBufFull == true)
110 {
111 eventMessageBufferFlag = true;
112 }
113
114 // As phosphor-watchdog has not supported PreTimeoutInterruptFlags yet,
115 // so do nothing on clear watchdog pre-timeout interrupt flags.
116
117 return ipmi::responseSuccess();
118}
119
120void registerBridingFunctions() __attribute__((constructor));
121void registerBridingFunctions()
122{
123 // <Clear Message Flags Command>
124 ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnApp,
125 ipmi::app::cmdClearMessageFlags,
126 ipmi::Privilege::User, ipmiAppClearMessageFlags);
127
128 return;
129}