blob: e19953226aedda9b5a40552980231e1ab86e319f [file] [log] [blame]
Tom Joseph9662c3a2016-12-06 17:52:16 +05301#include "session_cmds.hpp"
2
3#include <iostream>
4
5#include "endian.hpp"
6#include "main.hpp"
7#include <host-ipmid/ipmid-api.h>
8
9namespace command
10{
11
Tom Joseph18a45e92017-04-11 11:30:44 +053012std::vector<uint8_t> setSessionPrivilegeLevel(
13 const std::vector<uint8_t>& inPayload, const message::Handler& handler)
Tom Joseph9662c3a2016-12-06 17:52:16 +053014{
Tom Joseph9662c3a2016-12-06 17:52:16 +053015
16 std::vector<uint8_t> outPayload(sizeof(SetSessionPrivLevelResp));
Tom Joseph18a45e92017-04-11 11:30:44 +053017 auto request = reinterpret_cast<const SetSessionPrivLevelReq*>
18 (inPayload.data());
Tom Joseph9662c3a2016-12-06 17:52:16 +053019 auto response = reinterpret_cast<SetSessionPrivLevelResp*>
20 (outPayload.data());
21 response->completionCode = IPMI_CC_OK;
22 uint8_t reqPrivilegeLevel = request->reqPrivLevel;
23
24 auto session = (std::get<session::Manager&>(singletonPool).getSession(
25 handler.sessionID)).lock();
26
27 if (reqPrivilegeLevel == 0) // Just return present privilege level
28 {
29 response->newPrivLevel = static_cast<uint8_t>(session->curPrivLevel);
30 }
31 else if (reqPrivilegeLevel <= static_cast<uint8_t>(session->maxPrivLevel))
32 {
33 session->curPrivLevel = static_cast<session::Privilege>
34 (reqPrivilegeLevel);
35 response->newPrivLevel = reqPrivilegeLevel;
36 }
37 else
38 {
39 // Requested level exceeds Channel and/or User Privilege Limit
40 response->completionCode = IPMI_CC_EXCEEDS_USER_PRIV;
41 }
Tom Joseph9662c3a2016-12-06 17:52:16 +053042 return outPayload;
43}
44
Tom Joseph18a45e92017-04-11 11:30:44 +053045std::vector<uint8_t> closeSession(const std::vector<uint8_t>& inPayload,
Tom Joseph9662c3a2016-12-06 17:52:16 +053046 const message::Handler& handler)
47{
Tom Joseph9662c3a2016-12-06 17:52:16 +053048 std::vector<uint8_t> outPayload(sizeof(CloseSessionResponse));
Tom Joseph18a45e92017-04-11 11:30:44 +053049 auto request = reinterpret_cast<const CloseSessionRequest*>
50 (inPayload.data());
Tom Joseph9662c3a2016-12-06 17:52:16 +053051 auto response = reinterpret_cast<CloseSessionResponse*>(outPayload.data());
52 response->completionCode = IPMI_CC_OK ;
53
54 auto bmcSessionID = endian::from_ipmi(request->sessionID);
55
56 // Session 0 is needed to handle session setup, so session zero is never
57 // closed
58 if (bmcSessionID == session::SESSION_ZERO)
59 {
60 response->completionCode = IPMI_CC_INVALID_SESSIONID;
61 }
62 else
63 {
64 auto status = std::get<session::Manager&>(singletonPool).stopSession
65 (bmcSessionID);
66 if(!status)
67 {
68 response->completionCode = IPMI_CC_INVALID_SESSIONID;
69 }
70 }
Tom Joseph9662c3a2016-12-06 17:52:16 +053071 return outPayload;
72}
73
74} // namespace command