1071f3f2fSAppaRao Puli /*
2071f3f2fSAppaRao Puli // Copyright (c) 2018 Intel Corporation
3071f3f2fSAppaRao Puli //
4071f3f2fSAppaRao Puli // Licensed under the Apache License, Version 2.0 (the "License");
5071f3f2fSAppaRao Puli // you may not use this file except in compliance with the License.
6071f3f2fSAppaRao Puli // You may obtain a copy of the License at
7071f3f2fSAppaRao Puli //
8071f3f2fSAppaRao Puli // http://www.apache.org/licenses/LICENSE-2.0
9071f3f2fSAppaRao Puli //
10071f3f2fSAppaRao Puli // Unless required by applicable law or agreed to in writing, software
11071f3f2fSAppaRao Puli // distributed under the License is distributed on an "AS IS" BASIS,
12071f3f2fSAppaRao Puli // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13071f3f2fSAppaRao Puli // See the License for the specific language governing permissions and
14071f3f2fSAppaRao Puli // limitations under the License.
15071f3f2fSAppaRao Puli */
16071f3f2fSAppaRao Puli
17071f3f2fSAppaRao Puli #include "channel_layer.hpp"
18071f3f2fSAppaRao Puli
1989e4bf28SNITIN SHARMA #include <ipmid/api.hpp>
2082844ef6SGeorge Liu #include <phosphor-logging/lg2.hpp>
21fbc6c9d7SPatrick Williams
22071f3f2fSAppaRao Puli #include <regex>
23071f3f2fSAppaRao Puli
24071f3f2fSAppaRao Puli namespace ipmi
25071f3f2fSAppaRao Puli {
26071f3f2fSAppaRao Puli
2789e4bf28SNITIN SHARMA /** @brief implements the set channel access command
2889e4bf28SNITIN SHARMA * @ param ctx - context pointer
2989e4bf28SNITIN SHARMA * @ param channel - channel number
3089e4bf28SNITIN SHARMA * @ param reserved - skip 4 bits
3189e4bf28SNITIN SHARMA * @ param accessMode - access mode for IPMI messaging
3289e4bf28SNITIN SHARMA * @ param usrAuth - user level authentication (enable/disable)
3389e4bf28SNITIN SHARMA * @ param msgAuth - per message authentication (enable/disable)
3489e4bf28SNITIN SHARMA * @ param alertDisabled - PEF alerting (enable/disable)
3589e4bf28SNITIN SHARMA * @ param chanAccess - channel access
3689e4bf28SNITIN SHARMA * @ param channelPrivLimit - channel privilege limit
3789e4bf28SNITIN SHARMA * @ param reserved - skip 3 bits
3889e4bf28SNITIN SHARMA * @ param channelPrivMode - channel priviledge mode
3989e4bf28SNITIN SHARMA *
4089e4bf28SNITIN SHARMA * @ returns IPMI completion code
4189e4bf28SNITIN SHARMA **/
ipmiSetChannelAccess(Context::ptr ctx,uint4_t channel,uint4_t reserved1,uint3_t accessMode,bool usrAuth,bool msgAuth,bool alertDisabled,uint2_t chanAccess,uint4_t channelPrivLimit,uint2_t reserved2,uint2_t channelPrivMode)42*1318a5edSPatrick Williams RspType<> ipmiSetChannelAccess(
43*1318a5edSPatrick Williams Context::ptr ctx, uint4_t channel, uint4_t reserved1, uint3_t accessMode,
44*1318a5edSPatrick Williams bool usrAuth, bool msgAuth, bool alertDisabled, uint2_t chanAccess,
45*1318a5edSPatrick Williams uint4_t channelPrivLimit, uint2_t reserved2, uint2_t channelPrivMode)
46071f3f2fSAppaRao Puli {
470e2dbee2Sjayaprakash Mutyala if (reserved1 || reserved2 ||
480e2dbee2Sjayaprakash Mutyala !isValidPrivLimit(static_cast<uint8_t>(channelPrivLimit)))
49071f3f2fSAppaRao Puli {
5082844ef6SGeorge Liu lg2::debug("Set channel access - Invalid field in request");
5189e4bf28SNITIN SHARMA return responseInvalidFieldRequest();
52071f3f2fSAppaRao Puli }
53071f3f2fSAppaRao Puli
540e2dbee2Sjayaprakash Mutyala const uint8_t chNum =
550e2dbee2Sjayaprakash Mutyala convertCurrentChannelNum(static_cast<uint8_t>(channel), ctx->channel);
560e2dbee2Sjayaprakash Mutyala if ((getChannelSessionSupport(chNum) == EChannelSessSupported::none) ||
570e2dbee2Sjayaprakash Mutyala (!isValidChannel(chNum)))
58071f3f2fSAppaRao Puli {
5982844ef6SGeorge Liu lg2::debug("Set channel access - No support on channel: {CHANNEL}",
6082844ef6SGeorge Liu "CHANNEL", chNum);
61ddb1f443Sanil kumar appana return response(ccActionNotSupportedForChannel);
62071f3f2fSAppaRao Puli }
63071f3f2fSAppaRao Puli
64071f3f2fSAppaRao Puli ChannelAccess chActData;
65071f3f2fSAppaRao Puli ChannelAccess chNVData;
66071f3f2fSAppaRao Puli uint8_t setActFlag = 0;
67071f3f2fSAppaRao Puli uint8_t setNVFlag = 0;
6889e4bf28SNITIN SHARMA Cc compCode;
69071f3f2fSAppaRao Puli
7089e4bf28SNITIN SHARMA // cannot static cast directly from uint2_t to enum; must go via int
7189e4bf28SNITIN SHARMA uint8_t channelAccessAction = static_cast<uint8_t>(chanAccess);
7289e4bf28SNITIN SHARMA switch (static_cast<EChannelActionType>(channelAccessAction))
73071f3f2fSAppaRao Puli {
74071f3f2fSAppaRao Puli case doNotSet:
75071f3f2fSAppaRao Puli break;
76071f3f2fSAppaRao Puli case nvData:
7789e4bf28SNITIN SHARMA chNVData.accessMode = static_cast<uint8_t>(accessMode);
7889e4bf28SNITIN SHARMA chNVData.userAuthDisabled = usrAuth;
7989e4bf28SNITIN SHARMA chNVData.perMsgAuthDisabled = msgAuth;
8089e4bf28SNITIN SHARMA chNVData.alertingDisabled = alertDisabled;
81071f3f2fSAppaRao Puli setNVFlag |= (setAccessMode | setUserAuthEnabled |
82071f3f2fSAppaRao Puli setMsgAuthEnabled | setAlertingEnabled);
83071f3f2fSAppaRao Puli break;
8489e4bf28SNITIN SHARMA
85071f3f2fSAppaRao Puli case activeData:
8689e4bf28SNITIN SHARMA chActData.accessMode = static_cast<uint8_t>(accessMode);
8789e4bf28SNITIN SHARMA chActData.userAuthDisabled = usrAuth;
8889e4bf28SNITIN SHARMA chActData.perMsgAuthDisabled = msgAuth;
8989e4bf28SNITIN SHARMA chActData.alertingDisabled = alertDisabled;
90071f3f2fSAppaRao Puli setActFlag |= (setAccessMode | setUserAuthEnabled |
91071f3f2fSAppaRao Puli setMsgAuthEnabled | setAlertingEnabled);
92071f3f2fSAppaRao Puli break;
9389e4bf28SNITIN SHARMA
94071f3f2fSAppaRao Puli case reserved:
95071f3f2fSAppaRao Puli default:
9682844ef6SGeorge Liu lg2::debug("Set channel access - Invalid access set mode");
970e2dbee2Sjayaprakash Mutyala return response(ccAccessModeNotSupportedForChannel);
98071f3f2fSAppaRao Puli }
99071f3f2fSAppaRao Puli
10089e4bf28SNITIN SHARMA // cannot static cast directly from uint2_t to enum; must go via int
10189e4bf28SNITIN SHARMA uint8_t channelPrivAction = static_cast<uint8_t>(channelPrivMode);
10289e4bf28SNITIN SHARMA switch (static_cast<EChannelActionType>(channelPrivAction))
103071f3f2fSAppaRao Puli {
104071f3f2fSAppaRao Puli case doNotSet:
105071f3f2fSAppaRao Puli break;
106071f3f2fSAppaRao Puli case nvData:
10789e4bf28SNITIN SHARMA chNVData.privLimit = static_cast<uint8_t>(channelPrivLimit);
108071f3f2fSAppaRao Puli setNVFlag |= setPrivLimit;
109071f3f2fSAppaRao Puli break;
110071f3f2fSAppaRao Puli case activeData:
11189e4bf28SNITIN SHARMA chActData.privLimit = static_cast<uint8_t>(channelPrivLimit);
11289e4bf28SNITIN SHARMA
113071f3f2fSAppaRao Puli setActFlag |= setPrivLimit;
114071f3f2fSAppaRao Puli break;
115071f3f2fSAppaRao Puli case reserved:
116071f3f2fSAppaRao Puli default:
11782844ef6SGeorge Liu lg2::debug("Set channel access - Invalid access priv mode");
1180e2dbee2Sjayaprakash Mutyala return response(ccAccessModeNotSupportedForChannel);
119071f3f2fSAppaRao Puli }
120071f3f2fSAppaRao Puli
121071f3f2fSAppaRao Puli if (setNVFlag != 0)
122071f3f2fSAppaRao Puli {
123071f3f2fSAppaRao Puli compCode = setChannelAccessPersistData(chNum, chNVData, setNVFlag);
124b541a5a5SNITIN SHARMA if (compCode != ccSuccess)
125071f3f2fSAppaRao Puli {
12682844ef6SGeorge Liu lg2::debug("Set channel access - Failed to set access data");
12789e4bf28SNITIN SHARMA return response(compCode);
128071f3f2fSAppaRao Puli }
129071f3f2fSAppaRao Puli }
130071f3f2fSAppaRao Puli
131071f3f2fSAppaRao Puli if (setActFlag != 0)
132071f3f2fSAppaRao Puli {
133071f3f2fSAppaRao Puli compCode = setChannelAccessData(chNum, chActData, setActFlag);
134b541a5a5SNITIN SHARMA if (compCode != ccSuccess)
135071f3f2fSAppaRao Puli {
13682844ef6SGeorge Liu lg2::debug("Set channel access - Failed to set access data");
13789e4bf28SNITIN SHARMA return response(compCode);
138071f3f2fSAppaRao Puli }
139071f3f2fSAppaRao Puli }
140071f3f2fSAppaRao Puli
14189e4bf28SNITIN SHARMA return responseSuccess();
142071f3f2fSAppaRao Puli }
143071f3f2fSAppaRao Puli
144bc5e9babSRichard Marian Thomaiyar /** @brief implements the get channel access command
145bc5e9babSRichard Marian Thomaiyar * @ param ctx - context pointer
146bc5e9babSRichard Marian Thomaiyar * @ param channel - channel number
147bc5e9babSRichard Marian Thomaiyar * @ param reserved1 - skip 4 bits
148bc5e9babSRichard Marian Thomaiyar * @ param reserved2 - skip 6 bits
149bc5e9babSRichard Marian Thomaiyar * @ param accessMode - get access mode
150bc5e9babSRichard Marian Thomaiyar *
151bc5e9babSRichard Marian Thomaiyar * @returns ipmi completion code plus response data
152bc5e9babSRichard Marian Thomaiyar * - accessMode - get access mode
153bc5e9babSRichard Marian Thomaiyar * - usrAuthDisabled - user level authentication status
154bc5e9babSRichard Marian Thomaiyar * - msgAuthDisabled - message level authentication status
155bc5e9babSRichard Marian Thomaiyar * - alertDisabled - alerting status
156bc5e9babSRichard Marian Thomaiyar * - reserved - skip 2 bits
157bc5e9babSRichard Marian Thomaiyar * - privLimit - channel privilege limit
158bc5e9babSRichard Marian Thomaiyar * - reserved - skip 4 bits
159bc5e9babSRichard Marian Thomaiyar * */
160bc5e9babSRichard Marian Thomaiyar ipmi ::RspType<uint3_t, // access mode,
161bc5e9babSRichard Marian Thomaiyar bool, // user authentication status,
162bc5e9babSRichard Marian Thomaiyar bool, // message authentication status,
163bc5e9babSRichard Marian Thomaiyar bool, // alerting status,
164bc5e9babSRichard Marian Thomaiyar uint2_t, // reserved,
165bc5e9babSRichard Marian Thomaiyar
166bc5e9babSRichard Marian Thomaiyar uint4_t, // channel privilege,
167bc5e9babSRichard Marian Thomaiyar uint4_t // reserved
168bc5e9babSRichard Marian Thomaiyar >
ipmiGetChannelAccess(Context::ptr ctx,uint4_t channel,uint4_t reserved1,uint6_t reserved2,uint2_t accessSetMode)169bc5e9babSRichard Marian Thomaiyar ipmiGetChannelAccess(Context::ptr ctx, uint4_t channel, uint4_t reserved1,
170bc5e9babSRichard Marian Thomaiyar uint6_t reserved2, uint2_t accessSetMode)
171071f3f2fSAppaRao Puli {
1720e2dbee2Sjayaprakash Mutyala if (reserved1 || reserved2)
173071f3f2fSAppaRao Puli {
17482844ef6SGeorge Liu lg2::debug("Get channel access - Invalid field in request");
175bc5e9babSRichard Marian Thomaiyar return responseInvalidFieldRequest();
176071f3f2fSAppaRao Puli }
177071f3f2fSAppaRao Puli
1787a0e5dfcSWilliam A. Kennington III if ((types::enum_cast<EChannelActionType>(accessSetMode) == doNotSet) ||
1797a0e5dfcSWilliam A. Kennington III (types::enum_cast<EChannelActionType>(accessSetMode) == reserved))
180071f3f2fSAppaRao Puli {
18182844ef6SGeorge Liu lg2::debug("Get channel access - Invalid Access mode");
182c4f4f7a6SAppaRao Puli return responseInvalidFieldRequest();
183071f3f2fSAppaRao Puli }
184071f3f2fSAppaRao Puli
1850e2dbee2Sjayaprakash Mutyala const uint8_t chNum =
1860e2dbee2Sjayaprakash Mutyala convertCurrentChannelNum(static_cast<uint8_t>(channel), ctx->channel);
1870e2dbee2Sjayaprakash Mutyala
1880e2dbee2Sjayaprakash Mutyala if ((getChannelSessionSupport(chNum) == EChannelSessSupported::none) ||
1890e2dbee2Sjayaprakash Mutyala (!isValidChannel(chNum)))
190071f3f2fSAppaRao Puli {
19182844ef6SGeorge Liu lg2::debug("Get channel access - No support on channel: {CHANNEL}",
19282844ef6SGeorge Liu "CHANNEL", chNum);
193ddb1f443Sanil kumar appana return response(ccActionNotSupportedForChannel);
194071f3f2fSAppaRao Puli }
195071f3f2fSAppaRao Puli
1963771f5f2SPavanKumarIntel ChannelAccess chAccess = {};
197071f3f2fSAppaRao Puli
1984c521025SWilliam A. Kennington III Cc compCode = ipmi::ccUnspecifiedError;
199bc5e9babSRichard Marian Thomaiyar
2007a0e5dfcSWilliam A. Kennington III if (types::enum_cast<EChannelActionType>(accessSetMode) == nvData)
201071f3f2fSAppaRao Puli {
202071f3f2fSAppaRao Puli compCode = getChannelAccessPersistData(chNum, chAccess);
203071f3f2fSAppaRao Puli }
2047a0e5dfcSWilliam A. Kennington III else if (types::enum_cast<EChannelActionType>(accessSetMode) == activeData)
205071f3f2fSAppaRao Puli {
206071f3f2fSAppaRao Puli compCode = getChannelAccessData(chNum, chAccess);
207071f3f2fSAppaRao Puli }
208071f3f2fSAppaRao Puli
209b541a5a5SNITIN SHARMA if (compCode != ccSuccess)
210071f3f2fSAppaRao Puli {
211bc5e9babSRichard Marian Thomaiyar return response(compCode);
212071f3f2fSAppaRao Puli }
213071f3f2fSAppaRao Puli
214bc5e9babSRichard Marian Thomaiyar constexpr uint2_t reservedOut1 = 0;
215bc5e9babSRichard Marian Thomaiyar constexpr uint4_t reservedOut2 = 0;
216071f3f2fSAppaRao Puli
217bc5e9babSRichard Marian Thomaiyar return responseSuccess(
2187a0e5dfcSWilliam A. Kennington III types::enum_cast<uint3_t>(chAccess.accessMode),
2197a0e5dfcSWilliam A. Kennington III chAccess.userAuthDisabled, chAccess.perMsgAuthDisabled,
2207a0e5dfcSWilliam A. Kennington III chAccess.alertingDisabled, reservedOut1,
2217a0e5dfcSWilliam A. Kennington III types::enum_cast<uint4_t>(chAccess.privLimit), reservedOut2);
222071f3f2fSAppaRao Puli }
223071f3f2fSAppaRao Puli
2246f1e9788SVernon Mauery /** @brief implements the get channel info command
2256f1e9788SVernon Mauery * @ param ctx - context pointer
2266f1e9788SVernon Mauery * @ param channel - channel number
2276f1e9788SVernon Mauery * @ param reserved - skip 4 bits
2286f1e9788SVernon Mauery *
2296f1e9788SVernon Mauery * @returns ipmi completion code plus response data
2306f1e9788SVernon Mauery * - chNum - the channel number for this request
2316f1e9788SVernon Mauery * - mediumType - see Table 6-3, Channel Medium Type Numbers
2326f1e9788SVernon Mauery * - protocolType - Table 6-2, Channel Protocol Type Numbers
2336f1e9788SVernon Mauery * - activeSessionCount - number of active sessions
2346f1e9788SVernon Mauery * - sessionType - channel support for sessions
2356f1e9788SVernon Mauery * - vendorId - vendor for this channel protocol (IPMI - 7154)
2366f1e9788SVernon Mauery * - auxChInfo - auxiliary info for channel
2376f1e9788SVernon Mauery * */
2386f1e9788SVernon Mauery RspType<uint4_t, // chNum
2396f1e9788SVernon Mauery uint4_t, // reserved
2406f1e9788SVernon Mauery uint7_t, // mediumType
2416f1e9788SVernon Mauery bool, // reserved
2426f1e9788SVernon Mauery uint5_t, // protocolType
2436f1e9788SVernon Mauery uint3_t, // reserved
2446f1e9788SVernon Mauery uint6_t, // activeSessionCount
2456f1e9788SVernon Mauery uint2_t, // sessionType
2466f1e9788SVernon Mauery uint24_t, // Vendor IANA
2476f1e9788SVernon Mauery uint16_t // aux info
2486f1e9788SVernon Mauery >
ipmiGetChannelInfo(Context::ptr ctx,uint4_t channel,uint4_t reserved)2496f1e9788SVernon Mauery ipmiGetChannelInfo(Context::ptr ctx, uint4_t channel, uint4_t reserved)
250071f3f2fSAppaRao Puli {
2510e2dbee2Sjayaprakash Mutyala if (reserved)
252071f3f2fSAppaRao Puli {
25382844ef6SGeorge Liu lg2::debug("Get channel access - Invalid field in request");
2546f1e9788SVernon Mauery return responseInvalidFieldRequest();
255071f3f2fSAppaRao Puli }
256071f3f2fSAppaRao Puli
257*1318a5edSPatrick Williams uint8_t chNum =
258*1318a5edSPatrick Williams convertCurrentChannelNum(static_cast<uint8_t>(channel), ctx->channel);
2590e2dbee2Sjayaprakash Mutyala if (!isValidChannel(chNum))
2600e2dbee2Sjayaprakash Mutyala {
26182844ef6SGeorge Liu lg2::debug("Get channel Info - No support on channel: {CHANNEL}",
26282844ef6SGeorge Liu "CHANNEL", chNum);
263afd12b4eSJayaprakash Mutyala return responseInvalidFieldRequest();
2640e2dbee2Sjayaprakash Mutyala }
2650e2dbee2Sjayaprakash Mutyala
266071f3f2fSAppaRao Puli ChannelInfo chInfo;
2676f1e9788SVernon Mauery Cc compCode = getChannelInfo(chNum, chInfo);
2686f1e9788SVernon Mauery if (compCode != ccSuccess)
269071f3f2fSAppaRao Puli {
27082844ef6SGeorge Liu lg2::error("Failed to get channel info, channel: {CHANNEL}, "
27182844ef6SGeorge Liu "errno: {ERRNO}",
27282844ef6SGeorge Liu "CHANNEL", chNum, "ERRNO", compCode);
2736f1e9788SVernon Mauery return response(compCode);
274071f3f2fSAppaRao Puli }
275071f3f2fSAppaRao Puli
2766f1e9788SVernon Mauery constexpr uint4_t reserved1 = 0;
2776f1e9788SVernon Mauery constexpr bool reserved2 = false;
2786f1e9788SVernon Mauery constexpr uint3_t reserved3 = 0;
2796f1e9788SVernon Mauery uint8_t mediumType = chInfo.mediumType;
2806f1e9788SVernon Mauery uint8_t protocolType = chInfo.protocolType;
2816f1e9788SVernon Mauery uint2_t sessionType = chInfo.sessionSupported;
2826f1e9788SVernon Mauery uint6_t activeSessionCount = getChannelActiveSessions(chNum);
283071f3f2fSAppaRao Puli // IPMI Spec: The IPMI Enterprise Number is: 7154 (decimal)
2846f1e9788SVernon Mauery constexpr uint24_t vendorId = 7154;
2856f1e9788SVernon Mauery constexpr uint16_t auxChInfo = 0;
286071f3f2fSAppaRao Puli
2876f1e9788SVernon Mauery return responseSuccess(chNum, reserved1, mediumType, reserved2,
2886f1e9788SVernon Mauery protocolType, reserved3, activeSessionCount,
2896f1e9788SVernon Mauery sessionType, vendorId, auxChInfo);
290071f3f2fSAppaRao Puli }
291071f3f2fSAppaRao Puli
292f6092898SVernon Mauery namespace
293b5a0f16dSSaravanan Palanisamy {
standardPayloadBit(PayloadType p)294f6092898SVernon Mauery constexpr uint16_t standardPayloadBit(PayloadType p)
295b5a0f16dSSaravanan Palanisamy {
296f6092898SVernon Mauery return (1 << static_cast<size_t>(p));
297b5a0f16dSSaravanan Palanisamy }
298b5a0f16dSSaravanan Palanisamy
sessionPayloadBit(PayloadType p)299f6092898SVernon Mauery constexpr uint16_t sessionPayloadBit(PayloadType p)
300b5a0f16dSSaravanan Palanisamy {
301f6092898SVernon Mauery constexpr size_t sessionShift =
302f6092898SVernon Mauery static_cast<size_t>(PayloadType::OPEN_SESSION_REQUEST);
303f6092898SVernon Mauery return ((1 << static_cast<size_t>(p)) >> sessionShift);
304b5a0f16dSSaravanan Palanisamy }
305f6092898SVernon Mauery } // namespace
306b5a0f16dSSaravanan Palanisamy
307f6092898SVernon Mauery /** @brief implements get channel payload support command
308f6092898SVernon Mauery * @ param ctx - ipmi context pointer
309f6092898SVernon Mauery * @ param chNum - channel number
310f6092898SVernon Mauery * @ param reserved - skip 4 bits
311f6092898SVernon Mauery *
312f6092898SVernon Mauery * @ returns IPMI completion code plus response data
313f6092898SVernon Mauery * - stdPayloadType - bitmask of supported standard payload types
314f6092898SVernon Mauery * - sessSetupPayloadType - bitmask of supported session setup payload types
315f6092898SVernon Mauery * - OEMPayloadType - bitmask of supported OEM payload types
316f6092898SVernon Mauery * - reserved - 2 bytes of 0
317f6092898SVernon Mauery **/
318f6092898SVernon Mauery RspType<uint16_t, // stdPayloadType
319f6092898SVernon Mauery uint16_t, // sessSetupPayloadType
320f6092898SVernon Mauery uint16_t, // OEMPayloadType
321f6092898SVernon Mauery uint16_t // reserved
322f6092898SVernon Mauery >
ipmiGetChannelPayloadSupport(Context::ptr ctx,uint4_t channel,uint4_t reserved)323f6092898SVernon Mauery ipmiGetChannelPayloadSupport(Context::ptr ctx, uint4_t channel,
324f6092898SVernon Mauery uint4_t reserved)
325b5a0f16dSSaravanan Palanisamy {
326*1318a5edSPatrick Williams uint8_t chNum =
327*1318a5edSPatrick Williams convertCurrentChannelNum(static_cast<uint8_t>(channel), ctx->channel);
3280e2dbee2Sjayaprakash Mutyala
3290e2dbee2Sjayaprakash Mutyala if (!doesDeviceExist(chNum) || !isValidChannel(chNum) || reserved)
330f6092898SVernon Mauery {
33182844ef6SGeorge Liu lg2::debug("Get channel payload - Invalid field in request");
332f6092898SVernon Mauery return responseInvalidFieldRequest();
333b5a0f16dSSaravanan Palanisamy }
334b5a0f16dSSaravanan Palanisamy
335b5a0f16dSSaravanan Palanisamy // Session support is available in active LAN channels.
3360e2dbee2Sjayaprakash Mutyala if (getChannelSessionSupport(chNum) == EChannelSessSupported::none)
337b5a0f16dSSaravanan Palanisamy {
33882844ef6SGeorge Liu lg2::debug("Get channel payload - No support on channel");
3390e2dbee2Sjayaprakash Mutyala return response(ccActionNotSupportedForChannel);
340b5a0f16dSSaravanan Palanisamy }
341f6092898SVernon Mauery constexpr uint16_t stdPayloadType = standardPayloadBit(PayloadType::IPMI) |
342f6092898SVernon Mauery standardPayloadBit(PayloadType::SOL);
343f6092898SVernon Mauery constexpr uint16_t sessSetupPayloadType =
344f6092898SVernon Mauery sessionPayloadBit(PayloadType::OPEN_SESSION_REQUEST) |
345f6092898SVernon Mauery sessionPayloadBit(PayloadType::OPEN_SESSION_RESPONSE) |
346f6092898SVernon Mauery sessionPayloadBit(PayloadType::RAKP1) |
347f6092898SVernon Mauery sessionPayloadBit(PayloadType::RAKP2) |
348f6092898SVernon Mauery sessionPayloadBit(PayloadType::RAKP3) |
349f6092898SVernon Mauery sessionPayloadBit(PayloadType::RAKP4);
350f6092898SVernon Mauery constexpr uint16_t OEMPayloadType = 0;
351f6092898SVernon Mauery constexpr uint16_t rspRsvd = 0;
352f6092898SVernon Mauery return responseSuccess(stdPayloadType, sessSetupPayloadType, OEMPayloadType,
353f6092898SVernon Mauery rspRsvd);
354b5a0f16dSSaravanan Palanisamy }
355b5a0f16dSSaravanan Palanisamy
3566fd812d1SAyushi Smriti /** @brief implements the get channel payload version command
3576fd812d1SAyushi Smriti * @param ctx - IPMI context pointer (for channel)
3586fd812d1SAyushi Smriti * @param chNum - channel number to get info about
3596fd812d1SAyushi Smriti * @param reserved - skip 4 bits
3606fd812d1SAyushi Smriti * @param payloadTypeNum - to get payload type info
3616fd812d1SAyushi Smriti
3626fd812d1SAyushi Smriti * @returns IPMI completion code plus response data
3636fd812d1SAyushi Smriti * - formatVersion - BCD encoded format version info
3646fd812d1SAyushi Smriti */
3656fd812d1SAyushi Smriti
3666fd812d1SAyushi Smriti RspType<uint8_t> // formatVersion
ipmiGetChannelPayloadVersion(Context::ptr ctx,uint4_t chNum,uint4_t reserved,uint8_t payloadTypeNum)3676fd812d1SAyushi Smriti ipmiGetChannelPayloadVersion(Context::ptr ctx, uint4_t chNum,
3686fd812d1SAyushi Smriti uint4_t reserved, uint8_t payloadTypeNum)
3696fd812d1SAyushi Smriti {
370*1318a5edSPatrick Williams uint8_t channel =
371*1318a5edSPatrick Williams convertCurrentChannelNum(static_cast<uint8_t>(chNum), ctx->channel);
372271d9c2fSManoj Ashok constexpr uint8_t payloadTypeNotSupported = 0x80;
3736fd812d1SAyushi Smriti
3740e2dbee2Sjayaprakash Mutyala if (reserved || !isValidChannel(channel))
3756fd812d1SAyushi Smriti {
37682844ef6SGeorge Liu lg2::debug("Get channel payload version - Invalid field in request");
3776fd812d1SAyushi Smriti return responseInvalidFieldRequest();
3786fd812d1SAyushi Smriti }
3796fd812d1SAyushi Smriti
3800e2dbee2Sjayaprakash Mutyala if (getChannelSessionSupport(channel) == EChannelSessSupported::none)
3810e2dbee2Sjayaprakash Mutyala {
38282844ef6SGeorge Liu lg2::debug("Get channel payload version - No support on channel");
383271d9c2fSManoj Ashok return response(payloadTypeNotSupported);
3840e2dbee2Sjayaprakash Mutyala }
3850e2dbee2Sjayaprakash Mutyala
3866fd812d1SAyushi Smriti if (!isValidPayloadType(static_cast<PayloadType>(payloadTypeNum)))
3876fd812d1SAyushi Smriti {
38882844ef6SGeorge Liu lg2::error("Get channel payload version - Payload type unavailable");
3896fd812d1SAyushi Smriti
3906fd812d1SAyushi Smriti return response(payloadTypeNotSupported);
3916fd812d1SAyushi Smriti }
3926fd812d1SAyushi Smriti
3936fd812d1SAyushi Smriti // BCD encoded version representation - 1.0
3946fd812d1SAyushi Smriti constexpr uint8_t formatVersion = 0x10;
3956fd812d1SAyushi Smriti
3966fd812d1SAyushi Smriti return responseSuccess(formatVersion);
3976fd812d1SAyushi Smriti }
3986fd812d1SAyushi Smriti
399343d0611SWilliam A. Kennington III void registerChannelFunctions() __attribute__((constructor));
registerChannelFunctions()400071f3f2fSAppaRao Puli void registerChannelFunctions()
401071f3f2fSAppaRao Puli {
402071f3f2fSAppaRao Puli ipmiChannelInit();
403071f3f2fSAppaRao Puli
40489e4bf28SNITIN SHARMA registerHandler(prioOpenBmcBase, netFnApp, app::cmdSetChannelAccess,
40589e4bf28SNITIN SHARMA Privilege::Admin, ipmiSetChannelAccess);
406071f3f2fSAppaRao Puli
407bc5e9babSRichard Marian Thomaiyar registerHandler(prioOpenBmcBase, netFnApp, app::cmdGetChannelAccess,
408bc5e9babSRichard Marian Thomaiyar Privilege::User, ipmiGetChannelAccess);
409071f3f2fSAppaRao Puli
4106f1e9788SVernon Mauery registerHandler(prioOpenBmcBase, netFnApp, app::cmdGetChannelInfoCommand,
4116f1e9788SVernon Mauery Privilege::User, ipmiGetChannelInfo);
412b5a0f16dSSaravanan Palanisamy
413f6092898SVernon Mauery registerHandler(prioOpenBmcBase, netFnApp, app::cmdGetChannelPayloadSupport,
414f6092898SVernon Mauery Privilege::User, ipmiGetChannelPayloadSupport);
4156fd812d1SAyushi Smriti
4166fd812d1SAyushi Smriti registerHandler(prioOpenBmcBase, netFnApp, app::cmdGetChannelPayloadVersion,
4176fd812d1SAyushi Smriti Privilege::User, ipmiGetChannelPayloadVersion);
418071f3f2fSAppaRao Puli }
419071f3f2fSAppaRao Puli
420071f3f2fSAppaRao Puli } // namespace ipmi
421