From 913cea1603b94531e6f1de0d480dfe614c9aa3ae Mon Sep 17 00:00:00 2001 From: Carl Philipp Klemm Date: Tue, 2 May 2023 18:58:52 +0200 Subject: [PATCH] add ipmi fan controll support --- CMakeLists.txt | 7 ++++--- main.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4eb83d6..5f17f3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,12 @@ set(CMAKE_CXX_STANDARD 20) find_package(Doxygen) find_package(PkgConfig REQUIRED) -pkg_search_module(IPMI REQUIRED libipmimonitoring) +pkg_search_module(IPMI_MONITORING REQUIRED libipmimonitoring) +pkg_search_module(IPMI REQUIRED libfreeipmi) add_executable(${PROJECT_NAME} main.cpp ipmi.cpp lm.cpp) -target_link_libraries(${PROJECT_NAME} ${IPMI_LINK_LIBRARIES} ${IPMIPOSIX_LINK_LIBRARIES} sensors) -target_include_directories(${PROJECT_NAME} PRIVATE ${IPMI_INCLUDE_DIRS} ${IPMIPOSIX_INCLUDE_DIRS}) +target_link_libraries(${PROJECT_NAME} ${IPMI_LINK_LIBRARIES} ${IPMI_MONITORING_LINK_LIBRARIES} sensors) +target_include_directories(${PROJECT_NAME} PRIVATE ${IPMI_INCLUDE_DIRS} ${IPMI_MONITORING_INCLUDE_DIRS}) target_compile_options(${PROJECT_NAME} PRIVATE "-Wall" "-O2" "-g" "-fno-strict-aliasing" "-Wfatal-errors" "-Wno-reorder") install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) diff --git a/main.cpp b/main.cpp index d8e1fb3..9798373 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,6 @@ +#include +#include +#include #include #include #include @@ -7,10 +10,13 @@ #include #include #include +#include #include "ipmi.h" #include "lm.h" +static constexpr size_t IPMI_RAW_MAX_ARGS = 65536*2; + sig_atomic_t running = true; void sig_handler(int sig) @@ -108,6 +114,35 @@ std::vector get_fan_zones(const std::vector& sensors) return out; } +ipmi_ctx_t ipmi_open() +{ + ipmi_ctx_t ctx = nullptr; + + ipmi_driver_type_t driver = IPMI_DEVICE_OPENIPMI; + int ret = ipmi_ctx_find_inband(ctx, &driver, false, 0, 0, nullptr, 0, 0); + if(ret < 0) + { + std::cerr<<"Could not create raw context "<(64), static_cast(speed*64)), static_cast(0)); + + char command[] = {0x70, 0x66, 0x01, static_cast(group), converted_speed}; + char bytesrx[IPMI_RAW_MAX_ARGS] = {0}; + int rxlen = ipmi_cmd_raw(raw_ctx, 0, 0x30, command, sizeof(command), bytesrx, IPMI_RAW_MAX_ARGS); + if(rxlen < 0) + { + std::cerr<<"Raw write to ipmi failed with: "< sensors = gather_sensors(ipmi_sensors, ctx, lm_chips); + std::vector sensors = gather_sensors(ipmi_sensors, monitoring_ctx, lm_chips); std::vector fanzones = get_fan_zones(sensors); for(const double fanzone : fanzones) std::cout<