blob: d363c1eb5062b5217b0774a21ece918e6f9f8cb2 [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 Maueryae1fda42018-10-15 12:55:34 -070026 auto session = std::get<session::Manager&>(singletonPool)
27 .getSession(handler.sessionID);
Tom Joseph9662c3a2016-12-06 17:52:16 +053028
29 if (reqPrivilegeLevel == 0) // Just return present privilege level
30 {
31 response->newPrivLevel = static_cast<uint8_t>(session->curPrivLevel);
32 }
33 else if (reqPrivilegeLevel <= static_cast<uint8_t>(session->maxPrivLevel))
34 {
Vernon Mauery9e801a22018-10-12 13:20:49 -070035 session->curPrivLevel =
36 static_cast<session::Privilege>(reqPrivilegeLevel);
Tom Joseph9662c3a2016-12-06 17:52:16 +053037 response->newPrivLevel = reqPrivilegeLevel;
38 }
39 else
40 {
41 // Requested level exceeds Channel and/or User Privilege Limit
42 response->completionCode = IPMI_CC_EXCEEDS_USER_PRIV;
43 }
Tom Joseph9662c3a2016-12-06 17:52:16 +053044 return outPayload;
45}
46
Tom Joseph18a45e92017-04-11 11:30:44 +053047std::vector<uint8_t> closeSession(const std::vector<uint8_t>& inPayload,
Tom Joseph9662c3a2016-12-06 17:52:16 +053048 const message::Handler& handler)
49{
Tom Joseph9662c3a2016-12-06 17:52:16 +053050 std::vector<uint8_t> outPayload(sizeof(CloseSessionResponse));
Vernon Mauery9e801a22018-10-12 13:20:49 -070051 auto request =
52 reinterpret_cast<const CloseSessionRequest*>(inPayload.data());
Tom Joseph9662c3a2016-12-06 17:52:16 +053053 auto response = reinterpret_cast<CloseSessionResponse*>(outPayload.data());
Vernon Mauery9e801a22018-10-12 13:20:49 -070054 response->completionCode = IPMI_CC_OK;
Tom Joseph9662c3a2016-12-06 17:52:16 +053055
56 auto bmcSessionID = endian::from_ipmi(request->sessionID);
57
58 // Session 0 is needed to handle session setup, so session zero is never
59 // closed
60 if (bmcSessionID == session::SESSION_ZERO)
61 {
62 response->completionCode = IPMI_CC_INVALID_SESSIONID;
63 }
64 else
65 {
Vernon Mauery9e801a22018-10-12 13:20:49 -070066 auto status = std::get<session::Manager&>(singletonPool)
67 .stopSession(bmcSessionID);
68 if (!status)
Tom Joseph9662c3a2016-12-06 17:52:16 +053069 {
70 response->completionCode = IPMI_CC_INVALID_SESSIONID;
71 }
72 }
Tom Joseph9662c3a2016-12-06 17:52:16 +053073 return outPayload;
74}
75
76} // namespace command