Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 3 | #include "session.hpp" |
| 4 | |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 5 | #include <ipmid/api.hpp> |
| 6 | #include <ipmid/sessiondef.hpp> |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 7 | #include <map> |
| 8 | #include <memory> |
| 9 | #include <mutex> |
| 10 | |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 11 | namespace session |
| 12 | { |
| 13 | |
| 14 | enum class RetrieveOption |
| 15 | { |
| 16 | BMC_SESSION_ID, |
| 17 | RC_SESSION_ID, |
| 18 | }; |
| 19 | |
Tom Joseph | 3563f8f | 2017-05-08 15:42:54 +0530 | [diff] [blame] | 20 | /** |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 21 | * @class Manager |
| 22 | * |
| 23 | * Manager class acts a manager for the IPMI sessions and provides interfaces |
| 24 | * to start a session, stop a session and get reference to the session objects. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | class Manager |
| 29 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 30 | public: |
| 31 | // BMC Session ID is the key for the map |
| 32 | using SessionMap = std::map<SessionID, std::shared_ptr<Session>>; |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 33 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 34 | Manager(); |
| 35 | ~Manager() = default; |
| 36 | Manager(const Manager&) = delete; |
| 37 | Manager& operator=(const Manager&) = delete; |
| 38 | Manager(Manager&&) = default; |
| 39 | Manager& operator=(Manager&&) = default; |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 40 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 41 | /** |
| 42 | * @brief Start an IPMI session |
| 43 | * |
| 44 | * @param[in] remoteConsoleSessID - Remote Console Session ID mentioned |
| 45 | * in the Open SessionRequest Command |
| 46 | * @param[in] priv - Privilege level requested |
| 47 | * @param[in] authAlgo - Authentication Algorithm |
| 48 | * @param[in] intAlgo - Integrity Algorithm |
| 49 | * @param[in] cryptAlgo - Confidentiality Algorithm |
| 50 | * |
| 51 | * @return session handle on success and nullptr on failure |
| 52 | * |
| 53 | */ |
Vernon Mauery | ae1fda4 | 2018-10-15 12:55:34 -0700 | [diff] [blame] | 54 | std::shared_ptr<Session> |
| 55 | startSession(SessionID remoteConsoleSessID, Privilege priv, |
| 56 | cipher::rakp_auth::Algorithms authAlgo, |
| 57 | cipher::integrity::Algorithms intAlgo, |
| 58 | cipher::crypt::Algorithms cryptAlgo); |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 59 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 60 | /** |
| 61 | * @brief Stop IPMI Session |
| 62 | * |
| 63 | * @param[in] bmcSessionID - BMC Session ID |
| 64 | * |
| 65 | * @return true on success and failure if session ID is invalid |
| 66 | * |
| 67 | */ |
| 68 | bool stopSession(SessionID bmcSessionID); |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 69 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 70 | /** |
| 71 | * @brief Get Session Handle |
| 72 | * |
| 73 | * @param[in] sessionID - Session ID |
| 74 | * @param[in] option - Select between BMC Session ID and Remote Console |
| 75 | * Session ID, Default option is BMC Session ID |
| 76 | * |
| 77 | * @return session handle on success and nullptr on failure |
| 78 | * |
| 79 | */ |
Vernon Mauery | ae1fda4 | 2018-10-15 12:55:34 -0700 | [diff] [blame] | 80 | std::shared_ptr<Session> |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 81 | getSession(SessionID sessionID, |
| 82 | RetrieveOption option = RetrieveOption::BMC_SESSION_ID); |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 83 | uint8_t getActiveSessionCount() const; |
| 84 | uint8_t getSessionHandle(SessionID bmcSessionID) const; |
| 85 | uint8_t storeSessionHandle(SessionID bmcSessionID); |
| 86 | uint32_t getSessionIDbyHandle(uint8_t sessionHandle) const; |
| 87 | |
| 88 | void managerInit(const std::string& channel); |
| 89 | |
| 90 | uint8_t getNetworkInstance(void); |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 91 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 92 | private: |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 93 | //+1 for session, as 0 is reserved for sessionless command |
| 94 | std::array<uint32_t, session::maxSessionCountPerChannel + 1> |
| 95 | sessionHandleMap = {0}; |
| 96 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 97 | /** |
| 98 | * @brief Session Manager keeps the session objects as a sorted |
| 99 | * associative container with Session ID as the unique key |
| 100 | */ |
| 101 | SessionMap sessionsMap; |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 102 | std::unique_ptr<sdbusplus::server::manager::manager> objManager = nullptr; |
| 103 | std::string chName{}; // Channel Name |
| 104 | uint8_t ipmiNetworkInstance; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 105 | /** |
| 106 | * @brief Clean Session Stale Entries |
| 107 | * |
| 108 | * Removes the inactive sessions entries from the Session Map |
| 109 | */ |
| 110 | void cleanStaleEntries(); |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 111 | void setNetworkInstance(void); |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // namespace session |