blob: ce985df79093774b7bbd86e3c2e5212ebee80cdb [file] [log] [blame]
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +05301/*
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
21namespace ipmi
22{
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053023
24// TODO: Has to be replaced with proper channel number assignment logic
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053025/**
26 * @enum Channel Id
27 */
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053028enum class EChannelID : uint8_t
29{
30 chanLan1 = 0x01
31};
32
33static constexpr uint8_t invalidUserId = 0xFF;
34static constexpr uint8_t reservedUserId = 0x0;
35static constexpr uint8_t ipmiMaxUserName = 16;
36static constexpr uint8_t ipmiMaxUsers = 15;
37static constexpr uint8_t ipmiMaxChannels = 16;
38
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053039/** @struct PrivAccess
40 *
41 * User privilege related access data as per IPMI specification.(refer spec
42 * sec 22.26)
43 */
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053044struct PrivAccess
45{
46#if BYTE_ORDER == LITTLE_ENDIAN
47 uint8_t privilege : 4;
48 uint8_t ipmiEnabled : 1;
49 uint8_t linkAuthEnabled : 1;
50 uint8_t accessCallback : 1;
51 uint8_t reserved : 1;
52#endif
53#if BYTE_ORDER == BIG_ENDIAN
54 uint8_t reserved : 1;
55 uint8_t accessCallback : 1;
56 uint8_t linkAuthEnabled : 1;
57 uint8_t ipmiEnabled : 1;
58 uint8_t privilege : 4;
59#endif
60} __attribute__((packed));
61
62/** @brief initializes user management
63 *
64 * @return IPMI_CC_OK for success, others for failure.
65 */
66ipmi_ret_t ipmiUserInit();
67
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053068/** @brief The ipmi get user password layer call
69 *
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053070 * @param[in] userName - user name
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053071 *
72 * @return password or empty string
73 */
74std::string ipmiUserGetPassword(const std::string& userName);
75
AppaRao Pulib29b5ab2018-05-17 10:28:48 +053076/** @brief The IPMI call to clear password entry associated with specified
77 * username
78 *
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053079 * @param[in] userName - user name to be removed
AppaRao Pulib29b5ab2018-05-17 10:28:48 +053080 *
81 * @return 0 on success, non-zero otherwise.
82 */
Richard Marian Thomaiyar42bed642018-09-21 12:28:57 +053083ipmi_ret_t ipmiClearUserEntryPassword(const std::string& userName);
84
85/** @brief The IPMI call to reuse password entry for the renamed user
86 * to another one
87 *
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053088 * @param[in] userName - user name which has to be renamed
89 * @param[in] newUserName - new user name
Richard Marian Thomaiyar42bed642018-09-21 12:28:57 +053090 *
91 * @return 0 on success, non-zero otherwise.
92 */
93ipmi_ret_t ipmiRenameUserEntryPassword(const std::string& userName,
94 const std::string& newUserName);
AppaRao Pulib29b5ab2018-05-17 10:28:48 +053095
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +053096/** @brief determines valid userId
97 *
98 * @param[in] userId - user id
99 *
100 * @return true if valid, false otherwise
101 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530102bool ipmiUserIsValidUserId(const uint8_t userId);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530103
104/** @brief determines valid channel
105 *
106 * @param[in] chNum- channel number
107 *
108 * @return true if valid, false otherwise
109 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530110bool ipmiUserIsValidChannel(const uint8_t chNum);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530111
112/** @brief determines valid privilege level
113 *
114 * @param[in] priv - privilege level
115 *
116 * @return true if valid, false otherwise
117 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530118bool ipmiUserIsValidPrivilege(const uint8_t priv);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530119
120/** @brief get user id corresponding to the user name
121 *
122 * @param[in] userName - user name
123 *
124 * @return userid. Will return 0xff if no user id found
125 */
126uint8_t ipmiUserGetUserId(const std::string& userName);
127
128/** @brief set's user name
129 *
130 * @param[in] userId - user id
131 * @param[in] userName - user name
132 *
133 * @return IPMI_CC_OK for success, others for failure.
134 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530135ipmi_ret_t ipmiUserSetUserName(const uint8_t userId, const char* userName);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530136
137/** @brief get user name
138 *
139 * @param[in] userId - user id
140 * @param[out] userName - user name
141 *
142 * @return IPMI_CC_OK for success, others for failure.
143 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530144ipmi_ret_t ipmiUserGetUserName(const uint8_t userId, std::string& userName);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530145
146/** @brief provides available fixed, max, and enabled user counts
147 *
148 * @param[out] maxChUsers - max channel users
149 * @param[out] enabledUsers - enabled user count
150 * @param[out] fixedUsers - fixed user count
151 *
152 * @return IPMI_CC_OK for success, others for failure.
153 */
154ipmi_ret_t ipmiUserGetAllCounts(uint8_t& maxChUsers, uint8_t& enabledUsers,
155 uint8_t& fixedUsers);
156
Richard Marian Thomaiyar282e79b2018-11-13 19:00:58 +0530157/** @brief function to update user enabled state
158 *
159 * @param[in] userId - user id
160 *..@param[in] state - state of the user to be updated, true - user enabled.
161 *
162 * @return IPMI_CC_OK for success, others for failure.
163 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530164ipmi_ret_t ipmiUserUpdateEnabledState(const uint8_t userId, const bool& state);
Richard Marian Thomaiyar282e79b2018-11-13 19:00:58 +0530165
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530166/** @brief determines whether user is enabled
167 *
168 * @param[in] userId - user id
169 *..@param[out] state - state of the user
170 *
171 * @return IPMI_CC_OK for success, others for failure.
172 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530173ipmi_ret_t ipmiUserCheckEnabled(const uint8_t userId, bool& state);
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530174
175/** @brief provides user privilege access data
176 *
177 * @param[in] userId - user id
178 * @param[in] chNum - channel number
179 * @param[out] privAccess - privilege access data
180 *
181 * @return IPMI_CC_OK for success, others for failure.
182 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530183ipmi_ret_t ipmiUserGetPrivilegeAccess(const uint8_t userId, const uint8_t chNum,
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530184 PrivAccess& privAccess);
185
186/** @brief sets user privilege access data
187 *
188 * @param[in] userId - user id
189 * @param[in] chNum - channel number
190 * @param[in] privAccess - privilege access data
191 * @param[in] otherPrivUpdate - flags to indicate other fields update
192 *
193 * @return IPMI_CC_OK for success, others for failure.
194 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530195ipmi_ret_t ipmiUserSetPrivilegeAccess(const uint8_t userId, const uint8_t chNum,
Richard Marian Thomaiyar5a6b6362018-03-12 23:42:34 +0530196 const PrivAccess& privAccess,
197 const bool& otherPrivUpdate);
198
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +0530199} // namespace ipmi