AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 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" |
Sumanth Bhat | e4e633e | 2019-05-14 12:13:57 +0000 | [diff] [blame] | 20 | #include "cipher_mgmt.hpp" |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 21 | |
| 22 | #include <phosphor-logging/log.hpp> |
| 23 | |
| 24 | namespace ipmi |
| 25 | { |
| 26 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 27 | bool doesDeviceExist(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 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 |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 32 | struct stat fileStat = {}; |
Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 33 | std::string devName("/sys/class/net/" + getChannelName(chNum)); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 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 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 45 | bool isValidPrivLimit(const uint8_t privLimit) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 46 | { |
jayaprakash Mutyala | 0e2dbee | 2019-12-26 13:03:04 +0000 | [diff] [blame] | 47 | // Callback privilege is deprecated in OpenBMC |
srikanta mondal | 785223a | 2020-04-10 11:35:32 +0000 | [diff] [blame] | 48 | // At present, "OEM Privilege" is not used in OpenBMC |
| 49 | return ((privLimit > PRIVILEGE_CALLBACK) && (privLimit < PRIVILEGE_OEM)); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 50 | } |
| 51 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 52 | bool isValidAccessMode(const uint8_t accessMode) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 53 | { |
PavanKumarIntel | 3771f5f | 2023-11-02 06:26:42 +0000 | [diff] [blame] | 54 | return (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared)); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 55 | } |
| 56 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 57 | bool isValidChannel(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 58 | { |
| 59 | return getChannelConfigObject().isValidChannel(chNum); |
| 60 | } |
| 61 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 62 | bool isValidAuthType(const uint8_t chNum, const EAuthType& authType) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 63 | { |
| 64 | return getChannelConfigObject().isValidAuthType(chNum, authType); |
| 65 | } |
| 66 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 67 | EChannelSessSupported getChannelSessionSupport(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 68 | { |
| 69 | return getChannelConfigObject().getChannelSessionSupport(chNum); |
| 70 | } |
| 71 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 72 | int getChannelActiveSessions(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 73 | { |
| 74 | return getChannelConfigObject().getChannelActiveSessions(chNum); |
| 75 | } |
| 76 | |
Vernon Mauery | 5831712 | 2018-11-28 11:02:43 -0800 | [diff] [blame] | 77 | size_t getChannelMaxTransferSize(uint8_t chNum) |
| 78 | { |
| 79 | return getChannelConfigObject().getChannelMaxTransferSize(chNum); |
| 80 | } |
| 81 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 82 | Cc ipmiChannelInit() |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 83 | { |
| 84 | getChannelConfigObject(); |
Sumanth Bhat | e4e633e | 2019-05-14 12:13:57 +0000 | [diff] [blame] | 85 | getCipherConfigObject(csPrivFileName, csPrivDefaultFileName); |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 86 | return ccSuccess; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 87 | } |
| 88 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 89 | Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 90 | { |
| 91 | return getChannelConfigObject().getChannelInfo(chNum, chInfo); |
| 92 | } |
| 93 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 94 | Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 95 | { |
| 96 | return getChannelConfigObject().getChannelAccessData(chNum, chAccessData); |
| 97 | } |
| 98 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 99 | Cc setChannelAccessData(const uint8_t chNum, const ChannelAccess& chAccessData, |
| 100 | const uint8_t setFlag) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 101 | { |
| 102 | return getChannelConfigObject().setChannelAccessData(chNum, chAccessData, |
| 103 | setFlag); |
| 104 | } |
| 105 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 106 | Cc getChannelAccessPersistData(const uint8_t chNum, ChannelAccess& chAccessData) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 107 | { |
| 108 | return getChannelConfigObject().getChannelAccessPersistData(chNum, |
| 109 | chAccessData); |
| 110 | } |
| 111 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 112 | Cc setChannelAccessPersistData(const uint8_t chNum, |
| 113 | const ChannelAccess& chAccessData, |
| 114 | const uint8_t setFlag) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 115 | { |
| 116 | return getChannelConfigObject().setChannelAccessPersistData( |
| 117 | chNum, chAccessData, setFlag); |
| 118 | } |
| 119 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 120 | Cc getChannelAuthTypeSupported(const uint8_t chNum, uint8_t& authTypeSupported) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 121 | { |
| 122 | return getChannelConfigObject().getChannelAuthTypeSupported( |
| 123 | chNum, authTypeSupported); |
| 124 | } |
| 125 | |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 126 | Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv, |
| 127 | EAuthType& authType) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 128 | { |
| 129 | return getChannelConfigObject().getChannelEnabledAuthType(chNum, priv, |
| 130 | authType); |
| 131 | } |
| 132 | |
Richard Marian Thomaiyar | 55768e3 | 2019-03-02 22:54:37 +0530 | [diff] [blame] | 133 | std::string getChannelName(const uint8_t chNum) |
Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 134 | { |
| 135 | return getChannelConfigObject().getChannelName(chNum); |
| 136 | } |
| 137 | |
Vernon Mauery | 735ee95 | 2019-02-15 13:38:52 -0800 | [diff] [blame] | 138 | uint8_t getChannelByName(const std::string& chName) |
| 139 | { |
| 140 | return getChannelConfigObject().getChannelByName(chName); |
| 141 | } |
Ayushi Smriti | 6fd812d | 2019-04-12 18:51:31 +0000 | [diff] [blame] | 142 | |
| 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 | } |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 153 | } // namespace ipmi |