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" |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 4 | |
| 5 | #include <stdio.h> |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 6 | #include <mapper.h> |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 7 | |
| 8 | void register_netfn_app_functions() __attribute__((constructor)); |
| 9 | |
| 10 | //------------------------------------------------------------------- |
| 11 | // Called by Host post response from Get_Message_Flags |
| 12 | //------------------------------------------------------------------- |
| 13 | ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 14 | ipmi_request_t request, ipmi_response_t response, |
| 15 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 16 | { |
| 17 | ipmi_ret_t rc = IPMI_CC_OK; |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 18 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 19 | printf("IPMI APP READ EVENT command received\n"); |
| 20 | |
| 21 | // TODO : For now, this is catering only to the Soft Power Off via OEM SEL |
| 22 | // mechanism. If we need to make this generically used for some |
| 23 | // other conditions, then we can take advantage of context pointer. |
| 24 | |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 25 | constexpr auto iface = "org.freedesktop.DBus.Properties"; |
| 26 | constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal." |
| 27 | "SoftPowerOff"; |
| 28 | |
| 29 | constexpr auto property = "ResponseReceived"; |
| 30 | constexpr auto value = "xyz.openbmc_project.Ipmi.Internal." |
| 31 | "SoftPowerOff.HostResponse.SoftOffReceived"; |
| 32 | char *busname = nullptr; |
| 33 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 34 | struct oem_sel_timestamped soft_off = {0}; |
| 35 | *data_len = sizeof(struct oem_sel_timestamped); |
| 36 | |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 37 | // Get the system bus where most system services are provided. |
| 38 | auto bus = ipmid_get_sd_bus_connection(); |
| 39 | |
| 40 | // Nudge the SoftPowerOff application that it needs to stop the |
| 41 | // initial watchdog timer. If we have some errors talking to Soft Off |
| 42 | // object, get going and do our regular job |
Vishwanatha Subbanna | b891a57 | 2017-03-31 11:34:48 +0530 | [diff] [blame] | 43 | mapper_get_service(bus, SOFTOFF_OBJPATH, &busname); |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 44 | if (busname) |
| 45 | { |
| 46 | // No error object or reply expected. |
Vishwanatha Subbanna | b891a57 | 2017-03-31 11:34:48 +0530 | [diff] [blame] | 47 | auto r = sd_bus_call_method(bus, busname, SOFTOFF_OBJPATH, iface, |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 48 | "Set", nullptr, nullptr, "ssv", |
| 49 | soft_off_iface, property, "s", value); |
| 50 | if (r < 0) |
| 51 | { |
| 52 | fprintf(stderr, "Failed to set property in SoftPowerOff object: %s\n", |
| 53 | strerror(-r)); |
| 54 | } |
| 55 | free (busname); |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | printf("Soft Power Off object is not available. Ignoring watchdog refresh"); |
| 60 | } |
| 61 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 62 | // either id[0] -or- id[1] can be filled in. We will use id[0] |
| 63 | soft_off.id[0] = SEL_OEM_ID_0; |
| 64 | soft_off.id[1] = SEL_OEM_ID_0; |
| 65 | soft_off.type = SEL_RECORD_TYPE_OEM; |
| 66 | |
| 67 | // Following 3 bytes are from IANA Manufactre_Id field. See below |
| 68 | soft_off.manuf_id[0]= 0x41; |
| 69 | soft_off.manuf_id[1]= 0xA7; |
| 70 | soft_off.manuf_id[2]= 0x00; |
| 71 | |
| 72 | // per IPMI spec NetFuntion for OEM |
| 73 | soft_off.netfun = 0x3A; |
| 74 | |
| 75 | // Mechanism to kick start soft shutdown. |
| 76 | soft_off.cmd = CMD_POWER; |
| 77 | soft_off.data[0] = SOFT_OFF; |
| 78 | |
| 79 | // All '0xFF' since unused. |
| 80 | memset(&soft_off.data[1], 0xFF, 3); |
| 81 | |
| 82 | // Pack the actual response |
| 83 | memcpy(response, &soft_off, *data_len); |
| 84 | return rc; |
| 85 | } |
| 86 | |
| 87 | //--------------------------------------------------------------------- |
| 88 | // Called by Host on seeing a SMS_ATN bit set. Return a hardcoded |
| 89 | // value of 0x2 indicating we need Host read some data. |
| 90 | //------------------------------------------------------------------- |
| 91 | ipmi_ret_t ipmi_app_get_msg_flags(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 92 | ipmi_request_t request, ipmi_response_t response, |
| 93 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 94 | { |
| 95 | // Generic return from IPMI commands. |
| 96 | ipmi_ret_t rc = IPMI_CC_OK; |
| 97 | |
| 98 | printf("IPMI APP GET MSG FLAGS returning with [bit:2] set\n"); |
| 99 | |
| 100 | // From IPMI spec V2.0 for Get Message Flags Command : |
| 101 | // bit:[1] from LSB : 1b = Event Message Buffer Full. |
| 102 | // Return as 0 if Event Message Buffer is not supported, |
| 103 | // or when the Event Message buffer is disabled. |
| 104 | // TODO. For now. assume its not disabled and send "0x2" anyway: |
| 105 | |
| 106 | uint8_t set_event_msg_buffer_full = 0x2; |
| 107 | *data_len = sizeof(set_event_msg_buffer_full); |
| 108 | |
| 109 | // Pack the actual response |
| 110 | memcpy(response, &set_event_msg_buffer_full, *data_len); |
| 111 | |
| 112 | return rc; |
| 113 | } |
| 114 | |
| 115 | ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 116 | ipmi_request_t request, ipmi_response_t response, |
| 117 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 118 | { |
| 119 | ipmi_ret_t rc = IPMI_CC_OK; |
| 120 | *data_len = 0; |
| 121 | |
| 122 | // Event and message logging enabled by default so return for now |
| 123 | printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n"); |
| 124 | |
| 125 | return rc; |
| 126 | } |
| 127 | |
| 128 | void register_netfn_app_functions() |
| 129 | { |
| 130 | |
| 131 | // <Read Event Message Buffer> |
| 132 | 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] | 133 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event, |
| 134 | SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 135 | |
| 136 | // <Set BMC Global Enables> |
| 137 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, |
| 138 | IPMI_CMD_SET_BMC_GLOBAL_ENABLES); |
| 139 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 140 | ipmi_app_set_bmc_global_enables, SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 141 | |
| 142 | // <Get Message Flags> |
| 143 | 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] | 144 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL, ipmi_app_get_msg_flags, |
| 145 | SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 146 | |
| 147 | return; |
| 148 | } |