blob: e59459fda3dcb7c2ac93a2187b242f5117f5116a [file] [log] [blame]
AppaRao Puli071f3f22018-05-24 16:45:30 +05301/*
2// Copyright (c) 2018 Intel Corporation
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 "channel_layer.hpp"
18
19#include "channel_mgmt.hpp"
Sumanth Bhate4e633e2019-05-14 12:13:57 +000020#include "cipher_mgmt.hpp"
AppaRao Puli071f3f22018-05-24 16:45:30 +053021
George Liu82844ef2024-07-17 17:03:56 +080022#include <phosphor-logging/lg2.hpp>
AppaRao Puli071f3f22018-05-24 16:45:30 +053023
24namespace ipmi
25{
26
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053027bool doesDeviceExist(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +053028{
29 // TODO: This is not the reliable way to find the device
30 // associated with ethernet interface as the channel number to
31 // eth association is not done. Need to revisit later
Willy Tu11d68892022-01-20 10:37:34 -080032 struct stat fileStat = {};
Prithvi Pai1dd18d22025-09-19 14:27:03 +053033 auto channelName = getChannelName(chNum);
34 if (channelName.empty())
35 {
36 lg2::error("Channel name does not exist for channel {CHANNEL}",
37 "CHANNEL", chNum);
38 return false;
39 }
40 std::string devName("/sys/class/net/" + channelName);
AppaRao Puli071f3f22018-05-24 16:45:30 +053041
42 if (stat(devName.data(), &fileStat) != 0)
43 {
George Liu82844ef2024-07-17 17:03:56 +080044 lg2::debug("Ethernet device not found");
AppaRao Puli071f3f22018-05-24 16:45:30 +053045 return false;
46 }
47
48 return true;
49}
50
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053051bool isValidPrivLimit(const uint8_t privLimit)
AppaRao Puli071f3f22018-05-24 16:45:30 +053052{
jayaprakash Mutyala0e2dbee2019-12-26 13:03:04 +000053 // Callback privilege is deprecated in OpenBMC
srikanta mondal785223a2020-04-10 11:35:32 +000054 // At present, "OEM Privilege" is not used in OpenBMC
55 return ((privLimit > PRIVILEGE_CALLBACK) && (privLimit < PRIVILEGE_OEM));
AppaRao Puli071f3f22018-05-24 16:45:30 +053056}
57
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053058bool isValidAccessMode(const uint8_t accessMode)
AppaRao Puli071f3f22018-05-24 16:45:30 +053059{
PavanKumarIntel3771f5f2023-11-02 06:26:42 +000060 return (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared));
AppaRao Puli071f3f22018-05-24 16:45:30 +053061}
62
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053063bool isValidChannel(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +053064{
65 return getChannelConfigObject().isValidChannel(chNum);
66}
67
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053068bool isValidAuthType(const uint8_t chNum, const EAuthType& authType)
AppaRao Puli071f3f22018-05-24 16:45:30 +053069{
70 return getChannelConfigObject().isValidAuthType(chNum, authType);
71}
72
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053073EChannelSessSupported getChannelSessionSupport(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +053074{
75 return getChannelConfigObject().getChannelSessionSupport(chNum);
76}
77
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053078int getChannelActiveSessions(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +053079{
80 return getChannelConfigObject().getChannelActiveSessions(chNum);
81}
82
Vernon Mauery58317122018-11-28 11:02:43 -080083size_t getChannelMaxTransferSize(uint8_t chNum)
84{
85 return getChannelConfigObject().getChannelMaxTransferSize(chNum);
86}
87
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000088Cc ipmiChannelInit()
AppaRao Puli071f3f22018-05-24 16:45:30 +053089{
90 getChannelConfigObject();
Sumanth Bhate4e633e2019-05-14 12:13:57 +000091 getCipherConfigObject(csPrivFileName, csPrivDefaultFileName);
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000092 return ccSuccess;
AppaRao Puli071f3f22018-05-24 16:45:30 +053093}
94
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000095Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo)
AppaRao Puli071f3f22018-05-24 16:45:30 +053096{
97 return getChannelConfigObject().getChannelInfo(chNum, chInfo);
98}
99
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000100Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530101{
102 return getChannelConfigObject().getChannelAccessData(chNum, chAccessData);
103}
104
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000105Cc setChannelAccessData(const uint8_t chNum, const ChannelAccess& chAccessData,
106 const uint8_t setFlag)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530107{
108 return getChannelConfigObject().setChannelAccessData(chNum, chAccessData,
109 setFlag);
110}
111
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000112Cc getChannelAccessPersistData(const uint8_t chNum, ChannelAccess& chAccessData)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530113{
Patrick Williams1318a5e2024-08-16 15:19:54 -0400114 return getChannelConfigObject().getChannelAccessPersistData(
115 chNum, chAccessData);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530116}
117
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000118Cc setChannelAccessPersistData(const uint8_t chNum,
119 const ChannelAccess& chAccessData,
120 const uint8_t setFlag)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530121{
122 return getChannelConfigObject().setChannelAccessPersistData(
123 chNum, chAccessData, setFlag);
124}
125
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000126Cc getChannelAuthTypeSupported(const uint8_t chNum, uint8_t& authTypeSupported)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530127{
128 return getChannelConfigObject().getChannelAuthTypeSupported(
129 chNum, authTypeSupported);
130}
131
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000132Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
133 EAuthType& authType)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530134{
Patrick Williams1318a5e2024-08-16 15:19:54 -0400135 return getChannelConfigObject().getChannelEnabledAuthType(
136 chNum, priv, authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530137}
138
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530139std::string getChannelName(const uint8_t chNum)
Johnathan Mantey74a21022018-12-13 13:17:56 -0800140{
141 return getChannelConfigObject().getChannelName(chNum);
142}
143
Vernon Mauery735ee952019-02-15 13:38:52 -0800144uint8_t getChannelByName(const std::string& chName)
145{
146 return getChannelConfigObject().getChannelByName(chName);
147}
Ayushi Smriti6fd812d2019-04-12 18:51:31 +0000148
149bool isValidPayloadType(const PayloadType payloadType)
150{
151 return (
152 payloadType == PayloadType::IPMI || payloadType == PayloadType::SOL ||
153 payloadType == PayloadType::OPEN_SESSION_REQUEST ||
154 payloadType == PayloadType::OPEN_SESSION_RESPONSE ||
155 payloadType == PayloadType::RAKP1 ||
156 payloadType == PayloadType::RAKP2 ||
157 payloadType == PayloadType::RAKP3 || payloadType == PayloadType::RAKP4);
158}
AppaRao Puli071f3f22018-05-24 16:45:30 +0530159} // namespace ipmi