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 |
Richard Marian Thomaiyar | 73906b9 | 2019-01-04 23:48:02 +0530 | [diff] [blame] | 31 | struct stat fileStat = {0}; |
Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 32 | std::string devName("/sys/class/net/" + getChannelName(chNum)); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 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 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 44 | bool isValidPrivLimit(const uint8_t privLimit) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 45 | { |
| 46 | return ((privLimit >= PRIVILEGE_CALLBACK) && (privLimit <= PRIVILEGE_OEM)); |
| 47 | } |
| 48 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 49 | bool isValidAccessMode(const uint8_t accessMode) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 50 | { |
| 51 | return ( |
| 52 | (accessMode >= static_cast<uint8_t>(EChannelAccessMode::disabled)) && |
| 53 | (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared))); |
| 54 | } |
| 55 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 56 | bool isValidChannel(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 57 | { |
| 58 | return getChannelConfigObject().isValidChannel(chNum); |
| 59 | } |
| 60 | |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 61 | uint8_t convertCurrentChannelNum(const uint8_t chNum) |
| 62 | { |
| 63 | return getChannelConfigObject().convertToChannelIndexNumber(chNum); |
| 64 | } |
| 65 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 66 | bool isValidAuthType(const uint8_t chNum, const EAuthType& authType) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 67 | { |
| 68 | return getChannelConfigObject().isValidAuthType(chNum, authType); |
| 69 | } |
| 70 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 71 | EChannelSessSupported getChannelSessionSupport(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 72 | { |
| 73 | return getChannelConfigObject().getChannelSessionSupport(chNum); |
| 74 | } |
| 75 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 76 | int getChannelActiveSessions(const uint8_t chNum) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 77 | { |
| 78 | return getChannelConfigObject().getChannelActiveSessions(chNum); |
| 79 | } |
| 80 | |
Vernon Mauery | 5831712 | 2018-11-28 11:02:43 -0800 | [diff] [blame] | 81 | size_t getChannelMaxTransferSize(uint8_t chNum) |
| 82 | { |
| 83 | return getChannelConfigObject().getChannelMaxTransferSize(chNum); |
| 84 | } |
| 85 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 86 | ipmi_ret_t ipmiChannelInit() |
| 87 | { |
| 88 | getChannelConfigObject(); |
| 89 | return IPMI_CC_OK; |
| 90 | } |
| 91 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 92 | ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 93 | { |
| 94 | return getChannelConfigObject().getChannelInfo(chNum, chInfo); |
| 95 | } |
| 96 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 97 | ipmi_ret_t getChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 98 | ChannelAccess& chAccessData) |
| 99 | { |
| 100 | return getChannelConfigObject().getChannelAccessData(chNum, chAccessData); |
| 101 | } |
| 102 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 103 | ipmi_ret_t setChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 104 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 105 | const uint8_t setFlag) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 106 | { |
| 107 | return getChannelConfigObject().setChannelAccessData(chNum, chAccessData, |
| 108 | setFlag); |
| 109 | } |
| 110 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 111 | ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 112 | ChannelAccess& chAccessData) |
| 113 | { |
| 114 | return getChannelConfigObject().getChannelAccessPersistData(chNum, |
| 115 | chAccessData); |
| 116 | } |
| 117 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 118 | ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 119 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 120 | const uint8_t setFlag) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 121 | { |
| 122 | return getChannelConfigObject().setChannelAccessPersistData( |
| 123 | chNum, chAccessData, setFlag); |
| 124 | } |
| 125 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 126 | ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 127 | uint8_t& authTypeSupported) |
| 128 | { |
| 129 | return getChannelConfigObject().getChannelAuthTypeSupported( |
| 130 | chNum, authTypeSupported); |
| 131 | } |
| 132 | |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 133 | ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 134 | EAuthType& authType) |
| 135 | { |
| 136 | return getChannelConfigObject().getChannelEnabledAuthType(chNum, priv, |
| 137 | authType); |
| 138 | } |
| 139 | |
Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 140 | std::string getChannelName(const int chNum) |
| 141 | { |
| 142 | return getChannelConfigObject().getChannelName(chNum); |
| 143 | } |
| 144 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 145 | } // namespace ipmi |