blob: 38fd43f361dbbf4139950d9948816e124cdb3852 [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
22#include <phosphor-logging/log.hpp>
23
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
Richard Marian Thomaiyar73906b92019-01-04 23:48:02 +053032 struct stat fileStat = {0};
Johnathan Mantey74a21022018-12-13 13:17:56 -080033 std::string devName("/sys/class/net/" + getChannelName(chNum));
AppaRao Puli071f3f22018-05-24 16:45:30 +053034
35 if (stat(devName.data(), &fileStat) != 0)
36 {
37 phosphor::logging::log<phosphor::logging::level::DEBUG>(
38 "Ethernet device not found");
39 return false;
40 }
41
42 return true;
43}
44
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053045bool isValidPrivLimit(const uint8_t privLimit)
AppaRao Puli071f3f22018-05-24 16:45:30 +053046{
jayaprakash Mutyala0e2dbee2019-12-26 13:03:04 +000047 // Callback privilege is deprecated in OpenBMC
48 return ((privLimit > PRIVILEGE_CALLBACK) && (privLimit <= PRIVILEGE_OEM));
AppaRao Puli071f3f22018-05-24 16:45:30 +053049}
50
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053051bool isValidAccessMode(const uint8_t accessMode)
AppaRao Puli071f3f22018-05-24 16:45:30 +053052{
53 return (
54 (accessMode >= static_cast<uint8_t>(EChannelAccessMode::disabled)) &&
55 (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared)));
56}
57
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053058bool isValidChannel(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +053059{
60 return getChannelConfigObject().isValidChannel(chNum);
61}
62
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053063bool isValidAuthType(const uint8_t chNum, const EAuthType& authType)
AppaRao Puli071f3f22018-05-24 16:45:30 +053064{
65 return getChannelConfigObject().isValidAuthType(chNum, authType);
66}
67
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053068EChannelSessSupported getChannelSessionSupport(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +053069{
70 return getChannelConfigObject().getChannelSessionSupport(chNum);
71}
72
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053073int getChannelActiveSessions(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +053074{
75 return getChannelConfigObject().getChannelActiveSessions(chNum);
76}
77
Vernon Mauery58317122018-11-28 11:02:43 -080078size_t getChannelMaxTransferSize(uint8_t chNum)
79{
80 return getChannelConfigObject().getChannelMaxTransferSize(chNum);
81}
82
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000083Cc ipmiChannelInit()
AppaRao Puli071f3f22018-05-24 16:45:30 +053084{
85 getChannelConfigObject();
Sumanth Bhate4e633e2019-05-14 12:13:57 +000086 getCipherConfigObject(csPrivFileName, csPrivDefaultFileName);
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000087 return ccSuccess;
AppaRao Puli071f3f22018-05-24 16:45:30 +053088}
89
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000090Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo)
AppaRao Puli071f3f22018-05-24 16:45:30 +053091{
92 return getChannelConfigObject().getChannelInfo(chNum, chInfo);
93}
94
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000095Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData)
AppaRao Puli071f3f22018-05-24 16:45:30 +053096{
97 return getChannelConfigObject().getChannelAccessData(chNum, chAccessData);
98}
99
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000100Cc setChannelAccessData(const uint8_t chNum, const ChannelAccess& chAccessData,
101 const uint8_t setFlag)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530102{
103 return getChannelConfigObject().setChannelAccessData(chNum, chAccessData,
104 setFlag);
105}
106
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000107Cc getChannelAccessPersistData(const uint8_t chNum, ChannelAccess& chAccessData)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530108{
109 return getChannelConfigObject().getChannelAccessPersistData(chNum,
110 chAccessData);
111}
112
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000113Cc setChannelAccessPersistData(const uint8_t chNum,
114 const ChannelAccess& chAccessData,
115 const uint8_t setFlag)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530116{
117 return getChannelConfigObject().setChannelAccessPersistData(
118 chNum, chAccessData, setFlag);
119}
120
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000121Cc getChannelAuthTypeSupported(const uint8_t chNum, uint8_t& authTypeSupported)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530122{
123 return getChannelConfigObject().getChannelAuthTypeSupported(
124 chNum, authTypeSupported);
125}
126
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000127Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
128 EAuthType& authType)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530129{
130 return getChannelConfigObject().getChannelEnabledAuthType(chNum, priv,
131 authType);
132}
133
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530134std::string getChannelName(const uint8_t chNum)
Johnathan Mantey74a21022018-12-13 13:17:56 -0800135{
136 return getChannelConfigObject().getChannelName(chNum);
137}
138
Vernon Mauery735ee952019-02-15 13:38:52 -0800139uint8_t getChannelByName(const std::string& chName)
140{
141 return getChannelConfigObject().getChannelByName(chName);
142}
Ayushi Smriti6fd812d2019-04-12 18:51:31 +0000143
144bool isValidPayloadType(const PayloadType payloadType)
145{
146 return (
147 payloadType == PayloadType::IPMI || payloadType == PayloadType::SOL ||
148 payloadType == PayloadType::OPEN_SESSION_REQUEST ||
149 payloadType == PayloadType::OPEN_SESSION_RESPONSE ||
150 payloadType == PayloadType::RAKP1 ||
151 payloadType == PayloadType::RAKP2 ||
152 payloadType == PayloadType::RAKP3 || payloadType == PayloadType::RAKP4);
153}
AppaRao Puli071f3f22018-05-24 16:45:30 +0530154} // namespace ipmi