blob: c6866c2a48ce729a59e5927bf1a8df301c8a02aa [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"
20
21#include <phosphor-logging/log.hpp>
22
23namespace ipmi
24{
25
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053026bool doesDeviceExist(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +053027{
28 // TODO: This is not the reliable way to find the device
29 // associated with ethernet interface as the channel number to
30 // eth association is not done. Need to revisit later
Richard Marian Thomaiyar73906b92019-01-04 23:48:02 +053031 struct stat fileStat = {0};
Johnathan Mantey74a21022018-12-13 13:17:56 -080032 std::string devName("/sys/class/net/" + getChannelName(chNum));
AppaRao Puli071f3f22018-05-24 16:45:30 +053033
34 if (stat(devName.data(), &fileStat) != 0)
35 {
36 phosphor::logging::log<phosphor::logging::level::DEBUG>(
37 "Ethernet device not found");
38 return false;
39 }
40
41 return true;
42}
43
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053044bool isValidPrivLimit(const uint8_t privLimit)
AppaRao Puli071f3f22018-05-24 16:45:30 +053045{
46 return ((privLimit >= PRIVILEGE_CALLBACK) && (privLimit <= PRIVILEGE_OEM));
47}
48
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053049bool isValidAccessMode(const uint8_t accessMode)
AppaRao Puli071f3f22018-05-24 16:45:30 +053050{
51 return (
52 (accessMode >= static_cast<uint8_t>(EChannelAccessMode::disabled)) &&
53 (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared)));
54}
55
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053056bool isValidChannel(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +053057{
58 return getChannelConfigObject().isValidChannel(chNum);
59}
60
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053061bool isValidAuthType(const uint8_t chNum, const EAuthType& authType)
AppaRao Puli071f3f22018-05-24 16:45:30 +053062{
63 return getChannelConfigObject().isValidAuthType(chNum, authType);
64}
65
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053066EChannelSessSupported getChannelSessionSupport(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +053067{
68 return getChannelConfigObject().getChannelSessionSupport(chNum);
69}
70
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053071int getChannelActiveSessions(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +053072{
73 return getChannelConfigObject().getChannelActiveSessions(chNum);
74}
75
Vernon Mauery58317122018-11-28 11:02:43 -080076size_t getChannelMaxTransferSize(uint8_t chNum)
77{
78 return getChannelConfigObject().getChannelMaxTransferSize(chNum);
79}
80
AppaRao Puli071f3f22018-05-24 16:45:30 +053081ipmi_ret_t ipmiChannelInit()
82{
83 getChannelConfigObject();
84 return IPMI_CC_OK;
85}
86
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053087ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo)
AppaRao Puli071f3f22018-05-24 16:45:30 +053088{
89 return getChannelConfigObject().getChannelInfo(chNum, chInfo);
90}
91
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053092ipmi_ret_t getChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +053093 ChannelAccess& chAccessData)
94{
95 return getChannelConfigObject().getChannelAccessData(chNum, chAccessData);
96}
97
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +053098ipmi_ret_t setChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +053099 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530100 const uint8_t setFlag)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530101{
102 return getChannelConfigObject().setChannelAccessData(chNum, chAccessData,
103 setFlag);
104}
105
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530106ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530107 ChannelAccess& chAccessData)
108{
109 return getChannelConfigObject().getChannelAccessPersistData(chNum,
110 chAccessData);
111}
112
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530113ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530114 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530115 const uint8_t setFlag)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530116{
117 return getChannelConfigObject().setChannelAccessPersistData(
118 chNum, chAccessData, setFlag);
119}
120
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530121ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530122 uint8_t& authTypeSupported)
123{
124 return getChannelConfigObject().getChannelAuthTypeSupported(
125 chNum, authTypeSupported);
126}
127
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530128ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530129 EAuthType& authType)
130{
131 return getChannelConfigObject().getChannelEnabledAuthType(chNum, priv,
132 authType);
133}
134
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530135std::string getChannelName(const uint8_t chNum)
Johnathan Mantey74a21022018-12-13 13:17:56 -0800136{
137 return getChannelConfigObject().getChannelName(chNum);
138}
139
Vernon Mauery735ee952019-02-15 13:38:52 -0800140uint8_t getChannelByName(const std::string& chName)
141{
142 return getChannelConfigObject().getChannelByName(chName);
143}
Ayushi Smriti6fd812d2019-04-12 18:51:31 +0000144
145bool isValidPayloadType(const PayloadType payloadType)
146{
147 return (
148 payloadType == PayloadType::IPMI || payloadType == PayloadType::SOL ||
149 payloadType == PayloadType::OPEN_SESSION_REQUEST ||
150 payloadType == PayloadType::OPEN_SESSION_RESPONSE ||
151 payloadType == PayloadType::RAKP1 ||
152 payloadType == PayloadType::RAKP2 ||
153 payloadType == PayloadType::RAKP3 || payloadType == PayloadType::RAKP4);
154}
AppaRao Puli071f3f22018-05-24 16:45:30 +0530155} // namespace ipmi