1 #include "config.h" 2 3 #include "systemintfcmds.hpp" 4 5 #include "host-cmd-manager.hpp" 6 #include "host-interface.hpp" 7 8 #include <cstring> 9 #include <ipmid-host/cmd.hpp> 10 #include <ipmid/api.hpp> 11 12 void register_netfn_app_functions() __attribute__((constructor)); 13 14 using namespace sdbusplus::xyz::openbmc_project::Control::server; 15 16 // For accessing Host command manager 17 using cmdManagerPtr = std::unique_ptr<phosphor::host::command::Manager>; 18 extern cmdManagerPtr& ipmid_get_host_cmd_manager(); 19 20 //------------------------------------------------------------------- 21 // Called by Host post response from Get_Message_Flags 22 //------------------------------------------------------------------- 23 ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t, 24 ipmi_response_t response, 25 ipmi_data_len_t data_len, ipmi_context_t) 26 { 27 ipmi_ret_t rc = IPMI_CC_OK; 28 29 struct oem_sel_timestamped oem_sel = {}; 30 *data_len = sizeof(struct oem_sel_timestamped); 31 32 // either id[0] -or- id[1] can be filled in. We will use id[0] 33 oem_sel.id[0] = SEL_OEM_ID_0; 34 oem_sel.id[1] = SEL_OEM_ID_0; 35 oem_sel.type = SEL_RECORD_TYPE_OEM; 36 37 // Following 3 bytes are from IANA Manufactre_Id field. See below 38 oem_sel.manuf_id[0] = 0x41; 39 oem_sel.manuf_id[1] = 0xA7; 40 oem_sel.manuf_id[2] = 0x00; 41 42 // per IPMI spec NetFuntion for OEM 43 oem_sel.netfun = 0x3A; 44 45 // Read from the Command Manager queue. What gets returned is a 46 // pair of <command, data> that can be directly used here 47 auto hostCmd = ipmid_get_host_cmd_manager()->getNextCommand(); 48 oem_sel.cmd = hostCmd.first; 49 oem_sel.data[0] = hostCmd.second; 50 51 // All '0xFF' since unused. 52 std::memset(&oem_sel.data[1], 0xFF, 3); 53 54 // Pack the actual response 55 std::memcpy(response, &oem_sel, *data_len); 56 return rc; 57 } 58 59 //--------------------------------------------------------------------- 60 // Called by Host on seeing a SMS_ATN bit set. Return a hardcoded 61 // value of 0x0 to indicate Event Message Buffer is not supported 62 //------------------------------------------------------------------- 63 ipmi::RspType<uint8_t> ipmiAppGetMessageFlags() 64 { 65 // From IPMI spec V2.0 for Get Message Flags Command : 66 // bit:[1] from LSB : 1b = Event Message Buffer Full. 67 // Return as 0 if Event Message Buffer is not supported, 68 // or when the Event Message buffer is disabled. 69 // This path is used to communicate messages to the host 70 // from within the phosphor::host::command::Manager 71 constexpr uint8_t setEventMsgBufferNotSupported = 0x0; 72 return ipmi::responseSuccess(setEventMsgBufferNotSupported); 73 } 74 75 ipmi::RspType<bool, // Receive Message Queue Interrupt Enabled 76 bool, // Event Message Buffer Full Interrupt Enabled 77 bool, // Event Message Buffer Enabled 78 bool, // System Event Logging Enabled 79 uint1_t, // Reserved 80 bool, // OEM 0 enabled 81 bool, // OEM 1 enabled 82 bool // OEM 2 enabled 83 > 84 ipmiAppGetBMCGlobalEnable() 85 { 86 return ipmi::responseSuccess(true, false, false, true, 0, false, false, 87 false); 88 } 89 90 ipmi::RspType<> ipmiAppSetBMCGlobalEnable( 91 ipmi::Context::ptr ctx, bool receiveMessageQueueInterruptEnabled, 92 bool eventMessageBufferFullInterruptEnabled, bool eventMessageBufferEnabled, 93 bool systemEventLogEnable, uint1_t reserved, bool OEM0Enabled, 94 bool OEM1Enabled, bool OEM2Enabled) 95 { 96 ipmi::ChannelInfo chInfo; 97 98 if (ipmi::getChannelInfo(ctx->channel, chInfo) != ipmi::ccSuccess) 99 { 100 phosphor::logging::log<phosphor::logging::level::ERR>( 101 "Failed to get Channel Info", 102 phosphor::logging::entry("CHANNEL=%d", ctx->channel)); 103 return ipmi::responseUnspecifiedError(); 104 } 105 106 if (chInfo.mediumType != 107 static_cast<uint8_t>(ipmi::EChannelMediumType::systemInterface)) 108 { 109 phosphor::logging::log<phosphor::logging::level::ERR>( 110 "Error - supported only in system interface"); 111 return ipmi::responseCommandNotAvailable(); 112 } 113 114 // Recv Message Queue and SEL are enabled by default. 115 // Event Message buffer are disabled by default (not supported). 116 // Any request that try to change the mask will be rejected 117 if (!receiveMessageQueueInterruptEnabled || !systemEventLogEnable || 118 eventMessageBufferFullInterruptEnabled || eventMessageBufferEnabled || 119 OEM0Enabled || OEM1Enabled || OEM2Enabled || reserved) 120 { 121 return ipmi::responseInvalidFieldRequest(); 122 } 123 124 return ipmi::responseSuccess(); 125 } 126 127 namespace 128 { 129 // Static storage to keep the object alive during process life 130 std::unique_ptr<phosphor::host::command::Host> host 131 __attribute__((init_priority(101))); 132 std::unique_ptr<sdbusplus::server::manager::manager> objManager 133 __attribute__((init_priority(101))); 134 } // namespace 135 136 void register_netfn_app_functions() 137 { 138 139 // <Read Event Message Buffer> 140 ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, 141 ipmi_app_read_event, SYSTEM_INTERFACE); 142 143 // <Set BMC Global Enables> 144 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, 145 ipmi::app::cmdSetBmcGlobalEnables, 146 ipmi::Privilege::Admin, ipmiAppSetBMCGlobalEnable); 147 148 // <Get BMC Global Enables> 149 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, 150 ipmi::app::cmdGetBmcGlobalEnables, 151 ipmi::Privilege::User, ipmiAppGetBMCGlobalEnable); 152 153 // <Get Message Flags> 154 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, 155 ipmi::app::cmdGetMessageFlags, ipmi::Privilege::Admin, 156 ipmiAppGetMessageFlags); 157 158 // Create new xyz.openbmc_project.host object on the bus 159 auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0'; 160 161 std::unique_ptr<sdbusplus::asio::connection>& sdbusp = 162 ipmid_get_sdbus_plus_handler(); 163 164 // Add sdbusplus ObjectManager. 165 objManager = std::make_unique<sdbusplus::server::manager::manager>( 166 *sdbusp, CONTROL_HOST_OBJ_MGR); 167 168 host = std::make_unique<phosphor::host::command::Host>(*sdbusp, 169 objPath.c_str()); 170 sdbusp->request_name(CONTROL_HOST_BUSNAME); 171 172 return; 173 } 174