├── .clang-format ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake └── CodeCoverage.cmake ├── include ├── asd_common.h ├── asd_server_api.h ├── asd_server_interface.h ├── asd_target_api.h ├── asd_target_interface.h ├── config.h ├── logging.h └── uapi │ └── linux │ └── i3c │ └── i3cdev.h ├── jtag_test ├── CMakeLists.txt ├── jtag_test.c ├── jtag_test.h └── tests │ ├── CMakeLists.txt │ └── jtag_test_tests.c ├── server ├── CMakeLists.txt ├── asd_main.c ├── asd_main.h ├── asd_server_api.c ├── asd_target_interface.c ├── auth_none.c ├── auth_none.h ├── auth_pam.c ├── auth_pam.h ├── authenticate.c ├── authenticate.h ├── config.c ├── ext_network.c ├── ext_network.h ├── ext_tcp.c ├── ext_tcp.h ├── ext_tls.c ├── ext_tls.h ├── logging.c ├── pam-asd ├── session.c ├── session.h └── tests │ ├── CMakeLists.txt │ ├── asd_main_tests.c │ ├── auth_none_tests.c │ ├── auth_pam_tests.c │ ├── authenticate_tests.c │ ├── config_tests.c │ ├── ext_network_tests.c │ ├── ext_tcp_tests.c │ ├── ext_tls_tests.c │ ├── logging_tests.c │ └── session_tests.c ├── spp_test ├── CMakeLists.txt ├── debug_over_i3c │ ├── CMakeLists.txt │ ├── debug-over-i3c.c │ └── debug-over-i3c.h ├── spp_test.c └── spp_test.h └── target ├── CMakeLists.txt ├── asd_msg.c ├── asd_msg.h ├── asd_server_interface.c ├── asd_target_api.c ├── dbus_helper.c ├── dbus_helper.h ├── gpio.c ├── gpio.h ├── i2c_handler.c ├── i2c_handler.h ├── i2c_handler_stub.c ├── i2c_msg_builder.c ├── i2c_msg_builder.h ├── i2c_msg_builder_stub.c ├── i3c_debug_handler.c ├── i3c_debug_handler.h ├── i3c_handler.c ├── i3c_handler.h ├── i3c_handler_stub.c ├── jtag_handler.c ├── jtag_handler.h ├── spp_handler.c ├── spp_handler.h ├── spp_handler_stub.c ├── target_handler.c ├── target_handler.h ├── tests ├── CMakeLists.txt ├── asd_msg_tests.c ├── asd_msg_tests.h ├── dbus_helper_tests.c ├── gpio_tests.c ├── i2c_handler_tests.c ├── i2c_msg_builder_tests.c ├── i2c_msg_builder_tests.h ├── jtag.h ├── jtag_drv.h ├── jtag_handler_tests.c ├── os-release_bad ├── os-release_good └── target_handler_tests.c ├── vprobe_handler.c └── vprobe_handler.h /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | AccessModifierOffset: -2 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveAssignments: false 7 | AlignConsecutiveDeclarations: false 8 | AlignEscapedNewlinesLeft: false 9 | AlignOperands: true 10 | AlignTrailingComments: true 11 | AllowAllParametersOfDeclarationOnNextLine: true 12 | AllowShortBlocksOnASingleLine: false 13 | AllowShortCaseLabelsOnASingleLine: false 14 | AllowShortFunctionsOnASingleLine: None 15 | AllowShortIfStatementsOnASingleLine: false 16 | AllowShortLoopsOnASingleLine: false 17 | AlwaysBreakAfterDefinitionReturnType: None 18 | AlwaysBreakAfterReturnType: None 19 | AlwaysBreakBeforeMultilineStrings: false 20 | AlwaysBreakTemplateDeclarations: true 21 | BinPackArguments: true 22 | BinPackParameters: true 23 | BraceWrapping: 24 | AfterCaseLabel: true 25 | AfterClass: true 26 | AfterControlStatement: true 27 | AfterEnum: true 28 | AfterFunction: true 29 | AfterNamespace: true 30 | AfterObjCDeclaration: true 31 | AfterStruct: true 32 | AfterUnion: true 33 | BeforeCatch: true 34 | BeforeElse: true 35 | IndentBraces: false 36 | BreakBeforeBinaryOperators: None 37 | BreakBeforeBraces: Custom 38 | BreakBeforeTernaryOperators: true 39 | BreakConstructorInitializers: AfterColon 40 | ColumnLimit: 80 41 | CommentPragmas: '^ IWYU pragma:' 42 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 43 | ConstructorInitializerIndentWidth: 4 44 | ContinuationIndentWidth: 4 45 | Cpp11BracedListStyle: true 46 | DerivePointerAlignment: false 47 | PointerAlignment: Left 48 | DisableFormat: false 49 | ExperimentalAutoDetectBinPacking: false 50 | FixNamespaceComments: true 51 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 52 | IncludeBlocks: Regroup 53 | IncludeCategories: 54 | - Regex: '^[<"](gtest|gmock)' 55 | Priority: 5 56 | - Regex: '^"config.h"' 57 | Priority: -1 58 | - Regex: '^".*\.hpp"' 59 | Priority: 1 60 | - Regex: '^<.*\.h>' 61 | Priority: 2 62 | - Regex: '^<.*' 63 | Priority: 3 64 | - Regex: '.*' 65 | Priority: 4 66 | IndentCaseLabels: true 67 | IndentWidth: 4 68 | IndentWrappedFunctionNames: true 69 | KeepEmptyLinesAtTheStartOfBlocks: true 70 | MacroBlockBegin: '' 71 | MacroBlockEnd: '' 72 | MaxEmptyLinesToKeep: 1 73 | NamespaceIndentation: None 74 | ObjCBlockIndentWidth: 2 75 | ObjCSpaceAfterProperty: false 76 | ObjCSpaceBeforeProtocolList: true 77 | PenaltyBreakBeforeFirstCallParameter: 19 78 | PenaltyBreakComment: 300 79 | PenaltyBreakFirstLessLess: 120 80 | PenaltyBreakString: 1000 81 | PenaltyExcessCharacter: 1000000 82 | PenaltyReturnTypeOnItsOwnLine: 60 83 | ReflowComments: true 84 | SortIncludes: true 85 | SortUsingDeclarations: true 86 | SpaceAfterCStyleCast: false 87 | SpaceBeforeAssignmentOperators: true 88 | SpaceBeforeParens: ControlStatements 89 | SpaceInEmptyParentheses: false 90 | SpacesBeforeTrailingComments: 1 91 | SpacesInAngles: false 92 | SpacesInContainerLiterals: true 93 | SpacesInCStyleCastParentheses: false 94 | SpacesInParentheses: false 95 | SpacesInSquareBrackets: false 96 | Standard: Cpp11 97 | TabWidth: 4 98 | UseTab: Never 99 | ... 100 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR) 2 | project(at-scale-debug C) 3 | 4 | find_package (PkgConfig REQUIRED) 5 | set(ASD_DIR ${PROJECT_SOURCE_DIR}) 6 | 7 | add_subdirectory(jtag_test) 8 | add_subdirectory(server) 9 | add_subdirectory(target) 10 | add_subdirectory(spp_test) 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020, Intel Corporation 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | (1) Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | (2) Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the 13 | distribution. 14 | 15 | (3)The name of the author may not be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 23 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 28 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # at-scale-debug 3 | 4 | Intel(R) At-Scale Debug (ASD) solution provides debug access through the BMC 5 | to the CPU/PCH JTAG chain(s) and target pins in order to facilitate debug. 6 | 7 | ## Development Pre-commit Checklist 8 | 9 | To keep the code tidy, or moving in that direction, 10 | please follow these steps for each commit. 11 | 12 | * **Write unit tests for all new code** 13 | 14 | Please ensure dependencies for the unit of code under test are mocked out 15 | to reduce the unit test complexity and maintain a fast set of tests. Also 16 | limit the scope of the unit test as much as possible. 17 | 18 | * **Ensure all unit tests pass** 19 | 20 | Each c file has it's own set of unit tests. You can run them individually 21 | if you like, or run ctest to run them all at once. 22 | 23 | An example to run them all at once: 24 | 25 | `(cd [build-path]/tmp/work/[platform]/at-scale-debug/1.0-r0/build/tests/; ctest)` 26 | 27 | * **Code coverage tools can be used to verify all code is tested** 28 | 29 | To build and generate a code coverage report, run: 30 | `make && make test_coverage` 31 | Then open the index.html in the test_coverage directory. 32 | 33 | * **Run clang-format to fix code style** 34 | 35 | Note the '.clang-format' config file is used when providing the '-style=file' 36 | argument. 37 | 38 | `clang-format -style=file -i ` 39 | 40 | * **Run valgrind** 41 | 42 | Since all code is unit tested, its helpful run Valgrind on the unit tests to 43 | screen for potential issues. 44 | 45 | ## Running Jtag Test on BMC 46 | 47 | asd & jtag_test can be found in /usr/bin on the BMC. 48 | From the BMC console, type `jtag_test --help` or 'asd --help' 49 | for instructions. 50 | -------------------------------------------------------------------------------- /include/asd_server_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _ASD_SERVER_API_H_ 29 | #define _ASD_SERVER_API_H_ 30 | 31 | #include "asd_common.h" 32 | #include "logging.h" 33 | 34 | #define ASD_SERVER_API_VERSION_MAJOR 1 35 | #define ASD_SERVER_API_VERSION_MINOR 0 36 | #define ASD_SERVER_API_VERSION_PATCH 0 37 | #define MAX_SERVER_VERSION_SIZE 12 38 | 39 | #define IOCTL_SERVER_GET_API_VERSION 0 40 | #define IOCTL_SERVER_GET_INTERFACE_VERSION 1 41 | #define IOCTL_SERVER_IS_INTERFACE_SUPPORTED 2 42 | #define IOCTL_SERVER_IS_DATA_PENDING 3 43 | 44 | size_t asd_server_read(unsigned char* buffer, size_t length, void* opt); 45 | size_t asd_server_write(void* buffer, size_t length, void* opt); 46 | STATUS asd_server_ioctl(void* input, void* output, unsigned int cmd); 47 | 48 | void asd_server_log(ASD_LogLevel level, ASD_LogStream stream, 49 | ASD_LogOption options, const char* string); 50 | void asd_server_log_buffer(ASD_LogLevel level, ASD_LogStream stream, 51 | ASD_LogOption options, const unsigned char* ptr, 52 | size_t len, const char* prefixPtr); 53 | void asd_server_log_shift(ASD_LogLevel level, ASD_LogStream stream, 54 | ASD_LogOption options, unsigned int number_of_bits, 55 | unsigned int size_bytes, unsigned char* buffer, 56 | const char* prefixPtr); 57 | #endif -------------------------------------------------------------------------------- /include/asd_server_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _ASD_SERVER_INTERFACE_H_ 29 | #define _ASD_SERVER_INTERFACE_H_ 30 | 31 | #include "asd_common.h" 32 | #include "logging.h" 33 | 34 | #define ASD_SERVER_INTERFACE_API_VERSION_MAJOR 1 35 | #define ASD_SERVER_INTERFACE_API_VERSION_MINOR 0 36 | #define ASD_SERVER_INTERFACE_API_VERSION_PATCH 0 37 | #define MAX_SERVER_INTERFACE_VERSION_SIZE 12 38 | 39 | #define IOCTL_SERVER_GET_API_VERSION 0 40 | #define IOCTL_SERVER_GET_INTERFACE_VERSION 1 41 | #define IOCTL_SERVER_IS_INTERFACE_SUPPORTED 2 42 | #define IOCTL_SERVER_IS_DATA_PENDING 3 43 | 44 | 45 | #define MAX_LOG_SIZE 120 46 | 47 | size_t asd_api_server_read(unsigned char* buffer, size_t length, void* opt); 48 | size_t asd_api_server_write(void* buffer, size_t length, void* opt); 49 | STATUS asd_api_server_ioctl(void* input, void* output, unsigned int cmd); 50 | 51 | void asd_api_server_log(ASD_LogLevel level, ASD_LogStream stream, 52 | ASD_LogOption options, const char* format, ...); 53 | void asd_api_server_log_buffer(ASD_LogLevel level, ASD_LogStream stream, 54 | ASD_LogOption options, const unsigned char* ptr, 55 | size_t len, const char* prefixPtr); 56 | void asd_api_server_log_shift(ASD_LogLevel level, ASD_LogStream stream, 57 | ASD_LogOption options, 58 | unsigned int number_of_bits, 59 | unsigned int size_bytes, unsigned char* buffer, 60 | const char* prefixPtr); 61 | #endif -------------------------------------------------------------------------------- /include/asd_target_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _ASD_TARGET_API_H_ 29 | #define _ASD_TARGET_API_H_ 30 | 31 | #include "asd_common.h" 32 | #include "logging.h" 33 | #include "config.h" 34 | 35 | #define ASD_TARGET_API_VERSION_MAJOR 1 36 | #define ASD_TARGET_API_VERSION_MINOR 0 37 | #define ASD_TARGET_API_VERSION_PATCH 0 38 | #define MAX_TARGET_VERSION_SIZE 12 39 | 40 | #define IOCTL_TARGET_GET_API_VERSION 0 41 | #define IOCTL_TARGET_GET_INTERFACE_VERSION 1 42 | #define IOCTL_TARGET_IS_INTERFACE_SUPPORTED 2 43 | #define IOCTL_TARGET_PROCESS_MSG 3 44 | #define IOCTL_TARGET_GET_PIN_FDS 4 45 | #define IOCTL_TARGET_PROCESS_ALL_PIN_EVENTS 5 46 | #define IOCTL_TARGET_PROCESS_PIN_EVENT 6 47 | #define IOCTL_TARGET_SEND_REMOTE_LOG_MSG 7 48 | #define IOCTL_TARGET_GET_I2C_I3C_BUS_CONFIG 8 49 | 50 | typedef struct asd_target_events { 51 | target_fdarr_t fds; 52 | int num_fds; 53 | } asd_target_events; 54 | 55 | typedef struct poll_asd_target_events { 56 | struct pollfd * poll_fds; 57 | int num_fds; 58 | } poll_asd_target_events; 59 | 60 | typedef struct asd_target_remote_log { 61 | ASD_LogLevel level; 62 | ASD_LogStream stream; 63 | const char* msg; 64 | } asd_target_remote_log; 65 | 66 | STATUS asd_target_init(config* asd_cfg); 67 | STATUS asd_target_deinit(void); 68 | size_t asd_target_read(unsigned char* buffer, size_t length, void* opt); /* unused */ 69 | size_t asd_target_write(unsigned char* buffer, size_t length, void* opt); /* unused */ 70 | STATUS asd_target_ioctl(void* input, void* output, unsigned int cmd); 71 | 72 | void asd_target_log(ASD_LogLevel level, ASD_LogStream stream, 73 | ASD_LogOption options, const char* string); 74 | void asd_target_log_buffer(ASD_LogLevel level, ASD_LogStream stream, 75 | ASD_LogOption options, const unsigned char* ptr, 76 | size_t len, const char* prefixPtr); 77 | void asd_target_log_shift(ASD_LogLevel level, ASD_LogStream stream, 78 | ASD_LogOption options, unsigned int number_of_bits, 79 | unsigned int size_bytes, unsigned char* buffer, 80 | const char* prefixPtr); 81 | #endif -------------------------------------------------------------------------------- /include/asd_target_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _ASD_TARGET_INTERFACE_H_ 29 | #define _ASD_TARGET_INTERFACE_H_ 30 | 31 | #include "asd_common.h" 32 | #include "logging.h" 33 | #include "config.h" 34 | 35 | #define ASD_TARGET_INTERFACE_API_VERSION_MAJOR 1 36 | #define ASD_TARGET_INTERFACE_API_VERSION_MINOR 0 37 | #define ASD_TARGET_INTERFACE_API_VERSION_PATCH 0 38 | #define MAX_TARGET_INTERFACE_VERSION_SIZE 12 39 | 40 | #define IOCTL_TARGET_GET_API_VERSION 0 41 | #define IOCTL_TARGET_GET_INTERFACE_VERSION 1 42 | #define IOCTL_TARGET_IS_INTERFACE_SUPPORTED 2 43 | #define IOCTL_TARGET_PROCESS_MSG 3 44 | #define IOCTL_TARGET_GET_PIN_FDS 4 45 | #define IOCTL_TARGET_PROCESS_ALL_PIN_EVENTS 5 46 | #define IOCTL_TARGET_PROCESS_PIN_EVENT 6 47 | #define IOCTL_TARGET_SEND_REMOTE_LOG_MSG 7 48 | #define IOCTL_TARGET_GET_I2C_I3C_BUS_CONFIG 8 49 | 50 | #define MAX_LOG_SIZE 120 51 | 52 | typedef struct asd_target_interface_events { 53 | target_fdarr_t fds; 54 | int num_fds; 55 | } asd_target_interface_events; 56 | 57 | typedef struct poll_asd_target_interface_events { 58 | struct pollfd * poll_fds; 59 | int num_fds; 60 | } poll_asd_target_interface_events; 61 | 62 | typedef struct asd_target_interface_remote_log { 63 | ASD_LogLevel level; 64 | ASD_LogStream stream; 65 | const char* msg; 66 | } asd_target_interface_remote_log; 67 | 68 | STATUS asd_api_target_init(config* asd_cfg); 69 | STATUS asd_api_target_deinit(void); 70 | size_t asd_api_target_read(unsigned char* buffer, size_t length, void* opt); /* unused */ 71 | size_t asd_api_target_write(unsigned char* buffer, size_t length, void* opt); /* unused */ 72 | STATUS asd_api_target_ioctl(void* input, void* output, unsigned int cmd); 73 | 74 | void asd_api_target_log(ASD_LogLevel level, ASD_LogStream stream, 75 | ASD_LogOption options, const char* format, ...); 76 | void asd_api_target_log_buffer(ASD_LogLevel level, ASD_LogStream stream, 77 | ASD_LogOption options, const unsigned char* ptr, 78 | size_t len, const char* prefixPtr); 79 | void asd_api_target_log_shift(ASD_LogLevel level, ASD_LogStream stream, 80 | ASD_LogOption options, unsigned int number_of_bits, 81 | unsigned int size_bytes, unsigned char* buffer, 82 | const char* prefixPtr); 83 | 84 | #endif -------------------------------------------------------------------------------- /include/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef __CONFIG_H_ 29 | #define __CONFIG_H_ 30 | 31 | #include "asd_common.h" 32 | 33 | typedef enum 34 | { 35 | JTAG_DRIVER_MODE_SOFTWARE = 0, 36 | JTAG_DRIVER_MODE_HARDWARE = 1 37 | } JTAG_DRIVER_MODE; 38 | 39 | typedef struct jtag_config 40 | { 41 | // use HW or SW jtag driver. 42 | JTAG_DRIVER_MODE mode; 43 | JTAG_CHAIN_SELECT_MODE chain_mode; 44 | bool xdp_fail_enable; 45 | } jtag_config; 46 | 47 | typedef struct bus_config 48 | { 49 | bool enable_i2c; 50 | bool enable_i3c; 51 | bool enable_spp; 52 | uint8_t default_bus; 53 | bus_config_type bus_config_type[MAX_IxC_BUSES + MAX_SPP_BUSES]; 54 | uint8_t bus_config_map[MAX_IxC_BUSES + MAX_SPP_BUSES]; 55 | } bus_config; 56 | 57 | typedef struct config 58 | { 59 | jtag_config jtag; 60 | remote_logging_config remote_logging; 61 | IPC_LogType ipc_asd_log_map[6]; 62 | bus_config buscfg; 63 | timeout_config timecfg; 64 | } config; 65 | 66 | STATUS set_config_defaults(config* config, const bus_options* opt, const timeout_config* tmo_cfg); 67 | 68 | #endif // __CONFIG_H_ -------------------------------------------------------------------------------- /include/logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _LOGGING_H_ 29 | #define _LOGGING_H_ 30 | 31 | #include 32 | #include 33 | 34 | #define ENABLE_DEBUG_LOGGING 35 | #define LOG_TIMESTAMP_LENGTH 17 36 | #define LOG_MESSAGE_LENGTH 4096 37 | #define LOG_TIME_MESSAGE_LENGTH (LOG_MESSAGE_LENGTH + LOG_TIMESTAMP_LENGTH) 38 | #define LOG_TIME_LINE_LENGTH 180 39 | #define CALLBACK_LOG_MESSAGE_LENGTH 256 40 | 41 | typedef enum 42 | { 43 | ASD_LogLevel_Trace = 0, 44 | ASD_LogLevel_Debug, 45 | ASD_LogLevel_Info, 46 | ASD_LogLevel_Warning, 47 | ASD_LogLevel_Error, 48 | ASD_LogLevel_Off 49 | } ASD_LogLevel; 50 | 51 | static const char* ASD_LogLevelString[] = {"Trace", "Debug", "Info", 52 | "Warning", "Error", "Off"}; 53 | 54 | typedef enum 55 | { 56 | ASD_LogStream_None = 0, 57 | ASD_LogStream_Network = 1, 58 | ASD_LogStream_JTAG = 2, 59 | ASD_LogStream_Pins = 4, 60 | ASD_LogStream_I2C = 8, 61 | ASD_LogStream_Test = 16, 62 | ASD_LogStream_Daemon = 32, 63 | ASD_LogStream_SDK = 64, 64 | ASD_LogStream_SPP = 128, 65 | ASD_LogStream_All = 0xFFFF, 66 | } ASD_LogStream; 67 | 68 | typedef enum 69 | { 70 | ASD_LogOption_None = 0, 71 | ASD_LogOption_No_Remote = 1 72 | } ASD_LogOption; 73 | 74 | extern ASD_LogLevel asd_log_level; 75 | extern ASD_LogStream asd_log_streams; 76 | 77 | typedef bool (*ShouldLogFunctionPtr)(ASD_LogLevel, ASD_LogStream); 78 | typedef void (*LogFunctionPtr)(ASD_LogLevel, ASD_LogStream, const char*); 79 | 80 | void ASD_log(ASD_LogLevel level, ASD_LogStream stream, ASD_LogOption options, 81 | const char* format, ...); 82 | 83 | void ASD_log_buffer(ASD_LogLevel level, ASD_LogStream stream, 84 | ASD_LogOption options, const unsigned char* ptr, size_t len, 85 | const char* prefixPtr); 86 | 87 | void ASD_log_shift(ASD_LogLevel level, ASD_LogStream stream, 88 | ASD_LogOption options, unsigned int number_of_bits, 89 | unsigned int size_bytes, unsigned char* buffer, 90 | const char* prefixPtr); 91 | 92 | void ASD_initialize_log_settings(ASD_LogLevel level, ASD_LogStream stream, 93 | bool write_to_syslog, 94 | bool log_timestamp_enable, 95 | ShouldLogFunctionPtr should_log_ptr, 96 | LogFunctionPtr log_ptr); 97 | 98 | bool strtolevel(char* input, ASD_LogLevel* output); 99 | 100 | bool strtostreams(char* input, ASD_LogStream* output); 101 | 102 | // maps individual ASD_LogStream flag values to string values. 103 | static inline char* streamtostring(ASD_LogStream stream) 104 | { 105 | if (stream == ASD_LogStream_None) 106 | return "None"; 107 | if (stream == ASD_LogStream_Network) 108 | return "Network"; 109 | if (stream == ASD_LogStream_JTAG) 110 | return "JTAG"; 111 | if (stream == ASD_LogStream_Pins) 112 | return "Pins"; 113 | if (stream == ASD_LogStream_I2C) 114 | return "I2C"; 115 | if (stream == ASD_LogStream_Test) 116 | return "Test"; 117 | if (stream == ASD_LogStream_Daemon) 118 | return "Daemon"; 119 | if (stream == ASD_LogStream_SDK) 120 | return "SDK"; 121 | if (stream == ASD_LogStream_SPP) 122 | return "SPP"; 123 | if (stream == ASD_LogStream_All) 124 | return "All"; 125 | return "Unknown-Stream"; 126 | } 127 | 128 | bool ASD_get_timestamp(char* time_buffer); 129 | 130 | #endif // _LOGGING_H_ 131 | -------------------------------------------------------------------------------- /include/uapi/linux/i3c/i3cdev.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2019 Synopsys, Inc. and/or its affiliates. 4 | * 5 | * Author: Vitor Soares 6 | */ 7 | 8 | #ifndef _UAPI_I3C_DEV_H_ 9 | #define _UAPI_I3C_DEV_H_ 10 | 11 | #include 12 | #include 13 | 14 | /* IOCTL commands */ 15 | #define I3C_DEV_IOC_MAGIC 0x07 16 | 17 | /** 18 | * struct i3c_ioc_priv_xfer - I3C SDR ioctl private transfer 19 | * @data: Holds pointer to userspace buffer with transmit data. 20 | * @len: Length of data buffer buffers, in bytes. 21 | * @rnw: encodes the transfer direction. true for a read, false for a write 22 | */ 23 | struct i3c_ioc_priv_xfer { 24 | __u64 data; 25 | __u16 len; 26 | __u8 rnw; 27 | __u8 pad[5]; 28 | }; 29 | 30 | 31 | #define I3C_PRIV_XFER_SIZE(N) \ 32 | ((((sizeof(struct i3c_ioc_priv_xfer)) * (N)) < (1 << _IOC_SIZEBITS)) \ 33 | ? ((sizeof(struct i3c_ioc_priv_xfer)) * (N)) : 0) 34 | 35 | #define I3C_IOC_PRIV_XFER(N) \ 36 | _IOC(_IOC_READ|_IOC_WRITE, I3C_DEV_IOC_MAGIC, 30, I3C_PRIV_XFER_SIZE(N)) 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /jtag_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR) 2 | project(at-scale-debug-jtag-test C) 3 | 4 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sysroot/include) 5 | pkg_check_modules (SAFEC REQUIRED libsafec) 6 | # Define HAVE_C99 to include sprintf_s macro in safec library 7 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_C99") 8 | include_directories (${SAFEC_INCLUDE_DIRS}) 9 | include_directories (${ASD_DIR}/include) 10 | include_directories (${ASD_DIR}/target) 11 | link_directories (${SAFEC_LIBRARY_DIRS}) 12 | 13 | # Set APB_FREQ to EXTRA_OECMAKE on bb recipe to modify JTAG frequency 14 | if(${APB_FREQ}) 15 | add_definitions( -DAPB_FREQ=${APB_FREQ} ) 16 | endif(${APB_FREQ}) 17 | 18 | if(NOT ${BUILD_UT}) 19 | add_executable(jtag_test jtag_test.c 20 | ${ASD_DIR}/server/logging.c 21 | ${ASD_DIR}/target/jtag_handler.c) 22 | target_link_libraries(jtag_test -lm ${SAFEC_LIBRARIES}) 23 | install (TARGETS jtag_test DESTINATION bin) 24 | endif(NOT ${BUILD_UT}) 25 | 26 | if(${BUILD_UT}) 27 | add_subdirectory(tests) 28 | endif(${BUILD_UT}) 29 | -------------------------------------------------------------------------------- /jtag_test/jtag_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _JTAG_TEST_H_ 29 | #define _JTAG_TEST_H_ 30 | 31 | #include 32 | #include 33 | #include "jtag_handler.h" 34 | #include "logging.h" 35 | 36 | #define MAX_TAPS_SUPPORTED 16 37 | #define MAX_TDO_SIZE 2048 38 | #define DEFAULT_TAP_DATA_PATTERN 0xdeadbeefbad4f00d // for tap comparison 39 | #define SIZEOF_TAP_DATA_PATTERN 8 40 | #define IR08_SHIFT_SIZE 8 // 8 bits per uncore 41 | #define DEFAULT_IR_SHIFT_SIZE 11 // 11 bits per uncore 42 | #define IR12_SHIFT_SIZE 12 // 12 bits per uncore 43 | #define IR14_SHIFT_SIZE 14 // 14 bits per uncore 44 | #define IR16_SHIFT_SIZE 16 // 16 bits per uncore 45 | #define MAX_IR_SHIFT_SIZE 0x400 46 | #define DEFAULT_NUMBER_TEST_ITERATIONS 40000 47 | #define DEFAULT_IR_VALUE 2 48 | #define DEFAULT_DR_SHIFT_SIZE 32 49 | #define MAX_DR_SHIFT_SIZE 0x20000 50 | #define DEFAULT_TO_MANUAL_MODE false 51 | #define DEFAULT_JTAG_CONTROLLER_MODE SW_MODE 52 | #define DEFAULT_JTAG_TCK 1 53 | #define SIZEOF_ID_CODE 4 54 | #define UNCORE_DISCOVERY_SHIFT_SIZE_IN_BITS \ 55 | (((MAX_TAPS_SUPPORTED * SIZEOF_ID_CODE) + SIZEOF_TAP_DATA_PATTERN) * 8) 56 | #define DEFAULT_LOG_LEVEL ASD_LogLevel_Info 57 | #define DEFAULT_LOG_STREAMS ASD_LogStream_Test 58 | 59 | #define IR_SIG_MASK 0x0FFFFFFF 60 | 61 | typedef struct jtag_test_args 62 | { 63 | unsigned long long int human_readable; 64 | unsigned int ir_shift_size; 65 | bool loop_forever; 66 | int numIterations; 67 | unsigned int ir_value; 68 | unsigned int dr_shift_size; 69 | bool manual_mode; 70 | bool count_mode; 71 | bool random_mode; 72 | int mode; 73 | unsigned int tck; 74 | unsigned char tap_data_pattern[8]; // Used for tap data comparison 75 | ASD_LogLevel log_level; 76 | ASD_LogStream log_streams; 77 | } jtag_test_args; 78 | 79 | typedef struct uncore_info 80 | { 81 | unsigned int idcode[MAX_TAPS_SUPPORTED]; 82 | unsigned int numUncores; 83 | } uncore_info; 84 | 85 | typedef struct ir_shift_size_map 86 | { 87 | unsigned int signature; 88 | unsigned int ir_shift_size; 89 | } ir_shift_size_map; 90 | 91 | extern bool continue_loop; 92 | 93 | #ifndef UNIT_TEST_MAIN 94 | int main(int argc, char** argv); 95 | #endif 96 | 97 | void load_ir_size_map_str(); 98 | 99 | int jtag_test_main(int argc, char** argv); 100 | 101 | void interrupt_handler(int dummy); 102 | 103 | void shift_right(unsigned char* buffer, size_t buffer_size); 104 | 105 | void shift_left(unsigned char* buffer, size_t buffer_size); 106 | 107 | bool parse_arguments(int argc, char** argv, jtag_test_args* args); 108 | 109 | void showUsage(char** argv); 110 | 111 | JTAG_Handler* init_jtag(jtag_test_args* args); 112 | 113 | unsigned int find_pattern(const unsigned char* haystack, 114 | unsigned int haystack_size, 115 | const unsigned char* needle, 116 | unsigned int needle_size); 117 | 118 | bool reset_jtag_to_RTI(JTAG_Handler* jtag); 119 | 120 | bool uncore_discovery(JTAG_Handler* jtag, uncore_info* uncore, 121 | jtag_test_args* args); 122 | 123 | bool jtag_test(JTAG_Handler* jtag, uncore_info* uncore, jtag_test_args* args); 124 | 125 | void print_test_results(uint64_t iterations, uint64_t micro_seconds, 126 | uint64_t total_bits, uint64_t failures); 127 | 128 | #endif // _JTAG_TEST_H_ 129 | -------------------------------------------------------------------------------- /jtag_test/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(at-scale-debug-jtag-test-tests C) 2 | 3 | # 4 | # CMake options 5 | cmake_minimum_required(VERSION 3.0) 6 | include(FindPkgConfig) 7 | # 8 | # import cmocka 9 | find_package(cmocka 1.1.0 REQUIRED) 10 | pkg_check_modules(CMOCKA REQUIRED cmocka) 11 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmocka) 12 | 13 | pkg_check_modules (SAFEC REQUIRED libsafec) 14 | include_directories (${SAFEC_INCLUDE_DIRS}) 15 | link_directories (${SAFEC_LIBRARY_DIRS}) 16 | 17 | # 18 | # Enable Cmake Tests 19 | enable_testing() 20 | 21 | # 22 | # Include code coverage 23 | set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 24 | include(CodeCoverage) 25 | 26 | # 27 | # Set options required for code coverage 28 | set(CMAKE_C_FLAGS 29 | "${CMAKE_C_FLAGS} -g -O0 --coverage -fprofile-arcs -ftest-coverage") 30 | set(CMAKE_EXE_LINKER "${CMAKE_EXE_LINKER}") 31 | set(CMAKE_SHARED_LINKER "${CMAKE_SHARED_LINKER}") 32 | 33 | # 34 | # Treat warnings as errors 35 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") 36 | 37 | # 38 | # Include local header files in project 39 | include_directories(".") 40 | 41 | # 42 | # For Unit Test specific code 43 | add_definitions(-DUNIT_TEST_MAIN) 44 | 45 | # 46 | # jtag_test tests 47 | add_executable(jtag_test_tests 48 | "jtag_test_tests.c" 49 | ../jtag_test.c) 50 | set_property(TARGET jtag_test_tests PROPERTY C_STANDARD 99) 51 | target_link_libraries( 52 | jtag_test_tests ${CMOCKA_LIBRARIES} pthread -fprofile-arcs -ftest-coverage -lm ${SAFEC_LIBRARIES}) 53 | add_test(jtag_test_tests jtag_test_tests) 54 | set_target_properties( 55 | jtag_test_tests 56 | PROPERTIES 57 | LINK_FLAGS 58 | " -Wl,--wrap=ASD_log -Wl,--wrap=ASD_log_buffer -Wl,--wrap=ASD_log_shift \ 59 | -Wl,--wrap=strtolevel -Wl,--wrap=strtostreams -Wl,--wrap=JTAGHandler \ 60 | -Wl,--wrap=JTAG_initialize -Wl,--wrap=JTAG_deinitialize -Wl,--wrap=JTAG_set_tap_state \ 61 | -Wl,--wrap=JTAG_shift -Wl,--wrap=JTAG_set_jtag_tck \ 62 | -Wl,--wrap=_memcpy_s_chk \ 63 | -Wl,--wrap=ASD_initialize_log_settings" 64 | ) 65 | 66 | # 67 | # Coverage settings 68 | set(COVERAGE_EXCLUDES '*/tests/*') 69 | 70 | setup_target_for_coverage(NAME test_coverage EXECUTABLE ctest) 71 | -------------------------------------------------------------------------------- /server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR) 2 | project(at-scale-debug C) 3 | 4 | find_package (PkgConfig REQUIRED) 5 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sysroot/include) 6 | pkg_check_modules (SAFEC REQUIRED libsafec) 7 | # Define HAVE_C99 to include sprintf_s macro in safec library 8 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_C99") 9 | include_directories (${SAFEC_INCLUDE_DIRS}) 10 | include_directories (${ASD_DIR}/include) 11 | link_directories (${SAFEC_LIBRARY_DIRS}) 12 | link_directories (${ASD_DIR}/target) 13 | 14 | if(NOT ${BUILD_UT}) 15 | add_executable(asd asd_main.c ext_network.c authenticate.c 16 | session.c config.c ext_tcp.c auth_none.c ext_tls.c 17 | auth_pam.c asd_target_interface.c asd_server_api.c 18 | logging.c) 19 | target_link_libraries(asd -lsystemd -lssl -lcrypto -lpam 20 | asd_target ${SAFEC_LIBRARIES}) 21 | install (TARGETS asd DESTINATION bin) 22 | 23 | # Copy pam-asd to etc/pam.d 24 | install ( 25 | FILES ${CMAKE_CURRENT_SOURCE_DIR}/pam-asd 26 | DESTINATION /etc/pam.d/ 27 | RENAME asd 28 | ) 29 | endif(NOT ${BUILD_UT}) 30 | -------------------------------------------------------------------------------- /server/asd_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _ASD_MAIN_H_ 29 | #define _ASD_MAIN_H_ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "asd_common.h" 36 | #include "config.h" 37 | #include "authenticate.h" 38 | #include "ext_network.h" 39 | #include "logging.h" 40 | #include "session.h" 41 | #include "sys/time.h" 42 | 43 | // DEFAULTS 44 | #define DEFAULT_I2C_ENABLE false 45 | #define DEFAULT_I3C_ENABLE false 46 | #define DEFAULT_SPP_ENABLE false 47 | #define DEFAULT_I2C_BUS 0x04 48 | #define DEFAULT_PORT 5123 49 | #define DEFAULT_CERT_FILE "/etc/ssl/certs/https/server.pem" 50 | #define DEFAULT_LOG_TO_SYSLOG false 51 | #define DEFAULT_LOG_LEVEL ASD_LogLevel_Warning 52 | #define DEFAULT_LOG_STREAMS ASD_LogStream_All 53 | #define DEFAULT_XDP_FAIL_ENABLE true 54 | #define IDLE_TIMEOUT_ENABLED false 55 | #define IDLE_TIMEOUT_MS 600000 56 | #define MINUTESTOMS 60000 //1000*60 57 | #define HOURSTOMS 3600000 //1000*60*60 58 | #define MSTOSEC 1000 59 | 60 | typedef struct session_options 61 | { 62 | uint16_t n_port_number; 63 | char* cp_certkeyfile; 64 | char* cp_net_bind_device; 65 | extnet_hdlr_type_t e_extnet_type; 66 | auth_hdlr_type_t e_auth_type; 67 | } session_options; 68 | 69 | typedef struct asd_args 70 | { 71 | session_options session; 72 | bus_options busopt; 73 | bool use_syslog; 74 | ASD_LogLevel log_level; 75 | ASD_LogStream log_streams; 76 | bool log_timestamp_enable; 77 | bool xdp_fail_enable; 78 | timeout_config timeout; 79 | } asd_args; 80 | 81 | typedef struct asd_state 82 | { 83 | asd_args args; 84 | int host_fd; 85 | int event_fd; 86 | config config; 87 | Session* session; 88 | ExtNet* extnet; 89 | } asd_state; 90 | 91 | #define MAX_INPUT_SIZE 100 92 | #define HOST_FD_INDEX 0 93 | #define GPIO_FD_INDEX 1 94 | #define NUM_I3C_DEBUG_FDS 1 95 | #define MAX_FDS (GPIO_FD_INDEX + MAX_SESSIONS + NUM_GPIOS + NUM_DBUS_FDS + NUM_I3C_DEBUG_FDS) 96 | 97 | typedef enum 98 | { 99 | CLOSE_CLIENT_EVENT = 1 100 | } InternalEventTypes; 101 | 102 | #ifndef UNIT_TEST_MAIN 103 | int main(int argc, char** argv); 104 | #endif 105 | 106 | int asd_main(int argc, char** argv); 107 | 108 | bool process_command_line(int argc, char** argv, asd_args* args); 109 | void showUsage(char** argv); 110 | STATUS init_asd_state(void); 111 | STATUS send_out_msg_on_socket(unsigned char* buffer, 112 | size_t length); 113 | void deinit_asd_state(asd_state* state); 114 | STATUS on_client_disconnect(asd_state* state); 115 | STATUS on_client_connect(asd_state* state, extnet_conn_t* p_extcon); 116 | void on_connection_aborted(void); 117 | void send_warning_message(long idle_timeout_ms, long warning_time_ms); 118 | bool check_idle_timeout(struct timeval* last_activity_time, 119 | bool* send_idle_warning_message, 120 | long idle_timeout_ms, long warning_time_ms); 121 | STATUS request_processing_loop(asd_state* state); 122 | STATUS process_new_client(asd_state* state, struct pollfd* poll_fds, 123 | size_t num_fds, int* num_clients, int client_index); 124 | STATUS process_all_client_messages(asd_state* state, 125 | const struct pollfd* poll_fds, 126 | size_t num_fds); 127 | STATUS process_all_gpio_events(asd_state* state, const struct pollfd* poll_fds, 128 | size_t num_fds); 129 | STATUS process_client_message(asd_state* state, struct pollfd poll_fd); 130 | STATUS ensure_client_authenticated(asd_state* state, extnet_conn_t* p_extconn); 131 | 132 | size_t read_data(void* buffer, size_t length); 133 | bool is_data_pending(void); 134 | 135 | STATUS close_connection(asd_state* state); 136 | void log_client_address(const extnet_conn_t* p_extcon); 137 | 138 | #endif // _ASD_MAIN_H_ -------------------------------------------------------------------------------- /server/asd_server_api.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "asd_common.h" 29 | #include "asd_server_api.h" 30 | #include "asd_main.h" 31 | #include 32 | 33 | static STATUS asd_server_version(char* version) 34 | { 35 | STATUS status = ST_ERR; 36 | if (version != NULL) { 37 | if (sprintf_s(version, MAX_SERVER_VERSION_SIZE, "%d.%d.%d", 38 | ASD_SERVER_API_VERSION_MAJOR, 39 | ASD_SERVER_API_VERSION_MINOR, 40 | ASD_SERVER_API_VERSION_PATCH) > 0) { 41 | status = ST_OK; 42 | } 43 | } 44 | return status; 45 | } 46 | 47 | size_t asd_server_read(unsigned char* buffer, size_t length, void* opt) 48 | { 49 | return read_data(buffer, length); 50 | } 51 | 52 | size_t asd_server_write(void* buffer, size_t length, void* opt) 53 | { 54 | if(send_out_msg_on_socket(buffer, length) == ST_OK) 55 | return length; 56 | 57 | return 0; 58 | } 59 | 60 | STATUS asd_server_ioctl(void* input, void* output, unsigned int cmd) 61 | { 62 | STATUS status = ST_ERR; 63 | switch(cmd) 64 | { 65 | case IOCTL_SERVER_GET_API_VERSION: 66 | if (output == NULL) 67 | break; 68 | char * server_api_version = (char *) output; 69 | status = asd_server_version(server_api_version); 70 | break; 71 | case IOCTL_SERVER_IS_DATA_PENDING: 72 | if (output == NULL) 73 | break; 74 | bool * data_pending = (bool *) output; 75 | *data_pending = is_data_pending(); 76 | status = ST_OK; 77 | break; 78 | } 79 | return status; 80 | } 81 | 82 | void asd_server_log(ASD_LogLevel level, ASD_LogStream stream, 83 | ASD_LogOption options, const char* string) 84 | { 85 | ASD_log(level, stream, options, string); 86 | } 87 | 88 | void asd_server_log_buffer(ASD_LogLevel level, ASD_LogStream stream, 89 | ASD_LogOption options, const unsigned char* ptr, 90 | size_t len, const char* prefixPtr) 91 | { 92 | ASD_log_buffer(level, stream, options, ptr, len, prefixPtr); 93 | } 94 | 95 | void asd_server_log_shift(ASD_LogLevel level, ASD_LogStream stream, 96 | ASD_LogOption options, unsigned int number_of_bits, 97 | unsigned int size_bytes, unsigned char* buffer, 98 | const char* prefixPtr) 99 | { 100 | ASD_log_shift(level, stream, options, number_of_bits, size_bytes, buffer, 101 | prefixPtr); 102 | } -------------------------------------------------------------------------------- /server/asd_target_interface.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "asd_target_interface.h" 29 | #include "asd_target_api.h" 30 | #include 31 | 32 | static STATUS asd_target_interface_version(char* version) 33 | { 34 | STATUS status = ST_ERR; 35 | if (version != NULL) { 36 | if (sprintf_s(version, MAX_TARGET_INTERFACE_VERSION_SIZE, "%d.%d.%d", 37 | ASD_TARGET_INTERFACE_API_VERSION_MAJOR, 38 | ASD_TARGET_INTERFACE_API_VERSION_MINOR, 39 | ASD_TARGET_INTERFACE_API_VERSION_PATCH) > 0) { 40 | status = ST_OK; 41 | } 42 | } 43 | return status; 44 | } 45 | 46 | static bool asd_is_api_target_version_supported(char* version) 47 | { 48 | bool supported = false; 49 | int cmp = -1; 50 | char target_api_version[MAX_TARGET_INTERFACE_VERSION_SIZE]; 51 | STATUS status = ST_ERR; 52 | 53 | if (version != NULL) { 54 | status = asd_target_ioctl(NULL, target_api_version, IOCTL_TARGET_GET_API_VERSION); 55 | } 56 | if (status == ST_OK) { 57 | strcmp_s(version, MAX_TARGET_INTERFACE_VERSION_SIZE, 58 | target_api_version, &cmp); 59 | if (cmp == 0) { 60 | supported = true; 61 | } else { 62 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK, 63 | ASD_LogOption_None, 64 | "Incompatible ASD Target API versions"); 65 | } 66 | ASD_log(ASD_LogLevel_Info, ASD_LogStream_SDK, ASD_LogOption_None, 67 | "target_interface_version = %s, target_api_version = %s", 68 | version, target_api_version); 69 | } 70 | return supported; 71 | } 72 | 73 | STATUS asd_api_target_init(config* asd_cfg) 74 | { 75 | // Check API version compatibility 76 | char target_interface_version[MAX_TARGET_INTERFACE_VERSION_SIZE]; 77 | STATUS status = asd_target_interface_version(target_interface_version); 78 | if(status == ST_OK) { 79 | if(asd_is_api_target_version_supported(target_interface_version)) { 80 | status = asd_target_init(asd_cfg); 81 | } else { 82 | status = ST_ERR; 83 | } 84 | } 85 | return status; 86 | } 87 | 88 | STATUS asd_api_target_deinit(void) 89 | { 90 | return asd_target_deinit(); 91 | } 92 | 93 | size_t asd_api_target_read(unsigned char* buffer, size_t length, void* opt) 94 | { 95 | return asd_target_read(buffer, length, opt); 96 | } 97 | 98 | size_t asd_api_target_write(unsigned char* buffer, size_t length, void* opt) 99 | { 100 | return asd_target_write(buffer, length, opt); 101 | } 102 | 103 | STATUS asd_api_target_ioctl(void* input, void* output, unsigned int cmd) 104 | { 105 | STATUS status = ST_ERR; 106 | char * target_interface_version = NULL; 107 | switch(cmd) 108 | { 109 | case IOCTL_TARGET_GET_INTERFACE_VERSION: 110 | if (output == NULL) 111 | break; 112 | target_interface_version = (char *) output; 113 | status = asd_target_interface_version(target_interface_version); 114 | break; 115 | case IOCTL_TARGET_IS_INTERFACE_SUPPORTED: 116 | if (input == NULL || output == NULL) 117 | break; 118 | target_interface_version = (char *) input; 119 | bool * supported = (bool *) output; 120 | *supported = asd_is_api_target_version_supported(target_interface_version); 121 | status = ST_OK; 122 | break; 123 | default: 124 | status = asd_target_ioctl(input, output, cmd); 125 | } 126 | return status; 127 | } 128 | 129 | void asd_api_target_log(ASD_LogLevel level, ASD_LogStream stream, 130 | ASD_LogOption options, const char* format, ...) 131 | { 132 | char string[MAX_LOG_SIZE]; 133 | va_list args; 134 | va_start(args, format); 135 | vsprintf_s(string, sizeof(string), format, args); 136 | asd_target_log(level, stream, options, string); 137 | va_end( args ); 138 | } 139 | 140 | void asd_api_target_log_buffer(ASD_LogLevel level, ASD_LogStream stream, 141 | ASD_LogOption options, const unsigned char* ptr, 142 | size_t len, const char* prefixPtr) 143 | { 144 | asd_target_log_buffer(level, stream, options, ptr, len, prefixPtr); 145 | } 146 | 147 | void asd_api_target_log_shift(ASD_LogLevel level, ASD_LogStream stream, 148 | ASD_LogOption options, unsigned int number_of_bits, 149 | unsigned int size_bytes, unsigned char* buffer, 150 | const char* prefixPtr) 151 | { 152 | asd_target_log_shift(level, stream, options, number_of_bits, size_bytes, 153 | buffer, prefixPtr); 154 | } 155 | 156 | -------------------------------------------------------------------------------- /server/auth_none.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /** 29 | * @file auth_none.c 30 | * @brief Handler functions to support no authentication 31 | */ 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "authenticate.h" 40 | #include "ext_network.h" 41 | 42 | STATUS authnone_init(void* p_hdlr_data); 43 | STATUS auth_none(Session* session, ExtNet* net_state, extnet_conn_t* p_extconn); 44 | 45 | auth_hdlrs_t authnone_hdlrs = {authnone_init, auth_none}; 46 | 47 | /** @brief Initialize authentication handler 48 | * @param [in] p_hdlr_data Pointer to handler specific data (not used) 49 | */ 50 | STATUS authnone_init(void* p_hdlr_data) 51 | { 52 | (void)p_hdlr_data; 53 | return ST_OK; 54 | } 55 | 56 | /** @brief Read and validate client header and password. 57 | * 58 | * Called when client has not been authenticated each time data is available 59 | * on the external socket. 60 | * 61 | * @param [in] p_extconn pointer 62 | * @return ST_OK if successful, otherwise ST_ERR. 63 | */ 64 | STATUS auth_none(Session* session, ExtNet* net_state, extnet_conn_t* p_extconn) 65 | { 66 | (void)session; 67 | (void)net_state; 68 | (void)p_extconn; 69 | return ST_OK; 70 | } 71 | -------------------------------------------------------------------------------- /server/auth_none.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /** 29 | * @file auth_none.h 30 | * @brief Handler definitions to support no authentication 31 | */ 32 | 33 | #ifndef __AUTH_NONE_H_ 34 | #define __AUTH_NONE_H_ 35 | 36 | #include "authenticate.h" 37 | 38 | extern auth_hdlrs_t authnone_hdlrs; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /server/auth_pam.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /** 29 | * @file auth_pam.h 30 | * @brief Functions and definitions to authenticate client credentials with PAM. 31 | */ 32 | 33 | #ifndef __AUTH_PAM_H_ 34 | #define __AUTH_PAM_H_ 35 | 36 | #include 37 | 38 | #include "authenticate.h" 39 | 40 | extern auth_hdlrs_t authpam_hdlrs; 41 | 42 | /** Auth Header version. */ 43 | #define AUTH_HDR_VERSION \ 44 | 0x30 /* Set to 30 to allow testing with ascii \ 45 | * tools. \ 46 | */ 47 | 48 | #define MAX_PW_LEN 128 49 | 50 | /** PAM service (/etc/pam.d/service) establishing rules for auth */ 51 | #define ASD_PAM_SERVICE "asd" 52 | 53 | /** User used for authentication. Only this user may authenticate */ 54 | #define ASD_PAM_USER "asdbg" 55 | 56 | /** Number of invalid auth attempts permitted before lockout */ 57 | #define INVALID_AUTH_MAX_ATTEMPTS 3 58 | 59 | /** Period of time for which invalid auth attempts are measured */ 60 | #define INVALID_AUTH_PERIOD_NSECS 60 61 | 62 | /** Amount of time auth attempts are locked out when threshold is exceeded */ 63 | #define INVALID_AUTH_LOCKOUT_NSECS 60 64 | 65 | /* Characters for the random string generator to use */ 66 | #define RANDOM_ASCII_CHARACTERS \ 67 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-!#$%()+" \ 68 | "=*" 69 | 70 | /** Header/Handshake responses */ 71 | typedef enum 72 | { 73 | AUTH_HANDSHAKE_SUCCESS = 0x30, 74 | AUTH_HANDSHAKE_SYSERR = 0x24, // system error. 75 | AUTH_HANDSHAKE_BUSY = 0x2b, // session already in progress 76 | AUTH_HANDSHAKE_FAILURE = 0x3f, 77 | } __attribute__((packed)) auth_handshake_ret_t; 78 | 79 | /** Structure passed from client to provide credentials for auth */ 80 | typedef struct 81 | { 82 | /** Header version */ 83 | unsigned char auth_hdr_version; 84 | 85 | /** Auth password*/ 86 | unsigned char auth_password[MAX_PW_LEN]; 87 | } __attribute__((packed)) auth_handshake_req_t; 88 | 89 | /** Structure returned to client with auth result */ 90 | typedef struct 91 | { 92 | /** Header version */ 93 | unsigned char svr_hdr_version; 94 | auth_handshake_ret_t result_code; 95 | } __attribute__((packed)) auth_handshake_resp_t; 96 | 97 | #ifdef UNIT_TESTING_ONLY 98 | // expose callback for testing 99 | int pam_conversation_function(int numMsg, const struct pam_message** msg, 100 | struct pam_response** resp, void* appdata_ptr); 101 | #endif 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /server/authenticate.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /** 29 | * @file authenticate.c 30 | * @brief Functions supporting authentication of credentials from client, 31 | * tracking authentication attempts and locking out authentication when a 32 | * threshold is exceeded. 33 | */ 34 | #include "authenticate.h" 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "asd_common.h" 45 | #include "auth_none.h" 46 | #include "auth_pam.h" 47 | #include "ext_network.h" 48 | #include "logging.h" 49 | #include "session.h" 50 | 51 | static struct 52 | { 53 | auth_hdlrs_t* p_hdlrs; 54 | } sg_data = {0}; 55 | 56 | /** @brief Initialize authentication handler 57 | * @param [in] e_type Handler type to use for authentication. 58 | * @param [in] p_hdlr_data Pointer to handler specific data (not used) 59 | */ 60 | STATUS auth_init(auth_hdlr_type_t e_type, void* p_hdlr_data) 61 | { 62 | STATUS st_ret = ST_OK; 63 | 64 | switch (e_type) 65 | { 66 | case AUTH_HDLR_NONE: 67 | sg_data.p_hdlrs = &authnone_hdlrs; 68 | break; 69 | case AUTH_HDLR_PAM: 70 | sg_data.p_hdlrs = &authpam_hdlrs; 71 | break; 72 | default: 73 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_Network, 74 | ASD_LogOption_None, "Invalid authentication handler %d!", 75 | e_type); 76 | st_ret = ST_ERR; 77 | break; 78 | } 79 | 80 | if (!sg_data.p_hdlrs || !sg_data.p_hdlrs->init) 81 | st_ret = ST_ERR; 82 | 83 | if (st_ret == ST_OK) 84 | { 85 | st_ret = sg_data.p_hdlrs->init(p_hdlr_data); 86 | } 87 | return st_ret; 88 | } 89 | 90 | /** @brief Read and validate client header and password. 91 | * 92 | * Called when client has not been authenticated each time data is available 93 | * on the external socket. 94 | * 95 | * @param [in] p_extconn pointer 96 | * @return AUTHRET_OK if successful, otherwise another auth_ret_t value. 97 | */ 98 | STATUS auth_client_handshake(Session* session, ExtNet* net_state, 99 | extnet_conn_t* p_extconn) 100 | { 101 | STATUS st_ret = ST_ERR; 102 | 103 | if (!sg_data.p_hdlrs || !sg_data.p_hdlrs->client_handshake) 104 | { 105 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_Network, ASD_LogOption_None, 106 | "%s Not initialized!", __FUNCTION__); 107 | } 108 | else 109 | { 110 | st_ret = 111 | sg_data.p_hdlrs->client_handshake(session, net_state, p_extconn); 112 | } 113 | return st_ret; 114 | } 115 | -------------------------------------------------------------------------------- /server/authenticate.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /** 29 | * @file authenticate.h 30 | * @brief Functions and definitions to authenticate client credentials. 31 | */ 32 | 33 | #ifndef __AUTHENTICATION_H_ 34 | #define __AUTHENTICATION_H_ 35 | 36 | #include "ext_network.h" 37 | #include "session.h" 38 | 39 | typedef enum 40 | { 41 | AUTH_HDLR_NONE, 42 | AUTH_HDLR_PAM 43 | } auth_hdlr_type_t; 44 | 45 | // Function pointers for external network interface. 46 | typedef struct 47 | { 48 | STATUS (*init)(void* p_hdlr_data); 49 | STATUS(*client_handshake) 50 | (Session* session, ExtNet* state, extnet_conn_t* pconn); 51 | } auth_hdlrs_t; 52 | 53 | STATUS auth_init(auth_hdlr_type_t e_type, void* p_hdlr_data); 54 | STATUS auth_client_handshake(Session* session, ExtNet* state, 55 | extnet_conn_t* p_extconn); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /server/config.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "config.h" 29 | 30 | #include 31 | #include 32 | 33 | #include "logging.h" 34 | 35 | STATUS set_config_defaults(config* config, const bus_options* opt, const timeout_config* tmo_cfg) 36 | { 37 | if (config == NULL || opt == NULL || tmo_cfg== NULL) 38 | { 39 | return ST_ERR; 40 | } 41 | config->jtag.mode = JTAG_DRIVER_MODE_SOFTWARE; 42 | config->jtag.chain_mode = JTAG_CHAIN_SELECT_MODE_SINGLE; 43 | config->remote_logging.logging_level = IPC_LogType_Off; 44 | config->remote_logging.logging_stream = 0; 45 | config->buscfg.enable_i2c = opt->enable_i2c; 46 | config->buscfg.enable_i3c = opt->enable_i3c; 47 | config->buscfg.enable_spp = opt->enable_spp; 48 | config->buscfg.default_bus = opt->bus; 49 | config->timecfg.is_timeout_enabled=tmo_cfg->is_timeout_enabled; 50 | config->timecfg.idle_timeout=tmo_cfg->idle_timeout; 51 | for (int i = 0; i < MAX_IxC_BUSES + MAX_SPP_BUSES; i++) 52 | { 53 | if (opt->enable_i2c || opt->enable_i3c || opt->enable_spp) 54 | { 55 | config->buscfg.bus_config_type[i] = opt->bus_config_type[i]; 56 | config->buscfg.bus_config_map[i] = opt->bus_config_map[i]; 57 | } 58 | else 59 | { 60 | config->buscfg.bus_config_type[i] = BUS_CONFIG_NOT_ALLOWED; 61 | config->buscfg.bus_config_map[i] = 0; 62 | } 63 | } 64 | 65 | return ST_OK; 66 | } -------------------------------------------------------------------------------- /server/ext_network.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /** @file ext_network.h 29 | * This file contains the external network interface between the Probe Plugin 30 | * and JTAG 31 | */ 32 | 33 | #ifndef __EXT_NETWORK_H_ 34 | #define __EXT_NETWORK_H_ 35 | 36 | #include 37 | #include 38 | 39 | #include "asd_common.h" 40 | 41 | #define UNUSED_SOCKET_FD (-1) 42 | 43 | // External network connection data structure. 44 | typedef struct 45 | { 46 | int sockfd; // File descriptor of socket 47 | void* p_hdlr_data; // handler private data pointer 48 | } extnet_conn_t; 49 | 50 | typedef enum 51 | { 52 | EXTNET_HDLR_NON_ENCRYPT, 53 | EXTNET_HDLR_TLS 54 | } extnet_hdlr_type_t; 55 | 56 | // Function pointers for external network interface. 57 | typedef struct 58 | { 59 | STATUS (*init)(void* p_hdlr_data); 60 | STATUS (*on_accept)(void* net_state, extnet_conn_t* pconn); 61 | STATUS (*on_close_client)(extnet_conn_t* pconn); 62 | STATUS (*init_client)(extnet_conn_t* pconn); 63 | int (*recv)(extnet_conn_t* pconn, void* pv_buf, size_t sz_len, 64 | bool* b_data_pending); 65 | int (*send)(extnet_conn_t* pconn, void* pv_buf, size_t sz_len); 66 | void (*cleanup)(void); 67 | } extnet_hdlrs_t; 68 | 69 | typedef struct ExtNet 70 | { 71 | extnet_hdlrs_t* p_hdlrs; 72 | int n_max_sessions; 73 | } ExtNet; 74 | 75 | ExtNet* extnet_init(extnet_hdlr_type_t eType, void* p_hdlr_data, 76 | int n_max_sessions); 77 | STATUS extnet_open_external_socket(ExtNet* state, const char* cp_bind_if, 78 | uint16_t u16_port, int* pfd_sock); 79 | STATUS extnet_accept_connection(ExtNet* state, int ext_listen_sockfd, 80 | extnet_conn_t* pconn); 81 | STATUS extnet_close_client(ExtNet* state, extnet_conn_t* pconn); 82 | STATUS extnet_init_client(ExtNet* state, extnet_conn_t* pconn); 83 | bool extnet_is_client_closed(ExtNet* state, extnet_conn_t* pconn); 84 | int extnet_recv(ExtNet* state, extnet_conn_t* pconn, void* pv_buf, 85 | size_t sz_len, bool* b_data_pending); 86 | int extnet_send(ExtNet* state, extnet_conn_t* pconn, void* pv_buf, 87 | size_t sz_len); 88 | 89 | #endif // __EXT_NETWORK_H_ 90 | -------------------------------------------------------------------------------- /server/ext_tcp.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /** @file ext_tcp.c 29 | * This file contains the external network interface using vanilla TCP with no 30 | * encryption. 31 | */ 32 | 33 | #include "ext_tcp.h" 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "asd_common.h" 40 | #include "logging.h" 41 | 42 | extnet_hdlrs_t tcp_hdlrs = { 43 | exttcp_init, exttcp_on_accept, exttcp_on_close_client, exttcp_init_client, 44 | exttcp_recv, exttcp_send, exttcp_cleanup, 45 | }; 46 | 47 | /** @brief Initialize TCP 48 | * 49 | * Called to initialize External Network Interface 50 | */ 51 | STATUS exttcp_init(void* p_hdlr_data) 52 | { 53 | (void)p_hdlr_data; 54 | return ST_OK; 55 | } 56 | 57 | /** @brief Cleans up TCP context and connections. 58 | * 59 | * Called to cleanup connection. 60 | */ 61 | void exttcp_cleanup(void) 62 | { 63 | } 64 | 65 | /** @brief Accepts the socket connection and handles client key 66 | * 67 | * Called each time a new connection is accepted on the listening socket. 68 | * 69 | * @param [in] ext_listen_sockfd File descriptor for listening socket. 70 | * @param [in,out] pconn Pointer to the connection structure. 71 | * @return ST_OK if successful. 72 | */ 73 | STATUS exttcp_on_accept(void* net_state, extnet_conn_t* pconn) 74 | { 75 | (void)net_state; 76 | (void)pconn; 77 | return ST_OK; 78 | } 79 | 80 | /** @brief Initialize client connection 81 | * 82 | * Called to initialize external client connection 83 | * 84 | * @param [in,out] pconn Pointer to the connection pointer. 85 | * @return RET_OK if successful. 86 | */ 87 | STATUS exttcp_init_client(extnet_conn_t* pconn) 88 | { 89 | (void)pconn; 90 | return ST_OK; 91 | } 92 | 93 | /** @brief Close client connection and free pointer. 94 | * 95 | * Called to close external client connection 96 | * 97 | * @param [in,out] pconn Pointer to the connection pointer. 98 | * @return RET_OK if successful. 99 | */ 100 | STATUS exttcp_on_close_client(extnet_conn_t* pconn) 101 | { 102 | (void)pconn; 103 | return ST_OK; 104 | } 105 | 106 | /** @brief Read data from external network connection 107 | * 108 | * Called each time data is available on the external socket. 109 | * 110 | * @param [in] pconn Connetion pointer 111 | * @param [out] pv_buf Buffer where data will be stored. 112 | * @param [in] sz_len sizeof pv_buf 113 | * @return number of bytes received. 114 | */ 115 | int exttcp_recv(extnet_conn_t* pconn, void* pv_buf, size_t sz_len, 116 | bool* b_data_pending) 117 | { 118 | int n_read = -1; 119 | *b_data_pending = false; 120 | if (!pconn) 121 | { 122 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_Network, ASD_LogOption_None, 123 | "%s called with invalid connection pointer", __FUNCTION__); 124 | } 125 | else if (!pv_buf) 126 | { 127 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_Network, ASD_LogOption_None, 128 | "%s called with invalid buffer pointer", __FUNCTION__); 129 | } 130 | else if (pconn->sockfd < 0) 131 | { 132 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_Network, ASD_LogOption_None, 133 | "%s called with invalid file descriptor %d", __FUNCTION__, 134 | pconn->sockfd); 135 | } 136 | else 137 | { 138 | n_read = (int)recv(pconn->sockfd, pv_buf, sz_len, 0); 139 | } 140 | return n_read; 141 | } 142 | 143 | /** @brief Write data to external network connection 144 | * 145 | * Called each time data is available on the external socket. 146 | * 147 | * @param [in] pconn Connetion pointer 148 | * @param [out] pv_buf Buffer where data will be stored. 149 | * @param [in] sz_len sizeof pv_buf 150 | * @return number of bytes received. 151 | */ 152 | int exttcp_send(extnet_conn_t* pconn, void* pv_buf, size_t sz_len) 153 | { 154 | int n_wr = -1; 155 | 156 | if (!pconn) 157 | { 158 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_Network, ASD_LogOption_None, 159 | "%s called with invalid pointer", __FUNCTION__); 160 | } 161 | else if (!pv_buf) 162 | { 163 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_Network, ASD_LogOption_None, 164 | "%s called with invalid pointer", __FUNCTION__); 165 | } 166 | else if (pconn->sockfd < 0) 167 | { 168 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_Network, ASD_LogOption_None, 169 | "%s called with invalid file descriptor %d", __FUNCTION__, 170 | pconn->sockfd); 171 | } 172 | else 173 | { 174 | n_wr = (int)send(pconn->sockfd, pv_buf, sz_len, 0); 175 | } 176 | return n_wr; 177 | } 178 | -------------------------------------------------------------------------------- /server/ext_tcp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /** @file ext_tcp.h 29 | * Handlers for unencrypted TCP connections. 30 | */ 31 | 32 | #ifndef __EXT_TCP_H 33 | #define __EXT_TCP_H 34 | 35 | #include 36 | 37 | #include "asd_common.h" 38 | #include "ext_network.h" 39 | 40 | extern extnet_hdlrs_t tcp_hdlrs; 41 | 42 | extern STATUS exttcp_init(void* p_hdlr_data); 43 | extern void exttcp_cleanup(void); 44 | extern STATUS exttcp_on_accept(void* net_state, extnet_conn_t* pconn); 45 | extern STATUS exttcp_init_client(extnet_conn_t* pconn); 46 | extern STATUS exttcp_on_close_client(extnet_conn_t* pconn); 47 | extern int exttcp_recv(extnet_conn_t* pconn, void* pv_buf, size_t sz_len, 48 | bool* b_data_pending); 49 | extern int exttcp_send(extnet_conn_t* pconn, void* pv_buf, size_t sz_len); 50 | 51 | #endif //__EXT_TCP_H 52 | -------------------------------------------------------------------------------- /server/ext_tls.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /** @file ext_tls.h 29 | * Handlers to support external encrypted TLS connections. 30 | */ 31 | 32 | #ifndef __EXT_TLS_H 33 | #define __EXT_TLS_H 34 | 35 | #include "asd_common.h" 36 | #include "ext_network.h" 37 | 38 | extern extnet_hdlrs_t tls_hdlrs; 39 | 40 | extern STATUS exttls_init(void* p_hdlr_data); 41 | extern void exttls_cleanup(void); 42 | extern STATUS exttls_on_accept(void* net_state, extnet_conn_t* pconn); 43 | extern STATUS exttls_init_client(extnet_conn_t* pconn); 44 | extern STATUS exttls_on_close_client(extnet_conn_t* pconn); 45 | extern int exttls_recv(extnet_conn_t* pconn, void* pv_buf, size_t sz_len, 46 | bool* b_data_pending); 47 | extern int exttls_send(extnet_conn_t* pconn, void* pv_buf, size_t sz_len); 48 | 49 | #endif //__EXT_TLS_H 50 | -------------------------------------------------------------------------------- /server/pam-asd: -------------------------------------------------------------------------------- 1 | # 2 | # The PAM configuration file for asd 3 | # 4 | 5 | auth required pam_unix.so 6 | -------------------------------------------------------------------------------- /server/session.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /** 29 | * @file session.h 30 | * @brief Functions and definitions to track remote sessions 31 | */ 32 | 33 | #ifndef __SESSION_H 34 | #define __SESSION_H 35 | 36 | #include 37 | 38 | #include "asd_common.h" 39 | #include "ext_network.h" 40 | 41 | /** Max number of sessions */ 42 | #define MAX_SESSIONS 5 43 | #define SESSION_AUTH_EXPIRE_TIMEOUT 15 44 | #define NO_SESSION_AUTHENTICATED (-1) 45 | 46 | typedef int session_fdarr_t[MAX_SESSIONS]; 47 | 48 | /** Structure to track session info */ 49 | typedef struct 50 | { 51 | int id; 52 | extnet_conn_t extconn; // External Connection 53 | time_t t_auth_tout; // Time stamp when authentication attempt times out 54 | bool b_authenticated; // True if session is authenticated. 55 | bool b_data_pending; // Hint that more data is pending for the 56 | // connection. 57 | } session_t; 58 | 59 | /** Global data struct */ 60 | typedef struct Session 61 | { 62 | bool b_initialized; 63 | session_t sessions[MAX_SESSIONS]; 64 | int n_authenticated_id; // only one session may be authenticated. 65 | ExtNet* extnet; 66 | } Session; 67 | 68 | extern Session* session_init(ExtNet* extnet); 69 | extern extnet_conn_t* session_lookup_conn(Session* state, int fd); 70 | extern STATUS session_open(Session* state, extnet_conn_t* p_extconn); 71 | extern STATUS session_close(Session* state, extnet_conn_t* p_extconn); 72 | extern void session_close_all(Session* state); 73 | extern void session_close_expired_unauth(Session* state); 74 | extern STATUS session_already_authenticated(Session* state, 75 | extnet_conn_t* p_extconn); 76 | extern STATUS session_auth_complete(Session* state, extnet_conn_t* p_extconn); 77 | extern STATUS session_get_authenticated_conn(Session* state, 78 | extnet_conn_t* p_authd_conn); 79 | extern STATUS session_getfds(Session* state, session_fdarr_t* na_fds, 80 | int* pn_fds, int* pn_timeout); 81 | extern STATUS session_set_data_pending(Session* state, extnet_conn_t* p_extconn, 82 | bool b_data_pending); 83 | extern STATUS session_get_data_pending(Session* state, extnet_conn_t* p_extconn, 84 | bool* b_data_pending); 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /server/tests/auth_none_tests.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "../auth_none.h" 41 | #include "../authenticate.h" 42 | #include "cmocka.h" 43 | 44 | void authnone_init_returns_success_test(void** state) 45 | { 46 | (void)state; 47 | assert_int_equal(ST_OK, authnone_hdlrs.init(NULL)); 48 | } 49 | 50 | void auth_none_returns_success_test(void** state) 51 | { 52 | (void)state; 53 | assert_int_equal(ST_OK, authnone_hdlrs.client_handshake(NULL, NULL, NULL)); 54 | } 55 | 56 | int main() 57 | { 58 | const struct CMUnitTest tests[] = { 59 | cmocka_unit_test(authnone_init_returns_success_test), 60 | cmocka_unit_test(auth_none_returns_success_test), 61 | }; 62 | 63 | return cmocka_run_group_tests(tests, NULL, NULL); 64 | } 65 | -------------------------------------------------------------------------------- /server/tests/authenticate_tests.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "../authenticate.h" 41 | #include "../logging.h" 42 | #include "cmocka.h" 43 | 44 | bool fake_authnone_init_was_called = false; 45 | STATUS fake_authnone_init(void* p_hdlr_data) 46 | { 47 | (void)p_hdlr_data; 48 | fake_authnone_init_was_called = true; 49 | return ST_OK; 50 | } 51 | 52 | bool fake_auth_none_was_called = false; 53 | STATUS fake_auth_none(Session* session, ExtNet* state, extnet_conn_t* p_extconn) 54 | { 55 | (void)session; 56 | (void)state; 57 | (void)p_extconn; 58 | fake_auth_none_was_called = true; 59 | return ST_OK; 60 | } 61 | 62 | bool fake_authpam_init_was_called = false; 63 | STATUS fake_authpam_init(void* p_hdlr_data) 64 | { 65 | (void)p_hdlr_data; 66 | fake_authpam_init_was_called = true; 67 | return ST_OK; 68 | } 69 | 70 | bool fake_auth_pam_was_called = false; 71 | STATUS fake_auth_pam(Session* session, ExtNet* state, extnet_conn_t* p_extconn) 72 | { 73 | (void)session; 74 | (void)state; 75 | (void)p_extconn; 76 | fake_auth_pam_was_called = true; 77 | return ST_OK; 78 | } 79 | 80 | auth_hdlrs_t authnone_hdlrs = {fake_authnone_init, fake_auth_none}; 81 | auth_hdlrs_t authpam_hdlrs = {fake_authpam_init, fake_auth_pam}; 82 | 83 | // static char temporary_log_buffer[512]; 84 | void __wrap_ASD_log(ASD_LogLevel level, ASD_LogStream stream, 85 | ASD_LogOption options, const char* format, ...) 86 | { 87 | (void)level; 88 | (void)stream; 89 | (void)options; 90 | (void)format; 91 | // va_list args; 92 | // va_start(args, format); 93 | // vsnprintf(temporary_log_buffer, sizeof(temporary_log_buffer), format, 94 | // args); 95 | // fprintf(stderr, "%s\n", temporary_log_buffer); 96 | // va_end(args); 97 | } 98 | 99 | static int setup(void** state) 100 | { 101 | (void)state; 102 | authnone_hdlrs.init = fake_authnone_init; 103 | authnone_hdlrs.client_handshake = fake_auth_none; 104 | authpam_hdlrs.init = fake_authnone_init; 105 | authpam_hdlrs.client_handshake = fake_auth_none; 106 | fake_authnone_init_was_called = false; 107 | fake_auth_none_was_called = false; 108 | return 0; 109 | } 110 | 111 | static int teardown(void** state) 112 | { 113 | (void)state; 114 | return 0; 115 | } 116 | 117 | void auth_init_invalid_handler_type_returns_error_test(void** state) 118 | { 119 | (void)state; 120 | int invalid_handler = 948; 121 | assert_int_equal(ST_ERR, auth_init(invalid_handler, NULL)); 122 | } 123 | 124 | void auth_init_invalid_handler_init_returns_error_test(void** state) 125 | { 126 | (void)state; 127 | authnone_hdlrs.init = NULL; 128 | assert_int_equal(ST_ERR, auth_init(AUTH_HDLR_NONE, NULL)); 129 | } 130 | 131 | void auth_init_calls_init_successfully_test(void** state) 132 | { 133 | (void)state; 134 | assert_int_equal(ST_OK, auth_init(AUTH_HDLR_NONE, NULL)); 135 | assert_true(fake_authnone_init_was_called); 136 | 137 | fake_authnone_init_was_called = false; 138 | assert_int_equal(ST_OK, auth_init(AUTH_HDLR_PAM, NULL)); 139 | assert_true(fake_authnone_init_was_called); 140 | } 141 | 142 | void auth_client_handshake_invalid_handler_client_handshake_returns_error_test( 143 | void** state) 144 | { 145 | (void)state; 146 | authnone_hdlrs.client_handshake = NULL; 147 | authpam_hdlrs.client_handshake = NULL; 148 | assert_int_equal(ST_ERR, auth_client_handshake(NULL, NULL, NULL)); 149 | } 150 | 151 | void auth_client_handshake_calls_client_handshake_successfully_test( 152 | void** state) 153 | { 154 | (void)state; 155 | assert_int_equal(ST_OK, auth_client_handshake(NULL, NULL, AUTH_HDLR_NONE)); 156 | assert_true(fake_auth_none_was_called); 157 | } 158 | 159 | int main() 160 | { 161 | const struct CMUnitTest tests[] = { 162 | cmocka_unit_test_setup_teardown( 163 | auth_init_invalid_handler_type_returns_error_test, setup, teardown), 164 | cmocka_unit_test_setup_teardown( 165 | auth_init_invalid_handler_init_returns_error_test, setup, teardown), 166 | cmocka_unit_test_setup_teardown(auth_init_calls_init_successfully_test, 167 | setup, teardown), 168 | cmocka_unit_test_setup_teardown( 169 | auth_client_handshake_invalid_handler_client_handshake_returns_error_test, 170 | setup, teardown), 171 | cmocka_unit_test_setup_teardown( 172 | auth_client_handshake_calls_client_handshake_successfully_test, 173 | setup, teardown), 174 | }; 175 | 176 | return cmocka_run_group_tests(tests, NULL, NULL); 177 | } 178 | -------------------------------------------------------------------------------- /server/tests/config_tests.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "../config.h" 41 | #include "../logging.h" 42 | #include "cmocka.h" 43 | 44 | // static char temporary_log_buffer[512]; 45 | void __wrap_ASD_log(ASD_LogLevel level, ASD_LogStream stream, 46 | ASD_LogOption options, const char* format, ...) 47 | { 48 | (void)level; 49 | (void)stream; 50 | (void)options; 51 | (void)format; 52 | // va_list args; 53 | // va_start(args, format); 54 | // vsnprintf(temporary_log_buffer, sizeof(temporary_log_buffer), format, 55 | // args); 56 | // fprintf(stderr, "%s\n", temporary_log_buffer); 57 | // va_end(args); 58 | } 59 | 60 | void set_config_defaults_failed_test(void** state) 61 | { 62 | config config_obj; 63 | i2c_options i2c; 64 | assert_int_equal(set_config_defaults(NULL, NULL), ST_ERR); 65 | assert_int_equal(set_config_defaults(NULL, &i2c), ST_ERR); 66 | assert_int_equal(set_config_defaults(&config_obj, NULL), ST_ERR); 67 | } 68 | 69 | void set_config_defaults_enabled_i2c_test(void** state) 70 | { 71 | config config_obj; 72 | i2c_options i2c; 73 | i2c.enable = true; 74 | i2c.bus = 4; 75 | 76 | STATUS status = set_config_defaults(&config_obj, &i2c); 77 | assert_int_equal(status, ST_OK); 78 | assert_true(config_obj.i2c.enable_i2c); 79 | assert_int_equal(config_obj.i2c.default_bus, 4); 80 | for (int i = 0; i < MAX_I2C_BUSES; i++) 81 | { 82 | if (i == 4) 83 | assert_true(config_obj.i2c.allowed_buses[i]); 84 | else 85 | assert_false(config_obj.i2c.allowed_buses[i]); 86 | } 87 | } 88 | 89 | int main() 90 | { 91 | const struct CMUnitTest tests[] = { 92 | cmocka_unit_test(set_config_defaults_failed_test), 93 | cmocka_unit_test(set_config_defaults_enabled_i2c_test), 94 | }; 95 | 96 | return cmocka_run_group_tests(tests, NULL, NULL); 97 | } 98 | -------------------------------------------------------------------------------- /server/tests/ext_tcp_tests.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "../ext_network.h" 41 | #include "../ext_tcp.h" 42 | #include "../logging.h" 43 | #include "cmocka.h" 44 | 45 | // static char temporary_log_buffer[512]; 46 | void __wrap_ASD_log(ASD_LogLevel level, ASD_LogStream stream, 47 | ASD_LogOption options, const char* format, ...) 48 | { 49 | (void)level; 50 | (void)stream; 51 | (void)options; 52 | (void)format; 53 | // va_list args; 54 | // va_start(args, format); 55 | // vsnprintf(temporary_log_buffer, sizeof(temporary_log_buffer), format, 56 | // args); 57 | // fprintf(stderr, "%s\n", temporary_log_buffer); 58 | // va_end(args); 59 | } 60 | 61 | ssize_t __wrap_recv(int socket, void* buffer, size_t length, int flags) 62 | { 63 | check_expected(socket); 64 | check_expected_ptr(buffer); 65 | check_expected(length); 66 | check_expected(flags); 67 | return length; 68 | } 69 | 70 | ssize_t __wrap_send(int socket, void* buffer, size_t length, int flags) 71 | { 72 | check_expected(socket); 73 | check_expected_ptr(buffer); 74 | check_expected(length); 75 | check_expected(flags); 76 | return length; 77 | } 78 | 79 | void exttcp_init_returns_success_test(void** state) 80 | { 81 | (void)state; 82 | assert_int_equal(ST_OK, exttcp_init(NULL)); 83 | } 84 | 85 | void exttcp_cleanup_returns_without_issue_test(void** state) 86 | { 87 | (void)state; 88 | exttcp_cleanup(); 89 | } 90 | 91 | void exttcp_on_accept_returns_success_test(void** state) 92 | { 93 | (void)state; 94 | assert_int_equal(ST_OK, exttcp_on_accept(NULL, NULL)); 95 | } 96 | 97 | void exttcp_init_client_returns_success_test(void** state) 98 | { 99 | (void)state; 100 | assert_int_equal(ST_OK, exttcp_init_client(NULL)); 101 | } 102 | 103 | void exttcp_on_close_client_returns_success_test(void** state) 104 | { 105 | (void)state; 106 | assert_int_equal(ST_OK, exttcp_on_close_client(NULL)); 107 | } 108 | 109 | void exttcp_recv_returns_error_on_invalid_connection_pointer_test(void** state) 110 | { 111 | (void)state; 112 | char buffer[15]; 113 | bool data_pending = false; 114 | assert_int_equal(-1, exttcp_recv(NULL, &buffer, 15, &data_pending)); 115 | } 116 | 117 | void exttcp_recv_returns_error_on_invalid_buffer_pointer_test(void** state) 118 | { 119 | (void)state; 120 | extnet_conn_t connection; 121 | connection.sockfd = 99; 122 | bool data_pending = false; 123 | assert_int_equal(-1, exttcp_recv(&connection, NULL, 1, &data_pending)); 124 | } 125 | 126 | void exttcp_recv_returns_error_on_invalid_socket_fd_test(void** state) 127 | { 128 | (void)state; 129 | extnet_conn_t connection; 130 | connection.sockfd = -1; 131 | char buffer[15]; 132 | bool data_pending = false; 133 | assert_int_equal(-1, exttcp_recv(&connection, &buffer, 1, &data_pending)); 134 | } 135 | 136 | void exttcp_recv_returns_calls_recv_test(void** state) 137 | { 138 | (void)state; 139 | int expected_socket = 12; 140 | size_t expected_length = 123; 141 | extnet_conn_t connection; 142 | connection.sockfd = expected_socket; 143 | char buffer[15]; 144 | bool data_pending = false; 145 | expect_value(__wrap_recv, socket, expected_socket); 146 | expect_any(__wrap_recv, buffer); 147 | expect_value(__wrap_recv, length, expected_length); 148 | expect_value(__wrap_recv, flags, 0); 149 | 150 | assert_int_equal( 151 | expected_length, 152 | exttcp_recv(&connection, &buffer, expected_length, &data_pending)); 153 | 154 | assert_false(data_pending); 155 | } 156 | 157 | void exttcp_send_returns_error_on_invalid_connection_pointer_test(void** state) 158 | { 159 | (void)state; 160 | char buffer[15]; 161 | assert_int_equal(-1, exttcp_send(NULL, &buffer, 15)); 162 | } 163 | 164 | void exttcp_send_returns_error_on_invalid_buffer_pointer_test(void** state) 165 | { 166 | (void)state; 167 | extnet_conn_t connection; 168 | connection.sockfd = 99; 169 | assert_int_equal(-1, exttcp_send(&connection, NULL, 1)); 170 | } 171 | 172 | void exttcp_send_returns_error_on_invalid_socket_fd_test(void** state) 173 | { 174 | (void)state; 175 | extnet_conn_t connection; 176 | connection.sockfd = -1; 177 | char buffer[15]; 178 | assert_int_equal(-1, exttcp_send(&connection, &buffer, 1)); 179 | } 180 | 181 | void exttcp_send_returns_calls_recv_test(void** state) 182 | { 183 | (void)state; 184 | int expected_socket = 12; 185 | size_t expected_length = 1234; 186 | extnet_conn_t connection; 187 | connection.sockfd = expected_socket; 188 | char buffer[15]; 189 | expect_value(__wrap_send, socket, expected_socket); 190 | expect_any(__wrap_send, buffer); 191 | expect_value(__wrap_send, length, expected_length); 192 | expect_value(__wrap_send, flags, 0); 193 | 194 | assert_int_equal(expected_length, 195 | exttcp_send(&connection, &buffer, expected_length)); 196 | } 197 | 198 | int main() 199 | { 200 | const struct CMUnitTest tests[] = { 201 | cmocka_unit_test(exttcp_init_returns_success_test), 202 | cmocka_unit_test(exttcp_cleanup_returns_without_issue_test), 203 | cmocka_unit_test(exttcp_on_accept_returns_success_test), 204 | cmocka_unit_test(exttcp_init_client_returns_success_test), 205 | cmocka_unit_test(exttcp_on_close_client_returns_success_test), 206 | cmocka_unit_test( 207 | exttcp_recv_returns_error_on_invalid_connection_pointer_test), 208 | cmocka_unit_test( 209 | exttcp_recv_returns_error_on_invalid_buffer_pointer_test), 210 | cmocka_unit_test(exttcp_recv_returns_error_on_invalid_socket_fd_test), 211 | cmocka_unit_test(exttcp_recv_returns_calls_recv_test), 212 | cmocka_unit_test( 213 | exttcp_send_returns_error_on_invalid_connection_pointer_test), 214 | cmocka_unit_test( 215 | exttcp_send_returns_error_on_invalid_buffer_pointer_test), 216 | cmocka_unit_test(exttcp_send_returns_error_on_invalid_socket_fd_test), 217 | cmocka_unit_test(exttcp_send_returns_calls_recv_test)}; 218 | 219 | return cmocka_run_group_tests(tests, NULL, NULL); 220 | } 221 | -------------------------------------------------------------------------------- /spp_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR) 2 | project(at-scale-debug-spp-test C) 3 | 4 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sysroot/include) 5 | pkg_check_modules (SAFEC REQUIRED libsafec) 6 | # Define HAVE_C99 to include sprintf_s macro in safec library 7 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_C99") 8 | include_directories (${SAFEC_INCLUDE_DIRS}) 9 | include_directories (${ASD_DIR}/include) 10 | include_directories (${ASD_DIR}/target) 11 | link_directories (${SAFEC_LIBRARY_DIRS}) 12 | set(SPP_HANDLER "${ASD_DIR}/target/spp_handler.c" "${ASD_DIR}/target/i3c_debug_handler.c") 13 | 14 | if(NOT ${BUILD_UT}) 15 | add_executable(spp_test spp_test.c 16 | ${ASD_DIR}/server/logging.c 17 | ${ASD_DIR}/target/jtag_handler.c 18 | ${SPP_HANDLER}) 19 | target_link_libraries(spp_test -lm ${SAFEC_LIBRARIES}) 20 | install (TARGETS spp_test DESTINATION bin) 21 | endif(NOT ${BUILD_UT}) 22 | 23 | add_subdirectory(debug_over_i3c) 24 | 25 | -------------------------------------------------------------------------------- /spp_test/debug_over_i3c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (debug-over-i3c C CXX) 2 | 3 | set (CMAKE_CXX_STANDARD 17) 4 | set (CMAKE_CXX_STANDARD_REQUIRED ON) 5 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") 6 | 7 | add_executable (debug-over-i3c debug-over-i3c.c) 8 | 9 | set ( 10 | CMAKE_C_FLAGS 11 | "${CMAKE_C_FLAGS} \ 12 | -Wall \ 13 | -Wextra \ 14 | -Wunused \ 15 | -Wsign-conversion \ 16 | -Wnull-dereference \ 17 | -Wdouble-promotion \ 18 | -Wformat=2 \ 19 | -Wno-unused-parameter \ 20 | -Werror \ 21 | -Wduplicated-cond \ 22 | -Wduplicated-branches \ 23 | -Wlogical-op \ 24 | -Wshadow \ 25 | -Wmisleading-indentation \ 26 | " 27 | ) 28 | 29 | install (TARGETS debug-over-i3c DESTINATION bin) -------------------------------------------------------------------------------- /spp_test/debug_over_i3c/debug-over-i3c.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef AT_SCALE_DEBUG_DEBUG_OVER_I3C_H 29 | #define AT_SCALE_DEBUG_DEBUG_OVER_I3C_H 30 | 31 | #pragma GCC diagnostic push 32 | #pragma GCC diagnostic ignored "-Wcpp" 33 | #include 34 | #include 35 | #pragma GCC diagnostic pop 36 | 37 | 38 | 39 | struct i3c_debug_opcode_ccc { 40 | __u8 opcode; 41 | __u16 write_len; 42 | __u64 write_ptr; 43 | __u16 read_len; 44 | __u64 read_ptr; 45 | }; 46 | 47 | struct i3c_debug_action_ccc { 48 | __u8 action; 49 | }; 50 | 51 | struct i3c_get_event_data { 52 | __u16 data_len; 53 | __u64 data_ptr; 54 | }; 55 | 56 | #define I3C_DEBUG_IOCTL_BASE 0x79 57 | 58 | #define I3C_DEBUG_IOCTL_DEBUG_OPCODE_CCC \ 59 | _IOWR(I3C_DEBUG_IOCTL_BASE, 0x41, struct i3c_debug_opcode_ccc) 60 | 61 | #define I3C_DEBUG_IOCTL_DEBUG_ACTION_CCC \ 62 | _IOW(I3C_DEBUG_IOCTL_BASE, 0x42, struct i3c_debug_action_ccc) 63 | 64 | #define I3C_DEBUG_IOCTL_GET_EVENT_DATA \ 65 | _IOWR(I3C_DEBUG_IOCTL_BASE, 0x43, struct i3c_get_event_data) 66 | #endif // AT_SCALE_DEBUG_DEBUG_OVER_I3C_H 67 | -------------------------------------------------------------------------------- /target/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR) 2 | project(at-scale-debug-target C) 3 | 4 | find_package (PkgConfig REQUIRED) 5 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sysroot/include) 6 | pkg_check_modules (SAFEC REQUIRED libsafec) 7 | # Define HAVE_C99 to include sprintf_s macro in safec library 8 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_C99") 9 | include_directories (${SAFEC_INCLUDE_DIRS}) 10 | include_directories (${ASD_DIR}/include) 11 | 12 | # Set APB_FREQ to EXTRA_OECMAKE on bb recipe to modify JTAG frequency 13 | if(${APB_FREQ}) 14 | add_definitions( -DAPB_FREQ=${APB_FREQ} ) 15 | endif(${APB_FREQ}) 16 | 17 | # Set I2C_STUB and/or I3C_STUB to EXTRA_OECMAKE on bb recipe to remove 18 | # i2c/i3c features and dependencies respectively. 19 | set(I2C_MSG_BUILDER "i2c_msg_builder.c") 20 | set(I2C_HANDLER "i2c_handler.c") 21 | set(I3C_HANDLER "i3c_handler.c") 22 | set(SPP_HANDLER "spp_handler.c" "i3c_debug_handler.c") 23 | 24 | if(${I2C_STUB}) 25 | if(${I3C_STUB}) 26 | set(I2C_MSG_BUILDER "i2c_msg_builder_stub.c") 27 | endif(${I3C_STUB}) 28 | endif(${I2C_STUB}) 29 | 30 | if(${I2C_STUB}) 31 | set(I2C_HANDLER "i2c_handler_stub.c") 32 | endif(${I2C_STUB}) 33 | 34 | if(${I3C_STUB}) 35 | set(I3C_HANDLER "i3c_handler_stub.c") 36 | endif(${I3C_STUB}) 37 | 38 | if(${SPP_STUB}) 39 | set(SPP_HANDLER "spp_handler_stub.c") 40 | endif(${SPP_STUB}) 41 | 42 | if(NOT ${BUILD_UT}) 43 | add_library(asd_target STATIC asd_msg.c jtag_handler.c 44 | target_handler.c ${I2C_MSG_BUILDER} ${I2C_HANDLER} 45 | ${I3C_HANDLER} gpio.c dbus_helper.c vprobe_handler.c 46 | ${SPP_HANDLER} asd_target_api.c asd_server_interface.c) 47 | target_link_libraries(asd_target -lm -lsystemd -lgpiod) 48 | endif(NOT ${BUILD_UT}) 49 | -------------------------------------------------------------------------------- /target/asd_msg.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef ASD_ASD_MSG_H 29 | #define ASD_ASD_MSG_H 30 | 31 | #include "config.h" 32 | 33 | #include 34 | 35 | #include "asd_common.h" 36 | #include "i2c_handler.h" 37 | #include "i2c_msg_builder.h" 38 | #include "i3c_handler.h" 39 | #include "jtag_handler.h" 40 | #include "logging.h" 41 | #include "target_handler.h" 42 | #include "vprobe_handler.h" 43 | #include "spp_handler.h" 44 | 45 | #define NUM_IN_FLIGHT_BUFFERS_TO_USE 20 46 | #define MAX_MULTICHAINS 16 47 | #define CHARS_PER_CHAIN 5 48 | #define OPENBMC_V "OPENBMC_VERSION" 49 | #define ASCII_DOUBLE_QUOTES 34 50 | 51 | // Reset operation request comes in a bundle where a request to assert 52 | // the reset signal is sent first, followed to an instruction for ASD 53 | // application to wait(WAIT_CYCLE) and ends with a request for de-asssert 54 | // reset signal. The sequence is an standard flow intended for a reset 55 | // signal driven by a GPIO. 56 | // After reset is de-asserted it is expected from BMC to detect the reset 57 | // and report it back to the client. However in our base code and some BMC 58 | // implementations reset execution is tied to an internal BMC function 59 | // (triggered during assertion) rather than a GPIO. In this scenario reset 60 | // events may occur while ASD application is still processing the wait cycles 61 | // preventing ASD to perform a proper detection. 62 | // You can use the following flag to skip wait cycles and allow ASD 63 | // application to be ready for processing platform events. On the other 64 | // hand if your RESET_BTN signal is driven by a GPIO this option should be 65 | // disabled and a separate process to monitor for events is suggested. 66 | #define SKIP_WAIT_CYCLES_DURING_RESET 67 | 68 | typedef STATUS (*SendFunctionPtr)(unsigned char* buffer, 69 | size_t length); 70 | typedef STATUS (*ReadFunctionPtr)(void* connection, void* buffer, 71 | size_t* num_to_read, bool* data_pending); 72 | 73 | typedef enum 74 | { 75 | READ_STATE_INITIAL = 0, 76 | READ_STATE_HEADER, 77 | READ_STATE_BUFFER, 78 | } ReadState; 79 | 80 | typedef struct incoming_msg 81 | { 82 | ssize_t read_index; 83 | ssize_t data_size; 84 | ReadState read_state; 85 | struct asd_message msg; 86 | } incoming_msg; 87 | 88 | typedef struct ASD_MSG 89 | { 90 | config* asd_cfg; 91 | struct incoming_msg in_msg; 92 | struct asd_message out_msg; 93 | JTAG_Handler* jtag_handler; 94 | Target_Control_Handle* target_handler; 95 | bus_config* buscfg; 96 | I2C_Handler* i2c_handler; 97 | I3C_Handler* i3c_handler; 98 | vProbe_Handler* vprobe_handler; 99 | SPP_Handler* spp_handler; 100 | bool handlers_initialized; 101 | LogFunctionPtr send_remote_logging_message; 102 | unsigned char prdy_timeout; 103 | JTAG_CHAIN_SELECT_MODE jtag_chain_mode; 104 | char bmc_version[120]; 105 | int bmc_version_size; 106 | } ASD_MSG; 107 | 108 | struct packet_data 109 | { 110 | unsigned char* next_data; 111 | unsigned int used, total; 112 | }; 113 | 114 | typedef enum 115 | { 116 | ScanType_Read, 117 | ScanType_Write, 118 | ScanType_ReadWrite 119 | } ScanType; 120 | 121 | extern int asd_poll_timeout_ms; 122 | 123 | STATUS asd_msg_init(config* asd_cfg); 124 | STATUS asd_msg_free(void); 125 | STATUS asd_msg_on_msg_recv(void); 126 | int get_message_size(struct asd_message* s_message); 127 | uint8_t lsb_from_msg_size(u_int32_t response_cnt); 128 | uint8_t msb_from_msg_size(u_int32_t response_cnt); 129 | STATUS determine_shift_end_state(ScanType scan_type, 130 | struct packet_data* packet, 131 | enum jtag_states* end_state); 132 | STATUS asd_msg_read(void); 133 | void send_error_message(struct asd_message* input_message, 134 | ASDError cmd_stat); 135 | STATUS send_response(struct asd_message* message); 136 | STATUS asd_msg_get_fds(target_fdarr_t* fds, int* num_fds); 137 | STATUS asd_msg_event(struct pollfd poll_fd); 138 | STATUS process_i2c_messages(struct asd_message* in_msg); 139 | STATUS do_read_command(uint8_t cmd, I2C_Msg_Builder* builder, 140 | struct packet_data* packet, bool* force_stop); 141 | STATUS do_write_command(uint8_t cmd, I2C_Msg_Builder* builder, 142 | struct packet_data* packet, bool* force_stop); 143 | STATUS build_responses(int* response_cnt, 144 | I2C_Msg_Builder* builder, bool ack); 145 | void* get_packet_data(struct packet_data* packet, int bytes_wanted); 146 | void process_message(); 147 | STATUS read_openbmc_version(void); 148 | static STATUS send_pin_event(ASD_EVENT value); 149 | 150 | #endif // ASD_ASD_MSG_H 151 | -------------------------------------------------------------------------------- /target/asd_server_interface.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "asd_server_interface.h" 29 | #include "asd_server_api.h" 30 | #include 31 | 32 | static STATUS asd_server_interface_version(char* version) 33 | { 34 | STATUS status = ST_ERR; 35 | if (version != NULL) { 36 | if (sprintf_s(version, MAX_SERVER_INTERFACE_VERSION_SIZE, "%d.%d.%d", 37 | ASD_SERVER_INTERFACE_API_VERSION_MAJOR, 38 | ASD_SERVER_INTERFACE_API_VERSION_MINOR, 39 | ASD_SERVER_INTERFACE_API_VERSION_PATCH) > 0) { 40 | status = ST_OK; 41 | } 42 | } 43 | return status; 44 | } 45 | 46 | static bool asd_is_api_server_version_supported(char* version) 47 | { 48 | bool supported = false; 49 | int cmp = -1; 50 | char server_api_version[MAX_SERVER_INTERFACE_VERSION_SIZE]; 51 | STATUS status = ST_ERR; 52 | 53 | if (version != NULL) { 54 | status = asd_server_ioctl(NULL, server_api_version, IOCTL_SERVER_GET_API_VERSION); 55 | } 56 | if (status == ST_OK) { 57 | strcmp_s(version, MAX_SERVER_INTERFACE_VERSION_SIZE, 58 | server_api_version, &cmp); 59 | if (cmp == 0) { 60 | supported = true; 61 | } else { 62 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_Daemon, 63 | ASD_LogOption_None, 64 | "Incompatible ASD Server API versions"); 65 | } 66 | ASD_log(ASD_LogLevel_Info, ASD_LogStream_Daemon, ASD_LogOption_None, 67 | "server_interface_version = %s, server_api_version = %s", 68 | version, server_api_version); 69 | } 70 | return supported; 71 | } 72 | 73 | size_t asd_api_server_read(unsigned char* buffer, size_t length, void* opt) 74 | { 75 | return asd_server_read(buffer, length, opt); 76 | } 77 | 78 | size_t asd_api_server_write(void* buffer, size_t length, void* opt) 79 | { 80 | return asd_server_write(buffer, length, opt); 81 | } 82 | 83 | STATUS asd_api_server_ioctl(void* input, void* output, unsigned int cmd) 84 | { 85 | STATUS status = ST_ERR; 86 | char * server_interface_version = NULL; 87 | switch(cmd) 88 | { 89 | case IOCTL_SERVER_GET_INTERFACE_VERSION: 90 | if (output == NULL) 91 | break; 92 | server_interface_version = (char *) output; 93 | status = asd_server_interface_version(server_interface_version); 94 | break; 95 | case IOCTL_SERVER_IS_INTERFACE_SUPPORTED: 96 | if (input == NULL || output == NULL) 97 | break; 98 | server_interface_version = (char *) input; 99 | bool * supported = (bool *) output; 100 | *supported = asd_is_api_server_version_supported(server_interface_version); 101 | status = ST_OK; 102 | break; 103 | default: 104 | status = asd_server_ioctl(input, output, cmd); 105 | } 106 | return status; 107 | } 108 | 109 | void asd_api_server_log(ASD_LogLevel level, ASD_LogStream stream, 110 | ASD_LogOption options, const char* format, ...) 111 | { 112 | char string[MAX_LOG_SIZE]; 113 | va_list args; 114 | va_start(args, format); 115 | vsprintf_s(string, sizeof(string), format, args); 116 | asd_server_log(level, stream, options, string); 117 | va_end( args ); 118 | } 119 | 120 | void asd_api_server_log_buffer(ASD_LogLevel level, ASD_LogStream stream, 121 | ASD_LogOption options, const unsigned char* ptr, 122 | size_t len, const char* prefixPtr) 123 | { 124 | asd_server_log_buffer(level, stream, options, ptr, len, prefixPtr); 125 | } 126 | 127 | void asd_api_server_log_shift(ASD_LogLevel level, ASD_LogStream stream, 128 | ASD_LogOption options, 129 | unsigned int number_of_bits, 130 | unsigned int size_bytes, unsigned char* buffer, 131 | const char* prefixPtr) 132 | { 133 | asd_server_log_shift(level, stream, options, number_of_bits, size_bytes, 134 | buffer, prefixPtr); 135 | } 136 | -------------------------------------------------------------------------------- /target/asd_target_api.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "asd_common.h" 29 | #include "asd_target_api.h" 30 | #include "asd_server_interface.h" 31 | #include "asd_msg.h" 32 | #include 33 | 34 | static STATUS asd_target_process_all_pin_events(const struct pollfd* poll_fds, size_t num_fds); 35 | static STATUS asd_target_process_pin_event(struct pollfd poll_fd); 36 | static void send_remote_log_message(ASD_LogLevel asd_level, 37 | ASD_LogStream asd_stream, 38 | const char* message); 39 | 40 | static STATUS asd_target_version(char* version) 41 | { 42 | STATUS status = ST_ERR; 43 | if (version != NULL) { 44 | if (sprintf_s(version, MAX_TARGET_VERSION_SIZE, "%d.%d.%d", 45 | ASD_TARGET_API_VERSION_MAJOR, 46 | ASD_TARGET_API_VERSION_MINOR, 47 | ASD_TARGET_API_VERSION_PATCH) > 0) { 48 | status = ST_OK; 49 | } 50 | } 51 | return status; 52 | } 53 | 54 | STATUS asd_target_init(config* asd_cfg) 55 | { 56 | // Check API version compatibility 57 | char server_interface_version[MAX_TARGET_VERSION_SIZE]; 58 | bool supported = false; 59 | STATUS status = asd_api_server_ioctl(NULL, server_interface_version, 60 | IOCTL_SERVER_GET_INTERFACE_VERSION); 61 | if(status == ST_OK) { 62 | status = asd_api_server_ioctl(server_interface_version, &supported, 63 | IOCTL_SERVER_IS_INTERFACE_SUPPORTED); 64 | } 65 | if (status == ST_OK) { 66 | if(supported) { 67 | status = asd_msg_init(asd_cfg); 68 | } else { 69 | status = ST_ERR; 70 | } 71 | } 72 | return status; 73 | } 74 | 75 | STATUS asd_target_deinit(void) 76 | { 77 | return asd_msg_free(); 78 | } 79 | 80 | size_t asd_target_read(unsigned char* buffer, size_t length, void* opt) 81 | { 82 | return 0; 83 | } 84 | 85 | size_t asd_target_write(unsigned char* buffer, size_t length, void* opt) 86 | { 87 | return 0; 88 | } 89 | 90 | STATUS asd_target_ioctl(void* input, void* output, unsigned int cmd) 91 | { 92 | STATUS status = ST_ERR; 93 | switch(cmd) 94 | { 95 | case IOCTL_TARGET_GET_API_VERSION: 96 | if (output == NULL) 97 | break; 98 | char * target_api_version = (char *) output; 99 | status = asd_target_version(target_api_version); 100 | break; 101 | case IOCTL_TARGET_PROCESS_MSG: 102 | status = asd_msg_read(); 103 | break; 104 | case IOCTL_TARGET_GET_PIN_FDS: 105 | if (output == NULL) 106 | break; 107 | asd_target_events * pin_events = (asd_target_events *) output; 108 | status = asd_msg_get_fds(&pin_events->fds, &pin_events->num_fds); 109 | break; 110 | case IOCTL_TARGET_PROCESS_ALL_PIN_EVENTS: 111 | if (input == NULL) 112 | break; 113 | poll_asd_target_events * poll_events = (poll_asd_target_events *)input; 114 | status = asd_target_process_all_pin_events(poll_events->poll_fds, poll_events->num_fds); 115 | break; 116 | case IOCTL_TARGET_PROCESS_PIN_EVENT: 117 | if (input == NULL) 118 | break; 119 | struct pollfd * poll_fd = (struct pollfd *)input; 120 | status = asd_target_process_pin_event(*poll_fd); 121 | break; 122 | case IOCTL_TARGET_SEND_REMOTE_LOG_MSG: 123 | if (input == NULL) 124 | break; 125 | asd_target_remote_log * remote_log = (asd_target_remote_log *)input; 126 | send_remote_log_message(remote_log->level, remote_log->stream, remote_log->msg); 127 | status = ST_OK; 128 | break; 129 | case IOCTL_TARGET_GET_I2C_I3C_BUS_CONFIG: 130 | if (output == NULL) 131 | break; 132 | bus_options * target_bus_options = (bus_options *)output; 133 | status = target_get_i2c_i3c_config(target_bus_options); 134 | break; 135 | } 136 | return status; 137 | } 138 | 139 | static STATUS asd_target_process_all_pin_events(const struct pollfd* poll_fds, size_t num_fds) 140 | { 141 | STATUS result = ST_OK; 142 | int poll_result = 0; 143 | 144 | // This cycle will check and report all pin events before checking the 145 | // requests on the network. 146 | while(1) 147 | { 148 | // Check if there has been a target event. 149 | poll_result = poll(poll_fds, num_fds, asd_poll_timeout_ms); 150 | if (poll_result <= 0) 151 | { 152 | asd_poll_timeout_ms = 0; 153 | return ST_OK; 154 | } 155 | 156 | for (int i = 0; i < num_fds; i++) 157 | { 158 | result = asd_target_process_pin_event(poll_fds[i]); 159 | if (result != ST_OK) 160 | return result; 161 | } 162 | } 163 | 164 | return result; 165 | } 166 | 167 | static STATUS asd_target_process_pin_event(struct pollfd poll_fd) 168 | { 169 | return asd_msg_event(poll_fd); 170 | } 171 | 172 | void asd_target_log(ASD_LogLevel level, ASD_LogStream stream, 173 | ASD_LogOption options, const char* string) 174 | { 175 | ASD_log(level, stream, options, string); 176 | } 177 | 178 | void asd_target_log_buffer(ASD_LogLevel level, ASD_LogStream stream, 179 | ASD_LogOption options, const unsigned char* ptr, 180 | size_t len, const char* prefixPtr) 181 | { 182 | ASD_log_buffer(level, stream, options, ptr, len, prefixPtr); 183 | } 184 | 185 | void asd_target_log_shift(ASD_LogLevel level, ASD_LogStream stream, 186 | ASD_LogOption options, unsigned int number_of_bits, 187 | unsigned int size_bytes, unsigned char* buffer, 188 | const char* prefixPtr) 189 | { 190 | ASD_log_shift(level, stream, options, number_of_bits, size_bytes, buffer, 191 | prefixPtr); 192 | } 193 | -------------------------------------------------------------------------------- /target/dbus_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef __ASD_DBUS_HELPER_H_ 29 | #define __ASD_DBUS_HELPER_H_ 30 | 31 | #include 32 | #include 33 | 34 | #include "asd_common.h" 35 | 36 | #define POWER_SERVICE_HOST "xyz.openbmc_project.State.Host" 37 | #define POWER_INTERFACE_NAME_HOST "xyz.openbmc_project.State.Host" 38 | #define POWER_OBJECT_PATH_HOST "/xyz/openbmc_project/state/host0" 39 | #define HOST_TRANSITION_PROPERTY "RequestedHostTransition" 40 | #define RESET_ARGUMENT_HOST \ 41 | "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot" 42 | #define POWER_SERVICE_CHASSIS "xyz.openbmc_project.State.Chassis" 43 | #define POWER_INTERFACE_NAME_CHASSIS "xyz.openbmc_project.State.Chassis" 44 | #define POWER_OBJECT_PATH_CHASSIS "/xyz/openbmc_project/state/chassis0" 45 | #define GET_POWER_STATE_PROPERTY_CHASSIS "CurrentPowerState" 46 | #define SET_POWER_STATE_METHOD_CHASSIS "RequestedPowerTransition" 47 | #define POWER_OFF_PROPERTY_CHASSIS \ 48 | "xyz.openbmc_project.State.Chassis.PowerState.Off" 49 | #define POWER_ON_PROPERTY_CHASSIS \ 50 | "xyz.openbmc_project.State.Chassis.PowerState.On" 51 | #define POWER_OFF_ARGUMENT_CHASSIS \ 52 | "xyz.openbmc_project.State.Chassis.Transition.Off" 53 | #define POWER_ON_ARGUMENT_CHASSIS \ 54 | "xyz.openbmc_project.State.Chassis.Transition.On" 55 | #define POWER_REBOOT_ARGUMENT_CHASSIS \ 56 | "xyz.openbmc_project.State.Chassis.Transition.Reboot" 57 | #define POWER_RESET_ARGUMENT_CHASSIS \ 58 | "xyz.openbmc_project.State.Chassis.Transition.Reset" 59 | 60 | #define DBUS_PROPERTIES "org.freedesktop.DBus.Properties" 61 | #define DBUS_SET_METHOD "Set" 62 | #define MATCH_STRING_CHASSIS \ 63 | "type='signal',path='/xyz/openbmc_project/state/chassis0',\ 64 | member='PropertiesChanged',interface='org.freedesktop.DBus.Properties',\ 65 | sender='xyz.openbmc_project.State.Chassis',\ 66 | arg0namespace='xyz.openbmc_project.State.Chassis'" 67 | 68 | #define OBJECT_MAPPER_SERVICE "xyz.openbmc_project.ObjectMapper" 69 | #define OBJECT_MAPPER_PATH "/xyz/openbmc_project/object_mapper" 70 | #define OBJECT_MAPPER_INTERFACE "xyz.openbmc_project.ObjectMapper" 71 | #define BASEBOARD_PATH "/xyz/openbmc_project/inventory/system/board" 72 | #define MOTHERBOARD_IDENTIFIER \ 73 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard" 74 | 75 | #define ENTITY_MANAGER_SERVICE "xyz.openbmc_project.EntityManager" 76 | #define ENTITY_MANAGER_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties" 77 | #define ASD_CONFIG_PATH "xyz.openbmc_project.Configuration.ASD" 78 | 79 | #define CLTT_SERVICE "xyz.openbmc_project.CLTT" 80 | #define CLTT_PATH "/xyz/openbmc_project/AllSpdBuses" 81 | #define CLTT_INTERFACE "xyz.openbmc_project.BusControl" 82 | 83 | #define SD_BUS_ASYNC_TIMEOUT 10000 84 | #define MAX_PLATFORM_PATH_SIZE 120 85 | 86 | typedef enum 87 | { 88 | STATE_UNKNOWN = -1, 89 | STATE_OFF = 0, 90 | STATE_ON = 1 91 | } Power_State; 92 | 93 | typedef struct Dbus_Handle 94 | { 95 | sd_bus* bus; 96 | int fd; 97 | Power_State power_state; 98 | } Dbus_Handle; 99 | 100 | typedef enum 101 | { 102 | CPU_OWNER, 103 | BMC_OWNER 104 | } I3c_Ownership; 105 | 106 | Dbus_Handle* dbus_helper(); 107 | STATUS dbus_initialize(Dbus_Handle*); 108 | STATUS dbus_deinitialize(Dbus_Handle*); 109 | STATUS dbus_power_reset(Dbus_Handle*); 110 | STATUS dbus_power_toggle(Dbus_Handle*); 111 | STATUS dbus_power_reboot(Dbus_Handle*); 112 | STATUS dbus_power_on(Dbus_Handle*); 113 | STATUS dbus_power_off(Dbus_Handle*); 114 | int sdbus_callback(sd_bus_message* reply, void* userdata, sd_bus_error* error); 115 | STATUS dbus_process_event(Dbus_Handle* state, ASD_EVENT* event); 116 | STATUS dbus_get_powerstate(Dbus_Handle* state, int* value); 117 | STATUS dbus_get_platform_path(const Dbus_Handle* state, char* path); 118 | STATUS dbus_get_platform_id(const Dbus_Handle* state, uint64_t* pid); 119 | STATUS dbus_read_asd_config(const Dbus_Handle* state, const char* interface, 120 | const char* name, char type, void* var); 121 | STATUS dbus_get_asd_interface_paths(const Dbus_Handle* state, 122 | const char* names[], 123 | char interfaces[][MAX_PLATFORM_PATH_SIZE], 124 | int arr_size); 125 | STATUS dbus_get_platform_bus_config(const Dbus_Handle* state, 126 | bus_options* busopt); 127 | STATUS dbus_read_i3c_ownership(const Dbus_Handle* state, I3c_Ownership* owner); 128 | STATUS dbus_req_i3c_ownership(const Dbus_Handle* state, int* token); 129 | STATUS dbus_rel_i3c_ownership(const Dbus_Handle* state, int token); 130 | int match_callback(sd_bus_message* m, void* userdata, sd_bus_error* error); 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /target/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef __GPIO_H_ 29 | #define __GPIO_H_ 30 | 31 | #include 32 | 33 | #include "asd_common.h" 34 | 35 | #define ALL_GPIO_EDGES(FUNC) \ 36 | FUNC(GPIO_EDGE_NONE) \ 37 | FUNC(GPIO_EDGE_RISING) \ 38 | FUNC(GPIO_EDGE_FALLING) \ 39 | FUNC(GPIO_EDGE_BOTH) 40 | 41 | #define ALL_GPIO_DIRECTIONS(FUNC) \ 42 | FUNC(GPIO_DIRECTION_IN) \ 43 | FUNC(GPIO_DIRECTION_OUT) \ 44 | FUNC(GPIO_DIRECTION_HIGH) \ 45 | FUNC(GPIO_DIRECTION_LOW) 46 | 47 | typedef enum 48 | { 49 | ALL_GPIO_EDGES(TO_ENUM) 50 | } GPIO_EDGE; 51 | 52 | static const char* GPIO_EDGE_STRINGS[] = {ALL_GPIO_EDGES(TO_STRING)}; 53 | 54 | typedef enum 55 | { 56 | ALL_GPIO_DIRECTIONS(TO_ENUM) 57 | } GPIO_DIRECTION; 58 | 59 | static const char* GPIO_DIRECTION_STRINGS[] = {ALL_GPIO_DIRECTIONS(TO_STRING)}; 60 | 61 | STATUS gpio_export(int gpio, int* fd); 62 | STATUS gpio_unexport(int gpio); 63 | STATUS gpio_get_value(int fd, int* value); 64 | STATUS gpio_set_value(int fd, int value); 65 | STATUS gpio_set_edge(int gpio, GPIO_EDGE edge); 66 | STATUS gpio_set_direction(int gpio, GPIO_DIRECTION direction); 67 | STATUS gpio_set_active_low(int gpio, bool active_low); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /target/i2c_handler.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "i2c_handler.h" 29 | 30 | // Disabling clang-format to avoid include alphabetical re-order that leads 31 | // into a conflict for i2c-dev.h that requires std headers to be added before. 32 | 33 | // clang-format off 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | // clang-format on 46 | 47 | #include "logging.h" 48 | 49 | #define I2C_DEV_FILE_NAME "/dev/i2c" 50 | #define MAX_I2C_DEV_FILENAME 256 51 | 52 | static const ASD_LogStream stream = ASD_LogStream_I2C; 53 | static const ASD_LogOption option = ASD_LogOption_None; 54 | 55 | static bool i2c_enabled(I2C_Handler* state); 56 | static STATUS i2c_open_driver(I2C_Handler* state, uint8_t bus); 57 | static void i2c_close_driver(I2C_Handler* state); 58 | static bool i2c_bus_allowed(I2C_Handler* state, uint8_t bus); 59 | 60 | I2C_Handler* I2CHandler(bus_config* config) 61 | { 62 | if (config == NULL) 63 | { 64 | ASD_log(ASD_LogLevel_Error, stream, option, 65 | "Invalid config parameter."); 66 | return NULL; 67 | } 68 | 69 | I2C_Handler* state = (I2C_Handler*)malloc(sizeof(I2C_Handler)); 70 | if (state == NULL) 71 | { 72 | ASD_log(ASD_LogLevel_Error, stream, option, 73 | "Failed to malloc I2C_Handler."); 74 | } 75 | else 76 | { 77 | state->i2c_driver_handle = UNINITIALIZED_I2C_DRIVER_HANDLE; 78 | state->config = config; 79 | } 80 | 81 | return state; 82 | } 83 | 84 | STATUS i2c_initialize(I2C_Handler* state) 85 | { 86 | STATUS status = ST_ERR; 87 | if (state != NULL && i2c_enabled(state)) 88 | { 89 | status = i2c_bus_select(state, state->config->default_bus); 90 | } 91 | return status; 92 | } 93 | 94 | STATUS i2c_deinitialize(I2C_Handler* state) 95 | { 96 | if (state == NULL) 97 | return ST_ERR; 98 | i2c_close_driver(state); 99 | state = NULL; 100 | return ST_OK; 101 | } 102 | 103 | STATUS i2c_bus_flock(I2C_Handler* state, uint8_t bus, int op) 104 | { 105 | STATUS status = ST_OK; 106 | ASD_log(ASD_LogLevel_Debug, ASD_LogStream_I2C, ASD_LogOption_None, 107 | "i2c - bus %d %s", bus, op == LOCK_EX ? "LOCK" : "UNLOCK"); 108 | if (bus != state->i2c_bus) 109 | { 110 | i2c_close_driver(state); 111 | status = i2c_open_driver(state, bus); 112 | } 113 | if (status == ST_OK) 114 | { 115 | if (flock(state->i2c_driver_handle, op) != 0) 116 | { 117 | ASD_log(ASD_LogLevel_Debug, ASD_LogStream_I2C, ASD_LogOption_None, 118 | "i2c flock for bus %d failed", bus); 119 | status = ST_ERR; 120 | } 121 | } 122 | 123 | return status; 124 | } 125 | 126 | STATUS i2c_bus_select(I2C_Handler* state, uint8_t bus) 127 | { 128 | STATUS status = ST_ERR; 129 | if (state != NULL && i2c_enabled(state)) 130 | { 131 | if (bus == state->i2c_bus) 132 | { 133 | status = ST_OK; 134 | } 135 | else if (i2c_bus_allowed(state, bus)) 136 | { 137 | i2c_close_driver(state); 138 | ASD_log(ASD_LogLevel_Error, stream, option, "Selecting Bus %d", 139 | bus); 140 | status = i2c_open_driver(state, bus); 141 | if (status == ST_OK) 142 | { 143 | state->config->default_bus = bus; 144 | } 145 | } 146 | else 147 | { 148 | ASD_log(ASD_LogLevel_Error, stream, option, "Bus %d not allowed", 149 | bus); 150 | } 151 | } 152 | return status; 153 | } 154 | 155 | STATUS i2c_set_sclk(I2C_Handler* state, uint16_t sclk) 156 | { 157 | if (state == NULL || !i2c_enabled(state)) 158 | return ST_ERR; 159 | return ST_OK; 160 | } 161 | 162 | STATUS i2c_read_write(I2C_Handler* state, void* msg_set) 163 | { 164 | if (state == NULL || msg_set == NULL || !i2c_enabled(state)) 165 | return ST_ERR; 166 | struct i2c_rdwr_ioctl_data* ioctl_data = msg_set; 167 | 168 | int ret = ioctl(state->i2c_driver_handle, I2C_RDWR, ioctl_data); 169 | 170 | if (ret != ioctl_data->nmsgs) 171 | { 172 | #ifdef ENABLE_DEBUG_LOGGING 173 | ASD_log(ASD_LogLevel_Debug, stream, option, 174 | "I2C_RDWR ioctl returned %d - %d - %s", ret, errno, 175 | strerror(errno)); 176 | #endif 177 | return ST_ERR; 178 | } 179 | 180 | return ST_OK; 181 | } 182 | 183 | static bool i2c_enabled(I2C_Handler* state) 184 | { 185 | return state->config->enable_i2c; 186 | } 187 | 188 | static STATUS i2c_open_driver(I2C_Handler* state, uint8_t bus) 189 | { 190 | char i2c_dev[MAX_I2C_DEV_FILENAME]; 191 | state->i2c_bus = bus; 192 | snprintf(i2c_dev, sizeof(i2c_dev), "%s-%d", I2C_DEV_FILE_NAME, bus); 193 | state->i2c_driver_handle = open(i2c_dev, O_RDWR); 194 | if (state->i2c_driver_handle == -1) 195 | { 196 | ASD_log(ASD_LogLevel_Error, stream, option, 197 | "Can't open %s, please install driver", i2c_dev); 198 | return ST_ERR; 199 | } 200 | return ST_OK; 201 | } 202 | 203 | static void i2c_close_driver(I2C_Handler* state) 204 | { 205 | if (state->i2c_driver_handle != UNINITIALIZED_I2C_DRIVER_HANDLE) 206 | { 207 | close(state->i2c_driver_handle); 208 | state->i2c_driver_handle = UNINITIALIZED_I2C_DRIVER_HANDLE; 209 | } 210 | } 211 | 212 | static bool i2c_bus_allowed(I2C_Handler* state, uint8_t bus) 213 | { 214 | for (int i = 0; i < MAX_IxC_BUSES; i++) 215 | { 216 | if (state->config->bus_config_map[i] == bus && 217 | state->config->bus_config_type[i] == BUS_CONFIG_I2C) 218 | return true; 219 | } 220 | return false; 221 | } -------------------------------------------------------------------------------- /target/i2c_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _I2C_HANDLER_H_ 29 | #define _I2C_HANDLER_H_ 30 | 31 | #include "config.h" 32 | 33 | #define UNINITIALIZED_I2C_DRIVER_HANDLE -1 34 | 35 | typedef struct I2C_Handler 36 | { 37 | uint8_t i2c_bus; 38 | bus_config* config; 39 | int i2c_driver_handle; 40 | } I2C_Handler; 41 | 42 | I2C_Handler* I2CHandler(bus_config* config); 43 | STATUS i2c_initialize(I2C_Handler* state); 44 | STATUS i2c_deinitialize(I2C_Handler* state); 45 | STATUS i2c_bus_flock(I2C_Handler* state, uint8_t bus, int op); 46 | STATUS i2c_bus_select(I2C_Handler* state, uint8_t bus); 47 | STATUS i2c_set_sclk(I2C_Handler* state, uint16_t sclk); 48 | STATUS i2c_read_write(I2C_Handler* state, void* msg_set); 49 | 50 | #endif -------------------------------------------------------------------------------- /target/i2c_handler_stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | // This file implements all i2c_handler functions required by ASD in stub 29 | // mode. A template for all interface functions is included but read / write 30 | // operation will always return an error. 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "i2c_handler.h" 38 | #include "logging.h" 39 | 40 | #define I2C_DEV_FILE_NAME "/dev/i2c" 41 | #define MAX_I2C_DEV_FILENAME 256 42 | 43 | static const ASD_LogStream stream = ASD_LogStream_I2C; 44 | static const ASD_LogOption option = ASD_LogOption_None; 45 | 46 | static bool i2c_enabled(I2C_Handler* state); 47 | static STATUS i2c_open_driver(I2C_Handler* state, uint8_t bus); 48 | static void i2c_close_driver(I2C_Handler* state); 49 | static bool i2c_bus_allowed(I2C_Handler* state, uint8_t bus); 50 | 51 | I2C_Handler* I2CHandler(bus_config* config) 52 | { 53 | if (config == NULL) 54 | { 55 | ASD_log(ASD_LogLevel_Error, stream, option, 56 | "I2C_Handler stub invalid config parameter."); 57 | return NULL; 58 | } 59 | 60 | I2C_Handler* state = (I2C_Handler*)malloc(sizeof(I2C_Handler)); 61 | if (state == NULL) 62 | { 63 | ASD_log(ASD_LogLevel_Error, stream, option, 64 | "Failed to malloc I2C_Handler stub."); 65 | } 66 | else 67 | { 68 | state->i2c_driver_handle = UNINITIALIZED_I2C_DRIVER_HANDLE; 69 | state->config = config; 70 | } 71 | 72 | return state; 73 | } 74 | 75 | STATUS i2c_initialize(I2C_Handler* state) 76 | { 77 | STATUS status = ST_ERR; 78 | if (state != NULL && i2c_enabled(state)) 79 | { 80 | status = i2c_bus_select(state, state->config->default_bus); 81 | } 82 | return status; 83 | } 84 | 85 | STATUS i2c_deinitialize(I2C_Handler* state) 86 | { 87 | if (state == NULL) 88 | return ST_ERR; 89 | i2c_close_driver(state); 90 | state = NULL; 91 | return ST_OK; 92 | } 93 | 94 | STATUS i2c_bus_flock(I2C_Handler* state, uint8_t bus, int op) 95 | { 96 | ASD_log(ASD_LogLevel_Debug, ASD_LogStream_I2C, ASD_LogOption_None, 97 | "i2c stub - bus %d %s", bus, op == LOCK_EX ? "LOCK" : "UNLOCK"); 98 | return ST_OK; 99 | } 100 | 101 | STATUS i2c_bus_select(I2C_Handler* state, uint8_t bus) 102 | { 103 | STATUS status = ST_ERR; 104 | if (state != NULL && i2c_enabled(state)) 105 | { 106 | if (bus == state->i2c_bus) 107 | { 108 | status = ST_OK; 109 | } 110 | else if (i2c_bus_allowed(state, bus)) 111 | { 112 | i2c_close_driver(state); 113 | ASD_log(ASD_LogLevel_Error, stream, option, "Selecting Stub Bus %d", 114 | bus); 115 | status = i2c_open_driver(state, bus); 116 | if (status == ST_OK) 117 | { 118 | state->config->default_bus = bus; 119 | } 120 | } 121 | else 122 | { 123 | ASD_log(ASD_LogLevel_Error, stream, option, "Bus %d not allowed", 124 | bus); 125 | } 126 | } 127 | return status; 128 | } 129 | 130 | STATUS i2c_set_sclk(I2C_Handler* state, uint16_t sclk) 131 | { 132 | if (state == NULL || !i2c_enabled(state)) 133 | return ST_ERR; 134 | return ST_OK; 135 | } 136 | 137 | STATUS i2c_read_write(I2C_Handler* state, void* msg_set) 138 | { 139 | ASD_log(ASD_LogLevel_Error, stream, option, 140 | "i2c_read_write stub function, R/W not implemented"); 141 | return ST_ERR; 142 | } 143 | 144 | static bool i2c_enabled(I2C_Handler* state) 145 | { 146 | return state->config->enable_i2c; 147 | } 148 | 149 | STATUS i2c_open_driver(I2C_Handler* state, uint8_t bus) 150 | { 151 | char i2c_dev[MAX_I2C_DEV_FILENAME]; 152 | state->i2c_bus = bus; 153 | snprintf(i2c_dev, sizeof(i2c_dev), "%s-%d", I2C_DEV_FILE_NAME, bus); 154 | state->i2c_driver_handle = UNINITIALIZED_I2C_DRIVER_HANDLE; 155 | ASD_log(ASD_LogLevel_Debug, stream, option, 156 | "Can't open %s, ASD is running i2c stub mode", i2c_dev); 157 | return ST_OK; 158 | } 159 | 160 | void i2c_close_driver(I2C_Handler* state) 161 | { 162 | if (state->i2c_driver_handle != UNINITIALIZED_I2C_DRIVER_HANDLE) 163 | { 164 | close(state->i2c_driver_handle); 165 | state->i2c_driver_handle = UNINITIALIZED_I2C_DRIVER_HANDLE; 166 | } 167 | } 168 | 169 | static bool i2c_bus_allowed(I2C_Handler* state, uint8_t bus) 170 | { 171 | for (int i = 0; i < MAX_IxC_BUSES; i++) 172 | { 173 | if (state->config->bus_config_map[i] == bus && 174 | state->config->bus_config_type[i] == BUS_CONFIG_I2C) 175 | return true; 176 | } 177 | return false; 178 | } -------------------------------------------------------------------------------- /target/i2c_msg_builder.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "i2c_msg_builder.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "logging.h" 36 | 37 | static STATUS copy_i2c_to_asd(asd_i2c_msg* asd, struct i2c_msg* i2c); 38 | static STATUS copy_asd_to_i2c(const asd_i2c_msg* asd, struct i2c_msg* i2c); 39 | 40 | I2C_Msg_Builder* I2CMsgBuilder() 41 | { 42 | I2C_Msg_Builder* state = (I2C_Msg_Builder*)malloc(sizeof(I2C_Msg_Builder)); 43 | if (state == NULL) 44 | { 45 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_Network, ASD_LogOption_None, 46 | "Failed to malloc I2C_Msg_Builder."); 47 | } 48 | else 49 | { 50 | state->msg_set = NULL; 51 | } 52 | 53 | return state; 54 | } 55 | 56 | STATUS i2c_msg_initialize(I2C_Msg_Builder* state) 57 | { 58 | STATUS status = ST_ERR; 59 | if (state != NULL) 60 | { 61 | state->msg_set = malloc(sizeof(struct i2c_rdwr_ioctl_data)); 62 | if (state->msg_set != NULL) 63 | { 64 | struct i2c_rdwr_ioctl_data* ioctl_data = state->msg_set; 65 | ioctl_data->nmsgs = 0; 66 | ioctl_data->msgs = NULL; 67 | status = ST_OK; 68 | } 69 | } 70 | return status; 71 | } 72 | 73 | STATUS i2c_msg_deinitialize(I2C_Msg_Builder* state) 74 | { 75 | STATUS status = ST_ERR; 76 | if (state != NULL) 77 | { 78 | if (state->msg_set != NULL) 79 | { 80 | status = i2c_msg_reset(state); 81 | if (status == ST_OK) 82 | { 83 | free(state->msg_set); 84 | state->msg_set = NULL; 85 | } 86 | } 87 | status = ST_OK; 88 | } 89 | return status; 90 | } 91 | 92 | STATUS i2c_msg_add(I2C_Msg_Builder* state, asd_i2c_msg* msg) 93 | { 94 | STATUS status = ST_ERR; 95 | if (state != NULL && msg != NULL) 96 | { 97 | struct i2c_rdwr_ioctl_data* ioctl_data = state->msg_set; 98 | if (ioctl_data->nmsgs == 0) 99 | { 100 | ioctl_data->msgs = (struct i2c_msg*)malloc(sizeof(struct i2c_msg)); 101 | } 102 | else 103 | { 104 | ioctl_data->msgs = (struct i2c_msg*)realloc( 105 | ioctl_data->msgs, 106 | (ioctl_data->nmsgs + 1) * sizeof(struct i2c_msg)); 107 | } 108 | if (ioctl_data->msgs) 109 | { 110 | struct i2c_msg* i2c_msg1 = ioctl_data->msgs + ioctl_data->nmsgs; 111 | status = copy_asd_to_i2c(msg, i2c_msg1); 112 | if (status == ST_OK) 113 | ioctl_data->nmsgs++; 114 | } 115 | } 116 | return status; 117 | } 118 | 119 | STATUS i2c_msg_get_count(I2C_Msg_Builder* state, uint32_t* count) 120 | { 121 | STATUS status = ST_ERR; 122 | if (state != NULL && state->msg_set != NULL && count != NULL) 123 | { 124 | struct i2c_rdwr_ioctl_data* ioctl_data = state->msg_set; 125 | *count = ioctl_data->nmsgs; 126 | status = ST_OK; 127 | } 128 | return status; 129 | } 130 | 131 | STATUS i2c_msg_get_asd_i2c_msg(I2C_Msg_Builder* state, uint32_t index, 132 | asd_i2c_msg* msg) 133 | { 134 | STATUS status = ST_ERR; 135 | if (state != NULL && state->msg_set != NULL && msg != NULL) 136 | { 137 | struct i2c_rdwr_ioctl_data* ioctl_data = state->msg_set; 138 | if (ioctl_data->nmsgs > index) 139 | { 140 | struct i2c_msg* i2c_msg1 = ioctl_data->msgs + index; 141 | status = copy_i2c_to_asd(msg, i2c_msg1); 142 | } 143 | } 144 | return status; 145 | } 146 | 147 | STATUS i2c_msg_reset(I2C_Msg_Builder* state) 148 | { 149 | STATUS status = ST_ERR; 150 | if (state != NULL) 151 | { 152 | struct i2c_rdwr_ioctl_data* ioctl_data = state->msg_set; 153 | for (int i = 0; i < ioctl_data->nmsgs; i++) 154 | { 155 | struct i2c_msg* i2c_msg1 = ioctl_data->msgs + i; 156 | if (i2c_msg1 != NULL && i2c_msg1->buf != NULL) 157 | { 158 | free(i2c_msg1->buf); 159 | i2c_msg1->buf = NULL; 160 | } 161 | } 162 | ioctl_data->nmsgs = 0; 163 | if (ioctl_data->msgs) 164 | { 165 | free(ioctl_data->msgs); 166 | ioctl_data->msgs = NULL; 167 | } 168 | status = ST_OK; 169 | } 170 | return status; 171 | } 172 | 173 | static STATUS copy_asd_to_i2c(const asd_i2c_msg* asd, struct i2c_msg* i2c) 174 | { 175 | STATUS status = ST_ERR; 176 | if (i2c != NULL && asd != NULL) 177 | { 178 | i2c->addr = asd->address; 179 | i2c->len = asd->length; 180 | i2c->flags = 0; 181 | if (asd->read) 182 | i2c->flags |= I2C_M_RD; 183 | i2c->buf = (__u8*)malloc(i2c->len); 184 | if (i2c->buf != NULL) 185 | { 186 | for (int i = 0; i < i2c->len; i++) 187 | { 188 | i2c->buf[i] = asd->buffer[i]; 189 | } 190 | status = ST_OK; 191 | } 192 | } 193 | return status; 194 | } 195 | 196 | static STATUS copy_i2c_to_asd(asd_i2c_msg* asd, struct i2c_msg* i2c) 197 | { 198 | STATUS status = ST_ERR; 199 | 200 | if (asd != NULL && i2c != NULL) 201 | { 202 | asd->address = (uint8_t)i2c->addr; 203 | asd->length = (uint8_t)i2c->len; 204 | asd->read = ((i2c->flags & I2C_M_RD) == I2C_M_RD); 205 | for (int i = 0; i < i2c->len; i++) 206 | { 207 | asd->buffer[i] = i2c->buf[i]; 208 | } 209 | status = ST_OK; 210 | } 211 | return status; 212 | } -------------------------------------------------------------------------------- /target/i2c_msg_builder.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef ASD_I2C_MSG_BUILDER_H 29 | #define ASD_I2C_MSG_BUILDER_H 30 | 31 | #include 32 | 33 | #include "asd_common.h" 34 | 35 | typedef struct I2C_Msg_Builder 36 | { 37 | void* msg_set; 38 | } I2C_Msg_Builder; 39 | 40 | I2C_Msg_Builder* I2CMsgBuilder(); 41 | STATUS i2c_msg_initialize(I2C_Msg_Builder* state); 42 | STATUS i2c_msg_deinitialize(I2C_Msg_Builder* state); 43 | STATUS i2c_msg_add(I2C_Msg_Builder* state, asd_i2c_msg* msg); 44 | STATUS i2c_msg_get_count(I2C_Msg_Builder* state, uint32_t* count); 45 | STATUS i2c_msg_get_asd_i2c_msg(I2C_Msg_Builder* state, uint32_t index, 46 | asd_i2c_msg* msg); 47 | STATUS i2c_msg_reset(I2C_Msg_Builder* state); 48 | 49 | #endif // ASD_I2C_MSG_BUILDER_H 50 | -------------------------------------------------------------------------------- /target/i2c_msg_builder_stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | // This file implements all i2c_msg_builder functions required by ASD in stub 29 | // mode. A template for all interface functions is included but read / write 30 | // operation will always return an error. 31 | 32 | #include 33 | #include 34 | 35 | #include "i2c_msg_builder.h" 36 | #include "logging.h" 37 | #define I2C_RDW_IOCTL_DATA_SIZE 8 38 | 39 | I2C_Msg_Builder* I2CMsgBuilder() 40 | { 41 | I2C_Msg_Builder* state = (I2C_Msg_Builder*)malloc(sizeof(I2C_Msg_Builder)); 42 | if (state == NULL) 43 | { 44 | ASD_log(ASD_LogLevel_Error, ASD_LogStream_Network, ASD_LogOption_None, 45 | "Failed to malloc I2C_Msg_Builder."); 46 | } 47 | else 48 | { 49 | state->msg_set = NULL; 50 | } 51 | 52 | return state; 53 | } 54 | 55 | STATUS i2c_msg_initialize(I2C_Msg_Builder* state) 56 | { 57 | STATUS status = ST_ERR; 58 | if (state != NULL) 59 | { 60 | state->msg_set = malloc(I2C_RDW_IOCTL_DATA_SIZE); 61 | if (state->msg_set != NULL) 62 | { 63 | status = ST_OK; 64 | } 65 | } 66 | return status; 67 | } 68 | 69 | STATUS i2c_msg_deinitialize(I2C_Msg_Builder* state) 70 | { 71 | STATUS status = ST_ERR; 72 | if (state != NULL) 73 | { 74 | if (state->msg_set != NULL) 75 | { 76 | status = i2c_msg_reset(state); 77 | if (status == ST_OK) 78 | { 79 | free(state->msg_set); 80 | state->msg_set = NULL; 81 | } 82 | } 83 | status = ST_OK; 84 | } 85 | return status; 86 | } 87 | 88 | STATUS i2c_msg_add(I2C_Msg_Builder* state, asd_i2c_msg* msg) 89 | { 90 | STATUS status = ST_ERR; 91 | if (state != NULL && msg != NULL) 92 | { 93 | status = ST_OK; 94 | } 95 | return status; 96 | } 97 | 98 | STATUS i2c_msg_get_count(I2C_Msg_Builder* state, uint32_t* count) 99 | { 100 | STATUS status = ST_ERR; 101 | if (state != NULL && state->msg_set != NULL && count != NULL) 102 | { 103 | *count = 0; 104 | status = ST_OK; 105 | } 106 | return status; 107 | } 108 | 109 | STATUS i2c_msg_get_asd_i2c_msg(I2C_Msg_Builder* state, uint32_t index, 110 | asd_i2c_msg* msg) 111 | { 112 | STATUS status = ST_ERR; 113 | if (state != NULL && state->msg_set != NULL && msg != NULL) 114 | { 115 | status = ST_OK; 116 | } 117 | return status; 118 | } 119 | 120 | STATUS i2c_msg_reset(I2C_Msg_Builder* state) 121 | { 122 | STATUS status = ST_ERR; 123 | if (state != NULL) 124 | { 125 | status = ST_OK; 126 | } 127 | return status; 128 | } -------------------------------------------------------------------------------- /target/i3c_debug_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef I3C_DEBUG_HANDLER_H 29 | #define I3C_DEBUG_HANDLER_H 30 | #define HEADER_SIZE 4 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include "logging.h" 38 | #include 39 | #include 40 | #include 41 | 42 | #include "spp_handler.h" 43 | 44 | struct i3c_debug_opcode_ccc { 45 | __u8 opcode; 46 | __u16 write_len; 47 | ___u64 write_ptr; 48 | __u16 read_len; 49 | ___u64 read_ptr; 50 | }; 51 | 52 | struct i3c_debug_action_ccc { 53 | __u8 action; 54 | }; 55 | #define TIMEOUT_I3C_DEBUG_RX 50 // milliseconds 56 | 57 | #define I3C_DEBUG_IOCTL_BASE 0x79 58 | 59 | #define I3C_DEBUG_IOCTL_DEBUG_OPCODE_CCC \ 60 | _IOWR(I3C_DEBUG_IOCTL_BASE, 0x41, struct i3c_debug_opcode_ccc) 61 | 62 | #define I3C_DEBUG_IOCTL_DEBUG_ACTION_CCC \ 63 | _IOW(I3C_DEBUG_IOCTL_BASE, 0x42, struct i3c_debug_action_ccc) 64 | 65 | #define I3C_DEBUG_IOCTL_GET_EVENT_DATA \ 66 | _IOWR(I3C_DEBUG_IOCTL_BASE, 0x43, struct i3c_get_event_data) 67 | 68 | struct i3c_get_event_data { 69 | __u16 data_len; 70 | ___u64 data_ptr; 71 | }; 72 | 73 | 74 | enum i3cMsgType 75 | { 76 | opcode, 77 | action, 78 | sppPayload, 79 | }; 80 | 81 | typedef struct i3c_cmd 82 | { 83 | int i3cFd; 84 | enum i3cMsgType msgType; 85 | uint8_t opcode; 86 | uint8_t action; 87 | int16_t write_len; 88 | int16_t read_len; 89 | uint8_t* tx_buffer; 90 | uint8_t* rx_buffer; 91 | } i3c_cmd; 92 | 93 | STATUS init_i3c_fd( SPP_Handler* state); 94 | STATUS init_i3c( SPP_Handler* state); 95 | STATUS send_i3c_action(SPP_Handler* state, i3c_cmd *cmd); 96 | STATUS send_i3c_opcode(SPP_Handler* state, i3c_cmd *cmd); 97 | ssize_t receive_i3c(SPP_Handler* state, i3c_cmd *cmd); 98 | void debug_i3c_rx(i3c_cmd*, int device_index); 99 | void debug_i3c_tx(i3c_cmd* cmd, int device_index); 100 | STATUS send_i3c_cmd(SPP_Handler* state, i3c_cmd *cmd); 101 | STATUS i3c_ibi_handler(int fd, uint8_t* ibi_buffer, size_t* ibi_len, 102 | int device_index); 103 | 104 | 105 | #endif // I3C_DEBUG_HANDLER_H -------------------------------------------------------------------------------- /target/i3c_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _I3C_HANDLER_H_ 29 | #define _I3C_HANDLER_H_ 30 | 31 | #include "config.h" 32 | 33 | #include "dbus_helper.h" 34 | 35 | #define UNINITIALIZED_I3C_DRIVER_HANDLE -1 36 | #define UNINITIALIZED_SPD_BUS_MAP_ENTRY -1 37 | #define UNINITIALIZED_I3C_BUS_TOKEN -1 38 | #define i3C_MAX_DEV_HANDLERS 16 39 | 40 | typedef struct I3C_Handler 41 | { 42 | uint8_t i3c_bus; 43 | bus_config* config; 44 | Dbus_Handle* dbus; 45 | int bus_token; 46 | int spd_map[MAX_IxC_BUSES]; 47 | int i3c_driver_handlers[i3C_MAX_DEV_HANDLERS]; 48 | } I3C_Handler; 49 | 50 | I3C_Handler* I3CHandler(bus_config* config); 51 | STATUS i3c_initialize(I3C_Handler* state); 52 | STATUS i3c_deinitialize(I3C_Handler* state); 53 | STATUS i3c_bus_flock(I3C_Handler* state, uint8_t bus, int op); 54 | STATUS i3c_bus_select(I3C_Handler* state, uint8_t bus); 55 | STATUS i3c_set_sclk(I3C_Handler* state, uint16_t sclk); 56 | STATUS i3c_read_write(I3C_Handler* state, void* msg_set); 57 | 58 | #endif -------------------------------------------------------------------------------- /target/i3c_handler_stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "i3c_handler.h" 29 | 30 | // This file implements all i3c_handler functions required by ASD in stub 31 | // mode. A template for all interface functions is included but read / write 32 | // operation will always return an error. 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include "logging.h" 39 | 40 | #define I3C_BUS_ADDRESS_RESERVED 127 41 | 42 | static const ASD_LogStream stream = ASD_LogStream_I2C; 43 | static const ASD_LogOption option = ASD_LogOption_None; 44 | 45 | static bool i3c_enabled(I3C_Handler* state); 46 | static bool i3c_bus_allowed(I3C_Handler* state, uint8_t bus); 47 | static STATUS i3c_get_dev_name(I3C_Handler* state, uint8_t bus, uint8_t* dev); 48 | 49 | I3C_Handler* I3CHandler(bus_config* config) 50 | { 51 | if (config == NULL) 52 | { 53 | ASD_log(ASD_LogLevel_Error, stream, option, 54 | "Invalid config parameter."); 55 | return NULL; 56 | } 57 | 58 | I3C_Handler* state = (I3C_Handler*)malloc(sizeof(I3C_Handler)); 59 | if (state == NULL) 60 | { 61 | ASD_log(ASD_LogLevel_Error, stream, option, 62 | "Failed to malloc I3C_Handler."); 63 | } 64 | else 65 | { 66 | for (int i = 0; i < i3C_MAX_DEV_HANDLERS; i++) 67 | state->i3c_driver_handlers[i] = UNINITIALIZED_I3C_DRIVER_HANDLE; 68 | state->config = config; 69 | state->bus_token = UNINITIALIZED_I3C_BUS_TOKEN; 70 | state->dbus = NULL; 71 | } 72 | 73 | return state; 74 | } 75 | 76 | STATUS i3c_initialize(I3C_Handler* state) 77 | { 78 | STATUS status = ST_ERR; 79 | if (state != NULL && i3c_enabled(state)) 80 | { 81 | status = ST_OK; 82 | state->i3c_bus = I3C_BUS_ADDRESS_RESERVED; 83 | } 84 | return status; 85 | } 86 | 87 | STATUS i3c_deinitialize(I3C_Handler* state) 88 | { 89 | STATUS status = ST_OK; 90 | 91 | if (state == NULL) 92 | return ST_ERR; 93 | 94 | return status; 95 | } 96 | 97 | STATUS i3c_bus_flock(I3C_Handler* state, uint8_t bus, int op) 98 | { 99 | ASD_log(ASD_LogLevel_Debug, ASD_LogStream_I2C, ASD_LogOption_None, 100 | "i3c stub - bus %d %s", bus, op == LOCK_EX ? "LOCK" : "UNLOCK"); 101 | 102 | if (state == NULL) 103 | return ST_ERR; 104 | 105 | return ST_OK; 106 | } 107 | 108 | STATUS i3c_bus_select(I3C_Handler* state, uint8_t bus) 109 | { 110 | STATUS status = ST_ERR; 111 | if (state != NULL && i3c_enabled(state)) 112 | { 113 | if (bus == state->i3c_bus) 114 | { 115 | ASD_log(ASD_LogLevel_Error, stream, option, "Selecting Stub Bus %d", 116 | bus); 117 | status = ST_OK; 118 | } 119 | else if (i3c_bus_allowed(state, bus)) 120 | { 121 | ASD_log(ASD_LogLevel_Error, stream, option, "Selecting Stub Bus %d", 122 | bus); 123 | state->i3c_bus = bus; 124 | state->config->default_bus = bus; 125 | status = ST_OK; 126 | } 127 | else 128 | { 129 | ASD_log(ASD_LogLevel_Error, stream, option, "Bus %d not allowed", 130 | bus); 131 | } 132 | } 133 | return status; 134 | } 135 | 136 | STATUS i3c_set_sclk(I3C_Handler* state, uint16_t sclk) 137 | { 138 | if (state == NULL || !i3c_enabled(state)) 139 | return ST_ERR; 140 | return ST_OK; 141 | } 142 | 143 | STATUS i3c_read_write(I3C_Handler* state, void* msg_set) 144 | { 145 | ASD_log(ASD_LogLevel_Error, stream, option, 146 | "i3c_read_write stub function, R/W not implemented"); 147 | 148 | return ST_ERR; 149 | } 150 | 151 | static bool i3c_enabled(I3C_Handler* state) 152 | { 153 | return state->config->enable_i3c; 154 | } 155 | 156 | static bool i3c_bus_allowed(I3C_Handler* state, uint8_t bus) 157 | { 158 | if (state == NULL) 159 | return false; 160 | for (int i = 0; i < MAX_IxC_BUSES; i++) 161 | { 162 | if (state->config->bus_config_map[i] == bus && 163 | state->config->bus_config_type[i] == BUS_CONFIG_I3C) 164 | return true; 165 | } 166 | return false; 167 | } -------------------------------------------------------------------------------- /target/jtag_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _JTAG_HANDLER_H_ 29 | #define _JTAG_HANDLER_H_ 30 | 31 | #include 32 | 33 | #include "asd_common.h" 34 | 35 | typedef uint8_t __u8; 36 | typedef uint32_t __u32; 37 | 38 | // contains common ioctl command numbers for accessing jtag driver and structs 39 | // jtag_states enum is defined here 40 | //#define JTAG_LEGACY_DRIVER 41 | #ifdef JTAG_LEGACY_DRIVER 42 | #include "tests/jtag_drv.h" 43 | #else 44 | typedef unsigned long long __u64; 45 | #include "tests/jtag.h" 46 | #endif 47 | 48 | #ifndef JTAG_LEGACY_DRIVER 49 | #define jtag_states jtag_tapstate 50 | #define jtag_tlr JTAG_STATE_TLRESET 51 | #define jtag_rti JTAG_STATE_IDLE 52 | #define jtag_sel_dr JTAG_STATE_SELECTDR 53 | #define jtag_cap_dr JTAG_STATE_CAPTUREDR 54 | #define jtag_shf_dr JTAG_STATE_SHIFTDR 55 | #define jtag_ex1_dr JTAG_STATE_EXIT1DR 56 | #define jtag_pau_dr JTAG_STATE_PAUSEDR 57 | #define jtag_ex2_dr JTAG_STATE_EXIT2DR 58 | #define jtag_upd_dr JTAG_STATE_UPDATEDR 59 | #define jtag_sel_ir JTAG_STATE_SELECTIR 60 | #define jtag_cap_ir JTAG_STATE_CAPTUREIR 61 | #define jtag_shf_ir JTAG_STATE_SHIFTIR 62 | #define jtag_ex1_ir JTAG_STATE_EXIT1IR 63 | #define jtag_pau_ir JTAG_STATE_PAUSEIR 64 | #define jtag_ex2_ir JTAG_STATE_EXIT2IR 65 | #define jtag_upd_ir JTAG_STATE_UPDATEIR 66 | #define SW_MODE JTAG_XFER_SW_MODE 67 | #define HW_MODE JTAG_XFER_HW_MODE 68 | #define AST_JTAG_BITBANG JTAG_IOCBITBANG 69 | #define AST_JTAG_SET_TAPSTATE JTAG_SIOCSTATE 70 | #define AST_JTAG_READWRITESCAN JTAG_IOCXFER 71 | #define AST_JTAG_SET_TCK JTAG_SIOCFREQ 72 | #define controller_mode_param jtag_mode 73 | #define tap_state_param jtag_tap_state 74 | #endif 75 | 76 | #define DRMAXPADSIZE 250 77 | #define IRMAXPADSIZE 2000 78 | #define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d)) 79 | #define BITS_PER_BYTE 8 80 | #ifndef APB_FREQ 81 | #define APB_FREQ 24740000 82 | #endif 83 | 84 | typedef enum 85 | { 86 | JTAGPaddingTypes_IRPre, 87 | JTAGPaddingTypes_IRPost, 88 | JTAGPaddingTypes_DRPre, 89 | JTAGPaddingTypes_DRPost 90 | } JTAGPaddingTypes; 91 | 92 | typedef enum 93 | { 94 | JTAGScanState_Done = 0, 95 | JTAGScanState_Run 96 | } JTAGScanState; 97 | 98 | typedef struct JTAGShiftPadding 99 | { 100 | unsigned int drPre; 101 | unsigned int drPost; 102 | unsigned int irPre; 103 | unsigned int irPost; 104 | } JTAGShiftPadding; 105 | 106 | typedef struct JTAG_Chain_State 107 | { 108 | #ifdef JTAG_LEGACY_DRIVER 109 | enum jtag_states tap_state; 110 | #else 111 | enum jtag_tapstate tap_state; 112 | #endif 113 | JTAGShiftPadding shift_padding; 114 | JTAGScanState scan_state; 115 | } JTAG_Chain_State; 116 | 117 | typedef struct JTAG_Handler 118 | { 119 | JTAG_Chain_State chains[MAX_SCAN_CHAINS]; 120 | JTAG_Chain_State* active_chain; 121 | unsigned char padDataOne[IRMAXPADSIZE / 8]; 122 | unsigned char padDataZero[IRMAXPADSIZE / 8]; 123 | struct tck_bitbang bitbang_data[MAX_WAIT_CYCLES]; 124 | int JTAG_driver_handle; 125 | bool sw_mode; 126 | } JTAG_Handler; 127 | 128 | JTAG_Handler* JTAGHandler(); 129 | STATUS JTAG_initialize(JTAG_Handler* state, bool sw_mode); 130 | STATUS JTAG_deinitialize(JTAG_Handler* state); 131 | STATUS JTAG_set_padding(JTAG_Handler* state, JTAGPaddingTypes padding, 132 | unsigned int value); 133 | STATUS JTAG_tap_reset(JTAG_Handler* state); 134 | STATUS JTAG_set_tap_state(JTAG_Handler* state, enum jtag_states tap_state); 135 | STATUS JTAG_get_tap_state(JTAG_Handler* state, enum jtag_states* tap_state); 136 | STATUS JTAG_shift(JTAG_Handler* state, unsigned int number_of_bits, 137 | unsigned int input_bytes, unsigned char* input, 138 | unsigned int output_bytes, unsigned char* output, 139 | enum jtag_states end_tap_state); 140 | STATUS JTAG_shift_hw(JTAG_Handler* state, unsigned int number_of_bits, 141 | unsigned int input_bytes, unsigned char* input, 142 | unsigned int output_bytes, unsigned char* output, 143 | enum jtag_states end_tap_state); 144 | STATUS JTAG_wait_cycles(JTAG_Handler* state, unsigned int number_of_cycles); 145 | STATUS JTAG_set_jtag_tck(JTAG_Handler* state, unsigned int tck); 146 | STATUS JTAG_set_active_chain(JTAG_Handler* state, scanChain chain); 147 | #endif // _JTAG_HANDLER_H_ 148 | -------------------------------------------------------------------------------- /target/spp_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _SPP_HANDLER_H_ 29 | #define _SPP_HANDLER_H_ 30 | 31 | #include 32 | #include 33 | 34 | #include "asd_common.h" 35 | #include "config.h" 36 | 37 | #define UNINITIALIZED_SPP_DEBUG_DRIVER_HANDLE -1 38 | /*the i3c-3 might change in future platforms and will need to get updated.*/ 39 | #define BROADCASTACTIONFILE "/sys/bus/i3c/devices/i3c-3/dbgaction_broadcast" 40 | #define SPASENCLEAR_CMD {0x52, 0x30, 0x04, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff} 41 | #define CLEAR_ERROR_ACTION 0xfd 42 | #define SPP_IBI_DATA_READY 0xAD 43 | #define SPP_IBI_STATUS_CHANGED 0x5C 44 | #define SPP_IBI_SUBREASON_PRDY 0x83 45 | #define SPP_IBI_SUBREASON_OVERFLOW 0xFF 46 | #define SPP_IBI_PRDY_WAIT_TIMEOUT_MS 10 47 | 48 | typedef uint16_t __u16; 49 | typedef uint8_t __u8; 50 | typedef uint32_t __u32; 51 | typedef uint64_t ___u64; 52 | 53 | typedef enum { 54 | BroadcastResetAction = 0x2A, 55 | DirectResetAction = 0x9A, 56 | BpkOpcode = 0xD7, 57 | DebugAction = 0xD8, 58 | BroadcastDebugAction = 0x58 59 | } spp_command_t; 60 | 61 | typedef struct SPP_Handler 62 | { 63 | uint8_t spp_bus; 64 | int spp_buses[MAX_SPP_BUSES]; 65 | bus_config* config; 66 | int spp_dev_handlers[MAX_SPP_BUS_DEVICES]; 67 | int spp_device_count; 68 | uint8_t device_index; 69 | int spp_driver_handle; 70 | bool ibi_handled; 71 | } SPP_Handler; 72 | 73 | SPP_Handler* SPPHandler(bus_config* config); 74 | STATUS spp_initialize(SPP_Handler* state); 75 | STATUS spp_deinitialize(SPP_Handler* state); 76 | STATUS disconnect(SPP_Handler* state); 77 | STATUS spp_bus_flock(SPP_Handler* state, uint8_t bus, int op); 78 | STATUS spp_bus_select(SPP_Handler* state, uint8_t bus); 79 | STATUS spp_set_sclk(SPP_Handler* state, uint16_t sclk); 80 | STATUS spp_bus_device_count(SPP_Handler* state, uint8_t * count); 81 | STATUS spp_bus_get_device_map(SPP_Handler* state, uint32_t * device_mask); 82 | STATUS spp_device_select(SPP_Handler* state, uint8_t device); 83 | STATUS spp_send(SPP_Handler* state, uint16_t size, uint8_t * write_buffer); 84 | STATUS spp_receive(SPP_Handler* state, uint16_t * size, uint8_t * read_buffer); 85 | STATUS spp_send_cmd(SPP_Handler* state, spp_command_t cmd, uint16_t size, 86 | uint8_t * write_buffer); 87 | STATUS send_reset_rx(SPP_Handler* state); 88 | STATUS spp_send_receive_cmd(SPP_Handler* state, spp_command_t cmd, 89 | uint16_t wsize, uint8_t * write_buffer, 90 | const uint16_t * rsize, uint8_t * read_buffer); 91 | STATUS spp_set_sim_data_cmd(SPP_Handler* state, uint16_t size, uint8_t * read_buffer); 92 | bool check_spp_prdy_event(ASD_EVENT event, ASD_EVENT_DATA event_data); 93 | #endif // _SPP_HANDLER_H_ 94 | -------------------------------------------------------------------------------- /target/spp_handler_stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "spp_handler.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | // clang-format off 39 | #include 40 | // clang-format on 41 | 42 | #include "logging.h" 43 | 44 | static const ASD_LogStream stream = ASD_LogStream_SPP; 45 | static const ASD_LogOption option = ASD_LogLevel_Info; 46 | 47 | #define SPP_READ_BACK_SIMULATOR 48 | 49 | #ifdef SPP_READ_BACK_SIMULATOR 50 | #define SPP_SIM_DATA_STATUS_EMPTY 0 51 | #define SPP_SIM_DATA_STATUS_READY 1 52 | 53 | typedef struct SPP_Sim_Data 54 | { 55 | uint16_t status; 56 | uint16_t size; 57 | unsigned char buffer[MAX_DATA_SIZE]; 58 | } SPP_Sim_Data; 59 | 60 | SPP_Sim_Data sim_data; 61 | #endif // SPP_READ_BACK_SIMULATOR 62 | 63 | SPP_Handler* SPPHandler(bus_config* config) 64 | { 65 | uint16_t i = 0; 66 | SPP_Handler* state = (SPP_Handler*)malloc(sizeof(SPP_Handler)); 67 | if (state == NULL) 68 | { 69 | ASD_log(ASD_LogLevel_Error, stream, option, 70 | "Failed to malloc SPP_Handler."); 71 | return NULL; 72 | } 73 | 74 | for (i = 0; i < MAX_SPP_BUSES; i++) 75 | { 76 | state->spp_buses[i] = 0; 77 | } 78 | 79 | state->i3c_debug_driver_handle = UNINITIALIZED_I3C_DEBUG_DRIVER_HANDLE; 80 | 81 | #ifdef SPP_READ_BACK_SIMULATOR 82 | sim_data.size = 0; 83 | sim_data.status = SPP_SIM_DATA_STATUS_EMPTY; 84 | #endif // SPP_READ_BACK_SIMULATOR 85 | 86 | return state; 87 | } 88 | 89 | STATUS spp_initialize(SPP_Handler* state) 90 | { 91 | if (state == NULL) 92 | return ST_ERR; 93 | 94 | return ST_OK; 95 | } 96 | 97 | STATUS spp_deinitialize(SPP_Handler* state) 98 | { 99 | if (state == NULL) 100 | return ST_ERR; 101 | 102 | return ST_OK; 103 | } 104 | 105 | STATUS spp_bus_flock(SPP_Handler* state, uint8_t bus, int op) 106 | { 107 | return ST_OK; 108 | } 109 | 110 | STATUS spp_bus_select(SPP_Handler* state, uint8_t bus) 111 | { 112 | return ST_OK; 113 | } 114 | 115 | STATUS spp_set_sclk(SPP_Handler* state, uint16_t sclk) 116 | { 117 | return ST_OK; 118 | } 119 | 120 | STATUS spp_send(SPP_Handler* state, uint16_t size, uint8_t * write_buffer) 121 | { 122 | ASD_log(ASD_LogLevel_Debug, stream, option, "spp_send(%d bytes)", size); 123 | ASD_log_buffer(ASD_LogLevel_Debug, stream, option, write_buffer, 124 | (size_t)size, "Spp"); 125 | return ST_OK; 126 | } 127 | 128 | STATUS spp_receive(SPP_Handler* state, uint16_t * size, uint8_t * read_buffer) 129 | { 130 | STATUS status = ST_OK; 131 | uint16_t num_of_bytes = *size; 132 | uint16_t i = 0; 133 | 134 | #ifdef SPP_READ_BACK_SIMULATOR 135 | if(sim_data.status == SPP_SIM_DATA_STATUS_EMPTY) { 136 | status = ST_ERR; 137 | } else { 138 | for (i = 0; i < sim_data.size; i++) { 139 | read_buffer[i] = sim_data.buffer[i]; 140 | } 141 | *size = sim_data.size; 142 | ASD_log_buffer(ASD_LogLevel_Debug, stream, option,read_buffer, 143 | (size_t)*size, "SimOut"); 144 | sim_data.status = SPP_SIM_DATA_STATUS_EMPTY; 145 | sim_data.size = 0; 146 | } 147 | #else 148 | ASD_log(ASD_LogLevel_Debug, stream, option, "spp_receive(PATTERN)"); 149 | read_buffer[0] = 0xBB; 150 | for (i = 1; i < num_of_bytes - 1; i++) { 151 | read_buffer[i] = 0xCC; 152 | } 153 | read_buffer[num_of_bytes-1] = 0xEE; 154 | #endif // SPP_READ_BACK_SIMULATOR 155 | 156 | return status; 157 | } 158 | 159 | STATUS spp_send_cmd(SPP_Handler* state, spp_command_t cmd, uint16_t size, 160 | uint8_t * write_buffer) 161 | { 162 | ASD_log(ASD_LogLevel_Debug, stream, option, "spp_send_cmd(%d bytes)", 163 | size); 164 | ASD_log_buffer(ASD_LogLevel_Debug, stream, option, write_buffer, 165 | (size_t)size, "SppCmd"); 166 | return ST_OK; 167 | } 168 | 169 | STATUS spp_send_receive_cmd(SPP_Handler* state, spp_command_t cmd, 170 | uint16_t wsize, uint8_t * write_buffer, 171 | uint16_t * rsize, uint8_t * read_buffer) 172 | { 173 | STATUS status = ST_OK; 174 | uint16_t num_of_bytes = wsize; 175 | uint16_t i = 0; 176 | ASD_log(ASD_LogLevel_Debug, stream, option, 177 | "spp_send_receive_cmd(%d bytes)", num_of_bytes); 178 | ASD_log_buffer(ASD_LogLevel_Debug, stream, option, write_buffer, 179 | (size_t)num_of_bytes, "SppCmd"); 180 | 181 | #ifdef SPP_READ_BACK_SIMULATOR 182 | if(sim_data.status == SPP_SIM_DATA_STATUS_EMPTY) { 183 | status = ST_ERR; 184 | } else { 185 | for (i = 0; i < sim_data.size; i++) { 186 | read_buffer[i] = sim_data.buffer[i]; 187 | } 188 | *rsize = sim_data.size; 189 | ASD_log_buffer(ASD_LogLevel_Debug, stream, option,read_buffer, 190 | (size_t)*rsize, "SimOut"); 191 | sim_data.status = SPP_SIM_DATA_STATUS_EMPTY; 192 | sim_data.size = 0; 193 | } 194 | #else 195 | ASD_log(ASD_LogLevel_Debug, stream, option, 196 | "spp_send_receive_cmd(PATTERN)"); 197 | read_buffer[0] = 0xBB; 198 | for (i = 1; i < num_of_bytes - 1; i++) { 199 | read_buffer[i] = 0xCC; 200 | } 201 | read_buffer[num_of_bytes-1] = 0xEE; 202 | #endif // SPP_READ_BACK_SIMULATOR 203 | return status; 204 | } 205 | 206 | STATUS spp_set_sim_data_cmd(SPP_Handler* state, uint16_t size, 207 | uint8_t * read_buffer) 208 | { 209 | #ifdef SPP_READ_BACK_SIMULATOR 210 | uint16_t i = 0; 211 | ASD_log(ASD_LogLevel_Debug, stream, option, 212 | "spp_set_sim_read_data_cmd(%d bytes)", size); 213 | 214 | for (i = 0; i 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "logging.h" 40 | 41 | static const ASD_LogStream stream = ASD_LogStream_JTAG; 42 | static const ASD_LogOption option = ASD_LogOption_None; 43 | 44 | vProbe_Handler* vProbeHandler() 45 | { 46 | vProbe_Handler* state = (vProbe_Handler*)malloc(sizeof(vProbe_Handler)); 47 | 48 | if (state == NULL) 49 | { 50 | return NULL; 51 | } 52 | 53 | state->dbus = dbus_helper(); 54 | if (state->dbus == NULL) 55 | { 56 | free(state); 57 | return NULL; 58 | } 59 | 60 | state->initialized = false; 61 | state->remoteProbes = 0; 62 | state->remoteConfigs = 0; 63 | 64 | return state; 65 | } 66 | 67 | STATUS vProbeConfigAppend(char** buff, size_t* destsize, const char* str) 68 | { 69 | if (destsize == NULL || str == NULL || buff == NULL) 70 | return ST_ERR; 71 | 72 | uint32_t count = strnlen_s(str, MAX_DATA_SIZE); 73 | if (strcpy_s(*buff, *destsize, str)) 74 | { 75 | return ST_ERR; 76 | } 77 | 78 | *buff += count; 79 | *destsize = *destsize - count; 80 | return ST_OK; 81 | } 82 | 83 | STATUS vProbe_initialize(vProbe_Handler* state) 84 | { 85 | int ia[1] = {0}; 86 | uint8_t line[BUFFER_LINE_SIZE]; 87 | size_t cfg_remain_size = 0; 88 | char* buffer = NULL; 89 | STATUS result; 90 | 91 | if (state == NULL) 92 | return ST_ERR; 93 | 94 | cfg_remain_size = sizeof(state->probesConfig); 95 | buffer = state->probesConfig; 96 | 97 | // TODO: read configuration from dbus 98 | 99 | // Build XML config for remote probes 100 | result = vProbeConfigAppend(&buffer, &cfg_remain_size, 101 | "\r\n"); 102 | if (result != ST_OK) 103 | return result; 104 | 105 | for (unsigned int i = 0; i < state->remoteConfigs; i++) 106 | { 107 | ia[0] = MAX_SCAN_CHAINS + i; // UniqueId 108 | if (sprintf_s(line, sizeof(line), "\r\n", ia, 1)) 109 | return ST_ERR; 110 | 111 | result = vProbeConfigAppend(&buffer, &cfg_remain_size, line); 112 | if (result != ST_OK) 113 | return result; 114 | 115 | ia[0] = MAX_SCAN_CHAINS + i; // UniqueId 116 | if (sprintf_s(line, sizeof(line), 117 | "\r\n", 119 | ia, 1)) 120 | { 121 | return ST_ERR; 122 | } 123 | 124 | result = vProbeConfigAppend(&buffer, &cfg_remain_size, line); 125 | if (result != ST_OK) 126 | return result; 127 | 128 | result = vProbeConfigAppend(&buffer, &cfg_remain_size, "\r\n"); 129 | if (result != ST_OK) 130 | return result; 131 | } 132 | 133 | result = vProbeConfigAppend(&buffer, &cfg_remain_size, "\r\n"); 134 | if (result != ST_OK) 135 | return result; 136 | 137 | *buffer = 0x0; // Null termination caracter 138 | ASD_log(ASD_LogLevel_Debug, stream, option, "vProbe config:\r\n%s", 139 | state->probesConfig); 140 | 141 | state->initialized = true; 142 | return ST_OK; 143 | } 144 | 145 | STATUS vProbe_deinitialize(vProbe_Handler* state) 146 | { 147 | if (state == NULL || !state->initialized) 148 | return ST_ERR; 149 | 150 | if (state->dbus != NULL) 151 | { 152 | dbus_deinitialize(state->dbus); 153 | free(state->dbus); 154 | state->dbus = NULL; 155 | } 156 | 157 | return ST_OK; 158 | } 159 | -------------------------------------------------------------------------------- /target/vprobe_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2020, Intel Corporation 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _VPROBE_HANDLER_H_ 29 | #define _VPROBE_HANDLER_H_ 30 | 31 | #include 32 | 33 | #include "asd_common.h" 34 | #include "dbus_helper.h" 35 | #include "target_handler.h" 36 | 37 | #define MAX_REMOTE_PROBES 8 38 | #define BUFFER_LINE_SIZE 150 39 | 40 | typedef struct vProbe_Handler 41 | { 42 | uint8_t remoteProbes; 43 | uint8_t remoteConfigs; 44 | char probesConfig[MAX_DATA_SIZE]; 45 | bool initialized; 46 | Dbus_Handle* dbus; 47 | } vProbe_Handler; 48 | 49 | vProbe_Handler* vProbeHandler(); 50 | STATUS vProbe_initialize(vProbe_Handler* state); 51 | STATUS vProbe_deinitialize(vProbe_Handler* state); 52 | #endif // _VPROBE_HANDLER_H_ 53 | --------------------------------------------------------------------------------