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 | #pragma once |
| 17 | #include <host-ipmid/ipmid-api.h> |
| 18 | |
| 19 | #include <string> |
| 20 | |
| 21 | namespace ipmi |
| 22 | { |
| 23 | |
| 24 | static constexpr uint8_t maxIpmiChannels = 16; |
ssekar | f4b2b09 | 2018-07-25 18:49:08 +0530 | [diff] [blame] | 25 | static constexpr uint8_t selfChNum = 0xE; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 26 | |
| 27 | // IPMI return codes specific to channel |
| 28 | enum ipmi_channel_return_codes |
| 29 | { |
| 30 | IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL = 0x82, |
| 31 | IPMI_CC_ACCESS_MODE_NOT_SUPPORTED_FOR_CHANEL = 0x83 |
| 32 | }; |
| 33 | |
| 34 | // IPMI Spec: Channel Protocol Type |
| 35 | enum class EChannelProtocolType : uint8_t |
| 36 | { |
| 37 | na = 0x00, |
| 38 | ipmbV10 = 0x01, |
| 39 | icmbV11 = 0x02, |
| 40 | reserved = 0x03, |
| 41 | ipmiSmbus = 0x04, |
| 42 | kcs = 0x05, |
| 43 | smic = 0x06, |
| 44 | bt10 = 0x07, |
| 45 | bt15 = 0x08, |
| 46 | tMode = 0x09, |
| 47 | oem = 0x1C, |
| 48 | }; |
| 49 | |
| 50 | // IPMI Spec: Channel Medium Type |
| 51 | enum class EChannelMediumType : uint8_t |
| 52 | { |
| 53 | reserved = 0x00, |
| 54 | ipmb = 0x01, |
| 55 | icmbV10 = 0x02, |
| 56 | icmbV09 = 0x03, |
| 57 | lan8032 = 0x04, |
| 58 | serial = 0x05, |
| 59 | otherLan = 0x06, |
| 60 | pciSmbus = 0x07, |
| 61 | smbusV11 = 0x08, |
| 62 | smbusV20 = 0x09, |
| 63 | usbV1x = 0x0A, |
| 64 | usbV2x = 0x0B, |
| 65 | systemInterface = 0x0C, |
| 66 | oem = 0x60, |
| 67 | unknown = 0x82, |
| 68 | }; |
| 69 | |
| 70 | // IPMI Spec: Channel Session Type |
| 71 | enum class EChannelSessSupported : uint8_t |
| 72 | { |
| 73 | none = 0, |
| 74 | single = 1, |
| 75 | multi = 2, |
| 76 | any = 3, |
| 77 | }; |
| 78 | |
| 79 | // IPMI Spec: Channel Access Mode |
| 80 | enum class EChannelAccessMode : uint8_t |
| 81 | { |
| 82 | disabled = 0, |
| 83 | preboot = 1, |
| 84 | alwaysAvail = 2, |
| 85 | shared = 3, |
| 86 | }; |
| 87 | |
| 88 | // IPMI Spec 2.0 : Authentication Types |
| 89 | enum class EAuthType : uint8_t |
| 90 | { |
| 91 | none = (1 << 0x0), |
| 92 | md2 = (1 << 0x1), |
| 93 | md5 = (1 << 0x2), |
| 94 | reserved = (1 << 0x3), |
| 95 | straightPasswd = (1 << 0x4), |
| 96 | oem = (1 << 0x5), |
| 97 | }; |
| 98 | |
| 99 | // IPMI Spec: Access mode for channel access set/get |
| 100 | typedef enum |
| 101 | { |
| 102 | doNotSet = 0x00, |
| 103 | nvData = 0x01, |
| 104 | activeData = 0x02, |
| 105 | reserved = 0x03, |
| 106 | } EChannelActionType; |
| 107 | |
| 108 | enum AccessSetFlag |
| 109 | { |
| 110 | setAccessMode = (1 << 0), |
| 111 | setUserAuthEnabled = (1 << 1), |
| 112 | setMsgAuthEnabled = (1 << 2), |
| 113 | setAlertingEnabled = (1 << 3), |
| 114 | setPrivLimit = (1 << 4), |
| 115 | }; |
| 116 | |
| 117 | // Struct to store channel access data |
| 118 | struct ChannelAccess |
| 119 | { |
| 120 | uint8_t accessMode; |
| 121 | bool userAuthDisabled; |
| 122 | bool perMsgAuthDisabled; |
| 123 | bool alertingDisabled; |
| 124 | uint8_t privLimit; |
| 125 | }; |
| 126 | |
| 127 | // Struct store channel info data |
| 128 | struct ChannelInfo |
| 129 | { |
| 130 | uint8_t mediumType; |
| 131 | uint8_t protocolType; |
| 132 | uint8_t sessionSupported; |
| 133 | bool isIpmi; // Is session IPMI |
| 134 | // This is used in Get LAN Configuration parameter. |
| 135 | // This holds the supported AuthTypes for a given channel. |
| 136 | uint8_t authTypeSupported; |
| 137 | }; |
| 138 | |
| 139 | /** @brief determines valid channel |
| 140 | * |
| 141 | * @param[in] chNum- channel number |
| 142 | * |
| 143 | * @return true if valid, false otherwise |
| 144 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 145 | bool isValidChannel(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 146 | |
| 147 | /** @brief determines whether channel device exist |
| 148 | * |
| 149 | * @param[in] chNum - channel number |
| 150 | * |
| 151 | * @return true if valid, false otherwise |
| 152 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 153 | bool doesDeviceExist(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 154 | |
| 155 | /** @brief determines whether privilege limit is valid |
| 156 | * |
| 157 | * @param[in] privLimit - Privilege limit |
| 158 | * |
| 159 | * @return true if valid, false otherwise |
| 160 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 161 | bool isValidPrivLimit(const uint8_t privLimit); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 162 | |
| 163 | /** @brief determines whether access mode is valid |
| 164 | * |
| 165 | * @param[in] accessMode - Access mode |
| 166 | * |
| 167 | * @return true if valid, false otherwise |
| 168 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 169 | bool isValidAccessMode(const uint8_t accessMode); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 170 | |
| 171 | /** @brief determines valid authentication type based on channel number |
| 172 | * |
| 173 | * @param[in] chNum - channel number |
| 174 | * @param[in] authType - authentication type |
| 175 | * |
| 176 | * @return true if valid, false otherwise |
| 177 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 178 | bool isValidAuthType(const uint8_t chNum, const EAuthType& authType); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 179 | |
| 180 | /** @brief determines supported session type of a channel |
| 181 | * |
| 182 | * @param[in] chNum - channel number |
| 183 | * |
| 184 | * @return EChannelSessSupported - supported session type |
| 185 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 186 | EChannelSessSupported getChannelSessionSupport(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 187 | |
| 188 | /** @brief determines number of active sessions on a channel |
| 189 | * |
| 190 | * @param[in] chNum - channel number |
| 191 | * |
| 192 | * @return numer of active sessions |
| 193 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 194 | int getChannelActiveSessions(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 195 | |
| 196 | /** @brief initializes channel management |
| 197 | * |
| 198 | * @return IPMI_CC_OK for success, others for failure. |
| 199 | */ |
| 200 | ipmi_ret_t ipmiChannelInit(); |
| 201 | |
| 202 | /** @brief provides channel info details |
| 203 | * |
| 204 | * @param[in] chNum - channel number |
| 205 | * @param[out] chInfo - channel info details |
| 206 | * |
| 207 | * @return IPMI_CC_OK for success, others for failure. |
| 208 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 209 | ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 210 | |
| 211 | /** @brief provides channel access data |
| 212 | * |
| 213 | * @param[in] chNum - channel number |
| 214 | * @param[out] chAccessData -channel access data |
| 215 | * |
| 216 | * @return IPMI_CC_OK for success, others for failure. |
| 217 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 218 | ipmi_ret_t getChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 219 | ChannelAccess& chAccessData); |
| 220 | |
| 221 | /** @brief to set channel access data |
| 222 | * |
| 223 | * @param[in] chNum - channel number |
| 224 | * @param[in] chAccessData - channel access data |
| 225 | * @param[in] setFlag - flag to indicate updatable fields |
| 226 | * |
| 227 | * @return IPMI_CC_OK for success, others for failure. |
| 228 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 229 | ipmi_ret_t setChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 230 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 231 | const uint8_t setFlag); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 232 | |
| 233 | /** @brief to get channel access data persistent data |
| 234 | * |
| 235 | * @param[in] chNum - channel number |
| 236 | * @param[out] chAccessData - channel access data |
| 237 | * |
| 238 | * @return IPMI_CC_OK for success, others for failure. |
| 239 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 240 | ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 241 | ChannelAccess& chAccessData); |
| 242 | |
| 243 | /** @brief to set channel access data persistent data |
| 244 | * |
| 245 | * @param[in] chNum - channel number |
| 246 | * @param[in] chAccessData - channel access data |
| 247 | * @param[in] setFlag - flag to indicate updatable fields |
| 248 | * |
| 249 | * @return IPMI_CC_OK for success, others for failure. |
| 250 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 251 | ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 252 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 253 | const uint8_t setFlag); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 254 | |
| 255 | /** @brief provides supported authentication type for the channel |
| 256 | * |
| 257 | * @param[in] chNum - channel number |
| 258 | * @param[out] authTypeSupported - supported authentication type |
| 259 | * |
| 260 | * @return IPMI_CC_OK for success, others for failure. |
| 261 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 262 | ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 263 | uint8_t& authTypeSupported); |
| 264 | |
| 265 | /** @brief provides enabled authentication type for the channel |
| 266 | * |
| 267 | * @param[in] chNum - channel number |
| 268 | * @param[in] priv - privilege |
| 269 | * @param[out] authType - enabled authentication type |
| 270 | * |
| 271 | * @return IPMI_CC_OK for success, others for failure. |
| 272 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 273 | ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 274 | EAuthType& authType); |
| 275 | |
| 276 | } // namespace ipmi |