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> |
Andrew Geissler | 7408e76 | 2020-05-17 08:56:05 -0500 | [diff] [blame] | 10 | #include <string> |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 11 | |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 12 | namespace session |
| 13 | { |
| 14 | |
| 15 | enum class RetrieveOption |
| 16 | { |
| 17 | BMC_SESSION_ID, |
| 18 | RC_SESSION_ID, |
| 19 | }; |
| 20 | |
Tom Joseph | 3563f8f | 2017-05-08 15:42:54 +0530 | [diff] [blame] | 21 | /** |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 22 | * @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 | |
| 29 | class Manager |
| 30 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 31 | public: |
| 32 | // BMC Session ID is the key for the map |
| 33 | using SessionMap = std::map<SessionID, std::shared_ptr<Session>>; |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 34 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 35 | 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 Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 41 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 42 | /** |
| 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 Mauery | ae1fda4 | 2018-10-15 12:55:34 -0700 | [diff] [blame] | 55 | 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 Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 60 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 61 | /** |
| 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 Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 70 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 71 | /** |
| 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 Mauery | ae1fda4 | 2018-10-15 12:55:34 -0700 | [diff] [blame] | 81 | std::shared_ptr<Session> |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 82 | getSession(SessionID sessionID, |
| 83 | RetrieveOption option = RetrieveOption::BMC_SESSION_ID); |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 84 | 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 Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 92 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 93 | private: |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 94 | //+1 for session, as 0 is reserved for sessionless command |
| 95 | std::array<uint32_t, session::maxSessionCountPerChannel + 1> |
| 96 | sessionHandleMap = {0}; |
| 97 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 98 | /** |
| 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 Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 103 | std::unique_ptr<sdbusplus::server::manager::manager> objManager = nullptr; |
| 104 | std::string chName{}; // Channel Name |
| 105 | uint8_t ipmiNetworkInstance; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 106 | /** |
| 107 | * @brief Clean Session Stale Entries |
| 108 | * |
| 109 | * Removes the inactive sessions entries from the Session Map |
| 110 | */ |
| 111 | void cleanStaleEntries(); |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame] | 112 | void setNetworkInstance(void); |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | } // namespace session |