xref: /openbmc/phosphor-host-ipmid/user_channel/channel_layer.cpp (revision 1dd18d2466e7952a0d27b3e5c9fa18e6e91336e6)
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/lg2.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     auto channelName = getChannelName(chNum);
34     if (channelName.empty())
35     {
36         lg2::error("Channel name does not exist for channel {CHANNEL}",
37                    "CHANNEL", chNum);
38         return false;
39     }
40     std::string devName("/sys/class/net/" + channelName);
41 
42     if (stat(devName.data(), &fileStat) != 0)
43     {
44         lg2::debug("Ethernet device not found");
45         return false;
46     }
47 
48     return true;
49 }
50 
isValidPrivLimit(const uint8_t privLimit)51 bool isValidPrivLimit(const uint8_t privLimit)
52 {
53     // Callback privilege is deprecated in OpenBMC
54     // At present, "OEM Privilege" is not used in OpenBMC
55     return ((privLimit > PRIVILEGE_CALLBACK) && (privLimit < PRIVILEGE_OEM));
56 }
57 
isValidAccessMode(const uint8_t accessMode)58 bool isValidAccessMode(const uint8_t accessMode)
59 {
60     return (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared));
61 }
62 
isValidChannel(const uint8_t chNum)63 bool isValidChannel(const uint8_t chNum)
64 {
65     return getChannelConfigObject().isValidChannel(chNum);
66 }
67 
isValidAuthType(const uint8_t chNum,const EAuthType & authType)68 bool isValidAuthType(const uint8_t chNum, const EAuthType& authType)
69 {
70     return getChannelConfigObject().isValidAuthType(chNum, authType);
71 }
72 
getChannelSessionSupport(const uint8_t chNum)73 EChannelSessSupported getChannelSessionSupport(const uint8_t chNum)
74 {
75     return getChannelConfigObject().getChannelSessionSupport(chNum);
76 }
77 
getChannelActiveSessions(const uint8_t chNum)78 int getChannelActiveSessions(const uint8_t chNum)
79 {
80     return getChannelConfigObject().getChannelActiveSessions(chNum);
81 }
82 
getChannelMaxTransferSize(uint8_t chNum)83 size_t getChannelMaxTransferSize(uint8_t chNum)
84 {
85     return getChannelConfigObject().getChannelMaxTransferSize(chNum);
86 }
87 
ipmiChannelInit()88 Cc ipmiChannelInit()
89 {
90     getChannelConfigObject();
91     getCipherConfigObject(csPrivFileName, csPrivDefaultFileName);
92     return ccSuccess;
93 }
94 
getChannelInfo(const uint8_t chNum,ChannelInfo & chInfo)95 Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo)
96 {
97     return getChannelConfigObject().getChannelInfo(chNum, chInfo);
98 }
99 
getChannelAccessData(const uint8_t chNum,ChannelAccess & chAccessData)100 Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData)
101 {
102     return getChannelConfigObject().getChannelAccessData(chNum, chAccessData);
103 }
104 
setChannelAccessData(const uint8_t chNum,const ChannelAccess & chAccessData,const uint8_t setFlag)105 Cc setChannelAccessData(const uint8_t chNum, const ChannelAccess& chAccessData,
106                         const uint8_t setFlag)
107 {
108     return getChannelConfigObject().setChannelAccessData(chNum, chAccessData,
109                                                          setFlag);
110 }
111 
getChannelAccessPersistData(const uint8_t chNum,ChannelAccess & chAccessData)112 Cc getChannelAccessPersistData(const uint8_t chNum, ChannelAccess& chAccessData)
113 {
114     return getChannelConfigObject().getChannelAccessPersistData(
115         chNum, chAccessData);
116 }
117 
setChannelAccessPersistData(const uint8_t chNum,const ChannelAccess & chAccessData,const uint8_t setFlag)118 Cc setChannelAccessPersistData(const uint8_t chNum,
119                                const ChannelAccess& chAccessData,
120                                const uint8_t setFlag)
121 {
122     return getChannelConfigObject().setChannelAccessPersistData(
123         chNum, chAccessData, setFlag);
124 }
125 
getChannelAuthTypeSupported(const uint8_t chNum,uint8_t & authTypeSupported)126 Cc getChannelAuthTypeSupported(const uint8_t chNum, uint8_t& authTypeSupported)
127 {
128     return getChannelConfigObject().getChannelAuthTypeSupported(
129         chNum, authTypeSupported);
130 }
131 
getChannelEnabledAuthType(const uint8_t chNum,const uint8_t priv,EAuthType & authType)132 Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
133                              EAuthType& authType)
134 {
135     return getChannelConfigObject().getChannelEnabledAuthType(
136         chNum, priv, authType);
137 }
138 
getChannelName(const uint8_t chNum)139 std::string getChannelName(const uint8_t chNum)
140 {
141     return getChannelConfigObject().getChannelName(chNum);
142 }
143 
getChannelByName(const std::string & chName)144 uint8_t getChannelByName(const std::string& chName)
145 {
146     return getChannelConfigObject().getChannelByName(chName);
147 }
148 
isValidPayloadType(const PayloadType payloadType)149 bool isValidPayloadType(const PayloadType payloadType)
150 {
151     return (
152         payloadType == PayloadType::IPMI || payloadType == PayloadType::SOL ||
153         payloadType == PayloadType::OPEN_SESSION_REQUEST ||
154         payloadType == PayloadType::OPEN_SESSION_RESPONSE ||
155         payloadType == PayloadType::RAKP1 ||
156         payloadType == PayloadType::RAKP2 ||
157         payloadType == PayloadType::RAKP3 || payloadType == PayloadType::RAKP4);
158 }
159 } // namespace ipmi
160