1 /*
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 
23 namespace ipmi
24 {
25 
26 bool 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 = {0};
32     std::string devName("/sys/class/net/" + getChannelName(chNum));
33 
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 
44 bool isValidPrivLimit(const uint8_t privLimit)
45 {
46     return ((privLimit >= PRIVILEGE_CALLBACK) && (privLimit <= PRIVILEGE_OEM));
47 }
48 
49 bool isValidAccessMode(const uint8_t accessMode)
50 {
51     return (
52         (accessMode >= static_cast<uint8_t>(EChannelAccessMode::disabled)) &&
53         (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared)));
54 }
55 
56 bool isValidChannel(const uint8_t chNum)
57 {
58     return getChannelConfigObject().isValidChannel(chNum);
59 }
60 
61 bool isValidAuthType(const uint8_t chNum, const EAuthType& authType)
62 {
63     return getChannelConfigObject().isValidAuthType(chNum, authType);
64 }
65 
66 EChannelSessSupported getChannelSessionSupport(const uint8_t chNum)
67 {
68     return getChannelConfigObject().getChannelSessionSupport(chNum);
69 }
70 
71 int getChannelActiveSessions(const uint8_t chNum)
72 {
73     return getChannelConfigObject().getChannelActiveSessions(chNum);
74 }
75 
76 size_t getChannelMaxTransferSize(uint8_t chNum)
77 {
78     return getChannelConfigObject().getChannelMaxTransferSize(chNum);
79 }
80 
81 Cc ipmiChannelInit()
82 {
83     getChannelConfigObject();
84     return ccSuccess;
85 }
86 
87 Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo)
88 {
89     return getChannelConfigObject().getChannelInfo(chNum, chInfo);
90 }
91 
92 Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData)
93 {
94     return getChannelConfigObject().getChannelAccessData(chNum, chAccessData);
95 }
96 
97 Cc setChannelAccessData(const uint8_t chNum, const ChannelAccess& chAccessData,
98                         const uint8_t setFlag)
99 {
100     return getChannelConfigObject().setChannelAccessData(chNum, chAccessData,
101                                                          setFlag);
102 }
103 
104 Cc getChannelAccessPersistData(const uint8_t chNum, ChannelAccess& chAccessData)
105 {
106     return getChannelConfigObject().getChannelAccessPersistData(chNum,
107                                                                 chAccessData);
108 }
109 
110 Cc setChannelAccessPersistData(const uint8_t chNum,
111                                const ChannelAccess& chAccessData,
112                                const uint8_t setFlag)
113 {
114     return getChannelConfigObject().setChannelAccessPersistData(
115         chNum, chAccessData, setFlag);
116 }
117 
118 Cc getChannelAuthTypeSupported(const uint8_t chNum, uint8_t& authTypeSupported)
119 {
120     return getChannelConfigObject().getChannelAuthTypeSupported(
121         chNum, authTypeSupported);
122 }
123 
124 Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
125                              EAuthType& authType)
126 {
127     return getChannelConfigObject().getChannelEnabledAuthType(chNum, priv,
128                                                               authType);
129 }
130 
131 std::string getChannelName(const uint8_t chNum)
132 {
133     return getChannelConfigObject().getChannelName(chNum);
134 }
135 
136 uint8_t getChannelByName(const std::string& chName)
137 {
138     return getChannelConfigObject().getChannelByName(chName);
139 }
140 
141 bool isValidPayloadType(const PayloadType payloadType)
142 {
143     return (
144         payloadType == PayloadType::IPMI || payloadType == PayloadType::SOL ||
145         payloadType == PayloadType::OPEN_SESSION_REQUEST ||
146         payloadType == PayloadType::OPEN_SESSION_RESPONSE ||
147         payloadType == PayloadType::RAKP1 ||
148         payloadType == PayloadType::RAKP2 ||
149         payloadType == PayloadType::RAKP3 || payloadType == PayloadType::RAKP4);
150 }
151 } // namespace ipmi
152