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