Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +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 |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 17 | |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 18 | #include <bitset> |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 19 | #include <ipmid/api.hpp> |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 20 | #include <string> |
| 21 | |
| 22 | namespace ipmi |
| 23 | { |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 24 | |
| 25 | // TODO: Has to be replaced with proper channel number assignment logic |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 26 | /** |
| 27 | * @enum Channel Id |
| 28 | */ |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 29 | enum class EChannelID : uint8_t |
| 30 | { |
| 31 | chanLan1 = 0x01 |
| 32 | }; |
| 33 | |
| 34 | static constexpr uint8_t invalidUserId = 0xFF; |
| 35 | static constexpr uint8_t reservedUserId = 0x0; |
| 36 | static constexpr uint8_t ipmiMaxUserName = 16; |
| 37 | static constexpr uint8_t ipmiMaxUsers = 15; |
| 38 | static constexpr uint8_t ipmiMaxChannels = 16; |
Suryakanth Sekar | 90b00c7 | 2019-01-16 10:37:57 +0530 | [diff] [blame] | 39 | static constexpr uint8_t maxIpmi20PasswordSize = 20; |
| 40 | static constexpr uint8_t maxIpmi15PasswordSize = 16; |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 41 | static constexpr uint8_t payloadsPerByte = 8; |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 42 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 43 | /** @struct PrivAccess |
| 44 | * |
| 45 | * User privilege related access data as per IPMI specification.(refer spec |
| 46 | * sec 22.26) |
| 47 | */ |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 48 | struct PrivAccess |
| 49 | { |
| 50 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 51 | uint8_t privilege : 4; |
| 52 | uint8_t ipmiEnabled : 1; |
| 53 | uint8_t linkAuthEnabled : 1; |
| 54 | uint8_t accessCallback : 1; |
| 55 | uint8_t reserved : 1; |
| 56 | #endif |
| 57 | #if BYTE_ORDER == BIG_ENDIAN |
| 58 | uint8_t reserved : 1; |
| 59 | uint8_t accessCallback : 1; |
| 60 | uint8_t linkAuthEnabled : 1; |
| 61 | uint8_t ipmiEnabled : 1; |
| 62 | uint8_t privilege : 4; |
| 63 | #endif |
| 64 | } __attribute__((packed)); |
| 65 | |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 66 | /** @struct UserPayloadAccess |
| 67 | * |
| 68 | * Structure to denote payload access restrictions applicable for a |
| 69 | * given user and channel. (refer spec sec 24.6) |
| 70 | */ |
| 71 | struct PayloadAccess |
| 72 | { |
| 73 | std::bitset<payloadsPerByte> stdPayloadEnables1; |
| 74 | std::bitset<payloadsPerByte> stdPayloadEnables2Reserved; |
| 75 | std::bitset<payloadsPerByte> oemPayloadEnables1; |
| 76 | std::bitset<payloadsPerByte> oemPayloadEnables2Reserved; |
| 77 | }; |
| 78 | |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 79 | /** @brief initializes user management |
| 80 | * |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 81 | * @return ccSuccess for success, others for failure. |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 82 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 83 | Cc ipmiUserInit(); |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 84 | |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 85 | /** @brief The ipmi get user password layer call |
| 86 | * |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 87 | * @param[in] userName - user name |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 88 | * |
| 89 | * @return password or empty string |
| 90 | */ |
| 91 | std::string ipmiUserGetPassword(const std::string& userName); |
| 92 | |
AppaRao Puli | b29b5ab | 2018-05-17 10:28:48 +0530 | [diff] [blame] | 93 | /** @brief The IPMI call to clear password entry associated with specified |
| 94 | * username |
| 95 | * |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 96 | * @param[in] userName - user name to be removed |
AppaRao Puli | b29b5ab | 2018-05-17 10:28:48 +0530 | [diff] [blame] | 97 | * |
| 98 | * @return 0 on success, non-zero otherwise. |
| 99 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 100 | Cc ipmiClearUserEntryPassword(const std::string& userName); |
Richard Marian Thomaiyar | 42bed64 | 2018-09-21 12:28:57 +0530 | [diff] [blame] | 101 | |
| 102 | /** @brief The IPMI call to reuse password entry for the renamed user |
| 103 | * to another one |
| 104 | * |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 105 | * @param[in] userName - user name which has to be renamed |
| 106 | * @param[in] newUserName - new user name |
Richard Marian Thomaiyar | 42bed64 | 2018-09-21 12:28:57 +0530 | [diff] [blame] | 107 | * |
| 108 | * @return 0 on success, non-zero otherwise. |
| 109 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 110 | Cc ipmiRenameUserEntryPassword(const std::string& userName, |
| 111 | const std::string& newUserName); |
AppaRao Puli | b29b5ab | 2018-05-17 10:28:48 +0530 | [diff] [blame] | 112 | |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 113 | /** @brief determines valid userId |
| 114 | * |
| 115 | * @param[in] userId - user id |
| 116 | * |
| 117 | * @return true if valid, false otherwise |
| 118 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 119 | bool ipmiUserIsValidUserId(const uint8_t userId); |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 120 | |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 121 | /** @brief determines valid privilege level |
| 122 | * |
| 123 | * @param[in] priv - privilege level |
| 124 | * |
| 125 | * @return true if valid, false otherwise |
| 126 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 127 | bool ipmiUserIsValidPrivilege(const uint8_t priv); |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 128 | |
| 129 | /** @brief get user id corresponding to the user name |
| 130 | * |
| 131 | * @param[in] userName - user name |
| 132 | * |
| 133 | * @return userid. Will return 0xff if no user id found |
| 134 | */ |
| 135 | uint8_t ipmiUserGetUserId(const std::string& userName); |
| 136 | |
| 137 | /** @brief set's user name |
jayaprakash Mutyala | cdcdf2b | 2020-03-28 00:12:05 +0000 | [diff] [blame] | 138 | * This API is deprecated |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 139 | */ |
jayaprakash Mutyala | cdcdf2b | 2020-03-28 00:12:05 +0000 | [diff] [blame] | 140 | Cc ipmiUserSetUserName(const uint8_t userId, const char* userName) |
| 141 | __attribute__((deprecated)); |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 142 | |
jayaprakash Mutyala | 7636330 | 2020-02-14 23:50:38 +0000 | [diff] [blame] | 143 | /** @brief set's user name |
| 144 | * |
| 145 | * @param[in] userId - user id |
| 146 | * @param[in] userName - user name |
| 147 | * |
| 148 | * @return ccSuccess for success, others for failure. |
| 149 | */ |
| 150 | Cc ipmiUserSetUserName(const uint8_t userId, const std::string& userName); |
| 151 | |
Suryakanth Sekar | 90b00c7 | 2019-01-16 10:37:57 +0530 | [diff] [blame] | 152 | /** @brief set user password |
| 153 | * |
| 154 | * @param[in] userId - user id |
| 155 | * @param[in] userPassword - New Password |
| 156 | * |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 157 | * @return ccSuccess for success, others for failure. |
Suryakanth Sekar | 90b00c7 | 2019-01-16 10:37:57 +0530 | [diff] [blame] | 158 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 159 | Cc ipmiUserSetUserPassword(const uint8_t userId, const char* userPassword); |
Suryakanth Sekar | 90b00c7 | 2019-01-16 10:37:57 +0530 | [diff] [blame] | 160 | |
Richard Marian Thomaiyar | 788362c | 2019-04-14 15:12:47 +0530 | [diff] [blame] | 161 | /** @brief set special user password (non-ipmi accounts) |
| 162 | * |
| 163 | * @param[in] userName - user name |
| 164 | * @param[in] userPassword - New Password |
| 165 | * |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 166 | * @return ccSuccess for success, others for failure. |
Richard Marian Thomaiyar | 788362c | 2019-04-14 15:12:47 +0530 | [diff] [blame] | 167 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 168 | Cc ipmiSetSpecialUserPassword(const std::string& userName, |
| 169 | const std::string& userPassword); |
Richard Marian Thomaiyar | 788362c | 2019-04-14 15:12:47 +0530 | [diff] [blame] | 170 | |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 171 | /** @brief get user name |
| 172 | * |
| 173 | * @param[in] userId - user id |
| 174 | * @param[out] userName - user name |
| 175 | * |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 176 | * @return ccSuccess for success, others for failure. |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 177 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 178 | Cc ipmiUserGetUserName(const uint8_t userId, std::string& userName); |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 179 | |
| 180 | /** @brief provides available fixed, max, and enabled user counts |
| 181 | * |
| 182 | * @param[out] maxChUsers - max channel users |
| 183 | * @param[out] enabledUsers - enabled user count |
| 184 | * @param[out] fixedUsers - fixed user count |
| 185 | * |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 186 | * @return ccSuccess for success, others for failure. |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 187 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 188 | Cc ipmiUserGetAllCounts(uint8_t& maxChUsers, uint8_t& enabledUsers, |
| 189 | uint8_t& fixedUsers); |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 190 | |
Richard Marian Thomaiyar | 282e79b | 2018-11-13 19:00:58 +0530 | [diff] [blame] | 191 | /** @brief function to update user enabled state |
| 192 | * |
| 193 | * @param[in] userId - user id |
| 194 | *..@param[in] state - state of the user to be updated, true - user enabled. |
| 195 | * |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 196 | * @return ccSuccess for success, others for failure. |
Richard Marian Thomaiyar | 282e79b | 2018-11-13 19:00:58 +0530 | [diff] [blame] | 197 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 198 | Cc ipmiUserUpdateEnabledState(const uint8_t userId, const bool& state); |
Richard Marian Thomaiyar | 282e79b | 2018-11-13 19:00:58 +0530 | [diff] [blame] | 199 | |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 200 | /** @brief determines whether user is enabled |
| 201 | * |
| 202 | * @param[in] userId - user id |
| 203 | *..@param[out] state - state of the user |
| 204 | * |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 205 | * @return ccSuccess for success, others for failure. |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 206 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 207 | Cc ipmiUserCheckEnabled(const uint8_t userId, bool& state); |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 208 | |
| 209 | /** @brief provides user privilege access data |
| 210 | * |
| 211 | * @param[in] userId - user id |
| 212 | * @param[in] chNum - channel number |
| 213 | * @param[out] privAccess - privilege access data |
| 214 | * |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 215 | * @return ccSuccess for success, others for failure. |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 216 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 217 | Cc ipmiUserGetPrivilegeAccess(const uint8_t userId, const uint8_t chNum, |
| 218 | PrivAccess& privAccess); |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 219 | |
| 220 | /** @brief sets user privilege access data |
| 221 | * |
| 222 | * @param[in] userId - user id |
| 223 | * @param[in] chNum - channel number |
| 224 | * @param[in] privAccess - privilege access data |
| 225 | * @param[in] otherPrivUpdate - flags to indicate other fields update |
| 226 | * |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 227 | * @return ccSuccess for success, others for failure. |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 228 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 229 | Cc ipmiUserSetPrivilegeAccess(const uint8_t userId, const uint8_t chNum, |
| 230 | const PrivAccess& privAccess, |
| 231 | const bool& otherPrivUpdate); |
Richard Marian Thomaiyar | 5a6b636 | 2018-03-12 23:42:34 +0530 | [diff] [blame] | 232 | |
Ayushi Smriti | 02650d5 | 2019-05-15 11:59:09 +0000 | [diff] [blame] | 233 | /** @brief check for user pam authentication. This is to determine, whether user |
| 234 | * is already locked out for failed login attempt |
| 235 | * |
| 236 | * @param[in] username - username |
| 237 | * @param[in] password - password |
| 238 | * |
| 239 | * @return status |
| 240 | */ |
| 241 | bool ipmiUserPamAuthenticate(std::string_view userName, |
| 242 | std::string_view userPassword); |
| 243 | |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 244 | /** @brief sets user payload access data |
| 245 | * |
| 246 | * @param[in] chNum - channel number |
| 247 | * @param[in] operation - ENABLE / DISABLE operation |
| 248 | * @param[in] userId - user id |
| 249 | * @param[in] payloadAccess - payload access data |
| 250 | * |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 251 | * @return ccSuccess for success, others for failure. |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 252 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 253 | Cc ipmiUserSetUserPayloadAccess(const uint8_t chNum, const uint8_t operation, |
| 254 | const uint8_t userId, |
| 255 | const PayloadAccess& payloadAccess); |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 256 | |
| 257 | /** @brief provides user payload access data |
| 258 | * |
| 259 | * @param[in] chNum - channel number |
| 260 | * @param[in] userId - user id |
| 261 | * @param[out] payloadAccess - payload access data |
| 262 | * |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 263 | * @return ccSuccess for success, others for failure. |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 264 | */ |
NITIN SHARMA | b541a5a | 2019-07-18 12:46:59 +0000 | [diff] [blame] | 265 | Cc ipmiUserGetUserPayloadAccess(const uint8_t chNum, const uint8_t userId, |
| 266 | PayloadAccess& payloadAccess); |
Saravanan Palanisamy | 77381f1 | 2019-05-15 22:33:17 +0000 | [diff] [blame] | 267 | |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 268 | } // namespace ipmi |