Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 1 | #include "systemintfcmds.h" |
| 2 | #include "host-ipmid/ipmid-api.h" |
Vishwanatha Subbanna | b891a57 | 2017-03-31 11:34:48 +0530 | [diff] [blame] | 3 | #include "config.h" |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 4 | #include "host-interface.hpp" |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 5 | |
| 6 | #include <stdio.h> |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 7 | #include <mapper.h> |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 8 | |
| 9 | void register_netfn_app_functions() __attribute__((constructor)); |
| 10 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 11 | using namespace sdbusplus::xyz::openbmc_project::Control::server; |
| 12 | |
| 13 | // Internal function to get next host command |
| 14 | Host::Command getNextHostCmd(); |
| 15 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 16 | //------------------------------------------------------------------- |
| 17 | // Called by Host post response from Get_Message_Flags |
| 18 | //------------------------------------------------------------------- |
| 19 | ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 20 | ipmi_request_t request, ipmi_response_t response, |
| 21 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 22 | { |
| 23 | ipmi_ret_t rc = IPMI_CC_OK; |
| 24 | |
| 25 | printf("IPMI APP READ EVENT command received\n"); |
| 26 | |
| 27 | struct oem_sel_timestamped oem_sel = {0}; |
| 28 | *data_len = sizeof(struct oem_sel_timestamped); |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 29 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 30 | // either id[0] -or- id[1] can be filled in. We will use id[0] |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 31 | oem_sel.id[0] = SEL_OEM_ID_0; |
| 32 | oem_sel.id[1] = SEL_OEM_ID_0; |
| 33 | oem_sel.type = SEL_RECORD_TYPE_OEM; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 34 | |
| 35 | // Following 3 bytes are from IANA Manufactre_Id field. See below |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 36 | oem_sel.manuf_id[0]= 0x41; |
| 37 | oem_sel.manuf_id[1]= 0xA7; |
| 38 | oem_sel.manuf_id[2]= 0x00; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 39 | |
| 40 | // per IPMI spec NetFuntion for OEM |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 41 | oem_sel.netfun = 0x3A; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 42 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 43 | // Read from the queue to see what our response is here |
| 44 | Host::Command hCmd = getNextHostCmd(); |
| 45 | switch (hCmd) |
| 46 | { |
| 47 | case Host::Command::SoftOff: |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 48 | oem_sel.cmd = CMD_POWER; |
| 49 | oem_sel.data[0] = SOFT_OFF; |
| 50 | break; |
| 51 | case Host::Command::Heartbeat: |
| 52 | oem_sel.cmd = CMD_HEARTBEAT; |
| 53 | oem_sel.data[0] = 0x00; |
| 54 | break; |
| 55 | } |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 56 | |
| 57 | // All '0xFF' since unused. |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 58 | memset(&oem_sel.data[1], 0xFF, 3); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 59 | |
| 60 | // Pack the actual response |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 61 | memcpy(response, &oem_sel, *data_len); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 62 | return rc; |
| 63 | } |
| 64 | |
| 65 | //--------------------------------------------------------------------- |
| 66 | // Called by Host on seeing a SMS_ATN bit set. Return a hardcoded |
| 67 | // value of 0x2 indicating we need Host read some data. |
| 68 | //------------------------------------------------------------------- |
| 69 | ipmi_ret_t ipmi_app_get_msg_flags(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 70 | ipmi_request_t request, ipmi_response_t response, |
| 71 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 72 | { |
| 73 | // Generic return from IPMI commands. |
| 74 | ipmi_ret_t rc = IPMI_CC_OK; |
| 75 | |
| 76 | printf("IPMI APP GET MSG FLAGS returning with [bit:2] set\n"); |
| 77 | |
| 78 | // From IPMI spec V2.0 for Get Message Flags Command : |
| 79 | // bit:[1] from LSB : 1b = Event Message Buffer Full. |
| 80 | // Return as 0 if Event Message Buffer is not supported, |
| 81 | // or when the Event Message buffer is disabled. |
| 82 | // TODO. For now. assume its not disabled and send "0x2" anyway: |
| 83 | |
| 84 | uint8_t set_event_msg_buffer_full = 0x2; |
| 85 | *data_len = sizeof(set_event_msg_buffer_full); |
| 86 | |
| 87 | // Pack the actual response |
| 88 | memcpy(response, &set_event_msg_buffer_full, *data_len); |
| 89 | |
| 90 | return rc; |
| 91 | } |
| 92 | |
| 93 | ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 94 | ipmi_request_t request, ipmi_response_t response, |
| 95 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 96 | { |
| 97 | ipmi_ret_t rc = IPMI_CC_OK; |
| 98 | *data_len = 0; |
| 99 | |
| 100 | // Event and message logging enabled by default so return for now |
| 101 | printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n"); |
| 102 | |
| 103 | return rc; |
| 104 | } |
| 105 | |
Lei YU | 12c2db7 | 2017-05-15 11:24:04 +0800 | [diff] [blame] | 106 | namespace { |
| 107 | // Static storage to keep the object alive during process life |
| 108 | std::unique_ptr<sdbusplus::bus::bus> sdbus __attribute__((init_priority(101))); |
| 109 | std::unique_ptr<phosphor::host::Host> host __attribute__((init_priority(101))); |
| 110 | } |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 111 | |
| 112 | #include <unistd.h> |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 113 | void register_netfn_app_functions() |
| 114 | { |
| 115 | |
| 116 | // <Read Event Message Buffer> |
| 117 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 118 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event, |
| 119 | SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 120 | |
| 121 | // <Set BMC Global Enables> |
| 122 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, |
| 123 | IPMI_CMD_SET_BMC_GLOBAL_ENABLES); |
| 124 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 125 | ipmi_app_set_bmc_global_enables, SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 126 | |
| 127 | // <Get Message Flags> |
| 128 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 129 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL, ipmi_app_get_msg_flags, |
| 130 | SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 131 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 132 | // Gets a hook onto SYSTEM bus used by host-ipmid |
| 133 | sd_bus *bus = ipmid_get_sd_bus_connection(); |
| 134 | |
| 135 | sdbus = std::make_unique<sdbusplus::bus::bus>(bus); |
| 136 | |
| 137 | // Create new xyz.openbmc_project.host object on the bus |
| 138 | auto objPathInst = std::string{CONTROL_HOST_OBJPATH} + '0'; |
| 139 | |
| 140 | // Add sdbusplus ObjectManager. |
| 141 | sdbusplus::server::manager::manager objManager(*sdbus, |
| 142 | objPathInst.c_str()); |
| 143 | |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 144 | // Get the sd_events pointer |
| 145 | auto events = ipmid_get_sd_event_connection(); |
| 146 | |
Lei YU | 12c2db7 | 2017-05-15 11:24:04 +0800 | [diff] [blame] | 147 | host = std::make_unique<phosphor::host::Host>(*sdbus, |
| 148 | objPathInst.c_str(), |
| 149 | events); |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 150 | |
| 151 | sdbus->request_name(CONTROL_HOST_BUSNAME); |
| 152 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 153 | return; |
| 154 | } |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 155 | |
| 156 | Host::Command getNextHostCmd() |
| 157 | { |
| 158 | return(host->getNextCommand()); |
| 159 | } |