1636577f4SEdward A. James #include "occ_presence.hpp" 294df8c90SGunnar Mills 394df8c90SGunnar Mills #include "occ_manager.hpp" 494df8c90SGunnar Mills 594df8c90SGunnar Mills #include <errno.h> 694df8c90SGunnar Mills #include <fcntl.h> 794df8c90SGunnar Mills #include <sys/ioctl.h> 894df8c90SGunnar Mills #include <unistd.h> 994df8c90SGunnar Mills 1094df8c90SGunnar Mills #include <org/open_power/OCC/Device/error.hpp> 11*d8aab2a9SPatrick Williams #include <phosphor-logging/elog-errors.hpp> 1294df8c90SGunnar Mills #include <phosphor-logging/elog.hpp> 1394df8c90SGunnar Mills #include <phosphor-logging/log.hpp> 1494df8c90SGunnar Mills #include <xyz/openbmc_project/Common/error.hpp> 15636577f4SEdward A. James 16636577f4SEdward A. James namespace open_power 17636577f4SEdward A. James { 18636577f4SEdward A. James namespace occ 19636577f4SEdward A. James { 20636577f4SEdward A. James 21636577f4SEdward A. James // Reads the occs_present file and analyzes the data 22636577f4SEdward A. James void Presence::analyzeEvent() 23636577f4SEdward A. James { 24636577f4SEdward A. James using namespace phosphor::logging; 25636577f4SEdward A. James using namespace sdbusplus::org::open_power::OCC::Device::Error; 26636577f4SEdward A. James 27636577f4SEdward A. James // Get the number of bytes to read 28636577f4SEdward A. James int len = -1; 29636577f4SEdward A. James auto r = ioctl(fd, FIONREAD, &len); 30636577f4SEdward A. James if (r < 0) 31636577f4SEdward A. James { 32636577f4SEdward A. James elog<ConfigFailure>( 3394df8c90SGunnar Mills phosphor::logging::org::open_power::OCC::Device::ConfigFailure:: 3494df8c90SGunnar Mills CALLOUT_ERRNO(errno), 3594df8c90SGunnar Mills phosphor::logging::org::open_power::OCC::Device::ConfigFailure:: 3694df8c90SGunnar Mills CALLOUT_DEVICE_PATH(file.c_str())); 37636577f4SEdward A. James } 38636577f4SEdward A. James 39636577f4SEdward A. James auto data = readFile(len); 40636577f4SEdward A. James if (data.empty()) 41636577f4SEdward A. James { 42636577f4SEdward A. James return; 43636577f4SEdward A. James } 44636577f4SEdward A. James 45636577f4SEdward A. James // Let stoi determine the base 46636577f4SEdward A. James auto occsPresent = std::stoi(data, nullptr, 0); 47636577f4SEdward A. James if (manager.getNumOCCs() != occsPresent) 48636577f4SEdward A. James { 49a7b74dc3SChris Cain log<level::ERR>(fmt::format("OCC presence mismatch - BMC: {}, OCC: {}", 50a7b74dc3SChris Cain manager.getNumOCCs(), occsPresent) 51a7b74dc3SChris Cain .c_str()); 52636577f4SEdward A. James if (callBack) 53636577f4SEdward A. James { 549789e71fSEddie James callBack(occsPresent); 55636577f4SEdward A. James } 56636577f4SEdward A. James } 57636577f4SEdward A. James } 58636577f4SEdward A. James 59636577f4SEdward A. James } // namespace occ 60636577f4SEdward A. James } // namespace open_power 61