Add Fii oem command
Signed-off-by: mohaimen alsamarai <mohaimen.alsamarai@fii-na.com>
Change-Id: I1b9113367f71d9484688b3d7fe4a923007fe31e2
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..f5cf270
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,109 @@
+cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
+
+cmake_policy (SET CMP0054 NEW)
+
+option (YOCTO "Use YOCTO depedencies system" OFF)
+include (ExternalProject)
+set (CMAKE_CXX_STANDARD 17)
+set (CMAKE_CXX_STANDARD_REQUIRED ON)
+set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
+
+
+set (
+ CMAKE_CXX_FLAGS
+ "${CMAKE_CXX_FLAGS} \
+ -Werror \
+ -Wtype-limits \
+ -Wnull-dereference \
+"
+)
+
+project (fii-ipmi-oem CXX)
+
+add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
+add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
+add_definitions (-DBOOST_ALL_NO_LIB)
+add_definitions (-DBOOST_NO_RTTI)
+add_definitions (-DBOOST_NO_TYPEID)
+add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
+add_definitions (-DBOOST_COROUTINES_NO_DEPRECATION_WARNING)
+add_definitions (-Wno-psabi)
+
+if (NOT YOCTO) # headers that can't be built without yocto
+ include_directories (SYSTEM non-yocto)
+
+ configure_file (CMakeLists.txt.in 3rdparty/CMakeLists.txt)
+ execute_process (COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty)
+ execute_process (COMMAND ${CMAKE_COMMAND} --build .
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty)
+
+ set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/prefix ${CMAKE_PREFIX_PATH})
+ include_directories (SYSTEM ${CMAKE_BINARY_DIR}/prefix/include)
+ link_directories (${CMAKE_BINARY_DIR}/prefix/lib)
+
+ include_directories (SYSTEM ${CMAKE_BINARY_DIR}/sdbusplus-src)
+ link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
+ include_directories (SYSTEM ${CMAKE_BINARY_DIR}/phosphor-logging-src)
+ link_directories (${CMAKE_BINARY_DIR}/phosphor-logging-src/.libs)
+ include_directories (SYSTEM ${CMAKE_BINARY_DIR}/phosphor-ipmi-host/include)
+ include_directories (SYSTEM ${CMAKE_BINARY_DIR}/ipmid/user_channel)
+ include_directories (SYSTEM ${CMAKE_BINARY_DIR}) # link_directories (${CMAK
+ # E_BINARY_DIR}/sdbusplus-
+ # src/.libs)
+endif ()
+
+if (YOCTO)
+ find_package (PkgConfig REQUIRED)
+ pkg_check_modules (LOGGING phosphor-logging REQUIRED)
+ include_directories (SYSTEM ${LOGGING_INCLUDE_DIRS})
+ link_directories (${LOGGING_LIBRARY_DIRS})
+
+ pkg_check_modules (LIBIPMID libipmid REQUIRED)
+ include_directories (SYSTEM ${LIBIPMID_INCLUDE_DIRS})
+ link_directories (${LIBIPMID_LIBRARY_DIRS})
+
+endif ()
+
+include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+#
+# import OpenSSL (crypto)
+find_package (OpenSSL REQUIRED)
+include_directories (SYSTEM ${OPENSSL_INCLUDE_DIR})
+
+include_directories (SYSTEM ${CMAKE_BINARY_DIR})
+add_custom_command(OUTPUT include/ipmi-whitelist.hpp
+ COMMAND ./generate-whitelist.py
+ ARGS ipmi-whitelist.conf ${CMAKE_BINARY_DIR}/ipmi-whitelist.hpp
+ MAIN_DEPENDENCY ipmi-whitelist.conf
+ DEPENDS generate-whitelist.py
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+add_library (fiioemcmds
+ SHARED
+ src/systemcommands.cpp
+ src/bioscommands.cpp)
+
+set_target_properties (fiioemcmds PROPERTIES VERSION "0.1.0")
+set_target_properties (fiioemcmds PROPERTIES SOVERSION "0")
+target_link_libraries (fiioemcmds stdc++fs)
+target_link_libraries (fiioemcmds ipmid)
+target_link_libraries (fiioemcmds sdbusplus)
+target_link_libraries (fiioemcmds phosphor_logging)
+target_link_libraries (fiioemcmds -luserlayer)
+target_link_libraries (fiioemcmds -lchannellayer)
+target_link_libraries (fiioemcmds ${OPENSSL_CRYPTO_LIBRARY})
+target_link_libraries (fiioemcmds gpiodcxx)
+
+install (TARGETS fiioemcmds DESTINATION lib/ipmid-providers)
+
+target_compile_definitions (
+ fiioemcmds PRIVATE
+# $<$<BOOL:${INTEL_PFR_ENABLED}>: -DINTEL_PFR_ENABLED>
+# $<$<BOOL:${BMC_VALIDATION_UNSECURE_FEATURE}>:
+# -DBMC_VALIDATION_UNSECURE_FEATURE>
+# $<$<BOOL:${MDR_V1_SUPPORT}>: -DMDR_V1_SUPPORT>
+# $<$<BOOL:${USING_ENTITY_MANAGER_DECORATORS}>:
+# -DUSING_ENTITY_MANAGER_DECORATORS>
+)
diff --git a/CMakeLists.txt.in b/CMakeLists.txt.in
new file mode 100644
index 0000000..f50f74d
--- /dev/null
+++ b/CMakeLists.txt.in
@@ -0,0 +1,31 @@
+cmake_minimum_required (VERSION 3.5)
+
+include (ExternalProject)
+
+file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/prefix)
+file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/prefix/include)
+
+# requires apt install autoconf-archive and autoconf
+
+externalproject_add (
+ host-ipmid PREFIX ${CMAKE_BINARY_DIR}/phosphor-host-ipmid GIT_REPOSITORY
+ https://github.com/openbmc/phosphor-host-ipmid SOURCE_DIR
+ ${CMAKE_BINARY_DIR}/phosphor-ipmi-host-src BINARY_DIR
+ ${CMAKE_BINARY_DIR}/phosphor-ipmi-host-build CONFIGURE_COMMAND cd
+ ${CMAKE_BINARY_DIR}/phosphor-ipmi-host-src && export
+ PYTHONPATH=${CMAKE_BINARY_DIR}/prefix/lib/python2.7/site-packages:$ENV{PYTHONPATH}
+ && export PATH=${CMAKE_BINARY_DIR}/prefix/bin:$ENV{PATH} && export
+ PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/prefix/lib/pkgconfig && ./bootstrap.sh
+ && ./configure --prefix=${CMAKE_BINARY_DIR}/prefix
+ CPPFLAGS=-I${CMAKE_BINARY_DIR}/prefix/include/
+ CXXFLAGS=-Wno-error=unused-result LDFLAGS=-L${CMAKE_BINARY_DIR}/prefix/lib/
+ BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/phosphor-ipmi-host-src && export
+ PYTHONPATH=${CMAKE_BINARY_DIR}/prefix/lib/python2.7/site-packages:$ENV{PYTHONPATH}
+ && export PATH=${CMAKE_BINARY_DIR}/prefix/bin:$ENV{PATH} && export
+ PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/prefix/lib/pkgconfig && make -j
+ verbose=1 INSTALL_COMMAND cd ${CMAKE_BINARY_DIR}/phosphor-ipmi-host-src &&
+ make install && mkdir -p
+ "${CMAKE_BINARY_DIR}/prefix/include/ipmid" && cp include/ipmid/api.h
+ "${CMAKE_BINARY_DIR}/prefix/include/ipmid/" LOG_DOWNLOAD ON
+)
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/MAINTAINERS b/MAINTAINERS
new file mode 100644
index 0000000..f4cb0b5
--- /dev/null
+++ b/MAINTAINERS
@@ -0,0 +1,46 @@
+How to use this list:
+ Find the most specific section entry (described below) that matches where
+ your change lives and add the reviewers (R) and maintainers (M) as
+ reviewers. You can use the same method to track down who knows a particular
+ code base best.
+
+ Your change/query may span multiple entries; that is okay.
+
+ If you do not find an entry that describes your request at all, someone
+ forgot to update this list; please at least file an issue or send an email
+ to a maintainer, but preferably you should just update this document.
+
+Description of section entries:
+
+ Section entries are structured according to the following scheme:
+
+ X: NAME <EMAIL_USERNAME@DOMAIN> <IRC_USERNAME!>
+ X: ...
+ .
+ .
+ .
+
+ Where REPO_NAME is the name of the repository within the OpenBMC GitHub
+ organization; FILE_PATH is a file path within the repository, possibly with
+ wildcards; X is a tag of one of the following types:
+
+ M: Denotes maintainer; has fields NAME <EMAIL_USERNAME@DOMAIN> <IRC_USERNAME!>;
+ if omitted from an entry, assume one of the maintainers from the
+ MAINTAINERS entry.
+ R: Denotes reviewer; has fields NAME <EMAIL_USERNAME@DOMAIN> <IRC_USERNAME!>;
+ these people are to be added as reviewers for a change matching the repo
+ path.
+ F: Denotes forked from an external repository; has fields URL.
+
+ Line comments are to be denoted "# SOME COMMENT" (typical shell style
+ comment); it is important to follow the correct syntax and semantics as we
+ may want to use automated tools with this file in the future.
+
+ A change cannot be added to an OpenBMC repository without a MAINTAINER's
+ approval; thus, a MAINTAINER should always be listed as a reviewer.
+
+START OF MAINTAINERS LIST
+-------------------------
+
+M: Lancelot Kao <lancelot.kao@fii-usa.com> <Lancelot-Kao!>
+M: Mohaimen Alsamarai <Mohaimen.Alsamarai@fii-na.com> <Mohaimen13!>
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e2aa7da
--- /dev/null
+++ b/README.md
@@ -0,0 +1,64 @@
+### Fii IPMI OEM Commands (0x34)
+
+There are and will be a variety of sys specific commands.
+
+### System Commands (0x h)
+
+#### PCIe Bifurcation Command 0x03
+
+The PCIe bifurcation command checks the type of pcei adapter instailled in
+each slot.
+
+Request
+
+|Byte(s) |Value |Data
+|--------|-------|----
+|0x00|0x03|Subcommand
+
+Response
+
+|Byte(s) |Value |Data
+|--------|-------|----
+|0x00|0x03|Subcommand
+|0x01|0x--|Bifurcation each bit identified the slot support x16(1b) or x8(0b)
+|0x02|0x--|Present bit each bit identified PCIe adapter installed(0b) or not(1b)
+
+Example
+|# |Command |Example
+|--------|-------|----
+|1|Read the information|ipmitool 0x34 0x03
+
+### BIOS Related Commands (7x h)
+
+#### BIOS Boot Count 0x71
+
+This is a 32 bits register that provides bios pushs the boot counter to BMC, or
+get the boot counter from BMC.
+
+Request
+
+|Byte(s) |Value |Data
+|--------|-------|----
+|0x00|0x03|Subcommand
+|0x01|0x00/0x01| read/write the boot counter register
+|0x02|0x--|Byte 0
+|0x03|0x--|Byte 1
+|0x04|0x--|Byte 2
+|0x05|0x--|Byte 3
+
+Response
+
+|Byte(s) |Value |Data
+|--------|-------|----
+|0x00|0x71|Subcommand
+|0x00|0x--|Byte 0
+|0x01|0x--|Byte 1
+|0x02|0x--|Byte 2
+|0x03|0x--|Byte 3
+
+Example
+|# |Command |Example
+|--------|-------|----
+|1|Read the boot count|ipmitool raw 0x34 0x71 0x00
+|2|Add the boot count by 1|ipmitool raw 0x34 0x71 0x01
+|3|Add the boot count by index|ipmitool raw 0x34 0x71 0x01 byte0 byte1 byte2 byte3
diff --git a/generate-whitelist.py b/generate-whitelist.py
new file mode 100755
index 0000000..c732726
--- /dev/null
+++ b/generate-whitelist.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python3
+
+import re, sys, os.path
+
+def usage():
+ sys.stderr.write("Usage: $0 whitelist-config-in whitelist-header-out\n")
+ sys.stderr.write(" Reads in whitelist config, sorting the contents\n")
+ sys.stderr.write(" and outputs a header file\n")
+ sys.exit(-1)
+
+class Error(Exception):
+ pass
+
+class DuplicateEntry(Error):
+ def __init__(self, e):
+ super(Error, self).__init__(
+ "Multiple entries with matching netfn/cmd found ({})".format(e))
+
+class ParseError(Error):
+ def __init__(self, d):
+ super(Error, self).__init__("Parse error at: '{}'".format(d))
+
+class entry:
+ linere = re.compile(
+ r'(0x[0-9a-f]{2}):(0x[0-9a-f]{2})((:(0x[0-9a-f]{4}))?)\s*((//\s*(.*))?)',
+ re.I
+ )
+ def __init__(self, data):
+ # parse data line into values:
+ # type 1, two values: netfn, cmd
+ # type 2, three values: netfn, cmd, channels
+ try:
+ m = self.linere.fullmatch(data).groups()
+ except:
+ raise ParseError(data)
+ self.netfn = int(m[0], 16)
+ self.cmd = int(m[1], 16)
+ if m[4] is not None:
+ self.channels = int(m[4], 16)
+ else:
+ # if no channel was provided, default to previous behavior, which
+ # is allow all interfaces, including the system interface (ch 15)
+ self.channels = 0xffff
+ if m[6] is not None:
+ self.comment = "// " + m[7]
+ else:
+ self.comment = "//"
+ def __str__(self):
+ return " ".join([ '{',
+ "0x{0.netfn:02x},".format(self),
+ "0x{0.cmd:02x},".format(self),
+ "0x{0.channels:04x}".format(self),
+ "},",
+ "{0.comment}".format(self),
+ ])
+ def __lt__(self, other):
+ if self.netfn == other.netfn:
+ return self.cmd < other.cmd
+ return self.netfn < other.netfn
+ def match(self, other):
+ return (self.netfn == other.netfn) and (self.cmd == other.cmd)
+
+def parse(config):
+ entries = []
+ with open(config) as f:
+ for line in f:
+ line = line.strip()
+ if len(line) == 0 or line[0] == '#':
+ continue
+ e = entry(line)
+ if any([e.match(item) for item in entries]):
+ d = DuplicateEntry(e)
+ sys.stderr.write("WARNING: {}\n".format(d))
+ else:
+ entries.append(e)
+ entries.sort()
+ return entries
+
+def output(entries, hppfile):
+ lines = [
+ "#pragma once",
+ "",
+ "// AUTOGENERATED FILE; DO NOT MODIFY",
+ "",
+ "#include <array>",
+ "#include <tuple>",
+ "",
+ "using netfncmd_tuple = std::tuple<unsigned char, unsigned char, unsigned short>;",
+ "",
+ "constexpr const std::array<netfncmd_tuple, {}> whitelist = ".format(
+ len(entries)),
+ "{{"
+ ]
+ lines.extend([' {}'.format(e) for e in entries])
+ lines.append("}};\n");
+
+ with open(hppfile, "w") as hpp:
+ hpp.write("\n".join(lines))
+
+
+if __name__ == "__main__":
+ if len(sys.argv) != 3:
+ usage()
+ config = sys.argv[1]
+ header = sys.argv[2]
+ entries = parse(config)
+ output(entries, header)
diff --git a/include/bioscommands.hpp b/include/bioscommands.hpp
new file mode 100644
index 0000000..15b6c13
--- /dev/null
+++ b/include/bioscommands.hpp
@@ -0,0 +1,26 @@
+/********************************************************************************
+* HON HAI Precision IND.Co., LTD. *
+* Personal Computer & Enterprise Product Business Group *
+* Enterprise Product Business Group *
+* *
+* Copyright (c) 2010 by FOXCONN/CESBG/CABG/SRD. All rights reserved. *
+* All data and information contained in this document is confidential *
+* and proprietary information of FOXCONN/CESBG/CABG/SRD and all rights *
+* are reserved. By accepting this material the recipient agrees that *
+* the information contained therein is held in confidence and in trust *
+* and will not be used, copied, reproduced in whole or in part, nor its *
+* contents revealed in any manner to others without the express written *
+* permission of FOXCONN/CESBG/CABG/SRD. *
+* *
+********************************************************************************/
+
+#pragma once
+
+#define BOOT_COUNT_FILE "/etc/conf/bios.cnt"
+
+enum fii_bios_cmds
+{
+ FII_CMD_BIOS_BOOT_COUNT = 0x71,
+};
+
+#define FII_CMD_BIOS_BOOT_COUNT_LEN 5
diff --git a/include/common.hpp b/include/common.hpp
new file mode 100644
index 0000000..c2d64a9
--- /dev/null
+++ b/include/common.hpp
@@ -0,0 +1,32 @@
+/********************************************************************************
+* HON HAI Precision IND.Co., LTD. *
+* Personal Computer & Enterprise Product Business Group *
+* Enterprise Product Business Gro:qup *
+* *
+* Copyright (c) 2010 by FOXCONN/CESBG/CABG/SRD. All rights reserved. *
+* All data and information contained in this document is confidential *
+* and proprietary information of FOXCONN/CESBG/CABG/SRD and all rights *
+* are reserved. By accepting this material the recipient agrees that *
+* the information contained therein is held in confidence and in trust *
+* and will not be used, copied, reproduced in whole or in part, nor its *
+* contents revealed in any manner to others without the express written *
+* permission of FOXCONN/CESBG/CABG/SRD. *
+* *
+********************************************************************************/
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <iostream>
+#include <iomanip>
+#include <sstream>
+#include <fstream>
+
+#include <ipmid/api.hpp>
+#include <ipmid/utils.hpp>
+#include <ipmid/message.hpp>
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/message/types.hpp>
+
+#define OP_CODE_READ 0b00
+#define OP_CODE_WRITE 0b01
+
diff --git a/include/systemcommands.hpp b/include/systemcommands.hpp
new file mode 100644
index 0000000..2a67a0b
--- /dev/null
+++ b/include/systemcommands.hpp
@@ -0,0 +1,24 @@
+/********************************************************************************
+* HON HAI Precision IND.Co., LTD. *
+* Personal Computer & Enterprise Product Business Group *
+* Enterprise Product Business Group *
+* *
+* Copyright (c) 2010 by FOXCONN/CESBG/CABG/SRD. All rights reserved. *
+* All data and information contained in this document is confidential *
+* and proprietary information of FOXCONN/CESBG/CABG/SRD and all rights *
+* are reserved. By accepting this material the recipient agrees that *
+* the information contained therein is held in confidence and in trust *
+* and will not be used, copied, reproduced in whole or in part, nor its *
+* contents revealed in any manner to others without the express written *
+* permission of FOXCONN/CESBG/CABG/SRD. *
+* *
+********************************************************************************/
+
+#pragma once
+
+#define PCIEINFO_COMMAND "i2cget -y -a -f 26 0x76 0x01 i 2"
+
+enum fii_sys_cmds
+{
+ FII_CMD_SYS_PCIE_INFO = 0x03,
+};
diff --git a/ipmi-whitelist.conf b/ipmi-whitelist.conf
new file mode 100644
index 0000000..67b9f76
--- /dev/null
+++ b/ipmi-whitelist.conf
@@ -0,0 +1,81 @@
+#<NetFn>:<Command>
+0x00:0x00 //<Chassis>:<Chassis Capabiliti>
+0x00:0x01 //<Chassis>:<Get Chassis Status>
+0x00:0x02 //<Chassis>:<Chassis Control>
+0x00:0x04 //<Chassis>:<Chassis Identify>
+0x00:0x05 //<Chassis>:<Set Chassis Capabilities>
+0x00:0x06 //<Chassis>:<Set Power Restore Policy>
+0x00:0x08 //<Chassis>:<Set System Boot Options>
+0x00:0x09 //<Chassis>:<Get System Boot Options>
+0x00:0x0F //<Chassis>:<Get POH Counter>
+0x04:0x02 //<Sensor/Event>:<Platform Event>
+0x04:0x20 //<Sensor/Event>:<Get Device SDR Info>
+0x04:0x21 //<Sensor/Event>:<Get Device SDR>
+0x04:0x22 //<Sensor/Event>:<Reserve Device SDR Repository>
+0x04:0x27 //<Sensor/Event>:<Get Sensor Threshold>
+0x04:0x29 //<Sensor/Event>:<Get Sensor Event Enable>
+0x04:0x2B //<Sensor/Event>:<Get Sensor Event Status>
+0x04:0x2D //<Sensor/Event>:<Get Sensor Reading>
+0x04:0x2F //<Sensor/Event>:<Get Sensor Type>
+0x04:0x30 //<Sensor/Event>:<Set Sensor Reading and Event Status>
+0x06:0x01 //<App>:<Get Device ID>
+0x06:0x02 //<App>:<Cold Reset>
+0x06:0x03 //<App>:<Warm Reset>
+0x06:0x04 //<App>:<Get Self Test Results>
+0x06:0x06 //<App>:<Set ACPI Power State>
+0x06:0x07 //<App>:<Get ACPI Power State>
+0x06:0x08 //<App>:<Get Device GUID>
+0x06:0x22 //<App>:<Reset Watchdog Timer>
+0x06:0x24 //<App>:<Set Watchdog Timer>
+0x06:0x25 //<App>:<Get Watchdog Timer>
+0x06:0x35 //<App>:<Read Event Message Buffer>
+0x06:0x3D //<App>:<Get Session Info>
+0x06:0x40 //<App>:<Set Channel Access>
+0x06:0x41 //<App>:<Get Channel Access>
+0x06:0x42 //<App>:<Get Channel Info>
+0x06:0x43 //<App>:<Set User Access>
+0x06:0x44 //<App>:<Get User Access>
+0x06:0x45 //<App>:<Set User Name>
+0x06:0x46 //<App>:<Get User Name>
+0x06:0x47 //<App>:<Set User Password>
+0x06:0x48 //<App>:<Activate Payload>
+0x06:0x49 //<App>:<Deactivate Payload>
+0x06:0x4A //<App>:<Get Payload Activation Status>
+0x06:0x4B //<App>:<Get Payload Instance Info>
+0x06:0x54 //<App>:<Get Channel Cipher Suites>
+0x06:0x58 //<App>:<Set System Info Parameters>
+0x06:0x59 //<App>:<Get System Info Parameters>
+0x0A:0x10 //<Storage>:<Get FRU Inventory Area Info>
+0x0A:0x11 //<Storage>:<Read FRU Data>
+0x0A:0x20 //<Storage>:<Get SDR Repository Info>
+0x0A:0x22 //<Storage>:<Reserve SDR Repository>
+0x0A:0x23 //<Storage>:<Get SDR>
+0x0A:0x40 //<Storage>:<Get SEL Info>
+0x0A:0x42 //<Storage>:<Reserve SEL>
+0x0A:0x43 //<Storage>:<Get SEL Entry>
+0x0A:0x44 //<Storage>:<Add SEL Entry>
+0x0A:0x46 //<Storage>:<Delete SEL Entry>
+0x0A:0x47 //<Storage>:<Clear SEL>
+0x0A:0x48 //<Storage>:<Get SEL Time>
+0x0A:0x49 //<Storage>:<Set SEL Time>
+0x0C:0x01 //<Transport>:<Set LAN Configuration Parameters>
+0x0C:0x02 //<Transport>:<Get LAN Configuration Parameters>
+0x2C:0x00 //<Group Extension>:<Group Extension Command>
+0x2C:0x01 //<Group Extension>:<Get DCMI Capabilities>
+0x2C:0x02 //<Group Extension>:<Get Power Reading>
+0x2C:0x03 //<Group Extension>:<Get Power Limit>
+0x2C:0x06 //<Group Extension>:<Get Asset Tag>
+0x2C:0x07 //<Group Extension>:<Get Sensor Info>
+0x2C:0x09 //<Group Extension>:<Get Management Controller Identifier String>
+0x2C:0x0A //<Group Extension>:<Set Management Controller Identifier String>
+0x2C:0x10 //<Group Extension>:<Get Temperature Readings>
+0x2C:0x12 //<Group Extension>:<Set DCMI Configuration Parameters>
+0x2C:0x13 //<Group Extension>:<Get DCMI Configuration Parameters>
+0x2C:0x3E //<Group Extension>:<Get HPM.x Capabilities>
+0x2E:0x02 //<Google OEM>:<I2C via Proxy Adapter>
+0x2E:0x04 //<Google OEM>:<Fan Manual Control Mode>
+0x2E:0x30 //<Google OEM>:<Ethernet Statistics>
+0x2E:0x32 //<Google OEM>:<Sys Commands>
+0x2E:0x80 //<Google OEM>:<Blob Commands>
+0x34:0x03 //<Fii OEM>:<System PCIe Bifurcation Commands>
+0x34:0x71 //<Fii OEM>:<BIOS Boot Count Commands>
diff --git a/src/bioscommands.cpp b/src/bioscommands.cpp
new file mode 100644
index 0000000..9670def
--- /dev/null
+++ b/src/bioscommands.cpp
@@ -0,0 +1,105 @@
+/********************************************************************************
+* HON HAI Precision IND.Co., LTD. *
+* Personal Computer & Enterprise Product Business Group *
+* Enterprise Product Business Gro:qup *
+* *
+* Copyright (c) 2010 by FOXCONN/CESBG/CABG/SRD. All rights reserved. *
+* All data and information contained in this document is confidential *
+* and proprietary information of FOXCONN/CESBG/CABG/SRD and all rights *
+* are reserved. By accepting this material the recipient agrees that *
+* the information contained therein is held in confidence and in trust *
+* and will not be used, copied, reproduced in whole or in part, nor its *
+* contents revealed in any manner to others without the express written *
+* permission of FOXCONN/CESBG/CABG/SRD. *
+* *
+********************************************************************************/
+
+#include <common.hpp>
+#include <bioscommands.hpp>
+
+namespace ipmi
+{
+ static void registerBIOSFunctions() __attribute__((constructor));
+
+ ipmi::RspType<std::vector<uint8_t>> FiiBIOSBootCount(boost::asio::yield_context yield, std::vector<uint8_t> reqParams)
+ {
+ bool op;
+ std::vector<uint8_t> boot_count;
+ uint32_t counter = 0, ret;
+
+ if (reqParams.empty())
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(" Fii bios cmd : command format error.");
+ return ipmi::responseReqDataLenInvalid();
+ }
+
+ op = reqParams[0] & 0b11;
+ // check the boot count file exist or not
+ std::fstream fptr(BOOT_COUNT_FILE);
+
+ if (!fptr.is_open())
+ {
+ std::cerr << " Fii bios cmd : file didn't exist and try to create one\n";
+ ret = system("mkdir -p /etc/conf");
+ std::ofstream outfile (BOOT_COUNT_FILE);
+ outfile << "0" << std::endl;
+ outfile.close();
+ boot_count.push_back(static_cast<uint8_t>(counter));
+ boot_count.push_back(static_cast<uint8_t>(counter >> 8));
+ boot_count.push_back(static_cast<uint8_t>(counter >> 16));
+ boot_count.push_back(static_cast<uint8_t>(counter >> 24));
+ return ipmi::responseSuccess(boot_count);
+ }
+ else
+ {
+ std::string str;
+ while (std::getline(fptr, str))
+ {
+ //boot_count.push_back(static_cast<uint8_t>(std::stoul(str)));
+ counter = (std::stoul(str));
+ //std::cerr << " Fii bios cmd : " << counter << std::endl;
+ }
+ boot_count.push_back(static_cast<uint8_t>(counter));
+ boot_count.push_back(static_cast<uint8_t>(counter >> 8));
+ boot_count.push_back(static_cast<uint8_t>(counter >> 16));
+ boot_count.push_back(static_cast<uint8_t>(counter >> 24));
+ fptr.close();
+ }
+ if (op == OP_CODE_READ)
+ {
+ return ipmi::responseSuccess(boot_count);
+ }
+ else if (op == OP_CODE_WRITE)
+ {
+ uint32_t value = 0;
+ if (reqParams.size() == 1)
+ {
+ boot_count[0] += 1;
+ value = boot_count[0] + (boot_count[1] << 8) + (boot_count[2] << 16) + (boot_count[3] << 24);
+ }
+ else if (reqParams.size() == FII_CMD_BIOS_BOOT_COUNT_LEN)
+ {
+ value = reqParams[1] + + (reqParams[2] << 8) + (reqParams[3] << 16) + (reqParams[4] << 24);
+ boot_count.clear();
+ boot_count.insert(boot_count.begin(), reqParams.begin()+1, reqParams.end());
+ }
+ std::ofstream fptr_w(BOOT_COUNT_FILE, std::ios::out | std::ios::trunc);
+ fptr_w << value << std::endl;
+ fptr_w.close();
+ }
+ else
+ {
+ return ipmi::responseInvalidCommand();
+ }
+ return ipmi::responseSuccess(boot_count);
+ }
+
+ void registerBIOSFunctions()
+ {
+ std::fprintf(stderr, "Registering OEM:[0x34], Cmd:[%#04X] for Fii BIOS OEM Commands\n", FII_CMD_BIOS_BOOT_COUNT);
+ ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemThree, FII_CMD_BIOS_BOOT_COUNT, ipmi::Privilege::User,
+ FiiBIOSBootCount);
+
+ return;
+ }
+}
diff --git a/src/systemcommands.cpp b/src/systemcommands.cpp
new file mode 100644
index 0000000..eb5a578
--- /dev/null
+++ b/src/systemcommands.cpp
@@ -0,0 +1,70 @@
+/********************************************************************************
+* HON HAI Precision IND.Co., LTD. *
+* Personal Computer & Enterprise Product Business Group *
+* Enterprise Product Business Gro:qup *
+* *
+* Copyright (c) 2010 by FOXCONN/CESBG/CABG/SRD. All rights reserved. *
+* All data and information contained in this document is confidential *
+* and proprietary information of FOXCONN/CESBG/CABG/SRD and all rights *
+* are reserved. By accepting this material the recipient agrees that *
+* the information contained therein is held in confidence and in trust *
+* and will not be used, copied, reproduced in whole or in part, nor its *
+* contents revealed in any manner to others without the express written *
+* permission of FOXCONN/CESBG/CABG/SRD. *
+* *
+********************************************************************************/
+
+#include <common.hpp>
+#include <systemcommands.hpp>
+
+#include <stdio.h>
+
+namespace ipmi
+{
+static void registerSystemFunctions() __attribute__((constructor));
+
+ipmi::RspType<std::vector<uint8_t>> FiiSysPCIeInfo(boost::asio::yield_context yield)
+{
+ std::vector<uint8_t> rsp;
+ char buffer[128], *token;
+ uint32_t value;
+ FILE *pipe = popen(PCIEINFO_COMMAND, "r");
+
+ // Read pcie bifurcation information
+ // it return two bytes, 1st byte bifurcation, 2nd byte present pin
+ if (!pipe) throw std::runtime_error("popen() failed !!!");
+ while (fgets(buffer, sizeof(buffer), pipe) != NULL)
+ {
+ std::cerr << " Command : " << buffer << std::endl;
+ }
+ pclose(pipe);
+
+ token = std::strtok(buffer, " ");
+ if (token == NULL)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Fii system cmd : Error geting PCIe Info came back null");
+ ipmi::responseUnspecifiedError();
+ }
+ token = std::strtok(NULL, " ");
+ while (token != NULL)
+ {
+ //std::cerr << " Command token: " << token << std::endl;
+ value = std::stoul(token, nullptr, 16);
+ //std::cerr << " Command value: " << value << ":" << std::hex << value << std::endl;
+ rsp.push_back(static_cast<uint8_t>(value & 0xFF));
+ token = std::strtok(NULL, " ");
+ }
+
+ return ipmi::responseSuccess(rsp);
+}
+
+void registerSystemFunctions()
+{
+ std::fprintf(stderr, "Registering OEM:[0x34], Cmd:[%#04X] for Fii System OEM Commands\n", FII_CMD_SYS_PCIE_INFO);
+ ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemThree, FII_CMD_SYS_PCIE_INFO, ipmi::Privilege::User,
+ FiiSysPCIeInfo);
+
+ return;
+}
+}