blob: 32f4ded466bbae105b0e8c974e05f5e5e6ed0cb3 [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
26bool doesDeviceExist(const uint8_t& chNum)
27{
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
31 struct stat fileStat;
32 std::string devName("/sys/class/net/eth");
33 devName += std::to_string(chNum - 1);
34
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
45bool isValidPrivLimit(const uint8_t& privLimit)
46{
47 return ((privLimit >= PRIVILEGE_CALLBACK) && (privLimit <= PRIVILEGE_OEM));
48}
49
50bool isValidAccessMode(const uint8_t& accessMode)
51{
52 return (
53 (accessMode >= static_cast<uint8_t>(EChannelAccessMode::disabled)) &&
54 (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared)));
55}
56
57bool isValidChannel(const uint8_t& chNum)
58{
59 return getChannelConfigObject().isValidChannel(chNum);
60}
61
62bool isValidAuthType(const uint8_t& chNum, const EAuthType& authType)
63{
64 return getChannelConfigObject().isValidAuthType(chNum, authType);
65}
66
67EChannelSessSupported getChannelSessionSupport(const uint8_t& chNum)
68{
69 return getChannelConfigObject().getChannelSessionSupport(chNum);
70}
71
72int getChannelActiveSessions(const uint8_t& chNum)
73{
74 return getChannelConfigObject().getChannelActiveSessions(chNum);
75}
76
77ipmi_ret_t ipmiChannelInit()
78{
79 getChannelConfigObject();
80 return IPMI_CC_OK;
81}
82
83ipmi_ret_t getChannelInfo(const uint8_t& chNum, ChannelInfo& chInfo)
84{
85 return getChannelConfigObject().getChannelInfo(chNum, chInfo);
86}
87
88ipmi_ret_t getChannelAccessData(const uint8_t& chNum,
89 ChannelAccess& chAccessData)
90{
91 return getChannelConfigObject().getChannelAccessData(chNum, chAccessData);
92}
93
94ipmi_ret_t setChannelAccessData(const uint8_t& chNum,
95 const ChannelAccess& chAccessData,
96 const uint8_t& setFlag)
97{
98 return getChannelConfigObject().setChannelAccessData(chNum, chAccessData,
99 setFlag);
100}
101
102ipmi_ret_t getChannelAccessPersistData(const uint8_t& chNum,
103 ChannelAccess& chAccessData)
104{
105 return getChannelConfigObject().getChannelAccessPersistData(chNum,
106 chAccessData);
107}
108
109ipmi_ret_t setChannelAccessPersistData(const uint8_t& chNum,
110 const ChannelAccess& chAccessData,
111 const uint8_t& setFlag)
112{
113 return getChannelConfigObject().setChannelAccessPersistData(
114 chNum, chAccessData, setFlag);
115}
116
117ipmi_ret_t getChannelAuthTypeSupported(const uint8_t& chNum,
118 uint8_t& authTypeSupported)
119{
120 return getChannelConfigObject().getChannelAuthTypeSupported(
121 chNum, authTypeSupported);
122}
123
124ipmi_ret_t getChannelEnabledAuthType(const uint8_t& chNum, const uint8_t& priv,
125 EAuthType& authType)
126{
127 return getChannelConfigObject().getChannelEnabledAuthType(chNum, priv,
128 authType);
129}
130
131} // namespace ipmi