summaryrefslogtreecommitdiffstats
path: root/apphandler.cpp
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2017-10-25 12:16:19 -0700
committerPatrick Venture <venture@google.com>2017-10-25 12:18:40 -0700
commit5e6ac715611ab118d243318ea44523cc67de77c4 (patch)
treed833a57e190903acce594fea64f0a45d44146572 /apphandler.cpp
parent5914678ceaa2b070ed67b16f7c8441947f514d4d (diff)
downloadphosphor-host-ipmid-5e6ac715611ab118d243318ea44523cc67de77c4.tar.gz
phosphor-host-ipmid-5e6ac715611ab118d243318ea44523cc67de77c4.zip
watchdog: split out commands
I split out the watchdog command handlers into their own subordinate file from the apphandler. This reduces the size of the contents of the apphandler file, and logically cuts out code into its own files. Change-Id: Idc70acad6c93c12456cc7092786715643c9c1ffb Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'apphandler.cpp')
-rw-r--r--apphandler.cpp170
1 files changed, 1 insertions, 169 deletions
diff --git a/apphandler.cpp b/apphandler.cpp
index 29adfa4..f1cd2dd 100644
--- a/apphandler.cpp
+++ b/apphandler.cpp
@@ -1,4 +1,5 @@
#include "apphandler.h"
+#include "app/watchdog.hpp"
#include "host-ipmid/ipmid-api.h"
#include "ipmid.hpp"
#include "types.hpp"
@@ -365,175 +366,6 @@ ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
return rc;
}
-
-struct set_wd_data_t {
- uint8_t t_use;
- uint8_t t_action;
- uint8_t preset;
- uint8_t flags;
- uint8_t ls;
- uint8_t ms;
-} __attribute__ ((packed));
-
-
-
-ipmi_ret_t ipmi_app_set_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
- ipmi_request_t request, ipmi_response_t response,
- ipmi_data_len_t data_len, ipmi_context_t context)
-{
- const char *objname = "/xyz/openbmc_project/watchdog/host0";
- const char *iface = "xyz.openbmc_project.State.Watchdog";
- const char *property_iface = "org.freedesktop.DBus.Properties";
- sd_bus_message *reply = NULL;
- sd_bus_error error = SD_BUS_ERROR_NULL;
- int r = 0;
-
- set_wd_data_t *reqptr = (set_wd_data_t*) request;
- uint16_t timer = 0;
-
- // Making this uint64_t to match with provider
- uint64_t timer_ms = 0;
- char *busname = NULL;
- *data_len = 0;
-
- // Get number of 100ms intervals
- timer = (((uint16_t)reqptr->ms) << 8) + reqptr->ls;
- // Get timer value in ms
- timer_ms = timer * 100;
-
- printf("WATCHDOG SET Timer:[0x%X] 100ms intervals\n",timer);
-
- // Get bus name
- r = mapper_get_service(bus, objname, &busname);
- if (r < 0) {
- fprintf(stderr, "Failed to get %s bus name: %s\n",
- objname, strerror(-r));
- goto finish;
- }
-
- // Disable watchdog if running
- r = sd_bus_call_method(bus, busname, objname, property_iface,
- "Set", &error, &reply, "ssv",
- iface, "Enabled", "b", false);
- if(r < 0) {
- fprintf(stderr, "Failed to disable Watchdog: %s\n",
- strerror(-r));
- goto finish;
- }
-
- /*
- * If the action is 0, it means, do nothing. Multiple actions on timer
- * expiration aren't supported by phosphor-watchdog yet, so when the
- * action set is "none", we should just leave the timer disabled.
- */
- if (0 == reqptr->t_action)
- {
- goto finish;
- }
-
- if (reqptr->t_use & 0x40)
- {
- sd_bus_error_free(&error);
- reply = sd_bus_message_unref(reply);
-
- // Set the Interval for the Watchdog
- r = sd_bus_call_method(bus, busname, objname, property_iface,
- "Set", &error, &reply, "ssv",
- iface, "Interval", "t", timer_ms);
- if(r < 0) {
- fprintf(stderr, "Failed to set new expiration time: %s\n",
- strerror(-r));
- goto finish;
- }
-
- // Now Enable Watchdog
- r = sd_bus_call_method(bus, busname, objname, property_iface,
- "Set", &error, &reply, "ssv",
- iface, "Enabled", "b", true);
- if(r < 0) {
- fprintf(stderr, "Failed to Enable Watchdog: %s\n",
- strerror(-r));
- goto finish;
- }
- }
-
-finish:
- sd_bus_error_free(&error);
- reply = sd_bus_message_unref(reply);
- free(busname);
-
- return (r < 0) ? -1 : IPMI_CC_OK;
-}
-
-
-ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
- ipmi_request_t request, ipmi_response_t response,
- ipmi_data_len_t data_len, ipmi_context_t context)
-{
- const char *objname = "/xyz/openbmc_project/watchdog/host0";
- const char *iface = "xyz.openbmc_project.State.Watchdog";
- const char *property_iface = "org.freedesktop.DBus.Properties";
- sd_bus_message *reply = NULL;
- sd_bus_error error = SD_BUS_ERROR_NULL;
- int r = 0;
- char *busname = NULL;
-
- // Current time interval that is set in watchdog.
- uint64_t interval = 0;
-
- // Status code.
- ipmi_ret_t rc = IPMI_CC_OK;
- *data_len = 0;
-
- printf("WATCHDOG RESET\n");
- // Get bus name
- r = mapper_get_service(bus, objname, &busname);
- if (r < 0) {
- fprintf(stderr, "Failed to get %s bus name: %s\n",
- objname, strerror(-r));
- goto finish;
- }
-
- // Get the current interval and set it back.
- r = sd_bus_call_method(bus, busname, objname, property_iface,
- "Get", &error, &reply, "ss",
- iface, "Interval");
-
- if(r < 0) {
- fprintf(stderr, "Failed to get current Interval msg: %s\n",
- strerror(-r));
- goto finish;
- }
-
- // Now extract the value
- r = sd_bus_message_read(reply, "v", "t", &interval);
- if (r < 0) {
- fprintf(stderr, "Failed to read current interval: %s\n",
- strerror(-r));
- goto finish;
- }
-
- sd_bus_error_free(&error);
- reply = sd_bus_message_unref(reply);
-
- // Set watchdog timer
- r = sd_bus_call_method(bus, busname, objname, property_iface,
- "Set", &error, &reply, "ssv",
- iface, "TimeRemaining", "t", interval);
- if(r < 0) {
- fprintf(stderr, "Failed to refresh the timer: %s\n",
- strerror(-r));
- goto finish;
- }
-
-finish:
- sd_bus_error_free(&error);
- reply = sd_bus_message_unref(reply);
- free(busname);
-
- return rc;
-}
-
extern struct ChannelConfig_t channelConfig;
ipmi_ret_t ipmi_set_channel_access(ipmi_netfn_t netfn,
OpenPOWER on IntegriCloud