blob: fb2d0740b32aacdf6c361b69c9de5f8d53f74ba2 [file] [log] [blame]
Tom Joseph9662c3a2016-12-06 17:52:16 +05301#include "session_cmds.hpp"
2
Tom Joseph9662c3a2016-12-06 17:52:16 +05303#include "endian.hpp"
4#include "main.hpp"
Vernon Mauery9e801a22018-10-12 13:20:49 -07005
Tom Joseph9662c3a2016-12-06 17:52:16 +05306#include <host-ipmid/ipmid-api.h>
7
Vernon Mauery9e801a22018-10-12 13:20:49 -07008#include <iostream>
9
Tom Joseph9662c3a2016-12-06 17:52:16 +053010namespace command
11{
12
Vernon Mauery9e801a22018-10-12 13:20:49 -070013std::vector<uint8_t>
14 setSessionPrivilegeLevel(const std::vector<uint8_t>& inPayload,
15 const message::Handler& handler)
Tom Joseph9662c3a2016-12-06 17:52:16 +053016{
Tom Joseph9662c3a2016-12-06 17:52:16 +053017
18 std::vector<uint8_t> outPayload(sizeof(SetSessionPrivLevelResp));
Vernon Mauery9e801a22018-10-12 13:20:49 -070019 auto request =
20 reinterpret_cast<const SetSessionPrivLevelReq*>(inPayload.data());
21 auto response =
22 reinterpret_cast<SetSessionPrivLevelResp*>(outPayload.data());
Tom Joseph9662c3a2016-12-06 17:52:16 +053023 response->completionCode = IPMI_CC_OK;
24 uint8_t reqPrivilegeLevel = request->reqPrivLevel;
25
Vernon Mauery9e801a22018-10-12 13:20:49 -070026 auto session = (std::get<session::Manager&>(singletonPool)
27 .getSession(handler.sessionID))
28 .lock();
Tom Joseph9662c3a2016-12-06 17:52:16 +053029
30 if (reqPrivilegeLevel == 0) // Just return present privilege level
31 {
32 response->newPrivLevel = static_cast<uint8_t>(session->curPrivLevel);
33 }
34 else if (reqPrivilegeLevel <= static_cast<uint8_t>(session->maxPrivLevel))
35 {
Vernon Mauery9e801a22018-10-12 13:20:49 -070036 session->curPrivLevel =
37 static_cast<session::Privilege>(reqPrivilegeLevel);
Tom Joseph9662c3a2016-12-06 17:52:16 +053038 response->newPrivLevel = reqPrivilegeLevel;
39 }
40 else
41 {
42 // Requested level exceeds Channel and/or User Privilege Limit
43 response->completionCode = IPMI_CC_EXCEEDS_USER_PRIV;
44 }
Tom Joseph9662c3a2016-12-06 17:52:16 +053045 return outPayload;
46}
47
Tom Joseph18a45e92017-04-11 11:30:44 +053048std::vector<uint8_t> closeSession(const std::vector<uint8_t>& inPayload,
Tom Joseph9662c3a2016-12-06 17:52:16 +053049 const message::Handler& handler)
50{
Tom Joseph9662c3a2016-12-06 17:52:16 +053051 std::vector<uint8_t> outPayload(sizeof(CloseSessionResponse));
Vernon Mauery9e801a22018-10-12 13:20:49 -070052 auto request =
53 reinterpret_cast<const CloseSessionRequest*>(inPayload.data());
Tom Joseph9662c3a2016-12-06 17:52:16 +053054 auto response = reinterpret_cast<CloseSessionResponse*>(outPayload.data());
Vernon Mauery9e801a22018-10-12 13:20:49 -070055 response->completionCode = IPMI_CC_OK;
Tom Joseph9662c3a2016-12-06 17:52:16 +053056
57 auto bmcSessionID = endian::from_ipmi(request->sessionID);
58
59 // Session 0 is needed to handle session setup, so session zero is never
60 // closed
61 if (bmcSessionID == session::SESSION_ZERO)
62 {
63 response->completionCode = IPMI_CC_INVALID_SESSIONID;
64 }
65 else
66 {
Vernon Mauery9e801a22018-10-12 13:20:49 -070067 auto status = std::get<session::Manager&>(singletonPool)
68 .stopSession(bmcSessionID);
69 if (!status)
Tom Joseph9662c3a2016-12-06 17:52:16 +053070 {
71 response->completionCode = IPMI_CC_INVALID_SESSIONID;
72 }
73 }
Tom Joseph9662c3a2016-12-06 17:52:16 +053074 return outPayload;
75}
76
77} // namespace command