blob: ed3db49c6602dec4e25da7d5ffe60a59b9edadff [file] [log] [blame]
Tom Joseph3e61aa02016-08-08 08:42:39 -05001#pragma once
2
Vernon Mauery9e801a22018-10-12 13:20:49 -07003#include "session.hpp"
4
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +05305#include <ipmid/api.hpp>
6#include <ipmid/sessiondef.hpp>
Tom Joseph3e61aa02016-08-08 08:42:39 -05007#include <map>
8#include <memory>
9#include <mutex>
Andrew Geissler7408e762020-05-17 08:56:05 -050010#include <string>
Tom Joseph3e61aa02016-08-08 08:42:39 -050011
Tom Joseph3e61aa02016-08-08 08:42:39 -050012namespace session
13{
14
15enum class RetrieveOption
16{
17 BMC_SESSION_ID,
18 RC_SESSION_ID,
19};
20
Tom Joseph3563f8f2017-05-08 15:42:54 +053021/**
Tom Joseph3e61aa02016-08-08 08:42:39 -050022 * @class Manager
23 *
24 * Manager class acts a manager for the IPMI sessions and provides interfaces
25 * to start a session, stop a session and get reference to the session objects.
26 *
27 */
28
29class Manager
30{
Vernon Mauery9e801a22018-10-12 13:20:49 -070031 public:
32 // BMC Session ID is the key for the map
33 using SessionMap = std::map<SessionID, std::shared_ptr<Session>>;
Tom Joseph3e61aa02016-08-08 08:42:39 -050034
Vernon Mauery9e801a22018-10-12 13:20:49 -070035 Manager();
36 ~Manager() = default;
37 Manager(const Manager&) = delete;
38 Manager& operator=(const Manager&) = delete;
39 Manager(Manager&&) = default;
40 Manager& operator=(Manager&&) = default;
Tom Joseph3e61aa02016-08-08 08:42:39 -050041
Vernon Mauery9e801a22018-10-12 13:20:49 -070042 /**
43 * @brief Start an IPMI session
44 *
45 * @param[in] remoteConsoleSessID - Remote Console Session ID mentioned
46 * in the Open SessionRequest Command
47 * @param[in] priv - Privilege level requested
48 * @param[in] authAlgo - Authentication Algorithm
49 * @param[in] intAlgo - Integrity Algorithm
50 * @param[in] cryptAlgo - Confidentiality Algorithm
51 *
52 * @return session handle on success and nullptr on failure
53 *
54 */
Vernon Maueryae1fda42018-10-15 12:55:34 -070055 std::shared_ptr<Session>
56 startSession(SessionID remoteConsoleSessID, Privilege priv,
57 cipher::rakp_auth::Algorithms authAlgo,
58 cipher::integrity::Algorithms intAlgo,
59 cipher::crypt::Algorithms cryptAlgo);
Tom Joseph3e61aa02016-08-08 08:42:39 -050060
Vernon Mauery9e801a22018-10-12 13:20:49 -070061 /**
62 * @brief Stop IPMI Session
63 *
64 * @param[in] bmcSessionID - BMC Session ID
65 *
66 * @return true on success and failure if session ID is invalid
67 *
68 */
69 bool stopSession(SessionID bmcSessionID);
Tom Joseph3e61aa02016-08-08 08:42:39 -050070
Vernon Mauery9e801a22018-10-12 13:20:49 -070071 /**
72 * @brief Get Session Handle
73 *
74 * @param[in] sessionID - Session ID
75 * @param[in] option - Select between BMC Session ID and Remote Console
76 * Session ID, Default option is BMC Session ID
77 *
78 * @return session handle on success and nullptr on failure
79 *
80 */
Vernon Maueryae1fda42018-10-15 12:55:34 -070081 std::shared_ptr<Session>
Vernon Mauery9e801a22018-10-12 13:20:49 -070082 getSession(SessionID sessionID,
83 RetrieveOption option = RetrieveOption::BMC_SESSION_ID);
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +053084 uint8_t getActiveSessionCount() const;
85 uint8_t getSessionHandle(SessionID bmcSessionID) const;
86 uint8_t storeSessionHandle(SessionID bmcSessionID);
87 uint32_t getSessionIDbyHandle(uint8_t sessionHandle) const;
88
89 void managerInit(const std::string& channel);
90
91 uint8_t getNetworkInstance(void);
Tom Joseph3e61aa02016-08-08 08:42:39 -050092
Vernon Mauery9e801a22018-10-12 13:20:49 -070093 private:
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +053094 //+1 for session, as 0 is reserved for sessionless command
95 std::array<uint32_t, session::maxSessionCountPerChannel + 1>
96 sessionHandleMap = {0};
97
Vernon Mauery9e801a22018-10-12 13:20:49 -070098 /**
99 * @brief Session Manager keeps the session objects as a sorted
100 * associative container with Session ID as the unique key
101 */
102 SessionMap sessionsMap;
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +0530103 std::unique_ptr<sdbusplus::server::manager::manager> objManager = nullptr;
104 std::string chName{}; // Channel Name
105 uint8_t ipmiNetworkInstance;
Vernon Mauery9e801a22018-10-12 13:20:49 -0700106 /**
107 * @brief Clean Session Stale Entries
108 *
109 * Removes the inactive sessions entries from the Session Map
110 */
111 void cleanStaleEntries();
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +0530112 void setNetworkInstance(void);
Tom Joseph3e61aa02016-08-08 08:42:39 -0500113};
114
115} // namespace session