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" |
| 20 | |
| 21 | #include <phosphor-logging/log.hpp> |
| 22 | |
| 23 | namespace ipmi |
| 24 | { |
| 25 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 26 | bool doesDeviceExist(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 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 | |
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 | { |
| 47 | return ((privLimit >= PRIVILEGE_CALLBACK) && (privLimit <= PRIVILEGE_OEM)); |
| 48 | } |
| 49 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 50 | bool isValidAccessMode(const uint8_t accessMode) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 51 | { |
| 52 | return ( |
| 53 | (accessMode >= static_cast<uint8_t>(EChannelAccessMode::disabled)) && |
| 54 | (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared))); |
| 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 | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 62 | uint8_t convertCurrentChannelNum(const uint8_t chNum) |
| 63 | { |
| 64 | return getChannelConfigObject().convertToChannelIndexNumber(chNum); |
| 65 | } |
| 66 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 67 | bool isValidAuthType(const uint8_t chNum, const EAuthType& authType) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 68 | { |
| 69 | return getChannelConfigObject().isValidAuthType(chNum, authType); |
| 70 | } |
| 71 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 72 | EChannelSessSupported getChannelSessionSupport(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 73 | { |
| 74 | return getChannelConfigObject().getChannelSessionSupport(chNum); |
| 75 | } |
| 76 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 77 | int getChannelActiveSessions(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 78 | { |
| 79 | return getChannelConfigObject().getChannelActiveSessions(chNum); |
| 80 | } |
| 81 | |
| 82 | ipmi_ret_t ipmiChannelInit() |
| 83 | { |
| 84 | getChannelConfigObject(); |
| 85 | return IPMI_CC_OK; |
| 86 | } |
| 87 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 88 | ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 89 | { |
| 90 | return getChannelConfigObject().getChannelInfo(chNum, chInfo); |
| 91 | } |
| 92 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 93 | ipmi_ret_t getChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 94 | ChannelAccess& chAccessData) |
| 95 | { |
| 96 | return getChannelConfigObject().getChannelAccessData(chNum, chAccessData); |
| 97 | } |
| 98 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 99 | ipmi_ret_t setChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 100 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 101 | const uint8_t setFlag) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 102 | { |
| 103 | return getChannelConfigObject().setChannelAccessData(chNum, chAccessData, |
| 104 | setFlag); |
| 105 | } |
| 106 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 107 | ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 108 | ChannelAccess& chAccessData) |
| 109 | { |
| 110 | return getChannelConfigObject().getChannelAccessPersistData(chNum, |
| 111 | chAccessData); |
| 112 | } |
| 113 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 114 | ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 115 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 116 | const uint8_t setFlag) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 117 | { |
| 118 | return getChannelConfigObject().setChannelAccessPersistData( |
| 119 | chNum, chAccessData, setFlag); |
| 120 | } |
| 121 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 122 | ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 123 | uint8_t& authTypeSupported) |
| 124 | { |
| 125 | return getChannelConfigObject().getChannelAuthTypeSupported( |
| 126 | chNum, authTypeSupported); |
| 127 | } |
| 128 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 129 | ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 130 | EAuthType& authType) |
| 131 | { |
| 132 | return getChannelConfigObject().getChannelEnabledAuthType(chNum, priv, |
| 133 | authType); |
| 134 | } |
| 135 | |
| 136 | } // namespace ipmi |