blob: 1389db989b8bc83b678b3fdc270bd760aaf887da [file] [log] [blame]
Adriana Kobylak40814c62015-10-27 15:58:44 -05001#include "chassishandler.h"
2#include "ipmid-api.h"
3#include <stdio.h>
4#include <string.h>
5#include <stdint.h>
6
vishwa36993272015-11-20 12:43:49 -06007// OpenBMC Chassis Manager dbus framework
8const char *chassis_bus_name = "org.openbmc.control.Chassis";
9const char *chassis_object_name = "/org/openbmc/control/chassis0";
10const char *chassis_intf_name = "org.openbmc.control.Chassis";
11
Adriana Kobylak40814c62015-10-27 15:58:44 -050012void register_netfn_chassis_functions() __attribute__((constructor));
13
14struct get_sys_boot_options_t {
15 uint8_t parameter;
16 uint8_t set;
17 uint8_t block;
18} __attribute__ ((packed));
19
20ipmi_ret_t ipmi_chassis_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
21 ipmi_request_t request, ipmi_response_t response,
22 ipmi_data_len_t data_len, ipmi_context_t context)
23{
24 printf("Handling CHASSIS WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
25 // Status code.
26 ipmi_ret_t rc = IPMI_CC_OK;
27 *data_len = 0;
28 return rc;
29}
30
vishwa36993272015-11-20 12:43:49 -060031//------------------------------------------------------------
32// Calls into Chassis Control Dbus object to do the power off
33//------------------------------------------------------------
Chris Austen7888c4d2015-12-03 15:26:20 -060034int ipmi_chassis_power_control(const char *method)
vishwa36993272015-11-20 12:43:49 -060035{
36 // sd_bus error
37 int rc = 0;
38
39 // SD Bus error report mechanism.
40 sd_bus_error bus_error = SD_BUS_ERROR_NULL;
41
42 // Response from the call. Although there is no response for this call,
43 // obligated to mention this to make compiler happy.
44 sd_bus_message *response = NULL;
45
46 // Gets a hook onto either a SYSTEM or SESSION bus
47 sd_bus *bus_type = ipmid_get_sd_bus_connection();
48
49 rc = sd_bus_call_method(bus_type, // On the System Bus
50 chassis_bus_name, // Service to contact
51 chassis_object_name, // Object path
52 chassis_intf_name, // Interface name
Chris Austen7888c4d2015-12-03 15:26:20 -060053 method, // Method to be called
vishwa36993272015-11-20 12:43:49 -060054 &bus_error, // object to return error
55 &response, // Response buffer if any
56 NULL); // No input arguments
57 if(rc < 0)
58 {
59 fprintf(stderr,"ERROR initiating Power Off:[%s]\n",bus_error.message);
60 }
61 else
62 {
63 printf("Chassis Power Off initiated successfully\n");
64 }
65
66 sd_bus_error_free(&bus_error);
67 sd_bus_message_unref(response);
68
69 return rc;
70}
71
Chris Austen7888c4d2015-12-03 15:26:20 -060072
vishwa36993272015-11-20 12:43:49 -060073//----------------------------------------------------------------------
74// Chassis Control commands
75//----------------------------------------------------------------------
76ipmi_ret_t ipmi_chassis_control(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
77 ipmi_request_t request, ipmi_response_t response,
78 ipmi_data_len_t data_len, ipmi_context_t context)
79{
80 // Error from power off.
81 int rc = 0;
82
83 // No response for this command.
84 *data_len = 0;
85
86 // Catch the actual operaton by peeking into request buffer
87 uint8_t chassis_ctrl_cmd = *(uint8_t *)request;
88 printf("Chassis Control Command: Operation:[0x%X]\n",chassis_ctrl_cmd);
89
90 switch(chassis_ctrl_cmd)
91 {
92 case CMD_POWER_OFF:
Chris Austen7888c4d2015-12-03 15:26:20 -060093 rc = ipmi_chassis_power_control("powerOff");
vishwa36993272015-11-20 12:43:49 -060094 break;
Chris Austen7888c4d2015-12-03 15:26:20 -060095 case CMD_HARD_RESET:
96 rc = ipmi_chassis_power_control("reboot");
97 break;
vishwa36993272015-11-20 12:43:49 -060098 default:
99 {
100 fprintf(stderr, "Invalid Chassis Control command:[0x%X] received\n",chassis_ctrl_cmd);
101 rc = -1;
102 }
103 }
104
105 return ( (rc < 0) ? IPMI_CC_INVALID : IPMI_CC_OK);
106}
107
Adriana Kobylak40814c62015-10-27 15:58:44 -0500108ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
109 ipmi_request_t request, ipmi_response_t response,
110 ipmi_data_len_t data_len, ipmi_context_t context)
111{
112 ipmi_ret_t rc = IPMI_CC_OK;
113 *data_len = 0;
114
115 printf("IPMI GET_SYS_BOOT_OPTIONS\n");
116
117 get_sys_boot_options_t *reqptr = (get_sys_boot_options_t*) request;
118
119 // TODO Return default values to OPAL until dbus interface is available
120
121 if (reqptr->parameter == 5) // Parameter #5
122 {
123 uint8_t buf[] = {0x1,0x5,80,0,0,0,0};
124 *data_len = sizeof(buf);
125 memcpy(response, &buf, *data_len);
126 }
127 else
128 {
129 fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter);
130 return IPMI_CC_PARM_NOT_SUPPORTED;
131 }
132
133 return rc;
134}
135
136void register_netfn_chassis_functions()
137{
138 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_WILDCARD);
139 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_WILDCARD, NULL, ipmi_chassis_wildcard);
140
141 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS);
142 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS, NULL, ipmi_chassis_get_sys_boot_options);
Adriana Kobylak40814c62015-10-27 15:58:44 -0500143
vishwa36993272015-11-20 12:43:49 -0600144 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL);
145 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL, NULL, ipmi_chassis_control);
146}