From 61d5f7bcd892b9f546ad5b19ad96238110602743 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Fri, 9 Feb 2018 15:23:53 -0800 Subject: watchdog: Reorganize header and function names This is a refactoring of names + header cleanup and has no functional change. Change-Id: Ie90fded80b6a26927f56bb342993193530b8b8ef Signed-off-by: William A. Kennington III --- app/watchdog.cpp | 196 +++++++++++++++++++++++++++---------------------------- app/watchdog.hpp | 17 ++--- apphandler.cpp | 4 +- 3 files changed, 109 insertions(+), 108 deletions(-) diff --git a/app/watchdog.cpp b/app/watchdog.cpp index 6870aaa..c8c9ced 100644 --- a/app/watchdog.cpp +++ b/app/watchdog.cpp @@ -21,104 +21,7 @@ static constexpr auto objname = "/xyz/openbmc_project/watchdog/host0"; static constexpr auto iface = "xyz.openbmc_project.State.Watchdog"; static constexpr auto property_iface = "org.freedesktop.DBus.Properties"; -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) -{ - sd_bus_message *reply = NULL; - sd_bus_error error = SD_BUS_ERROR_NULL; - int r = 0; - ipmi_ret_t ret = IPMI_CC_UNSPECIFIED_ERROR; - - 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)); - ret = IPMI_CC_BUSY; - 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)); - ret = IPMI_CC_BUSY; - 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->timer_action) - { - ret = IPMI_CC_OK; - goto finish; - } - - if (reqptr->timer_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)); - ret = IPMI_CC_BUSY; - 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)); - ret = IPMI_CC_BUSY; - goto finish; - } - } - - ret = IPMI_CC_OK; -finish: - sd_bus_error_free(&error); - reply = sd_bus_message_unref(reply); - free(busname); - - return ret; -} - -ipmi_ret_t ipmi_app_reset_watchdog( +ipmi_ret_t ipmi_app_watchdog_reset( ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request, @@ -222,3 +125,100 @@ finish: return ret; } + +ipmi_ret_t ipmi_app_watchdog_set( + 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) +{ + sd_bus_message *reply = NULL; + sd_bus_error error = SD_BUS_ERROR_NULL; + int r = 0; + ipmi_ret_t ret = IPMI_CC_UNSPECIFIED_ERROR; + + 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)); + ret = IPMI_CC_BUSY; + 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)); + ret = IPMI_CC_BUSY; + 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->timer_action) + { + ret = IPMI_CC_OK; + goto finish; + } + + if (reqptr->timer_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)); + ret = IPMI_CC_BUSY; + 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)); + ret = IPMI_CC_BUSY; + goto finish; + } + } + + ret = IPMI_CC_OK; +finish: + sd_bus_error_free(&error); + reply = sd_bus_message_unref(reply); + free(busname); + + return ret; +} diff --git a/app/watchdog.hpp b/app/watchdog.hpp index f434493..c09bd1c 100644 --- a/app/watchdog.hpp +++ b/app/watchdog.hpp @@ -1,6 +1,8 @@ -#include "ipmid.hpp" +#pragma once -/** @brief The SET watchdog IPMI command. +#include "host-ipmid/ipmid-api.h" + +/** @brief The RESET watchdog IPMI command. * * @param[in] netfn * @param[in] cmd @@ -9,9 +11,9 @@ * @param[out] data_len * @param[in] context * - * @return IPMI_CC_OK on success, -1 otherwise. + * @return IPMI_CC_OK on success, an IPMI error code otherwise. */ -ipmi_ret_t ipmi_app_set_watchdog( +ipmi_ret_t ipmi_app_watchdog_reset( ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request, @@ -19,7 +21,7 @@ ipmi_ret_t ipmi_app_set_watchdog( ipmi_data_len_t data_len, ipmi_context_t context); -/** @brief The RESET watchdog IPMI command. +/** @brief The SET watchdog IPMI command. * * @param[in] netfn * @param[in] cmd @@ -28,13 +30,12 @@ ipmi_ret_t ipmi_app_set_watchdog( * @param[out] data_len * @param[in] context * - * @return IPMI_CC_OK on success, -1 otherwise. + * @return IPMI_CC_OK on success, an IPMI error code otherwise. */ -ipmi_ret_t ipmi_app_reset_watchdog( +ipmi_ret_t ipmi_app_watchdog_set( 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); - diff --git a/apphandler.cpp b/apphandler.cpp index 84cf3c9..47a165b 100644 --- a/apphandler.cpp +++ b/apphandler.cpp @@ -533,7 +533,7 @@ void register_netfn_app_functions() ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, - ipmi_app_reset_watchdog, + ipmi_app_watchdog_reset, PRIVILEGE_OPERATOR); // @@ -543,7 +543,7 @@ void register_netfn_app_functions() ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, - ipmi_app_set_watchdog, + ipmi_app_watchdog_set, PRIVILEGE_OPERATOR); // -- cgit v1.2.1