1de54f486SWilly Tu /* 2de54f486SWilly Tu // Copyright (c) 2018 Intel Corporation 3de54f486SWilly Tu // 4de54f486SWilly Tu // Licensed under the Apache License, Version 2.0 (the "License"); 5de54f486SWilly Tu // you may not use this file except in compliance with the License. 6de54f486SWilly Tu // You may obtain a copy of the License at 7de54f486SWilly Tu // 8de54f486SWilly Tu // http://www.apache.org/licenses/LICENSE-2.0 9de54f486SWilly Tu // 10de54f486SWilly Tu // Unless required by applicable law or agreed to in writing, software 11de54f486SWilly Tu // distributed under the License is distributed on an "AS IS" BASIS, 12de54f486SWilly Tu // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13de54f486SWilly Tu // See the License for the specific language governing permissions and 14de54f486SWilly Tu // limitations under the License. 15de54f486SWilly Tu */ 16de54f486SWilly Tu 17de54f486SWilly Tu #include <boost/algorithm/string.hpp> 18de54f486SWilly Tu #include <boost/bimap.hpp> 19de54f486SWilly Tu #include <boost/container/flat_map.hpp> 20de54f486SWilly Tu #include <cstdio> 21de54f486SWilly Tu #include <cstring> 22de54f486SWilly Tu #include <exception> 23de54f486SWilly Tu #include <filesystem> 24de54f486SWilly Tu #include <ipmid/api.hpp> 25de54f486SWilly Tu #include <ipmid/types.hpp> 26de54f486SWilly Tu #include <map> 27de54f486SWilly Tu #include <phosphor-logging/log.hpp> 28de54f486SWilly Tu #include <sdbusplus/bus/match.hpp> 29de54f486SWilly Tu #include <string> 30de54f486SWilly Tu #include <vector> 31de54f486SWilly Tu 32de54f486SWilly Tu #pragma once 33de54f486SWilly Tu 34de54f486SWilly Tu static constexpr bool debug = false; 35de54f486SWilly Tu 36de54f486SWilly Tu struct CmpStrVersion 37de54f486SWilly Tu { 38de54f486SWilly Tu bool operator()(std::string a, std::string b) const 39de54f486SWilly Tu { 40de54f486SWilly Tu return strverscmp(a.c_str(), b.c_str()) < 0; 41de54f486SWilly Tu } 42de54f486SWilly Tu }; 43de54f486SWilly Tu 44de54f486SWilly Tu using SensorSubTree = boost::container::flat_map< 45de54f486SWilly Tu std::string, 46de54f486SWilly Tu boost::container::flat_map<std::string, std::vector<std::string>>, 47de54f486SWilly Tu CmpStrVersion>; 48de54f486SWilly Tu 49de54f486SWilly Tu using SensorNumMap = boost::bimap<int, std::string>; 50de54f486SWilly Tu 51de54f486SWilly Tu static constexpr uint16_t maxSensorsPerLUN = 255; 52de54f486SWilly Tu static constexpr uint16_t maxIPMISensors = (maxSensorsPerLUN * 3); 53de54f486SWilly Tu static constexpr uint16_t lun1Sensor0 = 0x100; 54de54f486SWilly Tu static constexpr uint16_t lun3Sensor0 = 0x300; 55de54f486SWilly Tu static constexpr uint16_t invalidSensorNumber = 0xFFFF; 56de54f486SWilly Tu static constexpr uint8_t reservedSensorNumber = 0xFF; 57de54f486SWilly Tu 58de54f486SWilly Tu namespace details 59de54f486SWilly Tu { 60*a8b5b26dSKuiying Wang uint16_t getSensorSubtree(std::shared_ptr<SensorSubTree>& subtree); 61de54f486SWilly Tu 62de54f486SWilly Tu bool getSensorNumMap(std::shared_ptr<SensorNumMap>& sensorNumMap); 63de54f486SWilly Tu } // namespace details 64de54f486SWilly Tu 65de54f486SWilly Tu bool getSensorSubtree(SensorSubTree& subtree); 66de54f486SWilly Tu 67de54f486SWilly Tu struct CmpStr 68de54f486SWilly Tu { 69de54f486SWilly Tu bool operator()(const char* a, const char* b) const 70de54f486SWilly Tu { 71de54f486SWilly Tu return std::strcmp(a, b) < 0; 72de54f486SWilly Tu } 73de54f486SWilly Tu }; 74de54f486SWilly Tu 75de54f486SWilly Tu enum class SensorTypeCodes : uint8_t 76de54f486SWilly Tu { 77de54f486SWilly Tu reserved = 0x0, 78de54f486SWilly Tu temperature = 0x1, 79de54f486SWilly Tu voltage = 0x2, 80de54f486SWilly Tu current = 0x3, 81de54f486SWilly Tu fan = 0x4, 82de54f486SWilly Tu other = 0xB, 83de54f486SWilly Tu }; 84de54f486SWilly Tu 85de54f486SWilly Tu const static boost::container::flat_map<const char*, SensorTypeCodes, CmpStr> 86de54f486SWilly Tu sensorTypes{{{"temperature", SensorTypeCodes::temperature}, 87de54f486SWilly Tu {"voltage", SensorTypeCodes::voltage}, 88de54f486SWilly Tu {"current", SensorTypeCodes::current}, 89de54f486SWilly Tu {"fan_tach", SensorTypeCodes::fan}, 90de54f486SWilly Tu {"fan_pwm", SensorTypeCodes::fan}, 91de54f486SWilly Tu {"power", SensorTypeCodes::other}}}; 92de54f486SWilly Tu 93de54f486SWilly Tu std::string getSensorTypeStringFromPath(const std::string& path); 94de54f486SWilly Tu 95de54f486SWilly Tu uint8_t getSensorTypeFromPath(const std::string& path); 96de54f486SWilly Tu 97de54f486SWilly Tu uint16_t getSensorNumberFromPath(const std::string& path); 98de54f486SWilly Tu 99de54f486SWilly Tu uint8_t getSensorEventTypeFromPath(const std::string& path); 100de54f486SWilly Tu 101de54f486SWilly Tu std::string getPathFromSensorNumber(uint16_t sensorNum); 102de54f486SWilly Tu 103de54f486SWilly Tu namespace ipmi 104de54f486SWilly Tu { 105de54f486SWilly Tu std::map<std::string, std::vector<std::string>> 106de54f486SWilly Tu getObjectInterfaces(const char* path); 107de54f486SWilly Tu 108de54f486SWilly Tu std::map<std::string, Value> getEntityManagerProperties(const char* path, 109de54f486SWilly Tu const char* interface); 110de54f486SWilly Tu 111de54f486SWilly Tu const std::string* getSensorConfigurationInterface( 112de54f486SWilly Tu const std::map<std::string, std::vector<std::string>>& 113de54f486SWilly Tu sensorInterfacesResponse); 114de54f486SWilly Tu 115de54f486SWilly Tu void updateIpmiFromAssociation(const std::string& path, 116de54f486SWilly Tu const DbusInterfaceMap& sensorMap, 117de54f486SWilly Tu uint8_t& entityId, uint8_t& entityInstance); 118de54f486SWilly Tu } // namespace ipmi 119