blob: 304867c7a92d626368d1da4bb067d5fbe9d197c3 [file] [log] [blame]
Williamcb8ac882015-12-31 19:15:17 +08001#include "globalhandler.h"
Patrick Williams37af7332016-09-02 21:21:42 -05002#include "host-ipmid/ipmid-api.h"
Williamcb8ac882015-12-31 19:15:17 +08003#include <stdio.h>
4#include <string.h>
5#include <stdint.h>
Brad Bishop30be0f72016-10-05 23:39:41 -04006#include <mapper.h>
Williamcb8ac882015-12-31 19:15:17 +08007
8const char *control_object_name = "/org/openbmc/control/bmc0";
9const char *control_intf_name = "org.openbmc.control.Bmc";
10
Williamcb8ac882015-12-31 19:15:17 +080011void register_netfn_global_functions() __attribute__((constructor));
12
Nan Libc759882016-08-22 15:00:21 +080013int dbus_reset(const char *method)
Williamcb8ac882015-12-31 19:15:17 +080014{
15 sd_bus_error error = SD_BUS_ERROR_NULL;
16 sd_bus_message *m = NULL;
17 sd_bus *bus = NULL;
Williamcb8ac882015-12-31 19:15:17 +080018 char* connection = NULL;
Matthew Barth8b470052016-09-21 10:02:57 -050019 int r;
Williamcb8ac882015-12-31 19:15:17 +080020
Brad Bishop30be0f72016-10-05 23:39:41 -040021 bus = ipmid_get_sd_bus_connection();
22 r = mapper_get_service(bus, control_object_name, &connection);
Williamcb8ac882015-12-31 19:15:17 +080023 if (r < 0) {
Brad Bishop30be0f72016-10-05 23:39:41 -040024 fprintf(stderr, "Failed to get connection for %s: %s\n",
25 control_object_name, strerror(-r));
Williamcb8ac882015-12-31 19:15:17 +080026 goto finish;
27 }
28
29 printf("connection: %s\n", connection);
30
31 // Open the system bus where most system services are provided.
32 bus = ipmid_get_sd_bus_connection();
33
34 /*
35 * Bus, service, object path, interface and method are provided to call
36 * the method.
37 * Signatures and input arguments are provided by the arguments at the
38 * end.
Nan Libc759882016-08-22 15:00:21 +080039 */
Williamcb8ac882015-12-31 19:15:17 +080040 r = sd_bus_call_method(bus,
41 connection, /* service to contact */
42 control_object_name, /* object path */
43 control_intf_name, /* interface name */
Nan Libc759882016-08-22 15:00:21 +080044 method, /* method name */
Williamcb8ac882015-12-31 19:15:17 +080045 &error, /* object to return error in */
46 &m, /* return message on success */
47 NULL,
48 NULL
49 );
50
51 if (r < 0) {
52 fprintf(stderr, "Failed to issue method call: %s\n", error.message);
53 goto finish;
54 }
55
56finish:
57 sd_bus_error_free(&error);
58 sd_bus_message_unref(m);
59 free(connection);
60
61 return r;
62}
63
64ipmi_ret_t ipmi_global_warm_reset(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
65 ipmi_request_t request, ipmi_response_t response,
66 ipmi_data_len_t data_len, ipmi_context_t context)
67{
68 printf("Handling GLOBAL warmReset Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
69
70 // TODO: call the correct dbus method for warmReset.
Nan Libc759882016-08-22 15:00:21 +080071 dbus_reset("warmReset");
Williamcb8ac882015-12-31 19:15:17 +080072
73 // Status code.
74 ipmi_ret_t rc = IPMI_CC_OK;
75 *data_len = 0;
76 return rc;
77}
78
Nan Libc759882016-08-22 15:00:21 +080079ipmi_ret_t ipmi_global_cold_reset(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
80 ipmi_request_t request, ipmi_response_t response,
81 ipmi_data_len_t data_len, ipmi_context_t context)
82{
83 printf("Handling GLOBAL coldReset Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
84
85 // TODO: call the correct dbus method for coldReset.
86 dbus_reset("coldReset");
87
88 // Status code.
89 ipmi_ret_t rc = IPMI_CC_OK;
90 *data_len = 0;
91 return rc;
92}
Williamcb8ac882015-12-31 19:15:17 +080093
94void register_netfn_global_functions()
95{
Tom05732372016-09-06 17:21:23 +053096 // Cold Reset
Nan Libc759882016-08-22 15:00:21 +080097 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_COLD_RESET);
Tom05732372016-09-06 17:21:23 +053098 ipmi_register_callback(NETFUN_APP, IPMI_CMD_COLD_RESET, NULL, ipmi_global_cold_reset,
99 PRIVILEGE_ADMIN);
Nan Libc759882016-08-22 15:00:21 +0800100
Tom05732372016-09-06 17:21:23 +0530101 // <Warm Reset>
Williamcb8ac882015-12-31 19:15:17 +0800102 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WARM_RESET);
Tom05732372016-09-06 17:21:23 +0530103 ipmi_register_callback(NETFUN_APP, IPMI_CMD_WARM_RESET, NULL, ipmi_global_warm_reset,
104 PRIVILEGE_ADMIN);
Williamcb8ac882015-12-31 19:15:17 +0800105
Ratan Guptaeedf4f52016-02-25 18:53:52 +0530106 return;
Williamcb8ac882015-12-31 19:15:17 +0800107}